update.
[elisp/apel.git] / pccl-om.el
1 ;;; pccl-om.el --- Portable CCL utility for Mule 2.*
2
3 ;; Copyright (C) 1998 Free Software Foundation, Inc.
4 ;; Copyright (C) 1998 Tanaka Akira
5
6 ;; Author: Tanaka Akira <akr@jaist.ac.jp>
7 ;;      Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
8 ;; Keywords: emulation, compatibility, Mule
9
10 ;; This file is part of APEL (A Portable Emacs Library).
11
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
16
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26
27 ;;; Code:
28
29 (eval-when-compile (require 'ccl))
30 (require 'broken)
31
32 (broken-facility ccl-accept-symbol-as-program
33   "Emacs does not accept symbol as CCL program.")
34
35 (eval-and-compile
36   (defun make-ccl-coding-system
37     (coding-system mnemonic doc-string decoder encoder)
38     "\
39 Define a new CODING-SYSTEM by CCL programs DECODER and ENCODER.
40
41 CODING-SYSTEM, DECODER and ENCODER must be symbol."
42     (setq decoder (symbol-value decoder)
43           encoder (symbol-value encoder))
44     (make-coding-system coding-system 4 mnemonic doc-string
45                         nil             ; Mule takes one more optional argument: EOL-TYPE.
46                         (cons decoder encoder)))
47   )
48
49 (defun ccl-execute (ccl-prog reg)
50   "Execute CCL-PROG with registers initialized by REGISTERS.
51 If CCL-PROG is symbol, it is dereferenced."
52   (exec-ccl
53    (if (symbolp ccl-prog) (symbol-value ccl-prog) ccl-prog)
54    reg))
55
56 (defun ccl-execute-on-string (ccl-prog status string &optional contin)
57   "Execute CCL-PROG with initial STATUS on STRING.
58 If CCL-PROG is symbol, it is dereferenced."
59   (exec-ccl-string
60    (if (symbolp ccl-prog) (symbol-value ccl-prog) ccl-prog)
61    status string))
62
63 (broken-facility ccl-execute-on-string-ignore-contin
64   "CONTIN argument for ccl-execute-on-string is ignored.")
65
66 (eval-when-compile
67   (define-ccl-program test-ccl-eof-block
68     '(1
69       ((read r0)
70        (write r0)
71        (read r0))
72       (write "[EOF]")))
73
74   (make-ccl-coding-system
75    'test-ccl-eof-block-cs ?T "CCL_EOF_BLOCK tester"
76    'test-ccl-eof-block 'test-ccl-eof-block)
77   )
78
79 (broken-facility ccl-execute-eof-block-on-encoding-null
80   "Emacs forgets executing CCL_EOF_BLOCK with encoding on empty input."
81   (equal (code-convert-string "" *internal* 'test-ccl-eof-block-cs) "[EOF]"))
82
83 (broken-facility ccl-execute-eof-block-on-encoding-some
84   "Emacs forgets executing CCL_EOF_BLOCK with encoding on non-empty input."
85   (equal (code-convert-string "a" *internal* 'test-ccl-eof-block-cs) "a[EOF]"))
86
87 (broken-facility ccl-execute-eof-block-on-decoding-null
88   "Emacs forgets executing CCL_EOF_BLOCK with decoding on empty input."
89   (equal (code-convert-string "" 'test-ccl-eof-block-cs *internal*) "[EOF]"))
90
91 (broken-facility ccl-execute-eof-block-on-decoding-some
92   "Emacs forgets executing CCL_EOF_BLOCK with decoding on non-empty input."
93   (equal (code-convert-string "a" 'test-ccl-eof-block-cs *internal*) "a[EOF]"))
94
95 (broken-facility ccl-execute-eof-block-on-encoding
96   "Emacs may forget executing CCL_EOF_BLOCK with encoding."
97   (not (or (broken-p 'ccl-execute-eof-block-on-encoding-null)
98            (broken-p 'ccl-execute-eof-block-on-encoding-some)))
99   t)
100
101 (broken-facility ccl-execute-eof-block-on-decoding
102   "Emacs may forget executing CCL_EOF_BLOCK with decoding."
103   (not (or (broken-p 'ccl-execute-eof-block-on-decoding-null)
104            (broken-p 'ccl-execute-eof-block-on-decoding-some)))
105   t)
106
107 (broken-facility ccl-execute-eof-block
108   "Emacs may forget executing CCL_EOF_BLOCK."
109   (not (or (broken-p 'ccl-execute-eof-block-on-encoding)
110            (broken-p 'ccl-execute-eof-block-on-decoding)))
111   t)
112
113 (broken-facility ccl-cascading-read
114   "Emacs CCL read command does not accept more than 2 arguments."
115   (condition-case nil
116       (progn
117         (define-ccl-program cascading-read-test
118           '(1
119             (read r0 r1 r2)))
120         t)
121     (error nil)))
122
123 ;;; @ end
124 ;;;
125
126 (require 'product)
127 (product-provide (provide 'pccl-om) (require 'apel-ver))
128
129 ;;; pccl-om.el ends here