* pccl.el (transform-make-coding-system-args): Follow old backquote style.
[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)
89               nil (, properties) (, eol-type))))
90          ((eq type 'iso2022) ; This is not perfect.
91           (if (plist-get props 'escape-quoted)
92               (error "escape-quoted is not supported: %S"
93                      (` ((, name) (, type) (, doc-string) (, props)))))
94           (let ((g0 (plist-get props 'charset-g0))
95                 (g1 (plist-get props 'charset-g1))
96                 (g2 (plist-get props 'charset-g2))
97                 (g3 (plist-get props 'charset-g3))
98                 (use-roman
99                  (and
100                   (eq (cadr (assoc 'latin-jisx0201
101                                    (plist-get props 'input-charset-conversion)))
102                       'ascii)
103                   (eq (cadr (assoc 'ascii
104                                    (plist-get props 'output-charset-conversion)))
105                       'latin-jisx0201)))
106                 (use-oldjis
107                  (and
108                   (eq (cadr (assoc 'japanese-jisx0208-1978
109                                    (plist-get props 'input-charset-conversion)))
110                       'japanese-jisx0208)
111                   (eq (cadr (assoc 'japanese-jisx0208
112                                    (plist-get props 'output-charset-conversion)))
113                       'japanese-jisx0208-1978))))
114             (if (charsetp g0)
115                 (if (plist-get props 'force-g0-on-output)
116                     (setq g0 (` (nil (, g0))))
117                   (setq g0 (` ((, g0) t)))))
118             (if (charsetp g1)
119                 (if (plist-get props 'force-g1-on-output)
120                     (setq g1 (` (nil (, g1))))
121                   (setq g1 (` ((, g1) t)))))
122             (if (charsetp g2)
123                 (if (plist-get props 'force-g2-on-output)
124                     (setq g2 (` (nil (, g2))))
125                   (setq g2 (` ((, g2) t)))))
126             (if (charsetp g3)
127                 (if (plist-get props 'force-g3-on-output)
128                     (setq g3 (` (nil (, g3))))
129                   (setq g3 (` ((, g3) t)))))
130             (` ((, name) 2 (, mnemonic) (, doc-string)
131                 ((, g0) (, g1) (, g2) (, g3)
132                  (, (plist-get props 'short))
133                  (, (not (plist-get props 'no-ascii-eol)))
134                  (, (not (plist-get props 'no-ascii-cntl)))
135                  (, (plist-get props 'seven))
136                  t
137                  (, (not (plist-get props 'lock-shift)))
138                  (, use-roman)
139                  (, use-oldjis)
140                  (, (plist-get props 'no-iso6429))
141                  nil nil nil nil)
142                 (, properties) (, eol-type)))))
143          ((eq type 'big5)
144           (` ((, name) 3 (, mnemonic) (, doc-string)
145               nil (, properties) (, eol-type))))
146          ((eq type 'ccl)
147           (` ((, name) 4 (, mnemonic) (, doc-string)
148               ((, (plist-get props 'decode)) . (, (plist-get props 'encode)))
149               (, properties) (, eol-type))))
150          (t
151           (error "unsupported XEmacs style make-coding-style arguments: %S"
152                  (` ((, name) (, type) (, doc-string) (, props))))))))
153     (defadvice make-coding-system
154       (before ccl-compat (name type &rest ad-subr-args) activate)
155       "Emulate XEmacs style make-coding-system."
156       (when (and (symbolp type) (not (memq type '(t nil))))
157         (let ((args (apply 'transform-make-coding-system-args
158                            name type ad-subr-args)))
159           (setq type (cadr args)
160                 ad-subr-args (cddr args)))))))
161
162
163 ;;; @ end
164 ;;;
165
166 (require 'product)
167 (product-provide (provide 'pccl) (require 'apel-ver))
168
169 ;;; pccl.el ends here