1 ;;; egg/sj3rpc.el --- SJ3 Support (low level interface) in Egg
2 ;;; 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.
36 ;; Only support SJ3 version 2.
40 ;; (load-library "egg/sj3")
41 (defmacro sj3-const (c)
42 (cond ((eq c 'OPEN) 1)
47 ((eq c 'CLOSESTDY) 22)
52 ((eq c 'BEGIN_EUC) 111)
54 ((eq c 'TANCONV_EUC) 112)
56 ((eq c 'KOUHO_EUC) 115)
58 ((eq c 'KOUHOSU_EUC) 116)
61 ((eq c 'CLSTDY_EUC) 117)
63 ((eq c 'WREG_EUC) 118)
65 ((eq c 'WDEL_EUC) 119)
71 ((eq c 'WSCH_EUC) 120)
73 ((eq c 'WNSCH_EUC) 121)
75 (t (error "No such constant")))))
78 (defconst sj3rpc-error-message (vector ))
80 (defun sj3rpc-get-error-message (errno)
82 (< errno (length sj3rpc-error-message))
83 (aref sj3rpc-error-message errno))
84 (format "#%d" errno)))
86 (defmacro sj3rpc-call-with-environment (e vlist send-expr &rest receive-exprs)
88 `((proc (sj3env-get-proc ,e)))
94 (set-buffer (process-buffer proc))
97 (process-send-region proc (point-min) (point-max))
98 (goto-char (prog1 (point) (accept-process-output proc))))
101 (defun sj3rpc-open (proc myhostname username)
102 "Open the session. Return 0 on success, error code on failure."
103 (comm-call-with-proc proc (result)
104 (comm-format (u u s s s) (sj3-const OPEN) 2 ; Server version
107 (format "%d.emacs-egg" (emacs-pid)))
108 (comm-unpack (u) result)
113 (defun sj3rpc-close (proc)
114 (comm-call-with-proc proc (result)
115 (comm-format (u) (sj3-const CLOSE))
116 (comm-unpack (u) result)
119 (defun sj3rpc-get-stdy-size (proc)
120 "Return STDYSIZE of SJ3 server. On failure, return error code."
121 (comm-call-with-proc proc (result)
122 (comm-format (u) (sj3-const STDYSIZE))
123 (comm-unpack (u) result)
126 (comm-unpack (u) result)
129 (defsubst sj3rpc-get-stdy (proc)
131 (stdy (make-vector sj3-stdy-size 0)))
132 (while (< n sj3-stdy-size)
138 (defun sj3rpc-begin (env yomi)
140 (let ((yomi-ext (encode-coding-string yomi 'euc-japan))
142 len source converted stdy bunsetsu-list bl)
143 (sj3rpc-call-with-environment env (result)
144 (comm-format (u s) (sj3-const BEGIN_EUC) yomi-ext)
145 (comm-unpack (u) result)
148 (comm-unpack (u) result) ; skip
150 (comm-unpack (b) len)
152 (setq stdy (sj3rpc-get-stdy proc))
153 (comm-unpack (E) converted)
155 (decode-coding-string (substring yomi-ext p (+ p len))
158 (let ((bl1 (cons (sj3-make-bunsetsu env
159 source converted nil stdy) nil)))
161 (setq bl (setcdr bl bl1))
162 (setq bunsetsu-list (setq bl bl1)))))
165 (defun sj3rpc-open-dictionary (proc dict-file-name password)
166 (comm-call-with-proc proc (result)
167 (comm-format (u s s) (sj3-const DICADD) dict-file-name password)
168 (comm-unpack (u) result)
171 (comm-unpack (u) result)
174 (defun sj3rpc-close-dictionary (proc dict-no)
175 (comm-call-with-proc proc (result)
176 (comm-format (u u) (sj3-const DICDEL) dict-no)
177 (comm-unpack (u) result)
180 (defun sj3rpc-make-dictionary (proc dict-name)
181 (comm-call-with-proc proc (result)
182 (comm-format (u s u u u) (sj3-const MKDIC) dict-name
187 (comm-unpack (u) result)
190 (defun sj3rpc-open-stdy (proc stdy-name)
191 (comm-call-with-proc proc (result)
192 (comm-format (u s s) (sj3-const OPENSTDY) stdy-name "")
193 (comm-unpack (u) result)
196 (defun sj3rpc-close-stdy (proc)
197 (comm-call-with-proc proc (result)
198 (comm-format (u) (sj3-const CLOSESTDY))
199 (comm-unpack (u) result)
202 (defun sj3rpc-make-stdy (proc stdy-name)
203 (comm-call-with-proc proc (result)
204 (comm-format (u s u u u) (sj3-const MKSTDY) stdy-name
209 (comm-unpack (u) result)
212 (defun sj3rpc-make-directory (proc name)
213 (comm-call-with-proc proc (result)
214 (comm-format (u s) (sj3-const MKDIR) name)
215 (comm-unpack (u) result)
218 (defun sj3rpc-get-bunsetsu-candidates-sub (proc env yomi yomi-ext len n)
220 stdy converted bunsetsu bl bunsetsu-list cylen rest)
221 (comm-call-with-proc-1 proc (result)
222 (comm-format (u u s) (sj3-const KOUHO_EUC) len yomi-ext)
223 (comm-unpack (u) result)
227 (comm-unpack (u) cylen)
228 (setq stdy (sj3rpc-get-stdy proc))
229 (comm-unpack (E) converted)
230 (setq rest (decode-coding-string
231 (substring yomi-ext cylen) 'euc-japan))
232 (setq bunsetsu (sj3-make-bunsetsu env yomi converted rest stdy))
234 (setq bl (setcdr bl (cons bunsetsu nil)))
235 (setq bunsetsu-list (setq bl (cons bunsetsu nil))))
237 (setq bunsetsu (sj3-make-bunsetsu env yomi yomi nil nil))
238 (setq bl (setcdr bl (cons bunsetsu nil)))
240 (sj3-make-bunsetsu env yomi (japanese-katakana yomi) nil nil))
241 (setq bl (setcdr bl (cons bunsetsu nil)))
244 (defun sj3rpc-get-bunsetsu-candidates (env yomi)
245 (let* ((yomi-ext (encode-coding-string yomi 'euc-japan))
246 (len (length yomi-ext)))
247 (sj3rpc-call-with-environment env (result)
248 (comm-format (u u s) (sj3-const KOUHOSU_EUC) len yomi-ext)
249 (comm-unpack (u) result)
252 (comm-unpack (u) result)
254 (list (sj3-make-bunsetsu env yomi yomi nil nil)) ; XXX
255 (sj3rpc-get-bunsetsu-candidates-sub proc env
256 yomi yomi-ext len result))))))
258 (defun sj3rpc-tanbunsetsu-conversion (env yomi)
259 (let* ((yomi-ext (encode-coding-string yomi 'euc-japan))
260 (len (length yomi-ext)) cylen stdy converted rest)
261 (sj3rpc-call-with-environment env (result)
262 (comm-format (u u s) (sj3-const TANCONV_EUC) len yomi-ext)
263 (comm-unpack (u) result)
266 (comm-unpack (u) cylen)
267 (setq stdy (sj3rpc-get-stdy proc))
268 (comm-unpack (E) converted)
269 (setq rest (decode-coding-string
270 (substring yomi-ext cylen) 'euc-japan))
271 (setq bunsetsu (sj3-make-bunsetsu env yomi converted rest stdy))))))
273 (defun sj3rpc-bunsetsu-stdy (env stdy)
274 (sj3rpc-call-with-environment env (result)
275 (comm-format (u v) (sj3-const STDY) stdy (length stdy))
276 (comm-unpack (u) result)
281 (defun sj3rpc-kugiri-stdy (env yomi1 yomi2 stdy)
282 (let* ((yomi1-ext (encode-coding-string yomi1 'euc-japan))
283 (yomi2-ext (encode-coding-string yomi2 'euc-japan)))
284 (sj3rpc-call-with-environment env (result)
285 (comm-format (u s s v) (sj3-const CLSTDY_EUC)
286 yomi1-ext yomi2-ext stdy (length stdy))
287 (comm-unpack (u) result)
292 ;;; egg/sj3rpc.el ends here.