1 ;;; egg/wnnrpc.el --- WNN 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 ;; GNU Emacs 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 ;; GNU Emacs 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.
34 (load-library "egg/wnn")
35 (defmacro wnn-const (c)
36 "Macro for WNN constants."
37 (cond ((eq c 'JS_VERSION) 0)
40 ((eq c 'JS_CONNECT) 5)
41 ((eq c 'JS_DISCONNECT) 6)
42 ((eq c 'JS_ENV_EXIST) 7)
43 ((eq c 'JS_ENV_STICKY) 8)
44 ((eq c 'JS_ENV_UNSTICKY) 9)
45 ((eq c 'JS_KANREN) 17)
46 ((eq c 'JS_KANTAN_SHO) 18)
47 ((eq c 'JS_KANZEN_SHO) 19)
48 ((eq c 'JS_KANTAN_DAI) 20)
49 ((eq c 'JS_KANZEN_DAI) 21)
50 ((eq c 'JS_HINDO_SET) 24)
51 ((eq c 'JS_DIC_ADD) 33)
52 ((eq c 'JS_DIC_DELETE) 34)
53 ((eq c 'JS_DIC_USE) 35)
54 ((eq c 'JS_DIC_LIST) 36)
55 ((eq c 'JS_DIC_INFO) 37)
56 ((eq c 'JS_FUZOKUGO_SET) 41)
57 ((eq c 'JS_FUZOKUGO_GET) 48)
58 ((eq c 'JS_WORD_ADD) 49)
59 ((eq c 'JS_WORD_DELETE) 50)
60 ((eq c 'JS_WORD_SEARCH) 51)
61 ((eq c 'JS_WORD_SEARCH_BY_ENV) 52)
62 ((eq c 'JS_WORD_INFO) 53)
63 ((eq c 'JS_WORD_COMMENT_SET) 54)
64 ((eq c 'JS_PARAM_SET) 65)
65 ((eq c 'JS_PARAM_GET) 66)
67 ((eq c 'JS_ACCESS) 82)
69 ((eq c 'JS_ENV_LIST) 85)
70 ((eq c 'JS_FILE_LIST_ALL) 86)
71 ((eq c 'JS_DIC_LIST_ALL) 87)
72 ((eq c 'JS_FILE_READ) 97)
73 ((eq c 'JS_FILE_WRITE) 98)
74 ((eq c 'JS_FILE_SEND) 99)
75 ((eq c 'JS_FILE_RECEIVE) 100)
76 ((eq c 'JS_HINDO_FILE_CREATE) 101)
77 ((eq c 'JS_DIC_FILE_CREATE) 102)
78 ((eq c 'JS_FILE_REMOVE) 103)
79 ((eq c 'JS_FILE_LIST) 104)
80 ((eq c 'JS_FILE_INFO) 105)
81 ((eq c 'JS_FILE_LOADED) 106)
82 ((eq c 'JS_FILE_LOADED_LOCAL) 107)
83 ((eq c 'JS_FILE_DISCARD) 108)
84 ((eq c 'JS_FILE_COMMENT_SET) 109)
85 ((eq c 'JS_FILE_PASSWORD) 110)
86 ((eq c 'JS_FILE_STAT) 111)
88 ((eq c 'JS_HINSI_LIST) 114)
89 ((eq c 'JS_HINSI_NAME) 115)
90 ((eq c 'JS_HINSI_NUMBER) 116)
91 ((eq c 'JS_HINSI_DICTS) 117)
92 ((eq c 'JS_HINSI_TABLE_SET) 118)
94 ((eq c 'JLIB_VERSION) 16387) ; 0x4003
96 ((eq c 'WNN_REV_DICT) 3)
97 ((eq c 'WNN_VECT_NO) -1)
98 ((eq c 'WNN_VECT_BUNSETSU) 2)
99 ((eq c 'WNN_VECT_KANREN) 0)
100 ((eq c 'WNN_VECT_KANZEN) 1)
101 ((eq c 'WNN_VECT_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/%i%$%"%s%H$,FI$_9~$s$@%U%!%$%k$G$"$j$^$;$s
\e(B"
223 "
\e$B<-=q$KIQEY%U%!%$%k$,$D$$$F$$$^$;$s
\e(B"
224 "
\e$B%Q%9%o!<%I$N%U%!%$%k$,:n@.=PMh$^$;$s
\e(B"
226 "Array of WNN error messages. Indexed by error code.")
228 (defun wnnrpc-get-error-message (errno)
229 "Return error message string specified by ERRNO."
230 (or (aref wnnrpc-error-message errno) (format "#%d" errno)))
232 (defmacro wnnrpc-call-with-environment (e vlist send-expr &rest receive-exprs)
234 `((proc (wnnenv-get-proc ,e))
235 (env-id (wnnenv-get-env-id ,e)))
241 (set-buffer (process-buffer proc))
244 (process-send-region proc (point-min) (point-max))
245 (goto-char (prog1 (point) (accept-process-output proc))))
248 (defsubst wnnrpc-test-result-and-get-error (proc result)
249 (if (< result 0) ; Get error # (XXX: Bad protocol)
251 (comm-unpack (u) error)
255 (defun wnnrpc-open (proc myhostname username)
256 "Open the session. Return 0 on success, error code on failure."
257 (comm-call-with-proc proc (result)
258 (comm-format (u u s s)
260 (wnn-const JLIB_VERSION)
262 (comm-unpack (u) result)
263 (wnnrpc-test-result-and-get-error proc result)))
265 (defun wnnrpc-connect (proc envname)
266 "Establish new `connection' and make an environment.
267 Return the identitifation of the environment on success,
268 negate-encoded error code on failure."
269 (comm-call-with-proc proc (result)
270 (comm-format (u s) (wnn-const JS_CONNECT) envname)
271 (comm-unpack (u) result)
272 (wnnrpc-test-result-and-get-error proc result)))
274 (defun wnnrpc-open-file (proc env-id filename)
275 "Open the file FILENAME on the environment ENV-ID on server process PROC.
276 Return file descripter on success, negate-encoded error code on failure."
277 (comm-call-with-proc proc (result)
278 (comm-format (u u s) (wnn-const JS_FILE_READ) env-id filename)
279 (comm-unpack (u) result)
280 (wnnrpc-test-result-and-get-error proc result)))
282 (defun wnnrpc-set-fuzokugo-file (proc env-id fid)
283 "For PROC, on environment ENV-ID,
284 Set Fuzokugo file specified by FID.
285 Return 0 on success, negate-encoded error code on failure."
286 (comm-call-with-proc proc (result)
287 (comm-format (u u i) (wnn-const JS_FUZOKUGO_SET) env-id fid)
288 (comm-unpack (u) result)
289 (wnnrpc-test-result-and-get-error proc result)))
291 (defun wnnrpc-set-dictionary (proc env-id rev dic freq pri dic-mode freq-mode)
292 "Set dictionary on server.
293 Return 0 on success, negate-encoded error code on faiulure."
294 (comm-call-with-proc proc (result)
295 (comm-format (u u i i i u u s s u) (wnn-const JS_DIC_ADD)
299 "" "" ; XXX: No password
301 (comm-unpack (u) result)
302 (wnnrpc-test-result-and-get-error proc result)))
304 (defun wnnrpc-version (proc)
305 "Return the version number of WNN server."
306 (comm-call-with-proc proc (result)
307 (comm-format (u) (wnn-const JS_VERSION))
308 (comm-unpack (u) result)
311 (defun wnnrpc-access (proc env-id mode path)
312 "On the server connected by PROC, check the accessibility of file in
313 the environment ENV-ID. Return 0 when the remote file
314 (dictionary/frequency) of PATH can be accessed in mode MODE. Return
316 (comm-call-with-proc proc (result)
317 (comm-format (u u u s) (wnn-const JS_ACCESS) env-id mode path)
318 (comm-unpack (u) result)
321 (defun wnnrpc-mkdir (proc env-id path)
322 "Create directory specified by PATH."
323 (comm-call-with-proc proc (result)
324 (comm-format (u u s) (wnn-const JS_MKDIR) env-id path)
325 (comm-unpack (u) result)
326 (wnnrpc-test-result-and-get-error proc result)))
328 (defun wnnrpc-create-dictionary (proc env-id dicname)
329 "Create dictionary on server."
330 (comm-call-with-proc proc (result)
331 (comm-format (u u s S s s u) (wnn-const JS_DIC_FILE_CREATE)
332 env-id dicname "" ; XXX: No comment
333 "" "" ; XXX: No passwd
334 (wnn-const WNN_REV_DICT))
335 (comm-unpack (u) result)
336 (wnnrpc-test-result-and-get-error proc result)))
338 (defun wnnrpc-create-frequency (proc env-id freqname dictionary)
339 "Create frequency file on server."
340 (comm-call-with-proc proc (result)
341 (comm-format (u u u s S s) (wnn-const JS_HINDO_FILE_CREATE)
342 env-id dictionary freqname "" ; XXX: No comment
343 "") ; XXX: No password
344 (comm-unpack (u) result)
345 (wnnrpc-test-result-and-get-error proc result)))
347 (defun wnnrpc-discard-file (proc env-id fid)
348 "Discard a file specified by FID. Call this for already-opened file
349 before remove and create new file."
350 (comm-call-with-proc proc (result)
351 (comm-format (u u u) (wnn-const JS_FILE_DISCARD)
353 (comm-unpack (u) result)
354 (wnnrpc-test-result-and-get-error proc result)))
356 (defun wnnrpc-remove-file (proc filename)
358 (comm-call-with-proc proc (result)
359 (comm-format (u s s) (wnn-const JS_FILE_REMOVE) filename "") ; No passwd
360 (comm-unpack (u) result)
361 (wnnrpc-test-result-and-get-error proc result)))
363 (defun wnnrpc-set-conversion-parameters (proc env-id v)
364 "Set conversion parameters."
365 (comm-call-with-proc proc (result)
366 (comm-format (u u i i i i i i i i i i i i i i i i i)
367 (wnn-const JS_PARAM_SET)
369 (aref v 0) (aref v 1) (aref v 2) (aref v 3)
370 (aref v 4) (aref v 5) (aref v 6) (aref v 7)
371 (aref v 8) (aref v 9) (aref v 10) (aref v 11)
372 (aref v 12) (aref v 13) (aref v 14) (aref v 15)
373 (aref v 16) (aref v 17))
374 (comm-unpack (u) result)
375 (wnnrpc-test-result-and-get-error proc result)))
377 (defsubst wnnrpc-receive-sho-bunsetsu-list-sub (e proc number-of-sho-bunsetsu)
380 end start jiritsugo-end dic-no entry freq right-now
381 hinshi status status-backward kangovect evaluation)
382 (while (< i number-of-sho-bunsetsu)
383 (comm-unpack (u u u u u u u u u u u u)
384 end start jiritsugo-end dic-no entry freq right-now
385 hinshi status status-backward kangovect evaluation)
388 (wnn-bunsetsu-create e
389 end start jiritsugo-end dic-no entry freq right-now
390 hinshi status status-backward kangovect evaluation)
395 (defsubst wnnrpc-receive-sho-bunsetsu-list-sub-2 (proc slist)
397 result origin fuzokugo b)
400 (comm-unpack (S S S) result origin fuzokugo)
401 (wnn-bunsetsu-set-converted b result)
402 (wnn-bunsetsu-set-yomi b origin)
403 (wnn-bunsetsu-set-fuzokugo b fuzokugo)
407 (defun wnnrpc-receive-sho-bunsetsu-list (e proc number-of-sho-bunsetsu)
408 (let ((slist (wnnrpc-receive-sho-bunsetsu-list-sub e proc
409 number-of-sho-bunsetsu)))
410 (wnnrpc-receive-sho-bunsetsu-list-sub-2 proc slist)))
412 (defun wnnrpc-renbunsetsu-conversion (e yomi hinshi fuzoku &optional v)
413 "Convert YOMI string into Kanji.
414 HINSHI and FUZOKU are information of preceding bunsetsu."
418 v1 (wnn-const WNN_VECT_KANREN))
419 (setq v0 (wnn-const WNN_VECT_KANREN)
420 v1 (wnn-const WNN_VECT_NO)))
421 (wnnrpc-call-with-environment e (number-of-dai-bunsetsu kanji-length error
422 number-of-sho-bunsetsu dlist)
423 (comm-format (u u S i S i i i) (wnn-const JS_KANREN)
424 env-id yomi hinshi fuzoku v0 v1
425 (wnn-const WNN_VECT_BUNSETSU))
426 (comm-unpack (u) number-of-dai-bunsetsu)
427 (if (< number-of-dai-bunsetsu 0)
429 (comm-unpack (u) error)
430 (error "WNN Error on renbunsetsu conversion: %s"
431 (wnnrpc-get-error-message error)))
432 (comm-unpack (u u) number-of-sho-bunsetsu kanji-length)
433 (setq dlist (cons nil nil))
436 end start count evaluation)
439 (comm-unpack (u u u u) end start count evaluation)
440 (setcar d (vector end start count evaluation))
441 (if (< (setq i (1+ i)) number-of-dai-bunsetsu)
442 (setq d (setcdr d (cons nil nil)))
443 (throw 'break nil))))
445 (wnnrpc-receive-sho-bunsetsu-list e proc
446 number-of-sho-bunsetsu)))))))
448 (defun wnnrpc-get-bunsetsu-candidates (e yomi hinshi fuzoku &optional v)
453 v1 (wnn-const WNN_VECT_KANZEN))
454 (setq v0 (wnn-const WNN_VECT_KANZEN)
455 v1 (wnn-const WNN_VECT_NO)))
456 (wnnrpc-call-with-environment e (number-of-sho-bunsetsu kanji-length slist)
457 (comm-format (u u S i S i i) (wnn-const JS_KANZEN_SHO)
458 env-id yomi hinshi fuzoku v0 v1)
459 (comm-unpack (u) number-of-sho-bunsetsu)
460 (if (< number-of-sho-bunsetsu 0)
462 (comm-unpack (u) error)
463 (error "WNN Error on getting candidates: %s"
464 (wnnrpc-get-error-message error)))
465 (comm-unpack (u) kanji-length)
466 (wnnrpc-receive-sho-bunsetsu-list e proc number-of-sho-bunsetsu)))))
468 (defun wnnrpc-tanbunsetsu-conversion (e yomi hinshi fuzoku &optional v)
473 v1 (wnn-const WNN_VECT_KANTAN))
474 (setq v0 (wnn-const WNN_VECT_KANTAN)
475 v1 (wnn-const WNN_VECT_NO)))
476 (wnnrpc-call-with-environment e (number-of-sho-bunsetsu kanji-length slist)
477 (comm-format (u u S i S i i) (wnn-const JS_KANTAN_SHO)
478 env-id yomi hinshi fuzoku v0 v1)
479 (comm-unpack (u) number-of-sho-bunsetsu)
480 (if (< number-of-sho-bunsetsu 0) ; Get error # (XXX: Bad protocol)
482 (comm-unpack (u) error)
483 (error "WNN Error on tanbunsetsu conversion: %s"
484 (wnnrpc-get-error-message error)))
485 (comm-unpack (u) kanji-length)
486 (wnnrpc-receive-sho-bunsetsu-list e proc number-of-sho-bunsetsu)))))
488 (defun wnnrpc-set-frequency (e dicno entry ima hindo)
490 (wnnrpc-call-with-environment e (result)
491 (comm-format (u u i i i i) (wnn-const JS_HINDO_SET)
492 env-id dicno entry ima hindo)
493 (comm-unpack (u) result)
494 (wnnrpc-test-result-and-get-error proc result)))
496 (defun wnnrpc-close (proc)
498 (comm-call-with-proc proc (result)
499 (comm-format (u) (wnn-const JS_CLOSE))
500 (comm-unpack (u) result)
501 (wnnrpc-test-result-and-get-error proc result)))
503 (defun wnnrpc-env-exist (proc envname)
505 (comm-call-with-proc proc (result)
506 (comm-format (u s) (wnn-const JS_ENV_EXIST) envname)
507 (comm-unpack (u) result)
510 (defun wnnrpc-make-env-sticky (e)
512 (wnnrpc-call-with-environment e (result)
513 (comm-format (u u) (wnn-const JS_ENV_STICKY) env-id)
514 (comm-unpack (u) result)
515 (wnnrpc-test-result-and-get-error proc result)))
517 (defun wnnrpc-make-env-unsticky (e)
519 (wnnrpc-call-with-environment e (result)
520 (comm-format (u u) (wnn-const JS_ENV_UNSTICKY) env-id)
521 (comm-unpack (u) result)
522 (wnnrpc-test-result-and-get-error proc result)))
524 (defun wnnrpc-disconnect (e)
526 (wnnrpc-call-with-environment e (result)
527 (comm-format (u u) (wnn-const JS_DISCONNECT) env-id)
528 (comm-unpack (u) result)
529 (wnnrpc-test-result-and-get-error proc result)))
531 (defun wnnrpc-add-word (e dictionary yomi kanji comment hinshi initial-freq)
533 (wnnrpc-call-with-environment e (result)
534 (comm-format (u u u S S S u u) (wnn-const JS_WORD_ADD)
536 dictionary yomi kanji comment
538 (comm-unpack (u) result)
539 (wnnrpc-test-result-and-get-error proc result)))
541 (defun wnnrpc-get-dictionary-list-with-environment (e)
543 (wnnrpc-call-with-environment e (number-of-dic)
544 (comm-format (u u) (wnn-const JS_DIC_LIST) env-id)
545 (comm-unpack (u) number-of-dic)
546 (if (< number-of-dic 0)
547 (let (error) ; XXX js.c is correct?
548 (comm-unpack (u) error)
549 (error "WNN Error on listing dictionaries: %s"
550 (wnnrpc-get-error-message error)))
551 (wnnrpc-receive-dictionary-list proc number-of-dic))))
553 (defun wnnrpc-receive-dictionary-list (proc number-of-dic)
554 (let (dic-entry dic freq dic-mode freq-mode enable-flag nice
555 rev comment dicname freqname dic-passwd freq-passwd
556 type gosuu dic-local-flag freq-local-flag)
557 (if (= number-of-dic 0)
559 (comm-unpack (u u u u u u u u S s s s s u u u u)
560 dic-entry dic freq dic-mode freq-mode enable-flag nice
561 rev comment dicname freqname dic-passwd freq-passwd
562 type gosuu dic-local-flag freq-local-flag)
564 (vector dic-entry dic freq dic-mode freq-mode enable-flag nice
565 rev comment dicname freqname dic-passwd freq-passwd
566 type gosuu dic-local-flag freq-local-flag)
567 (wnnrpc-receive-dictionary-list proc (1- number-of-dic))))))
569 (defsubst wnndic-get-id (dic)
572 (defsubst wnndic-get-comment (dic)
575 (defsubst wnndic-get-dictname (dic)
578 (defun wnnrpc-get-writable-dictionary-id-list (e)
580 (wnnrpc-call-with-environment e (number-of-dic result)
581 (comm-format (u u i) (wnn-const JS_HINSI_DICTS) env-id -1)
582 (comm-unpack (u) number-of-dic)
583 (if (> number-of-dic 0)
584 (let ((l (cons nil nil))
590 (comm-unpack (u) dic)
592 (if (< (setq i (1+ i)) number-of-dic)
593 (setq l (setcdr l (cons nil nil)))
594 (throw 'break nil))))
596 (if (= number-of-dic 0)
599 (comm-unpack (u) error)
600 (error "WNN Error on listing dictionaries: %s"
601 (wnnrpc-get-error-message error)))))))
603 (defun wnnrpc-get-hinshi-list (e dic name)
605 (wnnrpc-call-with-environment e (number-of-hinshi size result)
606 (comm-format (u u u S) (wnn-const JS_HINSI_LIST) env-id dic name)
607 (comm-unpack (u u) number-of-hinshi size)
608 (if (> number-of-hinshi 0)
609 (let ((l (cons nil nil))
615 (comm-unpack (S) hinshi)
617 (if (< (setq i (1+ i)) number-of-hinshi)
618 (setq l (setcdr l (cons nil nil)))
619 (throw 'break nil))))
621 (if (= number-of-hinshi 0)
624 (comm-unpack (u) error)
625 (error "WNN Error on listing HINSHI: %s"
626 (wnnrpc-get-error-message error)))))))
628 (defun wnnrpc-hinshi-number (proc name)
630 (comm-call-with-proc proc (result)
631 (comm-format (u S) (wnn-const JS_HINSI_NUMBER) name)
632 (comm-unpack (u) result)
633 (wnnrpc-test-result-and-get-error proc result)))
635 (defun wnnrpc-get-conversion-parameters (e)
637 (wnnrpc-call-with-environment e (result
638 n nsho p1 p2 p3 p4 p5 p6 p7 p8 p9
639 p10 p11 p12 p13 p14 p15)
640 (comm-format (u u) (wnn-const JS_PARAM_GET) env-id)
641 (comm-unpack (u) result)
644 (comm-unpack (u) error)
646 (comm-unpack (u u u u u u u u u u u u u u u u u)
647 n nsho p1 p2 p3 p4 p5 p6 p7 p8 p9
648 p10 p11 p12 p13 p14 p15)
649 (vector n nsho p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15))))
651 (defun wnnrpc-file-loaded (proc path)
653 (comm-call-with-proc proc (result)
654 (comm-format (u s) (wnn-const JS_FILE_LOADED) path)
655 (comm-unpack (u) result)
658 (defun wnnrpc-write-file (e fid filename)
659 (wnnrpc-call-with-environment e (result)
660 (comm-format (u u u s) (wnn-const JS_FILE_WRITE) env-id fid filename)
661 (comm-unpack (u) result)
662 (wnnrpc-test-result-and-get-error proc result)))
664 (defun wnnrpc-get-fuzokugo-file (e)
666 (wnnrpc-call-with-environment e (result)
667 (comm-format (u u u) (wnn-const JS_FUZOKUGO_GET) env-id)
668 (comm-unpack (u) result)
669 (wnnrpc-test-result-and-get-error proc result)))
671 (defsubst wnnrpc-receive-file-list (proc)
674 number-of-files fid local-flag ref-count type name)
675 (comm-unpack (u) number-of-files)
676 (if (< number-of-files 0)
677 (error "WNN: wnnrpc-receive-file-list")
678 (while (< i number-of-files)
679 (comm-unpack (u u u u s) fid local-flag ref-count type name)
680 (setq flist (cons (vector fid local-flag ref-count type name) flist))
684 (defun wnnrpc-get-file-list (proc)
686 (comm-call-with-proc proc (result)
687 (comm-format (u) (wnn-const JS_FILE_LIST_ALL))
688 (wnnrpc-receive-file-list proc)))
690 (defun wnnrpc-get-file-list-with-env (e)
692 (wnnrpc-call-with-environment e (result)
693 (comm-format (u u) (wnn-const JS_FILE_LIST) env-id)
694 (wnnrpc-receive-file-list proc)))
696 (defun wnnrpc-file-attribute (e path)
697 "3: dictionary, 4: hindo file, 5: fuzokugo-file"
698 (wnnrpc-call-with-environment e (result)
699 (comm-format (u u s) (wnn-const JS_FILE_STAT) env-id path)
700 (comm-unpack (u) result)
701 (wnnrpc-test-result-and-get-error proc result)))
703 (defun wnnrpc-get-file-info (e fid)
705 (wnnrpc-call-with-environment e (result name local-flag ref-count type)
706 (comm-format (u u u) (wnn-const JS_FILE_INFO) env-id fid)
707 (comm-unpack (u) result)
710 (comm-unpack (u) error)
712 (comm-unpack (s u u u) name local-flag ref-count type)
713 (vector name local-flag ref-count type))))
715 (defun wnnrpc-who (proc)
717 (comm-call-with-proc proc (number-of-entry w)
718 (comm-format (u) (wnn-const JS_WHO))
719 (comm-unpack (u) number-of-entry)
720 (if (< number-of-entry 0)
722 (comm-unpack (u) error)
725 sd username hostname e-array)
726 (while (< i number-of-entry)
727 (comm-unpack (u s s) sd username hostname)
728 (setq e-array (make-vector 32 nil))
730 (while (< j (wnn-const WNN_MAX_ENV_OF_A_CLIENT))
734 (setq w (cons (vector sd username hostname e-array) w))
738 (defun wnnrpc-get-env-list (proc)
739 (comm-call-with-proc proc (number-of-entry l)
740 (comm-format (u) (wnn-const JS_ENV_LIST))
741 (comm-unpack (u) number-of-entry)
742 (if (< number-of-entry 0)
744 (comm-unpack (u) error)
747 env-id env-name ref-count fuzokugo-fid dic-max
748 dic-array file-array)
749 (while (< i number-of-entry)
750 (comm-unpack (u s u u u) env-id env-name ref-count
751 fuzokugo-fid dic-max)
752 (setq dic-array (make-vector 30 nil))
753 (setq file-array (make-vector 60 nil))
755 (while (< j (wnn-const WNN_MAX_DIC_OF_AN_ENV))
760 (while (< j (wnn-const WNN_MAX_FILE_OF_AN_ENV))
762 (aset file-array j f)
764 (setq l (cons (vector env-id env-name ref-count fuzokugo-fid dic-max
765 dic-array file-array) l))
769 (defun wnnrpc-kill (proc)
771 (comm-call-with-proc proc (result)
772 (comm-format (u) (wnn-const JS_KILL))
773 (comm-unpack (u) result)
774 result)) ; XXX: Bad protocol: error?
776 (defun wnnrpc-delete-dictionary (e dic)
778 (wnnrpc-call-with-environment e (result)
779 (comm-format (u u u) (wnn-const JS_DIC_DELETE) env-id dic)
780 (comm-unpack (u) result)
781 (wnnrpc-test-result-and-get-error proc result)))
783 (defun wnnrpc-set-flag-on-dictionary (e dic flag)
785 (wnnrpc-call-with-environment e (result)
786 (comm-format (u u u u) (wnn-const JS_DIC_USE) env-id dic flag)
787 (comm-unpack (u) result)
788 (wnnrpc-test-result-and-get-error proc result)))
790 (defun wnnrpc-get-dictionary-list (proc)
792 (comm-call-with-proc proc (number-of-dic)
793 (comm-format (u) (wnn-const JS_DIC_LIST_ALL))
794 (comm-unpack (u) number-of-dic)
795 (wnnrpc-receive-dictionary-list proc number-of-dic)))
797 (defun wnnrpc-delete-word (e dic entry)
799 (wnnrpc-call-with-environment e (result)
800 (comm-format (u u u u) (wnn-const JS_WORD_DELETE) env-id dic entry)
801 (comm-unpack (u) result)
802 (wnnrpc-test-result-and-get-error proc result)))
804 (defun wnnrpc-receive-word (proc yomi)
806 dic serial hinshi hindo right-now internal-hindo internal-right-now
809 (comm-unpack (u) dic)
812 (comm-unpack (u u u u u u) serial hinshi hindo right-now
813 internal-hindo internal-right-now)
814 (setq l (cons (vector dic serial hinshi hindo right-now
815 internal-hindo internal-right-now
820 (comm-unpack (S S) kanji comment)
821 (aset (car l1) 8 kanji)
822 (aset (car l1) 9 comment)
826 (defun wnnrpc-search-word-in-dictionary (e dic yomi)
828 (wnnrpc-call-with-environment e (c0 c1)
829 (comm-format (u u u S) (wnn-const JS_WORD_SEARCH) env-id dic yomi)
830 ;; XXX Bad protocol: error?
831 (comm-unpack (u u) c0 c1) ; ignored
832 (wnnrpc-receive-word proc yomi)))
834 (defun wnnrpc-search-word (e yomi)
836 (wnnrpc-call-with-environment e (c0 c1)
837 (comm-format (u u S) (wnn-const JS_WORD_SEARCH_BY_ENV) env-id yomi)
838 ;; XXX Bad protocol: error?
839 (comm-unpack (u u) c0 c1) ; ignored
840 (wnnrpc-receive-word proc yomi)))
842 (defun wnnrpc-get-word-info (e dic entry)
844 (wnnrpc-call-with-environment e (result c0 c1 yomi)
845 (comm-format (u u u u) (wnn-const JS_WORD_INFO) env-id dic entry)
846 (comm-unpack (u) result)
849 (comm-unpack (u) error)
851 (comm-unpack (S) yomi) ; XXX: reversed string
852 (comm-unpack (u u) c0 c1) ; ignored
853 (wnnrpc-receive-word proc yomi))))
855 (defun wnnrpc-set-comment-on-word (e dic entry comment)
857 (wnnrpc-call-with-environment e (result)
858 (comm-format (u u u u S) (wnn-const JS_WORD_COMMENT_SET)
859 env-id dic entry comment)
860 (comm-unpack (u) result)
861 (wnnrpc-test-result-and-get-error proc result)))
863 (defun wnnrpc-get-dictionary-info (e dic)
865 (wnnrpc-call-with-environment e (result)
866 (comm-format (u u u) (wnn-const JS_DIC_INFO) env-id dic)
867 (comm-unpack (u) result)
870 (comm-unpack (u) error)
872 (wnnrpc-receive-dictionary-list proc 1))))
874 (defun wnnrpc-set-file-comment (e fid comment)
876 (wnnrpc-call-with-environment e (result)
877 (comm-format (u u u S) (wnn-const JS_FILE_COMMENT_SET) env-id fid comment)
878 (comm-unpack (u) result)
879 (wnnrpc-test-result-and-get-error proc result)))
881 (defun wnnrpc-hinshi-name (proc hinshi)
883 (comm-call-with-proc proc (result)
884 (comm-format (u u) (wnn-const JS_HINSI_NAME) hinshi)
885 (comm-unpack (u) result)
888 (comm-unpack (u) error)
890 (comm-unpack (S) result)
893 ;;; WHICH: 1: DIC, 2: HINDO, 3(0): Both
894 (defun wnnrpc-set-file-password (e fid which old new)
896 (wnnrpc-call-with-environment e (result)
897 (comm-format (u u u u s s) (wnn-const JS_FILE_PASSWORD)
898 env-id fid which old new)
899 (comm-unpack (u) result)
900 (wnnrpc-test-result-and-get-error proc result)))
902 (defun wnnrpc-set-hinshi-table (e dic hinshi-table)
904 (wnnrpc-call-with-environment e (result)
905 (comm-format (u u u S) (wnn-const JS_HINSI_TABLE_SET)
906 env-id dic hinshi-table)
907 (comm-unpack (u) result)
908 (wnnrpc-test-result-and-get-error proc result)))
910 (defsubst wnnrpc-receive-dai-bunsetsu-list (proc number-of-bunsetsu)
913 end start number-of-sho-bunsetsu evaluation v)
914 (while (< i number-of-bunsetsu)
915 (comm-unpack (u u u u)
916 end start number-of-sho-bunsetsu evaluation)
918 (cons (vector end start number-of-sho-bunsetsu evaluation nil)
921 (setq slist (reverse slist))
926 (setq result (wnnrpc-receive-sho-bunsetsu-list-sub-2 proc (aref v 2)))
932 (wnnrpc-receive-sho-bunsetsu-list-sub-2 proc (aref v 4))
936 (defun wnnrpc-daibunsetsu-conversion (e yomi hinshi fuzoku &optional v)
941 v1 (wnn-const WNN_VECT_KANTAN))
942 (setq v0 (wnn-const WNN_VECT_KANTAN)
943 v1 (wnn-const WNN_VECT_NO)))
944 (wnnrpc-call-with-environment e (number-of-bunsetsu sho-size kanji-size)
945 (comm-format (u u S i S i i) (wnn-const JS_KANTAN_DAI)
946 env-id yomi hinshi fuzoku v0 v1)
947 (comm-unpack (u) number-of-bunsetsu)
948 (if (< number-of-bunsetsu 0) ; Get error # (XXX: Bad protocol)
950 (comm-unpack (u) error)
951 (error "WNN Error on daibunsetsu conversion: %s"
952 (wnnrpc-get-error-message error)))
953 (comm-unpack (u u) sho-size kanji-size)
954 (wnnrpc-receive-dai-bunsetsu-list proc number-of-bunsetsu)))))
956 (defun wnnrpc-get-daibunsetsu-candidate (e yomi hinshi fuzoku &optional v)
961 v1 (wnn-const WNN_VECT_KANZEN))
962 (setq v0 (wnn-const WNN_VECT_KANZEN)
963 v1 (wnn-const WNN_VECT_NO)))
964 (wnnrpc-call-with-environment e (number-of-bunsetsu sho-size kanji-size)
965 (comm-format (u u S i S i i) (wnn-const JS_KANZEN_DAI)
966 env-id yomi hinshi fuzoku v0 v1)
967 (comm-unpack (u) number-of-bunsetsu)
968 (if (< number-of-bunsetsu 0) ; Get error # (XXX: Bad protocol)
970 (comm-unpack (u) error)
971 (error "WNN Error on daibunsetsu conversion: %s"
972 (wnnrpc-get-error-message error)))
973 (comm-unpack (u u) sho-size kanji-size)
974 (wnnrpc-receive-dai-bunsetsu-list proc number-of-bunsetsu)))))
976 ;; XXX: NIY: check in the file contents
978 (defun wnnrpc-local-file-loaded (proc path)
980 (let ((attr (file-attributes path)))
981 (let ((time (cons (car (nth 6 attr)) (car (cdr (nth 6 attr)))))
982 (inode (nth 10 attr))
986 (concat (system-name)
987 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0") 0 16)))
988 (comm-call-with-proc proc (result)
989 (comm-format (u U U U s) (wnn-const JS_FILE_LOADED_LOCAL)
990 time dev inode padded-hostname)
991 (comm-unpack (u) result)
994 (defun wnnrpc-file-receive (e fid local-filename)
996 (wnnrpc-call-with-environment e (filename)
997 (comm-format (u u u) (wnn-const JS_FILE_RECEIVE)
999 (comm-unpack (s) filename)
1000 (if (null local-filename)
1001 (setq local-filename (substring filename
1002 (1+ (string-match "!" filename)))))
1003 (wnnrpc-file-receive-sub proc local-filename)))
1005 (defun wnnrpc-file-receive-sub (proc local-filename)
1006 ;; XXX check file header
1007 (let ((attr (file-attributes local-filename)))
1008 (let ((time (cons (car (nth 6 attr)) (car (cdr (nth 6 attr)))))
1009 (inode (nth 10 attr))
1013 (concat (system-name)
1014 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0") 0 16)))
1015 (comm-call-with-proc-1 proc (result)
1016 (comm-format (u U U U s) 0 ; ACK
1017 time dev inode padded-hostname)
1018 (comm-unpack (s) result)
1021 (comm-unpack (u) error)
1025 ((or (= result 1) (= result 3) (= result 2))
1026 ;; XXX distingush creation...
1027 (comm-call-with-proc-1 proc (contents result)
1028 (comm-format (u) 0) ; ACK
1029 (comm-unpack (B u) contents result)
1030 ;; XXX XXXXXXXXXXXXXXXXX save the contents...
1031 (wnnrpc-test-result-and-get-error proc result))))))))
1033 (defun wnnrpc-file-send (e filename)
1035 (wnnrpc-call-with-environment e (result)
1036 (comm-format (u u U U U s) (wnn-const JS_FILE_SEND)
1037 env-id time dev inode padded-hostname)
1038 (comm-unpack (u) result)
1041 (comm-unpack (u) result)
1044 (comm-unpack (u) error)
1047 (comm-unpack (u) result)
1050 (comm-unpack (u) error)
1052 (let ((path (concat (system-name) "!" filename)))
1053 (wnnrpc-send-file-sub proc path))))))
1055 (defun wnnrpc-send-file-sub (proc path)
1056 (comm-call-with-proc-1 proc (result)
1058 (comm-format (s) path)
1059 ;; XXXXXXXXXXXXXX send the contents of file...
1062 (comm-format (b b) 255 0)
1063 (comm-format (b) c)))
1064 (comm-format (b b) 255 255))
1065 (comm-unpack (u) result)
1066 (wnnrpc-test-result-and-get-error proc result)))
1068 (defun wnnrpc-file-remove-client ()
1071 (defun wnnrpc-dic-file-create-client ()
1074 (defun wnnrpc-hindo-file-create-client ()
1078 ;;; egg/wnnrpc.el ends here.