(minput_config_file): Comment fixed for man-page.
[m17n/m17n-lib.git] / src / input.c
index 1b4d6f1..cd67276 100644 (file)
@@ -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)
 {
@@ -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,9 +666,7 @@ integer_value (MInputContext *ic, MPlist *arg, MPlist **value, int surrounding)
                                       mtext_len (ic->produced) + pos);
              return get_preceding_char (ic, - pos);
            }
-         else
-           pos--;
-         if (pos >= len)
+         else if (pos >= len)
            return get_following_char (ic, pos - len);
        }
       else
@@ -719,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);
@@ -817,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))
@@ -824,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))
@@ -1566,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))
@@ -3100,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)
@@ -3261,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);
@@ -3290,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)
@@ -3309,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)
@@ -4779,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 ¤òÊÖ¤¹¡£ */
@@ -5564,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 <tt>${HOME}/.m17n.d</tt> (${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
 
@@ -6178,7 +6192,8 @@ minput_get_commands (MSymbol language, MSymbol name)
     ¤³¤Î³ä¤êÅö¤Æ¤Ï¡¢³ä¤êÅö¤Æ°Ê¹ß¿·¤·¤¯¥ª¡¼¥×¥ó¤µ¤ì¤¿ÆþÎϥ᥽¥Ã¥É¤«¤éÍ­
     ¸ú¤Ë¤Ê¤ë¡£
 
-    @return ½èÍý¤¬À®¸ù¤¹¤ì¤Ð 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤·¡¢
+    @return 
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤·¡¢
     #merror_code ¤ò #MERROR_IM ¤ËÀßÄꤹ¤ë¡£  */
 
 int