[uim-commit] r1260 - trunk/uim
yamamoto at freedesktop.org
yamamoto at freedesktop.org
Sun Aug 21 17:26:15 EST 2005
Author: yamamoto
Date: 2005-08-21 00:26:00 -0700 (Sun, 21 Aug 2005)
New Revision: 1260
Modified:
trunk/uim/canna.c
Log:
* uim/canna.c
(canna_context): Remove current_cand_num, max_current_cand_num and
current_segment_num. Add max_cand_num_list.
(get_canna_context): Simplify.
(init_canna_lib): Add initialization of max_cand_num_list.
(_reset_conversion, _update_status): Replace id parameter with
canna_context.
(_update_status): Set the number of candidates for each segments to
max_cand_num_list.
(begin_conversion, resize_segment): Call _update_status instead of
_update_segment.
(get_nth_candidate): Don't call _update_segment to improve
efficiency.
Modified: trunk/uim/canna.c
===================================================================
--- trunk/uim/canna.c 2005-08-21 04:08:53 UTC (rev 1259)
+++ trunk/uim/canna.c 2005-08-21 07:26:00 UTC (rev 1260)
@@ -58,11 +58,8 @@
int rk_context_id;
int rk_mode;
- int current_cand_num;
- int max_current_cand_num;
-
+ int *max_cand_num_list;
int segment_num;
- int current_segment_num;
};
static struct canna_context *context_array = NULL;
@@ -76,20 +73,14 @@
static struct canna_context *
get_canna_context(int id)
{
- int i;
- struct canna_context *context;
- context = context_array;
-
if (id >= MAX_CONTEXT || id < 0)
return NULL;
- for (i = 0; i < id; i++)
- context++;
#ifdef UIM_CANNA_DEBUG
- printf("rk_context_id: %d\n", context->rk_context_id);
- printf("segment_num: %d\n", context->segment_num);
+ printf("rk_context_id: %d\n", context_array[id].rk_context_id);
+ printf("segment_num: %d\n", context_array[id].segment_num);
#endif
- return context;
+ return &context_array[id];
}
static uim_lisp
@@ -113,11 +104,9 @@
context->rk_context_id = -1;
context->rk_mode = (RK_XFER << RK_XFERBITS) | RK_KFER;
- context->current_cand_num = -1;
- context->max_current_cand_num = -1;
+ context->max_cand_num_list = NULL;
context->segment_num = -1;
- context->current_segment_num = -1;
context->diclist[0] = '\0';
context++;
@@ -198,9 +187,8 @@
}
static void
-_reset_conversion(int id)
+_reset_conversion(struct canna_context *cc)
{
- struct canna_context *cc = get_canna_context(id);
if (cc == NULL)
return;
@@ -211,54 +199,30 @@
}
static void
-_update_status(int id)
+_update_status(struct canna_context *cc)
{
RkStat stat;
- struct canna_context *cc = get_canna_context(id);
+ int i;
if (cc == NULL)
return;
if (cc->rk_context_id == -1)
return;
- if (RkGetStat(cc->rk_context_id, &stat) == 0)
- {
- cc->current_segment_num = stat.bunnum;
- cc->current_cand_num = stat.candnum;
- cc->max_current_cand_num = stat.maxcand;
- } else {
- _reset_conversion(id);
+ if (cc->max_cand_num_list != NULL) {
+ free(cc->max_cand_num_list);
}
-}
-
-static void
-_update_segment (const int id, const int segment_num)
-{
- int i, tmp_segment_num;
- char buf[BUFSIZE];
- struct canna_context *cc = get_canna_context(id);
-
- if (cc == NULL)
- return;
-
- if (cc->rk_context_id == -1)
- return;
-
- tmp_segment_num = segment_num;
- if (segment_num >= cc->segment_num)
- tmp_segment_num = 0;
-
- for (i = 0; i <= tmp_segment_num; i++) {
- int len;
+ cc->max_cand_num_list = malloc(sizeof(int) * cc->segment_num);
+ for (i = 0; i < cc->segment_num; i++) {
RkGoTo(cc->rk_context_id, i);
- len = RkGetKanji(cc->rk_context_id, (unsigned char *)buf, BUFSIZE);
-#ifdef UIM_CANNA_DEBUG
- printf("segment: %d, buf: %s\n", i, buf);
-#endif
+ if (RkGetStat(cc->rk_context_id, &stat) == 0)
+ {
+ cc->max_cand_num_list[i] = stat.maxcand;
+ } else {
+ cc->max_cand_num_list[i] = -1;
+ _reset_conversion(cc);
+ }
}
-
- RkGoTo(cc->rk_context_id, tmp_segment_num);
- _update_status(id);
}
static uim_lisp
@@ -289,7 +253,7 @@
}
cc->segment_num = segment_num;
- _update_segment(id, 0);
+ _update_status(cc);
if (str != NULL)
free(str);
@@ -310,10 +274,10 @@
if (cc == NULL)
return uim_scm_f();
- _update_segment(id, seg);
- if (nth > cc->max_current_cand_num)
+ if (nth > cc->max_cand_num_list[seg])
nth = 0;
+ RkGoTo(cc->rk_context_id, seg);
RkXfer(cc->rk_context_id, nth);
len = RkGetKanji(cc->rk_context_id, (unsigned char *)buf, BUFSIZE);
#ifdef UIM_CANNA_DEBUG
@@ -343,7 +307,6 @@
{
int id = uim_scm_c_int(id_);
int nth = uim_scm_c_int(nth_);
- RkStat stat;
struct canna_context *cc = get_canna_context(id);
if (cc == NULL)
@@ -352,10 +315,9 @@
if (cc->rk_context_id == -1)
return uim_scm_f();
- RkGoTo(cc->rk_context_id, nth);
- if (RkGetStat(cc->rk_context_id, &stat) == 0)
- return uim_scm_make_int(stat.maxcand);
+ if (cc->max_cand_num_list[nth] != -1)
+ return uim_scm_make_int(cc->max_cand_num_list[nth]);
else
return uim_scm_f();
}
@@ -382,7 +344,7 @@
else
cc->segment_num = RkShorten(cc->rk_context_id);
- _update_segment(id, cc->current_segment_num);
+ _update_status(cc);
return uim_scm_t();
}
@@ -413,8 +375,9 @@
reset_conversion(uim_lisp id_)
{
int id = uim_scm_c_int(id_);
+ struct canna_context *cc = get_canna_context(id);
- _reset_conversion(id);
+ _reset_conversion(cc);
return uim_scm_t();
}
More information about the uim-commit
mailing list