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")))))
73 (defun sj3rpc-get-error-message (errno)
74 (or (aref sj3rpc-error-message errno) (format "#%d" errno)))
76 (defmacro sj3rpc-call-with-environment (e vlist send-expr &rest receive-exprs)
78 `((proc (sj3env-get-proc ,e)))
84 (set-buffer (process-buffer proc))
87 (process-send-region proc (point-min) (point-max))
88 (goto-char (prog1 (point) (accept-process-output proc))))
91 (defun sj3rpc-open (proc myhostname username)
92 "Open the session. Return 0 on success, error code on failure."
93 (comm-call-with-proc proc (result)
94 (comm-format (u u s s s) (sj3-const OPEN) 2 ; Server version
97 (format "%d.emacs-egg" (emacs-pid)))
98 (comm-unpack (u) result)
103 (defun sj3rpc-get-stdy-size (proc)
104 "Return STDYSIZE of SJ3 server. On failure, return error code."
105 (comm-call-with-proc proc (result)
106 (comm-format (u) (sj3-const STDYSIZE))
107 (comm-unpack (u) result)
110 (comm-unpack (u) result)
113 (defsubst sj3rpc-get-stdy (proc)
115 (stdy (make-vector sj3-stdy-size 0)))
116 (while (< n sj3-stdy-size)
122 (defun sj3rpc-begin (env yomi)
124 (let ((yomi-ext (encode-coding-string yomi 'euc-japan))
126 len source converted stdy bunsetsu-list bl)
127 (sj3rpc-call-with-environment env (result)
128 (comm-format (u s) (sj3-const BEGIN_EUC) yomi-ext)
129 (comm-unpack (u) result)
132 (comm-unpack (u) result) ; skip
134 (comm-unpack (b) len)
136 (setq stdy (sj3rpc-get-stdy proc))
137 (comm-unpack (E) converted)
139 (decode-coding-string (substring yomi-ext p (+ p len))
142 (let ((bl1 (cons (sj3-make-bunsetsu env
143 source converted nil stdy) nil)))
145 (setq bl (setcdr bl bl1))
146 (setq bunsetsu-list (setq bl bl1)))))
149 (defun sj3rpc-open-dictionary (proc dict-file-name password)
150 (comm-call-with-proc proc (result)
151 (comm-format (u s s) (sj3-const DICADD) dict-file-name password)
152 (comm-unpack (u) result)
155 (comm-unpack (u) result)
158 (defun sj3rpc-close-dictionary (proc dict-no)
159 (comm-call-with-proc proc (result)
160 (comm-format (u u) (sj3-const DICDEL) dict-no)
161 (comm-unpack (u) result)
164 (defun sj3rpc-make-dictionary (proc dict-name)
165 (comm-call-with-proc proc (result)
166 (comm-format (u s u u u) (sj3-const MKDIC) dict-name
170 (comm-unpack (u) result)
173 (defun sj3rpc-open-stdy (proc stdy-name)
174 (comm-call-with-proc proc (result)
175 (comm-format (u s s) (sj3-const OPENSTDY) stdy-name "")
176 (comm-unpack (u) result)
179 (defun sj3rpc-close-stdy (proc)
180 (comm-call-with-proc proc (result)
181 (comm-format (u) (sj3-const CLOSESTDY))
182 (comm-unpack (u) result)
185 (defun sj3rpc-make-stdy (proc stdy-name)
186 (comm-call-with-proc proc (result)
187 (comm-format (u) (sj3-const MKSTDY) stdy-name "")
191 (comm-unpack (u) result)
194 (defun sj3rpc-get-bunsetsu-candidates-sub (proc env yomi yomi-ext len n)
196 stdy converted bunsetsu bl bunsetsu-list cylen rest)
197 (comm-call-with-proc-1 proc (result)
198 (comm-format (u u s) (sj3-const KOUHO_EUC) len yomi-ext)
199 (comm-unpack (u) result)
203 (comm-unpack (u) cylen)
204 (setq stdy (sj3rpc-get-stdy proc))
205 (comm-unpack (E) converted)
206 (setq rest (decode-coding-string
207 (substring yomi-ext cylen) 'euc-japan))
208 (setq bunsetsu (sj3-make-bunsetsu env yomi converted rest stdy))
210 (setq bl (setcdr bl (cons bunsetsu nil)))
211 (setq bunsetsu-list (setq bl (cons bunsetsu nil))))
215 (defun sj3rpc-get-bunsetsu-candidates (env yomi)
216 (let* ((yomi-ext (encode-coding-string yomi 'euc-japan))
217 (len (length yomi-ext)))
218 (sj3rpc-call-with-environment env (result)
219 (comm-format (u u s) (sj3-const KOUHOSU_EUC) len yomi-ext)
220 (comm-unpack (u) result)
223 (comm-unpack (u) result)
225 (list (sj3-make-bunsetsu env yomi yomi nil nil)) ; XXX
226 (sj3rpc-get-bunsetsu-candidates-sub proc env
227 yomi yomi-ext len result))))))
229 (defun sj3rpc-tanbunsetsu-conversion (env yomi)
230 (let* ((yomi-ext (encode-coding-string yomi 'euc-japan))
231 (len (length yomi-ext)) cylen stdy converted rest)
232 (sj3rpc-call-with-environment env (result)
233 (comm-format (u u s) (sj3-const TANCONV_EUC) len yomi-ext)
234 (comm-unpack (u) result)
237 (comm-unpack (u) cylen)
238 (setq stdy (sj3rpc-get-stdy proc))
239 (comm-unpack (E) converted)
240 (setq rest (decode-coding-string
241 (substring yomi-ext cylen) 'euc-japan))
242 (setq bunsetsu (sj3-make-bunsetsu env yomi converted rest stdy))))))
244 ;;; egg/sj3rpc.el ends here.