* pccl.el (ccl-compat): Since mule 2.3 accepts `t' and `nil' as `type'
[elisp/apel.git] / pccl.el
1 ;;; pccl.el --- Portable CCL utility for Mule 2.*
2
3 ;; Copyright (C) 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 ;;; Code:
26
27 (require 'broken)
28
29 (broken-facility ccl-usable
30   "Emacs has not CCL."
31   (and (featurep 'mule)
32        (if (featurep 'xemacs)
33            (>= emacs-major-version 21)
34          (>= emacs-major-version 19))))
35
36 (unless-broken ccl-usable
37   (require 'ccl)
38   (require 'advice)
39
40   (if (featurep 'mule)
41       (if (featurep 'xemacs)
42           (if (>= emacs-major-version 21)
43               ;; for XEmacs 21 with mule
44               (require 'pccl-20))
45         (if (>= emacs-major-version 20)
46             ;; for Emacs 20
47             (require 'pccl-20)
48           ;; for Mule 2.*
49           (require 'pccl-om))))
50
51   (static-if (or (featurep 'xemacs) (< emacs-major-version 21))
52     (defadvice define-ccl-program
53       (before accept-long-ccl-program activate)
54       "When CCL-PROGRAM is too long, internal buffer is extended automatically."
55       (let ((try-ccl-compile t)
56             (prog (eval (ad-get-arg 1))))
57         (ad-set-arg 1 (` '(, prog)))
58         (while try-ccl-compile
59           (setq try-ccl-compile nil)
60           (condition-case sig
61               (ccl-compile prog)
62             (args-out-of-range
63              (if (and (eq (car (cdr sig)) ccl-program-vector)
64                       (= (car (cdr (cdr sig))) (length ccl-program-vector)))
65                  (setq ccl-program-vector
66                        (make-vector (* 2 (length ccl-program-vector)) 0)
67                        try-ccl-compile t)
68                (signal (car sig) (cdr sig)))))))))
69
70   (static-when (and (not (featurep 'xemacs)) (< emacs-major-version 21))
71     (defun-maybe transform-make-coding-system-args (name type &optional doc-string props)
72       "For internal use only.
73 Transform XEmacs style args for `make-coding-system' to Emacs style.
74 Value is a list of transformed arguments."
75       (let ((mnemonic (string-to-char (or (plist-get props 'mnemonic) "?")))
76             (eol-type (plist-get props 'eol-type))
77             properties tmp)
78         (cond
79          ((eq eol-type 'lf) (setq eol-type 'unix))
80          ((eq eol-type 'crlf) (setq eol-type 'dos))
81          ((eq eol-type 'cr) (setq eol-type 'mac)))
82         (if (setq tmp (plist-get props 'post-read-conversion))
83             (setq properties (plist-put properties 'post-read-conversion tmp)))
84         (if (setq tmp (plist-get props 'pre-write-conversion))
85             (setq properties (plist-put properties 'pre-write-conversion tmp)))
86         (cond
87          ((eq type 'shift-jis)
88           `(,name 1 ,mnemonic ,doc-string () ,properties ,eol-type))
89          ((eq type 'iso2022) ; This is not perfect.
90           (if (plist-get props 'escape-quoted)
91               (error "escape-quoted is not supported: %S"
92                      `(,name ,type ,doc-string ,props)))
93           (let ((g0 (plist-get props 'charset-g0))
94                 (g1 (plist-get props 'charset-g1))
95                 (g2 (plist-get props 'charset-g2))
96                 (g3 (plist-get props 'charset-g3))
97                 (use-roman
98                  (and
99                   (eq (cadr (assoc 'latin-jisx0201
100                                    (plist-get props 'input-charset-conversion)))
101                       'ascii)
102                   (eq (cadr (assoc 'ascii
103                                    (plist-get props 'output-charset-conversion)))
104                       'latin-jisx0201)))
105                 (use-oldjis
106                  (and
107                   (eq (cadr (assoc 'japanese-jisx0208-1978
108                                    (plist-get props 'input-charset-conversion)))
109                       'japanese-jisx0208)
110                   (eq (cadr (assoc 'japanese-jisx0208
111                                    (plist-get props 'output-charset-conversion)))
112                       'japanese-jisx0208-1978))))
113             (if (charsetp g0)
114                 (if (plist-get props 'force-g0-on-output)
115                     (setq g0 `(nil ,g0))
116                   (setq g0 `(,g0 t))))
117             (if (charsetp g1)
118                 (if (plist-get props 'force-g1-on-output)
119                     (setq g1 `(nil ,g1))
120                   (setq g1 `(,g1 t))))
121             (if (charsetp g2)
122                 (if (plist-get props 'force-g2-on-output)
123                     (setq g2 `(nil ,g2))
124                   (setq g2 `(,g2 t))))
125             (if (charsetp g3)
126                 (if (plist-get props 'force-g3-on-output)
127                     (setq g3 `(nil ,g3))
128                   (setq g3 `(,g3 t))))
129             `(,name 2 ,mnemonic ,doc-string
130               (,g0 ,g1 ,g2 ,g3
131                ,(plist-get props 'short)
132                ,(not (plist-get props 'no-ascii-eol))
133                ,(not (plist-get props 'no-ascii-cntl))
134                ,(plist-get props 'seven)
135                t
136                ,(not (plist-get props 'lock-shift))
137                ,use-roman
138                ,use-oldjis
139                ,(plist-get props 'no-iso6429)
140                nil nil nil nil)
141             ,properties ,eol-type)))
142          ((eq type 'big5)
143           `(,name 3 ,mnemonic ,doc-string () ,properties ,eol-type))
144          ((eq type 'ccl)
145           `(,name 4 ,mnemonic ,doc-string
146                   (,(plist-get props 'decode) . ,(plist-get props 'encode))
147                   ,properties ,eol-type))
148          (t
149           (error "unsupported XEmacs style make-coding-style arguments: %S"
150                  `(,name ,type ,doc-string ,props))))))
151     (defadvice make-coding-system
152       (before ccl-compat (name type &rest ad-subr-args) activate)
153       "Emulate XEmacs style make-coding-system."
154       (when (and (symbolp type) (not (memq type '(t nil))))
155         (let ((args (apply 'transform-make-coding-system-args
156                            name type ad-subr-args)))
157           (setq type (cadr args)
158                 ad-subr-args (cddr args)))))))
159
160
161 ;;; @ end
162 ;;;
163
164 (require 'product)
165 (product-provide (provide 'pccl) (require 'apel-ver))
166
167 ;;; pccl.el ends here