Author: yamakenz
Date: Fri Jul 20 11:26:16 2007
New Revision: 4763

Added:
   trunk/test/test-anthy.scm   (contents, props changed)
Modified:
   trunk/scm/anthy.scm
   trunk/test/Makefile.am
   trunk/uim/anthy.c

Log:
* uim/anthy.c
  - (anthy_version_major, anthy_version_minor): Removed
  - (anthy_version): Return bare Anthy version string
  - (get_anthy_version): Removed
  - (init_anthy_lib): Remove get_anthy_version() invocation
* scm/anthy.scm
  - Require SRFI-1, SRFI-8
  - (anthy-version->major.minor): New procedure
  - (anthy-context-new): Follow the change of anthy-lib-get-anthy-version
* test/test-anthy.scm
  - New file
  - Add tests for anthy-version->major.minor
* test/Makefile.am
  - (EXTRA_DIST): Add test-anthy.scm


Modified: trunk/scm/anthy.scm
==============================================================================
--- trunk/scm/anthy.scm (original)
+++ trunk/scm/anthy.scm Fri Jul 20 11:26:16 2007
@@ -30,6 +30,8 @@
 ;;; SUCH DAMAGE.
 ;;;;
 
+(require-extension (srfi 1 8))
+
 (require "util.scm")
 (require "ustr.scm")
 (require "japanese.scm")
@@ -68,6 +70,15 @@
 ;; I don't think the key needs to be customizable.
 (define-key anthy-space-key? '(" "))
 
+;; Handle Anthy's version scheme like 7100b, 8158memm.
+(define anthy-version->major.minor
+  (lambda (vstr)
+    (if (string=? vstr "(unknown)")
+       '("-1" . "")
+       (receive (maj min) (span char-numeric? (string->list vstr))
+         (cons (list->string maj)
+               (list->string min))))))
+
 (define anthy-prepare-input-rule-activation
   (lambda (ac)
     (cond
@@ -319,7 +330,8 @@
      (if (symbol-bound? 'anthy-lib-init)
          (begin
           (set! anthy-lib-initialized? (anthy-lib-init))
-          (set! anthy-version (anthy-lib-get-anthy-version))))
+          (set! anthy-version (anthy-version->major.minor
+                               (anthy-lib-get-anthy-version)))))
      (if anthy-lib-initialized?
         (anthy-context-set-ac-id! ac (anthy-lib-alloc-context)))
      (anthy-context-set-widgets! ac anthy-widgets)

Modified: trunk/test/Makefile.am
==============================================================================
--- trunk/test/Makefile.am      (original)
+++ trunk/test/Makefile.am      Fri Jul 20 11:26:16 2007
@@ -3,4 +3,5 @@
         test-i18n.scm test-im.scm test-intl.scm test-key.scm \
         test-lazy-load.scm test-plugin.scm \
         test-uim-test-utils.scm test-uim-util.scm test-ustr.scm \
-        test-util.scm test-example.scm
+        test-util.scm test-example.scm \
+       test-anthy.scm

Added: trunk/test/test-anthy.scm
==============================================================================
--- (empty file)
+++ trunk/test/test-anthy.scm   Fri Jul 20 11:26:16 2007
@@ -0,0 +1,51 @@
+#!/usr/bin/env gosh
+
+;;; Copyright (c) 2007 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.
+;;;;
+
+;; These tests are passed at revision 4763 (new repository)
+
+(use test.unit)
+
+(require "test/uim-test-utils")
+
+(define-uim-test-case "testcase anthy"
+  (setup
+   (lambda ()
+    (uim '(require-module "anthy"))))
+
+  ("test anthy-version"
+   (assert-equal '("-1" . "")
+                (uim '(anthy-version->major.minor "(unknown)")))
+   (assert-equal '("7100" . "b")
+                (uim '(anthy-version->major.minor "7100b")))
+   (assert-equal '("8158" . "memm")
+                (uim '(anthy-version->major.minor "8158memm")))
+   (assert-equal '("9100" . "")
+                (uim '(anthy-version->major.minor "9100")))))

Modified: trunk/uim/anthy.c
==============================================================================
--- trunk/uim/anthy.c   (original)
+++ trunk/uim/anthy.c   Fri Jul 20 11:26:16 2007
@@ -40,53 +40,15 @@
 #include "uim-scm.h"
 #include "plugin.h"
 
+
 static uim_bool initialized;
 static uim_lisp context_list;
 
-/* handle anthy's version scheme like 7100b, 8158memm */
-static char *anthy_version_major;
-static char *anthy_version_minor;
-
 
 static uim_lisp
 anthy_version()
 {
-  return uim_scm_cons(uim_scm_make_str(anthy_version_major),
-                     uim_scm_make_str(anthy_version_minor));
-}
-
-static void
-get_anthy_version()
-{
-  const char *str;
-
-  free(anthy_version_major);
-  free(anthy_version_minor);
-
-  str = anthy_get_version_string();
-
-  if (!str || (!strcmp(str, "(unknown)"))) {
-    anthy_version_major = strdup("-1");
-    anthy_version_minor = strdup("");
-  } else {
-    int len, i;
-
-    len = strlen(str);
-    for (i = 0; str[i] != '\0'; i++) {
-      if (isalpha((unsigned char)str[i]))
-        break;
-    }
-
-    if (i != len) {
-      anthy_version_major = malloc(i + 1);
-      anthy_version_minor = malloc(len - i + 1);
-      strlcpy(anthy_version_major, str, i + 1);
-      strlcpy(anthy_version_minor, &str[i], len - i + 1);
-    } else {
-      anthy_version_major = strdup(str);
-      anthy_version_minor = strdup("");
-    }
-  }
+  return uim_scm_make_str(anthy_get_version_string());
 }
 
 static uim_lisp
@@ -95,8 +57,6 @@
   if (!initialized) {
     if (anthy_init() == -1)
       return uim_scm_f();
-
-    get_anthy_version();
 
     initialized = UIM_TRUE;
   }

Reply via email to