[uim-commit] r393 - in trunk: scm uim
ekato at freedesktop.org
ekato at freedesktop.org
Sat Jan 29 22:36:12 PST 2005
Author: ekato
Date: 2005-01-29 22:35:57 -0800 (Sat, 29 Jan 2005)
New Revision: 393
Modified:
trunk/scm/skk-custom.scm
trunk/scm/skk.scm
trunk/uim/skk-dic.c
Log:
* scm/skk-custom.scm (skk-show-annotation-in-preedit?) : New
custom variable. Default is #f.
* scm/skk.scm (skk-prepare-commit-string) : Evaluate candidate
string which contains 'concat'.
(skk-do-update-preedit) : Ditto. Check condition of
skk-show-annotation-in-preedit?
(skk-get-candidate-handler) : Evaluate 'concat'.
* uim/skk-dic.c : Stop including "uim-compat-scm.h".
(next_slash) : Renamed to next_cand_slash.
(next_cand_slash) : Renamed from next_slash. Locate the starting
point (slash) of next candidate.
(next_slash_in_bracket) : New. Locale next slash.
(okuri_in_bracket) : Use next_slash_in_bracket().
(nth_candidate) : Use next_cand_slash().
(skk_commit_candidate) : Also reorder base candidate array even if
candidate array with okuri string exists.
(quote_word) : New. Replace some words using 'concat'.
(sanitize_word) : Don't ignore some words to be registered in
personal dictionary. Word with space and parenthesis is allowed
except the words are composed by space only.
(skk_lib_get_annotation) : Don't assume the word as annotation if
it is ended with colon.
(skk_lib_remove_annotataion) : Ditto.
(skk_eval_candidate) : New. Evaluate 'concat' emacs lisp.
(uim_plugin_instance_init) : Export skk_eval_candidate as
skk-lib-eval-candidate to scheme.
Modified: trunk/scm/skk-custom.scm
===================================================================
--- trunk/scm/skk-custom.scm 2005-01-29 22:30:19 UTC (rev 392)
+++ trunk/scm/skk-custom.scm 2005-01-30 06:35:57 UTC (rev 393)
@@ -114,6 +114,13 @@
(_ "Show annotation in candidate window")
(_ "long description will be here."))
+(define-custom 'skk-show-annotation-in-preedit? #f
+ '(skk advanced)
+ '(boolean)
+ (_ "Show annotation in preedit area")
+ (_ "long description will be here."))
+
+
(define-custom 'skk-dic-file-name (string-append (sys-datadir)
"/skk/SKK-JISYO.L")
'(skk)
Modified: trunk/scm/skk.scm
===================================================================
--- trunk/scm/skk.scm 2005-01-29 22:30:19 UTC (rev 392)
+++ trunk/scm/skk.scm 2005-01-30 06:35:57 UTC (rev 393)
@@ -513,7 +513,7 @@
(define skk-prepare-commit-string
(lambda (sc)
- (let* ((cand (skk-lib-remove-annotation (skk-get-current-candidate sc)))
+ (let* ((cand (skk-lib-eval-candidate (skk-lib-remove-annotation (skk-get-current-candidate sc))))
(okuri (skk-make-string (skk-context-okuri sc)
(skk-context-kana-mode sc)))
(appendix (skk-make-string (skk-context-appendix sc)
@@ -661,7 +661,9 @@
sc
(bit-or skk-preedit-attr-conv-body
preedit-cursor)
- (skk-lib-remove-annotation (skk-get-current-candidate sc)))
+ (if skk-show-annotation-in-preedit?
+ (skk-lib-eval-candidate (skk-get-current-candidate sc))
+ (skk-lib-eval-candidate (skk-lib-remove-annotation (skk-get-current-candidate sc)))))
(im-pushback-preedit
sc skk-preedit-attr-conv-okuri
(skk-make-string (skk-context-okuri sc)
@@ -1601,7 +1603,7 @@
(define skk-get-candidate-handler
(lambda (sc idx)
(let* ((dcsc (skk-find-descendant-context sc))
- (cand (skk-get-nth-candidate dcsc idx))
+ (cand (skk-lib-eval-candidate (skk-get-nth-candidate dcsc idx)))
(okuri (skk-context-okuri dcsc)))
(list
(if (and
Modified: trunk/uim/skk-dic.c
===================================================================
--- trunk/uim/skk-dic.c 2005-01-29 22:30:19 UTC (rev 392)
+++ trunk/uim/skk-dic.c 2005-01-30 06:35:57 UTC (rev 393)
@@ -47,7 +47,6 @@
#include <ctype.h>
#include "uim-scm.h"
-#include "uim-compat-scm.h"
#include "context.h"
#include "plugin.h"
@@ -283,22 +282,31 @@
}
static char *
-next_slash(char *str)
+next_cand_slash(char *str)
{
int p = 0;
while (*str && (*str != '/' || p == 1)) {
- if (*str == '[') {
+ if (*str == '[' && (*(str - 1) == '\0' || *(str - 1) == '/')) {
p = 1;
}
- if (p == 1 && *str == ']') {
+ if (p == 1 && *str == ']' && *(str + 1) == '/') {
p = 0;
}
- str ++;
+ str++;
}
return str;
}
static char *
+next_slash_in_bracket(char *str)
+{
+ while (*str && *str != '/')
+ str++;
+
+ return str;
+}
+
+static char *
okuri_in_bracket(char *str)
{
char *p, *term;
@@ -307,7 +315,7 @@
return NULL;
p = strdup(str);
- term = next_slash(p);
+ term = next_slash_in_bracket(p);
*term = '\0';
return p;
}
@@ -321,7 +329,7 @@
str = first_space(str);
for (i = 0; i <= nth; i++) {
- str = next_slash(str);
+ str = next_cand_slash(str);
if (*str == '/') {
str++;
}
@@ -333,8 +341,8 @@
str++;
}
p = strdup(str);
- term = next_slash(p);
- *term = 0;
+ term = next_cand_slash(p);
+ *term = '\0';
return p;
}
@@ -445,7 +453,7 @@
tmp = nth_candidate(line, nth);
if (tmp && strlen(tmp)) {
if (tmp[0] == '[') {
- tmp[0] = ' ';
+ tmp[0] = ' '; /* create first_space */
compose_line_parts(di, sl, okuri_in_bracket(&tmp[1]), &tmp[0]);
} else if (tmp[0] != ']') {
push_back_candidate_to_array(ca, tmp);
@@ -1509,6 +1517,9 @@
if (!found) {
ca = find_cand_array_lisp(head_, okuri_head_, okuri_, 1);
reorder_candidate(ca, str);
+ } else {
+ /* also reorder base candidate array */
+ reorder_candidate(&sl->cands[0], str);
}
}
@@ -1535,17 +1546,88 @@
}
static char *
+quote_word(const char *word)
+{
+ char *str;
+ const char *tmp;
+ int len;
+
+ str= strdup("(concat \"");
+ for (tmp = word; *tmp; tmp++) {
+ len = strlen(str);
+
+ switch(*tmp) {
+ case '/':
+ str = realloc(str, len + strlen("\\057") + 1);
+ strcat(str, "\\057");
+ break;
+ case '[':
+ str = realloc(str, len + strlen("[") + 1);
+ strcat(str, "[");
+ break;
+ case ']':
+ str = realloc(str, len + strlen("]") + 1);
+ strcat(str, "]");
+ break;
+ case '\n':
+ str = realloc(str, len + strlen("\\n") + 1);
+ strcat(str, "\\n");
+ break;
+ case '\r':
+ str = realloc(str, len + strlen("\\r") + 1);
+ strcat(str, "\\r");
+ break;
+ case '\\':
+ str = realloc(str, len + strlen("\\\\") + 1);
+ strcat(str, "\\\\");
+ break;
+ case ';':
+ str = realloc(str, len + strlen("\\073") + 1);
+ strcat(str, "\\073");
+ break;
+ default:
+ str = realloc(str, len + 2);
+ str[len] = *tmp;
+ str[len + 1] = '\0';
+ break;
+ }
+ }
+ len = strlen(str);
+ str = realloc(str, len + strlen("\")") + 1);
+ strcat(str, "\")");
+
+ return str;
+}
+
+static char *
sanitize_word(const char *arg)
{
const char *tmp;
+ int is_space_only = 1;
+
if (!arg || !strlen(arg)) {
return NULL;
}
for (tmp = arg; *tmp; tmp++) {
- if (strchr(" /[]()\n", *tmp)) {
- return NULL;
+ switch(*tmp) {
+ case '/':
+ case '[':
+ case ']':
+ case '\n':
+ case '\r':
+ case '\\':
+ case ';':
+ return quote_word(arg);
+ case ' ':
+ break;
+ default:
+ is_space_only = 0;
+ break;
}
}
+ if (is_space_only)
+ return NULL;
+
return strdup(arg);
}
@@ -1594,7 +1676,7 @@
if (sep == buf) {
return ;
}
- *sep = 0;
+ *sep = '\0';
if (!islower(buf[0]) && islower(sep[-1])) { /* okuri-ari entry */
char okuri_head = sep[-1];
sep[-1] = 0;
@@ -1633,6 +1715,7 @@
{
struct skk_cand_array *ca;
int i;
+
fprintf(fp, "%s", sl->head);
if (sl->okuri_head) {
fprintf(fp, "%c /", sl->okuri_head);
@@ -2007,8 +2090,7 @@
str = uim_scm_refer_c_str(str_);
sep = strrchr(str, ';');
- if (sep) {
- sep++;
+ if (sep && (*(++sep) != '\0')) {
res = uim_scm_make_str(sep);
} else {
res = uim_scm_make_str("");
@@ -2027,14 +2109,68 @@
str = uim_scm_c_str(str_);
sep = strrchr(str, ';');
- if (sep) {
- *sep = 0;
+ if (sep && (*(sep + 1) != '\0')) {
+ *sep = '\0';
}
res = uim_scm_make_str(str);
free(str);
return res;
}
+static uim_lisp
+skk_eval_candidate(uim_lisp str_)
+{
+ const char *cand, *return_val;
+ char *p, *q, *str;
+ size_t len;
+ uim_lisp cand_;
+
+ if (str_ == uim_scm_null_list())
+ return uim_scm_null_list();
+
+ cand = uim_scm_refer_c_str(str_);
+
+ /* eval concat only for now */
+ if ((p = strstr(cand, "(concat")) == NULL)
+ return str_;
+
+ /* check close paren */
+ q = strrchr(p, ')');
+ if (!q)
+ return str_;
+
+ /* ignore make-string */
+ if (strstr(p, "make-string"))
+ return str_;
+
+ len = q - p + 1;
+ /* replace elisp's concat with string-append */
+ str = malloc(len + strlen("string-append") - strlen("concat") + 1);
+ strcpy(str, "(string-append");
+ strncat(str, p + strlen("(concat"), q - (p + strlen("(concat")) + 1);
+
+ UIM_EVAL_FSTRING1(NULL, "%s", str);
+ return_val = uim_scm_refer_c_str(uim_scm_return_value());
+
+ /* get evaluated candidate */
+ len = p - cand + strlen(return_val);
+ if (len > strlen(str))
+ str = realloc(str, len + 1);
+
+ if (p != cand) {
+ strncpy(str, cand, p - cand);
+ str[p - cand] = '\0';
+ strcat(str, return_val);
+ } else {
+ strcpy(str, return_val);
+ }
+
+ cand_ = uim_scm_make_str(str);
+ free(str);
+ return cand_;
+}
+
+
void
uim_plugin_instance_init(void)
{
@@ -2055,6 +2191,7 @@
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-eval-candidate", skk_eval_candidate);
}
void
More information about the Uim-commit
mailing list