1 ;;; egg/sj3rpc.el --- SJ3 Support (low level interface) in Egg
2 ;;; 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 will be 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.
32 ;; Only support SJ3 version 2.
36 ;; (load-library "egg/sj3")
37 (defmacro sj3-const (c)
38 (cond ((eq c 'OPEN) 1)
43 ((eq c 'CLOSESTDY) 22)
48 ((eq c 'BEGIN_EUC) 111)
50 ((eq c 'TANCONV_EUC) 112)
52 ((eq c 'KOUHO_EUC) 115)
54 ((eq c 'KOUHOSU_EUC) 116)
57 ((eq c 'CLSTDY_EUC) 117)
59 ((eq c 'WREG_EUC) 118)
61 ((eq c 'WDEL_EUC) 119)
67 ((eq c 'WSCH_EUC) 120)
69 ((eq c 'WNSCH_EUC) 121)
71 (t (error "No such constant")))))
74 (defconst sj3rpc-error-message (vector ))
76 (defun sj3rpc-get-error-message (errno)
78 (< errno (length sj3rpc-error-message))
79 (aref sj3rpc-error-message errno))
80 (format "#%d" errno)))
82 (defmacro sj3rpc-call-with-environment (e vlist send-expr &rest receive-exprs)
84 `((proc (sj3env-get-proc ,e)))
90 (set-buffer (process-buffer proc))
93 (process-send-region proc (point-min) (point-max))
94 (goto-char (prog1 (point) (accept-process-output proc))))
97 (defun sj3rpc-open (proc myhostname username)
98 "Open the session. Return 0 on success, error code on failure."
99 (comm-call-with-proc proc (result)
100 (comm-format (u u s s s) (sj3-const OPEN) 2 ; Server version
103 (format "%d.emacs-egg" (emacs-pid)))
104 (comm-unpack (u) result)
109 (defun sj3rpc-close (proc)
110 (comm-call-with-proc proc (result)
111 (comm-format (u) (sj3-const CLOSE))
112 (comm-unpack (u) result)
115 (defun sj3rpc-get-stdy-size (proc)
116 "Return STDYSIZE of SJ3 server. On failure, return error code."
117 (comm-call-with-proc proc (result)
118 (comm-format (u) (sj3-const STDYSIZE))
119 (comm-unpack (u) result)
122 (comm-unpack (u) result)
125 (defsubst sj3rpc-get-stdy (proc)
127 (stdy (make-vector sj3-stdy-size 0)))
128 (while (< n sj3-stdy-size)
134 (defun sj3rpc-begin (env yomi)
136 (let ((yomi-ext (encode-coding-string yomi 'euc-japan))
138 len source converted stdy bunsetsu-list bl)
139 (sj3rpc-call-with-environment env (result)
140 (comm-format (u s) (sj3-const BEGIN_EUC) yomi-ext)
141 (comm-unpack (u) result)
144 (comm-unpack (u) result) ; skip
146 (comm-unpack (b) len)
148 (setq stdy (sj3rpc-get-stdy proc))
149 (comm-unpack (E) converted)
151 (decode-coding-string (substring yomi-ext p (+ p len))
154 (let ((bl1 (cons (sj3-make-bunsetsu env
155 source converted nil stdy) nil)))
157 (setq bl (setcdr bl bl1))
158 (setq bunsetsu-list (setq bl bl1)))))
161 (defun sj3rpc-open-dictionary (proc dict-file-name password)
162 (comm-call-with-proc proc (result)
163 (comm-format (u s s) (sj3-const DICADD) dict-file-name password)
164 (comm-unpack (u) result)
167 (comm-unpack (u) result)
170 (defun sj3rpc-close-dictionary (proc dict-no)
171 (comm-call-with-proc proc (result)
172 (comm-format (u u) (sj3-const DICDEL) dict-no)
173 (comm-unpack (u) result)
176 (defun sj3rpc-make-dictionary (proc dict-name)
177 (comm-call-with-proc proc (result)
178 (comm-format (u s u u u) (sj3-const MKDIC) dict-name
183 (comm-unpack (u) result)
186 (defun sj3rpc-open-stdy (proc stdy-name)
187 (comm-call-with-proc proc (result)
188 (comm-format (u s s) (sj3-const OPENSTDY) stdy-name "")
189 (comm-unpack (u) result)
192 (defun sj3rpc-close-stdy (proc)
193 (comm-call-with-proc proc (result)
194 (comm-format (u) (sj3-const CLOSESTDY))
195 (comm-unpack (u) result)
198 (defun sj3rpc-make-stdy (proc stdy-name)
199 (comm-call-with-proc proc (result)
200 (comm-format (u s u u u) (sj3-const MKSTDY) stdy-name
205 (comm-unpack (u) result)
208 (defun sj3rpc-make-directory (proc name)
209 (comm-call-with-proc proc (result)
210 (comm-format (u s) (sj3-const MKDIR) name)
211 (comm-unpack (u) result)
214 (defun sj3rpc-get-bunsetsu-candidates-sub (proc env yomi yomi-ext len n)
216 stdy converted bunsetsu bl bunsetsu-list cylen rest)
217 (comm-call-with-proc-1 proc (result)
218 (comm-format (u u s) (sj3-const KOUHO_EUC) len yomi-ext)
219 (comm-unpack (u) result)
223 (comm-unpack (u) cylen)
224 (setq stdy (sj3rpc-get-stdy proc))
225 (comm-unpack (E) converted)
226 (setq rest (decode-coding-string
227 (substring yomi-ext cylen) 'euc-japan))
228 (setq bunsetsu (sj3-make-bunsetsu env yomi converted rest stdy))
230 (setq bl (setcdr bl (cons bunsetsu nil)))
231 (setq bunsetsu-list (setq bl (cons bunsetsu nil))))
233 (setq bunsetsu (sj3-make-bunsetsu env yomi yomi nil nil))
234 (setq bl (setcdr bl (cons bunsetsu nil)))
236 (sj3-make-bunsetsu env yomi (japanese-katakana yomi) nil nil))
237 (setq bl (setcdr bl (cons bunsetsu nil)))
240 (defun sj3rpc-get-bunsetsu-candidates (env yomi)
241 (let* ((yomi-ext (encode-coding-string yomi 'euc-japan))
242 (len (length yomi-ext)))
243 (sj3rpc-call-with-environment env (result)
244 (comm-format (u u s) (sj3-const KOUHOSU_EUC) len yomi-ext)
245 (comm-unpack (u) result)
248 (comm-unpack (u) result)
250 (list (sj3-make-bunsetsu env yomi yomi nil nil)) ; XXX
251 (sj3rpc-get-bunsetsu-candidates-sub proc env
252 yomi yomi-ext len result))))))
254 (defun sj3rpc-tanbunsetsu-conversion (env yomi)
255 (let* ((yomi-ext (encode-coding-string yomi 'euc-japan))
256 (len (length yomi-ext)) cylen stdy converted rest)
257 (sj3rpc-call-with-environment env (result)
258 (comm-format (u u s) (sj3-const TANCONV_EUC) len yomi-ext)
259 (comm-unpack (u) result)
262 (comm-unpack (u) cylen)
263 (setq stdy (sj3rpc-get-stdy proc))
264 (comm-unpack (E) converted)
265 (setq rest (decode-coding-string
266 (substring yomi-ext cylen) 'euc-japan))
267 (setq bunsetsu (sj3-make-bunsetsu env yomi converted rest stdy))))))
269 (defun sj3rpc-bunsetsu-stdy (env stdy)
270 (sj3rpc-call-with-environment env (result)
271 (comm-format (u v) (sj3-const STDY) stdy)
272 (comm-unpack (u) result)
277 (defun sj3rpc-kugiri-stdy (env yomi1 yomi2 stdy)
278 (let* ((yomi1-ext (encode-coding-string yomi1 'euc-japan))
279 (yomi2-ext (encode-coding-string yomi2 'euc-japan)))
280 (sj3rpc-call-with-environment env (result)
281 (comm-format (u s s v) (sj3-const CLSTDY_EUC) yomi1-ext yomi2-ext stdy)
282 (comm-unpack (u) result)
287 ;;; egg/sj3rpc.el ends here.