1 ;;; egg/cannarpc.el --- Canna Support (low level interface) in
2 ;;; Egg Input Method Architecture
4 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc
6 ;; Author: NIIBE Yutaka <gniibe@chroot.org>
8 ;; Maintainer: TOMURA Satoru <tomura@etl.go.jp>
10 ;; Keywords: mule, multilingual, input method
12 ;; This file is part of EGG.
14 ;; EGG is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; EGG is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
38 ;; (load-library "egg/canna")
39 (defmacro canna-const (c)
40 (cond ((eq c 'Initialize) 1)
42 ((eq c 'CreateContext) 3)
43 ((eq c 'CloseContext) 5)
44 ((eq c 'GetDictionaryList) 6)
45 ((eq c 'GetDirectoryList) 7)
46 ((eq c 'MountDictionary) 8)
47 ((eq c 'UnmountDictionary) 9)
48 ((eq c 'BeginConvert) 15)
49 ((eq c 'EndConvert) 16)
50 ((eq c 'GetCandidacyList) 17)
52 ((eq c 'ResizePause) 26)
54 ((eq c 'CreateDictionary) 3)
55 (t (error "No such constant")))))
57 (defun cannarpc-get-error-message (errno)
58 (or (aref cannarpc-error-message errno) (format "#%d" errno)))
60 (defmacro cannarpc-call-with-environment (e vlist send-expr &rest receive-exprs)
62 `((proc (cannaenv-get-proc ,e))
63 (context (cannaenv-get-context ,e)))
69 (set-buffer (process-buffer proc))
72 (process-send-region proc (point-min) (point-max))
73 (goto-char (prog1 (point) (accept-process-output proc))))
76 (defconst canna-version-fmt "2.0:%s")
78 (defun cannarpc-open (proc username)
79 "Open the session. Return 0 on success, error code on failure."
80 (let ((verusr (format canna-version-fmt username)))
81 (comm-call-with-proc proc (result)
82 (comm-format (u u v) (canna-const Initialize) (length verusr) verusr)
83 (comm-unpack (u) result)
86 (defun cannarpc-close (proc)
87 (comm-call-with-proc proc (dummy result)
88 (comm-format (b b w) (canna-const Finalize) 0 0)
89 (comm-unpack (b b w b) dummy dummy dummy result)
92 (defun cannarpc-create-context (proc)
93 (comm-call-with-proc proc (dummy result)
94 (comm-format (b b w) (canna-const CreateContext) 0 0)
95 (comm-unpack (b b w w) dummy dummy dummy result)
98 (defun cannarpc-close-context (proc context)
99 (comm-call-with-proc proc (dummy result)
100 (comm-format (b b w w) (canna-const CloseContext) 0 2 context)
101 (comm-unpack (b b w b) dummy dummy dummy result)
104 ;; XXX: Not implemented fully
105 (defun cannarpc-get-dictionary-list (env)
106 (cannarpc-call-with-environment env (dymmy result)
107 (comm-format (b b w w w) (canna-const GetDictionaryList) 0 4
109 (comm-unpack (u w) dummy result)
110 ;; follow list of dictionaries
113 ;; XXX: Not implemented fully
114 (defun cannarpc-get-directory-list (env)
115 (cannarpc-call-with-environment env (dymmy result)
116 (comm-format (b b w w w) (canna-const GetDirectoryList) 0 4
118 (comm-unpack (u w) dummy result)
119 ;; follow list of directories
122 (defun cannarpc-open-dictionary (env dict-file-name mode)
123 (cannarpc-call-with-environment env (dymmy result)
124 (comm-format (b b w u w s) (canna-const MountDictionary) 0
125 (+ (length dict-file-name) 7)
126 mode context dict-file-name)
127 (comm-unpack (u b) dummy result)
130 (defun cannarpc-close-dictionary (env dict-file-name mode)
131 (cannarpc-call-with-environment env (dymmy result)
132 (comm-format (b b w u w s) (canna-const UnmountDictionary) 0
133 (+ (length dict-file-name) 6)
134 mode context dict-file-name)
135 (comm-unpack (u b) dummy result)
138 (defun cannarpc-begin-conversion (env yomi)
140 (let ((yomi-ext (encode-coding-string yomi 'euc-japan))
142 converted bunsetsu-list bl)
143 (cannarpc-call-with-environment env (dummy result)
144 (comm-format (b b w u w S) (canna-const BeginConvert) 0
145 (+ (length yomi-ext) 8) 0 context yomi)
146 (comm-unpack (u w) dummy result)
150 (comm-unpack (S) converted)
151 (let ((bl1 (cons (canna-make-bunsetsu env converted i)
154 (setq bl (setcdr bl bl1))
155 (setq bunsetsu-list (setq bl bl1))))
159 (defun cannarpc-end-conversion (env len zenkouho-pos-vector mode)
161 (cannarpc-call-with-environment env (dummy result)
162 (comm-format (b b w w w u v) (canna-const EndConvert) 0
163 (+ (* len 2) 8) context len mode zenkouho-pos-vector)
164 (comm-unpack (u b) dummy result)
169 (defun cannarpc-make-dictionary (env dict-name)
170 (cannarpc-call-with-environment env (dummy result)
171 (comm-format (b b w u w s) (canna-const CreateDictionary) 1
172 (+ (length dict-name) 7) 0 context dict-name)
173 (comm-unpack (u b) dummy result)
176 (defun cannarpc-get-bunsetsu-source (env bunsetsu-pos)
177 (cannarpc-call-with-environment env (dummy result)
178 (comm-format (b b w w w w) (canna-const GetYomi) 0 6 context
180 (comm-unpack (u w) dummy result)
183 (comm-unpack (S) result)
186 (defun cannarpc-get-bunsetsu-candidates (env bunsetsu-pos)
188 converted bunsetsu-list bl)
189 (cannarpc-call-with-environment env (dummy result)
190 (comm-format (b b w w w w) (canna-const GetCandidacyList) 0 6 context
192 (comm-unpack (u w) dymmy result)
196 (comm-unpack (S) converted)
197 (let ((bl1 (cons (canna-make-bunsetsu env converted bunsetsu-pos)
200 (setq bl (setcdr bl bl1))
201 (setq bunsetsu-list (setq bl bl1))))
205 ;;; egg/cannarpc.el ends here.