1 ;;; egg/cannarpc.el --- Canna Support (low level interface) in
2 ;;; Egg Input Method Architecture
4 ;; Copyright (C) 1997, 1998 Mule Project,
5 ;; Powered by Electrotechnical Laboratory, JAPAN.
6 ;; Project Leader: Satoru Tomura <tomura@etl.go.jp>
8 ;; Author: NIIBE Yutaka <gniibe@mri.co.jp>
9 ;; Maintainer: NIIBE Yutaka <gniibe@mri.co.jp>
11 ;; This file is part of EGG.
13 ;; EGG is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; EGG is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
34 ;; (load-library "egg/canna")
35 (defmacro canna-const (c)
36 (cond ((eq c 'Initialize) 1)
38 ((eq c 'CreateContext) 3)
39 ((eq c 'CloseContext) 5)
40 ((eq c 'GetDictionaryList) 6)
41 ((eq c 'GetDirectoryList) 7)
42 ((eq c 'MountDictionary) 8)
43 ((eq c 'UnmountDictionary) 9)
44 ((eq c 'BeginConvert) 15)
45 ((eq c 'EndConvert) 16)
46 ((eq c 'GetCandidacyList) 17)
48 ((eq c 'ResizePause) 26)
50 ((eq c 'CreateDictionary) 3)
51 (t (error "No such constant")))))
53 (defun cannarpc-get-error-message (errno)
54 (or (aref cannarpc-error-message errno) (format "#%d" errno)))
56 (defmacro cannarpc-call-with-environment (e vlist send-expr &rest receive-exprs)
58 `((proc (cannaenv-get-proc ,e))
59 (context (cannaenv-get-context ,e)))
65 (set-buffer (process-buffer proc))
68 (process-send-region proc (point-min) (point-max))
69 (goto-char (prog1 (point) (accept-process-output proc))))
72 (defconst canna-version-fmt "2.0:%s")
74 (defun cannarpc-open (proc username)
75 "Open the session. Return 0 on success, error code on failure."
76 (let ((verusr (format canna-version-fmt username)))
77 (comm-call-with-proc proc (result)
78 (comm-format (u u v) (canna-const Initialize) (length verusr) verusr)
79 (comm-unpack (u) result)
82 (defun cannarpc-close (proc)
83 (comm-call-with-proc proc (dummy result)
84 (comm-format (b b w) (canna-const Finalize) 0 0)
85 (comm-unpack (b b w b) dummy dummy dummy result)
88 (defun cannarpc-create-context (proc)
89 (comm-call-with-proc proc (dummy result)
90 (comm-format (b b w) (canna-const CreateContext) 0 0)
91 (comm-unpack (b b w w) dummy dummy dummy result)
94 (defun cannarpc-close-context (proc context)
95 (comm-call-with-proc proc (dummy result)
96 (comm-format (b b w w) (canna-const CloseContext) 0 2 context)
97 (comm-unpack (b b w b) dummy dummy dummy result)
100 ;; XXX: Not implemented fully
101 (defun cannarpc-get-dictionary-list (env)
102 (cannarpc-call-with-environment env (dymmy result)
103 (comm-format (b b w w w) (canna-const GetDictionaryList) 0 4
105 (comm-unpack (u w) dummy result)
106 ;; follow list of dictionaries
109 ;; XXX: Not implemented fully
110 (defun cannarpc-get-directory-list (env)
111 (cannarpc-call-with-environment env (dymmy result)
112 (comm-format (b b w w w) (canna-const GetDirectoryList) 0 4
114 (comm-unpack (u w) dummy result)
115 ;; follow list of directories
118 (defun cannarpc-open-dictionary (env dict-file-name mode)
119 (cannarpc-call-with-environment env (dymmy result)
120 (comm-format (b b w u w s) (canna-const MountDictionary) 0
121 (+ (length dict-file-name) 7)
122 mode context dict-file-name)
123 (comm-unpack (u b) dummy result)
126 (defun cannarpc-close-dictionary (env dict-file-name mode)
127 (cannarpc-call-with-environment env (dymmy result)
128 (comm-format (b b w u w s) (canna-const UnmountDictionary) 0
129 (+ (length dict-file-name) 6)
130 mode context dict-file-name)
131 (comm-unpack (u b) dummy result)
134 (defun cannarpc-begin-conversion (env yomi)
136 (let ((yomi-ext (encode-coding-string yomi 'euc-japan))
138 converted bunsetsu-list bl)
139 (cannarpc-call-with-environment env (dummy result)
140 (comm-format (b b w u w S) (canna-const BeginConvert) 0
141 (+ (length yomi-ext) 8) 0 context yomi)
142 (comm-unpack (u w) dummy result)
146 (comm-unpack (S) converted)
147 (let ((bl1 (cons (canna-make-bunsetsu env converted i)
150 (setq bl (setcdr bl bl1))
151 (setq bunsetsu-list (setq bl bl1))))
155 (defun cannarpc-end-conversion (env len zenkouho-pos-vector mode)
157 (cannarpc-call-with-environment env (dummy result)
158 (comm-format (b b w w w u v) (canna-const EndConvert) 0
159 (+ (* len 2) 8) context len mode zenkouho-pos-vector)
160 (comm-unpack (u b) dummy result)
165 (defun cannarpc-make-dictionary (env dict-name)
166 (cannarpc-call-with-environment env (dummy result)
167 (comm-format (b b w u w s) (canna-const CreateDictionary) 1
168 (+ (length dict-name) 7) 0 context dict-name)
169 (comm-unpack (u b) dummy result)
172 (defun cannarpc-get-bunsetsu-source (env bunsetsu-pos)
173 (cannarpc-call-with-environment env (dummy result)
174 (comm-format (b b w w w w) (canna-const GetYomi) 0 6 context
176 (comm-unpack (u w) dummy result)
179 (comm-unpack (S) result)
182 (defun cannarpc-get-bunsetsu-candidates (env bunsetsu-pos)
184 converted bunsetsu-list bl)
185 (cannarpc-call-with-environment env (dummy result)
186 (comm-format (b b w w w w) (canna-const GetCandidacyList) 0 6 context
188 (comm-unpack (u w) dymmy result)
192 (comm-unpack (S) converted)
193 (let ((bl1 (cons (canna-make-bunsetsu env converted bunsetsu-pos)
196 (setq bl (setcdr bl bl1))
197 (setq bunsetsu-list (setq bl bl1))))
201 ;;; egg/cannarpc.el ends here.