1 ;;; egg/sj3.el --- SJ3 Support (low level interface) in Egg
2 ;;; Input Method Architecture
4 ;; Copyright (C) 1997 Mule Project, Powered by Electrotechnical
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 GNU Emacs (in future).
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)
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-get-stdy-size (proc)
110 "Return STDYSIZE of SJ3 server. On failure, return error code."
111 (comm-call-with-proc proc (result)
112 (comm-format (u) (sj3-const STDYSIZE))
113 (comm-unpack (u) result)
116 (comm-unpack (u) result)
119 (defsubst sj3rpc-get-stdy (proc)
121 (stdy (make-vector sj3-stdy-size 0)))
122 (while (< n sj3-stdy-size)
128 (defun sj3rpc-begin (env yomi)
130 (let ((yomi-ext (encode-coding-string yomi 'euc-japan))
132 len source converted stdy bunsetsu-list bl)
133 (sj3rpc-call-with-environment env (result)
134 (comm-format (u s) (sj3-const BEGIN_EUC) yomi-ext)
135 (comm-unpack (u) result)
138 (comm-unpack (u) result) ; skip
140 (comm-unpack (b) len)
142 (setq stdy (sj3rpc-get-stdy proc))
143 (comm-unpack (E) converted)
145 (decode-coding-string (substring yomi-ext p (+ p len))
148 (let ((bl1 (cons (sj3-make-bunsetsu env
149 source converted nil stdy) nil)))
151 (setq bl (setcdr bl bl1))
152 (setq bunsetsu-list (setq bl bl1)))))
155 (defun sj3rpc-open-dictionary (proc dict-file-name password)
156 (comm-call-with-proc proc (result)
157 (comm-format (u s s) (sj3-const DICADD) dict-file-name password)
158 (comm-unpack (u) result)
161 (comm-unpack (u) result)
164 (defun sj3rpc-close-dictionary (proc dict-no)
165 (comm-call-with-proc proc (result)
166 (comm-format (u u) (sj3-const DICDEL) dict-no)
167 (comm-unpack (u) result)
170 (defun sj3rpc-make-dictionary (proc dict-name)
171 (comm-call-with-proc proc (result)
172 (comm-format (u s u u u) (sj3-const MKDIC) dict-name
176 (comm-unpack (u) result)
179 (defun sj3rpc-open-stdy (proc stdy-name)
180 (comm-call-with-proc proc (result)
181 (comm-format (u s s) (sj3-const OPENSTDY) stdy-name "")
182 (comm-unpack (u) result)
185 (defun sj3rpc-close-stdy (proc)
186 (comm-call-with-proc proc (result)
187 (comm-format (u) (sj3-const CLOSESTDY))
188 (comm-unpack (u) result)
191 (defun sj3rpc-make-stdy (proc stdy-name)
192 (comm-call-with-proc proc (result)
193 (comm-format (u) (sj3-const MKSTDY) stdy-name "")
197 (comm-unpack (u) result)
200 (defun sj3rpc-get-bunsetsu-candidates-sub (proc env yomi yomi-ext len n)
202 stdy converted bunsetsu bl bunsetsu-list cylen rest)
203 (comm-call-with-proc-1 proc (result)
204 (comm-format (u u s) (sj3-const KOUHO_EUC) len yomi-ext)
205 (comm-unpack (u) result)
209 (comm-unpack (u) cylen)
210 (setq stdy (sj3rpc-get-stdy proc))
211 (comm-unpack (E) converted)
212 (setq rest (decode-coding-string
213 (substring yomi-ext cylen) 'euc-japan))
214 (setq bunsetsu (sj3-make-bunsetsu env yomi converted rest stdy))
216 (setq bl (setcdr bl (cons bunsetsu nil)))
217 (setq bunsetsu-list (setq bl (cons bunsetsu nil))))
221 (defun sj3rpc-get-bunsetsu-candidates (env yomi)
222 (let* ((yomi-ext (encode-coding-string yomi 'euc-japan))
223 (len (length yomi-ext)))
224 (sj3rpc-call-with-environment env (result)
225 (comm-format (u u s) (sj3-const KOUHOSU_EUC) len yomi-ext)
226 (comm-unpack (u) result)
229 (comm-unpack (u) result)
231 (list (sj3-make-bunsetsu env yomi yomi nil nil)) ; XXX
232 (sj3rpc-get-bunsetsu-candidates-sub proc env
233 yomi yomi-ext len result))))))
235 (defun sj3rpc-tanbunsetsu-conversion (env yomi)
236 (let* ((yomi-ext (encode-coding-string yomi 'euc-japan))
237 (len (length yomi-ext)) cylen stdy converted rest)
238 (sj3rpc-call-with-environment env (result)
239 (comm-format (u u s) (sj3-const TANCONV_EUC) len yomi-ext)
240 (comm-unpack (u) result)
243 (comm-unpack (u) cylen)
244 (setq stdy (sj3rpc-get-stdy proc))
245 (comm-unpack (E) converted)
246 (setq rest (decode-coding-string
247 (substring yomi-ext cylen) 'euc-japan))
248 (setq bunsetsu (sj3-make-bunsetsu env yomi converted rest stdy))))))
250 ;;; egg/sj3rpc.el ends here.