X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Finput.c;h=cd6727660aab245f56c5cc37f5409deedd272334;hb=7a7928899a9cbfcb8a439fd698857408c337a822;hp=fb2f224d274e8e848ffc5e40d0e6d869eef70571;hpb=abb137c1d368021f9f3ef62c801610b572f56672;p=m17n%2Fm17n-lib.git diff --git a/src/input.c b/src/input.c index fb2f224..cd67276 100644 --- a/src/input.c +++ b/src/input.c @@ -153,7 +153,7 @@ #include #endif -#include "m17n-gui.h" +#include "m17n.h" #include "m17n-misc.h" #include "internal.h" #include "mtext.h" @@ -163,7 +163,7 @@ #include "database.h" #include "charset.h" -static int mdebug_mask = MDEBUG_INPUT; +static int mdebug_flag = MDEBUG_INPUT; static int fully_initialized; @@ -489,6 +489,8 @@ marker_code (MSymbol sym, int surrounding) } +/* Return a plist containing an integer value of VAR. */ + static MPlist * resolve_variable (MInputContextInfo *ic_info, MSymbol var) { @@ -585,10 +587,10 @@ get_following_char (MInputContext *ic, int pos) if (ic_info->following_text) { len = mtext_nchars (ic_info->following_text); - if (pos <= len) - return mtext_ref_char (ic_info->following_text, pos - 1); + if (pos < len) + return mtext_ref_char (ic_info->following_text, pos); } - mt = get_surrounding_text (ic, pos); + mt = get_surrounding_text (ic, pos + 1); if (! mt) return -2; len = mtext_nchars (mt); @@ -604,9 +606,9 @@ get_following_char (MInputContext *ic, int pos) } else ic_info->following_text = mt; - if (pos > len) + if (pos >= len) return -1; - return mtext_ref_char (ic_info->following_text, pos - 1); + return mtext_ref_char (ic_info->following_text, pos); } static int @@ -625,15 +627,13 @@ surrounding_pos (MSymbol sym) } static int -integer_value (MInputContext *ic, MPlist *arg, MPlist **value, int surrounding) +integer_value (MInputContext *ic, MPlist *arg, int surrounding) { MInputContextInfo *ic_info = (MInputContextInfo *) ic->info; int code, pos; MText *preedit = ic->preedit; int len = mtext_nchars (preedit); - if (value) - *value = NULL; if (MPLIST_INTEGER_P (arg)) return MPLIST_INTEGER (arg); @@ -642,8 +642,6 @@ integer_value (MInputContext *ic, MPlist *arg, MPlist **value, int surrounding) { MPlist *val = resolve_variable (ic_info, MPLIST_SYMBOL (arg)); - if (value) - *value = val; return (MPLIST_INTEGER_P (val) ? MPLIST_INTEGER (val) : 0); } if (code == '@') @@ -657,7 +655,10 @@ integer_value (MInputContext *ic, MPlist *arg, MPlist **value, int surrounding) pos = atoi (name + 1); if (pos == 0) return get_preceding_char (ic, 0); - pos = ic->cursor_pos + pos; + if (pos < 0) + pos = ic->cursor_pos + pos; + else + pos = ic->cursor_pos + pos - 1; if (pos < 0) { if (ic->produced && mtext_len (ic->produced) + pos >= 0) @@ -665,8 +666,8 @@ integer_value (MInputContext *ic, MPlist *arg, MPlist **value, int surrounding) mtext_len (ic->produced) + pos); return get_preceding_char (ic, - pos); } - if (pos >= len) - return get_following_char (ic, pos - len + 1); + else if (pos >= len) + return get_following_char (ic, pos - len); } else pos = ic->cursor_pos + (code == '+' ? 1 : -1); @@ -717,7 +718,7 @@ resolve_expression (MInputContext *ic, MPlist *plist) if (MPLIST_INTEGER_P (plist)) return MPLIST_INTEGER (plist); if (MPLIST_SYMBOL_P (plist)) - return integer_value (ic, plist, NULL, 1); + return integer_value (ic, plist, 1); if (! MPLIST_PLIST_P (plist)) return 0; plist = MPLIST_PLIST (plist); @@ -815,6 +816,11 @@ parse_action_list (MPlist *plist, MPlist *macros) pl = MPLIST_NEXT (pl); + if (action_name == M_candidates) + { + /* This is an already regularised action. */ + continue; + } if (action_name == Minsert) { if (MPLIST_MTEXT_P (pl)) @@ -822,6 +828,13 @@ parse_action_list (MPlist *plist, MPlist *macros) if (mtext_nchars (MPLIST_MTEXT (pl)) == 0) MERROR (MERROR_IM, -1); } + else if (MPLIST_INTEGER_P (pl)) + { + int c = MPLIST_INTEGER (pl); + + if (c < 0 || c > MCHAR_MAX) + MERROR (MERROR_IM, -1); + } else if (MPLIST_PLIST_P (pl)) { MPLIST_DO (pl, MPLIST_PLIST (pl)) @@ -1564,6 +1577,8 @@ get_im_info (MSymbol language, MSymbol name, MSymbol extra, MSymbol key) im_info->cmds = mplist (); if (! im_info->vars) im_info->vars = mplist (); + if (! im_info->states) + im_info->states = mplist (); } if (! im_info->title && (key == Mnil || key == Mtitle)) @@ -2354,7 +2369,7 @@ shift_state (MInputContext *ic, MSymbol state_name) state = (MIMState *) MPLIST_VAL (im_info->states); } - if (mdebug__flag & mdebug_mask) + if (MDEBUG_FLAG ()) { if (orig_state) MDEBUG_PRINT2 ("\n [IM] [%s] (shift %s)\n", @@ -2486,7 +2501,10 @@ preedit_insert (MInputContext *ic, int pos, MText *mt, int c) else { mtext_ins_char (ic->preedit, pos, c, 1); - MDEBUG_PRINT1 ("('%c')", c); + if (c < 0x7F) + MDEBUG_PRINT1 ("('%c')", c); + else + MDEBUG_PRINT1 ("(U+%04X)", c); } adjust_markers (ic, pos, pos, nchars); ic->preedit_changed = 1; @@ -2537,7 +2555,7 @@ preedit_commit (MInputContext *ic, int need_prefix) mtext_put_prop_values (ic->preedit, 0, mtext_nchars (ic->preedit), Mcandidate_index, NULL, 0); mtext_cat (ic->produced, ic->preedit); - if (mdebug__flag & mdebug_mask) + if (MDEBUG_FLAG ()) { int i; @@ -3095,8 +3113,9 @@ take_action_list (MInputContext *ic, MPlist *action_list) to = 0; else if (to > len) to = len; + pos = to - ic->cursor_pos; } - MDEBUG_PRINT1 ("(%d)", to - ic->cursor_pos); + MDEBUG_PRINT1 ("(%d)", pos); if (to < ic->cursor_pos) preedit_delete (ic, to, ic->cursor_pos); else if (to > ic->cursor_pos) @@ -3256,7 +3275,7 @@ take_action_list (MInputContext *ic, MPlist *action_list) { int intarg = (MPLIST_TAIL_P (args) ? ic_info->used - 2 - : integer_value (ic, args, NULL, 0)); + : integer_value (ic, args, 0)); mtext_reset (ic->preedit); mtext_reset (ic_info->preedit_saved); @@ -3285,11 +3304,11 @@ take_action_list (MInputContext *ic, MPlist *action_list) || name == Mmul || name == Mdiv) { MSymbol sym = MPLIST_SYMBOL (args); + MPlist *value = resolve_variable (ic_info, sym); int val1, val2; - MPlist *value; char *op; - val1 = integer_value (ic, args, &value, 0); + val1 = MPLIST_INTEGER (value); args = MPLIST_NEXT (args); val2 = resolve_expression (ic, args); if (name == Mset) @@ -3304,8 +3323,7 @@ take_action_list (MInputContext *ic, MPlist *action_list) val1 /= val2, op = "/="; MDEBUG_PRINT4 ("(%s %s 0x%X(%d))", MSYMBOL_NAME (sym), op, val1, val1); - if (value) - mplist_set (value, Minteger, (void *) val1); + mplist_set (value, Minteger, (void *) val1); } else if (name == Mequal || name == Mless || name == Mgreater || name == Mless_equal || name == Mgreater_equal) @@ -3845,7 +3863,7 @@ filter (MInputContext *ic, MSymbol key, void *arg) if (mtext_nchars (ic->produced) > 0) { - if (mdebug__flag & mdebug_mask) + if (MDEBUG_FLAG ()) { MDEBUG_PRINT1 ("\n [IM] [%s] (produced", MSYMBOL_NAME (ic_info->state->name)); @@ -4774,7 +4792,8 @@ minput_get_title_icon (MSymbol language, MSymbol name) ´Ø¿ô minput_get_description () ¤Ï¡¢$LANGUAGE ¤È $NAME ¤Ë¤è¤Ã¤Æ»ØÄê ¤µ¤ì¤¿ÆþÎϥ᥽¥Ã¥É¤òÀâÌÀ¤¹¤ë M-text ¤òÊÖ¤¹¡£ - @return »ØÄꤵ¤ì¤¿ÆþÎϥ᥽¥Ã¥É¤¬ÀâÌÀ¤¹¤ë¥Æ¥­¥¹¥È¤ò»ý¤Ã¤Æ¤¤¤ì¤Ð¡¢ + @return + »ØÄꤵ¤ì¤¿ÆþÎϥ᥽¥Ã¥É¤¬ÀâÌÀ¤¹¤ë¥Æ¥­¥¹¥È¤ò»ý¤Ã¤Æ¤¤¤ì¤Ð¡¢ #MText ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¸Æ¤Ó½Ð¤·Â¦¤Ï¡¢¤½¤ì¤ò m17n_object_unref () ¤òÍѤ¤¤Æ²òÊü¤·¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£ÆþÎϥ᥽¥Ã¥É¤ËÀâÌÀ¥Æ¥­¥¹¥È¤¬Ìµ¤± ¤ì¤Ð@c NULL ¤òÊÖ¤¹¡£ */ @@ -5559,12 +5578,12 @@ minput_config_variable (MSymbol language, MSymbol name, MSymbol variable, The minput_config_file () function returns the absolute path name of per-user customization file into which minput_save_config () - save configurations. It is usually @c "config.mic" under the - directory @c ".m17n.d" of user's home directory. It is not assured - that the file of the returned name exists nor is - readable/writable. If minput_save_config () fails and returns -1, - an application program might check the file, make it - writable (if possible), and try minput_save_config () again. + save configurations. It is usually @c config.mic under the + directory ${HOME}/.m17n.d (${HOME} is user's home + directory). It is not assured that the file of the returned name + exists nor is readable/writable. If minput_save_config () fails + and returns -1, an application program might check the file, make + it writable (if possible), and try minput_save_config () again. @return @@ -6173,7 +6192,8 @@ minput_get_commands (MSymbol language, MSymbol name) ¤³¤Î³ä¤êÅö¤Æ¤Ï¡¢³ä¤êÅö¤Æ°Ê¹ß¿·¤·¤¯¥ª¡¼¥×¥ó¤µ¤ì¤¿ÆþÎϥ᥽¥Ã¥É¤«¤éÍ­ ¸ú¤Ë¤Ê¤ë¡£ - @return ½èÍý¤¬À®¸ù¤¹¤ì¤Ð 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤·¡¢ + @return + ½èÍý¤¬À®¸ù¤¹¤ì¤Ð 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤·¡¢ #merror_code ¤ò #MERROR_IM ¤ËÀßÄꤹ¤ë¡£ */ int