[uim-commit] r2584 - in branches/1.0: scm uim
ekato at freedesktop.org
ekato at freedesktop.org
Wed Dec 14 18:34:12 PST 2005
Author: ekato
Date: 2005-12-14 18:34:09 -0800 (Wed, 14 Dec 2005)
New Revision: 2584
Modified:
branches/1.0/scm/skk-custom.scm
branches/1.0/scm/skk.scm
branches/1.0/uim/skk.c
Log:
* uim/skk.c
* uim/skk.scm
* uim/skk-custom.scm
- Port r2570-2572 from trunk.
Modified: branches/1.0/scm/skk-custom.scm
===================================================================
--- branches/1.0/scm/skk-custom.scm 2005-12-15 01:06:01 UTC (rev 2583)
+++ branches/1.0/scm/skk-custom.scm 2005-12-15 02:34:09 UTC (rev 2584)
@@ -400,6 +400,11 @@
(_ "Enable dynamic completion")
(_ "long description will be here."))
+(define-custom 'skk-use-look? #f
+ '(skk-advanced)
+ '(boolean)
+ (_ "Use UNIX look command for completion")
+ (_ "long description will be here."))
;;
;; annotation
;;
Modified: branches/1.0/scm/skk.scm
===================================================================
--- branches/1.0/scm/skk.scm 2005-12-15 01:06:01 UTC (rev 2583)
+++ branches/1.0/scm/skk.scm 2005-12-15 02:34:09 UTC (rev 2584)
@@ -517,7 +517,8 @@
(skk-lib-get-nth-completion
n
(skk-make-string (skk-context-head sc) skk-type-hiragana)
- skk-use-numeric-conversion?)))
+ skk-use-numeric-conversion?
+ skk-use-look?)))
(define skk-get-current-completion
(lambda (sc)
@@ -620,7 +621,8 @@
(skk-lib-get-dcomp-word
(skk-make-string
(skk-context-head sc) (skk-context-kana-mode sc))
- skk-use-numeric-conversion?))))))
+ skk-use-numeric-conversion?
+ skk-use-look?))))))
(define skk-append-okuri-string
(lambda (sc str)
@@ -670,7 +672,8 @@
(skk-append-residual-kana sc))
(skk-lib-get-completion
(skk-make-string (skk-context-head sc) (skk-context-kana-mode sc))
- skk-use-numeric-conversion?)
+ skk-use-numeric-conversion?
+ skk-use-look?)
(skk-context-set-completion-nth! sc 0)
(skk-context-set-state! sc 'skk-state-completion)))
@@ -1198,7 +1201,8 @@
(skk-make-string
(skk-context-head sc)
(skk-context-kana-mode sc))
- skk-use-numeric-conversion?)))
+ skk-use-numeric-conversion?
+ skk-use-look?)))
(if (not (string=? dcomp ""))
(begin
(skk-string-list-to-context-head
@@ -1295,7 +1299,8 @@
(skk-make-string
(skk-context-head sc)
(skk-context-kana-mode sc))
- skk-use-numeric-conversion?)
+ skk-use-numeric-conversion?
+ skk-use-look?)
"")))
#f)
#t)
@@ -1336,7 +1341,8 @@
(skk-make-string
(skk-context-head sc)
(skk-context-kana-mode sc))
- skk-use-numeric-conversion?))))
+ skk-use-numeric-conversion?
+ skk-use-look?))))
(if (not (null? sl))
(begin
(skk-string-list-to-context-head sc sl)
@@ -1729,7 +1735,8 @@
(begin
(if (> (- (skk-lib-get-nr-completions
(skk-make-string (skk-context-head sc) skk-type-hiragana)
- skk-use-numeric-conversion?)
+ skk-use-numeric-conversion?
+ skk-use-look?)
1)
(skk-context-completion-nth sc))
(skk-context-set-completion-nth!
@@ -1795,7 +1802,8 @@
(if (not (null? sl))
(begin (skk-lib-get-completion
(skk-get-current-completion sc)
- skk-use-numeric-conversion?)))
+ skk-use-numeric-conversion?
+ skk-use-look?)))
(skk-lib-clear-completions
(skk-make-string
(skk-context-head sc)
Modified: branches/1.0/uim/skk.c
===================================================================
--- branches/1.0/uim/skk.c 2005-12-15 01:06:01 UTC (rev 2583)
+++ branches/1.0/uim/skk.c 2005-12-15 02:34:09 UTC (rev 2584)
@@ -66,6 +66,7 @@
#define USE_SKK_JISYO_S_BUF 1 /* use SKK-JISYO.S as a cache for
word completion */
#define SKK_JISYO_S DATADIR "/skk/SKK-JISYO.S"
+#define LOOK_COMMAND "look" /* UNIX look command for completion */
/*
* cand : candidate
@@ -162,6 +163,8 @@
struct skk_cand_array *dst_ca, char *purged_cand);
static void update_personal_dictionary_cache_with_file(const char *fn,
int is_personal);
+static void look_get_comp(struct skk_comp_array *ca, const char *str);
+static uim_lisp look_get_top_word(const char *str);
/* skkserv connection */
#define SKK_SERVICENAME "skkserv"
@@ -413,6 +416,8 @@
uim_bool use_skkserv = uim_scm_c_bool(use_skkserv_);
int skkserv_portnum = uim_scm_c_int(skkserv_portnum_);
+ signal(SIGPIPE, SIG_IGN);
+
if (!skk_dic) {
skk_dic = open_dic(fn, use_skkserv, skkserv_portnum);
}
@@ -1750,7 +1755,7 @@
}
static struct skk_comp_array *
-make_comp_array_from_cache(struct dic_info *di, const char *s)
+make_comp_array_from_cache(struct dic_info *di, const char *s, uim_lisp use_look_)
{
struct skk_line *sl;
struct skk_comp_array *ca;
@@ -1779,6 +1784,9 @@
}
}
+ if NFALSEP(use_look_)
+ look_get_comp(ca, s);
+
if (ca->nr_comps == 0) {
free(ca);
ca = NULL;
@@ -1791,7 +1799,7 @@
}
static struct skk_comp_array *
-find_comp_array(struct dic_info *di, const char *s)
+find_comp_array(struct dic_info *di, const char *s, uim_lisp use_look_)
{
struct skk_comp_array *ca;
@@ -1803,14 +1811,14 @@
break;
}
if (ca == NULL) {
- ca = make_comp_array_from_cache(di, s);
+ ca = make_comp_array_from_cache(di, s, use_look_);
}
return ca;
}
static struct skk_comp_array *
-find_comp_array_lisp(uim_lisp head_, uim_lisp numeric_conv_)
+find_comp_array_lisp(uim_lisp head_, uim_lisp numeric_conv_, uim_lisp use_look_)
{
const char *hs;
struct skk_comp_array *ca;
@@ -1822,32 +1830,33 @@
rs = replace_numeric(hs);
if (!rs)
- ca = find_comp_array(skk_dic, hs);
+ ca = find_comp_array(skk_dic, hs, use_look_);
else {
- ca = find_comp_array(skk_dic, rs);
+ ca = find_comp_array(skk_dic, rs, use_look_);
free(rs);
}
return ca;
}
static uim_lisp
-skk_get_completion(uim_lisp head_, uim_lisp numeric_conv_)
+skk_get_completion(uim_lisp head_, uim_lisp numeric_conv_, uim_lisp use_look_)
{
struct skk_comp_array *ca;
- ca = find_comp_array_lisp(head_, numeric_conv_);
+ ca = find_comp_array_lisp(head_, numeric_conv_, use_look_);
if (ca) {
ca->refcount++;
return uim_scm_t();
}
if (NFALSEP(numeric_conv_) && has_numeric_in_head(head_))
- return skk_get_completion(head_, uim_scm_f());
+ return skk_get_completion(head_, uim_scm_f(), use_look_);
return uim_scm_f();
}
static uim_lisp
-skk_get_nth_completion(uim_lisp nth_, uim_lisp head_, uim_lisp numeric_conv_)
+skk_get_nth_completion(uim_lisp nth_, uim_lisp head_,
+ uim_lisp numeric_conv_, uim_lisp use_look_)
{
int n;
struct skk_comp_array *ca;
@@ -1858,13 +1867,13 @@
numlst_ = skk_store_replaced_numeric_str(head_);
if (!uim_scm_nullp(numlst_))
- ca = find_comp_array_lisp(head_, numeric_conv_);
+ ca = find_comp_array_lisp(head_, numeric_conv_, use_look_);
else
- ca = find_comp_array_lisp(head_, uim_scm_f());
+ ca = find_comp_array_lisp(head_, uim_scm_f(), use_look_);
if (!ca) {
if (!uim_scm_nullp(numlst_))
- return skk_get_nth_completion(nth_, head_, uim_scm_f());
+ return skk_get_nth_completion(nth_, head_, uim_scm_f(), use_look_);
else
return uim_scm_make_str("");
}
@@ -1880,24 +1889,24 @@
if (!uim_scm_nullp(numlst_) && n >= ca->nr_comps)
return skk_get_nth_completion(uim_scm_make_int(n - ca->nr_comps),
- head_, uim_scm_f());
+ head_, uim_scm_f(), use_look_);
return uim_scm_make_str("");
}
static uim_lisp
-skk_get_nr_completions(uim_lisp head_, uim_lisp numeric_conv_)
+skk_get_nr_completions(uim_lisp head_, uim_lisp numeric_conv_, uim_lisp use_look_)
{
int n = 0;
struct skk_comp_array *ca;
- ca = find_comp_array_lisp(head_, numeric_conv_);
+ ca = find_comp_array_lisp(head_, numeric_conv_, use_look_);
if (ca)
n = ca->nr_comps;
if (NFALSEP(numeric_conv_) && has_numeric_in_head(head_))
return uim_scm_make_int(n +
- uim_scm_c_int(skk_get_nr_completions(head_, uim_scm_f())));
+ uim_scm_c_int(skk_get_nr_completions(head_, uim_scm_f(), use_look_)));
return uim_scm_make_int(n);
}
@@ -1992,14 +2001,15 @@
}
static uim_lisp
-skk_get_dcomp_word(uim_lisp head_, uim_lisp numeric_conv_)
+skk_get_dcomp_word(uim_lisp head_, uim_lisp numeric_conv_, uim_lisp use_look_)
{
const char *hs;
struct skk_line *sl;
int len;
- uim_lisp numlst_ = uim_scm_null_list();
+ uim_lisp numlst_, look_;
char *rs = NULL;
-
+
+ numlst_ = uim_scm_null_list();
hs = uim_scm_refer_c_str(head_);
if NFALSEP(numeric_conv_)
@@ -2013,14 +2023,19 @@
if (len != 0) {
/* Search from cache using same way as in make_comp_array_from_cache(). */
- if (!rs)
+ 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' &&
sl->state & SKK_LINE_USE_FOR_COMPLETION)
return uim_scm_make_str(sl->head);
}
- else {
+ if NFALSEP(use_look_) {
+ look_ = look_get_top_word(hs);
+ if NFALSEP(look_)
+ return look_;
+ }
+ } 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' &&
@@ -2029,8 +2044,15 @@
return restore_numeric(sl->head, numlst_);
}
}
- free(rs);
- return skk_get_dcomp_word(head_, uim_scm_f());
+ if NFALSEP(use_look_) {
+ look_ = look_get_top_word(rs);
+ free(rs);
+ if NFALSEP(look_)
+ return look_;
+ } else {
+ free(rs);
+ }
+ return skk_get_dcomp_word(head_, uim_scm_f(), use_look_);
}
}
return uim_scm_make_str("");
@@ -3316,7 +3338,112 @@
return ret;
}
+static FILE *
+look_popen(const char *str)
+{
+ char *command;
+ FILE *fp;
+ int len;
+
+ len = strlen(LOOK_COMMAND) + strlen(str) + strlen(" 2>/dev/null") + 1;
+ command = malloc(len + 1);
+ if (!command)
+ return NULL;
+ snprintf(command, len + 1, "%s %s%s", LOOK_COMMAND, str, " 2>/dev/null");
+ fp = popen(command, "r");
+ free(command);
+
+ return fp;
+}
+
+static uim_lisp
+look_get_top_word(const char *str)
+{
+ char buf[512], *p;
+ FILE *fp;
+ uim_lisp ret_ = uim_scm_f();
+
+ if (!skk_isalpha(str[0]))
+ return ret_;
+
+ fp = look_popen(str);
+ if (!fp) {
+ perror("popen look");
+ return ret_;
+ }
+
+ while (fgets(buf, 512, fp) != NULL) {
+ p = strchr(buf, '\n');
+ if (p != NULL)
+ *p = '\0';
+ if (strcmp(buf, str)) { /* don't use the word itself */
+ ret_ = uim_scm_make_str(buf);
+ break;
+ }
+ }
+ /* read to the end */
+ /* while (fgets(buf, 512, fp) != NULL) ; */
+ pclose(fp);
+
+ return ret_;
+}
+
+static void
+look_get_comp(struct skk_comp_array *ca, const char *str)
+{
+ char buf[512], *p;
+ FILE *fp;
+ int i, nr_pre, top_line = 1;
+ int *matched;
+
+ if (!skk_isalpha(str[0]))
+ return;
+
+ fp = look_popen(str);
+ if (!fp) {
+ perror("popen look");
+ return;
+ }
+
+ nr_pre = ca->nr_comps;
+ matched = malloc(sizeof(int) * nr_pre);
+ for (i = 0; i < nr_pre; i++)
+ matched[i] = 0;
+
+ while (fgets(buf, 512, fp) != NULL) {
+ int match = 0;
+
+ p = strchr(buf, '\n');
+ if (p != NULL)
+ *p = '\0';
+
+ /* don't use the word itself */
+ if (top_line == 1 && !strcmp(buf, str)) {
+ top_line = 0;
+ continue;
+ }
+
+ /* skip words already in the cache */
+ for (i = 0; i < nr_pre; i++) {
+ if (matched[i])
+ continue;
+ if (!strcmp(ca->comps[i], buf)) {
+ matched[i] = 1;
+ match = 1;
+ break;
+ }
+ }
+ if (!match) {
+ ca->nr_comps++;
+ ca->comps = realloc(ca->comps, sizeof(char *) * ca->nr_comps);
+ ca->comps[ca->nr_comps - 1] = strdup(buf);
+ }
+ }
+ pclose(fp);
+ free(matched);
+}
+
void
uim_plugin_instance_init(void)
{
@@ -3334,11 +3461,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_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_3("skk-lib-get-completion", skk_get_completion);
+ uim_scm_init_subr_4("skk-lib-get-nth-completion", skk_get_nth_completion);
+ uim_scm_init_subr_3("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_3("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);
}
@@ -3379,8 +3506,6 @@
struct protoent *proto;
char *hostname;
- signal(SIGPIPE, SIG_IGN);
-
/* serv = getservbyname(SKK_SERVICENAME, "tcp"); */
memset((char*)&hostaddr, 0, sizeof(struct sockaddr_in));
if ((proto = getprotobyname("tcp")) == NULL) {
More information about the uim-commit
mailing list