-/* 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
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 <ja, anthy>
+ @enpage mimx-anthy external module for the input method <ja, anthy>
@section mimx-anthy-description DESCRIPTION
@section mimx-anthy-seealso See also
@ref mdbIM
*/
+/***ja
+ @japage mimx-anthy ÆþÎϥ᥽¥Ã¥É <ja, anthy> Íѳ°Éô¥â¥¸¥å¡¼¥ë.
+
+ @section mimx-anthy-description DESCRIPTION
+
+ ¶¦Í¥é¥¤¥Ö¥é¥ê mimx-anthy.so ¤ÏÆþÎϥ᥽¥Ã¥É<ja, anthy> ¤ËÍѤ¤¤é¤ì
+ ¤ë³°Éô¥â¥¸¥å¡¼¥ë¤Ç¤¢¤ê¡¢°Ê²¼¤Î´Ø¿ô¤ò export ¤·¤Æ¤¤¤ë¡£
+
+ <ul>
+ <li> init
+
+ ¥â¥¸¥å¡¼¥ë¤Î½é´ü²½¡£
+
+ <li> fini
+
+ ¥â¥¸¥å¡¼¥ë¤Î½ªÎ»¡£
+
+ <li> convert
+
+ ¸½ºß¤Î preedit ¥Æ¥¥¹¥È (¤Ò¤é¤¬¤ÊÎó) ¤ò¤«¤Ê´Á»ú¥Æ¥¥¹¥È¤ËÊÑ´¹¤¹¤ë¡£
+
+ <li> change
+
+ ¸½ºß¤Î¥»¥°¥á¥ó¥È¤Î¸õÊä¤ÎÊÑÁ«¤òµÏ¿¤¹¤ë¡£
+
+ <li> resize
+
+ ¸½ºß¤Î¥»¥°¥á¥ó¥È¤ÎŤµ¤òÊѹ¹¤¹¤ë¡£
+
+ <li> commit
+
+ Á´¥»¥°¥á¥ó¥È¤ÎºÇ¿·¤Î¸õÊä¤ò¥³¥ß¥Ã¥È¤¹¤ë¡£
+
+ </ul>
+
+ @section mimx-anthy-seealso »²¾È
+ @ref mdbIM
+*/
#ifndef FOR_DOXYGEN
#include <stdio.h>
#include <string.h>
-#include <config.h>
#include <m17n.h>
#ifdef HAVE_ANTHY
/* 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;
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)
{
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;
}
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);
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;
change (MPlist *args)
{
MInputContext *ic = mplist_value (args);
- AnthyContext *context = mplist_get (ic->plist, Manthy);
+ AnthyContext *context = get_context (ic);
int segment;
if (! context)
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;
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]);