[uim-commit] r2149 - in trunk: scm uim

ekato at freedesktop.org ekato at freedesktop.org
Tue Nov 15 15:48:49 PST 2005


Author: ekato
Date: 2005-11-15 15:48:44 -0800 (Tue, 15 Nov 2005)
New Revision: 2149

Modified:
   trunk/scm/skk.scm
   trunk/uim/skk.c
Log:
* scm/skk.scm (skk-get-nth-completion) : Enable completion with
  numeric conversion.
(skk-begin-completion) : Ditto.
(skk-proc-state-direct) : Ditto.
(skk-proc-state-direct) : Ditto.
(skk-change-completion-index) : Ditto.
(skk-proc-state-completion) : Ditto.
* uim/skk.c (find_comp_array_lisp) : Use numeric_conv_ argument to
  support numeric conversion with completion.
(skk_get_completion) : Ditto.
(skk_get_nth_completion) : Ditto.
(skk_get_nr_completion) : Ditto.
(skk_clear_completion) : Ditto.
(skk_get_dcomp_word) : Ditto.
(restore_numeric) : New function to merge numeric list to str.
(uim_plugin_instance_init) : Update.


Modified: trunk/scm/skk.scm
===================================================================
--- trunk/scm/skk.scm	2005-11-15 10:29:08 UTC (rev 2148)
+++ trunk/scm/skk.scm	2005-11-15 23:48:44 UTC (rev 2149)
@@ -500,7 +500,8 @@
   (lambda (sc n)
     (skk-lib-get-nth-completion
      n
-     (skk-make-string (skk-context-head sc) skk-type-hiragana))))
+     (skk-make-string (skk-context-head sc) skk-type-hiragana)
+     skk-use-numeric-conversion?)))
 
 (define skk-get-current-completion
   (lambda (sc)
@@ -645,7 +646,8 @@
       ;;
       (set! res
 	    (skk-lib-get-completion
-	     (skk-make-string (skk-context-head sc) (skk-context-kana-mode sc))))
+	     (skk-make-string (skk-context-head sc) (skk-context-kana-mode sc))
+	     skk-use-numeric-conversion?))
       (if res
 	  (begin
 	    (skk-context-set-completion-nth! sc 0)
@@ -1082,7 +1084,8 @@
 		      sc
 		      (skk-lib-get-dcomp-word
 		       (skk-make-string
-			(skk-context-head sc) (skk-context-kana-mode sc)))))
+			(skk-context-head sc) (skk-context-kana-mode sc))
+		       skk-use-numeric-conversion?)))
 		 #f)
 	       (let* ((residual-kana (rk-push-key-last! rkc)))
 		 ;; handle preceding "n"
@@ -1124,7 +1127,9 @@
 		(skk-context-set-dcomp-word!
 		 sc
 		 (skk-lib-get-dcomp-word
-		  (skk-make-string (skk-context-head sc) (skk-context-kana-mode sc)))))))
+		  (skk-make-string
+		   (skk-context-head sc) (skk-context-kana-mode sc))
+		  skk-use-numeric-conversion?)))))
       (if (or
 	   (eq? (skk-context-state sc) 'skk-state-direct)
 	   (eq? (skk-context-state sc) 'skk-state-latin)
@@ -1200,8 +1205,9 @@
 		  (if (not (skk-rk-pending? sc))
 		      (skk-lib-get-dcomp-word
 		       (skk-make-string
-		       (skk-context-head sc)
-		       (skk-context-kana-mode sc)))
+			(skk-context-head sc)
+			(skk-context-kana-mode sc))
+		       skk-use-numeric-conversion?)
 			"")))
 	     #f)
 	   #t)
