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