1 ;;; egg/sj3.el --- SJ3 Support (high 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 (defconst sj3-support-languages '("Japanese"))
34 (defconst sj3-conversion-backend
38 sj3-get-bunsetsu-converted
39 sj3-get-bunsetsu-source
41 sj3-get-number-of-candidates
42 sj3-get-current-candidate-number
43 sj3-get-all-candidates
45 sj3-change-bunsetsu-length
52 (defvar sj3-server-port 3000 "Port number of SJ3 server")
53 (defvar sj3-stdy-size 0 "STDYSIZE of SJ3 server")
54 (defvar sj3-hostname "localhost"
55 "Hostname of SJ3 server")
57 (defvar sj3-open-message)
59 (defun sj3-open (hostname-list)
60 "Establish the connection to SJ3 server. Return process object."
61 (let* ((buf (generate-new-buffer " *SJ3*"))
62 (msg-form "SJ3: connecting to sj3serv at %s...")
63 hostname proc result msg)
68 (setq enable-multibyte-characters nil))
71 (setq hostname-list '("localhost")))
72 ((null (listp hostname-list))
73 (setq hostname-list (list hostname-list))))
74 (while (and hostname-list (null proc))
75 (setq hostname (car hostname-list)
76 hostname-list (cdr hostname-list))
77 (message msg-form hostname)
79 (condition-case result
80 (setq proc (open-network-stream "SJ3" buf hostname sj3-server-port))
84 (process-kill-without-query proc)
85 (set-process-coding-system proc 'no-conversion 'no-conversion)
86 (set-marker-insertion-type (process-mark proc) t)
87 ;; Initialize dictionaries
88 (setq sj3-sys-dict-list nil)
89 (setq sj3-user-dict-list nil)
90 (setq result (sj3rpc-open proc (system-name) (user-login-name)))
95 msg (format "Can't open SJ3 session (%s): %s"
97 (setq result (sj3rpc-get-stdy-size proc))
100 (delete-process proc)
102 msg (format "Can't get SJ3 STDYSIZE: %s"
103 (sj3rpc-get-error-message (- result)))))
104 (setq sj3-stdy-size result))))))
107 (setq sj3-open-message (format (concat msg-form "done") hostname))
110 (error "%s" (or msg "no sj3serv available")))))
112 ;; <env> ::= [ <proc> <dictionary-list> ]
113 (defvar sj3-environment nil
114 "Environment for SJ3 kana-kanji conversion")
116 (defsubst sj3env-get-proc (env)
118 (defsubst sj3env-get-dictionary-list (env)
122 ;; [ <env> <source> <converted> <rest>
123 ;; <stdy> <zenkouho> <zenkouho-pos> <stdy-down> ]
124 (defsubst sj3-make-bunsetsu (env source converted rest stdy)
125 (vector env source converted rest stdy nil nil nil))
127 (defsubst sj3bunsetsu-get-env (b)
129 (defsubst sj3bunsetsu-get-source (b)
131 (defsubst sj3bunsetsu-get-converted (b)
133 (defsubst sj3bunsetsu-get-rest (b)
135 (defsubst sj3bunsetsu-get-stdy (b)
137 (defsubst sj3bunsetsu-get-zenkouho (b)
139 (defsubst sj3bunsetsu-set-zenkouho (b z)
141 (defsubst sj3bunsetsu-get-zenkouho-pos (b)
143 (defsubst sj3bunsetsu-set-zenkouho-pos (b p)
145 (defsubst sj3bunsetsu-get-stdydown (b)
147 (defsubst sj3bunsetsu-set-stdydown (b s)
150 (defun sj3-get-bunsetsu-source (b)
151 (sj3bunsetsu-get-source b))
152 (defun sj3-get-bunsetsu-converted (b)
153 (concat (sj3bunsetsu-get-converted b)
154 (sj3bunsetsu-get-rest b)))
155 (defun sj3-get-bunsetsu-stdy (b)
156 (sj3bunsetsu-get-stdy b))
158 (defvar sj3-dictionary-specification
161 [("private.dic") ""])
162 "Dictionary specification of SJ3.")
164 (defvar sj3-usr-dic-dir (concat "user/" (user-login-name))
165 "*Directory of user dictionary for SJ3.")
167 (defun sj3-filename (p)
169 (cond ((consp p) (concat sj3-usr-dic-dir "/" (car p)))
172 (defun sj3-get-environment ()
175 (let* ((proc (sj3-open sj3-hostname))
176 (stdy (sj3-filename (car sj3-dictionary-specification)))
177 (l (cdr sj3-dictionary-specification))
179 (if (/= (sj3rpc-open-stdy proc stdy) 0)
180 (error "Dame1") ; XXX
185 (sj3rpc-open-dictionary proc (sj3-filename (aref dic 0))
188 (error "Dame2") ; XXX
189 (setq dict-list (cons dic-id dict-list)
191 (message "%s" sj3-open-message)
192 (setq sj3-environment (vector proc dict-list))))))
197 (defun sj3-start-conversion (yomi &optional lang)
198 "Convert YOMI string to kanji, and enter conversion mode.
199 Return the list of bunsetsu."
200 (let ((env (sj3-get-environment)))
201 (sj3rpc-begin env yomi)))
203 ;; XXX: not implemented yet
204 (defun sj3-end-conversion (bunsetsu-list)
207 (defun sj3-list-candidates (bunsetsu prev-bunsetsu)
208 (let* ((env (sj3bunsetsu-get-env bunsetsu))
209 (yomi (sj3bunsetsu-get-source bunsetsu))
210 (z (sj3rpc-get-bunsetsu-candidates env yomi)))
211 (sj3bunsetsu-set-zenkouho bunsetsu z)
212 (sj3bunsetsu-set-zenkouho-pos bunsetsu 0)
215 (defun sj3-get-number-of-candidates (bunsetsu)
216 (let ((l (sj3bunsetsu-get-zenkouho bunsetsu)))
221 (defun sj3-decide-candidate (bunsetsu candidate-pos)
222 (let* ((candidate-list (sj3bunsetsu-get-zenkouho bunsetsu))
223 (candidate (nth candidate-pos candidate-list)))
224 (sj3bunsetsu-set-zenkouho candidate candidate-list)
225 (sj3bunsetsu-set-zenkouho-pos candidate candidate-pos)
228 (defun sj3-get-current-candidate-number (bunsetsu)
229 (sj3bunsetsu-get-zenkouho-pos bunsetsu))
231 (defun sj3-get-all-candidates (bunsetsu)
232 (let* ((l (sj3bunsetsu-get-zenkouho bunsetsu))
233 (result (cons nil nil))
237 (let ((candidate (car l)))
238 (setcar r (sj3bunsetsu-get-converted candidate))
239 (if (null (setq l (cdr l)))
241 (setq r (setcdr r (cons nil nil)))))))
244 (defun sj3-change-bunsetsu-length (b0 b1 b2 len)
246 (sj3bunsetsu-get-source b1)
247 (if b2 (sj3bunsetsu-get-source b2))))
248 (env (sj3bunsetsu-get-env b1))
251 (setq yomi1 (substring yomi 0 len)
252 yomi2 (substring yomi len))
254 (sj3rpc-tanbunsetsu-conversion env yomi1))
256 (sj3bunsetsu-set-stdydown bunsetsu1
257 (or (sj3bunsetsu-get-stdydown b1)
261 (if (< 0 (length yomi2))
262 (setq bunsetsu2 (sj3rpc-tanbunsetsu-conversion env yomi2))
263 (setq bunsetsu2 nil))
265 (list bunsetsu1 bunsetsu2)
268 ;; XXX: Not implemented yet
269 (defun sj3-fini (lang)
278 (defun egg-activate-sj3 (&rest arg)
279 "Activate SJ3 backend of Tamagotchy."
280 (egg-set-support-languages sj3-support-languages)
281 (egg-set-conversion-backend sj3-conversion-backend
282 sj3-support-languages)
283 (apply 'egg-mode arg))
285 ;;; egg/sj3.el ends here.