@@ -1239,7 +1245,8 @@
 		 	    (skk-lib-get-dcomp-word
 			     (skk-make-string
 			      (skk-context-head sc)
-			      (skk-context-kana-mode sc))))))
+			      (skk-context-kana-mode sc))
+			     skk-use-numeric-conversion?))))
 		     (if (not (null? sl))
 			 (begin
 			   (skk-context-set-head! sc '())
@@ -1274,7 +1281,8 @@
 			sc
 			(skk-lib-get-dcomp-word
 			 (skk-make-string
-			  (skk-context-head sc) (skk-context-kana-mode sc)))))))
+			  (skk-context-head sc) (skk-context-kana-mode sc))
+			 skk-use-numeric-conversion?)))))
 	     #f)
 	   #t)
        (if (skk-kanji-mode-key? key key-state)
@@ -1397,7 +1405,8 @@
 		     sc
 		     (skk-lib-get-dcomp-word
 		      (skk-make-string
-		       (skk-context-head sc) (skk-context-kana-mode sc)))))
+		       (skk-context-head sc) (skk-context-kana-mode sc))
+		      skk-use-numeric-conversion?)))
 		#t)
 	      #t)
 	   (if (and res
@@ -1624,7 +1633,9 @@
     (if incr
 	(begin
 	  (if (> (- (skk-lib-get-nr-completions
-		  (skk-make-string (skk-context-head sc) skk-type-hiragana)) 1)
+		     (skk-make-string (skk-context-head sc) skk-type-hiragana)
+		     skk-use-numeric-conversion?)
+		    1)
 		 (skk-context-completion-nth sc))
 	      (skk-context-set-completion-nth!
 	       sc
@@ -1681,7 +1692,8 @@
        (if (skk-cancel-key? key key-state)
 	   (begin
 	     (skk-lib-clear-completions
-	       (skk-make-string (skk-context-head sc) skk-type-hiragana))
+	       (skk-make-string (skk-context-head sc) skk-type-hiragana)
+	       skk-use-numeric-conversion?)
 	     (skk-context-set-state! sc 'skk-state-kanji)
 	     (if skk-dcomp-activate?
 		 (skk-context-set-dcomp-word! sc ""))
@@ -1689,7 +1701,8 @@
 	   #t)
        (let ((sl (string-to-list (skk-get-current-completion sc))))
 	 (skk-lib-clear-completions
-	   (skk-make-string (skk-context-head sc) (skk-context-kana-mode sc)))
+	   (skk-make-string (skk-context-head sc) (skk-context-kana-mode sc))
+	   skk-use-numeric-conversion?)
 	 (skk-context-set-head! sc '())
 	 (skk-string-list-to-context-head sc sl)
 	 (skk-context-set-state! sc 'skk-state-kanji)

Modified: trunk/uim/skk.c
===================================================================
--- trunk/uim/skk.c	2005-11-15 10:29:08 UTC (rev 2148)
+++ trunk/uim/skk.c	2005-11-15 23:48:44 UTC (rev 2149)
@@ -147,6 +147,7 @@
 /* XXX should create skk.h */
 static uim_lisp skk_replace_numeric(uim_lisp head_);
 
+static uim_lisp restore_numeric(const char *s, uim_lisp numlst_);
 static char *replace_numeric(const char *str);
 static char *sanitize_word(const char *str, const char *prefix);
 static int is_purged_cand(const char *str);
@@ -1770,21 +1771,31 @@
 }
 
 static struct skk_comp_array *
-find_comp_array_lisp(uim_lisp head_)
+find_comp_array_lisp(uim_lisp head_, uim_lisp numeric_conv_)
 {
   const char *hs;
   struct skk_comp_array *ca;
+  char *rs = NULL;
   
   hs = uim_scm_refer_c_str(head_);
-  ca = find_comp_array(skk_dic, hs);
+
+  if NFALSEP(numeric_conv_)
+    rs = replace_numeric(hs);
+
+  if (!rs)
+    ca = find_comp_array(skk_dic, hs);
+  else {
+    ca = find_comp_array(skk_dic, rs);
+    free(rs);
+  }
   return ca;
 }
 
 static uim_lisp
-skk_get_completion(uim_lisp head_)
+skk_get_completion(uim_lisp head_, uim_lisp numeric_conv_)
 {
   struct skk_comp_array *ca;
-  ca = find_comp_array_lisp(head_);
+  ca = find_comp_array_lisp(head_, numeric_conv_);
   if (ca) {
     ca->refcount++;
     return uim_scm_t();
@@ -1793,47 +1804,73 @@
 }
 
 static uim_lisp
-skk_get_nth_completion(uim_lisp nth_, uim_lisp head_)
+skk_get_nth_completion(uim_lisp nth_, uim_lisp head_, uim_lisp numeric_conv_)
 {
   int n;
   struct skk_comp_array *ca;
   char *str;
+  uim_lisp numlst_ = uim_scm_null_list();
 
-  ca = find_comp_array_lisp(head_);
+  if NFALSEP(numeric_conv_)
+    numlst_ = skk_store_replaced_numeric_str(head_);
+
+  if (!uim_scm_nullp(numlst_))
+    ca = find_comp_array_lisp(head_, numeric_conv_);
+  else
+    ca = find_comp_array_lisp(head_, uim_scm_f());
+
   n = uim_scm_c_int(nth_);
   if (ca && ca->nr_comps > n) {
     str = ca->comps[n];
-    return uim_scm_make_str(str);
+    if (!uim_scm_nullp(numlst_))
+      return restore_numeric(str, numlst_);
+    else
+      return uim_scm_make_str(str);
   }
   return uim_scm_null_list();
 }
 
 static uim_lisp
-skk_get_nr_completions(uim_lisp head_)
+skk_get_nr_completions(uim_lisp head_, uim_lisp numeric_conv_)
 {
   int n = 0;
   struct skk_comp_array *ca;
 
-  ca = find_comp_array_lisp(head_);
-  if (ca) {
+  ca = find_comp_array_lisp(head_, numeric_conv_);
+  if (ca)
     n = ca->nr_comps;
-  }
+
   return uim_scm_make_int(n);
 }
 
 static uim_lisp
-skk_clear_completions(uim_lisp head_)
+skk_clear_completions(uim_lisp head_, uim_lisp numeric_conv_)
 {
   int i;
   struct skk_comp_array *ca, *ca_prev;
   const char *hs;
+  char *rs = NULL;
 
   hs = uim_scm_refer_c_str(head_);
-  for (ca = skk_comp; ca; ca = ca->next) {
-    if (!strcmp(ca->head, hs)) {
-      ca->refcount--;
-      break;
+
+  if NFALSEP(numeric_conv_)
+    rs = replace_numeric(hs);
+
+  if (!rs)
+    for (ca = skk_comp; ca; ca = ca->next) {
+      if (!strcmp(ca->head, hs)) {
+        ca->refcount--;
+        break;
+      }
     }
+  else {
+    for (ca = skk_comp; ca; ca = ca->next) {
+      if (!strcmp(ca->head, rs)) {
+        ca->refcount--;
+        break;
+      }
+    }
+    free(rs);
   }
 
   if (ca && ca->refcount == 0) {
@@ -1859,21 +1896,75 @@
 }
 
 static uim_lisp
-skk_get_dcomp_word(uim_lisp head_)
+restore_numeric(const char *s, uim_lisp numlst_)
 {
+  int i, j, len, newlen, numstrlen;
+  const char *numstr;
+  char *str;
+  uim_lisp ret;
+
+  str = strdup(s);
+  newlen = len = strlen(str);
+
+  for (i = 0, j = 0; j < len; i++, j++) {
+    if (str[i] == '#') {
+      if (uim_scm_nullp(numlst_))
+	break;
+      
+      numstr  = uim_scm_refer_c_str(uim_scm_car(numlst_));
+      numstrlen = strlen(numstr);
+      newlen = newlen - 1 + numstrlen;
+      str = realloc(str, newlen + 1);
+      memmove(&str[i + numstrlen], &str[i + 1], newlen - i - numstrlen + 1);
+      memcpy(&str[i], numstr, numstrlen);
+      i = i  - 1 + numstrlen;
+
+      numlst_ = uim_scm_cdr(numlst_);
+    }
+  }
+  ret = uim_scm_make_str(str);
+  free(str);
+
+  return ret;
+}
+
+static uim_lisp
+skk_get_dcomp_word(uim_lisp head_, uim_lisp numeric_conv_)
+{
   const char *hs;
   struct skk_line *sl;
   int len;
+  uim_lisp numlst_ = uim_scm_null_list();
+  char *rs = NULL;
   
   hs = uim_scm_refer_c_str(head_);
-  len = strlen(hs);
 
+  if NFALSEP(numeric_conv_)
+    numlst_ = skk_store_replaced_numeric_str(head_);
+
+  if (!uim_scm_nullp(numlst_)) {
+    rs = replace_numeric(hs);
+    len = strlen(rs);
+  } else
+    len = strlen(hs);
+
   if (len != 0) {
     /* Search from cache using same way as in make_comp_array_from_cache(). */
-    for (sl = skk_dic->head.next; sl; sl = sl->next) {
-      if (!strncmp(sl->head, hs, len) && strcmp(sl->head, hs) &&
-		   sl->okuri_head == '\0')
-	return uim_scm_make_str(sl->head);
+    if (!rs)
+      for (sl = skk_dic->head.next; sl; sl = sl->next) {
+	if (!strncmp(sl->head, hs, len) && strcmp(sl->head, hs) &&
+			sl->okuri_head == '\0')
+	  return uim_scm_make_str(sl->head);
+      }
+    else {
+      for (sl = skk_dic->head.next; sl; sl = sl->next) {
+	if (!strncmp(sl->head, rs, len) && strcmp(sl->head, rs) &&
+			sl->okuri_head == '\0') {
+	  free(rs);
+	  return restore_numeric(sl->head, numlst_);
+	}
+      }
+      free(rs);
     }
   }
   return uim_scm_make_str("");
@@ -3155,11 +3246,11 @@
   uim_scm_init_subr_5("skk-lib-learn-word", skk_learn_word);
   uim_scm_init_subr_1("skk-lib-get-annotation", skk_get_annotation);
   uim_scm_init_subr_1("skk-lib-remove-annotation", skk_remove_annotation);
-  uim_scm_init_subr_1("skk-lib-get-completion", skk_get_completion);
-  uim_scm_init_subr_2("skk-lib-get-nth-completion", skk_get_nth_completion);
-  uim_scm_init_subr_1("skk-lib-get-nr-completions", skk_get_nr_completions);
-  uim_scm_init_subr_1("skk-lib-clear-completions", skk_clear_completions);
-  uim_scm_init_subr_1("skk-lib-get-dcomp-word", skk_get_dcomp_word);
+  uim_scm_init_subr_2("skk-lib-get-completion", skk_get_completion);
+  uim_scm_init_subr_3("skk-lib-get-nth-completion", skk_get_nth_completion);
+  uim_scm_init_subr_2("skk-lib-get-nr-completions", skk_get_nr_completions);
+  uim_scm_init_subr_2("skk-lib-clear-completions", skk_clear_completions);
+  uim_scm_init_subr_2("skk-lib-get-dcomp-word", skk_get_dcomp_word);
   uim_scm_init_subr_1("skk-lib-eval-candidate", skk_eval_candidate);
   uim_scm_init_subr_3("skk-lib-substring", skk_substring);
 }



More information about the uim-commit mailing list