X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=example%2Fmimx-anthy.c;h=997a7266fe8af70632ee7fed19131169dadf3086;hb=f585b4727a65159d539c8921b0c354c501cdb043;hp=518abb82606f3169156fbe6d812fde78736aa19a;hpb=1359a5c46aaaa266d1d6a0f30f2478a18e439b5c;p=m17n%2Fm17n-lib.git diff --git a/example/mimx-anthy.c b/example/mimx-anthy.c index 518abb8..997a726 100644 --- a/example/mimx-anthy.c +++ b/example/mimx-anthy.c @@ -1,4 +1,4 @@ -/* mimx-anthy.c -- Input method external module for Anthy. +/* mimx-anthy.c -- Anthy input method external module. -*- coding: euc-jp; -*- Copyright (C) 2003, 2004 National Institute of Advanced Industrial Science and Technology (AIST) Registration Number H15PRO112 @@ -17,11 +17,11 @@ You should have received a copy of the GNU Lesser General Public License along with the m17n library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 02111-1307, USA. */ /***en - @page mimx-anthy external module for the input method + @enpage mimx-anthy external module for the input method @section mimx-anthy-description DESCRIPTION @@ -59,12 +59,49 @@ @section mimx-anthy-seealso See also @ref mdbIM */ +/***ja + @japage mimx-anthy ÆþÎϥ᥽¥Ã¥É Íѳ°Éô¥â¥¸¥å¡¼¥ë. + + @section mimx-anthy-description DESCRIPTION + + ¶¦Í­¥é¥¤¥Ö¥é¥ê mimx-anthy.so ¤ÏÆþÎϥ᥽¥Ã¥É ¤ËÍѤ¤¤é¤ì + ¤ë³°Éô¥â¥¸¥å¡¼¥ë¤Ç¤¢¤ê¡¢°Ê²¼¤Î´Ø¿ô¤ò export ¤·¤Æ¤¤¤ë¡£ + +
    +
  • init + + ¥â¥¸¥å¡¼¥ë¤Î½é´ü²½¡£ + +
  • fini + + ¥â¥¸¥å¡¼¥ë¤Î½ªÎ»¡£ + +
  • convert + + ¸½ºß¤Î preedit ¥Æ¥­¥¹¥È (¤Ò¤é¤¬¤ÊÎó) ¤ò¤«¤Ê´Á»ú¥Æ¥­¥¹¥È¤ËÊÑ´¹¤¹¤ë¡£ + +
  • change + + ¸½ºß¤Î¥»¥°¥á¥ó¥È¤Î¸õÊä¤ÎÊÑÁ«¤òµ­Ï¿¤¹¤ë¡£ + +
  • resize + + ¸½ºß¤Î¥»¥°¥á¥ó¥È¤ÎŤµ¤òÊѹ¹¤¹¤ë¡£ + +
  • commit + + Á´¥»¥°¥á¥ó¥È¤ÎºÇ¿·¤Î¸õÊä¤ò¥³¥ß¥Ã¥È¤¹¤ë¡£ + +
+ + @section mimx-anthy-seealso »²¾È + @ref mdbIM +*/ #ifndef FOR_DOXYGEN #include #include -#include #include #ifdef HAVE_ANTHY @@ -77,6 +114,7 @@ static MSymbol Manthy, Msegment; /* A structure to record in MInputContext->plist with key Manthy. */ typedef struct { + MInputContext *ic; anthy_context_t ac; /* Which candidate is selected in each segment. */ int *candidate_numbers; @@ -89,22 +127,44 @@ typedef struct { static AnthyContext * new_context (MInputContext *ic) { - AnthyContext *context = NULL; + AnthyContext *context; + anthy_context_t ac; MSymbol euc_jp = msymbol ("euc-jp"); /* Rebound to an actual buffer just before being used. */ MConverter *converter = mconv_buffer_converter (euc_jp, NULL, 0); - if (converter) + if (! converter) + return NULL; + ac = anthy_create_context (); + if (! ac) + return NULL; + context = calloc (1, sizeof (AnthyContext)); + context->ic = ic; + context->ac = ac; + context->num_segments = 0; + context->candidate_numbers = NULL; + context->converter = converter; + return context; +} + +static AnthyContext * +get_context (MInputContext *ic) +{ + MPlist *plist = ic->plist; + AnthyContext *context; + + for (; plist && mplist_key (plist) != Mnil; plist = mplist_next (plist)) { - context = calloc (1, sizeof (AnthyContext)); - context->ac = anthy_create_context (); - context->num_segments = 0; - context->candidate_numbers = NULL; - context->converter = converter; + if (mplist_key (plist) != Manthy) + continue; + context = mplist_value (plist); + if (context->ic == ic) + return context; } - return context; + return NULL; } + static void free_context (AnthyContext *context) { @@ -180,15 +240,17 @@ MPlist * init (MPlist *args) { MInputContext *ic = mplist_value (args); + AnthyContext *context; - if (! initialized) + if (! initialized++) { anthy_init (); Manthy = msymbol (" anthy"); Msegment = msymbol (" segment"); - initialized = 1; } - mplist_push (ic->plist, Manthy, new_context (ic)); + context = new_context (ic); + if (context) + mplist_push (ic->plist, Manthy, context); return NULL; } @@ -196,7 +258,7 @@ MPlist * fini (MPlist *args) { MInputContext *ic = mplist_value (args); - AnthyContext *context = mplist_get (ic->plist, Manthy); + AnthyContext *context = get_context (ic); if (context) free_context (context); @@ -207,7 +269,7 @@ MPlist * convert (MPlist *args) { MInputContext *ic = mplist_value (args); - AnthyContext *context = mplist_get (ic->plist, Manthy); + AnthyContext *context = get_context (ic); struct anthy_conv_stat cs; MPlist *action, *actions; int i; @@ -245,7 +307,7 @@ MPlist * change (MPlist *args) { MInputContext *ic = mplist_value (args); - AnthyContext *context = mplist_get (ic->plist, Manthy); + AnthyContext *context = get_context (ic); int segment; if (! context) @@ -264,7 +326,7 @@ MPlist * resize (MPlist *args) { MInputContext *ic = mplist_value (args); - AnthyContext *context = mplist_get (ic->plist, Manthy); + AnthyContext *context = get_context (ic); struct anthy_conv_stat cs; MSymbol shorten; int segment; @@ -309,10 +371,12 @@ MPlist * commit (MPlist *args) { MInputContext *ic = mplist_value (args); - AnthyContext *context = mplist_get (ic->plist, Manthy); + AnthyContext *context = get_context (ic); struct anthy_conv_stat cs; int i; + if (! context) + return NULL; anthy_get_stat (context->ac, &cs); for (i = 0; i < cs.nr_segment; i++) anthy_commit_segment (context->ac, i, context->candidate_numbers[i]);