Revision: 6075
Author: iratqq
Date: Fri Nov 20 02:25:44 2009
Log: * scm/cannav3-socket.scm:
  - New file.
* scm/Makefile.am (SCM_FILES):
  - Add cannav3-socket.scm.
* scm/canna.scm:
  - Use cannav3-socket.scm.
* uim/Makefile.am:
  - Remove CANNA.
* uim/canna.c
  - Bye bye.

http://code.google.com/p/uim/source/detail?r=6075

Added:
 /trunk/scm/cannav3-socket.scm
Deleted:
 /trunk/uim/canna.c
Modified:
 /trunk/scm/Makefile.am
 /trunk/scm/canna.scm
 /trunk/uim/Makefile.am

=======================================
--- /dev/null
+++ /trunk/scm/cannav3-socket.scm       Fri Nov 20 02:25:44 2009
@@ -0,0 +1,343 @@
+;;; cannav3-socket.scm: Canna protocol version 3 for uim.
+;;;
+;;; Copyright (c) 2009- uim Project http://code.google.com/p/uim/
+;;;
+;;; All rights reserved.
+;;;
+;;; Redistribution and use in source and binary forms, with or without
+;;; modification, are permitted provided that the following conditions
+;;; are met:
+;;; 1. Redistributions of source code must retain the above copyright
+;;;    notice, this list of conditions and the following disclaimer.
+;;; 2. Redistributions in binary form must reproduce the above copyright
+;;;    notice, this list of conditions and the following disclaimer in the
+;;;    documentation and/or other materials provided with the distribution.
+;;; 3. Neither the name of authors nor the names of its contributors
+;;; may be used to endorse or promote products derived from this software
+;;;    without specific prior written permission.
+;;;
+;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +;;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE +;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+;;; SUCH DAMAGE.
+;;;;
+
+(use srfi-1)
+(require "socket.scm")
+(require "lolevel.scm")
+
+(define (canna-var&user-fmt user)
+  (format "3.3:~a" user))
+
+(define (canna-lib-make-s16-list l)
+  (apply
+   append
+   (map (lambda (p)
+          (u8list-pack '(s16) p))
+        (append l (list "")))))
+
+(define (canna-lib-initialize socket user)
+  (define initialize-op #x1)
+  (let* ((canna-var&user (canna-var&user-fmt user))
+         (canna-var&user-len (+ 1 (string-length canna-var&user))))
+    (file-write socket
+                (u8list->string-buf
+                 (u8list-pack '(u32 u32 s8)
+ initialize-op canna-var&user-len canna-var&user)))
+    (call-with-u8list-unpack
+     '(u16 u16) (string-buf->u8list (file-read socket 4))
+     (lambda (major minor)
+       (not (and (= major 65535) (= major 65535)))))))
+
+(define (canna-lib-finalize socket)
+  (define finalize-op #x2)
+  (file-write socket
+              (u8list->string-buf
+               (u8list-pack '(u8 u8 u16)
+                            finalize-op 0 0)))
+  (call-with-u8list-unpack
+   '(u32 u8) (string-buf->u8list (file-read socket 5))
+        (lambda (dummy result)
+          (= result 0))))
+
+(define (canna-lib-create-context socket)
+  (define create-context-op #x3)
+  (file-write socket
+              (u8list->string-buf
+               (u8list-pack '(u8 u8 u16)
+                            create-context-op 0 0)))
+  (call-with-u8list-unpack
+   '(u32 u16) (string-buf->u8list (file-read socket 6))
+   (lambda (dummy context-id)
+     (and (not (= context-id 65535))
+          context-id))))
+
+(define (canna-lib-close-context socket context-id)
+  (define close-context-op #x5)
+  (file-write socket
+              (u8list->string-buf
+               (u8list-pack '(u8 u8 u16 u16)
+                            close-context-op 0 2 context-id)))
+  (call-with-u8list-unpack
+   '(u32 u8) (string-buf->u8list (file-read socket 5))
+   (lambda (dummy result)
+     (not (= result 255)))))
+
+(define (canna-lib-get-dictionary-list socket context-id)
+  (define get-dictionary-list-op #x6)
+  (file-write socket
+              (u8list->string-buf
+               (u8list-pack '(u8 u8 u16 u16 u16)
+                            get-dictionary-list-op 0 4 context-id 1024)))
+  (call-with-u8list-unpack
+   '(u32 u16) (string-buf->u8list (file-read socket 6))
+   (lambda (dummy result)
+     (and (not (= result 65535))
+          (call-with-u8list-unpack
+ (make-list result 's8) (string-buf->u8list (file-read socket 1024))
+           (lambda dict-list
+             dict-list))))))
+
+(define (canna-lib-mount-dictionary socket context-id dict mode)
+  (define mount-dictionary-op #x8)
+  (file-write socket
+              (u8list->string-buf
+               (u8list-pack '(u8 u8 u16 u32 u16 s8)
+                            mount-dictionary-op
+                            0
+                            (+ (string-length dict) 7)
+                            mode context-id dict)))
+  (call-with-u8list-unpack
+   '(u32 u8) (string-buf->u8list (file-read socket 5))
+   (lambda (dummy result)
+     (not (= result 255)))))
+
+(define (canna-lib-unmount-dictionary socket context-id dict mode)
+  (define unmount-dictionary-op #x9)
+  (file-write socket
+              (u8list->string-buf
+               (u8list-pack '(u8 u8 u16 u32 u16 s8)
+                            unmount-dictionary-op
+                            0
+                            (+ (string-length dict) 7)
+                            mode context-id dict)))
+  (call-with-u8list-unpack
+   '(u32 u8) (string-buf->u8list (file-read socket 5))
+   (lambda (dummy result)
+     (not (= result 255)))))
+
+(define (canna-lib-begin-convert socket context-id yomi mode)
+  (define begin-convert-op #xf)
+  (file-write socket
+              (u8list->string-buf
+               (u8list-pack '(u8 u8 u16 u32 u16 s16)
+                            begin-convert-op
+                            0
+                            (+ (string-length yomi) 8)
+                            mode context-id yomi)))
+  (call-with-u8list-unpack
+   '(u16 u16 u16) (string-buf->u8list (file-read socket 6))
+   (lambda (dummy len bunsetsu)
+     (and (not (= bunsetsu 65535))
+          (call-with-u8list-unpack
+ (make-list bunsetsu 's16) (string-buf->u8list (file-read socket len))
+           (lambda conv
+             conv))))))
+
+(define (canna-lib-end-convert socket context-id cands mode)
+  (define end-convert-op #x10)
+  (file-write socket
+              (u8list->string-buf
+               (u8list-pack '(u8 u8 u16 u16 u16 u32 u16list)
+                            end-convert-op
+                            0
+                            (+ (* 2 (length cands)) 8)
+                            context-id (length cands) mode
+                            cands)))
+  (call-with-u8list-unpack
+   '(u32 u8) (string-buf->u8list (file-read socket 5))
+   (lambda (dummy result)
+     (not (= result 255)))))
+
+(define (canna-lib-get-candidacy-list socket context-id bunsetsu-pos)
+  (define get-candidacy-list-op #x11)
+  (file-write socket
+              (u8list->string-buf
+               (u8list-pack '(u8 u8 u16 u16 u16 u16)
+                            get-candidacy-list-op
+                            0
+                            6
+                            context-id bunsetsu-pos 1024)))
+  (call-with-u8list-unpack
+   '(u16 u16 u16) (string-buf->u8list (file-read socket 6))
+   (lambda (dummy len cands)
+     (call-with-u8list-unpack
+      (make-list cands 's16) (string-buf->u8list (file-read socket len))
+      (lambda cand-list
+        cand-list)))))
+
+(define (canna-lib-get-yomi socket context-id bunsetsu-pos)
+  (define get-yomi-op #x12)
+  (file-write socket
+              (u8list->string-buf
+               (u8list-pack '(u8 u8 u16 u16 u16 u16)
+                            get-yomi-op
+                            0
+                            6
+                            context-id bunsetsu-pos 1024)))
+  (call-with-u8list-unpack
+   '(u16 u16 u16) (string-buf->u8list (file-read socket 6))
+   (lambda (dummy len yomi-len)
+     (call-with-u8list-unpack
+      '(s16) (string-buf->u8list (file-read socket len))
+      (lambda (conv)
+        conv)))))
+
+(define (canna-lib-resize-pause socket context-id yomi-length bunsetsu-pos)
+  (define resize-pause-op #x1a)
+  (file-write socket
+              (u8list->string-buf
+               (u8list-pack '(u8 u8 u16 u16 u16 u16)
+                            resize-pause-op
+                            0
+                            6
+                            context-id bunsetsu-pos yomi-length)))
+  (call-with-u8list-unpack
+   '(u16 u16 u16) (string-buf->u8list (file-read socket 6))
+   (lambda (dummy len bunsetsu)
+     (and (not (= bunsetsu 65535))
+          (call-with-u8list-unpack
+ (make-list bunsetsu 's16) (string-buf->u8list (file-read socket len))
+           (lambda conv
+             (take conv (- bunsetsu bunsetsu-pos))))))))
+
+;;
+;; RK compatible functions
+;;
+(define canna-lib-context-rec-spec
+  (list
+   (list 'id   #f)
+   (list 'mode 0)
+   (list 'nostudy #f)
+   (list 'cands '())
+   (list 'nth-cands '#())
+   (list 'dic-list '())))
+(define-record 'canna-lib-context canna-lib-context-rec-spec)
+(define canna-lib-context-new-internal canna-lib-context-new)
+
+(define *canna-lib-socket* #f)
+(define *canna-lib-context-list* '())
+(define canna-lib-cannaserver #f)
+
+(define (canna-lib-open-with-server server)
+  (if canna-server-name
+      (tcp-connect server "canna")
+      (unix-domain-socket-connect "/tmp/.iroha_unix/IROHA")))
+
+(define (canna-lib-init server)
+  (set! canna-lib-cannaserver server)
+  (and (not *canna-lib-socket*)
+       (let ((s (canna-lib-open-with-server server)))
+         (and s
+              (begin
+                (canna-lib-initialize s (user-name))
+                (set! *canna-lib-socket* s)
+                #t)))))
+
+(define (canna-lib-alloc-context)
+  (if (and (not *canna-lib-socket*)
+           (not (canna-lib-init canna-lib-cannaserver)))
+      (begin
+        (uim-notify-fatal (N_ "Initialize failed."))
+        #f)
+      (and-let* ((cic (canna-lib-context-new-internal))
+                 (id (canna-lib-create-context *canna-lib-socket*))
+                 (dic-list (canna-lib-context-set-dic-list!
+                            cic
+ (canna-lib-get-dictionary-list *canna-lib-socket* id)))
+                 (mode 19))  ;; XXX: (RK_XFER << RK_XFERBITS) | RK_KFER
+        (canna-lib-context-set-id! cic id)
+        (canna-lib-context-set-mode! cic mode)
+        (map (lambda (dict)
+               (canna-lib-mount-dictionary *canna-lib-socket* id dict 0))
+             dic-list)
+        (set! *canna-lib-context-list*
+              (cons cic *canna-lib-context-list*))
+        cic)))
+
+(define (canna-lib-release-context cic)
+ (set! *canna-lib-context-list* (delete! cic *canna-lib-context-list* equal?))
+  (canna-lib-close-context *canna-lib-socket*
+                           (canna-lib-context-id cic)))
+
+(define (canna-lib-begin-conversion cic str)
+  (let ((cands (canna-lib-begin-convert *canna-lib-socket*
+                                        (canna-lib-context-id cic)
+                                        str
+                                        (canna-lib-context-mode cic))))
+    (canna-lib-context-set-cands! cic cands)
+    (canna-lib-context-set-nth-cands! cic (make-vector (length cands) 0))
+    (length cands)))
+
+(define (canna-lib-get-nth-candidate cic seg nth)
+  (vector-set! (canna-lib-context-nth-cands cic) seg nth)
+  (list-ref (canna-lib-get-candidacy-list *canna-lib-socket*
+                                          (canna-lib-context-id cic)
+                                          seg)
+            nth))
+
+(define (canna-lib-get-unconv-candidate cic seg)
+ (canna-lib-context-set-nth-cands! cic (vector-set! (canna-lib-context-nth-cands cic) seg 0))
+  (canna-lib-get-yomi *canna-lib-socket*
+                      (canna-lib-context-id cic)
+                      seg))
+
+(define (canna-lib-resize-segment cic seg delta)
+  (let* ((direct (if (< 0 delta)
+                    -1
+                    -2))
+         (new-cands (canna-lib-resize-pause *canna-lib-socket*
+ (canna-lib-context-id cic) direct seg))
+         (len (length new-cands))
+         (new-nth-cands (make-vector (+ seg len) 0)))
+    ;; save unconverted segments
+    (for-each (lambda (n)
+                (vector-set! new-nth-cands
+                             n
+ (vector-ref (canna-lib-context-nth-cands cic) n)))
+              (iota seg))
+    (canna-lib-context-set-cands! cic new-cands)
+    (canna-lib-context-set-nth-cands! cic new-nth-cands)
+    #t))
+
+(define (canna-lib-get-nr-segments cic)
+  (vector-length (canna-lib-context-nth-cands cic)))
+
+(define (canna-lib-get-nr-candidates cic seg)
+  (length (canna-lib-get-candidacy-list *canna-lib-socket*
+                                        (canna-lib-context-id cic)
+                                        seg)))
+
+(define (canna-lib-commit-segment cic seg nth)
+  (let ((nth-cands (vector->list (canna-lib-context-nth-cands cic)))
+        (learn (if (canna-lib-context-nostudy cic)
+                   0
+                   1)))
+    (canna-lib-end-convert *canna-lib-socket*
+                           (canna-lib-context-id cic)
+                           nth-cands
+                           learn)))
+
+(define (canna-lib-reset-conversion cic)
+  (let ((nth-cands (vector->list (canna-lib-context-nth-cands cic))))
+    (canna-lib-end-convert *canna-lib-socket*
+                           (canna-lib-context-id cic)
+                           nth-cands
+                           0)))
=======================================
--- /trunk/uim/canna.c  Tue Jan 20 18:11:15 2009
+++ /dev/null
@@ -1,448 +0,0 @@
-/*
-  $Id:$
-
-  canna.c: Canna for uim.
-
-  Copyright (c) 2003-2009 uim Project http://code.google.com/p/uim/
-
-  All rights reserved.
-
-  Redistribution and use in source and binary forms, with or without
-  modification, are permitted provided that the following conditions
-  are met:
-
-  1. Redistributions of source code must retain the above copyright
-     notice, this list of conditions and the following disclaimer.
-  2. Redistributions in binary form must reproduce the above copyright
-     notice, this list of conditions and the following disclaimer in the
-     documentation and/or other materials provided with the distribution.
-  3. Neither the name of authors nor the names of its contributors
-     may be used to endorse or promote products derived from this software
-     without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
-  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-  SUCH DAMAGE.
-*/
-
-#include <config.h>
-
-#ifdef HAVE_CANNA_RK_H
-#include <canna/RK.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <assert.h>
-
-#include "uim.h"
-#include "uim-scm.h"
-#include "uim-scm-abbrev.h"
-#include "uim-notify.h"
-#include "gettext.h"
-#include "dynlib.h"
-
-#if 0
-#define UIM_CANNA_DEBUG
-#endif
-
-#define BUFSIZE 1024
-
-#define VALID_CANNA_CONTEXTP(cc)    ((cc) && (cc)->rk_context_id != -1)
-#define VALID_SEGMENT_INDEXP(cc, i) (0 <= (i) && (i) < cc->segment_num)
-
-enum canna_api_result {
-  ERR = -1,
-  OK  = 0
-};
-
-enum learning_mode {
-  FORGET_SELECTED_CAND = 0,
-  LEARN_SELECTED_CAND  = 1
-};
-
-struct canna_context {
-#ifdef UIM_CANNA_DEBUG
-  char *diclist;
-#endif
-
-  int rk_context_id;
-  int rk_mode;
-
-  int *max_cand_num_list;
-  int segment_num;
-};
-
-static int rk_initialized = -1;
-static char *cannaserver = NULL;
-static uim_lisp context_list;
-
-
-static struct canna_context *
-get_canna_context(uim_lisp cc_)
-{
-  struct canna_context *cc;
-
-  cc = C_PTR(cc_);
-  if (!cc)
-    uim_fatal_error("NULL canna_context");
-  assert(cc->rk_context_id != -1);
-#ifdef UIM_CANNA_DEBUG
-  printf("rk_context_id: %d\n", cc->rk_context_id);
-  printf("segment_num: %d\n", cc->segment_num);
-#endif
-
-  return cc;
-}
-
-static void
-validate_segment_index(struct canna_context *cc, int i)
-{
-  assert(VALID_CANNA_CONTEXTP(cc));
-  if (!VALID_SEGMENT_INDEXP(cc, i))
-    ERROR_OBJ("invalid segment index", MAKE_INT(i));
-}
-
-static uim_lisp
-init_canna_lib(uim_lisp str_)
-{
-  cannaserver = (TRUEP(str_)) ? C_STR(str_) : NULL;
-
-  /* Immediate init & quit to test cannaserver connectivity? Real
-   * initialization is exist at beginning of create_context(). I don't
-   * know why this sequence is needed at here.  -- YamaKen 2007-07-21 */
-  if (rk_initialized == -1) {
-    if (RkInitialize(cannaserver) == ERR) {
-      uim_notify_fatal("RkInitialize() failed");
-      return uim_scm_f();
-    }
-    RkFinalize();
-  }
-
-  return uim_scm_t();
-}
-
-static uim_lisp
-create_context(void)
-{
-  struct canna_context *cc;
-  uim_lisp cc_;
-  int dic_num;
-  char *diclist, *buf;
-  int buflen, i;
-
-  if (rk_initialized == -1) {
-    if (RkInitialize(cannaserver) == ERR) {
-      uim_notify_fatal("RkInitialize() failed");
-      return uim_scm_f();
-    }
-    rk_initialized = 1;
-  }
-
-  cc = uim_malloc(sizeof(*cc));
-  cc->rk_context_id = RkCreateContext();
-  if (cc->rk_context_id == ERR) {
-    free(cc);
-    RkFinalize();
-    rk_initialized = -1;
-    uim_notify_fatal("RkCreateContext() failed");
-    return uim_scm_f();
-  }
-
-  cc->rk_mode = (RK_XFER << RK_XFERBITS) | RK_KFER;
-  cc->max_cand_num_list = NULL;
-  cc->segment_num = -1;
-
-  diclist = uim_malloc(BUFSIZE);
-  diclist[0] = '\0';
-
-  dic_num = RkGetDicList(cc->rk_context_id, diclist, BUFSIZE);
-  if (dic_num == ERR) {
-    /* invalid context number */
-    uim_fatal_error("RkGetDicList() failed");
-  }
-
-  /* buf[] = "dicname1\0dicname2\0dicname3\0...dicname_n\0\0" */
-  buf = diclist;
-  for (i = 0; i < dic_num; i++) {
-    if (RkMountDic(cc->rk_context_id, buf, 0) == ERR) {
-      /* FIXME: gettext here to expand %s in accordance with the
-       * locale for the selected notification agent. See also the TODO
-       * comment of uim-notify.h  -- YamaKen 2008-02-11 */
- uim_notify_fatal(N_("uim-canna: Failed to mount dictionary %s."), buf);
-    }
-    buflen = strlen(buf) + sizeof((char)'\0');
-    buf += buflen;
-  }
-#ifdef UIM_CANNA_DEBUG
-  cc->diclist = diclist;
-#else
-  free(diclist);
-#endif
-
-  cc_ = MAKE_PTR(cc);
-  context_list = uim_scm_callf("cons", "oo", cc_, context_list);
-
-  return cc_;
-}
-
-static uim_lisp
-release_context(uim_lisp cc_)
-{
-  struct canna_context *cc;
-  uim_bool err;
-
-  context_list = uim_scm_callf("delete!", "oo", cc_, context_list);
-
-  cc = get_canna_context(cc_);
-  uim_scm_nullify_c_ptr(cc_);
-
-  if (cc->rk_context_id != -1) {
-    err = (RkCloseContext(cc->rk_context_id) == ERR);
-  } else {
-    err = UIM_TRUE;
-  }
-#ifdef UIM_CANNA_DEBUG
-  free(cc->diclist);
-#endif
-  free(cc);
-
-  if (err)
-    uim_notify_fatal("canna-lib-release-context failed");
-
-  return uim_scm_f();
-}
-
-static void
-_reset_conversion(struct canna_context *cc)
-{
-  assert(VALID_CANNA_CONTEXTP(cc));
-
-  if (cc->segment_num >= 0) {
-     cc->segment_num = -1;
-     RkEndBun(cc->rk_context_id, FORGET_SELECTED_CAND);
-  }
-}
-
-static void
-_update_status(struct canna_context *cc)
-{
-  RkStat stat;
-  int i;
-
-  assert(VALID_CANNA_CONTEXTP(cc));
-
-  free(cc->max_cand_num_list);
-  cc->max_cand_num_list = uim_malloc(sizeof(int) * cc->segment_num);
-  for (i = 0; i < cc->segment_num; i++) {
-    RkGoTo(cc->rk_context_id, i);
-    if (RkGetStat(cc->rk_context_id, &stat) == OK) {
-      cc->max_cand_num_list[i] = stat.maxcand;
-    } else {
-      cc->max_cand_num_list[i] = -1;
-      _reset_conversion(cc);
-    }
-  }
-}
-
-static uim_lisp
-begin_conversion(uim_lisp cc_, uim_lisp str_)
-{
-  struct canna_context *cc;
-  const char *str;
-  int len, segment_num, mode;
-
-  cc = get_canna_context(cc_);
-
-  mode = cc->rk_mode;
-  str = REFER_C_STR(str_);
-  len = strlen(str);
-
-  segment_num = RkBgnBun(cc->rk_context_id, (char *)str, len, mode);
-  if (segment_num == ERR) {
-    uim_notify_fatal("RkBgnBun() failed");
-    return uim_scm_f();
-  }
-
-  cc->segment_num = segment_num;
-  _update_status(cc);
-
-  return MAKE_INT(cc->segment_num);
-}
-
-static uim_lisp
-get_nth_candidate(uim_lisp cc_, uim_lisp seg_, uim_lisp nth_)
-{
-  struct canna_context *cc;
-  int seg, nth, len;
-  char buf[BUFSIZE];
-
-  cc = get_canna_context(cc_);
-  seg = C_INT(seg_);
-  nth = C_INT(nth_);
-  validate_segment_index(cc, seg);
-
-  RkGoTo(cc->rk_context_id, seg);
-
-  if (nth < 0 || nth > cc->max_cand_num_list[seg])
-    nth = 0;
-  RkXfer(cc->rk_context_id, nth);
-
-  len = RkGetKanji(cc->rk_context_id, (unsigned char *)buf, BUFSIZE);
-  if (len == ERR)
-    uim_fatal_error("RkGetKanji() failed");
-#ifdef UIM_CANNA_DEBUG
-  printf("nth: %d, kanji: %s\n", nth, buf);
-#endif
-  return MAKE_STR(buf);
-}
-
-static uim_lisp
-get_unconv_candidate(uim_lisp cc_, uim_lisp seg_)
-{
-  struct canna_context *cc;
-  int seg, len;
-  char buf[BUFSIZE];
-
-  cc = get_canna_context(cc_);
-  seg = C_INT(seg_);
-  validate_segment_index(cc, seg);
-
-  RkGoTo(cc->rk_context_id, seg);
-
-  len = RkGetYomi(cc->rk_context_id, (unsigned char *)buf, BUFSIZE);
-  if (len == ERR)
-    uim_fatal_error("RkGetYomi() failed");
-#ifdef UIM_CANNA_DEBUG
-  fprintf(stderr, "yomi: %s\n", buf);
-#endif
-  return MAKE_STR(buf);
-}
-
-static uim_lisp
-get_nr_segments(uim_lisp cc_)
-{
-  struct canna_context *cc;
-  /* RkStat stat; */
-
-  cc = get_canna_context(cc_);
-
-  return MAKE_INT(cc->segment_num);
-}
-
-static uim_lisp
-get_nr_candidates(uim_lisp cc_, uim_lisp seg_)
-{
-  struct canna_context *cc;
-  int seg;
-
-  cc = get_canna_context(cc_);
-  seg = C_INT(seg_);
-  validate_segment_index(cc, seg);
-
-  if (cc->max_cand_num_list[seg] == -1)
-    ERROR("invalid candidate index");
-
-  return MAKE_INT(cc->max_cand_num_list[seg]);
-}
-
-static uim_lisp
-resize_segment(uim_lisp cc_, uim_lisp seg_, uim_lisp delta_)
-{
-  struct canna_context *cc;
-  int seg, delta, id;
-
-  cc = get_canna_context(cc_);
-  seg = C_INT(seg_);
-  delta = C_INT(delta_);
-  validate_segment_index(cc, seg);
-
-  RkGoTo(cc->rk_context_id, seg);
-  RkNfer(cc->rk_context_id);
-
-  id = cc->rk_context_id;
-  cc->segment_num = (delta > 0) ? RkEnlarge(id) : RkShorten(id);
-
-  _update_status(cc);
-
-  return uim_scm_t();
-}
-
-static uim_lisp
-commit_segment(uim_lisp cc_, uim_lisp seg_, uim_lisp nth_)
-{
-  struct canna_context *cc;
-#if 0
-  int seg, nth;
-#endif
-
-  cc = get_canna_context(cc_);
-#if 0
-  seg = C_INT(seg_);
-  nth = C_INT(nth_);
-  validate_segment_index(cc, seg);
-#endif
-
-  RkEndBun(cc->rk_context_id, LEARN_SELECTED_CAND);
-  cc->segment_num = -1;
-
-  return uim_scm_t();
-}
-
-static uim_lisp
-reset_conversion(uim_lisp cc_)
-{
-  struct canna_context *cc;
-
-  cc = get_canna_context(cc_);
-
-  _reset_conversion(cc);
-
-  return uim_scm_t();
-}
-
-void
-uim_plugin_instance_init(void)
-{
-  context_list = uim_scm_null();
-  uim_scm_gc_protect(&context_list);
-
-  uim_scm_eval_c_string("(require-extension (srfi 1))"); /* for delete! */
-
-  uim_scm_init_proc1("canna-lib-init", init_canna_lib);
-  uim_scm_init_proc0("canna-lib-alloc-context", create_context);
-  uim_scm_init_proc1("canna-lib-release-context", release_context);
-  uim_scm_init_proc3("canna-lib-get-nth-candidate", get_nth_candidate);
- uim_scm_init_proc2("canna-lib-get-unconv-candidate", get_unconv_candidate);
-  uim_scm_init_proc1("canna-lib-get-nr-segments",get_nr_segments);
-  uim_scm_init_proc2("canna-lib-get-nr-candidates", get_nr_candidates);
-  uim_scm_init_proc3("canna-lib-resize-segment", resize_segment);
-  uim_scm_init_proc2("canna-lib-begin-conversion", begin_conversion);
-  uim_scm_init_proc3("canna-lib-commit-segment", commit_segment);
-  uim_scm_init_proc1("canna-lib-reset-conversion", reset_conversion);
-}
-
-void
-uim_plugin_instance_quit(void)
-{
- uim_scm_callf("for-each", "vo", "canna-lib-release-context", context_list);
-  context_list = uim_scm_null();
-  uim_scm_gc_unprotect(&context_list);
-
-  free(cannaserver);
-  cannaserver = NULL;
-
-  if (rk_initialized == 1) {
-     RkFinalize();
-     rk_initialized = -1;
-  }
-}
-#endif /* HAVE_CANNA_RK_H */
=======================================
--- /trunk/scm/Makefile.am      Thu Nov 12 05:26:02 2009
+++ /trunk/scm/Makefile.am      Fri Nov 20 02:25:44 2009
@@ -22,7 +22,7 @@
  japanese.scm japanese-azik.scm japanese-kana.scm \
  anthy.scm anthy-custom.scm anthy-key-custom.scm \
  anthy-utf8.scm anthy-utf8-custom.scm \
- canna.scm canna-custom.scm canna-key-custom.scm \
+ canna.scm cannav3-socket.scm canna-custom.scm canna-key-custom.scm \
  wnn.scm wnn-custom.scm wnn-key-custom.scm \
  sj3.scm sj3-custom.scm sj3-key-custom.scm \
  prime.scm prime-custom.scm prime-key-custom.scm \
@@ -61,9 +61,6 @@
 if ANTHY_UTF8
   module_names += "anthy-utf8"
 endif
-if CANNA
-  module_names += "canna"
-endif
 if WNN
   module_names += "wnn"
 endif
@@ -79,7 +76,7 @@
 if SKK
   module_names += "skk"
 endif
-module_names += "tcode" "trycode" "tutcode" "byeoru" "latin" "elatin"
+module_names += "canna" "tcode" "trycode" "tutcode" "byeoru" "latin" "elatin"
 if M17NLIB
   module_names += "m17nlib"
 endif
=======================================
--- /trunk/scm/canna.scm        Wed Nov  4 08:13:55 2009
+++ /trunk/scm/canna.scm        Fri Nov 20 02:25:44 2009
@@ -34,6 +34,7 @@
 (require "japanese-kana.scm")
 (require "japanese-azik.scm")
 (require "generic-predict.scm")
+(require "cannav3-socket.scm")
 (require-custom "generic-key-custom.scm")
 (require-custom "canna-custom.scm")
 (require-custom "canna-key-custom.scm")
=======================================
--- /trunk/uim/Makefile.am      Thu Nov 12 05:26:02 2009
+++ /trunk/uim/Makefile.am      Fri Nov 20 02:25:44 2009
@@ -93,15 +93,6 @@
   libuim_scim_la_CXXFLAGS = -I$(top_srcdir) @SCIM_CFLAGS@
 endif

-if CANNA
-  uim_plugin_LTLIBRARIES += libuim-canna.la
-  libuim_canna_la_SOURCES = canna.c
-  libuim_canna_la_LIBADD = libuim-scm.la libuim.la -lcanna
-  libuim_canna_la_LDFLAGS = -rpath $(uim_plugindir) -avoid-version -module
-  libuim_canna_la_CPPFLAGS = -I$(top_srcdir)
-endif
-
-
 if WNN
 uim_plugin_LTLIBRARIES += libuim-wnn.la
 libuim_wnn_la_SOURCES = wnnlib.h wnnlib.c

Reply via email to