[uim-commit] r2013 - in branches/r5rs: . uim
yamaken at freedesktop.org
yamaken at freedesktop.org
Sat Nov 5 13:22:23 PST 2005
Author: yamaken
Date: 2005-11-05 13:22:19 -0800 (Sat, 05 Nov 2005)
New Revision: 2013
Modified:
branches/r5rs/
branches/r5rs/uim/anthy.c
Log:
r487 at deepblue (orig r1985): kzk | 2005-11-04 19:58:35 +0900
* uim/anthy.c
- (struct anthy_api): add member set_prediction_string,
get_prediction_stat, get_prediction
- (get_anthy_api): dlsy "anthy_set_prediction_string",
"anthy_get_prediction_stat", "anthy_get_prediction"
- (set_prediction_src_string,
get_nr_predictions,
get_nth_prediction): new function
- (uim_plugin_instance_init): init subr
"anthy-lib-set-prediction-src-string",
"anthy-lib-get-nr-predictions",
"anthy-lib-get-nth-prediction"
Property changes on: branches/r5rs
___________________________________________________________________
Name: svk:merge
- 2f05256a-0800-0410-85e3-84fe06922419:/local/uim/trunk:1514
74100eb5-a104-0410-9326-fdab01523867:/branches/r5rs:6
fb73e508-85ea-0310-95c3-a85c473e0941:/trunk:1984
+ 2f05256a-0800-0410-85e3-84fe06922419:/local/uim/trunk:1514
74100eb5-a104-0410-9326-fdab01523867:/branches/r5rs:6
fb73e508-85ea-0310-95c3-a85c473e0941:/trunk:1985
Modified: branches/r5rs/uim/anthy.c
===================================================================
--- branches/r5rs/uim/anthy.c 2005-11-05 21:21:59 UTC (rev 2012)
+++ branches/r5rs/uim/anthy.c 2005-11-05 21:22:19 UTC (rev 2013)
@@ -68,6 +68,13 @@
int (*get_segment)(anthy_context_t , int, int, char *, int);
void (*resize_segment)(anthy_context_t , int, int);
int (*commit_segment)(anthy_context_t , int, int);
+
+#ifdef HAS_ANTHY_PREDICTION
+ /* prediction */
+ int (*set_prediction_string)(anthy_context_t , const char *);
+ int (*get_prediction_stat)(anthy_context_t , struct anthy_prediction_stat *);
+ int (*get_prediction)(anthy_context_t , int, char *, int);
+#endif /* HAS_ANTHY_PREDICTION */
} api;
static struct context {
@@ -98,12 +105,19 @@
*(int **)(&api.get_segment) = dlsym(api.lib, "anthy_get_segment");
*(void **)(&api.resize_segment) = dlsym(api.lib, "anthy_resize_segment");
*(int **)(&api.commit_segment) = dlsym(api.lib, "anthy_commit_segment");
- if (api.init &&
- api.quit &&
- api.create_context &&
- api.release_context && api.set_string &&
- api.get_stat && api.get_segment_stat &&
- api.get_segment && api.resize_segment && api.commit_segment) {
+#ifdef HAS_ANTHY_PREDICTION
+ *(int **)(&api.set_prediction_string) = dlsym(api.lib, "anthy_set_prediction_string");
+ *(int **)(&api.get_prediction_stat) = dlsym(api.lib, "anthy_get_prediction_stat");
+ *(int **)(&api.get_prediction) = dlsym(api.lib, "anthy_get_prediction");
+#endif /* HAS_ANTHY_PREDICTION */
+ if (api.init && api.quit
+ && api.create_context && api.release_context
+ && api.set_string && api.get_stat && api.get_segment_stat
+ && api.get_segment && api.resize_segment && api.commit_segment
+#ifdef HAS_ANTHY_PREDICTION
+ && api.set_prediction_string && api.get_prediction_stat && api.get_prediction
+#endif /* HAS_ANTHY_PREDICTION */
+ ) {
return 0;
}
return -1;
@@ -292,6 +306,57 @@
return uim_scm_f();
}
+#ifdef HAS_ANTHY_PREDICTION
+static uim_lisp
+set_prediction_src_string(uim_lisp id_, uim_lisp str_)
+{
+ int id = uim_scm_c_int(id_);
+ const char *str = uim_scm_refer_c_str(str_);
+ anthy_context_t ac = get_anthy_context(id);
+ if (!ac) {
+ return uim_scm_f();
+ }
+ api.set_prediction_string(ac, str);
+ return uim_scm_f();
+}
+
+static uim_lisp
+get_nr_predictions(uim_lisp id_)
+{
+ int id = uim_scm_c_int(id_);
+ anthy_context_t ac = get_anthy_context(id);
+ struct anthy_prediction_stat ps;
+ if (!ac) {
+ return uim_scm_f();
+ }
+ api.get_prediction_stat(ac, &ps);
+ return uim_scm_make_int(ps.nr_prediction);
+}
+
+static uim_lisp
+get_nth_prediction(uim_lisp id_, uim_lisp nth_)
+{
+ int id = uim_scm_c_int(id_);
+ int nth = uim_scm_c_int(nth_);
+ int buflen;
+ char *buf;
+ uim_lisp buf_;
+ anthy_context_t ac = get_anthy_context(id);
+ if (!ac) {
+ return uim_scm_f();
+ }
+ buflen = api.get_prediction(ac, nth, NULL, 0);
+ if (buflen == -1) {
+ return uim_scm_f();
+ }
+ buf = (char *)malloc(buflen + 1);
+ api.get_prediction(ac, nth, buf, buflen + 1);
+ buf_ = uim_scm_make_str(buf);
+ free(buf);
+ return buf_;
+}
+#endif /* HAS_ANTHY_PREDICTION */
+
void
uim_plugin_instance_init(void)
{
@@ -305,6 +370,11 @@
uim_scm_init_subr_2("anthy-lib-get-segment-length", get_segment_length);
uim_scm_init_subr_3("anthy-lib-resize-segment", resize_segment);
uim_scm_init_subr_3("anthy-lib-commit-segment", commit_segment);
+#ifdef HAS_ANTHY_PREDICTION
+ uim_scm_init_subr_2("anthy-lib-set-prediction-src-string", set_prediction_src_string);
+ uim_scm_init_subr_1("anthy-lib-get-nr-predictions", get_nr_predictions);
+ uim_scm_init_subr_2("anthy-lib-get-nth-prediction", get_nth_prediction);
+#endif /* HAS_ANTHY_PREDICTION */
}
void
More information about the uim-commit
mailing list