summaryrefslogtreecommitdiff
path: root/src-util
diff options
context:
space:
mode:
Diffstat (limited to 'src-util')
-rw-r--r--src-util/Makefile.am32
-rw-r--r--src-util/Makefile.in764
-rw-r--r--src-util/agent.c1153
-rw-r--r--src-util/anthy-azik.el233
-rw-r--r--src-util/anthy-conf.el122
-rw-r--r--src-util/anthy-dic.el132
-rw-r--r--src-util/anthy-isearch.el102
-rw-r--r--src-util/anthy-kyuri.el210
-rw-r--r--src-util/anthy.el930
-rw-r--r--src-util/anthy.i251
-rw-r--r--src-util/convdb.c542
-rw-r--r--src-util/dic-tool-usage.txt30
-rw-r--r--src-util/dic-tool.c448
-rw-r--r--src-util/egg.c551
-rw-r--r--src-util/input.c1543
-rw-r--r--src-util/leim-list.el7
-rw-r--r--src-util/morph-main.c154
-rw-r--r--src-util/rkconv.c791
-rw-r--r--src-util/rkconv.h51
-rw-r--r--src-util/rkhelper.c442
-rw-r--r--src-util/rkhelper.h41
-rw-r--r--src-util/rkmap.h954
-rw-r--r--src-util/typetab477
23 files changed, 9960 insertions, 0 deletions
diff --git a/src-util/Makefile.am b/src-util/Makefile.am
new file mode 100644
index 0000000..8dd7710
--- /dev/null
+++ b/src-util/Makefile.am
@@ -0,0 +1,32 @@
+## $Id: Makefile.am,v 1.10 2002/08/08 07:20:45 gniibe Exp $
+
+SUBDIRS =
+
+# Files
+# Dictionary utilities
+ELISP_FILES = anthy.el anthy-dic.el anthy-conf.el leim-list.el \
+ anthy-isearch.el anthy-azik.el anthy-kyuri.el
+EXTRA_DIST = $(ELISP_FILES) typetab dic-tool-usage.txt anthy.i
+bin_PROGRAMS = anthy-dic-tool anthy-agent anthy-morphological-analyzer
+ELCFILES = anthy.elc anthy-dic.elc anthy-azik.elc anthy-conf.elc anthy-isearch.elc anthy-kyuri.elc leim-list.elc
+if ELISP
+lisp_LISP = $(ELISP_FILES)
+endif
+
+noinst_LTLIBRARIES = libconvdb.la
+libconvdb_la_SOURCES = convdb.c
+
+INCLUDES = -I$(top_srcdir)/
+anthy_dic_tool_SOURCES = dic-tool.c
+anthy_dic_tool_LDADD = ../src-worddic/libanthydic.la
+anthy_agent_SOURCES = agent.c egg.c
+anthy_agent_LDADD = libanthyinput.la ../src-main/libanthy.la ../src-worddic/libanthydic.la
+anthy_morphological_analyzer_SOURCES= morph-main.c
+anthy_morphological_analyzer_LDADD = libconvdb.la ../src-main/libanthy.la ../src-worddic/libanthydic.la
+
+lib_LTLIBRARIES = libanthyinput.la
+libanthyinput_la_SOURCES = input.c rkconv.c rkhelper.c\
+ rkconv.h rkmap.h rkhelper.h
+libanthyinput_la_LIBADD = ../src-main/libanthy.la ../src-worddic/libanthydic.la
+
+pkgdata_DATA = typetab dic-tool-usage.txt
diff --git a/src-util/Makefile.in b/src-util/Makefile.in
new file mode 100644
index 0000000..ae85a65
--- /dev/null
+++ b/src-util/Makefile.in
@@ -0,0 +1,764 @@
+# Makefile.in generated by automake 1.9.6 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+
+
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+top_builddir = ..
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+INSTALL = @INSTALL@
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+bin_PROGRAMS = anthy-dic-tool$(EXEEXT) anthy-agent$(EXEEXT) \
+ anthy-morphological-analyzer$(EXEEXT)
+subdir = src-util
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
+am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \
+ "$(DESTDIR)$(lispdir)" "$(DESTDIR)$(pkgdatadir)"
+libLTLIBRARIES_INSTALL = $(INSTALL)
+LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES)
+libanthyinput_la_DEPENDENCIES = ../src-main/libanthy.la \
+ ../src-worddic/libanthydic.la
+am_libanthyinput_la_OBJECTS = input.lo rkconv.lo rkhelper.lo
+libanthyinput_la_OBJECTS = $(am_libanthyinput_la_OBJECTS)
+libconvdb_la_LIBADD =
+am_libconvdb_la_OBJECTS = convdb.lo
+libconvdb_la_OBJECTS = $(am_libconvdb_la_OBJECTS)
+binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
+PROGRAMS = $(bin_PROGRAMS)
+am_anthy_agent_OBJECTS = agent.$(OBJEXT) egg.$(OBJEXT)
+anthy_agent_OBJECTS = $(am_anthy_agent_OBJECTS)
+anthy_agent_DEPENDENCIES = libanthyinput.la ../src-main/libanthy.la \
+ ../src-worddic/libanthydic.la
+am_anthy_dic_tool_OBJECTS = dic-tool.$(OBJEXT)
+anthy_dic_tool_OBJECTS = $(am_anthy_dic_tool_OBJECTS)
+anthy_dic_tool_DEPENDENCIES = ../src-worddic/libanthydic.la
+am_anthy_morphological_analyzer_OBJECTS = morph-main.$(OBJEXT)
+anthy_morphological_analyzer_OBJECTS = \
+ $(am_anthy_morphological_analyzer_OBJECTS)
+anthy_morphological_analyzer_DEPENDENCIES = libconvdb.la \
+ ../src-main/libanthy.la ../src-worddic/libanthydic.la
+DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+SOURCES = $(libanthyinput_la_SOURCES) $(libconvdb_la_SOURCES) \
+ $(anthy_agent_SOURCES) $(anthy_dic_tool_SOURCES) \
+ $(anthy_morphological_analyzer_SOURCES)
+DIST_SOURCES = $(libanthyinput_la_SOURCES) $(libconvdb_la_SOURCES) \
+ $(anthy_agent_SOURCES) $(anthy_dic_tool_SOURCES) \
+ $(anthy_morphological_analyzer_SOURCES)
+RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
+ html-recursive info-recursive install-data-recursive \
+ install-exec-recursive install-info-recursive \
+ install-recursive installcheck-recursive installdirs-recursive \
+ pdf-recursive ps-recursive uninstall-info-recursive \
+ uninstall-recursive
+lispLISP_INSTALL = $(INSTALL_DATA)
+LISP = $(lisp_LISP)
+am__ELFILES = anthy-azik.el anthy-conf.el anthy-dic.el \
+ anthy-isearch.el anthy-kyuri.el anthy.el leim-list.el
+am__ELCFILES = $(am__ELFILES:.el=.elc)
+elisp_comp = $(top_srcdir)/elisp-comp
+pkgdataDATA_INSTALL = $(INSTALL_DATA)
+DATA = $(pkgdata_DATA)
+ETAGS = etags
+CTAGS = ctags
+DIST_SUBDIRS = $(SUBDIRS)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMDEP_FALSE = @AMDEP_FALSE@
+AMDEP_TRUE = @AMDEP_TRUE@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+ECHO = @ECHO@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ELISP_FALSE = @ELISP_FALSE@
+ELISP_TRUE = @ELISP_TRUE@
+EMACS = @EMACS@
+EMACSLOADPATH = @EMACSLOADPATH@
+EXEEXT = @EXEEXT@
+F77 = @F77@
+FFLAGS = @FFLAGS@
+GREP = @GREP@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_F77 = @ac_ct_F77@
+am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
+am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
+am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
+am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+lispdir = @lispdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+SUBDIRS =
+
+# Files
+# Dictionary utilities
+ELISP_FILES = anthy.el anthy-dic.el anthy-conf.el leim-list.el \
+ anthy-isearch.el anthy-azik.el anthy-kyuri.el
+
+EXTRA_DIST = $(ELISP_FILES) typetab dic-tool-usage.txt anthy.i
+ELCFILES = anthy.elc anthy-dic.elc anthy-azik.elc anthy-conf.elc anthy-isearch.elc anthy-kyuri.elc leim-list.elc
+@ELISP_TRUE@lisp_LISP = $(ELISP_FILES)
+noinst_LTLIBRARIES = libconvdb.la
+libconvdb_la_SOURCES = convdb.c
+INCLUDES = -I$(top_srcdir)/
+anthy_dic_tool_SOURCES = dic-tool.c
+anthy_dic_tool_LDADD = ../src-worddic/libanthydic.la
+anthy_agent_SOURCES = agent.c egg.c
+anthy_agent_LDADD = libanthyinput.la ../src-main/libanthy.la ../src-worddic/libanthydic.la
+anthy_morphological_analyzer_SOURCES = morph-main.c
+anthy_morphological_analyzer_LDADD = libconvdb.la ../src-main/libanthy.la ../src-worddic/libanthydic.la
+lib_LTLIBRARIES = libanthyinput.la
+libanthyinput_la_SOURCES = input.c rkconv.c rkhelper.c\
+ rkconv.h rkmap.h rkhelper.h
+
+libanthyinput_la_LIBADD = ../src-main/libanthy.la ../src-worddic/libanthydic.la
+pkgdata_DATA = typetab dic-tool-usage.txt
+all: all-recursive
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src-util/Makefile'; \
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu src-util/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+install-libLTLIBRARIES: $(lib_LTLIBRARIES)
+ @$(NORMAL_INSTALL)
+ test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)"
+ @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
+ if test -f $$p; then \
+ f=$(am__strip_dir) \
+ echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
+ $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
+ else :; fi; \
+ done
+
+uninstall-libLTLIBRARIES:
+ @$(NORMAL_UNINSTALL)
+ @set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \
+ p=$(am__strip_dir) \
+ echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
+ $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
+ done
+
+clean-libLTLIBRARIES:
+ -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
+ @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
+ dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+ test "$$dir" != "$$p" || dir=.; \
+ echo "rm -f \"$${dir}/so_locations\""; \
+ rm -f "$${dir}/so_locations"; \
+ done
+
+clean-noinstLTLIBRARIES:
+ -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+ @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \
+ dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+ test "$$dir" != "$$p" || dir=.; \
+ echo "rm -f \"$${dir}/so_locations\""; \
+ rm -f "$${dir}/so_locations"; \
+ done
+libanthyinput.la: $(libanthyinput_la_OBJECTS) $(libanthyinput_la_DEPENDENCIES)
+ $(LINK) -rpath $(libdir) $(libanthyinput_la_LDFLAGS) $(libanthyinput_la_OBJECTS) $(libanthyinput_la_LIBADD) $(LIBS)
+libconvdb.la: $(libconvdb_la_OBJECTS) $(libconvdb_la_DEPENDENCIES)
+ $(LINK) $(libconvdb_la_LDFLAGS) $(libconvdb_la_OBJECTS) $(libconvdb_la_LIBADD) $(LIBS)
+install-binPROGRAMS: $(bin_PROGRAMS)
+ @$(NORMAL_INSTALL)
+ test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"
+ @list='$(bin_PROGRAMS)'; for p in $$list; do \
+ p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
+ if test -f $$p \
+ || test -f $$p1 \
+ ; then \
+ f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
+ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
+ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
+ else :; fi; \
+ done
+
+uninstall-binPROGRAMS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(bin_PROGRAMS)'; for p in $$list; do \
+ f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
+ echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
+ rm -f "$(DESTDIR)$(bindir)/$$f"; \
+ done
+
+clean-binPROGRAMS:
+ @list='$(bin_PROGRAMS)'; for p in $$list; do \
+ f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f $$p $$f"; \
+ rm -f $$p $$f ; \
+ done
+anthy-agent$(EXEEXT): $(anthy_agent_OBJECTS) $(anthy_agent_DEPENDENCIES)
+ @rm -f anthy-agent$(EXEEXT)
+ $(LINK) $(anthy_agent_LDFLAGS) $(anthy_agent_OBJECTS) $(anthy_agent_LDADD) $(LIBS)
+anthy-dic-tool$(EXEEXT): $(anthy_dic_tool_OBJECTS) $(anthy_dic_tool_DEPENDENCIES)
+ @rm -f anthy-dic-tool$(EXEEXT)
+ $(LINK) $(anthy_dic_tool_LDFLAGS) $(anthy_dic_tool_OBJECTS) $(anthy_dic_tool_LDADD) $(LIBS)
+anthy-morphological-analyzer$(EXEEXT): $(anthy_morphological_analyzer_OBJECTS) $(anthy_morphological_analyzer_DEPENDENCIES)
+ @rm -f anthy-morphological-analyzer$(EXEEXT)
+ $(LINK) $(anthy_morphological_analyzer_LDFLAGS) $(anthy_morphological_analyzer_OBJECTS) $(anthy_morphological_analyzer_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/agent.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/convdb.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dic-tool.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/egg.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/input.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/morph-main.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rkconv.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rkhelper.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+distclean-libtool:
+ -rm -f libtool
+uninstall-info-am:
+
+elc-stamp: $(LISP)
+ @echo 'WARNING: Warnings can be ignored. :-)'
+ @rm -f elc-temp && touch elc-temp
+ if test "$(EMACS)" != no; then \
+ set x; \
+ list='$(LISP)'; for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ set x "$$@" "$$d$$p"; shift; \
+ done; \
+ shift; \
+ EMACS="$(EMACS)" $(SHELL) $(elisp_comp) "$$@" || exit 1; \
+ else : ; fi
+ @mv -f elc-temp $@
+$(am__ELCFILES): elc-stamp
+ @if test "$(EMACS)" != no && test ! -f $@; then \
+ trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
+ if mkdir elc-lock 2>/dev/null; then \
+ rm -f elc-stamp; \
+ $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
+ rmdir elc-lock; \
+ else \
+ while test -d elc-lock; do sleep 1; done; \
+ test -f elc-stamp; exit $$?; \
+ fi; \
+ else : ; fi
+install-lispLISP: $(lisp_LISP) $(ELCFILES)
+ @$(NORMAL_INSTALL)
+ @if test "$(EMACS)" != no; then \
+ test -z "$(lispdir)" || $(mkdir_p) "$(DESTDIR)$(lispdir)"; \
+ list='$(lisp_LISP)'; for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ f=$(am__strip_dir) \
+ echo " $(lispLISP_INSTALL) '$$d$$p' '$(DESTDIR)$(lispdir)/$$f'"; \
+ $(lispLISP_INSTALL) "$$d$$p" "$(DESTDIR)$(lispdir)/$$f"; \
+ if test -f $${p}c; then \
+ echo " $(lispLISP_INSTALL) '$${p}c' '$(DESTDIR)$(lispdir)/$${f}c'"; \
+ $(lispLISP_INSTALL) "$${p}c" "$(DESTDIR)$(lispdir)/$${f}c"; \
+ else : ; fi; \
+ done; \
+ else : ; fi
+
+uninstall-lispLISP:
+ @$(NORMAL_UNINSTALL)
+ @if test "$(EMACS)" != no; then \
+ list='$(lisp_LISP)'; for p in $$list; do \
+ f=$(am__strip_dir) \
+ echo " rm -f '$(DESTDIR)$(lispdir)/$$f' '$(DESTDIR)$(lispdir)/$${f}c'"; \
+ rm -f "$(DESTDIR)$(lispdir)/$$f" "$(DESTDIR)$(lispdir)/$${f}c"; \
+ done; \
+ else : ; fi
+
+clean-lisp:
+ -rm -f elc-stamp $(ELCFILES)
+install-pkgdataDATA: $(pkgdata_DATA)
+ @$(NORMAL_INSTALL)
+ test -z "$(pkgdatadir)" || $(mkdir_p) "$(DESTDIR)$(pkgdatadir)"
+ @list='$(pkgdata_DATA)'; for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ f=$(am__strip_dir) \
+ echo " $(pkgdataDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(pkgdatadir)/$$f'"; \
+ $(pkgdataDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(pkgdatadir)/$$f"; \
+ done
+
+uninstall-pkgdataDATA:
+ @$(NORMAL_UNINSTALL)
+ @list='$(pkgdata_DATA)'; for p in $$list; do \
+ f=$(am__strip_dir) \
+ echo " rm -f '$(DESTDIR)$(pkgdatadir)/$$f'"; \
+ rm -f "$(DESTDIR)$(pkgdatadir)/$$f"; \
+ done
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run `make' without going through this Makefile.
+# To change the values of `make' variables: instead of editing Makefiles,
+# (1) if the variable is set in `config.status', edit `config.status'
+# (which will cause the Makefiles to be regenerated when you run `make');
+# (2) otherwise, pass the desired values on the `make' command line.
+$(RECURSIVE_TARGETS):
+ @failcom='exit 1'; \
+ for f in x $$MAKEFLAGS; do \
+ case $$f in \
+ *=* | --[!k]*);; \
+ *k*) failcom='fail=yes';; \
+ esac; \
+ done; \
+ dot_seen=no; \
+ target=`echo $@ | sed s/-recursive//`; \
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ echo "Making $$target in $$subdir"; \
+ if test "$$subdir" = "."; then \
+ dot_seen=yes; \
+ local_target="$$target-am"; \
+ else \
+ local_target="$$target"; \
+ fi; \
+ (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+ || eval $$failcom; \
+ done; \
+ if test "$$dot_seen" = "no"; then \
+ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+ fi; test -z "$$fail"
+
+mostlyclean-recursive clean-recursive distclean-recursive \
+maintainer-clean-recursive:
+ @failcom='exit 1'; \
+ for f in x $$MAKEFLAGS; do \
+ case $$f in \
+ *=* | --[!k]*);; \
+ *k*) failcom='fail=yes';; \
+ esac; \
+ done; \
+ dot_seen=no; \
+ case "$@" in \
+ distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+ *) list='$(SUBDIRS)' ;; \
+ esac; \
+ rev=''; for subdir in $$list; do \
+ if test "$$subdir" = "."; then :; else \
+ rev="$$subdir $$rev"; \
+ fi; \
+ done; \
+ rev="$$rev ."; \
+ target=`echo $@ | sed s/-recursive//`; \
+ for subdir in $$rev; do \
+ echo "Making $$target in $$subdir"; \
+ if test "$$subdir" = "."; then \
+ local_target="$$target-am"; \
+ else \
+ local_target="$$target"; \
+ fi; \
+ (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+ || eval $$failcom; \
+ done && test -z "$$fail"
+tags-recursive:
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
+ done
+ctags-recursive:
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
+ done
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
+ include_option=--etags-include; \
+ empty_fix=.; \
+ else \
+ include_option=--include; \
+ empty_fix=; \
+ fi; \
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ if test "$$subdir" = .; then :; else \
+ test ! -f $$subdir/TAGS || \
+ tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
+ fi; \
+ done; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$tags $$unique; \
+ fi
+ctags: CTAGS
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(CTAGS_ARGS)$$tags$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$tags $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && cd $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
+ list='$(DISTFILES)'; for file in $$list; do \
+ case $$file in \
+ $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
+ $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
+ esac; \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+ dir="/$$dir"; \
+ $(mkdir_p) "$(distdir)$$dir"; \
+ else \
+ dir=''; \
+ fi; \
+ if test -d $$d/$$file; then \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+ list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+ if test "$$subdir" = .; then :; else \
+ test -d "$(distdir)/$$subdir" \
+ || $(mkdir_p) "$(distdir)/$$subdir" \
+ || exit 1; \
+ distdir=`$(am__cd) $(distdir) && pwd`; \
+ top_distdir=`$(am__cd) $(top_distdir) && pwd`; \
+ (cd $$subdir && \
+ $(MAKE) $(AM_MAKEFLAGS) \
+ top_distdir="$$top_distdir" \
+ distdir="$$distdir/$$subdir" \
+ distdir) \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-recursive
+all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(LISP) $(ELCFILES) \
+ $(DATA)
+install-binPROGRAMS: install-libLTLIBRARIES
+
+installdirs: installdirs-recursive
+installdirs-am:
+ for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(lispdir)" "$(DESTDIR)$(pkgdatadir)"; do \
+ test -z "$$dir" || $(mkdir_p) "$$dir"; \
+ done
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-recursive
+
+clean-am: clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \
+ clean-libtool clean-lisp clean-noinstLTLIBRARIES \
+ mostlyclean-am
+
+distclean: distclean-recursive
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-libtool distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+html: html-recursive
+
+info: info-recursive
+
+info-am:
+
+install-data-am: install-lispLISP install-pkgdataDATA
+
+install-exec-am: install-binPROGRAMS install-libLTLIBRARIES
+
+install-info: install-info-recursive
+
+install-man:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-recursive
+
+pdf-am:
+
+ps: ps-recursive
+
+ps-am:
+
+uninstall-am: uninstall-binPROGRAMS uninstall-info-am \
+ uninstall-libLTLIBRARIES uninstall-lispLISP \
+ uninstall-pkgdataDATA
+
+uninstall-info: uninstall-info-recursive
+
+.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am \
+ clean clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \
+ clean-libtool clean-lisp clean-noinstLTLIBRARIES \
+ clean-recursive ctags ctags-recursive distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-recursive distclean-tags distdir dvi dvi-am html \
+ html-am info info-am install install-am install-binPROGRAMS \
+ install-data install-data-am install-exec install-exec-am \
+ install-info install-info-am install-libLTLIBRARIES \
+ install-lispLISP install-man install-pkgdataDATA install-strip \
+ installcheck installcheck-am installdirs installdirs-am \
+ maintainer-clean maintainer-clean-generic \
+ maintainer-clean-recursive mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool mostlyclean-recursive \
+ pdf pdf-am ps ps-am tags tags-recursive uninstall uninstall-am \
+ uninstall-binPROGRAMS uninstall-info-am \
+ uninstall-libLTLIBRARIES uninstall-lispLISP \
+ uninstall-pkgdataDATA
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src-util/agent.c b/src-util/agent.c
new file mode 100644
index 0000000..6baede7
--- /dev/null
+++ b/src-util/agent.c
@@ -0,0 +1,1153 @@
+/*
+ * 標準入出力でコマンドを受けたり,変換結果を送るなどの通信を
+ * アプリケーション(おもにEmacs)と行うことにより,アプリケーションに
+ * Anthyによる入力機能を容易かつ安全に追加できる.
+ *
+ * Funded by IPA未踏ソフトウェア創造事業 2002 2/26
+ * Copyright (C) 2001-2002 UGAWA Tomoharu
+ * Copyright (C) 2002-2004 TABATA Yusuke,
+ */
+/*
+ * *マルチコンテキストの扱いを決めかねている
+ * *入出力にstdioを使うかfdを使うか決めかねている
+ */
+
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <assert.h>
+
+#include <anthy/anthy.h>
+#include <anthy/input.h>
+
+#include "rkconv.h"
+
+#include <config.h>
+
+extern void egg_main(void);
+
+/* 何回次候補を押すと候補の列挙を一覧モードに切替えるか? */
+#define DEFAULT_ENUM_CAND_LIMIT 3
+
+
+/* キーに対応する定数 */
+#define KEY_SHIFT 0x00010000
+#define KEY_CTRL 0x00020000
+#define KEY_ALT 0x00040000
+
+#define KEY_SPACE ' '
+#define KEY_OPAR '('
+#define KEY_CPAR ')'
+
+#define KEY_ENTER 0x00000100
+#define KEY_DELETE 0x00000200
+#define KEY_LEFT 0x00000300
+#define KEY_RIGHT 0x00000400
+#define KEY_ESC 0x00000500
+#define KEY_BACKSPACE 0x00000600
+#define KEY_UP 0x00000700
+#define KEY_DOWN 0x00000800
+
+#define KEY_CTRL_A (KEY_CTRL | 'A')
+#define KEY_CTRL_E (KEY_CTRL | 'E')
+#define KEY_CTRL_J (KEY_CTRL | 'J')
+#define KEY_CTRL_K (KEY_CTRL | 'K')
+#define KEY_CTRL_H (KEY_CTRL | 'H')
+#define KEY_CTRL_D (KEY_CTRL | 'D')
+#define KEY_SHIFT_LEFT (KEY_SHIFT | KEY_LEFT)
+#define KEY_SHIFT_RIGHT (KEY_SHIFT | KEY_RIGHT)
+
+#define BUF_GROW_SIZE 4096
+
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+
+
+/*
+ * コマンドにはキーが押されたことを示す普通のコマンドと
+ * 高水準な命令のハイレベルコマンドがある.
+ */
+enum {
+ /* ハイレベルコマンド */
+ CMDH_IGNORE_ICTXT, CMDH_GETPREEDIT, CMDH_SELECT_CONTEXT,
+ CMDH_RELEASE_CONTEXT, CMDH_MAP_EDIT, CMDH_MAP_SELECT,
+ CMDH_GET_CANDIDATE, CMDH_SELECT_CANDIDATE, CMDH_CHANGE_TOGGLE,
+ CMDH_MAP_CLEAR, CMDH_SET_BREAK_INTO_ROMAN,
+ CMDH_SET_PREEDIT_MODE, CMDH_PRINT_CONTEXT,
+
+ /* キーコマンド */
+ CMD_SPACE = 1000,
+ CMD_ENTER,
+ CMD_BACKSPACE,
+ CMD_DELETE,
+ CMD_UP,
+ CMD_ESC,
+ CMD_SHIFTARROW,
+ CMD_ARROW,
+ CMD_KEY,
+ CMD_GOBOL,
+ CMD_GOEOL,
+ CMD_CUT
+};
+
+struct high_level_command_type {
+ const char* name;
+ int cmd;
+ int n_arg;
+ int opt_arg;
+} high_level_command_type[] = {
+ /* コンテキストの情報を表示する */
+ {"PRINT_CONTEXT", CMDH_PRINT_CONTEXT, 0, 0},
+ /* トグルに使うキーを変更する */
+ {"CHANGE_TOGGLE", CMDH_CHANGE_TOGGLE, 1, 0},
+ /* コンテキストを選択する */
+ {"SELECT_CONTEXT", CMDH_SELECT_CONTEXT, 1, 0},
+ {"RELEASE_CONTEXT", CMDH_RELEASE_CONTEXT, 0, 0},
+ {"MAP_CLEAR", CMDH_MAP_CLEAR, 1, 0},
+ {"MAP_EDIT", CMDH_MAP_EDIT, 3, 0},
+ {"MAP_SELECT", CMDH_MAP_SELECT, 1, 0},
+ {"GET_CANDIDATE", CMDH_GET_CANDIDATE, 1, 0},
+ {"SELECT_CANDIDATE", CMDH_SELECT_CANDIDATE, 1, 0},
+ /* バックスペースでローマ字に戻る */
+ {"BREAK_INTO_ROMAN", CMDH_SET_BREAK_INTO_ROMAN, 1, 0},
+ /**/
+ {"SET_PREEDIT_MODE", CMDH_SET_PREEDIT_MODE, 1, 0},
+ /**/
+ {NULL, -1, 0, 0}
+};
+
+struct command {
+ int cmd;
+ char** arg;
+ int n_arg;
+ struct command* next;
+};
+
+struct connection {
+ char* rbuf;
+ int n_rbuf;
+ int s_rbuf;
+ int rfd;
+
+ char* wbuf;
+ int n_wbuf;
+ int s_wbuf;
+ int wfd;
+};
+
+static void send_error(void);
+
+static struct connection* conn;
+static struct anthy_input_config* config;
+static struct command* command_queue;
+static int daemon_sock = -1;
+static int anonymous;
+static int egg;
+static char *personality;
+int use_utf8;
+
+static char *
+encode_command_arg(char *a)
+{
+ int i, j, len;
+ char *s;
+
+ len = strlen(a);
+ s = malloc(len + 1);
+ for(i = 0,j = 0; i < len; i++) {
+ if (a[i] != '\\') {
+ s[j] = a[i];
+ j++;
+ continue;
+ }
+ /* バックスラッシュ */
+ i++;
+ switch (a[i]) {
+ case 0:
+ case '\\':
+ s[j] = '\\';
+ j++;
+ break;
+ case '\"':
+ s[j] = '\"';
+ j++;
+ break;
+ case 'X':
+ {
+ char buf[5];
+ unsigned char *p;
+ int num;
+ /* ToBeDone エラーチェック */
+ strncpy(buf, &a[i+1], 4);
+ i+= 5;
+ sscanf(buf, "%x", (unsigned int *)&num);
+ p = (unsigned char *)buf;
+ p[0] = num & 255;
+ p[1] = num >> 8;
+ j += sprintf(&s[j], "%c%c", buf[1] , buf[0]);
+ }
+ break;
+ }
+ }
+ s[j] = 0;
+
+ return s;
+}
+
+static int
+ensure_buffer(char** buf, int* size, int to_size)
+{
+ if (*size < to_size) {
+ *buf = (char*) realloc(*buf, to_size);
+ if (*buf == NULL) {
+ return -1;
+ }
+ *size = to_size;
+ }
+ return 0;
+}
+
+static void
+kill_connection(struct connection* conn)
+{
+ (void) conn;
+ exit(0);
+}
+
+static struct command *
+make_command0(int no)
+{
+ struct command* cmd;
+
+ cmd = (struct command*) malloc(sizeof(struct command));
+ cmd->cmd = no;
+ cmd->n_arg = 0;
+ cmd->arg = NULL;
+ cmd->next = NULL;
+
+ return cmd;
+}
+
+static struct command *
+make_command1(int no, const char* arg1)
+{
+ struct command* cmd;
+
+ cmd = (struct command*) malloc(sizeof(struct command));
+ cmd->cmd = no;
+ cmd->n_arg = 1;
+ cmd->arg = (char**) malloc(sizeof(char*) * 1);
+ cmd->arg[0] = strdup(arg1);
+ cmd->next = NULL;
+
+ return cmd;
+}
+
+static struct key_name_table {
+ const char* name;
+ int code;
+ int is_modifier;
+} key_name_table[] = {
+ {"shift", KEY_SHIFT, 1},
+ {"ctrl", KEY_CTRL, 1},
+ {"alt", KEY_ALT, 1},
+
+ {"space", KEY_SPACE, 0},
+ {"opar", KEY_OPAR, 0},
+ {"cpar", KEY_CPAR, 0},
+ {"enter", KEY_ENTER, 0},
+ {"esc", KEY_ESC, 0},
+ {"backspace", KEY_BACKSPACE, 0},
+ {"delete", KEY_DELETE, 0},
+ {"left", KEY_LEFT, 0},
+ {"right", KEY_RIGHT, 0},
+ {"up", KEY_UP, 0},
+
+ {NULL, 0, 0}
+};
+
+/*
+ * エンコードされたキーの情報を取得する
+ */
+static int
+read_encoded_key(char** buf)
+{
+ char* p;
+ char* str;
+
+ int key = 0;
+
+ /* 閉じ括弧を探す */
+ for (p = *buf + 1; *p; p++) {
+ if (*p == ')') {
+ break;
+ }
+ }
+
+ if (*p == '\0') {
+ *buf = p;
+ return '\0';
+ }
+
+ str = *buf + 1;
+ *p = '\0';
+ *buf = p + 1;
+
+ p = strtok(str, " \t\r");
+ if (!p) {
+ return '\0';
+ }
+
+ do {
+ if (p[1] == '\0') {
+ return key | *p;
+ } else {
+ struct key_name_table* e;
+
+ for (e = key_name_table; e->name; e++) {
+ if (strcmp(e->name, p) == 0) {
+ key |= e->code;
+ if (e->is_modifier == 0) {
+ return key;
+ }
+ }
+ }
+ }
+ } while((p = strtok(NULL, " \t\r")));
+
+ return '\0';
+}
+
+static struct high_level_command_type *
+find_command_type(char *str)
+{
+ struct high_level_command_type* cmdn;
+ for (cmdn = high_level_command_type; cmdn->name; cmdn++) {
+ if (!strcmp(str, cmdn->name)) {
+ return cmdn;
+ }
+ }
+ return NULL;
+}
+
+/* ハイレベルコマンドをパースする */
+static struct command *
+make_hl_command(char *buf)
+{
+ /* high-level command */
+ struct high_level_command_type* cmdn;
+ struct command* cmd = NULL;
+ char* p;
+ int i;
+
+ /* コマンドの種類を調べる */
+ p = strtok(buf, " \t\r");
+ if (!p) {
+ return NULL;
+ }
+ cmdn = find_command_type(p);
+ if (!cmdn) {
+ return NULL;
+ }
+
+ /* コマンドを作る */
+ cmd = (struct command*) malloc(sizeof(struct command));
+ cmd->cmd = cmdn->cmd;
+ cmd->n_arg = cmdn->n_arg;
+ if (cmd->n_arg > 0) {
+ cmd->arg = (char**) malloc(sizeof(char*) * cmd->n_arg);
+ } else {
+ cmd->arg = NULL;
+ }
+ for (i = 0; i < cmd->n_arg; i++) {
+ p = strtok(NULL, " \t\r");
+ if (!p) {
+ while (i-- > 0)
+ free(cmd->arg[i]);
+ free(cmd->arg);
+ free(cmd);
+ return NULL;
+ }
+ cmd->arg[i] = encode_command_arg(p);
+ }
+ while ((p = strtok(NULL, " \t\r"))) {
+ if (!p) {
+ break;
+ }
+ cmd->n_arg++;
+ cmd->arg = (char**) realloc(cmd->arg, sizeof(char*) * cmd->n_arg);
+ cmd->arg[cmd->n_arg - 1] = encode_command_arg(p);
+ }
+ cmd->next = NULL;
+ return cmd;
+}
+
+/* 普通のコマンドをパースする */
+static struct command *
+make_ll_command(char *buf)
+{
+ struct command* cmd_head = NULL;
+ struct command* cmd = NULL;
+ char* p;
+
+ for (p = buf; *p; ) {
+ struct command* cmd0 = NULL;
+ int c;
+
+ if (isspace((int)(unsigned char) *p)) {
+ p++;
+ continue;
+ } else if (*p == '(') {
+ c = read_encoded_key(&p);
+ } else {
+ c = *p++;
+ }
+
+ switch (c) {
+ case '\0':
+ break;
+ case KEY_SPACE:
+ cmd0 = make_command0(CMD_SPACE);
+ break;
+ case KEY_CTRL_J:
+ case KEY_ENTER:
+ case KEY_DOWN:
+ cmd0 = make_command0(CMD_ENTER);
+ break;
+ case KEY_BACKSPACE:
+ case KEY_CTRL_H:
+ cmd0 = make_command0(CMD_BACKSPACE);
+ break;
+ case KEY_DELETE:
+ case KEY_CTRL_D:
+ cmd0 = make_command0(CMD_DELETE);
+ break;
+ case KEY_SHIFT_LEFT:
+ cmd0 = make_command1(CMD_SHIFTARROW, "-1");
+ break;
+ case KEY_SHIFT_RIGHT:
+ cmd0 = make_command1(CMD_SHIFTARROW, "1");
+ break;
+ case KEY_LEFT:
+ cmd0 = make_command1(CMD_ARROW, "-1");
+ break;
+ case KEY_RIGHT:
+ cmd0 = make_command1(CMD_ARROW, "1");
+ break;
+ case KEY_UP:
+ cmd0 = make_command0(CMD_UP);
+ break;
+ case KEY_ESC:
+ cmd0 = make_command0(CMD_ESC);
+ break;
+ case KEY_CTRL_A:
+ cmd0 = make_command0(CMD_GOBOL);
+ break;
+ case KEY_CTRL_E:
+ cmd0 = make_command0(CMD_GOEOL);
+ break;
+ case KEY_CTRL_K:
+ cmd0 = make_command0(CMD_CUT);
+ break;
+ default:
+ if ((c & 0xffffff80) == 0) {
+ /* ASCII文字 */
+ char str[2];
+
+ str[0] = (char)c;
+ str[1] = '\0';
+ /* cmd_key */
+ cmd0 = make_command1(CMD_KEY, str);
+ }
+ break;
+ }
+
+ if (cmd0) {
+ if (cmd) {
+ cmd->next = cmd0;
+ } else {
+ cmd_head = cmd0;
+ }
+ cmd = cmd0;
+ }
+ } /* for (p) */
+
+ if (cmd) {
+ cmd->next = make_command0(CMDH_GETPREEDIT);
+ } else {
+ cmd_head = make_command0(CMDH_GETPREEDIT);
+ }
+
+ return cmd_head;
+}
+
+static struct command*
+make_command(char* buf)
+{
+
+ if (*buf == ' ') {
+ /* ハイレベルコマンド */
+ struct command *cmd;
+ cmd = make_hl_command(buf);
+ if (!cmd) {
+ send_error();
+ }
+ return cmd;
+ }
+ return make_ll_command(buf);
+}
+
+static int
+proc_connection(void)
+{
+ fd_set rfds;
+ fd_set wfds;
+ int max_fd;
+ int ret;
+
+ max_fd = -1;
+ FD_ZERO(&rfds);
+ FD_ZERO(&wfds);
+ if (daemon_sock >= 0) {
+ max_fd = daemon_sock;
+ FD_SET(daemon_sock, &rfds);
+ }
+ max_fd = MAX(conn->rfd, max_fd);
+ FD_SET(conn->rfd, &rfds);
+ if (conn->n_wbuf > 0) {
+ max_fd = MAX(conn->wfd, max_fd);
+ FD_SET(conn->wfd, &wfds);
+ }
+
+ if (max_fd == -1)
+ return -1;
+
+ ret = select(max_fd + 1, &rfds, &wfds, NULL, NULL);
+ if (ret < 0) {
+ return -1;
+ }
+
+ if (conn->n_wbuf > 0 && FD_ISSET(conn->wfd, &wfds)) {
+ ret = write(conn->wfd, conn->wbuf, conn->n_wbuf);
+ if (ret <= 0) {
+ kill_connection (conn);
+ } else {
+ conn->n_wbuf -= ret;
+ if (conn->n_wbuf > 0) {
+ memmove(conn->wbuf, conn->wbuf + ret, conn->n_wbuf);
+ }
+ }
+ }
+
+ if (FD_ISSET(conn->rfd, &rfds)) {
+ ensure_buffer(&conn->rbuf, &conn->s_rbuf,
+ conn->n_rbuf + BUF_GROW_SIZE);
+ ret = read(conn->rfd,
+ conn->rbuf + conn->n_rbuf, conn->s_rbuf - conn->n_rbuf);
+ if (ret <= 0) {
+ kill_connection (conn);
+ } else {
+ conn->n_rbuf += ret;
+ }
+ }
+ return 0;
+}
+
+static struct command *
+read_command(void)
+{
+ struct command* cmd;
+
+AGAIN:
+ if (command_queue != NULL) {
+ cmd = command_queue;
+ command_queue = cmd->next;
+ return cmd;
+ }
+
+ while (1) {
+
+ char* p;
+ for (p = conn->rbuf; p < conn->rbuf + conn->n_rbuf; p++) {
+ if (*p == '\n') {
+ *p = '\0';
+ cmd = make_command(conn->rbuf);
+ conn->n_rbuf -= p + 1 - conn->rbuf;
+ memmove(conn->rbuf, p + 1, conn->n_rbuf);
+ if (cmd) {
+ command_queue = cmd;
+ goto AGAIN;
+ }
+ }
+ }
+
+ if (proc_connection() == -1) {
+ return NULL;
+ }
+
+ }
+}
+
+static void
+write_reply(const char* buf)
+{
+ printf("%s", buf);
+}
+
+static void
+send_error(void)
+{
+ write_reply("ERR\r\n");
+}
+
+static void
+send_ok(void)
+{
+ write_reply("OK\r\n");
+}
+
+static void
+send_number10(int num)
+{
+ char buf[20];
+
+ sprintf(buf, "%d", num);
+ write_reply(buf);
+}
+
+static void
+send_string(const char* str)
+{
+ write_reply(str);
+}
+
+static void
+send_quote_string(const char* str)
+{
+ char buf[20]; /* このぐらいあれば大抵大丈夫 */
+ const char *p;
+ char *q, *end;
+
+ end = buf + sizeof(buf) - 2;
+ for (q = buf, p = str; *p;) {
+ if (q >= end) {
+ *q = '\0';
+ write_reply(buf);
+ q = buf;
+ }
+
+ switch (*p) {
+ case '\"':
+ case '\\':
+ *q++ = '\\';
+ break;
+ default:
+ break;
+ }
+
+ *q++ = *p++;
+ }
+ *q = '\0';
+ write_reply(buf);
+}
+
+static void
+send_preedit(struct anthy_input_preedit* pedit)
+{
+ send_string("(");
+ send_number10(pedit->state);
+
+ if (pedit->commit != NULL) {
+ send_string(" ((COMMIT) \"");
+ send_quote_string(pedit->commit);
+ send_string("\")");
+ }
+
+ if (pedit->cut_buf != NULL) {
+ send_string(" ((CUTBUF) \"");
+ send_quote_string(pedit->cut_buf);
+ send_string("\")");
+ }
+
+ switch (pedit->state) {
+ case ANTHY_INPUT_ST_OFF:
+ case ANTHY_INPUT_ST_NONE:
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ case ANTHY_INPUT_ST_CONV:
+ case ANTHY_INPUT_ST_CSEG:
+ {
+ struct anthy_input_segment* seg;
+
+ for (seg = pedit->segment; seg; seg = seg->next) {
+ if (seg->str == NULL) {
+ if (seg->flag & ANTHY_INPUT_SF_CURSOR)
+ send_string(" cursor");
+ } else {
+ if (seg->flag & ANTHY_INPUT_SF_CURSOR) {
+ if (seg->flag & ANTHY_INPUT_SF_ENUM)
+ send_string(" ((UL RV ENUM) \"");
+ else if (seg->flag & ANTHY_INPUT_SF_ENUM_REVERSE)
+ send_string(" ((UL RV ENUMR) \"");
+ else
+ send_string(" ((UL RV) \"");
+ } else
+ send_string(" ((UL) \"");
+
+ send_quote_string(seg->str);
+ send_string("\" ");
+ send_number10(seg->cand_no);
+ send_string(" ");
+ send_number10(seg->nr_cand);
+ send_string(")");
+ }
+ }
+ }
+ break;
+ }
+
+ send_string(")\r\n");
+}
+
+static void
+send_single_candidate(struct anthy_input_segment* seg)
+{
+ send_string("(\"");
+ send_quote_string(seg->str);
+ send_string("\" ");
+ send_number10(seg->cand_no);
+ send_string(" ");
+ send_number10(seg->nr_cand);
+ send_string(")\r\n");
+}
+
+static void
+free_command(struct command* cmd)
+{
+ int i;
+
+ for (i = 0; i < cmd->n_arg; i++)
+ free(cmd->arg[i]);
+ free(cmd->arg);
+ free(cmd);
+}
+
+struct input_context_list {
+ int id;
+ struct anthy_input_context* ictx;
+ struct input_context_list* next;
+};
+
+static struct input_context_list* ictx_list = NULL;
+
+static void
+new_input_context(int id)
+{
+ struct input_context_list* ictxl;
+
+ ictxl =
+ (struct input_context_list*) malloc(sizeof (struct input_context_list));
+ ictxl->id = id;
+ ictxl->ictx = anthy_input_create_context(config);
+ ictxl->next = ictx_list;
+ ictx_list = ictxl;
+}
+
+static struct anthy_input_context*
+get_current_input_context(void)
+{
+ if (ictx_list == NULL)
+ new_input_context(0);
+
+ return ictx_list->ictx;
+}
+
+static void
+cmdh_get_preedit(struct anthy_input_context* ictx)
+{
+ struct anthy_input_preedit* pedit;
+
+ pedit = anthy_input_get_preedit(ictx);
+ send_preedit(pedit);
+ anthy_input_free_preedit(pedit);
+}
+
+static void
+cmdh_select_input_context(struct command* cmd)
+{
+ int id;
+ struct input_context_list** p;
+
+ id = atoi(cmd->arg[0]);
+ for (p = &ictx_list; *p; p = &(*p)->next) {
+ if ((*p)->id == id) {
+ struct input_context_list* sel;
+ sel = *p;
+ *p = sel->next;
+ sel->next = ictx_list;
+ ictx_list = sel;
+ send_ok();
+ return;
+ }
+ }
+
+ new_input_context(id);
+ send_ok();
+}
+
+static void
+cmdh_release_input_context(struct command* cmd)
+{
+ struct input_context_list* sel;
+ (void)cmd;
+ if (!ictx_list) {
+ send_ok();
+ return ;
+ }
+ sel = ictx_list;
+ ictx_list = ictx_list->next;
+ anthy_input_free_context(sel->ictx);
+ free(sel);
+ send_ok();
+}
+
+static void
+cmdh_change_toggle(struct command *cmd)
+{
+ int toggle = cmd->arg[0][0];
+ int ret;
+
+ ret = anthy_input_edit_toggle_config(config, toggle);
+
+ if (ret != 0) {
+ send_error();
+ return;
+ }
+ anthy_input_change_config(config);
+ send_ok();
+}
+
+static void
+cmdh_map_clear(struct command *cmd)
+{
+ anthy_input_clear_rk_config(config, atoi(cmd->arg[0]));
+ anthy_input_change_config(config);
+ send_ok();
+}
+
+static void
+cmdh_set_break_into_roman(struct command *cmd)
+{
+ anthy_input_break_into_roman_config(config, atoi(cmd->arg[0]));
+ anthy_input_change_config(config);
+ send_ok();
+}
+
+static void
+cmdh_set_preedit_mode(struct command *cmd)
+{
+ anthy_input_preedit_mode_config(config, atoi(cmd->arg[0]));
+ anthy_input_change_config(config);
+ send_ok();
+}
+
+static void
+cmdh_map_edit(struct command* cmd)
+{
+ /* MAP,from,to */
+ int map_no = atoi(cmd->arg[0]);
+ int ret;
+
+ ret = anthy_input_edit_rk_config(config, map_no,
+ cmd->arg[1], cmd->arg[2], NULL);
+
+ if (ret != 0) {
+ send_error();
+ return;
+ }
+ anthy_input_change_config(config);
+ send_ok();
+}
+
+static void
+cmdh_map_select(struct anthy_input_context* ictx,
+ struct command* cmd)
+{
+ char* map_name;
+ int map_no;
+
+ map_name = cmd->arg[0];
+ if (strcmp(map_name, "alphabet") == 0)
+ map_no = ANTHY_INPUT_MAP_ALPHABET;
+ else if (strcmp(map_name, "hiragana") == 0)
+ map_no = ANTHY_INPUT_MAP_HIRAGANA;
+ else if (strcmp(map_name, "katakana") == 0)
+ map_no = ANTHY_INPUT_MAP_KATAKANA;
+ else if (strcmp(map_name, "walphabet") == 0)
+ map_no = ANTHY_INPUT_MAP_WALPHABET;
+ else if (strcmp(map_name, "hankaku_kana") == 0)
+ map_no = ANTHY_INPUT_MAP_HANKAKU_KANA;
+ else {
+ send_error();
+ return;
+ }
+
+ anthy_input_map_select(ictx, map_no);
+ send_ok();
+}
+
+static void
+cmdh_get_candidate(struct anthy_input_context* ictx,
+ struct command* cmd)
+{
+ struct anthy_input_segment* seg;
+ int cand_no;
+
+ cand_no = atoi(cmd->arg[0]);
+
+ seg = anthy_input_get_candidate(ictx, cand_no);
+ if (seg == NULL)
+ send_error();
+ else {
+ send_single_candidate(seg);
+ anthy_input_free_segment(seg);
+ }
+}
+
+static void
+cmdh_select_candidate(struct anthy_input_context* ictx,
+ struct command* cmd)
+{
+ int ret;
+ int cand_no;
+
+ cand_no = atoi(cmd->arg[0]);
+ ret = anthy_input_select_candidate(ictx, cand_no);
+ if (ret < 0) {
+ send_error();
+ } else {
+ cmdh_get_preedit(ictx);
+ }
+}
+
+static void
+cmd_shift_arrow(struct anthy_input_context* ictx,
+ struct command* cmd)
+{
+ int lr = atoi(cmd->arg[0]);
+ anthy_input_resize(ictx, lr);
+}
+
+static void
+cmd_arrow(struct anthy_input_context* ictx, struct command* cmd)
+{
+ int lr = atoi(cmd->arg[0]);
+ anthy_input_move(ictx, lr);
+}
+
+static void
+cmd_key(struct anthy_input_context* ictx, struct command* cmd)
+{
+ anthy_input_str(ictx, cmd->arg[0]);
+}
+
+/*
+ * コマンドをディスパッチする
+ */
+static void
+dispatch_command(struct anthy_input_context* ictx,
+ struct command* cmd)
+{
+ switch (cmd->cmd) {
+ case CMDH_IGNORE_ICTXT:
+ send_error();
+ break;
+ case CMDH_PRINT_CONTEXT:
+ /* Dirty implementation, would cause corrpution.*/
+ {
+ anthy_context_t ac = anthy_input_get_anthy_context(ictx);
+ if (ac) {
+ anthy_print_context(ac);
+ }
+ }
+ break;
+ case CMDH_GETPREEDIT:
+ cmdh_get_preedit(ictx);
+ break;
+ case CMDH_SELECT_CONTEXT:
+ cmdh_select_input_context(cmd);
+ break;
+ case CMDH_RELEASE_CONTEXT:
+ cmdh_release_input_context(cmd);
+ break;
+ case CMDH_MAP_EDIT:
+ cmdh_map_edit(cmd);
+ break;
+ case CMDH_CHANGE_TOGGLE:
+ cmdh_change_toggle(cmd);
+ break;
+ case CMDH_MAP_CLEAR:
+ cmdh_map_clear(cmd);
+ break;
+ case CMDH_MAP_SELECT:
+ cmdh_map_select(ictx, cmd);
+ break;
+ case CMDH_GET_CANDIDATE:
+ cmdh_get_candidate(ictx, cmd);
+ break;
+ case CMDH_SELECT_CANDIDATE:
+ cmdh_select_candidate(ictx, cmd);
+ break;
+ case CMDH_SET_BREAK_INTO_ROMAN:
+ cmdh_set_break_into_roman(cmd);
+ break;
+ case CMDH_SET_PREEDIT_MODE:
+ cmdh_set_preedit_mode(cmd);
+ break;
+ /* key commands follows */
+
+ case CMD_SPACE:
+ anthy_input_space(ictx);
+ break;
+ case CMD_ENTER:
+ anthy_input_commit(ictx);
+ break;
+ case CMD_BACKSPACE:
+ anthy_input_erase_prev(ictx);
+ break;
+ case CMD_DELETE:
+ anthy_input_erase_next(ictx);
+ break;
+ case CMD_UP:
+ anthy_input_prev_candidate(ictx);
+ break;
+ case CMD_ESC:
+ anthy_input_quit(ictx);
+ break;
+ case CMD_SHIFTARROW:
+ cmd_shift_arrow(ictx, cmd);
+ break;
+ case CMD_ARROW:
+ cmd_arrow(ictx, cmd);
+ break;
+ case CMD_KEY:
+ cmd_key(ictx, cmd);
+ break;
+ case CMD_GOBOL:
+ anthy_input_beginning_of_line(ictx);
+ break;
+ case CMD_GOEOL:
+ anthy_input_end_of_line(ictx);
+ break;
+ case CMD_CUT:
+ anthy_input_cut(ictx);
+ break;
+ }
+}
+
+static void
+main_loop(void)
+{
+ struct anthy_input_context* ictx;
+ struct command* cmd;
+
+ while (1) {
+ cmd = read_command();
+ if (!cmd)
+ break;
+ ictx = get_current_input_context();
+
+ dispatch_command(ictx, cmd);
+ fflush(stdout);
+
+ free_command(cmd);
+ }
+}
+
+static void
+print_version(void)
+{
+ printf(PACKAGE "-agent "VERSION "\n");
+ exit(0);
+}
+
+static void
+parse_args(int argc, char **argv)
+{
+ int i;
+ char *conffile = NULL, *dir = NULL, *dic = NULL;
+
+
+ for (i = 1; i < argc; i++) {
+ char *str = argv[i];
+ if (!strcmp("--version", str)) {
+ print_version();
+ } else if (!strcmp("--anonymous", str)) {
+ anonymous = 1;
+ } else if (!strcmp("--egg", str)) {
+ egg = 1;
+ } else if (!strncmp("--personality=", str, 14)) {
+ personality = &str[14];
+ } else if (!strcmp("--utf8", str)) {
+ use_utf8 = 1;
+ } else if (i < argc - 1) {
+ char *arg = argv[i+1];
+ if (!strcmp("--dir", str)) {
+ dir = arg;
+ i++;
+ } else if (!strcmp("--dic", str)) {
+ dic = arg;
+ i++;
+ } else if (!strcmp("--conffile", str)) {
+ conffile = arg;
+ i++;
+ }
+ }
+ }
+ if (conffile) {
+ anthy_conf_override("CONFFILE", conffile);
+ }
+ if (dir) {
+ anthy_conf_override("ANTHYDIR", dir);
+ }
+ if (dic) {
+ anthy_conf_override("SDIC", dic);
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ parse_args(argc, argv);
+ if (anthy_input_init()) {
+ printf("Failed to init anthy\n");
+ exit(0);
+ }
+ if (anonymous) {
+ anthy_input_set_personality("");
+ } else if (personality) {
+ anthy_input_set_personality(personality);
+ }
+
+ if (egg) {
+ egg_main();
+ anthy_quit();
+ } else {
+ config = anthy_input_create_config();
+ conn = (struct connection*) malloc(sizeof(struct connection));
+ conn->rbuf = NULL;
+ conn->n_rbuf = 0;
+ conn->s_rbuf = 0;
+ conn->rfd = 0;
+ conn->wbuf = NULL;
+ conn->n_wbuf = 0;
+ conn->s_wbuf = 0;
+ conn->wfd = 1;
+
+ main_loop();
+ }
+ return 0;
+}
diff --git a/src-util/anthy-azik.el b/src-util/anthy-azik.el
new file mode 100644
index 0000000..53e5d3e
--- /dev/null
+++ b/src-util/anthy-azik.el
@@ -0,0 +1,233 @@
+;; anthy-azik.el
+
+;; Copyright (C) 2004
+;; Author: Yutaka Hara<yhara@kmc.gr.jp>
+
+;; add following 2 lines to ~/.emacs
+;; (load-library "anthy-azik")
+;; (anthy-azik-mode)
+;;
+
+(defvar anthy-azik-mode-hiragana-map
+ '(
+ (";" . "$B$C(B") ("x;" . ";") ("b." . "$B$V(B") ("bd" . "$B$Y$s(B") ("bh" . "$B$V$&(B")
+ ("bj" . "$B$V$s(B") ("bk" . "$B$S$s(B") ("bl" . "$B$\$s(B") ("bn" . "$B$P$s(B") ("bp" . "$B$\$&(B")
+ ("bq" . "$B$P$$(B") ("br" . "$B$P$i(B") ("bt" . "$B$S$H(B") ("bw" . "$B$Y$$(B") ("bx" . "$B$Y$$(B")
+ ("byd" . "$B$S$'$s(B") ("byh" . "$B$S$e$&(B") ("byj" . "$B$S$e$s(B") ("byl" . "$B$S$g$s(B") ("byn" . "$B$S$c$s(B")
+ ("byp" . "$B$S$g$&(B") ("byq" . "$B$S$c$$(B") ("byw" . "$B$S$'$$(B") ("byz" . "$B$S$c$s(B") ("bz" . "$B$P$s(B")
+ ("ca" . "$B$A$c(B") ("cc" . "$B$A$c(B") ("cd" . "$B$A$'$s(B") ("ce" . "$B$A$'(B") ("cf" . "$B$A$'(B")
+ ("ch" . "$B$A$e$&(B") ("ci" . "$B$A(B") ("cj" . "$B$A$e$s(B") ("ck" . "$B$A$s(B") ("cl" . "$B$A$g$s(B")
+ ("cn" . "$B$A$c$s(B") ("co" . "$B$A$g(B") ("cp" . "$B$A$g$&(B") ("cq" . "$B$A$c$$(B") ("cu" . "$B$A$e(B")
+ ("cv" . "$B$A$c$$(B") ("cw" . "$B$A$'$$(B") ("cx" . "$B$A$'$$(B") ("cz" . "$B$A$c$s(B") ("dch" . "$B$G$e!<(B")
+ ("dci" . "$B$G$#(B") ("dck" . "$B$G$#$s(B") ("dcp" . "$B$I$%!<(B") ("dcu" . "$B$G$e(B") ("dd" . "$B$G$s(B")
+ ("df" . "$B$G(B") ("dg" . "$B$@$,(B") ("dh" . "$B$E$&(B") ("dj" . "$B$E$s(B") ("dk" . "$B$B$s(B")
+ ("dl" . "$B$I$s(B") ("dm" . "$B$G$b(B") ("dn" . "$B$@$s(B") ("dp" . "$B$I$&(B") ("dq" . "$B$@$$(B")
+ ("dr" . "$B$G$"$k(B") ("ds" . "$B$G$9(B") ("dt" . "$B$@$A(B") ("dv" . "$B$G$s(B") ("dw" . "$B$G$$(B")
+ ("dy" . "$B$G$#(B") ("dz" . "$B$@$s(B") ("fd" . "$B$U$'$s(B") ("fh" . "$B$U$&(B") ("fj" . "$B$U$s(B")
+ ("fk" . "$B$U$#$s(B") ("fl" . "$B$U$)$s(B") ("fm" . "$B$U$`(B") ("fn" . "$B$U$!$s(B") ("fp" . "$B$U$)!<(B")
+ ("fq" . "$B$U$!$$(B") ("fr" . "$B$U$k(B") ("fs" . "$B$U$!$$(B") ("fw" . "$B$U$'$$(B") ("fz" . "$B$U$!$s(B")
+ ("gd" . "$B$2$s(B") ("gh" . "$B$0$&(B") ("gj" . "$B$0$s(B") ("gk" . "$B$.$s(B") ("gl" . "$B$4$s(B")
+ ("gn" . "$B$,$s(B") ("gp" . "$B$4$&(B") ("gq" . "$B$,$$(B") ("gr" . "$B$,$i(B") ("gt" . "$B$4$H(B")
+ ("gw" . "$B$2$$(B") ("gyd" . "$B$.$'$s(B") ("gyh" . "$B$.$e$&(B") ("gyj" . "$B$.$e$s(B") ("gyl" . "$B$.$g$s(B")
+ ("gyn" . "$B$.$c$s(B") ("gyp" . "$B$.$g$&(B") ("gyq" . "$B$.$c$$(B") ("gyw" . "$B$.$'$$(B") ("gyz" . "$B$.$c$s(B")
+ ("gz" . "$B$,$s(B") ("hd" . "$B$X$s(B") ("hf" . "$B$U(B") ("hga" . "$B$R$c(B") ("hgd" . "$B$R$'$s(B")
+ ("hge" . "$B$R$'(B") ("hgh" . "$B$R$e$&(B") ("hgj" . "$B$R$e$s(B") ("hgl" . "$B$R$g$s(B") ("hgn" . "$B$R$c$s(B")
+ ("hgo" . "$B$R$g(B") ("hgp" . "$B$R$g$&(B") ("hgq" . "$B$R$c$$(B") ("hgu" . "$B$R$e(B") ("hgw" . "$B$R$'$$(B")
+ ("hgz" . "$B$R$c$s(B") ("hh" . "$B$U$&(B") ("hj" . "$B$U$s(B") ("hk" . "$B$R$s(B") ("hl" . "$B$[$s(B")
+ ("hn" . "$B$O$s(B") ("hp" . "$B$[$&(B") ("hq" . "$B$O$$(B") ("ht" . "$B$R$H(B") ("hw" . "$B$X$$(B")
+ ("hyd" . "$B$R$'$s(B") ("hyh" . "$B$R$e$&(B") ("hyl" . "$B$R$g$s(B") ("hyp" . "$B$R$g$&(B") ("hyq" . "$B$R$c$$(B")
+ ("hyw" . "$B$R$'$$(B") ("hyz" . "$B$R$c$s(B") ("hz" . "$B$O$s(B") ("jd" . "$B$8$'$s(B") ("jf" . "$B$8$e(B")
+ ("jh" . "$B$8$e$&(B") ("jj" . "$B$8$e$s(B") ("jk" . "$B$8$s(B") ("jl" . "$B$8$g$s(B") ("jn" . "$B$8$c$s(B")
+ ("jp" . "$B$8$g$&(B") ("jq" . "$B$8$c$$(B") ("jv" . "$B$8$e$&(B") ("jw" . "$B$8$'$$(B") ("jz" . "$B$8$c$s(B")
+ ("kA" . "$B%u(B") ("kE" . "$B%v(B") ("kd" . "$B$1$s(B") ("kf" . "$B$-(B") ("kga" . "$B$-$c(B")
+ ("kgd" . "$B$-$'$s(B") ("kge" . "$B$-$'(B") ("kgh" . "$B$-$e$&(B") ("kgl" . "$B$-$g$s(B") ("kgn" . "$B$-$c$s(B")
+ ("kgo" . "$B$-$g(B") ("kgp" . "$B$-$g$&(B") ("kgq" . "$B$-$c$$(B") ("kgu" . "$B$-$e(B") ("kgw" . "$B$-$'$$(B")
+ ("kgz" . "$B$-$c$s(B") ("kh" . "$B$/$&(B") ("kj" . "$B$/$s(B") ("kk" . "$B$-$s(B") ("kl" . "$B$3$s(B")
+ ("km" . "$B$-(B") ("kn" . "$B$+$s(B") ("kp" . "$B$3$&(B") ("kq" . "$B$+$$(B") ("kr" . "$B$+$i(B")
+ ("kt" . "$B$3$H(B") ("kv" . "$B$-$s(B") ("kw" . "$B$1$$(B") ("kyd" . "$B$-$'$s(B") ("kyh" . "$B$-$e$&(B")
+ ("kyj" . "$B$-$e$s(B") ("kyl" . "$B$-$g$s(B") ("kyn" . "$B$-$c$s(B") ("kyp" . "$B$-$g$&(B") ("kyq" . "$B$-$c$$(B")
+ ("kyw" . "$B$-$'$$(B") ("kyz" . "$B$-$c$s(B") ("kz" . "$B$+$s(B") ("m." . "$B$`(B") ("md" . "$B$a$s(B")
+ ("mf" . "$B$`(B") ("mga" . "$B$_$c(B") ("mgd" . "$B$_$'$s(B") ("mge" . "$B$_$'(B") ("mgh" . "$B$_$e$&(B")
+ ("mgj" . "$B$_$e$s(B") ("mgl" . "$B$_$g$s(B") ("mgn" . "$B$_$c$s(B") ("mgo" . "$B$_$g(B") ("mgp" . "$B$_$g$&(B")
+ ("mgq" . "$B$_$c$$(B") ("mgu" . "$B$_$e(B") ("mgw" . "$B$_$'$$(B") ("mgz" . "$B$_$c$s(B") ("mh" . "$B$`$&(B")
+ ("mj" . "$B$`$s(B") ("mk" . "$B$_$s(B") ("ml" . "$B$b$s(B") ("mn" . "$B$b$N(B") ("mp" . "$B$b$&(B")
+ ("mq" . "$B$^$$(B") ("mr" . "$B$^$k(B") ("ms" . "$B$^$9(B") ("mt" . "$B$^$?(B") ("mv" . "$B$`$s(B")
+ ("mw" . "$B$a$$(B") ("myd" . "$B$_$'$s(B") ("myh" . "$B$_$e$&(B") ("myj" . "$B$_$e$s(B") ("myl" . "$B$_$g$s(B")
+ ("myn" . "$B$_$c$s(B") ("myp" . "$B$_$g$&(B") ("myq" . "$B$_$c$$(B") ("myw" . "$B$_$'$$(B") ("myz" . "$B$_$c$s(B")
+ ("mz" . "$B$^$s(B") ("n." . "$B$L(B") ("nb" . "$B$M$P(B") ("nd" . "$B$M$s(B") ("nf" . "$B$L(B")
+ ("nga" . "$B$K$c(B") ("ngd" . "$B$K$'$s(B") ("nge" . "$B$K$'(B") ("ngh" . "$B$K$e$&(B") ("ngj" . "$B$K$e$s(B")
+ ("ngl" . "$B$K$g$s(B") ("ngn" . "$B$K$c$s(B") ("ngo" . "$B$K$g(B") ("ngp" . "$B$K$g$&(B") ("ngq" . "$B$K$c$$(B")
+ ("ngu" . "$B$K$e(B") ("ngw" . "$B$K$'$$(B") ("ngz" . "$B$K$c$s(B") ("nh" . "$B$L$&(B") ("nj" . "$B$L$s(B")
+ ("nk" . "$B$K$s(B") ("nl" . "$B$N$s(B") ("np" . "$B$N$&(B") ("nq" . "$B$J$$(B") ("nr" . "$B$J$k(B")
+ ("nt" . "$B$K$A(B") ("nv" . "$B$L$s(B") ("nw" . "$B$M$$(B") ("nyd" . "$B$K$'$s(B") ("nyh" . "$B$K$e$&(B")
+ ("nyj" . "$B$K$e$s(B") ("nyl" . "$B$K$g$s(B") ("nyn" . "$B$K$c$s(B") ("nyp" . "$B$K$g$&(B") ("nyq" . "$B$K$c$$(B")
+ ("nyw" . "$B$K$'$$(B") ("nyz" . "$B$K$c$s(B") ("nz" . "$B$J$s(B") ("pd" . "$B$Z$s(B") ("pf" . "$B$]$s(B")
+ ("pga" . "$B$T$c(B") ("pgd" . "$B$T$'$s(B") ("pge" . "$B$T$'(B") ("pgh" . "$B$T$e$&(B") ("pgj" . "$B$T$e$s(B")
+ ("pgl" . "$B$T$g$s(B") ("pgn" . "$B$T$c$s(B") ("pgo" . "$B$T$g(B") ("pgp" . "$B$T$g$&(B") ("pgq" . "$B$T$c$$(B")
+ ("pgu" . "$B$T$e(B") ("pgw" . "$B$T$'$$(B") ("pgz" . "$B$T$c$s(B") ("ph" . "$B$W$&(B") ("pj" . "$B$W$s(B")
+ ("pk" . "$B$T$s(B") ("pl" . "$B$]$s(B") ("pn" . "$B$Q$s(B") ("pp" . "$B$]$&(B") ("pq" . "$B$Q$$(B")
+ ("pv" . "$B$]$&(B") ("pw" . "$B$Z$$(B") ("pyd" . "$B$T$'$s(B") ("pyh" . "$B$T$e$&(B") ("pyj" . "$B$T$e$s(B")
+ ("pyl" . "$B$T$g$s(B") ("pyn" . "$B$T$c$s(B") ("pyp" . "$B$T$g$&(B") ("pyq" . "$B$T$c$$(B") ("pyw" . "$B$T$'$$(B")
+ ("pyz" . "$B$T$c$s(B") ("pz" . "$B$Q$s(B") ("q" . "$B$s(B") ("rd" . "$B$l$s(B") ("rh" . "$B$k$&(B")
+ ("rj" . "$B$k$s(B") ("rk" . "$B$j$s(B") ("rl" . "$B$m$s(B") ("rn" . "$B$i$s(B") ("rp" . "$B$m$&(B")
+ ("rq" . "$B$i$$(B") ("rr" . "$B$i$l(B") ("rw" . "$B$l$$(B") ("ryd" . "$B$j$'$s(B") ("ryh" . "$B$j$e$&(B")
+ ("ryj" . "$B$j$e$s(B") ("ryk" . "$B$j$g$/(B") ("ryl" . "$B$j$g$s(B") ("ryn" . "$B$j$c$s(B") ("ryp" . "$B$j$g$&(B")
+ ("ryq" . "$B$j$c$$(B") ("ryw" . "$B$j$'$$(B") ("ryz" . "$B$j$c$s(B") ("rz" . "$B$i$s(B") ("sd" . "$B$;$s(B")
+ ("sf" . "$B$5$$(B") ("sh" . "$B$9$&(B") ("sj" . "$B$9$s(B") ("sk" . "$B$7$s(B") ("sl" . "$B$=$s(B")
+ ("sm" . "$B$7$b(B") ("sn" . "$B$5$s(B") ("sp" . "$B$=$&(B") ("sq" . "$B$5$$(B") ("sr" . "$B$9$k(B")
+ ("ss" . "$B$;$$(B") ("st" . "$B$7$?(B") ("sv" . "$B$5$$(B") ("sw" . "$B$;$$(B") ("syd" . "$B$7$'$s(B")
+ ("syh" . "$B$7$e$&(B") ("syj" . "$B$7$e$s(B") ("syl" . "$B$7$g$s(B") ("syp" . "$B$7$g$&(B") ("syq" . "$B$7$c$$(B")
+ ("syw" . "$B$7$'$$(B") ("syz" . "$B$7$c$s(B") ("sz" . "$B$5$s(B") ("tU" . "$B$C(B") ("tb" . "$B$?$S(B")
+ ("td" . "$B$F$s(B") ("tgh" . "$B$F$e!<(B") ("tgi" . "$B$F$#(B") ("tgk" . "$B$F$#$s(B") ("tgp" . "$B$H$%!<(B")
+ ("tgu" . "$B$F$e(B") ("th" . "$B$D$&(B") ("tj" . "$B$D$s(B") ("tk" . "$B$A$s(B") ("tl" . "$B$H$s(B")
+ ("tm" . "$B$?$a(B") ("tn" . "$B$?$s(B") ("tp" . "$B$H$&(B") ("tq" . "$B$?$$(B") ("tr" . "$B$?$i(B")
+ ("tsU" . "$B$C(B") ("tsa" . "$B$D$!(B") ("tse" . "$B$D$'(B") ("tsi" . "$B$D$#(B") ("tso" . "$B$D$)(B")
+ ("tt" . "$B$?$A(B") ("tw" . "$B$F$$(B") ("tyd" . "$B$A$'$s(B") ("tyh" . "$B$A$e$&(B") ("tyj" . "$B$A$e$s(B")
+ ("tyl" . "$B$A$g$s(B") ("tyn" . "$B$A$c$s(B") ("typ" . "$B$A$g$&(B") ("tyq" . "$B$A$c$$(B") ("tyw" . "$B$A$'$$(B")
+ ("tyz" . "$B$A$c$s(B") ("tz" . "$B$?$s(B") ("vd" . "$B$&!+$'$s(B") ("vk" . "$B$&!+$#$s(B") ("vl" . "$B$&!+$)$s(B")
+ ("vn" . "$B$&!+$!$s(B") ("vp" . "$B$&!+$)!<(B") ("vq" . "$B$&!+$!$$(B") ("vw" . "$B$&!+$'$$(B") ("vya" . "$B$&!+$c(B")
+ ("vye" . "$B$&!+$'(B") ("vyo" . "$B$&!+$g(B") ("vyu" . "$B$&!+$e(B") ("vz" . "$B$&!+$!$s(B") ("wA" . "$B$n(B")
+ ("wd" . "$B$&$'$s(B") ("wf" . "$B$o(B") ("wha" . "$B$&$!(B") ("whe" . "$B$&$'(B") ("whi" . "$B$&$#(B")
+ ("who" . "$B$&$)(B") ("whu" . "$B$&(B") ("wk" . "$B$&$#$s(B") ("wl" . "$B$&$)$s(B") ("wn" . "$B$o$s(B")
+ ("wp" . "$B$&$)!<(B") ("wq" . "$B$o$$(B") ("wr" . "$B$o$l(B") ("wso" . "$B$&$)(B") ("wt" . "$B$o$?(B")
+ ("wz" . "$B$o$s(B") ("xa" . "$B$7$c(B") ("xc" . "$B$7$c(B") ("xd" . "$B$7$'$s(B") ("xe" . "$B$7$'(B")
+ ("xf" . "$B$7$'$$(B") ("xh" . "$B$7$e$&(B") ("xi" . "$B$7(B") ("xj" . "$B$7$e$s(B") ("xk" . "$B$7$s(B")
+ ("xl" . "$B$7$g$s(B") ("xn" . "$B$7$c$s(B") ("xo" . "$B$7$g(B") ("xp" . "$B$7$g$&(B") ("xq" . "$B$7$c$$(B")
+ ("xt" . "$B$7$e$D(B") ("xu" . "$B$7$e(B") ("xv" . "$B$7$c$$(B") ("xw" . "$B$7$'$$(B") ("xxa" . "$B$!(B")
+ ("xxe" . "$B$'(B") ("xxi" . "$B$#(B") ("xxo" . "$B$)(B") ("xxu" . "$B$%(B") ("xxh" . "$B"+(B")
+ ("xxj" . "$B"-(B") ("xxk" . "$B",(B") ("xxl" . "$B"*(B") ("xz" . "$B$7$c$s(B") ("y<" . "$B"+(B")
+ ("y>" . "$B"*(B") ("y^" . "$B",(B") ("yf" . "$B$f(B") ("yh" . "$B$f$&(B") ("yi" . "$B$p(B")
+ ("yj" . "$B$f$s(B") ("yl" . "$B$h$s(B") ("yn" . "$B$d$s(B") ("yp" . "$B$h$&(B") ("yq" . "$B$d$$(B")
+ ("yr" . "$B$h$k(B") ("yv" . "$B$f$&(B") ("yz" . "$B$d$s(B") ("z." . "$B$:(B") ("zc" . "$B$6(B")
+ ("zd" . "$B$<$s(B") ("zf" . "$B$<(B") ("zh" . "$B$:$&(B") ("zj" . "$B$:$s(B") ("zk" . "$B$8$s(B")
+ ("zl" . "$B$>$s(B") ("zn" . "$B$6$s(B") ("zp" . "$B$>$&(B") ("zq" . "$B$6$$(B") ("zr" . "$B$6$k(B")
+ ("zv" . "$B$6$$(B") ("zw" . "$B$<$$(B") ("zx" . "$B$<$$(B") ("zyd" . "$B$8$'$s(B") ("zyh" . "$B$8$e$&(B")
+ ("zyj" . "$B$8$e$s(B") ("zyl" . "$B$8$g$s(B") ("zyn" . "$B$8$c$s(B") ("zyp" . "$B$8$g$&(B") ("zyq" . "$B$8$c$$(B")
+ ("zyw" . "$B$8$'$$(B") ("zyz" . "$B$8$c$s(B") ("zz" . "$B$6$s(B") ("bx" . "$B$S$g$&(B") ("bx" . "$B$S$g$&(B")
+ ("dx" . "$B$B$g$&(B") ("gx" . "$B$.$g$&(B") ("hx" . "$B$R$g$&(B") ("kx" . "$B$-$g$&(B") ("mx" . "$B$_$g$&(B")
+ ("nx" . "$B$K$g$&(B") ("px" . "$B$T$g$&(B") ("rx" . "$B$j$g$&(B") ("sx" . "$B$7$g$&(B") ("bv" . "$B$S$e$&(B")
+ ("dv" . "$B$B$e$&(B") ("fv" . "$B$U$e!<(B") ("gv" . "$B$.$e$&(B") ("hv" . "$B$R$e$&(B") ("kv" . "$B$-$e$&(B")
+ ("mv" . "$B$_$e$&(B") ("nv" . "$B$K$e$&(B") ("pv" . "$B$T$e$&(B") ("rv" . "$B$j$e$&(B") ("sv" . "$B$7$e$&(B")
+ ("vv" . "$B$&!+$e!<(B")
+ ))
+
+; (defvar anthy-azik-mode-katakana-map
+; '(
+; (";" . "$B%C(B") ("x;" . ";") ("b." . "$B%V(B") ("bd" . "$B%Y%s(B") ("bh" . "$B%V%&(B")
+; ("bj" . "$B%V%s(B") ("bk" . "$B%S%s(B") ("bl" . "$B%%(Bs") ("bn" . "$B%P%s(B") ("bp" . "$B%%(B&")
+; ("bq" . "$B%P%$(B") ("br" . "$B%P%i(B") ("bt" . "$B%S%H(B") ("bw" . "$B%Y%$(B") ("bx" . "$B%Y%$(B")
+; ("byd" . "$B%S%'%s(B") ("byh" . "$B%S%e%&(B") ("byj" . "$B%S%e%s(B") ("byl" . "$B%S%g%s(B") ("byn" . "$B%S%c%s(B")
+; ("byp" . "$B%S%g%&(B") ("byq" . "$B%S%c%$(B") ("byw" . "$B%S%'%$(B") ("byz" . "$B%S%c%s(B") ("bz" . "$B%P%s(B")
+; ("ca" . "$B%A%c(B") ("cc" . "$B%A%c(B") ("cd" . "$B%A%'%s(B") ("ce" . "$B%A%'(B") ("cf" . "$B%A%'(B")
+; ("ch" . "$B%A%e%&(B") ("ci" . "$B%A(B") ("cj" . "$B%A%e%s(B") ("ck" . "$B%A%s(B") ("cl" . "$B%A%g%s(B")
+; ("cn" . "$B%A%c%s(B") ("co" . "$B%A%g(B") ("cp" . "$B%A%g%&(B") ("cq" . "$B%A%c%$(B") ("cu" . "$B%A%e(B")
+; ("cv" . "$B%A%c%$(B") ("cw" . "$B%A%'%$(B") ("cx" . "$B%A%'%$(B") ("cz" . "$B%A%c%s(B") ("dch" . "$B%G%e!<(B")
+; ("dci" . "$B%G%#(B") ("dck" . "$B%G%#%s(B") ("dcp" . "$B%I%%!<(B") ("dcu" . "$B%G%e(B") ("dd" . "$B%G%s(B")
+; ("df" . "$B%G(B") ("dg" . "$B%@%,(B") ("dh" . "$B%E%&(B") ("dj" . "$B%E%s(B") ("dk" . "$B%B%s(B")
+; ("dl" . "$B%I%s(B") ("dm" . "$B%G%b(B") ("dn" . "$B%@%s(B") ("dp" . "$B%I%&(B") ("dq" . "$B%@%$(B")
+; ("dr" . "$B%G%"%k(B") ("ds" . "$B%G%9(B") ("dt" . "$B%@%A(B") ("dv" . "$B%G%s(B") ("dw" . "$B%G%$(B")
+; ("dy" . "$B%G%#(B") ("dz" . "$B%@%s(B") ("fd" . "$B%U%'%s(B") ("fh" . "$B%U%&(B") ("fj" . "$B%U%s(B")
+; ("fk" . "$B%U%#%s(B") ("fl" . "$B%U%)%s(B") ("fm" . "$B%U%`(B") ("fn" . "$B%U%!%s(B") ("fp" . "$B%U%)!<(B")
+; ("fq" . "$B%U%!%$(B") ("fr" . "$B%U%k(B") ("fs" . "$B%U%!%$(B") ("fw" . "$B%U%'%$(B") ("fz" . "$B%U%!%s(B")
+; ("gd" . "$B%2%s(B") ("gh" . "$B%0%&(B") ("gj" . "$B%0%s(B") ("gk" . "$B%.%s(B") ("gl" . "$B%4%s(B")
+; ("gn" . "$B%,%s(B") ("gp" . "$B%4%&(B") ("gq" . "$B%,%$(B") ("gr" . "$B%,%i(B") ("gt" . "$B%4%H(B")
+; ("gw" . "$B%2%$(B") ("gyd" . "$B%.%'%s(B") ("gyh" . "$B%.%e%&(B") ("gyj" . "$B%.%e%s(B") ("gyl" . "$B%.%g%s(B")
+; ("gyn" . "$B%.%c%s(B") ("gyp" . "$B%.%g%&(B") ("gyq" . "$B%.%c%$(B") ("gyw" . "$B%.%'%$(B") ("gyz" . "$B%.%c%s(B")
+; ("gz" . "$B%,%s(B") ("hd" . "$B%X%s(B") ("hf" . "$B%U(B") ("hga" . "$B%R%c(B") ("hgd" . "$B%R%'%s(B")
+; ("hge" . "$B%R%'(B") ("hgh" . "$B%R%e%&(B") ("hgj" . "$B%R%e%s(B") ("hgl" . "$B%R%g%s(B") ("hgn" . "$B%R%c%s(B")
+; ("hgo" . "$B%R%g(B") ("hgp" . "$B%R%g%&(B") ("hgq" . "$B%R%c%$(B") ("hgu" . "$B%R%e(B") ("hgw" . "$B%R%'%$(B")
+; ("hgz" . "$B%R%c%s(B") ("hh" . "$B%U%&(B") ("hj" . "$B%U%s(B") ("hk" . "$B%R%s(B") ("hl" . "$B%[%s(B")
+; ("hn" . "$B%O%s(B") ("hp" . "$B%[%&(B") ("hq" . "$B%O%$(B") ("ht" . "$B%R%H(B") ("hw" . "$B%X%$(B")
+; ("hyd" . "$B%R%'%s(B") ("hyh" . "$B%R%e%&(B") ("hyl" . "$B%R%g%s(B") ("hyp" . "$B%R%g%&(B") ("hyq" . "$B%R%c%$(B")
+; ("hyw" . "$B%R%'%$(B") ("hyz" . "$B%R%c%s(B") ("hz" . "$B%O%s(B") ("jd" . "$B%8%'%s(B") ("jf" . "$B%8%e(B")
+; ("jh" . "$B%8%e%&(B") ("jj" . "$B%8%e%s(B") ("jk" . "$B%8%s(B") ("jl" . "$B%8%g%s(B") ("jn" . "$B%8%c%s(B")
+; ("jp" . "$B%8%g%&(B") ("jq" . "$B%8%c%$(B") ("jv" . "$B%8%e%&(B") ("jw" . "$B%8%'%$(B") ("jz" . "$B%8%c%s(B")
+; ("kA" . "$B%u(B") ("kE" . "$B%v(B") ("kd" . "$B%1%s(B") ("kf" . "$B%-(B") ("kga" . "$B%-%c(B")
+; ("kgd" . "$B%-%'%s(B") ("kge" . "$B%-%'(B") ("kgh" . "$B%-%e%&(B") ("kgl" . "$B%-%g%s(B") ("kgn" . "$B%-%c%s(B")
+; ("kgo" . "$B%-%g(B") ("kgp" . "$B%-%g%&(B") ("kgq" . "$B%-%c%$(B") ("kgu" . "$B%-%e(B") ("kgw" . "$B%-%'%$(B")
+; ("kgz" . "$B%-%c%s(B") ("kh" . "$B%/%&(B") ("kj" . "$B%/%s(B") ("kk" . "$B%-%s(B") ("kl" . "$B%3%s(B")
+; ("km" . "$B%-(B") ("kn" . "$B%+%s(B") ("kp" . "$B%3%&(B") ("kq" . "$B%+%$(B") ("kr" . "$B%+%i(B")
+; ("kt" . "$B%3%H(B") ("kv" . "$B%-%s(B") ("kw" . "$B%1%$(B") ("kyd" . "$B%-%'%s(B") ("kyh" . "$B%-%e%&(B")
+; ("kyj" . "$B%-%e%s(B") ("kyl" . "$B%-%g%s(B") ("kyn" . "$B%-%c%s(B") ("kyp" . "$B%-%g%&(B") ("kyq" . "$B%-%c%$(B")
+; ("kyw" . "$B%-%'%$(B") ("kyz" . "$B%-%c%s(B") ("kz" . "$B%+%s(B") ("m." . "$B%`(B") ("md" . "$B%a%s(B")
+; ("mf" . "$B%`(B") ("mga" . "$B%_%c(B") ("mgd" . "$B%_%'%s(B") ("mge" . "$B%_%'(B") ("mgh" . "$B%_%e%&(B")
+; ("mgj" . "$B%_%e%s(B") ("mgl" . "$B%_%g%s(B") ("mgn" . "$B%_%c%s(B") ("mgo" . "$B%_%g(B") ("mgp" . "$B%_%g%&(B")
+; ("mgq" . "$B%_%c%$(B") ("mgu" . "$B%_%e(B") ("mgw" . "$B%_%'%$(B") ("mgz" . "$B%_%c%s(B") ("mh" . "$B%`%&(B")
+; ("mj" . "$B%`%s(B") ("mk" . "$B%_%s(B") ("ml" . "$B%b%s(B") ("mn" . "$B%b%N(B") ("mp" . "$B%b%&(B")
+; ("mq" . "$B%^%$(B") ("mr" . "$B%^%k(B") ("ms" . "$B%^%9(B") ("mt" . "$B%^%?(B") ("mv" . "$B%`%s(B")
+; ("mw" . "$B%a%$(B") ("myd" . "$B%_%'%s(B") ("myh" . "$B%_%e%&(B") ("myj" . "$B%_%e%s(B") ("myl" . "$B%_%g%s(B")
+; ("myn" . "$B%_%c%s(B") ("myp" . "$B%_%g%&(B") ("myq" . "$B%_%c%$(B") ("myw" . "$B%_%'%$(B") ("myz" . "$B%_%c%s(B")
+; ("mz" . "$B%^%s(B") ("n." . "$B%L(B") ("nb" . "$B%M%P(B") ("nd" . "$B%M%s(B") ("nf" . "$B%L(B")
+; ("nga" . "$B%K%c(B") ("ngd" . "$B%K%'%s(B") ("nge" . "$B%K%'(B") ("ngh" . "$B%K%e%&(B") ("ngj" . "$B%K%e%s(B")
+; ("ngl" . "$B%K%g%s(B") ("ngn" . "$B%K%c%s(B") ("ngo" . "$B%K%g(B") ("ngp" . "$B%K%g%&(B") ("ngq" . "$B%K%c%$(B")
+; ("ngu" . "$B%K%e(B") ("ngw" . "$B%K%'%$(B") ("ngz" . "$B%K%c%s(B") ("nh" . "$B%L%&(B") ("nj" . "$B%L%s(B")
+; ("nk" . "$B%K%s(B") ("nl" . "$B%N%s(B") ("np" . "$B%N%&(B") ("nq" . "$B%J%$(B") ("nr" . "$B%J%k(B")
+; ("nt" . "$B%K%A(B") ("nv" . "$B%L%s(B") ("nw" . "$B%M%$(B") ("nyd" . "$B%K%'%s(B") ("nyh" . "$B%K%e%&(B")
+; ("nyj" . "$B%K%e%s(B") ("nyl" . "$B%K%g%s(B") ("nyn" . "$B%K%c%s(B") ("nyp" . "$B%K%g%&(B") ("nyq" . "$B%K%c%$(B")
+; ("nyw" . "$B%K%'%$(B") ("nyz" . "$B%K%c%s(B") ("nz" . "$B%J%s(B") ("pd" . "$B%Z%s(B") ("pf" . "$B%]%s(B")
+; ("pga" . "$B%T%c(B") ("pgd" . "$B%T%'%s(B") ("pge" . "$B%T%'(B") ("pgh" . "$B%T%e%&(B") ("pgj" . "$B%T%e%s(B")
+; ("pgl" . "$B%T%g%s(B") ("pgn" . "$B%T%c%s(B") ("pgo" . "$B%T%g(B") ("pgp" . "$B%T%g%&(B") ("pgq" . "$B%T%c%$(B")
+; ("pgu" . "$B%T%e(B") ("pgw" . "$B%T%'%$(B") ("pgz" . "$B%T%c%s(B") ("ph" . "$B%W%&(B") ("pj" . "$B%W%s(B")
+; ("pk" . "$B%T%s(B") ("pl" . "$B%]%s(B") ("pn" . "$B%Q%s(B") ("pp" . "$B%]%&(B") ("pq" . "$B%Q%$(B")
+; ("pv" . "$B%]%&(B") ("pw" . "$B%Z%$(B") ("pyd" . "$B%T%'%s(B") ("pyh" . "$B%T%e%&(B") ("pyj" . "$B%T%e%s(B")
+; ("pyl" . "$B%T%g%s(B") ("pyn" . "$B%T%c%s(B") ("pyp" . "$B%T%g%&(B") ("pyq" . "$B%T%c%$(B") ("pyw" . "$B%T%'%$(B")
+; ("pyz" . "$B%T%c%s(B") ("pz" . "$B%Q%s(B") ("q" . "$B%s(B") ("rd" . "$B%l%s(B") ("rh" . "$B%k%&(B")
+; ("rj" . "$B%k%s(B") ("rk" . "$B%j%s(B") ("rl" . "$B%m%s(B") ("rn" . "$B%i%s(B") ("rp" . "$B%m%&(B")
+; ("rq" . "$B%i%$(B") ("rr" . "$B%i%l(B") ("rw" . "$B%l%$(B") ("ryd" . "$B%j%'%s(B") ("ryh" . "$B%j%e%&(B")
+; ("ryj" . "$B%j%e%s(B") ("ryk" . "$B%j%g%/(B") ("ryl" . "$B%j%g%s(B") ("ryn" . "$B%j%c%s(B") ("ryp" . "$B%j%g%&(B")
+; ("ryq" . "$B%j%c%$(B") ("ryw" . "$B%j%'%$(B") ("ryz" . "$B%j%c%s(B") ("rz" . "$B%i%s(B") ("sd" . "$B%;%s(B")
+; ("sf" . "$B%5%$(B") ("sh" . "$B%9%&(B") ("sj" . "$B%9%s(B") ("sk" . "$B%7%s(B") ("sl" . "$B%=%s(B")
+; ("sm" . "$B%7%b(B") ("sn" . "$B%5%s(B") ("sp" . "$B%=%&(B") ("sq" . "$B%5%$(B") ("sr" . "$B%9%k(B")
+; ("ss" . "$B%;%$(B") ("st" . "$B%7%?(B") ("sv" . "$B%5%$(B") ("sw" . "$B%;%$(B") ("syd" . "$B%7%'%s(B")
+; ("syh" . "$B%7%e%&(B") ("syj" . "$B%7%e%s(B") ("syl" . "$B%7%g%s(B") ("syp" . "$B%7%g%&(B") ("syq" . "$B%7%c%$(B")
+; ("syw" . "$B%7%'%$(B") ("syz" . "$B%7%c%s(B") ("sz" . "$B%5%s(B") ("tU" . "$B%C(B") ("tb" . "$B%?%S(B")
+; ("td" . "$B%F%s(B") ("tgh" . "$B%F%e!<(B") ("tgi" . "$B%F%#(B") ("tgk" . "$B%F%#%s(B") ("tgp" . "$B%H%%!<(B")
+; ("tgu" . "$B%F%e(B") ("th" . "$B%D%&(B") ("tj" . "$B%D%s(B") ("tk" . "$B%A%s(B") ("tl" . "$B%H%s(B")
+; ("tm" . "$B%?%a(B") ("tn" . "$B%?%s(B") ("tp" . "$B%H%&(B") ("tq" . "$B%?%$(B") ("tr" . "$B%?%i(B")
+; ("tsU" . "$B%C(B") ("tsa" . "$B%D%!(B") ("tse" . "$B%D%'(B") ("tsi" . "$B%D%#(B") ("tso" . "$B%D%)(B")
+; ("tt" . "$B%?%A(B") ("tw" . "$B%F%$(B") ("tyd" . "$B%A%'%s(B") ("tyh" . "$B%A%e%&(B") ("tyj" . "$B%A%e%s(B")
+; ("tyl" . "$B%A%g%s(B") ("tyn" . "$B%A%c%s(B") ("typ" . "$B%A%g%&(B") ("tyq" . "$B%A%c%$(B") ("tyw" . "$B%A%'%$(B")
+; ("tyz" . "$B%A%c%s(B") ("tz" . "$B%?%s(B") ("vd" . "$B%t%'%s(B") ("vk" . "$B%t%#%s(B") ("vl" . "$B%t%)%s(B")
+; ("vn" . "$B%t%!%s(B") ("vp" . "$B%t%)!<(B") ("vq" . "$B%t%!%$(B") ("vw" . "$B%t%'%$(B") ("vya" . "$B%t%c(B")
+; ("vye" . "$B%t%'(B") ("vyo" . "$B%t%g(B") ("vyu" . "$B%t%e(B") ("vz" . "$B%t%!%s(B") ("wA" . "$B%n(B")
+; ("wd" . "$B%&%'%s(B") ("wf" . "$B%o(B") ("wha" . "$B%&%!(B") ("whe" . "$B%&%'(B") ("whi" . "$B%&%#(B")
+; ("who" . "$B%&%)(B") ("whu" . "$B%&(B") ("wk" . "$B%&%#%s(B") ("wl" . "$B%&%)%s(B") ("wn" . "$B%o%s(B")
+; ("wp" . "$B%&%)!<(B") ("wq" . "$B%o%$(B") ("wr" . "$B%o%l(B") ("wso" . "$B%&%)(B") ("wt" . "$B%o%?(B")
+; ("wz" . "$B%o%s(B") ("xa" . "$B%7%c(B") ("xc" . "$B%7%c(B") ("xd" . "$B%7%'%s(B") ("xe" . "$B%7%'(B")
+; ("xf" . "$B%7%'%$(B") ("xh" . "$B%7%e%&(B") ("xi" . "$B%7(B") ("xj" . "$B%7%e%s(B") ("xk" . "$B%7%s(B")
+; ("xl" . "$B%7%g%s(B") ("xn" . "$B%7%c%s(B") ("xo" . "$B%7%g(B") ("xp" . "$B%7%g%&(B") ("xq" . "$B%7%c%$(B")
+; ("xt" . "$B%7%e%D(B") ("xu" . "$B%7%e(B") ("xv" . "$B%7%c%$(B") ("xw" . "$B%7%'%$(B") ("xxa" . "$B%!(B")
+; ("xxe" . "$B%'(B") ("xxi" . "$B%#(B") ("xxo" . "$B%)(B") ("xxu" . "$B%%(B") ("xxh" . "$B"+(B")
+; ("xxj" . "$B"-(B") ("xxk" . "$B",(B") ("xxl" . "$B"*(B") ("xz" . "$B%7%c%s(B") ("y<" . "$B"+(B")
+; ("y>" . "$B"*(B") ("y^" . "$B",(B") ("yf" . "$B%f(B") ("yh" . "$B%f%&(B") ("yi" . "$B%p(B")
+; ("yj" . "$B%f%s(B") ("yl" . "$B%h%s(B") ("yn" . "$B%d%s(B") ("yp" . "$B%h%&(B") ("yq" . "$B%d%$(B")
+; ("yr" . "$B%h%k(B") ("yv" . "$B%f%&(B") ("yz" . "$B%d%s(B") ("z." . "$B%:(B") ("zc" . "$B%6(B")
+; ("zd" . "$B%<%s(B") ("zf" . "$B%<(B") ("zh" . "$B%:%&(B") ("zj" . "$B%:%s(B") ("zk" . "$B%8%s(B")
+; ("zl" . "$B%>%s(B") ("zn" . "$B%6%s(B") ("zp" . "$B%>%&(B") ("zq" . "$B%6%$(B") ("zr" . "$B%6%k(B")
+; ("zv" . "$B%6%$(B") ("zw" . "$B%<%$(B") ("zx" . "$B%<%$(B") ("zyd" . "$B%8%'%s(B") ("zyh" . "$B%8%e%&(B")
+; ("zyj" . "$B%8%e%s(B") ("zyl" . "$B%8%g%s(B") ("zyn" . "$B%8%c%s(B") ("zyp" . "$B%8%g%&(B") ("zyq" . "$B%8%c%$(B")
+; ("zyw" . "$B%8%'%$(B") ("zyz" . "$B%8%c%s(B") ("zz" . "$B%6%s(B") ("bx" . "$B%S%g%&(B") ("bx" . "$B%S%g%&(B")
+; ("dx" . "$B%B%g%&(B") ("gx" . "$B%.%g%&(B") ("hx" . "$B%R%g%&(B") ("kx" . "$B%-%g%&(B") ("mx" . "$B%_%g%&(B")
+; ("nx" . "$B%K%g%&(B") ("px" . "$B%T%g%&(B") ("rx" . "$B%j%g%&(B") ("sx" . "$B%7%g%&(B") ("bv" . "$B%S%e%&(B")
+; ("dv" . "$B%B%e%&(B") ("fv" . "$B%U%e!<(B") ("gv" . "$B%.%e%&(B") ("hv" . "$B%R%e%&(B") ("kv" . "$B%-%e%&(B")
+; ("mv" . "$B%_%e%&(B") ("nv" . "$B%K%e%&(B") ("pv" . "$B%T%e%&(B") ("rv" . "$B%j%e%&(B") ("sv" . "$B%7%e%&(B")
+; ("vv" . "$B%&!+%e!<(B")
+; ))
+
+(defun anthy-azik-mode ()
+ (interactive)
+ (setq anthy-rkmap-keybind
+ '(
+ ;; \C-p
+ (("hiragana" . 16) . "katakana")
+ (("katakana" . 16) . "hiragana")))
+; (define-key anthy-mode-map (char-to-string 16) 'anthy-insert)
+ (anthy-send-change-toggle-command "!")
+ (mapcar (lambda (x)
+ (anthy-change-hiragana-map (car x) (cdr x)))
+ anthy-azik-mode-hiragana-map)
+ (anthy-hiragana-map))
+; (mapcar (lambda (x)
+; (anthy-change-katakana-map (car x) (cdr x)))
+; anthy-azik-mode-katakana-map)
+
diff --git a/src-util/anthy-conf.el b/src-util/anthy-conf.el
new file mode 100644
index 0000000..3d6fbf7
--- /dev/null
+++ b/src-util/anthy-conf.el
@@ -0,0 +1,122 @@
+;; anthy-conf.el -- Anthy
+
+
+;; Copyright (C) 2002
+;; Author: Yusuke Tabata<yusuke@kmc.gr.jp>
+
+;; This file is part of Anthy
+
+;;; Commentary:
+;;
+
+(defvar anthy-alt-char-map
+ '(("," "$B!$(B")
+ ("." "$B!%(B")))
+
+(defvar anthy-kana-mode-hiragana-map
+ '(
+ ("3" . "$B$"(B") ("e" . "$B$$(B") ("4" . "$B$&(B") ("5" . "$B$((B") ("6" . "$B$*(B")
+ ("#" . "$B$!(B") ("E" . "$B$#(B") ("$" . "$B$%(B") ("%" . "$B$'(B") ("&" . "$B$)(B")
+ ("t" . "$B$+(B") ("g" . "$B$-(B") ("h" . "$B$/(B") (":" . "$B$1(B") ("b" . "$B$3(B")
+ ("t@" . "$B$,(B") ("g@" . "$B$.(B") ("h@" . "$B$0(B") (":@" . "$B$2(B") ("b@" . "$B$4(B")
+ ("x" . "$B$5(B") ("d" . "$B$7(B") ("r" . "$B$9(B") ("p" . "$B$;(B") ("c" . "$B$=(B")
+ ("x@" . "$B$6(B") ("d@" . "$B$8(B") ("r@" . "$B$:(B") ("p@" . "$B$<(B") ("c@" . "$B$>(B")
+ ("q" . "$B$?(B") ("a" . "$B$A(B") ("z" . "$B$D(B") ("w" . "$B$F(B") ("s" . "$B$H(B")
+ ("q@" . "$B$@(B") ("a@" . "$B$B(B") ("z@" . "$B$E(B") ("w@" . "$B$G(B") ("s@" . "$B$I(B")
+ ("u" . "$B$J(B") ("i" . "$B$K(B") ("1" . "$B$L(B") ("," . "$B$M(B") ("k" . "$B$N(B")
+ ("f" . "$B$O(B") ("v" . "$B$R(B") ("2" . "$B$U(B") ("^" . "$B$X(B") ("-" . "$B$[(B")
+ ("f@" . "$B$P(B") ("v@" . "$B$S(B") ("2@" . "$B$V(B") ("^@" . "$B$Y(B") ("-@" . "$B$\(B")
+ ("f[" . "$B$Q(B") ("v[" . "$B$T(B") ("2[" . "$B$W(B") ("^[" . "$B$Z(B") ("-[" . "$B$](B")
+ ("j" . "$B$^(B") ("n" . "$B$_(B") ("]" . "$B$`(B") ("/" . "$B$a(B") ("m" . "$B$b(B")
+ ("7" . "$B$d(B") ("8" . "$B$f(B") ("9" . "$B$h(B")
+ ("'" . "$B$c(B") ("(" . "$B$e(B") (")" . "$B$g(B")
+ ("o" . "$B$i(B") ("l" . "$B$j(B") ("." . "$B$k(B") (";" . "$B$l(B") ("\\" . "$B$m(B")
+ ("0" . "$B$o(B") ("~" . "$B$r(B")
+
+ ;; $B:$$C$?$3$H$K(B $B%P%C%/%9%i%C%7%e$H1_$r6hJL$9$kJ}K!$,$o$+$i$J$$(B
+ ("|" . "$B!<(B") ("_" . "$B!<(B") ("<" . "$B!"(B") (">" . "$B!#(B")
+ ("Z" . "$B$C(B") ("y" . "$B$s(B")
+ ))
+
+(defvar anthy-kana-mode-katakana-map
+ '(
+ ("3" . "$B%"(B") ("e" . "$B%$(B") ("4" . "$B%&(B") ("5" . "$B%((B") ("6" . "$B%*(B")
+ ("#" . "$B%!(B") ("E" . "$B%#(B") ("$" . "$B%%(B") ("%" . "$B%'(B") ("&" . "$B%)(B")
+ ("t" . "$B%+(B") ("g" . "$B%-(B") ("h" . "$B%/(B") (":" . "$B%1(B") ("b" . "$B%3(B")
+ ("t@" . "$B%,(B") ("g@" . "$B%.(B") ("h@" . "$B%0(B") (":@" . "$B%2(B") ("b@" . "$B%4(B")
+ ("x" . "$B%5(B") ("d" . "$B%7(B") ("r" . "$B%9(B") ("p" . "$B%;(B") ("c" . "$B%=(B")
+ ("x@" . "$B%6(B") ("d@" . "$B%8(B") ("r@" . "$B%:(B") ("p@" . "$B%<(B") ("c@" . "$B%>(B")
+ ("q" . "$B%?(B") ("a" . "$B%A(B") ("z" . "$B%D(B") ("w" . "$B%F(B") ("s" . "$B%H(B")
+ ("q@" . "$B%@(B") ("a@" . "$B%B(B") ("z@" . "$B%E(B") ("w@" . "$B%G(B") ("s@" . "$B%I(B")
+ ("u" . "$B%J(B") ("i" . "$B%K(B") ("1" . "$B%L(B") ("," . "$B%M(B") ("k" . "$B%N(B")
+ ("f" . "$B%O(B") ("v" . "$B%R(B") ("2" . "$B%U(B") ("^" . "$B%X(B") ("-" . "$B%[(B")
+ ("f@" . "$B%P(B") ("v@" . "$B%S(B") ("2@" . "$B%V(B") ("^@" . "$B%Y(B") ("-@" . "$B%\(B")
+ ("f[" . "$B%Q(B") ("v[" . "$B%T(B") ("2[" . "$B%W(B") ("^[" . "$B%Z(B") ("-[" . "$B%](B")
+ ("j" . "$B%^(B") ("n" . "$B%_(B") ("]" . "$B%`(B") ("/" . "$B%a(B") ("m" . "$B%b(B")
+ ("7" . "$B%d(B") ("8" . "$B%f(B") ("9" . "$B%h(B")
+ ("'" . "$B%c(B") ("(" . "$B%e(B") (")" . "$B%g(B")
+ ("o" . "$B%i(B") ("l" . "$B%j(B") ("." . "$B%k(B") (";" . "$B%l(B") ("\\" . "$B%m(B")
+ ("0" . "$B%o(B") ("~" . "$B%r(B")
+
+ ;; $B:$$C$?$3$H$K(B $B%P%C%/%9%i%C%7%e$H1_$r6hJL$9$kJ}K!$,$o$+$i$J$$(B
+ ("|" . "$B!<(B") ("_" . "$B!<(B") ("<" . "$B!"(B") (">" . "$B!#(B")
+ ("Z" . "$B%C(B") ("y" . "$B%s(B")
+ ))
+
+;;
+;; map$B$NJQ99(B
+;;
+(defun anthy-send-map-edit-command (mapno key str)
+ (if (not (stringp key))
+ (setq key (char-to-string key)))
+ (if (not (stringp str))
+ (setq str (char-to-string str)))
+ (anthy-send-recv-command
+ (concat " MAP_EDIT " (int-to-string mapno)
+ " " key " " str "\n")))
+(defun anthy-change-hiragana-map (key str)
+ (anthy-send-map-edit-command 2 key str))
+(defun anthy-change-katakana-map (key str)
+ (anthy-send-map-edit-command 3 key str))
+(defun anthy-load-hiragana-map (map)
+ (mapcar (lambda (x)
+ (let ((key (car x))
+ (str (cadr x)))
+ (anthy-change-hiragana-map key str))) map))
+(defun anthy-clear-map ()
+ (anthy-send-recv-command
+ " MAP_CLEAR 0\n"))
+;;
+;; toggle$B$NJQ99(B
+;;
+(defun anthy-send-change-toggle-command (str)
+ (anthy-send-recv-command
+ (concat " CHANGE_TOGGLE " str "\n")))
+
+;; should disable toggle
+;; ($B%m!<%^;z$G$O$J$/$F(B)$B$+$J%b!<%I$K$9$k(B
+(defun anthy-kana-map-mode ()
+ (setq anthy-rkmap-keybind
+ '(
+ ;; \C-p
+ (("hiragana" . 16) . "katakana")
+ (("katakana" . 16) . "hiragana")))
+ (define-key anthy-mode-map (char-to-string 16) 'anthy-insert)
+ (anthy-send-recv-command " SET_PREEDIT_MODE 1\n")
+ (anthy-send-change-toggle-command "!")
+ (anthy-clear-map)
+ (mapcar (lambda (x)
+ (anthy-change-hiragana-map (car x) (cdr x)))
+ anthy-kana-mode-hiragana-map)
+ (mapcar (lambda (x)
+ (anthy-change-katakana-map (car x) (cdr x)))
+ anthy-kana-mode-katakana-map))
+;;
+(defun anthy-set-break-into-roman (flag)
+ "$BFI$_$rF~NOCf$K%P%C%/%9%Z!<%9$rBG$D$H%m!<%^;z$^$G%P%i%P%i$K$9$k(B"
+ (anthy-send-recv-command
+ (if flag
+ " BREAK_INTO_ROMAN 1\n"
+ " BREAK_INTO_ROMAN 0\n")))
+
+(provide 'anthy-conf)
diff --git a/src-util/anthy-dic.el b/src-util/anthy-dic.el
new file mode 100644
index 0000000..07cfc7b
--- /dev/null
+++ b/src-util/anthy-dic.el
@@ -0,0 +1,132 @@
+;; anthy-dic.el -- Anthy
+
+;; Copyright (C) 2001 - 2005
+;; Author: Yusuke Tabata<yusuke@w5.dion.ne.jp>
+;; : Tomoharu Ugawa
+
+;; This file is part of Anthy
+
+;;; Commentary:
+;;
+;; tooo experimental
+;;
+;;
+;; Funded by IPA$BL$F'%=%U%H%&%'%"AOB$;v6H(B 2001 11/10
+
+;;; Code
+(defvar anthy-dic-util-command "anthy-dic-tool")
+(defvar anthy-dic-buffer-name " *anthy-dic*")
+
+(defun anthy-add-word-compose-paramlist (param)
+ (let ((str ""))
+ (while param
+ (let* ((cur (car param))
+ (var (car cur))
+ (val (if (stringp (car (cdr cur)))
+ (car (cdr cur))
+ (if (car (cdr cur)) "y" "n"))))
+ (setq str (concat str
+ var "\t=\t" val "\n")))
+ (setq param (cdr param)))
+ str))
+
+(defun anthy-add-word (yomi freq word paramlist)
+ (let ((proc))
+ (setq proc (start-process "anthy-dic" anthy-dic-buffer-name
+ anthy-dic-util-command "--append"))
+ (if proc
+ (progn
+ (if anthy-xemacs
+ (if (coding-system-p (find-coding-system 'euc-japan))
+ (set-process-coding-system proc 'euc-japan 'euc-japan))
+ (cond ((coding-system-p 'euc-japan)
+ (set-process-coding-system proc 'euc-japan 'euc-japan))
+ ((coding-system-p '*euc-japan*)
+ (set-process-coding-system proc '*euc-japan* '*euc-japan*))))
+ (process-send-string proc
+ (concat yomi " " (int-to-string freq) " " word "\n"))
+ (process-send-string proc
+ (anthy-add-word-compose-paramlist paramlist))
+ (process-send-string proc "\n")
+ (process-send-eof proc)
+ t)
+ nil)))
+
+(defun anthy-dic-get-noun-category (word)
+ (let
+ ((res '(("$BIJ;l(B" "$BL>;l(B")))
+ (na (y-or-n-p (concat "$B!V(B" word "$B$J!W$H8@$$$^$9$+(B? ")))
+ (sa (y-or-n-p (concat "$B!V(B" word "$B$5!W$H8@$$$^$9$+(B? ")))
+ (suru (y-or-n-p (concat "$B!V(B" word "$B$9$k!W$H8@$$$^$9$+(B? ")))
+ (ind (y-or-n-p (concat "$B!V(B" word "$B!W$OC1FH$GJ8@a$K$J$j$^$9$+(B? ")))
+ (kaku (y-or-n-p (concat "$B!V(B" word "$B$H!W$H8@$$$^$9$+(B? "))))
+ (setq res (cons `("$B$J@\B3(B" ,na) res))
+ (setq res (cons `("$B$5@\B3(B" ,sa) res))
+ (setq res (cons `("$B$9$k@\B3(B" ,suru) res))
+ (setq res (cons `("$B8l44$N$_$GJ8@a(B" ,ind) res))
+ (setq res (cons `("$B3J=u;l@\B3(B" ,kaku) res))
+ res))
+
+(defun anthy-dic-get-special-noun-category (word)
+ (let
+ ((res '())
+ (cat (string-to-int
+ (read-from-minibuffer "1:$B?ML>(B 2:$BCOL>(B: "))))
+ (cond ((= cat 1)
+ (setq res '(("$BIJ;l(B" "$B?ML>(B"))))
+ ((= cat 2)
+ (setq res '(("$BIJ;l(B" "$BCOL>(B")))))
+ res))
+
+(defun anthy-dic-get-adjective-category (word)
+ '(("$BIJ;l(B" "$B7AMF;l(B")))
+
+(defun anthy-dic-get-av-category (word)
+ (let
+ ((res '(("$BIJ;l(B" "$BI{;l(B")))
+ (to (y-or-n-p (concat "$B!V(B" word "$B$H!W$H8@$$$^$9$+(B?")))
+ (taru (y-or-n-p (concat "$B!V(B" word "$B$?$k!W$H8@$$$^$9$+(B?")))
+ (suru (y-or-n-p (concat "$B!V(B" word "$B$9$k!W$H8@$$$^$9$+(B?")))
+ (ind (y-or-n-p (concat "$B!V(B" word "$B!W$OC1FH$GJ8@a$K$J$j$^$9$+(B?"))))
+ (setq res (cons `("$B$H@\B3(B" ,to) res))
+ (setq res (cons `("$B$?$k@\B3(B" ,taru) res))
+ (setq res (cons `("$B$9$k@\B3(B" ,suru) res))
+ (setq res (cons `("$B8l44$N$_$GJ8@a(B" ,ind) res))
+ res))
+
+;; taken from tooltip.el
+(defmacro anthy-region-active-p ()
+ "Value is non-nil if the region is currently active."
+ (if (string-match "^GNU" (emacs-version))
+ `(and transient-mark-mode mark-active)
+ `(region-active-p)))
+
+(defun anthy-add-word-interactive ()
+ ""
+ (interactive)
+ (let
+ ((param '()) (res '())
+ (word (if (anthy-region-active-p)
+ (buffer-substring (region-beginning) (region-end))
+ ""))
+ yomi cat)
+ (and (string= word "")
+ (setq word (read-from-minibuffer "$BC18l(B($B8l44$N$_(B): ")))
+ (setq yomi (read-from-minibuffer (concat "$BFI$_(B (" word "): ")))
+ (setq cat (string-to-int
+ (read-from-minibuffer
+ "$B%+%F%4%j!<(B 1:$B0lHLL>;l(B 2:$B$=$NB>$NL>;l(B 3:$B7AMF;l(B 4:$BI{;l(B: ")))
+ (cond ((= cat 1)
+ (setq param (anthy-dic-get-noun-category word)))
+ ((= cat 2)
+ (setq param (anthy-dic-get-special-noun-category word)))
+ ((= cat 3)
+ (setq param (anthy-dic-get-adjective-category word)))
+ ((= cat 4)
+ (setq param (anthy-dic-get-av-category word))))
+ (if param
+ (setq res (anthy-add-word yomi 1 word param)))
+ (if res
+ (message (concat word "(" yomi ")$B$rEPO?$7$^$7$?(B")))))
+
+(provide 'anthy-dic)
diff --git a/src-util/anthy-isearch.el b/src-util/anthy-isearch.el
new file mode 100644
index 0000000..46d186f
--- /dev/null
+++ b/src-util/anthy-isearch.el
@@ -0,0 +1,102 @@
+;; anthy-isearch.el -- Anthy
+
+;; Copyright (C) 2003
+;; Author: Yusuke Tabata <yusuke@cherbim.icw.co.jp>
+
+;; DO NOT USE NOW.
+;;
+
+;;; Commentary:
+;; TOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO many things to be implemented.
+;; most of the code is stolen from SKK.
+;; for Emacs-21
+
+(require 'anthy)
+
+(defvar anthy-isearch-mode-map nil)
+
+;; $B8!:wBP>]$NJ8;zNs$H%W%j%(%G%#%C%H$rF~$l$k%P%C%U%!(B
+(defconst anthy-isearch-working-buffer " *anthy-isearch*")
+
+;; $B8!:wBP>]$NJ8;zNs$r<hF@$9$k(B
+(defun anthy-isearch-search-string ()
+ (with-current-buffer (get-buffer-create anthy-isearch-working-buffer)
+ (if (string-equal anthy-preedit "")
+ ;; $B%W%j%(%G%#%C%H$,L5$$;~$O(B
+ (buffer-string)
+ (save-restriction
+ (narrow-to-region (point-min) anthy-preedit-start)
+ (buffer-string)))))
+
+;; $B8!:wBP>]$NJ8;zNs(B + $BF~NOESCf$NJ8;zNs(B
+(defun anthy-isearch-search-message ()
+ (with-current-buffer (get-buffer-create anthy-isearch-working-buffer)
+ (buffer-string)))
+
+(defun anthy-isearch-process-search-string (string msg)
+ (setq isearch-string "")
+ (setq isearch-message "")
+ (isearch-process-search-string string msg))
+
+(defun anthy-isearch-raw-input ()
+ (with-current-buffer (get-buffer-create anthy-isearch-working-buffer)
+ (self-insert-command 1)))
+
+(defun anthy-isearch-wrapper (&rest args)
+ (interactive "P")
+ (if current-input-method
+ (with-current-buffer (get-buffer-create anthy-isearch-working-buffer)
+ (anthy-insert))
+ (anthy-isearch-raw-input))
+ (anthy-isearch-process-search-string
+ (anthy-isearch-search-string)
+ (anthy-isearch-search-message)))
+
+(defun anthy-isearch-keyboard-quit (&rest args)
+ (interactive "P")
+ (let ((p nil))
+ (with-current-buffer (get-buffer-create anthy-isearch-working-buffer)
+ (if (not (string-equal "" anthy-preedit))
+ (setq p t)))
+ (if p
+ (anthy-isearch-wrapper)
+ (progn
+ (setq isearch-string "")
+ (setq isearch-message "")
+ (isearch-abort)))))
+
+(defun anthy-isearch-toggle-input-method (&rest args)
+ (interactive "P")
+ (isearch-toggle-input-method))
+
+(defun anthy-isearch-setup-keymap (map)
+ (let ((i 0))
+ (while (< i 127)
+ (define-key map (char-to-string i) 'anthy-isearch-wrapper)
+ (setq i (+ 1 i)))
+ (define-key map "\C-g" 'anthy-isearch-keyboard-quit)
+ (substitute-key-definition
+ 'isearch-toggle-input-method
+ 'anthy-isearch-toggle-input-method
+ map isearch-mode-map)
+ map))
+
+(defun anthy-isearch-mode-setup ()
+ ;; $B:G=i$O%-!<%^%C%W$r=`Hw$9$k(B
+ (or (keymapp anthy-isearch-mode-map)
+ (setq anthy-isearch-mode-map
+ (anthy-isearch-setup-keymap (copy-keymap isearch-mode-map))))
+ ;;
+ (setq overriding-terminal-local-map anthy-isearch-mode-map)
+ (with-current-buffer (get-buffer-create anthy-isearch-working-buffer)
+ (erase-buffer))
+ ())
+
+(defun anthy-isearch-mode-cleanup ()
+ (setq overriding-terminal-local-map nil)
+ (kill-buffer anthy-isearch-working-buffer)
+ ())
+
+(add-hook 'isearch-mode-hook 'anthy-isearch-mode-setup)
+(add-hook 'isearch-mode-end-hook 'anthy-isearch-mode-cleanup)
+(setq debug-on-error 't)
diff --git a/src-util/anthy-kyuri.el b/src-util/anthy-kyuri.el
new file mode 100644
index 0000000..ddbcbd8
--- /dev/null
+++ b/src-util/anthy-kyuri.el
@@ -0,0 +1,210 @@
+;; anthy-kyuri.el
+
+;; Copyright (C) 2005
+;; Author: Yukihiro Matsumoto <matz@ruby-lang.org>
+
+(require 'anthy)
+
+(setq anthy-kyuri-mode-hiragana-map
+ '(
+ ("bh" . "$B$!(B") ("h" . "$B$"(B") ("bk" . "$B$#(B") ("k" . "$B$$(B") ("bj" . "$B$%(B")
+ ("j" . "$B$&(B") ("yj" . "$B$&!+(B") ("yh" . "$B$&!+$!(B") ("yk" . "$B$&!+$#(B") ("y;" . "$B$&!+$'(B")
+ ("yl" . "$B$&!+$)(B") ("b;" . "$B$'(B") (";" . "$B$((B") ("bl" . "$B$)(B") ("l" . "$B$*(B")
+ ("dh" . "$B$+(B") ("qh" . "$B$,(B") ("dk" . "$B$-(B") ("du" . "$B$-$c(B") ("di" . "$B$-$e(B") ("do" . "$B$-$g(B")
+ ("duu" . "$B$-$c$"(B") ("dii" . "$B$-$e$&(B") ("doo" . "$B$-$g$&(B")
+ ("qk" . "$B$.(B") ("qu" . "$B$.$c(B") ("qi" . "$B$.$e(B") ("qo" . "$B$.$g(B")
+ ("quu" . "$B$.$c$"(B") ("qii" . "$B$.$e$&(B") ("qoo" . "$B$.$g$&(B")
+ ("dj" . "$B$/(B") ("qj" . "$B$0(B") ("d;" . "$B$1(B") ("q;" . "$B$2(B") ("dl" . "$B$3(B") ("ql" . "$B$4(B")
+ ("fh" . "$B$5(B") ("zh" . "$B$6(B") ("fk" . "$B$7(B")
+ ("fu" . "$B$7$c(B") ("fi" . "$B$7$e(B") ("fo" . "$B$7$g(B") ("fb;" . "$B$7$'(B")
+ ("fuu" . "$B$7$c$"(B") ("fii" . "$B$7$e$&(B") ("foo" . "$B$7$g$&(B")
+ ("zk" . "$B$8(B") ("zu" . "$B$8$c(B") ("zi" . "$B$8$e(B") ("zo" . "$B$8$g(B")
+ ("zuu" . "$B$8$c$"(B") ("zii" . "$B$8$e$&(B") ("zoo" . "$B$8$g$&(B")
+ ("fj" . "$B$9(B") ("zj" . "$B$:(B") ("f;" . "$B$;(B") ("z;" . "$B$<(B") ("fl" . "$B$=(B") ("zl" . "$B$>(B")
+ ("gh" . "$B$?(B") ("vh" . "$B$@(B") ("gk" . "$B$A(B")
+ ("gu" . "$B$A$c(B") ("gi" . "$B$A$e(B") ("go" . "$B$A$g(B") ("gb;" . "$B$A$'(B")
+ ("guu" . "$B$A$c$"(B") ("gii" . "$B$A$e$&(B") ("goo" . "$B$A$g$&(B")
+ ("vk" . "$B$B(B") ("vu" . "$B$B$c(B") ("vi" . "$B$B$e(B") ("vo" . "$B$B$g(B") ("vb;" . "$B$B$'(B")
+ ("vuu" . "$B$B$c$"(B") ("vii" . "$B$B$e$&(B")
+ ("voo" . "$B$B$g$&(B") ("m" . "$B$C(B") ("ddh" . "$B$C$+(B") ("qqh" . "$B$C$,(B") ("ddk" . "$B$C$-(B")
+ ("ddu" . "$B$C$-$c(B") ("ddi" . "$B$C$-$e(B") ("ddo" . "$B$C$-$g(B")
+ ("dduu" . "$B$C$-$c$"(B") ("ddii" . "$B$C$-$e$&(B") ("ddoo" . "$B$C$-$g$&(B")
+ ("qqk" . "$B$C$.(B") ("qqu" . "$B$C$.$c(B") ("qqi" . "$B$C$.$e(B") ("qqo" . "$B$C$.$g(B")
+ ("qquu" . "$B$C$.$c$"(B") ("qqii" . "$B$C$.$e$&(B") ("qqoo" . "$B$C$.$g$&(B")
+ ("ddj" . "$B$C$/(B") ("dd;" . "$B$C$1(B") ("ddl" . "$B$C$3(B")
+ ("qqj" . "$B$C$0(B") ("qq;" . "$B$C$2(B") ("qql" . "$B$C$4(B")
+ ("ffh" . "$B$C$5(B") ("zzh" . "$B$C$6(B") ("ffk" . "$B$C$7(B")
+ ("ffu" . "$B$C$7$c(B") ("ffi" . "$B$C$7$e(B") ("ffo" . "$B$C$7$g(B")
+ ("ffuu" . "$B$C$7$c$"(B") ("ffii" . "$B$C$7$e$&(B") ("ffoo" . "$B$C$7$g$&(B")
+ ("zzk" . "$B$C$8(B")
+ ("zzu" . "$B$C$8$c(B") ("zzi" . "$B$C$8$e(B") ("zzo" . "$B$C$8$g(B")
+ ("zzuu" . "$B$C$8$c$"(B") ("zzii" . "$B$C$8$e$&(B") ("zzoo" . "$B$C$8$g$&(B")
+ ("ffj" . "$B$C$9(B") ("zzj" . "$B$C$:(B") ("ff;" . "$B$C$;(B") ("zz;" . "$B$C$<(B") ("ffl" . "$B$C$=(B")
+ ("zzl" . "$B$C$>(B") ("ggh" . "$B$C$?(B") ("vvh" . "$B$C$@(B") ("ggk" . "$B$C$A(B")
+ ("ggu" . "$B$C$A$c(B") ("ggi" . "$B$C$A$e(B") ("ggo" . "$B$C$A$g(B") ("ggb;" . "$B$C$A$'(B")
+ ("gguu" . "$B$C$A$c$"(B") ("ggii" . "$B$C$A$e$&(B") ("ggoo" . "$B$C$A$g$&(B")
+ ("vvk" . "$B$C$B(B")
+ ("vvu" . "$B$C$B$c(B") ("vvi" . "$B$C$B$e(B") ("vvoo" . "$B$C$B$g(B")
+ ("vvuu" . "$B$C$B$c$"(B") ("vvii" . "$B$C$B$e$&(B") ("vvoo" . "$B$C$B$g$&(B")
+ ("ggj" . "$B$C$D(B") ("gg;" . "$B$C$F(B") ("ggl" . "$B$C$H(B")
+ ("vvj" . "$B$C$E(B") ("vv;" . "$B$C$G(B") ("vvl" . "$B$C$I(B")
+ ("ssh" . "$B$C$O(B") ("cch" . "$B$C$P(B") ("tth" . "$B$C$Q(B")
+ ("ttk" . "$B$C$R(B")
+ ("ssu" . "$B$C$R$c(B") ("ssi" . "$B$C$R$e(B") ("sso" . "$B$C$R$g(B")
+ ("ssuu" . "$B$C$R$c$"(B") ("ssii" . "$B$C$R$e$&(B") ("ssoo" . "$B$C$R$g$&(B")
+ ("cck" . "$B$C$S(B")
+ ("ccu" . "$B$C$S$c(B") ("ccii" . "$B$C$S$e(B") ("cco" . "$B$C$S$g(B")
+ ("ccuu" . "$B$C$S$c$"(B") ("ccii" . "$B$C$S$e$&(B") ("ccoo" . "$B$C$S$g$&(B")
+ ("ttk" . "$B$C$T(B")
+ ("ttu" . "$B$C$T$c(B") ("tti" . "$B$C$T$e(B") ("tto" . "$B$C$T$g(B")
+ ("ttuu" . "$B$C$T$c$"(B") ("ttii" . "$B$C$T$e$&(B") ("ttoo" . "$B$C$T$g$&(B")
+ ("ssj" . "$B$C$U(B")
+ ("ssbh" . "$B$C$U$!(B") ("ssbk" . "$B$C$U$#(B") ("ssb;" . "$B$C$U$'(B") ("ssbl" . "$B$C$U$)(B")
+ ("ccj" . "$B$C$V(B") ("ttj" . "$B$C$W(B") ("ss;" . "$B$C$X(B") ("cc;" . "$B$C$Y(B") ("tt;" . "$B$C$Z(B")
+ ("ssl" . "$B$C$[(B") ("ccl" . "$B$C$\(B") ("ttl" . "$B$C$](B") ("aah" . "$B$C$d(B") ("aaj" . "$B$C$f(B")
+ ("yyo" . "$B$C$h(B") ("rra" . "$B$C$i(B") ("rri" . "$B$C$j(B")
+ ("rru" . "$B$C$j$c(B") ("rri" . "$B$C$j$e(B") ("rro" . "$B$C$j$g(B")
+ ("rruu" . "$B$C$j$c$"(B") ("rrii" . "$B$C$j$e$&(B") ("rroo" . "$B$C$j$g$&(B")
+ ("rrj" . "$B$C$k(B") ("rr;" . "$B$C$l(B") ("rrl" . "$B$C$m(B")
+ ("gj" . "$B$D(B") ("vj" . "$B$E(B") ("g;" . "$B$F(B") ("v;" . "$B$G(B")
+ ("vbu" . "$B$G$c(B") ("vbk" . "$B$G$#(B") ("vbj" . "$B$G$e(B") ("vb;" . "$B$G$'(B") ("vbo" . "$B$G$g(B")
+ ("gbu" . "$B$F$c(B") ("gbk" . "$B$F$#(B") ("gbj" . "$B$F$e(B") ("gbo" . "$B$F$g(B")
+ ("gl" . "$B$H(B") ("vl" . "$B$I(B") ("eh" . "$B$J(B") ("ek" . "$B$K(B")
+ ("eu" . "$B$K$c(B") ("ei" . "$B$K$e(B") ("eo" . "$B$K$g(B")
+ ("euu" . "$B$K$c$"(B") ("eii" . "$B$K$e$&(B") ("eoo" . "$B$K$g$&(B")
+ ("ej" . "$B$L(B") ("e;" . "$B$M(B") ("el" . "$B$N(B")
+ ("sh" . "$B$O(B") ("ch" . "$B$P(B") ("th" . "$B$Q(B") ("sk" . "$B$R(B")
+ ("su" . "$B$R$c(B") ("si" . "$B$R$e(B") ("so" . "$B$R$g(B") ("sb;" . "$B$R$'(B")
+ ("suu" . "$B$R$c$"(B") ("sii" . "$B$R$e$&(B") ("soo" . "$B$R$g$&(B")
+ ("ck" . "$B$S(B")
+ ("cu" . "$B$S$c(B") ("ci" . "$B$S$e(B") ("co" . "$B$S$g(B") ("cb;" . "$B$R$g(B")
+ ("cuu" . "$B$S$c$"(B") ("cii" . "$B$S$e$&(B") ("coo" . "$B$S$g$&(B")
+ ("tk" . "$B$T(B")
+ ("tu" . "$B$T$c(B") ("ti" . "$B$T$e(B") ("to" . "$B$T$g(B") ("tb;" . "$B$T$'(B")
+ ("tuu" . "$B$T$c$"(B") ("tii" . "$B$T$e$&(B") ("too" . "$B$T$g$&(B")
+ ("sj" . "$B$U(B")
+ ("sbh" . "$B$U$!(B") ("sbk" . "$B$U$#(B") ("sbj" . "$B$U$%(B") ("sb;" . "$B$U$'(B") ("sbl" . "$B$U$)(B")
+ ("cj" . "$B$V(B")
+ ("cbh" . "$B$V$!(B") ("cbk" . "$B$V$#(B") ("cbj" . "$B$V$%(B") ("cb;" . "$B$V$'(B") ("cbl" . "$B$V$)(B")
+ ("tj" . "$B$W(B")
+ ("tbh" . "$B$W$!(B") ("tbk" . "$B$W$#(B") ("tbj" . "$B$W$%(B") ("tb;" . "$B$W$'(B") ("tbl" . "$B$W$)(B")
+ ("s;" . "$B$X(B") ("c;" . "$B$Y(B") ("t;" . "$B$Z(B")
+ ("sl" . "$B$[(B") ("cl" . "$B$\(B") ("tl" . "$B$](B")
+ ("wh" . "$B$^(B") ("wk" . "$B$_(B")
+ ("wu" . "$B$_$c(B") ("wi" . "$B$_$e(B") ("wo" . "$B$_$g(B")
+ ("wuu" . "$B$_$c$"(B") ("wii" . "$B$_$e$&(B") ("woo" . "$B$_$g$&(B")
+ ("wj" . "$B$`(B") ("w;" . "$B$a(B") ("wl" . "$B$b(B")
+ ("u" . "$B$c(B") ("ah" . "$B$d(B") ("i" . "$B$e(B") ("aj" . "$B$f(B") ("o" . "$B$g(B")
+ ("al" . "$B$h(B")
+ ("rh" . "$B$i(B") ("rk" . "$B$j(B")
+ ("ru" . "$B$j$c(B") ("ri" . "$B$j$e(B") ("ro" . "$B$j$g(B")
+ ("ruu" . "$B$j$c$"(B") ("rii" . "$B$j$e$&(B") ("roo" . "$B$j$g$&(B")
+ ("rj" . "$B$k(B") ("r;" . "$B$l(B") ("rl" . "$B$m(B")
+ ("bxh" . "$B$n(B") ("xh" . "$B$o(B") ("xk" . "$B$p(B") ("x;" . "$B$q(B")
+ ("xbk" . "$B$&$#(B") ("xb;" . "$B$&$'(B")
+ ("xl" . "$B$r(B") ("n" . "$B$s(B")
+ ("p" . "$B!<(B") ("zb;" . "$B$8$'(B")
+ ("zp" . "$B!A(B") ("z/" . "$B!&(B") ("zx" . "^^;;;")
+
+ ("[" . "$B!V(B") ("]" . "$B!W(B") ("{" . "$B!X(B") ("}" . "$B!Y(B")
+ ("X1" . "$B!{(B") ("X!" . "$B!|(B") ("X2" . "$B"&(B") ("X@" . "$B"'(B") ("X3" . "$B"$(B")
+ ("X#" . "$B"%(B") ("X4" . "$B""(B") ("X$" . "$B"#(B") ("X5" . "$B!~(B") ("X%" . "$B"!(B")
+ ("X6" . "$B!y(B") ("X^" . "$B!z(B") ("X7" . "$B!}(B") ("X&" . "$B!r(B") ("X8" . "$B!q(B")
+ ("X*" . "$B!_(B") ("X9" . "$B!i(B") ("X(" . "$B!Z(B") ("X0" . "$B!j(B") ("X)" . "$B![(B")
+ ("X-" . "$B!A(B") ("X_" . "$B!h(B") ("X=" . "$B"b(B") ("X+" . "$B!^(B") ("X\\" . "$B!@(B")
+ ("X|" . "$B!B(B") ("X\`" . "$B!-(B") ("X~" . "$B!/(B") ("Xq" . "$B!T(B") ("XQ" . "$B!R(B")
+ ("Xw" . "$B!U(B") ("XW" . "$B!S(B") ("Xe" . "$B!9(B") ("XR" . "$B!8(B") ("Xt" . "$B!:(B")
+ ("XT" . "$B!x(B") ("Xp" . "$B")(B") ("XP" . "$B",(B") ("X[" . "$B!X(B") ("X]" . "$B!Y(B")
+ ("X{" . "$B!L(B") ("X}" . "$B!M(B") ("Xs" . "$B!3(B") ("XS" . "$B!4(B") ("Xd" . "$B!5(B")
+ ("XD" . "$B!6(B") ("Xf" . "$B!7(B") ("XF" . "$B"*(B") ("Xg" . "$B!>(B") ("Xj" . "$B"-(B")
+ ("XG" . "$B!=(B") ("Xh" . "$B"+(B") ("Xk" . "$B",(B") ("Xl" . "$B"*(B") ("X:" . "$B!,(B")
+ ("X\'" . "$B!F(B") ("X\"" . "$B!H(B") ("Xx" . ":-") ("XX" . ":-)")
+ ("Xc" . "$B!;(B") ("XC" . "$B!n(B") ("Xv" . "$B"((B") ("XV" . "$B!`(B") ("Xb" . "$B!k(B")
+ ("XB" . "$B"+(B") ("Xn" . "$B!l(B") ("XN" . "$B"-(B") ("X$B$C(B" . "$B!m(B") ("XM" . "$B".(B")
+ ("X," . "$B!E(B") ("X<" . "$B!e(B") ("X." . "$B!D(B") ("X>" . "$B!f(B") ("X/" . "$B!&(B")
+ ("X?" . "$B!g(B") ("z1" . "$B!{(B") ("z!" . "$B!|(B") ("z2" . "$B"&(B") ("z@" . "$B"'(B")
+ ("z3" . "$B"$(B") ("z#" . "$B"%(B") ("z4" . "$B""(B") ("z$" . "$B"#(B") ("z5" . "$B!~(B")
+ ("z%" . "$B"!(B") ("z6" . "$B!y(B") ("z^" . "$B!z(B") ("z7" . "$B!}(B") ("z&" . "$B!r(B")
+ ("z8" . "$B!q(B") ("z*" . "$B!_(B") ("z9" . "$B!i(B") ("z(" . "$B!Z(B") ("z0" . "$B!j(B")
+ ("z)" . "$B![(B") ("zp" . "$B!A(B") ("z_" . "$B!h(B") ("z=" . "$B!b(B") ("z+" . "$B!^(B")
+ ("z\\" . "$B!@(B") ("z|" . "$B!B(B") ("z\`" . "$B!-(B") ("z~" . "$B!/(B") ("z:" . "$B!,(B")
+ ("z\'" . "$B!F(B") ("z\"" . "$B!H(B") ("z," . "$B!E(B") ("z<" . "$B!e(B") ("z." . "$B!D(B")
+ ("z>" . "$B!f(B") ("z/" . "$B!&(B") ("z?" . "$B!g(B") ("z[" . "$B!X(B") ("z]" . "$B!Y(B")
+ ("z{" . "$B!L(B") ("z}" . "$B!M(B") ("zx" . "^^;;;") ("zX" . "(^^)") ("zs" . "$B!!(B")
+ ("@ " . "$B!!(B") ("@/" . "$B!?(B") ("@\\" . "$B!@(B") ("@@" . "$B!w(B") ("@," . "$B!$(B")
+ ("@." . "$B!%(B") ("@~" . "$B!A(B") ("@-" . "$B!=(B") ("@||" . "$B!B(B") ("@|" . "$B!C(B")
+ ("@\"" . "$B!7(B") ("@*" . "$B!_(B") ("@=" . "$B".(B") ("@3" . "$B!D(B") ("@2" . "$B!E(B")
+ ("@0" . "$B!{(B") ("@[" . "$B!N(B") ("@]" . "$B!O(B") ("@{" . "$B!P(B") ("@}" . "$B!Q(B")
+ ("@<" . "$B!T(B") ("@>" . "$B!U(B")
+
+ ("Z0" . "$B#0(B") ("Z1" . "$B#1(B") ("Z2" . "$B#2(B") ("Z3" . "$B#3(B") ("Z4" . "$B#4(B")
+ ("Z5" . "$B#5(B") ("Z6" . "$B#6(B") ("Z7" . "$B#7(B") ("Z8" . "$B#8(B") ("Z9" . "$B#9(B")
+ ("ZA" . "$B#A(B") ("ZB" . "$B#B(B") ("ZC" . "$B#C(B") ("ZD" . "$B#D(B") ("ZE" . "$B#E(B") ("ZF" . "$B#F(B")
+ ("ZG" . "$B#G(B") ("ZH" . "$B#H(B") ("ZI" . "$B#I(B") ("ZJ" . "$B#J(B") ("ZK" . "$B#K(B") ("ZL" . "$B#L(B")
+ ("ZM" . "$B#M(B") ("ZN" . "$B#N(B") ("ZO" . "$B#O(B") ("ZP" . "$B#P(B") ("ZQ" . "$B#Q(B") ("ZR" . "$B#R(B")
+ ("ZS" . "$B#S(B") ("ZT" . "$B#T(B") ("ZU" . "$B#U(B") ("ZV" . "$B#V(B") ("ZW" . "$B#W(B") ("ZX" . "$B#X(B")
+ ("ZY" . "$B#Y(B") ("ZZ" . "$B#Z(B")
+ ("Za" . "$B#a(B") ("Zb" . "$B#b(B") ("Zc" . "$B#c(B") ("Zd" . "$B#d(B") ("Ze" . "$B#e(B") ("Zf" . "$B#f(B")
+ ("Zg" . "$B#g(B") ("Zh" . "$B#h(B") ("Zi" . "$B#i(B") ("Zj" . "$B#j(B") ("Zk" . "$B#k(B") ("Zl" . "$B#l(B")
+ ("Zm" . "$B#m(B") ("Zn" . "$B#n(B") ("Zo" . "$B#o(B") ("Zp" . "$B#p(B") ("Zq" . "$B#q(B") ("Zr" . "$B#r(B")
+ ("Zs" . "$B#s(B") ("Zt" . "$B#t(B") ("Zu" . "$B#u(B") ("Zv" . "$B#v(B") ("Zw" . "$B#w(B") ("Zx" . "$B#x(B")
+ ("Zy" . "$B#y(B") ("Zz" . "$B#z(B")
+ ("Z!" . "$B!*(B") ("Z@" . "$B!w(B") ("Z#" . "$B!t(B") ("Z$" . "$B!p(B") ("Z%" . "$B!s(B")
+ ("Z^" . "$B!0(B") ("Z&" . "$B!u(B") ("Z*" . "$B!v(B") ("Z(" . "$B!J(B") ("Z)" . "$B!K(B") ("Z-" . "$B!](B")
+ ("Z=" . "$B!a(B") ("Z`" . "$B!.(B") ("Z\\" . "$B!o(B") ("Z|" . "$B!C(B") ("Z_" . "$B!2(B") ("Z+" . "$B!\(B")
+ ("Z~" . "$B!1(B") ("Z[" . "$B!N(B") ("Z]" . "$B!O(B") ("Z{" . "$B!P(B") ("Z}" . "$B!Q(B") ("Z:" . "$B!'(B")
+ ("Z;" . "$B!((B") ("Z\"" . "$B!I(B") ("Z\\'" . "$B!G(B") ("Z<" . "$B!c(B") ("Z>" . "$B!d(B") ("Z?" . "$B!)(B")
+ ("Z/" . "$B!?(B") ("Z," . "$B!$(B") ("Z." . "$B!%(B")
+
+ ("!" . "!") ("\"" . "\"") ("#" . "#") ("$" . "$") ("%" . "%") ("&" . "&")
+ ("'" . "'") ("(" . "(") (")" . ")") ("|" . "|")
+ ("*" . "*") ("+" . "+") ("`" . "`") ("-" . "-") ("/" . "/")
+ (":" . ":") ("<" . "<") ("=" . "=") (">" . ">") ("@" . "@")
+ ("0" . "0") ("1" . "1") ("2" . "2") ("3" . "3") ("4" . "4")
+ ("5" . "5") ("6" . "6") ("7" . "7") ("8" . "8") ("9" . "9")
+ ))
+
+;;
+;; toggle$B$NJQ99(B
+;;
+(defun anthy-send-change-toggle-command (str)
+ (anthy-send-recv-command
+ (concat " CHANGE_TOGGLE ~\n")))
+
+(defun anthy-kyuri ()
+ (setq anthy-rkmap-keybind nil)
+ (anthy-send-recv-command " SET_PREEDIT_MODE 0\n")
+ (anthy-set-break-into-roman t)
+ (anthy-send-change-toggle-command "~")
+ (anthy-clear-map)
+ (mapcar (lambda (x)
+ (anthy-change-hiragana-map (car x) (cdr x)))
+ anthy-kyuri-mode-hiragana-map)
+ )
+
+(define-key anthy-mode-map (char-to-string 10) 'newline-and-indent)
+(define-key anthy-mode-map (char-to-string 17) 'quoted-insert)
+
+(anthy-kyuri)
+
+(defun anthy-on ()
+ (interactive)
+ (anthy-mode-on))
+
+(defun anthy-off ()
+ (interactive)
+ (anthy-mode-off))
+
+(defun anthy-force-off ()
+ (interactive)
+ (anthy-handle-normal-key "(enter)")
+ (anthy-off))
+
+(global-set-key "\C-o" 'anthy-on)
+(global-set-key "\C-z" 'anthy-off)
+(global-set-key "\C-c\C-t" 'anthy-add-word-interactive)
+(define-key anthy-preedit-keymap "\C-z" 'anthy-force-off)
+(setq anthy-wide-space " ")
+(setq anthy-use-hankaku-kana nil)
+
+
diff --git a/src-util/anthy.el b/src-util/anthy.el
new file mode 100644
index 0000000..0270d83
--- /dev/null
+++ b/src-util/anthy.el
@@ -0,0 +1,930 @@
+;;; anthy.el -- Anthy
+
+;; Copyright (C) 2001 - 2007 KMC(Kyoto University Micro Computer Club)
+
+;; Author: Yusuke Tabata<yusuke@kmc.gr.jp>
+;; Tomoharu Ugawa
+;; Norio Suzuki <suzuki@sanpobu.net>
+;; Keywords: japanese
+
+;; This file is part of Anthy
+
+;;; Commentary:
+;;
+;; $B$+$J4A;zJQ49%(%s%8%s(B Anthy$B$r(B emacs$B$+$i;H$&$?$a$N%W%m%0%i%`(B
+;; Anthy$B%i%$%V%i%j$r;H$&$?$a$N%3%^%s%I(Banthy-agent$B$r5/F0$7$F!"(B
+;; anthy-agent$B$H%Q%$%W$GDL?.$r$9$k$3$H$K$h$C$FJQ49$NF0:n$r9T$&(B
+;;
+;;
+;; Funded by IPA$BL$F'%=%U%H%&%'%"AOB$;v6H(B 2001 10/10
+;;
+;; $B3+H/$O(Bemacs21.2$B>e$G9T$C$F$$$F(Bminor-mode
+;; $B$b$7$/$O(Bleim$B$H$7$F$b;HMQ$G$-$k(B
+;; (set-input-method 'japanese-anthy)
+;;
+;; emacs19(mule),20,21,xemacs$B$GF0:n$9$k(B
+;;
+;;
+;; 2003-08-24 XEmacs $B$N8uJdA*Br%b!<%I%P%0$KBP1~(B(suzuki)
+;;
+;; 2001-11-16 EUC-JP -> ISO-2022-JP
+;;
+;; TODO
+;; $B8uJdA*Br%b!<%I$G8uJd$r$$$C$-$K<!$N%Z!<%8$K$$$+$J$$$h$&$K$9$k(B(2ch$B%9%l(B78)
+;; minibufffer$B$N07$$(B
+;; isearch$BBP1~(B
+;;
+;; $BMQ8l(B
+;; commit $BJ8;zNs$r3NDj$9$k$3$H(B
+;; preedit($B%W%j%(%G%#%C%H(B) $B3NDjA0$NJ8;zNs%"%s%@!<%i%$%s$d6/D4$NB0@-$b4^$`(B
+;; segment($BJ8@a(B) $BJ8K!E*$JJ8@a$G$O$J$/!$F1$8B0@-$NJ8;zNs$N$+$?$^$j(B
+;;
+
+;;; Code:
+;(setq debug-on-error t)
+
+(defvar anthy-default-enable-enum-candidate-p t
+ "$B$3$l$r@_Dj$9$k$H<!8uJd$r?t2s2!$7$?:]$K8uJd$N0lMw$+$iA*Br$9$k%b!<%I$K$J$j$^$9!%(B")
+
+(defvar anthy-personality ""
+ "$B%Q!<%=%J%j%F%#(B")
+
+(defvar anthy-preedit-begin-mark "|"
+ "$BJQ49;~$N@hF,$KIU$/J8;zNs(B")
+
+(defvar anthy-preedit-delim-mark "|"
+ "$BJQ49;~$NJ8@a$N6h@Z$j$K;H$o$l$kJ8;zNs(B")
+
+(defvar anthy-accept-timeout 50)
+(if (string-match "^22\." emacs-version)
+ (setq anthy-accept-timeout 1))
+
+(defconst anthy-working-buffer " *anthy*")
+(defvar anthy-agent-process nil
+ "anthy-agent$B$N%W%m%;%9(B")
+(defvar anthy-use-hankaku-kana t)
+;;
+(defvar anthy-agent-command-list '("anthy-agent")
+ "anthy-agent$B$N(BPATH$BL>(B")
+
+;; face
+(defvar anthy-highlight-face nil)
+(defvar anthy-underline-face nil)
+(copy-face 'highlight 'anthy-highlight-face)
+(set-face-underline-p 'anthy-highlight-face t)
+(copy-face 'underline 'anthy-underline-face)
+
+;;
+(defvar anthy-xemacs
+ (if (featurep 'xemacs)
+ t nil))
+(if anthy-xemacs
+ (require 'overlay))
+;;
+(defvar anthy-mode-map nil
+ "Anthy$B$N(BASCII$B%b!<%I$N%-!<%^%C%W(B")
+(or anthy-mode-map
+ (let ((map (make-keymap))
+ (i 32))
+ (define-key map (char-to-string 10) 'anthy-insert)
+ (define-key map (char-to-string 17) 'anthy-insert)
+ (while (< i 127)
+ (define-key map (char-to-string i) 'anthy-insert)
+ (setq i (+ 1 i)))
+ (setq anthy-mode-map map)))
+;;
+(defvar anthy-preedit-keymap nil
+ "Anthy$B$N(Bpreedit$B$N%-!<%^%C%W(B")
+(or anthy-preedit-keymap
+ (let ((map (make-keymap))
+ (i 0))
+ ;; $BDL>o$NJ8;z$KBP$7$F(B
+ (while (< i 128)
+ (define-key map (char-to-string i) 'anthy-insert)
+ (setq i (+ 1 i)))
+ ;; $BJ8@a$N?-=L(B
+ (define-key map [(shift left)] 'anthy-insert)
+ (define-key map [(shift right)] 'anthy-insert)
+ ;; $BJ8@a$N0\F0(B
+ (define-key map [left] 'anthy-insert)
+ (define-key map [right] 'anthy-insert)
+ (define-key map [backspace] 'anthy-insert)
+ (setq anthy-preedit-keymap map)))
+
+;; anthy-agent$B$KAw$k:]$K%-!<$r%(%s%3!<%I$9$k$?$a$N%F!<%V%k(B
+(defvar anthy-keyencode-alist
+ '((1 . "(ctrl A)") ;; \C-a
+ (2 . "(left)") ;; \C-b
+ (4 . "(ctrl D)") ;; \C-d
+ (5 . "(ctrl E)") ;; \C-e
+ (6 . "(right)") ;; \C-f
+ (7 . "(esc)") ;; \C-g
+ (8 . "(ctrl H)") ;; \C-h
+ (9 . "(shift left)") ;; \C-i
+ (10 . "(ctrl J)")
+ (11 . "(ctrl K)")
+ (13 . "(enter)") ;; \C-m
+ (14 . "(space)") ;; \C-n
+ (15 . "(shift right)") ;; \C-o
+ (16 . "(up)") ;; \C-p
+ (32 . "(space)")
+ (40 . "(opar)") ;; '('
+ (41 . "(cpar)") ;; ')'
+ (127 . "(ctrl H)")
+ ;; emacs map
+ (S-right . "(shift right)")
+ (S-left . "(shift left)")
+ (right . "(right)")
+ (left . "(left)")
+ (up . "(up)")
+ (backspace . "(ctrl H)")
+ ;; xemacs
+ ((shift right) . "(shift right)")
+ ((shift left) . "(shift left)")
+ ((right) . "(right)")
+ ((left) . "(left)")
+ ((up) . "(up)"))
+ "$B%-!<$N%$%Y%s%H$r(Banthy-agent$B$KAw$k$?$a$NBP1~I=(B")
+
+;; $B%b!<%I%i%$%s$NJ8;zNs(B
+(defvar anthy-mode-line-string-alist
+ '(("hiragana" . " $B$"(B")
+ ("katakana" . " $B%"(B")
+ ("alphabet" . " A")
+ ("walphabet" . " $B#A(B")
+ ("hankaku_kana" . " (I1(B")
+ )
+ "$B%b!<%IL>$H%b!<%I%i%$%s$NJ8;zNs$NBP1~I=(B")
+
+;; $B:G8e$K3d$jEv$F$?(Bcontext id
+(defvar anthy-last-context-id 1)
+
+;; From skk-macs.el From viper-util.el. Welcome!
+(defmacro anthy-deflocalvar (var default-value &optional documentation)
+ (` (progn
+ (defvar (, var) (, default-value)
+ (, (format "%s\n\(buffer local\)" documentation)))
+ (make-variable-buffer-local '(, var))
+ )))
+
+;; buffer local variables
+(anthy-deflocalvar anthy-context-id nil "$B%3%s%F%-%9%H$N(Bid")
+; $B%b!<%I$N4IM}(B
+(anthy-deflocalvar anthy-minor-mode nil)
+(anthy-deflocalvar anthy-mode nil)
+(anthy-deflocalvar anthy-leim-active-p nil)
+(anthy-deflocalvar anthy-saved-mode nil)
+; $B%W%j%(%G%#%C%H(B
+(anthy-deflocalvar anthy-preedit "")
+(anthy-deflocalvar anthy-preedit-start 0)
+(anthy-deflocalvar anthy-preedit-overlays '())
+(anthy-deflocalvar anthy-mode-line-string " A")
+; $B8uJdNs5s(B
+(anthy-deflocalvar anthy-enum-candidate-p nil)
+(anthy-deflocalvar anthy-enum-rcandidate-p nil)
+(anthy-deflocalvar anthy-candidate-minibuffer "")
+(anthy-deflocalvar anthy-enum-candidate-list '()
+ "$B:#Ns5s$7$F$$$k8uJd$N>pJs(B(($B2hLLFb$N(Bindex $B8uJd$N(Bindex . $B8uJdJ8;zNs(B) ..)")
+(anthy-deflocalvar anthy-enable-enum-candidate-p
+ (cons anthy-default-enable-enum-candidate-p nil)
+ "$B$3$N%P%C%U%!$G8uJd$NNs5s$r9T$&$+$I$&$+(B")
+(anthy-deflocalvar anthy-current-candidate-index 0)
+(anthy-deflocalvar anthy-current-candidate-layout-begin-index 0)
+(anthy-deflocalvar anthy-current-candidate-layout-end-index 0)
+; $BF~NO>uBV(B
+(anthy-deflocalvar anthy-current-rkmap "hiragana")
+; undo
+(anthy-deflocalvar anthy-buffer-undo-list-saved nil)
+
+;;
+(defvar anthy-wide-space "$B!!(B" "$B%9%Z!<%9$r2!$7$?;~$K=P$FMh$kJ8;z(B")
+
+;;; setup minor-mode
+;; minor-mode-alist
+(if (not
+ (assq 'anthy-minor-mode minor-mode-alist))
+ (setq minor-mode-alist
+ (cons
+ (cons 'anthy-minor-mode '(anthy-mode-line-string))
+ minor-mode-alist)))
+;; minor-mode-map-alist
+(if (not
+ (assq 'anthy-minor-mode minor-mode-map-alist))
+ (setq minor-mode-map-alist
+ (cons
+ (cons 'anthy-minor-mode anthy-mode-map)
+ minor-mode-map-alist)))
+
+;;
+(defun anthy-process-sentinel (proc stat)
+ "$B%W%m%;%9$N>uBV$,JQ2=$7$?$i;2>H$r>C$7$F!$<!$K:F5/F0$G$-$k$h$&$K$9$k(B"
+ (message "%s" stat)
+ (anthy-mode-off)
+ (setq anthy-agent-process nil))
+
+;;; status
+(defun anthy-update-mode-line ()
+ "$B%b!<%I%i%$%s$r99?7$9$k(B"
+ (let ((a (assoc anthy-current-rkmap anthy-mode-line-string-alist)))
+ (if a
+ (progn
+ (setq anthy-mode-line-string (cdr a))
+ (setq current-input-method-title
+ (concat "<Anthy:" (cdr a) ">")))))
+ (force-mode-line-update))
+
+;;; preedit control
+(defun anthy-erase-preedit ()
+ "$B%W%j%(%G%#%C%H$rA4It>C$9(B"
+ (if (> (string-width anthy-preedit) 0)
+ (let* ((str anthy-preedit)
+ (len (length str))
+ (start anthy-preedit-start))
+ (delete-region start (+ start len))
+ (goto-char start)))
+ (setq anthy-preedit "")
+ (mapcar 'delete-overlay anthy-preedit-overlays)
+ (setq anthy-preedit-overlays nil))
+
+(defun anthy-select-face-by-attr (attr)
+ "$BJ8@a$NB0@-$K1~$8$?(Bface$B$rJV$9(B"
+ (if (memq 'RV attr)
+ 'anthy-highlight-face
+ 'anthy-underline-face))
+
+(defun anthy-enable-preedit-keymap ()
+ "$B%-!<%^%C%W$r%W%j%(%G%#%C%H$NB8:_$9$k;~$N$b$N$K@ZBX$($k(B"
+; (setq anthy-saved-buffer-undo-list buffer-undo-list)
+; (buffer-disable-undo)
+ (setcdr
+ (assq 'anthy-minor-mode minor-mode-map-alist)
+ anthy-preedit-keymap))
+
+(defun anthy-disable-preedit-keymap ()
+ "$B%-!<%^%C%W$r%W%j%(%G%#%C%H$NB8:_$7$J$$;~$N$b$N$K@ZBX$($k(B"
+; (buffer-enable-undo)
+; (setq buffer-undo-list anthy-saved-buffer-undo-list)
+ (setcdr
+ (assq 'anthy-minor-mode minor-mode-map-alist)
+ anthy-mode-map)
+ (anthy-update-mode-line))
+
+(defun anthy-insert-preedit-segment (str attr)
+ "$B%W%j%(%G%#%C%H$r0lJ8@aJ8DI2C$9$k(B"
+ (let ((start (point))
+ (end) (ol))
+ (cond ((or (memq 'ENUM attr) (memq 'ENUMR attr))
+ (setq str (concat "<" str ">")))
+ ((memq 'RV attr)
+ (setq str (concat "[" str "]"))))
+ ; $B%W%j%(%G%#%C%H$NJ8;zNs$rDI2C$9$k(B
+ (insert-and-inherit str)
+ (setq end (point))
+ ;; overlay$B$K$h$C$FB0@-$r@_Dj$9$k(B
+ (setq ol (make-overlay start end))
+ (overlay-put ol 'face (anthy-select-face-by-attr attr))
+ (setq anthy-preedit-overlays
+ (cons ol anthy-preedit-overlays))
+ str))
+
+(defvar anthy-select-candidate-keybind
+ '((0 . "a")
+ (1 . "s")
+ (2 . "d")
+ (3 . "f")
+ (4 . "g")
+ (5 . "h")
+ (6 . "j")
+ (7 . "k")
+ (8 . "l")
+ (9 . ";")))
+
+;;;
+;;; auto fill controll
+;;; from egg.el
+
+(defun anthy-do-auto-fill ()
+ (if (and auto-fill-function (> (current-column) fill-column))
+ (let ((ocolumn (current-column)))
+ (funcall auto-fill-function)
+ (while (and (< fill-column (current-column))
+ (< (current-column) ocolumn))
+ (setq ocolumn (current-column))
+ (funcall auto-fill-function)))))
+
+;;
+(defun anthy-check-context-id ()
+ "$B%P%C%U%!$K%3%s%F%-%9%H(Bid$B$,3d$j?6$i$l$F$$$k$+$r%A%'%C%/$9$k(B"
+ (if (null anthy-context-id)
+ (progn
+ (setq anthy-context-id anthy-last-context-id)
+ (setq anthy-last-context-id
+ (+ anthy-last-context-id 1)))))
+
+(defun anthy-get-candidate (idx)
+ "agent$B$+$i8uJd$r0l$D<hF@$9$k(B"
+ (anthy-send-recv-command
+ (concat " GET_CANDIDATE "
+ (number-to-string idx) "\n")))
+
+;; $B8uJd%j%9%H$+$i%_%K%P%C%U%!$KI=<($9$kJ8;zNs$r9=@.$9$k(B
+(defun anthy-make-candidate-minibuffer-string ()
+ (let ((cand-list anthy-enum-candidate-list)
+ (cur-elm)
+ (str))
+ (while cand-list
+ (setq cur-elm (car cand-list))
+ (let ((cand-str (cdr (cdr cur-elm)))
+ (cand-idx (car (cdr cur-elm)))
+ (sel-idx (car cur-elm)))
+ (setq str (format (if (= anthy-current-candidate-index cand-idx)
+ "%s:[%s] "
+ "%s: %s ")
+ (cdr (assoc sel-idx anthy-select-candidate-keybind))
+ cand-str)))
+ (setq anthy-candidate-minibuffer
+ (concat str
+ anthy-candidate-minibuffer))
+ (setq cand-list (cdr cand-list)))))
+
+;; $BI=<($9$k8uJd$N%j%9%H$K2hLLFb$G$N%$%s%G%C%/%9$rIU$1$k(B
+(defun anthy-add-candidate-index (lst)
+ (let ((i 0)
+ (res nil))
+ (while lst
+ (setq res
+ (cons
+ (cons i (car lst))
+ res))
+ (setq i (1+ i))
+ (setq lst (cdr lst)))
+ res))
+
+
+;; $BJ8;z$NI}$r7W;;$7$F!"I=<($9$k8uJd$N%j%9%H$r:n$k(B
+(defun anthy-make-candidate-index-list (base nr l2r)
+ (let ((width (frame-width))
+ (errorp nil)
+ (i 0)
+ (repl)
+ (cand-idx)
+ (lst))
+ ;; loop
+ (while (and
+ (if l2r
+ (< (+ base i) nr)
+ (<= 0 (- base i)))
+ (> width 0)
+ (< i (length anthy-select-candidate-keybind))
+ (not errorp))
+ (if l2r
+ (setq cand-idx (+ base i))
+ (setq cand-idx (- base i)))
+ (setq repl (anthy-get-candidate cand-idx))
+ (if (listp repl)
+ ;; append candidate
+ (let ((cand-str (car repl)))
+ (setq width (- width (string-width cand-str) 5))
+ (if (or (> width 0) (null lst))
+ (setq lst
+ (cons
+ (cons cand-idx cand-str)
+ lst))))
+ ;; erroneous candidate
+ (setq errorp t))
+ (setq i (1+ i)))
+ (if errorp
+ nil
+ lst)))
+
+
+;; $BI=<($9$k8uJd$N%j%9%H$r:n$k(B
+(defun anthy-calc-candidate-layout (base nr l2r)
+ (let
+ ((lst (anthy-make-candidate-index-list base nr l2r)))
+ ;;$B%+%l%s%H$N8uJdHV9f$r@_Dj$9$k(B
+ (if l2r
+ (progn
+ ;; $B:8$+$i1&$N>l9g(B
+ ;; index$B$r0lHV1&$N8uJd$K@_Dj$9$k(B
+ (anthy-get-candidate (car (car lst)))
+ (setq lst (reverse lst))
+ (setq anthy-current-candidate-index (car (car lst))))
+ (progn
+ ;; $B1&$+$i:8$N>l9g(B
+ (setq anthy-current-candidate-index (car (car (reverse lst))))))
+ ;;$B7k2L$r%;%C%H(B
+ (setq anthy-enum-candidate-list
+ (if lst
+ (anthy-add-candidate-index lst)
+ nil))))
+
+;;
+(defun anthy-layout-candidate (idx nr)
+ "$B8uJd%j%9%H$r(Bminibuffer$B$X%l%$%"%&%H$9$k(B"
+ (setq anthy-candidate-minibuffer "")
+ (setq anthy-enum-candidate-list '())
+ ;; $B:8(B->$B1&(B or $B1&(B->$B:8$K%l%$%"%&%H$9$k(B
+ (if anthy-enum-candidate-p
+ (anthy-calc-candidate-layout idx nr 't)
+ (anthy-calc-candidate-layout idx nr nil))
+ (anthy-make-candidate-minibuffer-string)
+ ;; $B7k2L$rI=<($9$k(B
+ (if anthy-enum-candidate-list
+ (progn
+ (message "%s" anthy-candidate-minibuffer)
+ (setq anthy-current-candidate-layout-begin-index
+ (car (cdr (car (reverse anthy-enum-candidate-list)))))
+ (setq anthy-current-candidate-layout-end-index
+ (car (cdr (car anthy-enum-candidate-list)))))
+
+ nil))
+
+(defun anthy-update-preedit (stat ps)
+ "$B%W%j%(%G%#%C%H$r99?7$9$k(B"
+ (let ((cursor-pos nil)
+ (num-candidate 0)
+ (idx-candidate 0)
+ (enum-candidate
+ (or anthy-enum-candidate-p
+ anthy-enum-rcandidate-p)))
+ ;; erase old preedit
+ (anthy-erase-preedit)
+
+ ;; $BF~NO%-%c%s%;%k;~$K(Bundo$B%j%9%H$r7R$2$k(B
+ (if (and (= (length ps) 0) anthy-buffer-undo-list-saved )
+ (progn
+; (message "enable")
+ (buffer-enable-undo)
+ (setq buffer-undo-list anthy-buffer-undo-list)
+ (setq anthy-buffer-undo-list-saved nil)
+ ))
+
+ (anthy-disable-preedit-keymap)
+ ;; insert new preedit
+ (setq anthy-preedit-start (point))
+ (setq anthy-enum-candidate-p nil)
+ (setq anthy-enum-rcandidate-p nil)
+ (if (member stat '(2 3 4))
+ (progn
+ (setq anthy-preedit
+ (concat anthy-preedit anthy-preedit-begin-mark))
+ (anthy-insert-preedit-segment anthy-preedit-begin-mark '())
+
+ ;; $BF~NO3+;O$HF1;~$K(Bundo$B%j%9%H$rL58z2=(B
+ (if (not anthy-buffer-undo-list-saved)
+ (progn
+ ;(message "disable")
+ (setq anthy-buffer-undo-list (cdr buffer-undo-list))
+ (buffer-disable-undo)
+ (setq anthy-buffer-undo-list-saved 't)
+ )
+ ;(message "not saved")
+ )
+
+ ))
+
+ ;; $B3FJ8@a$KBP$7$F(B
+ (while ps
+ (let ((cur (car ps)))
+ (setq ps (cdr ps))
+ (cond
+ ((eq cur 'cursor)
+ (setq cursor-pos (point)))
+ ((string-equal (car (cdr cur)) "")
+ nil)
+ (t
+ (let ((nr (car (cdr (cdr (cdr cur)))))
+ (idx (car (cdr (cdr cur))))
+ (str (car (cdr cur)))
+ (attr (car cur)))
+ (setq str (anthy-insert-preedit-segment str attr))
+ (cond ((and (car anthy-enable-enum-candidate-p) (memq 'ENUM attr))
+ ;; $B=gJ}8~$N8uJdNs5s(B
+ (setq anthy-enum-candidate-p t)
+ (setq idx-candidate idx)
+ (setq num-candidate nr))
+ ((and (car anthy-enable-enum-candidate-p) (memq 'ENUMR attr))
+ ;; $B5UJ}8~$N8uJdNs5s(B
+ (setq anthy-enum-rcandidate-p t)
+ (setq idx-candidate idx)
+ (setq num-candidate nr)))
+ (setq anthy-preedit
+ (concat anthy-preedit str))
+ (if (and (member stat '(3 4)) (not (eq ps '())))
+ (progn
+ (setq anthy-preedit
+ (concat anthy-preedit anthy-preedit-delim-mark))
+ (anthy-insert-preedit-segment anthy-preedit-delim-mark '()))))))))
+ ;; $B8uJd0lMw$NI=<(3+;O%A%'%C%/(B
+ (if (and (not enum-candidate)
+ (or anthy-enum-candidate-p anthy-enum-rcandidate-p))
+ (setq anthy-current-candidate-layout-begin-index 0))
+ ;; $B8uJd$NNs5s$r9T$&(B
+ (if (or anthy-enum-candidate-p anthy-enum-rcandidate-p)
+ (anthy-layout-candidate idx-candidate num-candidate))
+ ;; preedit$B$N(Bkeymap$B$r99?7$9$k(B
+ (if (member stat '(2 3 4))
+ (anthy-enable-preedit-keymap))
+ (if cursor-pos (goto-char cursor-pos))))
+
+; suzuki : Emacs / XEmacs $B$G6&DL$N4X?tDj5A(B
+(defun anthy-encode-key (ch)
+ (let ((c (assoc ch anthy-keyencode-alist)))
+ (if c
+ (cdr c)
+ (if (and
+ (integerp ch)
+ (> ch 32))
+ (char-to-string ch)
+ nil))))
+
+(defun anthy-restore-undo-list (commit-str)
+ (let* ((len (length commit-str))
+ (beginning (point))
+ (end (+ beginning len)))
+ (setq buffer-undo-list
+ (cons (cons beginning end)
+ (cons nil anthy-saved-buffer-undo-list)))
+ ))
+
+(defun anthy-proc-agent-reply (repl)
+ (let*
+ ((stat (car repl))
+ (body (cdr repl))
+ (commit "")
+ (commitlen nil)
+ (preedit nil))
+ ;; $B3FJ8@a$r=hM}$9$k(B
+ (while body
+ (let* ((cur (car body))
+ (pe nil))
+ (setq body (cdr body))
+ (if (and
+ (listp cur)
+ (listp (car cur)))
+ (cond
+ ((eq (car (car cur)) 'COMMIT)
+ (setq commit (concat commit (car (cdr cur)))))
+ ((eq (car (car cur)) 'CUTBUF)
+ (let ((len (length (car (cdr cur)))))
+ (copy-region-as-kill (point) (+ (point) len))))
+ ((memq 'UL (car cur))
+ (setq pe (list cur))))
+ (setq pe (list cur)))
+ (if pe
+ (setq preedit (append preedit pe)))))
+ ;; $B%3%_%C%H$5$l$?J8@a$r=hM}$9$k(B
+; (anthy-restore-undo-list commit)
+ (if (> (string-width commit) 0)
+ (progn
+ (setq commitlen (length commit))
+ (anthy-erase-preedit)
+ (anthy-disable-preedit-keymap)
+ ; $B@h$K%3%_%C%H$5$;$F$*$/(B
+ (insert-and-inherit commit)
+ (anthy-do-auto-fill)
+
+ ;; $B%3%_%C%H;~$K7R$2$k(B
+ (if anthy-buffer-undo-list-saved
+ (progn
+ ;(message "enable")
+ ; $BI|5"$5$;$kA0$K!$:#(Bcommit$B$7$?FbMF$r%j%9%H$KDI2C(B
+ (setq anthy-buffer-undo-list
+ (cons (cons anthy-preedit-start
+ (+ anthy-preedit-start commitlen))
+ anthy-buffer-undo-list))
+ (setq anthy-buffer-undo-list (cons nil anthy-buffer-undo-list))
+
+ (buffer-enable-undo)
+
+ (setq buffer-undo-list anthy-buffer-undo-list)
+
+ (setq anthy-buffer-undo-list-saved nil)
+ ))
+
+ (run-hooks 'anthy-commit-hook)
+ ))
+ (anthy-update-preedit stat preedit)
+ (anthy-update-mode-line)))
+
+(defun anthy-insert-select-candidate (ch)
+ (let* ((key-idx (car (rassoc (char-to-string ch)
+ anthy-select-candidate-keybind)))
+ (idx (car (cdr (assq key-idx
+ anthy-enum-candidate-list)))))
+ (if idx
+ (progn
+ (let ((repl (anthy-send-recv-command
+ (format " SELECT_CANDIDATE %d\n" idx))))
+ (anthy-proc-agent-reply repl))
+ (setq anthy-enum-candidate-p nil)
+ (setq anthy-enum-rcandidate-p nil))
+ (message "%s" anthy-candidate-minibuffer))))
+
+(defvar anthy-default-rkmap-keybind
+ '(
+ ;; q
+ (("hiragana" . 113) . "katakana")
+ (("katakana" . 113) . "hiragana")
+ ;; l
+ (("hiragana" . 108) . "alphabet")
+ (("katakana" . 108) . "alphabet")
+ ;; L
+ (("hiragana" . 76) . "walphabet")
+ (("katakana" . 76) . "walphabet")
+ ;; \C-j
+ (("alphabet" . 10) . "hiragana")
+ (("walphabet" . 10) . "hiragana")
+ ;; \C-q
+ (("hiragana" . 17) . "hankaku_kana")
+ (("hankaku_kana" . 17) . "hiragana")
+ ))
+
+
+(defvar anthy-rkmap-keybind anthy-default-rkmap-keybind)
+
+
+(defun anthy-find-rkmap-keybind (ch)
+ (let ((res
+ (assoc (cons anthy-current-rkmap ch) anthy-rkmap-keybind)))
+ (if (and res (string-equal (cdr res) "hankaku_kana"))
+ (if anthy-use-hankaku-kana res nil)
+ res)))
+
+(defun anthy-handle-normal-key (chenc)
+ (let* ((repl
+ (if chenc (anthy-send-recv-command
+ (concat chenc "\n"))
+ nil)))
+ (if repl
+ (anthy-proc-agent-reply repl))))
+
+(defun anthy-handle-enum-candidate-mode (chenc)
+ (anthy-handle-normal-key chenc))
+
+;;
+(defun anthy-insert (&optional arg)
+ "Anthy$B$N%-!<%O%s%I%i(B"
+ (interactive "*p")
+ ;; suzuki : last-command-char $B$r(B (anthy-last-command-char) $B$KJQ99(B
+ (let* ((ch (anthy-last-command-char))
+ (chenc (anthy-encode-key ch)))
+ (anthy-handle-key ch chenc)))
+
+(defun anthy-handle-key (ch chenc)
+ (cond
+ ;; $B8uJdA*Br%b!<%I$+$i8uJd$rA*$V(B
+ ((and (or anthy-enum-candidate-p anthy-enum-rcandidate-p)
+ (integerp ch)
+ (assq (car (rassoc (char-to-string ch)
+ anthy-select-candidate-keybind))
+ anthy-enum-candidate-list))
+ (anthy-insert-select-candidate ch))
+ ;; $B%-!<%^%C%W$rJQ99$9$k%3%^%s%I$r=hM}$9$k(B
+ ((and (anthy-find-rkmap-keybind ch)
+ (string-equal anthy-preedit ""))
+ (let ((mapname (cdr (anthy-find-rkmap-keybind ch))))
+ (let ((repl (anthy-send-recv-command
+ (concat " MAP_SELECT " mapname "\n"))))
+ (if (eq repl 'OK)
+ (progn
+ (setq anthy-current-rkmap
+ (cdr (assoc (cons anthy-current-rkmap ch)
+ anthy-rkmap-keybind)))
+ (anthy-update-mode-line))))))
+ ;; $B%"%k%U%!%Y%C%H%b!<%I$N>l9g$OD>@\F~NO(B
+ ((and (string-equal anthy-current-rkmap "alphabet")
+ (string-equal anthy-preedit ""))
+ (self-insert-command 1))
+ ;; $B%W%j%(%G%#%C%H$,$J$/$F%9%Z!<%9$,2!$5$l$?(B
+ ((and
+ (string-equal anthy-preedit "")
+ (= ch 32)
+ (not
+ (string-equal anthy-current-rkmap "alphabet")))
+ (progn
+ (insert-and-inherit anthy-wide-space)
+ (anthy-do-auto-fill)))
+ ((or anthy-enum-candidate-p anthy-enum-rcandidate-p)
+ (anthy-handle-enum-candidate-mode chenc))
+ ;; $BIaDL$NF~NO(B
+ (t
+ (anthy-handle-normal-key chenc))))
+
+;;
+(defun anthy-do-invoke-agent (cmd)
+ (if (and (stringp anthy-personality)
+ (> (length anthy-personality) 0))
+ (start-process "anthy-agent"
+ anthy-working-buffer
+ cmd
+ (concat " --personality=" anthy-personality))
+ (start-process "anthy-agent"
+ anthy-working-buffer
+ cmd)))
+;;
+(defun anthy-invoke-agent ()
+ (let ((list anthy-agent-command-list)
+ (proc nil))
+ (while (and list (not proc))
+ (setq proc
+ (anthy-do-invoke-agent (car list)))
+ (if (not (boundp 'proc))
+ (setq proc nil))
+ (setq list (cdr list)))
+ proc))
+;;
+;;
+;;
+(defun anthy-check-agent ()
+ ;; check and do invoke
+ (if (not anthy-agent-process)
+ (let
+ ((proc (anthy-invoke-agent)))
+ (if anthy-agent-process
+ (kill-process anthy-agent-process))
+ (setq anthy-agent-process proc)
+ (process-kill-without-query proc)
+ (if anthy-xemacs
+ (if (coding-system-p (find-coding-system 'euc-japan))
+ (set-process-coding-system proc 'euc-japan 'euc-japan))
+ (cond ((coding-system-p 'euc-japan)
+ (set-process-coding-system proc 'euc-japan 'euc-japan))
+ ((coding-system-p '*euc-japan*)
+ (set-process-coding-system proc '*euc-japan* '*euc-japan*))))
+ (set-process-sentinel proc 'anthy-process-sentinel))))
+;;
+(defun anthy-do-send-recv-command (cmd)
+ (if (not anthy-agent-process)
+ (anthy-check-agent))
+ (let ((old-buffer (current-buffer)))
+ (unwind-protect
+ (progn
+ (set-buffer anthy-working-buffer)
+ (erase-buffer)
+ (process-send-string anthy-agent-process cmd)
+ (while (= (buffer-size) 0)
+ (accept-process-output nil 0 anthy-accept-timeout))
+ (read (buffer-string)))
+ (set-buffer old-buffer))))
+;;
+(defun anthy-send-recv-command (cmd)
+ (if anthy-context-id
+ (anthy-do-send-recv-command
+ (concat " SELECT_CONTEXT "
+ (number-to-string anthy-context-id)
+ "\n")))
+ (anthy-do-send-recv-command cmd))
+;;
+(defun anthy-minibuffer-enter ()
+ (setq anthy-saved-mode anthy-mode)
+ (setq anthy-mode nil)
+ (setq anthy-enable-enum-candidate-p
+ (cons nil anthy-enable-enum-candidate-p))
+ (anthy-update-mode))
+;;
+(defun anthy-minibuffer-exit ()
+ (setq anthy-mode anthy-saved-mode)
+ (setq anthy-enable-enum-candidate-p
+ (cdr anthy-enable-enum-candidate-p))
+ (anthy-update-mode))
+;;
+(defun anthy-kill-buffer ()
+ (if anthy-context-id
+ (anthy-send-recv-command
+ " RELEASE_CONTEXT\n")))
+;;
+(defun anthy-mode-on ()
+ (add-hook 'minibuffer-setup-hook 'anthy-minibuffer-enter)
+ (add-hook 'minibuffer-exit-hook 'anthy-minibuffer-exit)
+ (add-hook 'kill-buffer-hook 'anthy-kill-buffer)
+ (anthy-check-context-id)
+ (setq anthy-minor-mode t)
+ (anthy-update-mode-line))
+;;
+(defun anthy-mode-off ()
+ (setq anthy-minor-mode nil)
+ (anthy-update-mode-line))
+;;
+(defun anthy-update-mode ()
+ (if (or anthy-mode anthy-leim-active-p)
+ (progn
+ (anthy-check-agent)
+ (anthy-mode-on))
+ (anthy-mode-off))
+ (run-hooks 'anthy-mode-hook))
+
+(defun anthy-mode (&optional arg)
+ "Start Anthy conversion system."
+ (interactive "P")
+ (setq anthy-mode
+ (if (null arg)
+ (not anthy-mode)
+ (> (prefix-numeric-value arg) 0)))
+ (anthy-update-mode))
+
+(defun anthy-select-map (map)
+ (anthy-send-recv-command (concat " MAP_SELECT " map "\n"))
+ (setq anthy-current-rkmap map)
+ (anthy-update-mode-line))
+;;
+(defun anthy-hiragana-map (&optional arg)
+ "Hiragana mode"
+ (interactive "P")
+ (anthy-select-map "hiragana"))
+;;
+(defun anthy-katakana-map (&optional arg)
+ "Katakana mode"
+ (interactive "P")
+ (anthy-select-map "katakana"))
+;;
+(defun anthy-alpha-map (arg)
+ "Alphabet mode"
+ (interactive "P")
+ (anthy-select-map "alphabet"))
+;;
+(defun anthy-wide-alpha-map (arg)
+ "Wide Alphabet mode"
+ (interactive "P")
+ (anthy-select-map "walphabet"))
+;;
+(defun anthy-hankaku-kana-map (arg)
+ "Hankaku Katakana mode"
+ (interactive "P")
+ (anthy-select-map "hankaku_kana"))
+;;
+;;
+;; leim $B$N(B inactivate
+;;
+(defun anthy-leim-inactivate ()
+ (setq anthy-leim-active-p nil)
+ (anthy-update-mode))
+;;
+;; leim $B$N(B activate
+;;
+(defun anthy-leim-activate (&optional name)
+ (setq inactivate-current-input-method-function 'anthy-leim-inactivate)
+ (setq anthy-leim-active-p t)
+ (anthy-update-mode)
+ (when (eq (selected-window) (minibuffer-window))
+ (add-hook 'minibuffer-exit-hook 'anthy-leim-exit-from-minibuffer)))
+
+;;
+;; emacs$B$N%P%0Hr$1$i$7$$$G$9(B
+;;
+(defun anthy-leim-exit-from-minibuffer ()
+ (inactivate-input-method)
+ (when (<= (minibuffer-depth) 1)
+ (remove-hook 'minibuffer-exit-hook 'anthy-leim-exit-from-minibuffer)))
+
+;;
+;; Emacs / XEmacs $B%3%s%Q%A%V%k$J(B last-command-char
+;; suzuki : $B?7@_(B
+;;
+(defun anthy-last-command-char ()
+ "$B:G8e$NF~NO%$%Y%s%H$rJV$9!#(BXEmacs $B$G$O(B int $B$KJQ49$9$k(B"
+ (if anthy-xemacs
+ (let ((event last-command-event))
+ (cond
+ ((event-matches-key-specifier-p event 'left) 2)
+ ((event-matches-key-specifier-p event 'right) 6)
+ ((event-matches-key-specifier-p event 'backspace) 8)
+ (t
+ (char-to-int (event-to-character event)))))
+ last-command-char))
+
+;;
+;;
+;;
+;(global-set-key [(meta escape)] 'anthy-mode)
+(provide 'anthy)
+
+(require 'anthy-dic)
+(require 'anthy-conf)
+
+;; is it ok for i18n?
+(set-language-info "Japanese" 'input-method "japanese-anthy")
+(if (equal current-language-environment "Japanese")
+ (progn
+ (if (boundp 'default-input-method)
+ (setq-default default-input-method "japanese-anthy"))
+ (setq default-input-method "japanese-anthy")))
+
+(defun anthy-default-mode ()
+ (interactive)
+ (setq anthy-rkmap-keybind anthy-default-rkmap-keybind)
+ (anthy-send-recv-command " MAP_CLEAR 1\n")
+ (anthy-send-recv-command " SET_PREEDIT_MODE 0\n")
+ (anthy-hiragana-map))
+
+(defun anthy-insert-and-convert (ch)
+ (interactive "P")
+ (if (< 0 (length anthy-preedit))
+ (progn
+ (anthy-insert ch)
+ (anthy-handle-normal-key "(space)"))
+ (anthy-insert ch)))
+
+;;;
+;;; anthy.el ends here
diff --git a/src-util/anthy.i b/src-util/anthy.i
new file mode 100644
index 0000000..c22f7cb
--- /dev/null
+++ b/src-util/anthy.i
@@ -0,0 +1,251 @@
+%module anthy
+%include typemaps.i
+
+%{
+#include "include/anthy.h"
+%}
+
+%init %{
+anthy_init();
+%}
+
+%define OUTPUT_TYPEMAP(type, klass)
+%typemap(in,numinputs=0) type *OUTPUT(VALUE temp)
+{
+ temp = rb_funcall(klass, rb_intern("new"), 0);
+ Data_Get_Struct(temp, $*ltype, $1);
+}
+
+%typemap(argout) type *OUTPUT
+{
+ if ($result < 0)
+ $result = Qnil;
+ else
+ $result = temp$argnum;
+}
+%enddef
+
+OUTPUT_TYPEMAP(struct anthy_conv_stat, cConvStat.klass);
+OUTPUT_TYPEMAP(struct anthy_segment_stat, cSegmentStat.klass);
+OUTPUT_TYPEMAP(struct anthy_prediction_stat, cPredictionStat.klass);
+
+#undef OUTPUT_TYPEMAP
+
+%rename(ConvStat) anthy_conv_stat;
+%rename(SegmentStat) anthy_segment_stat;
+%rename(PredictionStat) anthy_prediction_stat;
+
+%rename(COMPILED_ENCODING) ANTHY_COMPILED_ENCODING;
+%rename(EUC_JP_ENCODING) ANTHY_EUC_JP_ENCODING;
+%rename(UTF8_ENCODING) ANTHY_UTF8_ENCODING;
+
+%rename(init) anthy_init;
+%rename(quit) anthy_quit;
+%rename(conf_override) anthy_conf_override;
+%rename(set_personality) anthy_set_personality;
+
+%ignore anthy_create_context;
+%ignore anthy_reset_context;
+%ignore anthy_release_context;
+
+%ignore anthy_set_string;
+%ignore anthy_resize_segment;
+%ignore anthy_get_stat;
+%ignore anthy_get_segment_stat;
+%ignore anthy_get_segment;
+%ignore anthy_commit_segment;
+
+%ignore anthy_set_prediction_string;
+%ignore anthy_get_prediction_stat;
+%ignore anthy_get_prediction;
+
+%ignore anthy_print_context;
+%ignore anthy_context_set_encoding;
+
+%{
+#define anthy_context_set_string anthy_set_string
+#define anthy_context_resize_segment anthy_resize_segment
+#define anthy_context_get_stat anthy_get_stat
+#define anthy_context_get_segment_stat anthy_get_segment_stat
+/* #define anthy_context_get_segment anthy_get_segment */
+/* #define anthy_context_commit_segment anthy_commit_segment */
+#define anthy_context_print anthy_print_context
+
+#define anthy_context_set_prediction_string anthy_set_prediction_string
+#define anthy_context_get_prediction_stat anthy_get_prediction_stat
+/* #define anthy_context_get_prediction anthy_get_prediction */
+%}
+
+%rename(Context) anthy_context;
+
+%rename(get_version_string) anthy_get_version_string;
+/* SWIG says "Segmentation fault" */
+/* %alias anthy_get_version_string "version_string"; */
+%inline %{
+static char *
+version_string(void)
+{
+ return anthy_get_version_string();
+}
+%}
+
+/* logger */
+%ignore anthy_set_logger;
+
+%header %{
+static VALUE logger = Qnil;
+%}
+
+%init %{
+rb_gc_register_address(&logger);
+%}
+
+%{
+#if 0
+} /* for c-mode indentation */
+#endif
+
+typedef struct logger_info
+{
+ VALUE level;
+ VALUE message;
+} logger_info_t;
+
+static VALUE
+invoke_logger(VALUE data)
+{
+ logger_info_t *info = (logger_info_t *)data;
+ return rb_funcall(logger, rb_intern("call"), 2, info->level, info->message);
+}
+
+static void
+rb_logger(int lv, const char *str)
+{
+ int state = 0;
+ logger_info_t info;
+
+ info.level = INT2NUM(lv);
+ info.message = rb_str_new2(str);
+ rb_protect(invoke_logger, (VALUE)&info, &state);
+ if (state && !NIL_P(ruby_errinfo)) {
+ VALUE klass, message, backtrace;
+ int i, len;
+
+ klass = rb_funcall(rb_funcall(ruby_errinfo, rb_intern("class"), 0),
+ rb_intern("to_s"), 0);
+ message = rb_funcall(ruby_errinfo, rb_intern("message"), 0);
+ backtrace = rb_funcall(ruby_errinfo, rb_intern("backtrace"), 0);
+ rb_warning("%s: %s\n", StringValueCStr(klass), StringValueCStr(message));
+
+ len = RARRAY(backtrace)->len;
+ for (i = 0; i < len; i++) {
+ rb_warning("%s\n", StringValueCStr(RARRAY(backtrace)->ptr[i]));
+ }
+ }
+}
+
+#if 0
+{ /* for c-mode indentation */
+#endif
+%}
+
+%inline %{
+#if 0
+} /* for c-mode indentation */
+#endif
+
+static void
+set_logger(int level)
+{
+ if (rb_block_given_p()) {
+ logger = Qnil;
+ anthy_set_logger(NULL, level);
+ } else {
+ logger = rb_block_proc();
+ anthy_set_logger(rb_logger, level);
+ }
+}
+
+#if 0
+{ /* for c-mode indentation */
+#endif
+%}
+
+%include include/anthy.h
+
+
+%freefunc anthy_context "anthy_release_context";
+
+struct anthy_context
+{
+ %extend
+ {
+ anthy_context(void)
+ {
+ return anthy_create_context();
+ };
+
+ void reset(void)
+ {
+ anthy_reset_context(self);
+ };
+
+ %alias set_string "string=";
+ int set_string(char *);
+
+ void resize_segment(int, int);
+
+ %alias get_stat "stat";
+ int get_stat(struct anthy_conv_stat *OUTPUT);
+
+ %alias get_segment_stat "segment_stat";
+ int get_segment_stat(int, struct anthy_segment_stat *OUTPUT);
+
+ %alias get_segment "segment";
+ VALUE get_segment(int nth_seg, int nth_cand)
+ {
+ int len;
+ char *buffer;
+ len = anthy_get_segment(self, nth_seg, nth_cand, NULL, 0);
+ buffer = alloca(len + 1);
+ len = anthy_get_segment(self, nth_seg, nth_cand, buffer, len + 1);
+ if (len < 0) {
+ return Qnil;
+ } else {
+ return rb_str_new2(buffer);
+ }
+ };
+
+ VALUE commit_segment(int s, int c)
+ {
+ return (anthy_commit_segment(self, s, c) < 0) ? Qfalse : Qtrue;
+ }
+
+ %alias set_prediction_string "prediction_string=";
+ int set_prediction_string(const char *);
+
+ %alias get_prediction_stat "prediction_stat";
+ int get_prediction_stat(struct anthy_prediction_stat *OUTPUT);
+
+ %alias get_prediction "prediction";
+ int get_prediction(int nth_pre)
+ {
+ int len;
+ char *buffer;
+ len = anthy_get_prediction(self, nth_pre, NULL, 0);
+ buffer = alloca(len + 1);
+ len = anthy_get_prediction(self, nth_pre, buffer, len + 1);
+ if (len < 0) {
+ return Qnil;
+ } else {
+ return rb_str_new2(buffer);
+ }
+ };
+
+
+ void print();
+
+ %alias set_encoding "encoding=";
+ void set_encoding(int encoding);
+ }
+};
diff --git a/src-util/convdb.c b/src-util/convdb.c
new file mode 100644
index 0000000..3512403
--- /dev/null
+++ b/src-util/convdb.c
@@ -0,0 +1,542 @@
+/*
+ * 変換エンジンの内部情報を使うため、意図的に
+ * layer violationを放置している。
+ *
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <anthy/anthy.h>
+#include <anthy/convdb.h>
+#include <anthy/segment.h>
+#include <anthy/feature_set.h>
+/**/
+#include "../src-main/main.h"
+#include "../src-splitter/wordborder.h"
+#include "../src-worddic/dic_ent.h"
+
+
+/* 自立語部か付属語部か */
+#define WORD_INDEP 0
+#define WORD_DEP 1
+
+/* 単語(自立語or付属語) */
+struct word {
+ /* WORD_* */
+ int type;
+ /* 付属語のhash(WORD_INDEP)もしくは変換後の文字列のhash(WORD_DEP) */
+ int hash;
+ /* 読みの文字列のhash */
+ int yomi_hash;
+ /* 変換前の文字列 */
+ xstr *raw_xs;
+ /* 変換後の文字列 */
+ xstr *conv_xs;
+ /* 変換後の品詞 */
+ const char *wt;
+};
+
+static struct cand_ent *
+selected_candidate(struct seg_ent *seg)
+{
+ if (seg->committed > -1) {
+ return seg->cands[seg->committed];
+ }
+ return seg->cands[0];
+}
+
+static void
+get_res(anthy_context_t ac, char *res_buf, int conv)
+{
+ struct anthy_conv_stat acs;
+ int i;
+
+ anthy_get_stat(ac, &acs);
+ res_buf[0] = 0;
+ if (!conv) {
+ strcat(res_buf, "|");
+ }
+ for (i = 0; i < acs.nr_segment; i++) {
+ char buf[1024];
+ if (conv) {
+ anthy_get_segment(ac, i, 0, buf, 1024);
+ strcat(res_buf, buf);
+ } else {
+ anthy_get_segment(ac, i, NTH_UNCONVERTED_CANDIDATE, buf, 1024);
+ strcat(res_buf, buf);
+ strcat(res_buf, "|");
+ }
+ }
+}
+
+static struct conv_res *
+do_find_conv_res(struct res_db *db, const char *src, const char *res)
+{
+ struct conv_res *cr;
+
+ for (cr = db->res_list.next; cr; cr = cr->next) {
+ if (((!cr->res_str && !res) ||
+ !strcmp(cr->res_str, res)) &&
+ !strcmp(cr->src_str, src)) {
+ return cr;
+ }
+ }
+ cr = (struct conv_res *)malloc(sizeof(struct conv_res));
+ cr->src_str = strdup(src);
+ if (res) {
+ cr->res_str = strdup(res);
+ } else {
+ cr->res_str = NULL;
+ }
+ cr->cand_str = NULL;
+ cr->check = CHK_UNKNOWN;
+ cr->used = 0;
+ cr->cand_check = NULL;
+ /**/
+ db->tail->next = cr;
+ cr->next = NULL;
+ db->tail = cr;
+ return cr;
+}
+
+struct conv_res *
+find_conv_res(struct res_db *db, anthy_context_t ac,
+ const char *src, int conv)
+{
+ char res_buf[1024];
+ get_res(ac, res_buf, conv);
+
+ return do_find_conv_res(db, src, res_buf);
+}
+
+static void
+chomp_line(char *buf)
+{
+ int len = strlen(buf);
+ if (buf[len-1] == '\n') {
+ buf[len-1] = 0;
+ }
+}
+
+struct res_db *
+create_db(void)
+{
+ struct res_db *db;
+
+ db = malloc(sizeof(struct res_db));
+ db->res_list.next = NULL;
+ db->tail = &db->res_list;
+ db->total = 0;
+ db->res.unknown = 0;
+ db->res.ok = 0;
+ db->res.miss = 0;
+ db->res.dontcare = 0;
+ db->split.unknown = 0;
+ db->split.ok = 0;
+ db->split.miss = 0;
+ db->split.dontcare = 0;
+
+ return db;
+}
+
+static void
+strip_separator_vbar(char *buf, const char *str)
+{
+ const char *src = str;
+ char *dst = buf;
+ while (*src) {
+ if (*src != '|' && *src != '~') {
+ *dst = *src;
+ dst ++;
+ }
+ src ++;
+ }
+ *dst = 0;
+}
+
+static void
+parse_line(struct res_db *db, char *line)
+{
+ char buf1[1024], buf2[1024], buf3[1024], buf4[1024];
+ char *src, *res;
+ const char *check;
+ struct conv_res *cr;
+ int nr;
+ chomp_line(line);
+ if (line[0] == '#' || line[0] == 0) {
+ return ;
+ }
+ nr = sscanf(line, "%s %s %s", buf1, buf2, buf3);
+ if (nr == 1) {
+ cr = do_find_conv_res(db, buf1, NULL);
+ cr->check = CHK_UNKNOWN;
+ return ;
+ }
+ if (nr < 2) {
+ return ;
+ }
+ if (buf1[0] != '|') {
+ /* buf1 buf2 buf3
+ * 平文 区切り文
+ * 平文 区切り文 変換後
+ * 平文 区切り文 check
+ */
+ src = buf1;
+ res = buf2;
+ if (nr == 3) {
+ check = buf3;
+ } else {
+ check = "?";
+ }
+ } else {
+ /* buf1 buf2 (buf3)
+ * 区切り文
+ * 区切り文 変換後
+ * 区切り文 check
+ */
+ strip_separator_vbar(buf4, buf1);
+ src = buf4;
+ res = buf1;
+ check = buf2;
+ }
+ cr = do_find_conv_res(db, src, res);
+ if (nr == 2 && check[0] != '|') {
+ cr->check = CHK_OK;
+ return ;
+ }
+ if (check[0] == 'O') {
+ cr->check = CHK_OK;
+ } else if (check[0] == 'X') {
+ cr->check = CHK_MISS;
+ } else if (check[0] == '*') {
+ cr->check = CHK_DONTCARE;
+ } else if (check[0] == '|') {
+ cr->check = CHK_UNKNOWN;
+ cr->cand_str = strdup(check);
+ } else {
+ cr->check = CHK_UNKNOWN;
+ }
+}
+
+void
+read_db(struct res_db *db, const char *fn)
+{
+ FILE *fp;
+ char line[1024];
+
+ if (!fn) {
+ return ;
+ }
+ fp = fopen(fn, "r");
+ if (!fp) {
+ return ;
+ }
+ while (fgets(line, 1024, fp)) {
+ parse_line(db, line);
+ }
+}
+
+static void
+fill_conv_info(struct word *w, struct cand_elm *elm)
+{
+ /*w->conv_xs, w->wt*/
+ struct dic_ent *de;
+ if (elm->nth == -1 ||
+ elm->nth >= elm->se->nr_dic_ents) {
+ w->conv_xs = NULL;
+ w->wt = NULL;
+ return ;
+ }
+ if (!elm->se->dic_ents) {
+ w->conv_xs = NULL;
+ w->wt = NULL;
+ return ;
+ }
+ /**/
+ de = elm->se->dic_ents[elm->nth];
+ w->conv_xs = anthy_xstr_dup(&de->str);
+ w->wt = de->wt_name;
+ w->hash = anthy_xstr_hash(w->conv_xs);
+}
+
+static void
+init_word(struct word *w, int type)
+{
+ w->type = type;
+ w->raw_xs = NULL;
+ w->conv_xs = NULL;
+ w->wt = NULL;
+}
+
+static void
+free_word(struct word *w)
+{
+ anthy_free_xstr(w->raw_xs);
+ anthy_free_xstr(w->conv_xs);
+}
+
+/* 自立語を作る */
+static void
+fill_indep_word(struct word *w, struct cand_elm *elm)
+{
+ init_word(w, WORD_INDEP);
+ /* 変換前の読みを取得する */
+ w->raw_xs = anthy_xstr_dup(&elm->str);
+ w->yomi_hash = anthy_xstr_hash(w->raw_xs);
+ w->hash = 0;
+ /**/
+ fill_conv_info(w, elm);
+}
+
+/* 付属語を作る */
+static void
+fill_dep_word(struct word *w, struct cand_elm *elm)
+{
+ init_word(w, WORD_DEP);
+ /**/
+ w->hash = anthy_xstr_hash(&elm->str);
+ w->yomi_hash = w->hash;
+ w->raw_xs = anthy_xstr_dup(&elm->str);
+}
+
+static void
+print_features(struct feature_list *fl)
+{
+ int i, nr;
+ if (!fl) {
+ return ;
+ }
+ nr = anthy_feature_list_nr(fl);
+ if (nr == 0) {
+ return ;
+ }
+ printf(" features=");
+ for (i = 0; i < nr; i++) {
+ if (i > 0) {
+ printf(",");
+ }
+ printf("%d", anthy_feature_list_nth(fl, i));
+ }
+}
+
+static void
+print_word(const char *prefix, struct word *w, struct feature_list *fl)
+{
+ printf("%s", prefix);
+ if (w->type == WORD_DEP) {
+ /* 付属語 */
+ printf("dep_word hash=%d ", w->hash);
+ anthy_putxstrln(w->raw_xs);
+ return ;
+ }
+ /* 自立語 */
+ printf("indep_word hash=%d", w->hash);
+ /**/
+ if (fl) {
+ print_features(fl);
+ }
+ /* 品詞 */
+ if (w->wt) {
+ printf(" %s", w->wt);
+ } else {
+ printf(" null");
+ }
+ /* 文字列 */
+ if (w->conv_xs) {
+ printf(" ");
+ anthy_putxstr(w->conv_xs);
+ } else {
+ printf(" null");
+ }
+ printf(" ");
+ anthy_putxstrln(w->raw_xs);
+}
+
+/** segの文節クラスを返す
+ * segがnullであれば、clをクラスとする
+ */
+static int
+get_seg_class(struct seg_ent *seg, int cl)
+{
+ struct cand_ent *ce;
+ if (!seg) {
+ return cl;
+ }
+ ce = selected_candidate(seg);
+ if (ce->mw) {
+ return ce->mw->seg_class;
+ }
+ return SEG_BUNSETSU;
+}
+
+static void
+set_features(struct feature_list *fl,
+ struct seg_ent *prev_seg,
+ struct seg_ent *cur_seg)
+{
+ int cl, pc;
+ cl = get_seg_class(cur_seg, SEG_TAIL);
+ pc = get_seg_class(prev_seg, SEG_HEAD);
+
+ anthy_feature_list_set_cur_class(fl, cl);
+ if (cur_seg) {
+ struct cand_ent *ce = selected_candidate(cur_seg);
+ anthy_feature_list_set_dep_word(fl, ce->dep_word_hash);
+ if (ce->mw) {
+ anthy_feature_list_set_dep_class(fl, ce->mw->dep_class);
+ anthy_feature_list_set_mw_features(fl, ce->mw->mw_features);
+ anthy_feature_list_set_noun_cos(fl, ce->mw->core_wt);
+ }
+ }
+ anthy_feature_list_set_class_trans(fl, pc, cl);
+ /**/
+ anthy_feature_list_sort(fl);
+}
+
+static void
+print_element(const char *prefix,
+ struct cand_elm *elm, struct feature_list *fl)
+{
+ struct word w;
+
+ if (elm->str.len == 0) {
+ return ;
+ }
+ if (elm->id != -1) {
+ /* 自立語 */
+ fill_indep_word(&w, elm);
+ print_word(prefix, &w, fl);
+ } else {
+ /* 付属語 */
+ fill_dep_word(&w, elm);
+ print_word(prefix, &w, NULL);
+ }
+ free_word(&w);
+}
+
+static void
+print_unconverted(struct cand_ent *ce)
+{
+ printf("unknown ");
+ anthy_putxstrln(&ce->str);
+}
+
+static void
+print_eos(struct seg_ent *prev_seg)
+{
+ struct feature_list fl;
+ anthy_feature_list_init(&fl);
+ set_features(&fl, prev_seg, NULL);
+ printf("eos ");
+ print_features(&fl);
+ printf("\n");
+ anthy_feature_list_free(&fl);
+}
+
+/* 候補のミスには '~'、文節長のミスには '!'を付ける
+ * 同じ文節内の二つめ以降の自立語には '^'を付ける
+ */
+static const char *
+get_prefix(int flag)
+{
+ if (flag & CONV_INVALID) {
+ return "^";
+ }
+ if (flag & CONV_SIZE_MISS) {
+ return "!";
+ }
+ if (flag & CONV_CAND_MISS) {
+ return "~";
+ }
+ return "";
+}
+
+static void
+print_segment_info(int is_negative,
+ struct seg_ent *prev_seg,
+ struct seg_ent *seg)
+{
+ int i;
+ struct feature_list fl;
+ struct cand_ent *ce = selected_candidate(seg);
+ int nr_indep = 0;
+ const char *prefix = get_prefix(is_negative);
+
+ anthy_feature_list_init(&fl);
+ set_features(&fl, prev_seg, seg);
+ for (i = 0; i < ce->nr_words; i++) {
+ struct cand_elm *elm = &ce->elm[i];
+ prefix = get_prefix(is_negative);
+ if (nr_indep > 0 && elm->id != -1) {
+ prefix = get_prefix(is_negative | CONV_INVALID);
+ }
+ /* 出力する */
+ print_element(prefix, elm, &fl);
+ /* 自立語を数える */
+ if (elm->id != -1) {
+ nr_indep ++;
+ }
+ }
+ anthy_feature_list_free(&fl);
+}
+
+void
+print_size_miss_segment_info(anthy_context_t ac, int nth)
+{
+ struct seg_ent *prev_seg = NULL;
+ struct seg_ent *seg = anthy_get_nth_segment(&ac->seg_list, nth);
+ if (nth > 0) {
+ prev_seg = anthy_get_nth_segment(&ac->seg_list, nth - 1);
+ }
+ print_segment_info(CONV_SIZE_MISS, prev_seg, seg);
+}
+
+void
+print_cand_miss_segment_info(anthy_context_t ac, int nth)
+{
+ struct seg_ent *prev_seg = NULL;
+ struct seg_ent *seg = anthy_get_nth_segment(&ac->seg_list, nth);
+ if (nth > 0) {
+ prev_seg = anthy_get_nth_segment(&ac->seg_list, nth - 1);
+ }
+ print_segment_info(CONV_CAND_MISS, prev_seg, seg);
+}
+
+void
+print_context_info(anthy_context_t ac, struct conv_res *cr)
+{
+ int i;
+ struct seg_ent *prev_seg = NULL;
+
+ printf("segments: %d\n", ac->seg_list.nr_segments);
+ /* 各文節に対して */
+ for (i = 0; i < ac->seg_list.nr_segments; i++) {
+ struct seg_ent *seg = anthy_get_nth_segment(&ac->seg_list, i);
+ struct cand_ent *ce = selected_candidate(seg);
+ int is_negative = 0;
+ if (cr && cr->cand_check && cr->cand_check[i]) {
+ is_negative = CONV_CAND_MISS;
+ }
+
+ /* 各要素に対して */
+ if (!ce->nr_words) {
+ /* 要素が無いものはそのまま表示 */
+ print_unconverted(ce);
+ } else {
+ /* 候補の変更があった場合はそれを表示 */
+ if (seg->committed > 0) {
+ int tmp = seg->committed;
+ seg->committed = 0;
+ print_cand_miss_segment_info(ac, i);
+ seg->committed = tmp;
+ }
+ /* 文節の構成を表示 */
+ print_segment_info(is_negative, prev_seg, seg);
+ }
+ /**/
+ prev_seg = seg;
+ }
+ print_eos(prev_seg);
+ printf("\n");
+}
diff --git a/src-util/dic-tool-usage.txt b/src-util/dic-tool-usage.txt
new file mode 100644
index 0000000..c9be824
--- /dev/null
+++ b/src-util/dic-tool-usage.txt
@@ -0,0 +1,30 @@
+# Anthyの個人用辞書
+#
+# 各単語のエントリは次のような形式をとります
+#
+# 読み 頻度 単語 <必須>
+# 変数名 = 値 <一個以上>
+# <空行>
+#
+#
+# 名詞の場合は次の例にある6つのパラメータの定義が必要です.
+# 下の7行をコメントアウトすると読みが「よみ」の「単語」を名詞として
+# 登録できます.
+#
+# よみ 1 単語
+# 品詞 = 名詞
+# な接続 = y
+# さ接続 = y
+# する接続 = y
+# 語幹のみで文節 = y
+# 格助詞接続 = y
+#
+# 名詞の場合、品詞以外のパラメータは y もしくは nの値をとる。
+#
+#
+#
+# 以下に登録されている単語が続きます
+# 変更した場合には
+# cat <ファイル名> | anthy-dic-tool --load
+# とすることによって個人用の辞書を更新することができます。
+#
diff --git a/src-util/dic-tool.c b/src-util/dic-tool.c
new file mode 100644
index 0000000..f5ce076
--- /dev/null
+++ b/src-util/dic-tool.c
@@ -0,0 +1,448 @@
+/*
+ * 辞書操作用のユーティリティコマンド
+ *
+ * 辞書のライブラリ内部の形式と外部の形式の相互変換を行う
+ * 外部形式は
+ * *読み 頻度 単語
+ * *品詞の変数1 = 値1
+ * *品詞の変数2 = 値2
+ * *...
+ * *<空行>
+ * になる
+ */
+/*
+ * Funded by IPA未踏ソフトウェア創造事業 2001 9/22
+ *
+ * Copyright (C) 2000-2007 TABATA Yusuke
+ */
+/*
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <anthy/anthy.h>
+#include <anthy/dicutil.h>
+/**/
+#include <anthy/xstr.h>
+#include "config.h"
+
+#define UNSPEC 0
+#define DUMP_DIC 1
+#define LOAD_DIC 2
+#define APPEND_DIC 3
+
+#define TYPETAB "typetab"
+#define USAGE_TEXT "dic-tool-usage.txt"
+
+#define USAGE \
+ "Anthy-dic-util [options]\n"\
+ " --help: Show this usage text\n"\
+ " --version: Show version\n"\
+ " --dump: Dump dictionary\n"\
+ " --load: Load dictionary\n"\
+ " --append: Append dictionary\n"\
+ " --utf8: Use utf8 encoding\n"\
+ " --personality=NAME: use NAME as a name of personality\n"
+
+
+static int command = UNSPEC;
+static int encoding = ANTHY_EUC_JP_ENCODING;
+static FILE *fp_in;
+static char *fn;
+static const char *personality = "";
+
+/* 変数名と値のペア */
+struct var{
+ struct var *next;
+ char *var_name;
+ char *val;
+};
+
+/* 品詞のパラメータから品詞名を得るためのテーブル */
+struct trans_tab {
+ struct trans_tab *next;
+ char *type_name; /* 内部での型の名前 T35とか */
+ struct var var_list; /* 型を決定するためのパラメータ */
+}trans_tab_list;
+
+static void
+print_usage(void)
+{
+ printf(USAGE);
+ exit(0);
+}
+
+static FILE *
+open_typetab(void)
+{
+ FILE *fp;
+ char *fn;
+ fp = fopen(TYPETAB, "r");
+ if (fp) {
+ return fp;
+ }
+ fn = strdup(anthy_dic_util_get_anthydir());
+ fn = realloc(fn, strlen(fn) + strlen(TYPETAB) + 4);
+ strcat(fn, "/");
+ strcat(fn, TYPETAB);
+ fp = fopen(fn, "r");
+ return fp;
+}
+
+static FILE *
+open_usage_file(void)
+{
+ FILE *fp;
+ /* カレントディレクトリにある場合は、それを使用する */
+ fp = fopen(USAGE_TEXT, "r");
+ if (!fp) {
+ /* インストールされたものを使用 */
+ char *fn;
+ fn = strdup(anthy_dic_util_get_anthydir());
+ fn = realloc(fn, strlen(fn) + strlen(USAGE_TEXT) + 10);
+ strcat(fn, "/" USAGE_TEXT);
+ fp = fopen(fn, "r");
+ }
+ return fp;
+}
+
+static void
+print_usage_text(void)
+{
+ char buf[256];
+ FILE *fp = open_usage_file();
+ if (!fp) {
+ printf("# Anthy-dic-tool\n#\n");
+ return ;
+ }
+ fprintf(stdout, "#" PACKAGE " " VERSION "\n");
+ if (encoding == ANTHY_UTF8_ENCODING) {
+ } else {
+ }
+ /* そのままファイルの内容を出力 */
+ while (fgets(buf, 256, fp)) {
+ if (encoding == ANTHY_UTF8_ENCODING) {
+ char *s;
+ s = anthy_conv_euc_to_utf8(buf);
+ printf("%s", s);
+ free(s);
+ } else {
+ printf("%s", buf);
+ }
+ }
+ fclose(fp);
+}
+
+static char *
+read_line(char *buf, int len, FILE *fp)
+{
+ while (fgets(buf, len, fp)) {
+ if (buf[0] != '#') {
+ /* 改行を削除する */
+ int l = strlen(buf);
+ if (l > 0 && buf[l-1] == '\n') {
+ buf[l-1] = 0;
+ }
+ if (l > 1 && buf[l-2] == '\r') {
+ buf[l-1] = 0;
+ }
+ /**/
+ return buf;
+ }
+ }
+ return NULL;
+}
+
+static int
+read_typetab_var(struct var *head, FILE *fp, int table)
+{
+ char buf[256];
+ char var[256], eq[256], val[256];
+ struct var *v;
+ if (!read_line(buf, 256, fp)) {
+ return -1;
+ }
+ if (sscanf(buf, "%s %s %s", var, eq, val) != 3) {
+ return -1;
+ }
+
+ v = malloc(sizeof(struct var));
+ if (encoding == ANTHY_UTF8_ENCODING && table) {
+ /* UTF-8 */
+ v->var_name = anthy_conv_euc_to_utf8(var);
+ v->val = anthy_conv_euc_to_utf8(val);
+ } else {
+ /* do not change */
+ v->var_name = strdup(var);
+ v->val = strdup(val);
+ }
+
+ /* リストにつなぐ */
+ v->next = head->next;
+ head->next = v;
+
+ return 0;
+}
+
+static int
+read_typetab_entry(FILE *fp)
+{
+ char buf[256], type_name[257];
+ char *res;
+ struct trans_tab *t;
+ /* 一行目の品詞名を読む */
+ do {
+ res = read_line(buf, 256, fp);
+ if (!res) {
+ return -1;
+ }
+ } while (res[0] == '#' || res[0] == 0);
+ t = malloc(sizeof(struct trans_tab));
+ sprintf(type_name, "#%s", buf);
+ t->type_name = strdup(type_name);
+ t->var_list.next = 0;
+ /* パラメータを読む */
+ while(!read_typetab_var(&t->var_list, fp, 1));
+ /* リストにつなぐ */
+ t->next = trans_tab_list.next;
+ trans_tab_list.next = t;
+ return 0;
+}
+
+static void
+read_typetab(void)
+{
+ FILE *fp = open_typetab();
+ if (!fp) {
+ printf("Failed to open type table.\n");
+ exit(1);
+ }
+ while (!read_typetab_entry(fp));
+}
+
+static struct trans_tab *
+find_trans_tab_by_name(char *name)
+{
+ struct trans_tab *t;
+ for (t = trans_tab_list.next; t; t = t->next) {
+ if (!strcmp(t->type_name, name)) {
+ return t;
+ }
+ }
+ return NULL;
+}
+
+static void
+print_word_type(struct trans_tab *t)
+{
+ struct var *v;
+ for (v = t->var_list.next; v; v = v->next) {
+ printf("%s\t=\t%s\n", v->var_name, v->val);
+ }
+}
+
+static void
+dump_dic(void)
+{
+ print_usage_text();
+ if (anthy_priv_dic_select_first_entry() == -1) {
+ printf("# Failed to read private dictionary\n"
+ "# There are no words or error occurred?\n"
+ "#\n");
+ return ;
+ }
+ do {
+ char idx[100], wt[100], w[100];
+ int freq;
+ if (anthy_priv_dic_get_index(idx, 100) &&
+ anthy_priv_dic_get_wtype(wt, 100) &&
+ anthy_priv_dic_get_word(w, 100)) {
+ struct trans_tab *t;
+ freq = anthy_priv_dic_get_freq();
+ t = find_trans_tab_by_name(wt);
+ if (t) {
+ printf("%s %d %s\n", idx, freq, w);
+ print_word_type(t);
+ printf("\n");
+ } else {
+ printf("# Failed to determine word type of %s(%s).\n", w, wt);
+ }
+ }
+ } while (anthy_priv_dic_select_next_entry() == 0);
+}
+
+static void
+open_input_file(void)
+{
+ if (!fn) {
+ fp_in = stdin;
+ } else {
+ fp_in = fopen(fn, "r");
+ if (!fp_in) {
+ exit(1);
+ }
+ }
+}
+
+/* vが sの中にあるか */
+static int
+match_var(struct var *v, struct var *s)
+{
+ struct var *i;
+ for (i = s->next; i; i = i->next) {
+ if (!strcmp(v->var_name, i->var_name) &&
+ !strcmp(v->val, i->val)) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/* v1がv2の部分集合かどうか */
+static int
+var_list_subset_p(struct var *v1, struct var *v2)
+{
+ struct var *v;
+ for (v = v1->next; v; v = v->next) {
+ if (!match_var(v, v2)) {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+static char *
+find_wt(void)
+{
+ struct var v;
+ struct trans_tab *t;
+ v.next = 0;
+ while(!read_typetab_var(&v, fp_in, 0));
+ for (t = trans_tab_list.next; t; t = t->next) {
+ if (var_list_subset_p(&t->var_list, &v) &&
+ var_list_subset_p(&v, &t->var_list)) {
+ return t->type_name;
+ }
+ }
+ return NULL;
+}
+
+static int
+find_head(char *yomi, char *freq, char *w)
+{
+ char buf[256];
+ do {
+ if (!read_line(buf, 256, fp_in)) {
+ return -1;
+ }
+ } while (sscanf(buf, "%s %s %[^\n]",yomi, freq, w) != 3);
+ return 0;
+}
+
+static void
+load_dic(void)
+{
+ char yomi[256], freq[256], w[256];
+ while (!find_head(yomi, freq, w)) {
+ char *wt = find_wt();
+ if (wt) {
+ int ret;
+ ret = anthy_priv_dic_add_entry(yomi, w, wt, atoi(freq));
+ if (ret == -1) {
+ printf("Failed to register %s\n", yomi);
+ }else {
+ printf("Word %s is registered as %s\n", yomi, wt);
+ }
+ } else {
+ printf("Failed to find the type of %s.\n", yomi);
+ }
+ }
+}
+
+static void
+print_version(void)
+{
+ printf("Anthy-dic-util "VERSION".\n");
+ exit(0);
+}
+
+static void
+parse_args(int argc, char **argv)
+{
+ int i;
+ for (i = 1 ; i < argc ; i++) {
+ if (!strncmp(argv[i], "--", 2)) {
+ char *opt = &argv[i][2];
+ if (!strcmp(opt, "help")) {
+ print_usage();
+ } else if (!strcmp(opt, "version")){
+ print_version();
+ } else if (!strcmp(opt, "dump")) {
+ command = DUMP_DIC;
+ } else if (!strcmp(opt,"append") ){
+ command = APPEND_DIC;
+ } else if (!strncmp(opt, "personality=", 12)) {
+ personality = &opt[12];
+ } else if (!strcmp(opt, "utf8")) {
+ encoding = ANTHY_UTF8_ENCODING;
+ } else if (!strcmp(opt, "eucjp")) {
+ encoding = ANTHY_EUC_JP_ENCODING;
+ } else if (!strcmp(opt, "load")) {
+ command = LOAD_DIC;
+ }
+ }else{
+ fn = argv[i];
+ }
+ }
+}
+
+static void
+init_lib(void)
+{
+ anthy_dic_util_init();
+ anthy_dic_util_set_encoding(encoding);
+ read_typetab();
+}
+
+int
+main(int argc,char **argv)
+{
+ fp_in = stdin;
+ parse_args(argc, argv);
+
+ switch (command) {
+ case DUMP_DIC:
+ init_lib();
+ dump_dic();
+ break;
+ case LOAD_DIC:
+ init_lib();
+ anthy_priv_dic_delete();
+ open_input_file();
+ load_dic();
+ break;
+ case APPEND_DIC:
+ init_lib();
+ open_input_file();
+ load_dic();
+ break;
+ case UNSPEC:
+ default:
+ print_usage();
+ }
+ return 0;
+}
diff --git a/src-util/egg.c b/src-util/egg.c
new file mode 100644
index 0000000..1ef46a2
--- /dev/null
+++ b/src-util/egg.c
@@ -0,0 +1,551 @@
+/*
+ * Copyright (C) 2002 The Free Software Initiative of Japan
+ * Author: NIIBE Yutaka
+ */
+
+/*
+ * ANTHY Low Level Agent
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <anthy/anthy.h>
+
+#include "config.h"
+
+/*
+ * connection context
+ * S -- open -> [ ] -- new ----> [ ] -- convert --> [ ] --> get_candidates
+ * <- close -- <- release - <-- commit -- --> resize_segment
+ * <-- cancel -- --> select_candidate
+ *
+ */
+
+struct context {
+ struct anthy_context *ac;
+ int buflen;
+ unsigned char *buf;
+ int removed, inserted;
+ int sellen;
+ int *selection;
+};
+
+#define MAX_CONTEXT 16
+static struct context contexts[MAX_CONTEXT];
+
+extern int use_utf8;
+
+#define INITIAL_BUFLEN 512
+#define INITIAL_SELLEN 128
+
+/*
+ * Returns -1 on error.
+ * Returns >= 0 on success, and the number is context descriptor.
+ */
+static int
+new_context (void)
+{
+ int i;
+
+ for (i = 0; i < MAX_CONTEXT; i++)
+ if (contexts[i].buflen == 0) { /* Found free one */
+ struct context *c = &contexts[i];
+
+ if ((c->buf = (unsigned char *)malloc (INITIAL_BUFLEN)) == NULL)
+ return -1;
+
+ if ((c->selection = (int *)malloc (INITIAL_SELLEN)) == NULL) {
+ free (c->buf);
+ c->buf = NULL;
+ return -1;
+ }
+
+ if ((c->ac = anthy_create_context ()) == NULL) {
+ free (c->buf);
+ c->buf = NULL;
+ free (c->selection);
+ c->selection = NULL;
+ return -1;
+ }
+ if (use_utf8) {
+ anthy_context_set_encoding(c->ac, ANTHY_UTF8_ENCODING);
+ }
+
+ c->buflen = INITIAL_BUFLEN;
+ c->sellen = INITIAL_SELLEN;
+ return i;
+ }
+
+ /* No free context to be used */
+ return -1;
+}
+
+static int
+release_context (int c_desc)
+{
+ struct context *c = &contexts[c_desc];
+
+ anthy_release_context(c->ac);
+ free (c->buf);
+ c->buf = NULL;
+ c->buflen = 0;
+ free (c->selection);
+ c->selection = NULL;
+ c->sellen = 0;
+
+ return 0;
+}
+
+static struct context *
+c_desc_to_context (int c_desc)
+{
+ return &contexts[c_desc];
+}
+
+static int
+get_number_of_segments (struct context *c)
+{
+ struct anthy_conv_stat cs;
+
+ if (anthy_get_stat(c->ac, &cs) < 0)
+ return -1;
+
+ return cs.nr_segment;
+}
+
+static int
+begin_conversion (struct context *c, const char *input)
+{
+ int i;
+ int seg_num;
+ if (anthy_set_string(c->ac, (char *)input) < 0)
+ return -1;
+
+ seg_num = get_number_of_segments (c);
+ if (seg_num >= c->sellen) {
+ c->sellen *= 2;
+ c->selection = realloc (c->selection, c->sellen);
+ if (c->selection == NULL) { /* Fatal */
+ c->sellen = -1;
+ return -1;
+ }
+ }
+
+ for (i = 0; i < seg_num; i++)
+ c->selection[i] = 0;
+
+ return 0;
+}
+
+static int
+end_conversion (struct context *c, int cancel)
+{
+ int n;
+ int seg_num;
+ int can_num;
+
+ if (!cancel) {
+ n = get_number_of_segments (c);
+ for (seg_num = 0; seg_num < n; seg_num++) {
+ can_num = c->selection[seg_num];
+ anthy_commit_segment(c->ac, seg_num, can_num);
+ }
+ }
+
+ return 0;
+}
+
+static int
+get_segment_number_of_candidates (struct context *c, int seg_num)
+{
+ struct anthy_segment_stat ss;
+
+ if (anthy_get_segment_stat (c->ac, seg_num, &ss) != 0)
+ return -1;
+
+ return ss.nr_candidate;
+}
+
+static const unsigned char *
+get_segment_candidate (struct context *c, int seg_num, int cand_num)
+{
+ int len;
+
+ while (1) {
+ len = anthy_get_segment (c->ac, seg_num, cand_num,
+ (char *)c->buf, c->buflen);
+
+ if (len < 0)
+ return NULL;
+
+ if (len < c->buflen)
+ return c->buf;
+
+ c->buflen *= 2;
+ c->buf = realloc (c->buf, c->buflen);
+ if (c->buf == NULL) { /* Fatal */
+ c->buflen = -1;
+ return NULL;
+ }
+ }
+}
+
+static const unsigned char *
+get_segment_yomi (struct context *c, int seg_num)
+{
+ return get_segment_candidate (c, seg_num, NTH_UNCONVERTED_CANDIDATE);
+}
+
+static const unsigned char *
+get_segment_converted (struct context *c, int seg_num)
+{
+ return get_segment_candidate (c, seg_num, 0);
+}
+
+static int
+resize_segment (struct context *c, int seg_num, int inc_dec)
+{
+ int i;
+ struct anthy_conv_stat cs;
+
+ if (anthy_get_stat(c->ac, &cs) < 0)
+ return -1;
+
+ /* Replace all segments after SEG_NUM */
+ c->removed = cs.nr_segment - seg_num;
+ anthy_resize_segment(c->ac, seg_num, inc_dec?-1:1);
+ if (anthy_get_stat(c->ac, &cs) < 0)
+ return -1;
+ c->inserted = cs.nr_segment - seg_num;
+
+ if (cs.nr_segment >= c->sellen) {
+ c->sellen *= 2;
+ c->selection = realloc (c->selection, c->sellen);
+ if (c->selection == NULL) { /* Fatal */
+ c->sellen = -1;
+ return -1;
+ }
+ }
+ for (i = seg_num; i < cs.nr_segment; i++)
+ c->selection[i] = 0;
+
+ return seg_num;
+}
+
+/* Only valid after call of resize_segment or select_candidate */
+static int
+get_number_of_segments_removed (struct context *c, int seg_num)
+{
+ (void)seg_num;
+ return c->removed;
+}
+
+/* Only valid after call of resize_segment or select_candidate */
+static int
+get_number_of_segments_inserted (struct context *c, int seg_num)
+{
+ (void)seg_num;
+ return c->inserted;
+}
+
+static int
+select_candidate (struct context *c, int seg_num, int can_num)
+{
+ /*
+ * Anthy does not have capability to affect the result of selection
+ * to other segments.
+ */
+ c->removed = 0;
+ c->inserted = 0;
+
+ /*
+ * Record, but not call anthy_commit_segment.
+ */
+ c->selection[seg_num] = can_num;
+
+ return seg_num;
+}
+
+static int
+say_hello (void)
+{
+ const char *options = "";
+
+ printf ("Anthy (Version %s) [%s] : Nice to meet you.\r\n", VERSION,
+ options);
+ fflush (stdout);
+ return 0;
+}
+
+#define ERROR_CODE_UNKNOWN 400
+#define ERROR_CODE_UNSUPPOTED 401
+
+static int
+say_unknown (void)
+{
+ printf ("-ERR %d Unknown command.\r\n", ERROR_CODE_UNKNOWN);
+ fflush (stdout);
+ return 0;
+}
+
+static int
+do_commit (const char *line)
+{
+ char *p;
+ struct context *c;
+ int c_desc, cancel, r;
+
+ c_desc = strtol (line+7, &p, 10);
+ c = c_desc_to_context (c_desc);
+ cancel = strtol (p+1, &p, 10);
+ r = end_conversion (c, cancel);
+ if (r < 0)
+ printf ("-ERR %d commit failed.\r\n", -r);
+ else
+ printf ("+OK\r\n");
+ fflush (stdout);
+ return 0;
+}
+
+static void
+output_segments (struct context *c, int seg_num, int removed, int inserted)
+{
+ int i;
+
+ printf ("+DATA %d %d %d\r\n", seg_num, removed, inserted);
+ for (i = seg_num; i < seg_num + inserted; i++) {
+ int nc;
+
+ nc = get_segment_number_of_candidates (c, i);
+ printf ("%d " ,nc);
+ printf ("%s ", get_segment_converted (c, i));
+ printf ("%s\r\n", get_segment_yomi (c, i));
+ }
+ printf ("\r\n");
+}
+
+static int
+do_convert (const char *line)
+{
+ char *p;
+ struct context *c;
+ int c_desc, r;
+
+ c_desc = strtol (line+8, &p, 10);
+ c = c_desc_to_context (c_desc);
+ r = begin_conversion (c, p+1);
+ if (r < 0)
+ printf ("-ERR %d convert failed.\r\n", -r);
+ else
+ {
+ int n = get_number_of_segments (c);
+ output_segments (c, 0, 0, n);
+ }
+
+ fflush (stdout);
+ return 0;
+}
+
+static int
+do_get_candidates (const char *line)
+{
+ char *p;
+ struct context *c;
+ int c_desc, seg_num, cand_offset, max_cands;
+ int nc, i, max;
+
+ c_desc = strtol (line+15, &p, 10);
+ seg_num = strtol (p+1, &p, 10);
+ cand_offset = strtol (p+1, &p, 10);
+ max_cands = strtol (p+1, &p, 10);
+
+ c = c_desc_to_context (c_desc);
+ nc = get_segment_number_of_candidates (c, seg_num);
+
+ max = cand_offset + max_cands;
+ if (nc < cand_offset + max_cands)
+ max = nc;
+
+ printf ("+DATA %d %d\r\n", cand_offset, max);
+ for (i = cand_offset; i < max; i++)
+ printf ("%s\r\n", get_segment_candidate (c, seg_num, i));
+ printf ("\r\n");
+
+ fflush (stdout);
+ return 0;
+}
+
+static int
+do_new_context (const char *line)
+{
+ int r;
+
+ /* XXX: Should check arguments */
+ if (strncmp (" INPUT=#18 OUTPUT=#18", line+11, 20) != 0) {
+ printf ("-ERR %d unsupported context\r\n", ERROR_CODE_UNSUPPOTED);
+ return 1;
+ }
+
+ r = new_context ();
+ if (r < 0)
+ printf ("-ERR %d new context failed.\r\n", -r);
+ else
+ printf ("+OK %d\r\n", r);
+
+ fflush (stdout);
+ return 0;
+}
+
+static int
+do_release_context (const char *line)
+{
+ int c_desc;
+ int r;
+ char *p;
+
+ c_desc = strtol (line+15, &p, 10);
+ r = release_context (c_desc);
+ if (r < 0)
+ printf ("-ERR %d release context failed.\r\n", -r);
+ else
+ printf ("+OK\r\n");
+
+ fflush (stdout);
+ return 0;
+}
+
+static int
+do_resize_segment (const char *line)
+{
+ char *p;
+ struct context *c;
+ int c_desc, seg_num, inc_dec, r;
+
+ c_desc = strtol (line+15, &p, 10);
+ seg_num = strtol (p+1, &p, 10);
+ inc_dec= strtol (p+1, &p, 10);
+ c = c_desc_to_context (c_desc);
+ r = resize_segment (c, seg_num, inc_dec);
+
+ if (r < 0)
+ printf ("-ERR %d resize failed.\r\n", -r);
+ else {
+ int removed, inserted;
+
+ seg_num = r;
+ removed = get_number_of_segments_removed (c, seg_num);
+ inserted = get_number_of_segments_inserted (c, seg_num);
+
+ output_segments (c, seg_num, removed, inserted);
+ }
+
+ fflush (stdout);
+ return 0;
+}
+
+static int
+do_select_candidate (const char *line)
+{
+ char *p;
+ struct context *c;
+ int c_desc, seg_num, cand_num, r;
+
+ c_desc = strtol (line+17, &p, 10);
+ seg_num = strtol (p+1, &p, 10);
+ cand_num = strtol (p+1, &p, 10);
+ c = c_desc_to_context (c_desc);
+ r = select_candidate (c, seg_num, cand_num);
+
+ if (r < 0)
+ printf ("-ERR %d select failed.\r\n", -r);
+ else {
+ int removed;
+
+ seg_num = r;
+ removed = get_number_of_segments_removed (c, seg_num);
+
+ if (removed == 0)
+ printf ("+OK\r\n");
+ else {
+ int inserted = get_number_of_segments_inserted (c, seg_num);
+
+ output_segments (c, seg_num, removed, inserted);
+ }
+ }
+
+ fflush (stdout);
+ return 0;
+}
+
+static int
+do_quit (const char *line)
+{
+ (void)line;
+ return 1;
+}
+
+struct dispatch_table {
+ const char *command;
+ int size;
+ int (*func)(const char *line);
+};
+
+static struct dispatch_table dt[] = {
+ { "COMMIT", 6, do_commit },
+ { "CONVERT", 7, do_convert },
+ { "GET-CANDIDATES", 14, do_get_candidates },
+ { "NEW-CONTEXT", 11, do_new_context },
+ { "QUIT", 4, do_quit },
+ { "RELEASE-CONTEXT", 15, do_release_context },
+ { "RESIZE-SEGMENT", 14, do_resize_segment },
+ { "SELECT-CANDIDATE", 16, do_select_candidate },
+};
+
+static int
+dt_cmp (const char *line, struct dispatch_table *d)
+{
+ return strncmp (line, d->command, d->size);
+}
+
+#define MAX_LINE 512
+static char line[MAX_LINE];
+
+void egg_main (void);
+
+void
+egg_main (void)
+{
+ int done = 0;
+ char *s, *p;
+
+ say_hello ();
+
+ while (!done) {
+ struct dispatch_table *d;
+
+ s = fgets (line, MAX_LINE, stdin);
+ if (s == NULL) {
+ fprintf (stderr, "null input\n");
+ break;
+ }
+ if ((p = (char *)memchr(s, '\n', MAX_LINE)) == NULL) {
+ fprintf (stderr, "no newline\n");
+ break;
+ }
+ if (p > s && *(p-1) == '\r')
+ *(p-1) = '\0';
+ else
+ *p = '\0';
+ d = (struct dispatch_table *)
+ bsearch (s, dt,
+ sizeof (dt) / sizeof (struct dispatch_table),
+ sizeof (struct dispatch_table),
+ (int (*)(const void *, const void *))dt_cmp);
+ if (d != NULL)
+ done = d->func (s);
+ else
+ say_unknown ();
+ }
+}
diff --git a/src-util/input.c b/src-util/input.c
new file mode 100644
index 0000000..00c58da
--- /dev/null
+++ b/src-util/input.c
@@ -0,0 +1,1543 @@
+/*
+ * Anthyのキーの受け付けやプリエディットの制御を行うレイヤー
+ *
+ * 今からアプリケーションを書く場合にはuimの利用をお薦めします。
+ *
+ * Funded by IPA未踏ソフトウェア創造事業 2002 1/23
+ * Copyright (C) 2001-2002 UGAWA Tomoharu
+ *
+ * $Id: input.c,v 1.25 2002/11/16 03:35:21 yusuke Exp $
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#include <assert.h>
+
+#include <anthy/anthy.h>
+#include <anthy/input.h>
+
+#include "rkconv.h"
+#include "rkhelper.h"
+
+struct anthy_input_context {
+ /* ANTHY_INPUT_ST_* */
+ int state;
+
+ /* always allocated */
+ struct rk_conv_context* rkctx;
+ int map_no; /* RKMAP_* */
+ /* 変換する文字列のバッファ*/
+ char* hbuf;
+ int n_hbuf;
+ int s_hbuf;
+ char* hbuf_follow;
+ int n_hbuf_follow;
+ int s_hbuf_follow;
+
+ /* allocated only in conv state */
+ anthy_context_t actx;
+ struct a_segment* segment;
+ struct a_segment* cur_segment;
+ int enum_cand_count;
+ int enum_cand_limit;
+ int enum_reverse;
+ int last_gotten_cand;
+
+ /* always allocated by the library */
+ /* コミットバッファ */
+ char* commit;
+ int n_commit;
+ int s_commit;
+
+ /* always allocated by the library */
+ /* カットバッファ */
+ char* cut;
+ int n_cut;
+ int s_cut;
+
+ struct anthy_input_config* cfg;
+ struct anthy_input_context* next_cfg_owner;
+};
+
+int anthy_input_errno;
+
+#define DEFAULT_ENUM_CAND_LIMIT 3
+
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+
+#define is_eucchar(s) (((s)[0] & 0x80) && ((s)[1] & 0x80))
+
+
+struct anthy_input_config {
+ struct rk_option* rk_option;
+ /* 6はsrc-util/rkhelper.h の NR_RKMAPに相当 */
+ struct rk_map* rk_map[6];
+ struct anthy_input_context* owners;
+ /**/
+ int break_into_roman;
+ int preedit_mode;
+};
+
+struct a_segment {
+ int index;
+ int pos;
+ struct anthy_segment_stat ass;
+ int cand;
+ struct a_segment* next, * prev;
+};
+
+static int
+ensure_buffer(char** buf, int* size, int to_size)
+{
+ if (*size < to_size) {
+ *buf = (char*) realloc(*buf, to_size);
+ if (*buf == NULL) {
+ anthy_input_errno = AIE_NOMEM;
+ return -1;
+ }
+ *size = to_size;
+ }
+ return 0;
+}
+
+static void
+leave_edit_state(struct anthy_input_context* ictx)
+{
+ /* do noting */
+ (void) ictx;
+}
+
+
+static void
+enter_none_state(struct anthy_input_context* ictx)
+{
+ ictx->state = ANTHY_INPUT_ST_NONE;
+}
+
+static void
+enter_edit_state(struct anthy_input_context* ictx)
+{
+ ictx->state = ANTHY_INPUT_ST_EDIT;
+ rk_flush(ictx->rkctx);
+ rk_select_registered_map(ictx->rkctx, ictx->map_no);
+ ictx->n_hbuf = 0;
+ ictx->n_hbuf_follow = 0;
+}
+
+static void
+enter_edit_state_noinit(struct anthy_input_context* ictx)
+{
+ ictx->state = ANTHY_INPUT_ST_EDIT;
+}
+
+static void
+leave_conv_state(struct anthy_input_context* ictx)
+{
+ struct a_segment* as, * next;
+ anthy_release_context(ictx->actx);
+ for (as = ictx->segment; as; as = next) {
+ next = as->next;
+ free(as);
+ }
+ anthy_reset_context(ictx->actx);
+}
+
+static void
+reset_anthy_input_context(struct anthy_input_context* ictx)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_NONE:
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ leave_edit_state(ictx);
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ leave_conv_state(ictx);
+ break;
+ }
+ enter_none_state(ictx);
+}
+
+static void
+read_rk_result(struct anthy_input_context* ictx)
+{
+ int ret;
+
+ ret = rk_result(ictx->rkctx, ictx->hbuf + ictx->n_hbuf,
+ ictx->s_hbuf - ictx->n_hbuf);
+ if (ret > 0) {
+ if (ictx->s_hbuf - ictx->n_hbuf > 0)
+ ictx->n_hbuf = ictx->s_hbuf - 1;
+
+ ensure_buffer(&ictx->hbuf, &ictx->s_hbuf, ictx->n_hbuf + ret + 1);
+
+ rk_result(ictx->rkctx, ictx->hbuf + ictx->n_hbuf,
+ ictx->s_hbuf - ictx->n_hbuf);
+ }
+ if (ictx->hbuf)
+ ictx->n_hbuf += strlen(ictx->hbuf + ictx->n_hbuf);
+}
+
+static void
+terminate_rk(struct anthy_input_context* ictx)
+{
+ rk_terminate(ictx->rkctx);
+ read_rk_result(ictx);
+ rk_flush(ictx->rkctx);
+}
+
+static void
+join_noconv_string(struct anthy_input_context* ictx)
+{
+ if (ictx->n_hbuf_follow > 0) {
+ ensure_buffer(&ictx->hbuf, &ictx->s_hbuf,
+ ictx->n_hbuf + ictx->n_hbuf_follow);
+ memcpy(ictx->hbuf + ictx->n_hbuf, ictx->hbuf_follow, ictx->n_hbuf_follow);
+ ictx->n_hbuf += ictx->n_hbuf_follow;
+ ictx->n_hbuf_follow = 0;
+ }
+}
+
+static void
+enter_conv_state(struct anthy_input_context* ictx)
+{
+ int ret;
+ struct anthy_conv_stat acs;
+ struct a_segment* as_tail, ** as_tailp;
+ int i;
+ int last_pos;
+
+ ictx->state = ANTHY_INPUT_ST_CONV;
+
+ terminate_rk(ictx);
+
+ join_noconv_string(ictx);
+
+ if (ictx->n_hbuf == 0) {
+ ensure_buffer(&ictx->commit, &ictx->s_commit, ictx->n_commit + 1);
+ ictx->commit[ictx->n_commit++] = ' ';
+ enter_none_state(ictx);
+ return;
+ }
+
+ ensure_buffer(&ictx->hbuf, &ictx->s_hbuf, ictx->n_hbuf + 1);
+ ictx->hbuf[ictx->n_hbuf] = '\0';
+
+ ictx->enum_cand_count = 0;
+ ictx->actx = anthy_create_context();
+ anthy_context_set_encoding(ictx->actx, ANTHY_EUC_JP_ENCODING);
+ if (!ictx->actx) {
+ enter_none_state(ictx);
+ anthy_input_errno = AIE_NOMEM;
+ return;
+ }
+ anthy_reset_context(ictx->actx);
+ ret = anthy_set_string(ictx->actx, ictx->hbuf);
+ if (ret < 0) {
+ anthy_release_context(ictx->actx);
+ enter_none_state(ictx);
+ return;
+ }
+
+ anthy_get_stat(ictx->actx, &acs);
+ as_tail = NULL;
+ as_tailp = &ictx->segment;
+ last_pos = 0;
+ for (i = 0; i < acs.nr_segment; i++) {
+ struct a_segment* as;
+ as = (struct a_segment*) malloc(sizeof(struct a_segment));
+ as->index = i;
+ as->pos = last_pos;
+ anthy_get_segment_stat(ictx->actx, i, &as->ass);
+ last_pos += as->ass.seg_len;
+ as->cand = 0;
+ as->prev = as_tail;
+ *as_tailp = as;
+ as->next = NULL;
+ as_tailp = &as->next;
+ as_tail = as;
+ }
+ ictx->cur_segment = ictx->segment;
+ ictx->last_gotten_cand = 0;
+}
+
+static void
+enter_conv_state_noinit(struct anthy_input_context* ictx)
+{
+ ictx->state = ANTHY_INPUT_ST_CONV;
+}
+
+static void
+enter_cseg_state(struct anthy_input_context* ictx)
+{
+ ictx->state = ANTHY_INPUT_ST_CSEG;
+ ictx->enum_cand_count = 0;
+}
+
+static void
+leave_cseg_state(struct anthy_input_context* ictx)
+{
+ /* do nothing */
+ (void)ictx;
+}
+
+static int
+cmdh_map_select(struct anthy_input_context* ictx, int map)
+{
+ switch (map) {
+ case ANTHY_INPUT_MAP_ALPHABET:
+ ictx->map_no = RKMAP_ASCII;
+ break;
+ case ANTHY_INPUT_MAP_WALPHABET:
+ ictx->map_no = RKMAP_WASCII;
+ break;
+ case ANTHY_INPUT_MAP_HIRAGANA:
+ ictx->map_no = RKMAP_HIRAGANA;
+ break;
+ case ANTHY_INPUT_MAP_KATAKANA:
+ ictx->map_no = RKMAP_KATAKANA;
+ break;
+ case ANTHY_INPUT_MAP_HANKAKU_KANA:
+ ictx->map_no = RKMAP_HANKAKU_KANA;
+ break;
+ default:
+ anthy_input_errno = AIE_INVAL;
+ return -1;
+ }
+
+ rk_select_registered_map(ictx->rkctx, ictx->map_no);
+
+ return 0;
+}
+
+static struct anthy_input_segment*
+cmdh_get_candidate(struct anthy_input_context* ictx, int cand_no)
+{
+ struct a_segment* cs;
+ struct anthy_input_segment* seg;
+ int len;
+
+ cs = ictx->cur_segment;
+ if (cand_no >= cs->ass.nr_candidate) {
+ anthy_input_errno = AIE_INVAL;
+ return NULL;
+ }
+ ictx->last_gotten_cand = cand_no;
+
+ seg = (struct anthy_input_segment*)
+ malloc(sizeof(struct anthy_input_segment));
+ len = anthy_get_segment(ictx->actx, cs->index, cand_no, NULL, 0);
+ seg->str = (char*) malloc(len + 1);
+ anthy_get_segment(ictx->actx, cs->index, cand_no, seg->str, len + 1);
+ seg->cand_no = cand_no;
+ seg->noconv_len = anthy_get_segment(ictx->actx, cs->index,
+ NTH_UNCONVERTED_CANDIDATE, NULL, 0);
+ seg->nr_cand = cs->ass.nr_candidate;
+ seg->flag = ANTHY_INPUT_SF_CURSOR;
+ if (ictx->enum_cand_count >= ictx->enum_cand_limit)
+ seg->flag |= (ictx->enum_reverse ?
+ ANTHY_INPUT_SF_ENUM_REVERSE : ANTHY_INPUT_SF_ENUM);
+
+ return seg;
+}
+
+static void
+do_cmd_commit(struct anthy_input_context* ictx)
+{
+ struct a_segment* as;
+
+ for (as = ictx->segment; as; as = as->next) {
+ int len;
+
+ len = anthy_get_segment(ictx->actx, as->index, as->cand, NULL, 0);
+ ensure_buffer(&ictx->commit, &ictx->s_commit, ictx->n_commit + len + 1);
+ anthy_get_segment(ictx->actx, as->index, as->cand,
+ ictx->commit + ictx->n_commit, len + 1);
+ ictx->n_commit += len;
+ anthy_commit_segment(ictx->actx, as->index, as->cand);
+ }
+}
+
+static int
+cmdh_select_candidate(struct anthy_input_context* ictx,
+ int cand_no)
+{
+ struct a_segment* cs;
+
+ cs = ictx->cur_segment;
+ if (cand_no >= cs->ass.nr_candidate) {
+ anthy_input_errno = AIE_INVAL;
+ return -1;
+ }
+ cs->cand = cand_no;
+
+ if (cs->next) {
+ ictx->cur_segment = cs->next;
+ ictx->last_gotten_cand = ictx->cur_segment->cand;
+ ictx->enum_cand_count = 0;
+ } else {
+ ictx->last_gotten_cand = ictx->cur_segment->cand;
+ ictx->enum_cand_count = 0;
+ }
+
+ return 0;
+}
+
+static void
+do_cmd_push_key(struct anthy_input_context* ictx, const char* str)
+{
+ const char* p;
+
+ for (p = str; *p; p++) {
+ if (isspace((int)(unsigned char) *p) && *p != ' ')
+ continue;
+
+ rk_push_key(ictx->rkctx, *p);
+ read_rk_result(ictx);
+ }
+}
+
+static void
+cmd_push_key(struct anthy_input_context* ictx, const char* str)
+{
+ do_cmd_push_key(ictx, str);
+}
+
+static void
+cmd_move_cursor(struct anthy_input_context* ictx, int d)
+{
+ if (rk_get_pending_str(ictx->rkctx, NULL, 0) > 1) {
+ rk_flush(ictx->rkctx);
+ return;
+ }
+
+ if (d > 0) {
+ char* p;
+ int len;
+ if (ictx->n_hbuf_follow == 0)
+ return;
+ for (p = ictx->hbuf_follow;
+ p < ictx->hbuf_follow + ictx->n_hbuf_follow && d > 0; p++, d--) {
+ if (p < ictx->hbuf_follow + ictx->n_hbuf_follow - 1 && is_eucchar(p))
+ p++;
+ }
+ len = p - ictx->hbuf_follow;
+ ensure_buffer(&ictx->hbuf, &ictx->s_hbuf, ictx->n_hbuf + len);
+ memcpy(ictx->hbuf + ictx->n_hbuf, ictx->hbuf_follow, len);
+ ictx->n_hbuf += len;
+ ictx->n_hbuf_follow -= len;
+ memmove(ictx->hbuf_follow, p, ictx->n_hbuf_follow);
+ } else {
+ char* p;
+ int len;
+ if (ictx->n_hbuf == 0)
+ return;
+ for (p = ictx->hbuf + ictx->n_hbuf;
+ p > ictx->hbuf && d < 0; p--, d++) {
+ if (p - 1 > ictx->hbuf && is_eucchar(p - 2))
+ p--;
+ }
+ len = (ictx->hbuf + ictx->n_hbuf) - p;
+ ensure_buffer(&ictx->hbuf_follow, &ictx->s_hbuf_follow,
+ ictx->n_hbuf_follow + len);
+ if (ictx->n_hbuf_follow > 0)
+ memmove(ictx->hbuf_follow + len, ictx->hbuf_follow, ictx->n_hbuf_follow);
+ memcpy(ictx->hbuf_follow, p, len);
+ ictx->n_hbuf_follow += len;
+ ictx->n_hbuf -= len;
+ }
+}
+
+static void
+cmd_backspace(struct anthy_input_context* ictx)
+{
+ int len;
+
+ len = rk_get_pending_str(ictx->rkctx, NULL, 0);
+ if (len > 1) {
+ char* buf;
+ /* 確定されていないローマ字があるので、最後の文字をカット */
+ len--;
+
+ buf = (char*) malloc(len);
+ rk_get_pending_str(ictx->rkctx, buf, len);
+ rk_flush(ictx->rkctx);
+ do_cmd_push_key(ictx, buf);
+ free(buf);
+ } else {
+ if (brk_roman_get_previous_pending(ictx->rkctx)) {
+ char *buf;
+ buf = strdup(brk_roman_get_previous_pending(ictx->rkctx));
+ ictx->n_hbuf -= brk_roman_get_decided_len(ictx->rkctx);
+
+ rk_flush(ictx->rkctx);
+ do_cmd_push_key(ictx,buf);
+ free(buf);
+ } else {
+ if (ictx->n_hbuf >= 2 && is_eucchar(ictx->hbuf + ictx->n_hbuf - 2)) {
+ ictx->n_hbuf -= 2;
+ } else if (ictx->n_hbuf >= 1) {
+ ictx->n_hbuf--;
+ }
+ }
+ }
+
+ if (ictx->n_hbuf + ictx->n_hbuf_follow <= 0 && len <= 1) {
+ leave_edit_state(ictx);
+ enter_none_state(ictx);
+ }
+}
+
+static void
+cmd_delete(struct anthy_input_context* ictx)
+{
+ int len;
+
+ if (rk_get_pending_str(ictx->rkctx, NULL, 0) > 1)
+ return;
+ if (ictx->n_hbuf_follow <= 0)
+ return;
+
+ len = ictx->n_hbuf_follow >= 2 && is_eucchar(ictx->hbuf_follow) ? 2 : 1;
+
+ if (ictx->n_hbuf_follow <= len)
+ ictx->n_hbuf_follow = 0;
+ else {
+ ictx->n_hbuf_follow -= len;
+ memmove(ictx->hbuf_follow, ictx->hbuf_follow + len, ictx->n_hbuf_follow);
+ }
+
+ if (ictx->n_hbuf + ictx->n_hbuf_follow <= 0) {
+ leave_edit_state(ictx);
+ enter_none_state(ictx);
+ }
+}
+
+static void
+cmd_commit_unconv(struct anthy_input_context* ictx)
+{
+ ensure_buffer(&ictx->commit, &ictx->s_commit,
+ ictx->n_commit + ictx->n_hbuf + ictx->n_hbuf_follow);
+ memcpy(ictx->commit + ictx->n_commit, ictx->hbuf, ictx->n_hbuf);
+ ictx->n_commit += ictx->n_hbuf;
+ if (ictx->n_hbuf_follow > 0)
+ memcpy(ictx->commit + ictx->n_commit,
+ ictx->hbuf_follow, ictx->n_hbuf_follow);
+ ictx->n_commit += ictx->n_hbuf_follow;
+}
+
+static void
+cmd_resize(struct anthy_input_context* ictx, int d)
+{
+ int i;
+ struct anthy_conv_stat acs;
+ struct a_segment* as;
+ int last_pos;
+
+ anthy_resize_segment(ictx->actx, ictx->cur_segment->index, d);
+ anthy_get_stat(ictx->actx, &acs);
+
+ anthy_get_segment_stat(ictx->actx,
+ ictx->cur_segment->index, &ictx->cur_segment->ass);
+ ictx->cur_segment->cand = NTH_UNCONVERTED_CANDIDATE;
+ last_pos = ictx->cur_segment->ass.seg_len;
+ for (as = ictx->cur_segment, i = as->index + 1; i < acs.nr_segment; i++) {
+ if (as->next == NULL) {
+ struct a_segment* as2;
+
+ as2 = (struct a_segment*) malloc(sizeof(struct a_segment));
+ as2->index = i;
+ as2->prev = as;
+ as->next = as2;
+ as2->next = NULL;
+ as = as2;
+ } else
+ as = as->next;
+ as->pos = last_pos;
+ anthy_get_segment_stat(ictx->actx, i, &as->ass);
+ last_pos += as->ass.seg_len;
+ as->cand = NTH_UNCONVERTED_CANDIDATE;
+ }
+ ictx->last_gotten_cand = NTH_UNCONVERTED_CANDIDATE;
+
+ as = as->next; /* 不正なメモリアクセスの修正 */
+ if (as) {
+ as->prev->next = NULL;
+ for (; as; ) {
+ struct a_segment* const next = as->next;
+ free(as);
+ as = next;
+ }
+ }
+}
+
+static void
+commit_noconv_string(struct anthy_input_context* ictx)
+{
+ join_noconv_string(ictx);
+ ensure_buffer(&ictx->commit, &ictx->s_commit,
+ ictx->n_commit + ictx->n_hbuf + 1);
+ /* +1 is just for an optimization */
+ memcpy(ictx->commit + ictx->n_commit,
+ ictx->hbuf, ictx->n_hbuf);
+ ictx->n_commit += ictx->n_hbuf;
+ ictx->n_hbuf = 0;
+}
+
+static void
+cmd_commit(struct anthy_input_context* ictx)
+{
+ do_cmd_commit(ictx);
+}
+
+static void
+cmd_next_candidate(struct anthy_input_context* ictx)
+{
+ struct a_segment* as;
+
+ ictx->enum_cand_count++;
+
+ as = ictx->cur_segment;
+
+ if (!ictx->enum_reverse)
+ as->cand = ictx->last_gotten_cand;
+ else
+ ictx->enum_reverse = 0;
+
+ if (as->cand == NTH_UNCONVERTED_CANDIDATE) {
+ while (as) {
+ if (as->cand == NTH_UNCONVERTED_CANDIDATE) {
+ as->cand = 0;
+ }
+ as = as->next;
+ }
+ ictx->last_gotten_cand = 0;
+ } else {
+ if (++as->cand >= as->ass.nr_candidate)
+ as->cand = 0;
+ ictx->last_gotten_cand = as->cand;
+ }
+}
+
+static void
+cmd_prev_candidate(struct anthy_input_context* ictx)
+{
+ struct a_segment* as;
+
+ ictx->enum_cand_count++;
+
+ as = ictx->cur_segment;
+
+ if (ictx->enum_reverse)
+ as->cand = ictx->last_gotten_cand;
+ else
+ ictx->enum_reverse = 1;
+
+ if (as->cand == NTH_UNCONVERTED_CANDIDATE) {
+ while (as) {
+ if (as->cand == NTH_UNCONVERTED_CANDIDATE) {
+ as->cand = 0;
+ }
+ as = as->next;
+ }
+ ictx->last_gotten_cand = 0;
+ } else {
+ if (--as->cand < 0)
+ as->cand = as->ass.nr_candidate - 1;
+ ictx->last_gotten_cand = as->cand;
+ }
+}
+
+static void
+cmd_move_selection(struct anthy_input_context* ictx, int d)
+{
+ if (d > 0)
+ while (d-- > 0 && ictx->cur_segment->next) {
+ ictx->enum_cand_count = 0;
+ ictx->cur_segment = ictx->cur_segment->next;
+ ictx->last_gotten_cand = ictx->cur_segment->cand;
+ }
+ else
+ while (d++ < 0 && ictx->cur_segment->prev) {
+ ictx->enum_cand_count = 0;
+ ictx->cur_segment = ictx->cur_segment->prev;
+ ictx->last_gotten_cand = ictx->cur_segment->cand;
+ }
+}
+
+static void
+cmd_move_to_bol_seg(struct anthy_input_context* ictx)
+{
+ ictx->cur_segment = ictx->segment;
+ ictx->enum_cand_count = 0;
+ ictx->last_gotten_cand = ictx->cur_segment->cand;
+}
+
+static void
+cmd_move_to_eol_seg(struct anthy_input_context* ictx)
+{
+ while (ictx->cur_segment->next)
+ ictx->cur_segment = ictx->cur_segment->next;
+ ictx->enum_cand_count = 0;
+ ictx->last_gotten_cand = ictx->cur_segment->cand;
+}
+
+static void
+cmd_unhiragana_candidate(struct anthy_input_context* ictx)
+{
+ struct a_segment* as;
+
+ for (as = ictx->cur_segment->next; as; as = as->next)
+ as->cand = 0;
+}
+
+static void
+cmd_move_to_bol(struct anthy_input_context* ictx)
+{
+ terminate_rk(ictx);
+
+ if (ictx->hbuf_follow == NULL) { /* 最適化 */
+ ictx->hbuf_follow = ictx->hbuf;
+ ictx->n_hbuf_follow = ictx->n_hbuf;
+ ictx->s_hbuf_follow = ictx->s_hbuf;
+ ictx->hbuf = NULL;
+ ictx->n_hbuf = 0;
+ ictx->s_hbuf = 0;
+ return;
+ }
+
+ ensure_buffer(&ictx->hbuf_follow, &ictx->s_hbuf_follow,
+ ictx->n_hbuf + ictx->n_hbuf_follow);
+ memmove(ictx->hbuf_follow + ictx->n_hbuf,
+ ictx->hbuf_follow, ictx->n_hbuf_follow);
+ memcpy(ictx->hbuf_follow, ictx->hbuf, ictx->n_hbuf);
+ ictx->n_hbuf_follow += ictx->n_hbuf;
+ ictx->n_hbuf = 0;
+}
+
+static void
+cmd_move_to_eol(struct anthy_input_context* ictx)
+{
+ terminate_rk(ictx);
+
+ if (ictx->hbuf == NULL) { /* 最適化 */
+ ictx->hbuf = ictx->hbuf_follow;
+ ictx->n_hbuf = ictx->n_hbuf_follow;
+ ictx->s_hbuf = ictx->s_hbuf_follow;
+ ictx->hbuf_follow = NULL;
+ ictx->n_hbuf_follow = 0;
+ ictx->s_hbuf_follow = 0;
+ return;
+ }
+
+ ensure_buffer(&ictx->hbuf, &ictx->s_hbuf,
+ ictx->n_hbuf + ictx->n_hbuf_follow);
+ memcpy(ictx->hbuf + ictx->n_hbuf, ictx->hbuf_follow, ictx->n_hbuf_follow);
+ ictx->n_hbuf += ictx->n_hbuf_follow;
+ ictx->n_hbuf_follow = 0;
+}
+
+static void
+cmd_cut(struct anthy_input_context* ictx)
+{
+ char* tmp_str;
+ int tmp_int;
+
+ terminate_rk(ictx);
+
+ /* バッファの入れ換えで済ませる */
+ tmp_str = ictx->cut;
+ tmp_int = ictx->s_cut;
+ ictx->cut = ictx->hbuf_follow;
+ ictx->n_cut = ictx->n_hbuf_follow;
+ ictx->s_cut = ictx->s_hbuf_follow;
+ ictx->hbuf_follow = tmp_str;
+ ictx->n_hbuf_follow = 0;
+ ictx->s_hbuf_follow = tmp_int;
+}
+
+/*****************************************************************/
+
+/* pure function */
+struct anthy_input_context*
+anthy_input_create_context(struct anthy_input_config* cfg)
+{
+ struct anthy_input_context* ictx;
+ int i;
+
+ ictx =
+ (struct anthy_input_context*) malloc(sizeof(struct anthy_input_context));
+ ictx->state = ANTHY_INPUT_ST_NONE;
+ ictx->rkctx = rk_context_create(cfg->break_into_roman);
+ for (i = 0; i < NR_RKMAP; i++)
+ rk_register_map(ictx->rkctx, i, cfg->rk_map[i]);
+ ictx->map_no = RKMAP_HIRAGANA;
+ rk_select_registered_map(ictx->rkctx, ictx->map_no);
+ ictx->hbuf = NULL;
+ ictx->n_hbuf = 0;
+ ictx->s_hbuf = 0;
+ ictx->hbuf_follow = NULL;
+ ictx->n_hbuf_follow = 0;
+ ictx->s_hbuf_follow = 0;
+ ictx->enum_cand_limit = DEFAULT_ENUM_CAND_LIMIT;
+ ictx->enum_cand_count = 0;
+ ictx->actx = NULL;
+ ictx->segment = NULL;
+ ictx->cur_segment = NULL;
+ ictx->enum_reverse = 0; /* 初期化忘れの修正 */
+ ictx->last_gotten_cand = 0; /* 初期化忘れの修正 */
+ ictx->commit = NULL;
+ ictx->n_commit = 0;
+ ictx->s_commit = 0;
+ ictx->cut = NULL;
+ ictx->n_cut = 0;
+ ictx->s_cut = 0;
+ ictx->cfg = cfg;
+ ictx->next_cfg_owner = cfg->owners;
+ cfg->owners = ictx;
+ return ictx;
+}
+
+void
+anthy_input_free_context(struct anthy_input_context* ictx)
+{
+ struct anthy_input_context **p;
+
+ reset_anthy_input_context(ictx);
+ rk_context_free(ictx->rkctx);
+
+ for (p = &ictx->cfg->owners; *p; p = &(*p)->next_cfg_owner)
+ if (*p == ictx) {
+ *p = ictx->next_cfg_owner;
+ break;
+ }
+
+ free(ictx->hbuf);
+ free(ictx->hbuf_follow);
+ free(ictx->commit);
+ free(ictx->cut);
+ free(ictx);
+}
+
+void
+anthy_input_free_preedit(struct anthy_input_preedit* pedit)
+{
+ struct anthy_input_segment* p, * q;
+
+ free(pedit->commit);
+ free(pedit->cut_buf);
+ for (p = pedit->segment; p; p = q) {
+ q = p->next;
+ anthy_input_free_segment(p);
+ }
+ free(pedit);
+}
+
+void
+anthy_input_free_segment(struct anthy_input_segment* seg)
+{
+ free(seg->str);
+ free(seg);
+}
+
+void
+anthy_input_str(struct anthy_input_context* ictx, const char* str)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ break;
+ case ANTHY_INPUT_ST_NONE:
+ enter_edit_state(ictx);
+ cmd_push_key(ictx, str);
+ if (ictx->map_no == RKMAP_ASCII ||
+ ictx->map_no == RKMAP_WASCII) {
+ commit_noconv_string(ictx);
+ leave_edit_state(ictx);
+ enter_none_state(ictx);
+ }
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ cmd_push_key(ictx, str);
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ cmd_commit(ictx);
+ leave_conv_state(ictx);
+ enter_edit_state(ictx);
+ cmd_push_key(ictx, str);
+ break;
+ case ANTHY_INPUT_ST_CSEG:
+ cmd_commit(ictx);
+ leave_cseg_state(ictx);
+ enter_conv_state_noinit(ictx);
+ leave_conv_state(ictx);
+ enter_edit_state(ictx);
+ cmd_push_key(ictx, str);
+ break;
+ }
+}
+
+void
+anthy_input_next_candidate(struct anthy_input_context* ictx)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ break;
+ case ANTHY_INPUT_ST_NONE:
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ enter_conv_state(ictx);
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ cmd_next_candidate(ictx);
+ break;
+ case ANTHY_INPUT_ST_CSEG:
+ cmd_unhiragana_candidate(ictx);
+ leave_cseg_state(ictx);
+ enter_conv_state_noinit(ictx);
+ cmd_next_candidate(ictx);
+ break;
+ }
+}
+
+
+void
+anthy_input_prev_candidate(struct anthy_input_context* ictx)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ break;
+ case ANTHY_INPUT_ST_NONE:
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ enter_conv_state(ictx);
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ cmd_prev_candidate(ictx);
+ break;
+ case ANTHY_INPUT_ST_CSEG:
+ leave_cseg_state(ictx);
+ enter_conv_state_noinit(ictx);
+ cmd_prev_candidate(ictx);
+ break;
+ }
+}
+
+void
+anthy_input_quit(struct anthy_input_context* ictx)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ break;
+ case ANTHY_INPUT_ST_NONE:
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ leave_edit_state(ictx);
+ enter_none_state(ictx);
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ leave_conv_state(ictx);
+ enter_edit_state_noinit(ictx);
+ break;
+ case ANTHY_INPUT_ST_CSEG:
+ leave_cseg_state(ictx);
+ enter_conv_state_noinit(ictx);
+ leave_conv_state(ictx);
+ enter_edit_state_noinit(ictx);
+ break;
+ }
+}
+
+void
+anthy_input_erase_prev(struct anthy_input_context* ictx)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ break;
+ case ANTHY_INPUT_ST_NONE:
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ cmd_backspace(ictx);
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ leave_conv_state(ictx);
+ enter_edit_state_noinit(ictx);
+ break;
+ case ANTHY_INPUT_ST_CSEG:
+ leave_cseg_state(ictx);
+ enter_conv_state_noinit(ictx);
+ leave_conv_state(ictx);
+ enter_edit_state_noinit(ictx);
+ break;
+ }
+}
+
+void
+anthy_input_erase_next(struct anthy_input_context* ictx)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ break;
+ case ANTHY_INPUT_ST_NONE:
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ cmd_delete(ictx);
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ break;
+ case ANTHY_INPUT_ST_CSEG:
+ break;
+ }
+}
+
+void
+anthy_input_commit(struct anthy_input_context* ictx)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ break;
+ case ANTHY_INPUT_ST_NONE:
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ terminate_rk(ictx);
+ cmd_commit_unconv(ictx);
+ leave_edit_state(ictx);
+ enter_none_state(ictx);
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ cmd_commit(ictx);
+ leave_conv_state(ictx);
+ enter_none_state(ictx);
+ break;
+ case ANTHY_INPUT_ST_CSEG:
+ cmd_commit(ictx);
+ leave_cseg_state(ictx);
+ enter_conv_state_noinit(ictx);
+ leave_conv_state(ictx);
+ enter_none_state(ictx);
+ break;
+ }
+}
+
+void
+anthy_input_move(struct anthy_input_context* ictx, int lr)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ break;
+ case ANTHY_INPUT_ST_NONE:
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ cmd_move_cursor(ictx, lr);
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ cmd_move_selection(ictx, lr);
+ break;
+ case ANTHY_INPUT_ST_CSEG:
+ cmd_unhiragana_candidate(ictx);
+ leave_cseg_state(ictx);
+ enter_conv_state_noinit(ictx);
+ cmd_move_selection(ictx, lr);
+ break;
+ }
+}
+
+void
+anthy_input_resize(struct anthy_input_context* ictx, int lr)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ break;
+ case ANTHY_INPUT_ST_NONE:
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ enter_cseg_state(ictx);
+ cmd_resize(ictx, lr);
+ break;
+ case ANTHY_INPUT_ST_CSEG:
+ cmd_resize(ictx, lr);
+ break;
+ }
+}
+
+void
+anthy_input_beginning_of_line(struct anthy_input_context* ictx)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ break;
+ case ANTHY_INPUT_ST_NONE:
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ cmd_move_to_bol(ictx);
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ cmd_move_to_bol_seg(ictx);
+ break;
+ case ANTHY_INPUT_ST_CSEG:
+ break;
+ }
+}
+
+void
+anthy_input_end_of_line(struct anthy_input_context* ictx)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ break;
+ case ANTHY_INPUT_ST_NONE:
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ cmd_move_to_eol(ictx);
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ cmd_move_to_eol_seg(ictx);
+ break;
+ case ANTHY_INPUT_ST_CSEG:
+ break;
+ }
+}
+
+void
+anthy_input_cut(struct anthy_input_context* ictx)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ break;
+ case ANTHY_INPUT_ST_NONE:
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ cmd_cut(ictx);
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ break;
+ case ANTHY_INPUT_ST_CSEG:
+ break;
+ }
+}
+
+/* key oriented function */
+void
+anthy_input_key(struct anthy_input_context* ictx, int c)
+{
+ char buf[2];
+
+ buf[0] = (char) c;
+ buf[1] = '\0';
+ anthy_input_str(ictx, buf);
+}
+
+void
+anthy_input_space(struct anthy_input_context* ictx)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ break;
+ case ANTHY_INPUT_ST_NONE:
+ enter_edit_state(ictx);
+ do_cmd_push_key(ictx, " ");
+ commit_noconv_string(ictx);
+ leave_edit_state(ictx);
+ enter_none_state(ictx);
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ terminate_rk(ictx);
+ if (rk_selected_map(ictx->rkctx) == RKMAP_SHIFT_ASCII)
+ do_cmd_push_key(ictx, " ");
+ else
+ enter_conv_state(ictx);
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ cmd_next_candidate(ictx);
+ break;
+ case ANTHY_INPUT_ST_CSEG:
+ cmd_unhiragana_candidate(ictx);
+ leave_cseg_state(ictx);
+ enter_conv_state_noinit(ictx);
+ cmd_next_candidate(ictx);
+ break;
+ }
+}
+
+/* meta function command */
+
+int
+anthy_input_get_state(struct anthy_input_context* ictx)
+{
+ return ictx->state;
+}
+
+static struct anthy_input_segment *
+alloc_segment(int flag, int len, int noconv_len)
+{
+ struct anthy_input_segment *seg;
+ seg = (struct anthy_input_segment*)
+ malloc(sizeof(struct anthy_input_segment));
+ seg->flag = flag;
+ seg->cand_no = -1;
+ seg->nr_cand = -1;
+ seg->noconv_len = noconv_len;
+ if (len) {
+ seg->str = (char *)malloc(len);
+ } else {
+ seg->str = NULL;
+ }
+ seg->next = NULL;
+ return seg;
+}
+
+static void
+get_edit_mode_preedit(struct anthy_input_context* ictx,
+ struct anthy_input_preedit* pedit)
+{
+ struct anthy_input_segment** p;
+ int len;
+ /* 左の文字列pending|カーソル|右の文字列 */
+
+ p = &pedit->segment;
+
+ /* left */
+ if (ictx->n_hbuf > 0) {
+ *p = alloc_segment(ANTHY_INPUT_SF_EDITING, ictx->n_hbuf + 1,
+ ictx->n_hbuf);
+
+ memcpy((*p)->str, ictx->hbuf, ictx->n_hbuf);
+ (*p)->str[ictx->n_hbuf] = '\0';
+ p = &(*p)->next;
+ }
+
+ if (ictx->cfg->preedit_mode) {
+ len = rk_partial_result(ictx->rkctx, NULL, 0);
+ if (len > 1) {
+ *p = alloc_segment(ANTHY_INPUT_SF_PENDING, len, len - 1);
+
+ rk_partial_result(ictx->rkctx, (*p)->str, len);
+ p = &(*p)->next;
+ }
+ } else {
+ len = rk_get_pending_str(ictx->rkctx, NULL, 0);
+ if (len > 1) {
+ *p = alloc_segment(ANTHY_INPUT_SF_PENDING, len, len - 1);
+
+ rk_get_pending_str(ictx->rkctx, (*p)->str, len);
+ p = &(*p)->next;
+ }
+ }
+
+ /* cursor */
+ *p = alloc_segment(ANTHY_INPUT_SF_CURSOR, 0, 0);
+ pedit->cur_segment = *p;
+ p = &(*p)->next;
+
+ /* right */
+ if (ictx->n_hbuf_follow > 0) {
+ *p = alloc_segment(ANTHY_INPUT_SF_EDITING,
+ ictx->n_hbuf_follow + 1,
+ ictx->n_hbuf_follow);
+ memcpy((*p)->str, ictx->hbuf_follow, ictx->n_hbuf_follow);
+ (*p)->str[ictx->n_hbuf_follow] = '\0';
+ }
+}
+
+struct anthy_input_preedit*
+anthy_input_get_preedit(struct anthy_input_context* ictx)
+{
+ struct anthy_input_preedit* pedit;
+
+ pedit = (struct anthy_input_preedit*)
+ malloc(sizeof(struct anthy_input_preedit));
+
+ pedit->state = ictx->state;
+
+ /* 未コミットの文字列 */
+ if (ictx->n_commit > 0) {
+ pedit->commit = (char*) malloc(ictx->n_commit + 1);
+ memcpy(pedit->commit, ictx->commit, ictx->n_commit);
+ pedit->commit[ictx->n_commit] = '\0';
+ ictx->n_commit = 0;
+ } else {
+ pedit->commit = NULL;
+ }
+
+ /* カットバッファの文字列 */
+ if(ictx->n_cut > 0) {
+ pedit->cut_buf = (char*) malloc(ictx->n_cut + 1);
+ memcpy(pedit->cut_buf, ictx->cut, ictx->n_cut);
+ pedit->cut_buf[ictx->n_cut] = '\0';
+ ictx->n_cut = 0;
+ } else {
+ pedit->cut_buf = NULL;
+ }
+
+ pedit->segment = NULL;
+ pedit->cur_segment = NULL;
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ case ANTHY_INPUT_ST_NONE:
+ break;
+ case ANTHY_INPUT_ST_EDIT:
+ get_edit_mode_preedit(ictx, pedit);
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ case ANTHY_INPUT_ST_CSEG:
+ {
+ struct anthy_input_segment** p;
+ struct a_segment* as;
+
+ for (as = ictx->segment, p = &pedit->segment; as; as = as->next) {
+ /* 各文節に対して */
+ int len, noconv_len;
+
+ noconv_len = anthy_get_segment(ictx->actx, as->index,
+ NTH_UNCONVERTED_CANDIDATE,
+ NULL, 0);
+ len = anthy_get_segment(ictx->actx, as->index, as->cand, NULL, 0);
+ *p = alloc_segment(ANTHY_INPUT_SF_NONE, len + 1, noconv_len);
+
+ anthy_get_segment(ictx->actx, as->index, as->cand, (*p)->str, len + 1);
+ (*p)->cand_no = as->cand;
+ (*p)->nr_cand = as->ass.nr_candidate;
+ (*p)->next = NULL;
+
+ if (as == ictx->cur_segment) {
+ pedit->cur_segment = *p;
+ (*p)->flag |= ANTHY_INPUT_SF_CURSOR;
+ if (ictx->enum_cand_count >= ictx->enum_cand_limit)
+ (*p)->flag |= (ictx->enum_reverse ?
+ ANTHY_INPUT_SF_ENUM_REVERSE : ANTHY_INPUT_SF_ENUM);
+
+ if (ictx->state == ANTHY_INPUT_ST_CSEG) {
+ struct a_segment* as1;
+
+ for (as1 = as->next, len = 0; as1; as1 = as1->next)
+ len += anthy_get_segment(ictx->actx, as1->index,
+ NTH_UNCONVERTED_CANDIDATE, NULL, 0);
+ if (len > 0) {
+ char* s;
+
+ p = &(*p)->next;
+ *p = alloc_segment(ANTHY_INPUT_SF_FOLLOWING, len + 1, len);
+ for (as1 = as->next, s = (*p)->str; as1; as1 = as1->next) {
+ anthy_get_segment(ictx->actx, as1->index,
+ NTH_UNCONVERTED_CANDIDATE,
+ s, len - (s - (*p)->str) + 1);
+ s += anthy_get_segment(ictx->actx, as1->index,
+ NTH_UNCONVERTED_CANDIDATE, NULL, 0);
+ }
+ (*p)->str[len] = '\0';
+ (*p)->next = NULL;
+ }
+ break;
+ }
+ }
+
+ p = &(*p)->next;
+ }
+ }
+ break;
+ }
+
+ return pedit;
+}
+
+int
+anthy_input_map_select(struct anthy_input_context* ictx, int map)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ break;
+ case ANTHY_INPUT_ST_NONE:
+ case ANTHY_INPUT_ST_EDIT:
+ case ANTHY_INPUT_ST_CONV:
+ case ANTHY_INPUT_ST_CSEG:
+ return cmdh_map_select(ictx, map);
+ break;
+ }
+
+ anthy_input_errno = AIE_INVAL;
+ return -1;
+}
+
+int
+anthy_input_get_selected_map(struct anthy_input_context* ictx)
+{
+ return ictx->map_no;
+}
+
+struct anthy_input_segment*
+anthy_input_get_candidate(struct anthy_input_context* ictx, int cand_no)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_CONV:
+ return cmdh_get_candidate(ictx, cand_no);
+ break;
+ case ANTHY_INPUT_ST_OFF:
+ case ANTHY_INPUT_ST_NONE:
+ case ANTHY_INPUT_ST_EDIT:
+ case ANTHY_INPUT_ST_CSEG:
+ break;
+ }
+
+ anthy_input_errno = AIE_INVAL;
+ return NULL;
+}
+
+int
+anthy_input_select_candidate(struct anthy_input_context* ictx, int cand)
+{
+ switch (ictx->state) {
+ case ANTHY_INPUT_ST_OFF:
+ case ANTHY_INPUT_ST_NONE:
+ case ANTHY_INPUT_ST_EDIT:
+ break;
+ case ANTHY_INPUT_ST_CONV:
+ return cmdh_select_candidate(ictx, cand);
+ break;
+ case ANTHY_INPUT_ST_CSEG:
+ break;
+ }
+
+ anthy_input_errno = AIE_INVAL;
+ return -1;
+}
+
+int
+anthy_input_edit_toggle_config(struct anthy_input_config *cfg, char tg)
+{
+ return anthy_input_do_edit_toggle_option(cfg->rk_option, tg);
+}
+
+int
+anthy_input_edit_rk_config(struct anthy_input_config *cfg, int map,
+ const char *from, const char *to, const char *follow)
+{
+ return
+ anthy_input_do_edit_rk_option(cfg->rk_option, map,
+ from, to, follow);
+}
+
+int
+anthy_input_clear_rk_config(struct anthy_input_config *cfg,
+ int use_default)
+{
+ return
+ anthy_input_do_clear_rk_option(cfg->rk_option, use_default);
+}
+
+int
+anthy_input_break_into_roman_config(struct anthy_input_config *cfg,
+ int brk)
+{
+ int old_val;
+ old_val = cfg->break_into_roman;
+ cfg->break_into_roman = brk;
+ return old_val;
+}
+
+int
+anthy_input_preedit_mode_config(struct anthy_input_config *cfg,
+ int val)
+{
+ int old_val;
+ old_val = cfg->preedit_mode;
+ cfg->preedit_mode = val;
+ return old_val;
+}
+
+void
+anthy_input_change_config(struct anthy_input_config* cfg)
+{
+ struct anthy_input_context* p;
+
+ struct rk_map* h_map = cfg->rk_map[RKMAP_HIRAGANA];
+ struct rk_map* k_map = cfg->rk_map[RKMAP_KATAKANA];
+ struct rk_map* s_map = cfg->rk_map[RKMAP_SHIFT_ASCII];
+ struct rk_map* hk_map = cfg->rk_map[RKMAP_HANKAKU_KANA];
+
+ cfg->rk_map[RKMAP_HIRAGANA] = make_rkmap_hiragana(cfg->rk_option);
+ cfg->rk_map[RKMAP_KATAKANA] = make_rkmap_katakana(cfg->rk_option);
+ cfg->rk_map[RKMAP_SHIFT_ASCII] = make_rkmap_shiftascii(cfg->rk_option);
+ cfg->rk_map[RKMAP_HANKAKU_KANA] = make_rkmap_hankaku_kana(cfg->rk_option);
+
+ /* このconfigを共有するコンテキストすべてに対して */
+ for (p = cfg->owners; p; p = p->next_cfg_owner) {
+ reset_anthy_input_context(p);
+ rk_register_map(p->rkctx, RKMAP_HIRAGANA, cfg->rk_map[RKMAP_HIRAGANA]);
+ rk_register_map(p->rkctx, RKMAP_KATAKANA, cfg->rk_map[RKMAP_KATAKANA]);
+ rk_register_map(p->rkctx, RKMAP_SHIFT_ASCII,
+ cfg->rk_map[RKMAP_SHIFT_ASCII]);
+ rk_register_map(p->rkctx, RKMAP_HANKAKU_KANA,
+ cfg->rk_map[RKMAP_HANKAKU_KANA]);
+ rk_select_registered_map(p->rkctx, RKMAP_HIRAGANA);
+ }
+
+ rk_map_free(h_map);
+ rk_map_free(k_map);
+ rk_map_free(s_map);
+ rk_map_free(hk_map);
+}
+
+struct anthy_input_config*
+anthy_input_create_config(void)
+{
+ struct anthy_input_config* cfg;
+
+ cfg = (struct anthy_input_config*) malloc(sizeof(struct anthy_input_config));
+
+ cfg->rk_option = anthy_input_create_rk_option();
+ cfg->break_into_roman = 0;
+ cfg->preedit_mode = 0;
+ cfg->rk_map[RKMAP_ASCII] = make_rkmap_ascii(cfg->rk_option);
+ cfg->rk_map[RKMAP_SHIFT_ASCII] = make_rkmap_shiftascii(cfg->rk_option);
+ cfg->rk_map[RKMAP_HIRAGANA] = make_rkmap_hiragana(cfg->rk_option);
+ cfg->rk_map[RKMAP_KATAKANA] = make_rkmap_katakana(cfg->rk_option);
+ cfg->rk_map[RKMAP_WASCII] = make_rkmap_wascii(cfg->rk_option);
+ cfg->rk_map[RKMAP_HANKAKU_KANA] = make_rkmap_hankaku_kana(cfg->rk_option);
+ cfg->owners = NULL;
+
+ return cfg;
+}
+
+void
+anthy_input_free_config(struct anthy_input_config* cfg)
+{
+ int err;
+
+ /* このconfigを共有する全てのcontextを事前に解放する事 */
+ assert(!cfg->owners);
+
+ rk_map_free(cfg->rk_map[RKMAP_ASCII]);
+ rk_map_free(cfg->rk_map[RKMAP_SHIFT_ASCII]);
+ rk_map_free(cfg->rk_map[RKMAP_HIRAGANA]);
+ rk_map_free(cfg->rk_map[RKMAP_KATAKANA]);
+ rk_map_free(cfg->rk_map[RKMAP_WASCII]);
+ rk_map_free(cfg->rk_map[RKMAP_HANKAKU_KANA]);
+
+ err = anthy_input_free_rk_option(cfg->rk_option);
+ free(cfg);
+}
+
+int
+anthy_input_init(void)
+{
+ return anthy_init();
+}
+
+void
+anthy_input_set_personality(const char *personality)
+{
+ anthy_set_personality(personality);
+}
+
+anthy_context_t
+anthy_input_get_anthy_context(struct anthy_input_context *ictx)
+{
+ return ictx->actx;
+}
diff --git a/src-util/leim-list.el b/src-util/leim-list.el
new file mode 100644
index 0000000..c9b055a
--- /dev/null
+++ b/src-util/leim-list.el
@@ -0,0 +1,7 @@
+;; -*- no-byte-compile: t -*-
+(register-input-method "japanese-anthy" "Japanese"
+ 'anthy-leim-activate "[anthy]"
+ "Anthy Kana Kanji conversion system")
+
+(autoload 'anthy-leim-activate "anthy")
+;;
diff --git a/src-util/morph-main.c b/src-util/morph-main.c
new file mode 100644
index 0000000..17b28d0
--- /dev/null
+++ b/src-util/morph-main.c
@@ -0,0 +1,154 @@
+/* コーパスから遷移行列を作るためのコード
+ *
+ * Copyright (C) 2005-2006 TABATA Yusuke
+ * Copyright (C) 2005-2006 YOSHIDA Yuichi
+ *
+ */
+/*
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <anthy/anthy.h>
+/* for print_context_info() */
+#include <anthy/convdb.h>
+
+struct test_context {
+ anthy_context_t ac;
+};
+
+static void read_file(struct test_context *tc, const char *fn);
+extern void anthy_reload_record(void);
+
+int verbose;
+int use_utf8;
+
+/**/
+static void
+init_test_context(struct test_context *tc)
+{
+ tc->ac = anthy_create_context();
+ anthy_set_reconversion_mode(tc->ac, ANTHY_RECONVERT_ALWAYS);
+ if (use_utf8) {
+ anthy_context_set_encoding(tc->ac, ANTHY_UTF8_ENCODING);
+ }
+ anthy_reload_record();
+}
+
+static void
+conv_sentence(struct test_context *tc, const char *str)
+{
+ anthy_set_string(tc->ac, str);
+ if (verbose) {
+ anthy_print_context(tc->ac);
+ }
+ /**/
+ print_context_info(tc->ac, NULL);
+}
+
+/* 行末の改行を削除 */
+static void
+chomp(char *buf)
+{
+ int len = strlen(buf);
+ while (len > 0) {
+ char c = buf[len - 1];
+ if (c == '\n' || c == '\r' || c == ' ' || c == '\t') {
+ buf[len - 1] = 0;
+ len --;
+ } else {
+ return ;
+ }
+ }
+}
+
+static void
+read_fp(struct test_context *tc, FILE *fp)
+{
+ char buf[1024];
+ while (fgets(buf, 1024, fp)) {
+ if (buf[0] == '#') {
+ continue;
+ }
+
+ if (!strncmp(buf, "\\include ", 9)) {
+ read_file(tc, &buf[9]);
+ continue;
+ }
+ chomp(buf);
+ conv_sentence(tc, buf);
+ }
+}
+
+static void
+read_file(struct test_context *tc, const char *fn)
+{
+ FILE *fp;
+ fp = fopen(fn, "r");
+ if (!fp) {
+ printf("failed to open (%s)\n", fn);
+ return ;
+ }
+ read_fp(tc, fp);
+ fclose(fp);
+}
+
+static void
+print_usage(void)
+{
+ printf("morphological analyzer\n");
+ printf(" $ ./morphological analyzer < [text-file]\n or");
+ printf(" $ ./morphological analyzer [text-file]\n");
+ exit(0);
+}
+
+static void
+parse_args(int argc, char **argv)
+{
+ int i;
+ for (i = 1; i < argc; i++) {
+ char *arg = argv[i];
+ if (!strcmp(arg, "--utf8")) {
+ use_utf8 = 1;
+ } else if (arg[i] == '-') {
+ print_usage();
+ }
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ struct test_context tc;
+ int i, nr;
+ anthy_init();
+ anthy_set_personality("");
+ init_test_context(&tc);
+
+ /*read_file(&tc, "index.txt");*/
+ parse_args(argc, argv);
+
+ nr = 0;
+ for (i = 1; i < argc; i++) {
+ read_file(&tc, argv[i]);
+ nr ++;
+ }
+ if (nr == 0) {
+ read_fp(&tc, stdin);
+ }
+
+ return 0;
+}
diff --git a/src-util/rkconv.c b/src-util/rkconv.c
new file mode 100644
index 0000000..cd627bc
--- /dev/null
+++ b/src-util/rkconv.c
@@ -0,0 +1,791 @@
+/*
+ * roma kana converter
+ *
+ * 理解するためには,構文解析について書かれたテキストで
+ * SLR(1)について調べるよろし.
+ *
+ * $Id: rkconv.c,v 1.16 2002/11/16 03:35:21 yusuke Exp $
+ *
+ * Copyright (C) 2001-2002 UGAWA Tomoharu
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "rkconv.h"
+
+#define MAX_CONV_CHARS 1024
+#define MAX_MAP_PALETTE 10
+#define SPECIAL_CHAR '\xff'
+#define TERMINATE_CHAR '\n'
+
+/* break_into_roman */
+struct break_roman {
+ int decided_length;
+ int pending_size;
+ char* pending;
+};
+
+struct rk_rule_set
+{
+ struct rk_rule* rules;
+ int nr_rules;
+};
+
+struct next_array
+{
+ struct rk_slr_closure* array[128];
+};
+
+struct rk_slr_closure
+{
+ char* prefix;
+ struct rk_rule* r;
+ int is_reduction_only;
+ struct next_array *next;
+};
+
+struct rk_map
+{
+ struct rk_rule_set* rs;
+ struct rk_slr_closure* root_cl;
+ int refcount;
+};
+
+struct rk_conv_context
+{
+ struct rk_map* map;
+ int map_no;
+ int old_map_no;
+ struct rk_slr_closure* cur_state;
+ char cur_str[MAX_CONV_CHARS + 1];
+ int cur_str_len;
+ struct rk_map* map_palette[MAX_MAP_PALETTE];
+ struct break_roman *brk_roman;
+};
+
+static void
+rk_rule_set_free(struct rk_rule_set* rs)
+{
+ int i;
+
+ for (i = 0; i < rs->nr_rules; i++) {
+ free((void *) rs->rules[i].lhs);
+ free((void *) rs->rules[i].rhs);
+ free((void *) rs->rules[i].follow);
+ }
+ free(rs->rules);
+ free(rs);
+}
+
+static int
+rk_rule_copy_to(const struct rk_rule* from, struct rk_rule* to)
+{
+ char *lhs, *rhs;
+
+ if ((lhs = strdup(from->lhs))) {
+ if ((rhs = strdup(from->rhs))) {
+ if (!(to->follow = from->follow)
+ || (to->follow = strdup(from->follow))) {
+ to->lhs = lhs;
+ to->rhs = rhs;
+ return 0;
+ }
+ free(rhs);
+ }
+ free(lhs);
+ }
+ to->lhs = NULL;
+ to->rhs = NULL;
+ return -1;
+}
+
+static struct rk_rule_set*
+rk_rule_set_create(const struct rk_rule* rules)
+{
+ int i;
+ struct rk_rule_set* rs;
+
+ rs = (struct rk_rule_set*) malloc(sizeof(struct rk_rule_set));
+ if (rs == NULL) {
+ return NULL;
+ }
+
+ for (i = 0; rules[i].lhs != NULL; i++);
+ rs->nr_rules = i;
+ rs->rules = (struct rk_rule*) malloc(sizeof(struct rk_rule) * i);
+ if (rs->rules == NULL) {
+ free(rs);
+ return NULL;
+ }
+ for (i = 0; i < rs->nr_rules; i++) {
+ if (rk_rule_copy_to(rules + i, rs->rules + i) != 0) {
+ rs->nr_rules = i;
+ rk_rule_set_free(rs);
+ return NULL;
+ }
+ }
+ return rs;
+}
+
+
+static void
+rk_slr_closure_free(struct rk_slr_closure* cl)
+{
+ int i;
+ free(cl->prefix);
+ if (cl->next) {
+ for (i = 0; i < 128; i++) {
+ if (cl->next->array[i]) {
+ rk_slr_closure_free(cl->next->array[i]);
+ }
+ }
+ free(cl->next);
+ }
+ free(cl);
+}
+
+static struct next_array *
+alloc_next_array(void)
+{
+ int i;
+ struct next_array *na = malloc(sizeof(struct next_array));
+ for (i = 0; i < 128; i++) {
+ na->array[i] = NULL;
+ }
+ return na;
+}
+
+static struct rk_slr_closure*
+rk_slr_closure_create(struct rk_rule_set* rs,
+ const char* prefix, int pflen)
+{
+ struct rk_slr_closure* cl;
+ int i;
+
+ cl = (struct rk_slr_closure*) malloc(sizeof(struct rk_slr_closure));
+ if (cl == NULL) {
+ return NULL;
+ }
+
+ if (prefix != NULL) {
+ cl->prefix = (char*) malloc(pflen + 1);
+ if (cl->prefix == NULL) {
+ free(cl);
+ return NULL;
+ }
+ memcpy(cl->prefix, prefix, pflen);
+ cl->prefix[pflen] = '\0';
+ } else {
+ cl->prefix = strdup("");
+ if (cl->prefix == NULL) {
+ free(cl);
+ return NULL;
+ }
+ }
+
+ cl->r = NULL;
+ cl->is_reduction_only = 1;
+ cl->next = NULL;
+
+ for (i = 0; i < rs->nr_rules; i++) {
+ struct rk_rule* r;
+ int c;
+ r = rs->rules + i;
+ if (pflen > 0 && strncmp(prefix, r->lhs, pflen) != 0)
+ continue;
+
+ c = r->lhs[pflen] & 0x7f;
+ if (c == '\0') { /* reduce */
+ cl->r = r;
+ if (r->follow != NULL)
+ cl->is_reduction_only = 0;
+ } else {
+ cl->is_reduction_only = 0;
+ if (cl->next == NULL) {
+ cl->next = alloc_next_array();
+ }
+ if (cl->next->array[c] == NULL) {
+ cl->next->array[c] = rk_slr_closure_create(rs, r->lhs,
+ pflen + 1);
+ if (cl->next->array[c] == NULL) {
+ rk_slr_closure_free(cl);
+ return NULL;
+ }
+ }
+ }
+ }
+
+ return cl;
+}
+
+struct rk_map*
+rk_map_create(const struct rk_rule* rules)
+{
+ struct rk_map* map;
+
+ map = (struct rk_map*) malloc(sizeof(struct rk_map));
+ if (map == NULL) {
+ return NULL;
+ }
+
+ map->rs = rk_rule_set_create(rules);
+ if (map->rs == NULL) {
+ free(map);
+ return NULL;
+ }
+
+ map->root_cl = rk_slr_closure_create(map->rs, NULL, 0);
+ if (map->root_cl == NULL) {
+ rk_rule_set_free(map->rs);
+ free(map);
+ return NULL;
+ }
+
+ map->refcount = 0;
+
+ return map;
+}
+
+int
+rk_map_free(struct rk_map* map)
+{
+ if (map->refcount > 0) {
+ return -1;
+ }
+ rk_rule_set_free(map->rs);
+ rk_slr_closure_free(map->root_cl);
+ free(map);
+ return 0;
+}
+
+
+static int
+rk_reduce(struct rk_conv_context* cc,
+ struct rk_slr_closure* cur_state, char* buf, int size)
+{
+ struct rk_rule* r;
+ const char* p;
+ char* q, * end;
+
+ r = cur_state->r;
+ if (r == NULL || size <= 0)
+ return 0;
+
+ if (r->rhs[0] == SPECIAL_CHAR) {
+ if (r->rhs[1] == 'o')
+ rk_select_registered_map(cc, cc->old_map_no);
+ else {
+ int mapn = r->rhs[1] - '0';
+ rk_select_registered_map(cc, mapn);
+ }
+ return 0;
+ }
+
+ p = r->rhs;
+ q = buf;
+ end = buf + size - 1;
+ while (*p && q < end)
+ *q ++ = *p++;
+ *q = '\0';
+
+ return q - buf;
+}
+
+static void
+rk_convert_iterative(struct rk_conv_context* cc, int c,
+ char* buf, int size)
+{
+ struct rk_slr_closure* cur_state = cc->cur_state;
+
+ if (cc->map == NULL)
+ return;
+ if (size > 0)
+ *buf = '\0';
+ AGAIN:
+
+ if (cur_state->next && cur_state->next->array[c]) {
+ struct rk_slr_closure* next_state = cur_state->next->array[c];
+
+ if (next_state->is_reduction_only) {
+ rk_reduce(cc, next_state, buf, size);
+ if (cc->map == NULL) {
+ cc->cur_state = NULL;
+ return;
+ }
+ cur_state = cc->map->root_cl;
+ } else
+ cur_state = next_state;
+ } else if (cur_state->r != NULL &&
+ (cur_state->r->follow == NULL ||
+ strchr(cur_state->r->follow, c))) {
+ int len;
+
+ len = rk_reduce(cc, cur_state, buf, size);
+ if (cc->map == NULL) {
+ cc->cur_state = NULL;
+ return;
+ }
+ cur_state = cc->map->root_cl;
+ buf += len;
+ size -= len;
+ goto AGAIN;
+ } else if (cur_state != cc->map->root_cl) {
+ cur_state = cc->map->root_cl;
+ goto AGAIN;
+ }
+ cc->cur_state = cur_state;
+}
+
+static void
+brk_roman_init(struct rk_conv_context *rkctx)
+{
+ rkctx->brk_roman= (struct break_roman *)malloc(sizeof(struct break_roman));
+ rkctx->brk_roman->pending=NULL;
+ rkctx->brk_roman->pending_size=0;
+}
+
+static void
+brk_roman_free(struct rk_conv_context *rkctx)
+{
+ struct break_roman *br=rkctx->brk_roman;
+
+ if(!br)
+ return;
+
+ if (br->pending) {
+ free(br->pending);
+ }
+ free(br);
+}
+
+
+static void
+brk_roman_save_pending(struct rk_conv_context *rkctx)
+{
+ struct break_roman *br=rkctx->brk_roman;
+ int len;
+
+ if(!br)
+ return;
+
+ len = rk_get_pending_str(rkctx,NULL,0);
+
+ if(br->pending_size < len){
+ br->pending_size=len;
+ if(br->pending)
+ free(br->pending);
+ br->pending=(char *)malloc(len);
+ }
+
+ rk_get_pending_str(rkctx,br->pending,len);
+}
+
+
+static void
+brk_roman_set_decided_len(struct rk_conv_context *rkctx,int len)
+{
+ struct break_roman *br=rkctx->brk_roman;
+
+ if(!br)
+ return;
+
+ br->decided_length=len;
+}
+
+static void
+brk_roman_flush(struct rk_conv_context *rkctx)
+{
+ struct break_roman *br=rkctx->brk_roman;
+
+ if(!br)
+ return;
+
+ if(br->pending)
+ br->pending[0]='\0';
+ br->decided_length=0;
+}
+
+struct rk_conv_context*
+rk_context_create(int brk)
+{
+ struct rk_conv_context* cc;
+
+ cc = (struct rk_conv_context*) malloc(sizeof(struct rk_conv_context));
+ if (cc == NULL) {
+ return NULL;
+ }
+
+ cc->map = NULL;
+ memset(&cc->map_palette, 0, sizeof(struct rk_map*) * MAX_MAP_PALETTE);
+ cc->map_no = -1;
+ cc->old_map_no = -1;
+ cc->brk_roman = NULL;
+ if (brk) {
+ brk_roman_init(cc);
+ }
+ rk_flush(cc);
+
+ return cc;
+}
+
+void
+rk_context_free(struct rk_conv_context* cc)
+{
+ int i;
+
+ brk_roman_free(cc);
+ rk_select_map(cc, NULL);
+ for (i = 0; i < MAX_MAP_PALETTE; i++) {
+ rk_register_map(cc, i, NULL);
+ }
+ free(cc);
+}
+
+int
+rk_push_key(struct rk_conv_context* cc, int c)
+{
+ int increased_length;
+ c &= 0x7f;
+ if (cc->cur_state == NULL)
+ return -1;
+
+ brk_roman_save_pending(cc);
+ rk_convert_iterative(cc, c,
+ cc->cur_str + cc->cur_str_len,
+ MAX_CONV_CHARS + 1 - cc->cur_str_len);
+ increased_length = strlen(cc->cur_str + cc->cur_str_len);
+ brk_roman_set_decided_len(cc,increased_length);
+ cc->cur_str_len += increased_length;
+
+ return 0;
+}
+
+void
+rk_terminate(struct rk_conv_context* cc)
+{
+ rk_push_key(cc, TERMINATE_CHAR);
+}
+
+void
+rk_flush(struct rk_conv_context* cc)
+{
+ brk_roman_flush(cc);
+ cc->cur_state = (cc->map == NULL) ? NULL : cc->map->root_cl;
+ cc->cur_str[0] = '\0';
+ cc->cur_str_len = 0;
+}
+
+int
+rk_partial_result(struct rk_conv_context* cc, char* buf, int size)
+{
+ int nr_rules = cc->map->rs->nr_rules;
+ int i, pending_len;
+ char *pending_buf;
+ struct rk_rule *rule = cc->map->rs->rules;
+
+ pending_len = rk_get_pending_str(cc, NULL, 0);
+ if (pending_len == 0) {
+ return 0;
+ }
+ pending_buf = alloca(pending_len);
+ rk_get_pending_str(cc, pending_buf, pending_len);
+
+ for (i = 0; i < nr_rules; i++) {
+ if (!strcmp(rule[i].lhs, pending_buf)) {
+ const char *res = rule[i].rhs;
+ if (size <= 0) {
+ return strlen(res) + 1;
+ }
+ return snprintf(buf, size, "%s", res);
+ }
+ }
+ return 0;
+}
+
+int
+rk_result(struct rk_conv_context* cc, char* buf, int size)
+{
+ int copy_len;
+
+ if (size <= 0)
+ return cc->cur_str_len;
+ copy_len = (size - 1 < cc->cur_str_len) ? size - 1 : cc->cur_str_len;
+ memcpy(buf, cc->cur_str, copy_len);
+ buf[copy_len] = '\0';
+ if (copy_len < cc->cur_str_len)
+ memmove(cc->cur_str, cc->cur_str + copy_len,
+ cc->cur_str_len - copy_len + 1);
+ cc->cur_str_len -= copy_len;
+
+ return cc->cur_str_len;
+}
+
+struct rk_map*
+rk_select_map(struct rk_conv_context* cc, struct rk_map* map)
+{
+ struct rk_map* old_map;
+
+ cc->old_map_no = cc->map_no;
+ old_map = cc->map;
+ if (old_map) {
+ old_map->refcount--;
+ }
+
+ cc->map = map;
+ if (cc->map == NULL) {
+ cc->cur_state = NULL;
+ } else {
+ map->refcount++;
+ cc->cur_state = map->root_cl;
+ rk_flush(cc);
+ }
+ cc->map_no = -1;
+
+ return old_map;
+}
+
+
+int
+rk_get_pending_str(struct rk_conv_context* cc, char* buf, int size)
+{
+ const char* p, *end;
+ char *q;
+
+ p = (cc->cur_state == NULL) ? "" : cc->cur_state->prefix;
+
+ if (size <= 0)
+ return strlen(p) + 1;
+
+ q = buf;
+ end = buf + size - 1;
+ while (*p && q < end)
+ *q++ = *p++;
+ *q = '\0';
+ return strlen(p);
+}
+
+struct rk_map*
+rk_register_map(struct rk_conv_context* cc, int mapn, struct rk_map* map)
+{
+ struct rk_map* old_map;
+
+ if (mapn < 0 || MAX_MAP_PALETTE <= mapn)
+ return NULL;
+
+ old_map = cc->map_palette[mapn];
+ if (old_map)
+ old_map->refcount--;
+
+ cc->map_palette[mapn] = map;
+ if (map)
+ map->refcount++;
+
+ return old_map;
+}
+
+void
+rk_select_registered_map(struct rk_conv_context* cc, int mapn)
+{
+ if (0 <= mapn && mapn < 0 + MAX_MAP_PALETTE) {
+ rk_select_map(cc, cc->map_palette[mapn]);
+ cc->map_no = mapn;
+ } else {
+ rk_select_map(cc, NULL);
+ cc->map_no = -1;
+ }
+}
+
+int
+rk_selected_map(struct rk_conv_context* cc)
+{
+ return cc->map_no;
+}
+
+/* some utitlity functions to merge rk_rule */
+static int
+rk_rule_length(const struct rk_rule* rules)
+{
+ int i;
+ for (i = 0; rules[i].lhs != NULL; i++);
+ return i;
+}
+
+static int
+rk_my_strcmp(const char *s1, const char *s2)
+{
+ while (*s1 == *s2) {
+ if (!(*s1)) {
+ return 0;
+ }
+ s1++;
+ s2++;
+ }
+ return (*s1) - (*s2);
+}
+
+static int
+rk_rule_compare_func(const void *p, const void *q)
+{
+ const struct rk_rule *r1, *r2;
+ r1 = p;
+ r2 = q;
+ return rk_my_strcmp(r1->lhs, r2->lhs);
+}
+
+/*
+ * ソートされたrk_ruleを作って返す
+ */
+static struct rk_rule *
+rk_sort_rule(const struct rk_rule *src)
+{
+ struct rk_rule* rules;
+ int size = rk_rule_length(src);
+ int i, ret;
+
+ rules = (struct rk_rule*) malloc(sizeof(struct rk_rule) * (size + 1));
+ if (!rules) {
+ return NULL;
+ }
+ for (i = 0; i < size; i++) {
+ ret = rk_rule_copy_to (&src[i], &rules[i]);
+ if (ret == -1) {
+ goto ERROR;
+ }
+ }
+ qsort(rules, size, sizeof(struct rk_rule),
+ rk_rule_compare_func);
+
+ rules[i].lhs = NULL;
+ return rules;
+
+ ERROR:
+ rules[i].lhs = NULL;
+ rk_rules_free(rules);
+ free(rules);
+ return NULL;
+}
+
+/* 一つ目のルールが優先される */
+static struct rk_rule*
+rk_do_merge_rules(const struct rk_rule* r1,
+ const struct rk_rule* r2)
+{
+ int size;
+ int ret;
+ struct rk_rule* rules;
+ struct rk_rule* p, *q;
+ struct rk_rule* r;
+ struct rk_rule* tmp;
+ int i;
+
+ size = rk_rule_length(r1) + rk_rule_length(r2);
+ rules = (struct rk_rule*) malloc(sizeof(struct rk_rule) * (size + 1));
+ if (rules == NULL) {
+ return NULL;
+ }
+
+ r = rules;
+ p = (struct rk_rule *)r1;
+ q = (struct rk_rule *)r2;
+ /* ソート済の列に対してマージソートをする */
+ for (i = 0; i < size; i++) {
+ if (p->lhs && q->lhs) {
+ /* p,qを比較してどちらから取り出すかを選ぶ */
+ ret = rk_my_strcmp(p->lhs, q->lhs);
+ if (ret > 0) {
+ tmp = q;
+ q++;
+ } else if (ret < 0) {
+ tmp = p;
+ p++;
+ } else {
+ /* キーが両方同じなのでqの方を優先する */
+ tmp = q;
+ p++;q++;
+ }
+ } else if (p->lhs) {
+ tmp = p;
+ p++;
+ } else if (q->lhs) {
+ tmp = q;
+ q++;
+ } else {
+ continue;
+ }
+ /* ここまでに選択したものをcopyする */
+ ret = rk_rule_copy_to(tmp, r);
+ if (ret == -1) {
+ r->lhs = NULL;
+ goto ERROR;
+ }
+ r++;
+ }
+ r->lhs = NULL;
+
+ return rules;
+
+ ERROR:
+ rk_rules_free (rules);
+ return NULL;
+}
+
+struct rk_rule*
+rk_merge_rules(const struct rk_rule* r1,
+ const struct rk_rule* r2)
+{
+ struct rk_rule *t1, *t2;
+ struct rk_rule* rules;
+
+ t1 = rk_sort_rule(r1);
+ if (!t1) {
+ return NULL;
+ }
+ t2 = rk_sort_rule(r2);
+ if (!t2) {
+ rk_rules_free(t1);
+ return NULL;
+ }
+ rules = rk_do_merge_rules(t1, t2);
+ rk_rules_free(t1);
+ rk_rules_free(t2);
+ return rules;
+
+}
+
+void
+rk_rules_free(struct rk_rule* rules)
+{
+ struct rk_rule* p;
+
+ for (p = rules; p->lhs != NULL; p++) {
+ free((void *) p->lhs);
+ free((void *) p->rhs);
+ free((void *) p->follow);
+ }
+
+ free(rules);
+}
+
+const char *
+brk_roman_get_previous_pending(struct rk_conv_context *rkctx)
+{
+ struct break_roman *br=rkctx->brk_roman;
+
+ if(!br)
+ return NULL;
+
+ return br->pending[0] ? br->pending : NULL;
+}
+
+int
+brk_roman_get_decided_len(struct rk_conv_context *rkctx)
+{
+ struct break_roman *br=rkctx->brk_roman;
+
+ if(!br)
+ return 0;
+
+ return br->decided_length;
+}
diff --git a/src-util/rkconv.h b/src-util/rkconv.h
new file mode 100644
index 0000000..8220699
--- /dev/null
+++ b/src-util/rkconv.h
@@ -0,0 +1,51 @@
+#ifndef RKCONV_H_INCLUDED
+#define RKCONV_H_INCLUDED
+
+struct rk_map;
+struct rk_rule
+{
+ const char* lhs;
+ const char* rhs;
+ const char* follow;
+};
+struct rk_conv_context;
+
+struct rk_map*
+rk_map_create(const struct rk_rule* rules);
+struct rk_conv_context*
+rk_context_create(int brk);
+struct rk_map*
+rk_select_map(struct rk_conv_context* cc, struct rk_map* map);
+int
+rk_push_key(struct rk_conv_context* cc, int c);
+int
+rk_result(struct rk_conv_context* cc, char* buf, int size);
+void
+rk_context_free(struct rk_conv_context* cc);
+int
+rk_map_free(struct rk_map* map);
+int
+rk_partial_result(struct rk_conv_context* cc, char* buf, int size);
+
+void
+rk_flush(struct rk_conv_context* cc);
+void
+rk_terminate(struct rk_conv_context* cc);
+int
+rk_get_pending_str(struct rk_conv_context* cc, char* buf, int size);
+struct rk_map*
+rk_register_map(struct rk_conv_context* cc, int mapn, struct rk_map* map);
+void
+rk_select_registered_map(struct rk_conv_context* cc, int mapn);
+int
+rk_selected_map(struct rk_conv_context* cc);
+
+struct rk_rule*
+rk_merge_rules(const struct rk_rule* r1, const struct rk_rule* r2);
+void
+rk_rules_free(struct rk_rule* rules);
+
+const char *brk_roman_get_previous_pending(struct rk_conv_context *);
+int brk_roman_get_decided_len(struct rk_conv_context *);
+
+#endif /* RKCONV_H_INCLUDED */
diff --git a/src-util/rkhelper.c b/src-util/rkhelper.c
new file mode 100644
index 0000000..c99bd08
--- /dev/null
+++ b/src-util/rkhelper.c
@@ -0,0 +1,442 @@
+/*
+ * ローマ字から平仮名(正確にはキーの列から文字)の表(rk_map)の
+ * カスタマイズを管理する
+ *
+ * Copyright (C) 2001-2002 UGAWA Tomoharu
+ * Copyright (C) 2002 Tabata Yusuke
+ *
+ * Funded by IPA未踏ソフトウェア創造事業 2001
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include "rkconv.h"
+#include "rkhelper.h"
+
+static const char* rk_default_symbol[128] = {
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ " ", "!", "”", "#", "$", "%", "&", "’",
+ "(", ")", "*", "+", "、", "ー", "。", "/",
+ "0", "1", "2", "3", "4", "5", "6", "7",
+ "8", "9", ":", ";", "<", "=", ">", "?",
+
+ "@", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, "「", "\", "」", "^", "_",
+ "‘", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, "{", "|", "}", "〜", NULL
+};
+
+struct rk_conf_ent {
+ char *lhs;
+ char *rhs;
+ struct rk_conf_ent *next;
+};
+
+struct rk_option {
+ int enable_default;
+ char toggle; /* 英数との一時的な切替えに使うシンボル */
+ /*
+ * 配列はそれぞれリストの先頭になる
+ * リストの先頭は一文字のエントリが入る
+ */
+ struct rk_conf_ent hiragana_symbol[128]; /* ひらがなとの対応 */
+ struct rk_conf_ent katakana_symbol[128]; /* カタカナとの対応 */
+ struct rk_conf_ent hankaku_kana_symbol[128]; /* カタカナとの対応 */
+};
+
+#include "rkmap.h"
+
+struct rk_option *
+anthy_input_create_rk_option()
+{
+ struct rk_option *opt;
+ int i;
+
+ opt = malloc(sizeof(struct rk_option));
+ opt->enable_default = 1;
+ opt->toggle = '/';
+ for (i = 0; i < 128; i++) {
+ opt->hiragana_symbol[i].rhs = NULL;
+ opt->hiragana_symbol[i].lhs = NULL;
+ opt->hiragana_symbol[i].next = NULL;
+ opt->katakana_symbol[i].rhs = NULL;
+ opt->katakana_symbol[i].lhs = NULL;
+ opt->katakana_symbol[i].next = NULL;
+ opt->hankaku_kana_symbol[i].rhs = NULL;
+ opt->hankaku_kana_symbol[i].lhs = NULL;
+ opt->hankaku_kana_symbol[i].next = NULL;
+ }
+ return opt;
+}
+
+int
+anthy_input_free_rk_option(struct rk_option *opt)
+{
+ int err;
+
+ err = anthy_input_do_clear_rk_option(opt, 1);
+ free(opt);
+
+ return err;
+}
+
+static struct rk_conf_ent *
+find_rk_conf_ent(struct rk_option *opt, int map,
+ const char *key, int force)
+{
+ int c = key[0];
+ struct rk_conf_ent *tab = NULL;
+ struct rk_conf_ent *sym = NULL;
+
+ if (c == 0) {
+ return NULL;
+ }
+
+ if (map == RKMAP_HIRAGANA) {
+ tab = opt->hiragana_symbol;
+ }
+ if (map == RKMAP_KATAKANA) {
+ tab = opt->katakana_symbol;
+ }
+ if (map == RKMAP_HANKAKU_KANA) {
+ tab = opt->hankaku_kana_symbol;
+ }
+ if (!tab) {
+ return NULL;
+ }
+ if (strlen(key) == 1) {
+ sym = &tab[c];
+ } else {
+ /* 2文字以上 */
+ for (sym = tab[c].next; sym; sym = sym->next) {
+ if (!strcmp(sym->lhs, key)) {
+ break;
+ }
+ }
+ }
+ if (!sym && force) {
+ /* メモリ確保してつなぐ */
+ sym = malloc(sizeof(struct rk_conf_ent));
+ sym->rhs = NULL;
+ sym->lhs = NULL;
+ sym->next = tab[c].next;
+ tab[c].next = sym;
+ }
+ if (sym && !sym->lhs) {
+ sym->lhs = strdup(key);
+ }
+ return sym;
+}
+
+/*
+ * opt 変更対象のoption
+ * map RKMAP_*
+ * from 変換もとの文字
+ * to 変換先の文字列
+ * follow follow集合
+ */
+int
+anthy_input_do_edit_rk_option(struct rk_option* opt, int map,
+ const char* from, const char* to, const char *follow)
+{
+ struct rk_conf_ent *tab;
+ (void)follow;
+
+ tab = find_rk_conf_ent(opt, map, from, 1);
+ if (!tab) {
+ return -1;
+ }
+
+ if (tab->rhs) {
+ free(tab->rhs);
+ }
+ if (to == NULL) {
+ tab->rhs = NULL;
+ } else {
+ tab->rhs = strdup(to);
+ }
+ return 0;
+}
+
+static void
+free_rk_conf_ent(struct rk_conf_ent *e)
+{
+ if (e->lhs) {
+ free(e->lhs);
+ e->lhs = NULL;
+ }
+ if (e->rhs) {
+ free(e->rhs);
+ e->rhs = NULL;
+ }
+ e->next = NULL;
+}
+
+int
+anthy_input_do_clear_rk_option(struct rk_option* opt,
+ int use_default)
+{
+ int i;
+
+ opt->enable_default = use_default;
+ for (i = 0; i < 128; i++) {
+ /* 各文字に対して */
+ struct rk_conf_ent *tab, *tmp;
+ /* ひらがなのリストを解放 */
+ for (tab = opt->hiragana_symbol[i].next; tab;) {
+ tmp = tab;
+ tab = tab->next;
+ free_rk_conf_ent(tmp);
+ free(tmp);
+ }
+ /* カタカナのリストを解放 */
+ for (tab = opt->katakana_symbol[i].next; tab;) {
+ tmp = tab;
+ tab = tab->next;
+ free_rk_conf_ent(tmp);
+ free(tmp);
+ }
+ /* 先頭の一文字のエントリも忘れずに解放 */
+ free_rk_conf_ent(&opt->katakana_symbol[i]);
+ free_rk_conf_ent(&opt->hiragana_symbol[i]);
+ }
+ return 0;
+}
+
+int
+anthy_input_do_edit_toggle_option(struct rk_option* opt,
+ char toggle)
+{
+ opt->toggle = toggle;
+ return 0;
+}
+
+static void
+rkrule_set(struct rk_rule* r,
+ const char* lhs, const char* rhs, const char* follow)
+{
+ r->lhs = lhs;
+ r->rhs = rhs;
+ r->follow = follow;
+}
+
+struct rk_map*
+make_rkmap_ascii(struct rk_option* opt)
+{
+ struct rk_rule var_part[130];
+ struct rk_rule* complete_rules;
+ struct rk_map* map;
+ struct rk_rule* p;
+ char work[2*128];
+ char* w;
+ int c;
+
+ (void)opt;
+ p = var_part;
+ w = work;
+ for (c = 0; c < 128; c++) {
+ if (rk_default_symbol[c]) {
+ w[0] = c;
+ w[1] = '\0';
+ rkrule_set(p++, w, w, NULL);
+ w += 2;
+ }
+ }
+ p->lhs = NULL;
+
+ complete_rules = rk_merge_rules(rk_rule_alphabet, var_part);
+ map = rk_map_create(complete_rules);
+ rk_rules_free(complete_rules);
+
+ return map;
+}
+
+struct rk_map*
+make_rkmap_wascii(struct rk_option* opt)
+{
+ (void)opt;
+ return rk_map_create(rk_rule_walphabet);
+}
+
+struct rk_map*
+make_rkmap_shiftascii(struct rk_option* opt)
+{
+ struct rk_rule var_part[130];
+ struct rk_rule* complete_rules;
+ struct rk_map* map;
+ struct rk_rule* p;
+ char work[2*128 + 3];
+ char* w;
+ int c;
+ int toggle_char = opt->toggle;
+
+ p = var_part;
+ w = work;
+ for (c = 0; c < 128; c++) {
+ if (rk_default_symbol[c]) {
+ if (c == toggle_char) {
+ /* トグルする文字の場合 */
+ w[0] = c;
+ w[1] = '\0';
+ rkrule_set(p++, w, "\xff" "o", NULL);
+ w[2] = c;
+ w[3] = c;
+ w[4] = '\0';
+ rkrule_set(p++, w + 2, w, NULL);
+ w += 5;
+ } else {
+ /* 普通の文字の場合 */
+ w[0] = c;
+ w[1] = '\0';
+ rkrule_set(p++, w, w, NULL);
+ w += 2;
+ }
+ }
+ }
+ p->lhs = NULL;
+
+ complete_rules = rk_merge_rules(rk_rule_alphabet, var_part);
+ map = rk_map_create(complete_rules);
+ rk_rules_free(complete_rules);
+
+ return map;
+}
+
+static int
+count_rk_rule_ent(struct rk_option *opt, int map_no)
+{
+ int i , c;
+ struct rk_conf_ent *head;
+ struct rk_conf_ent *ent;
+
+ if (map_no == RKMAP_HIRAGANA) {
+ head = opt->hiragana_symbol;
+ } else if (map_no == RKMAP_HANKAKU_KANA) {
+ head = opt->katakana_symbol;
+ } else {
+ head = opt->hankaku_kana_symbol;
+ }
+
+ c = 128;
+ for (i = 0; i < 128; i++) {
+ for (ent = head[i].next; ent; ent = ent->next) {
+ if (ent->lhs) {
+ c++;
+ }
+ }
+ }
+ return c;
+}
+
+/*
+ * デフォルトのルールとカスタマイズされたルールをマージして
+ * rk_mapを作る。
+ */
+static struct rk_map*
+make_rkmap_hirakata(const struct rk_rule* rule,
+ struct rk_option *opt, int map_no)
+{
+ struct rk_conf_ent *tab;
+ struct rk_rule* rk_var_part;
+ struct rk_rule* complete_rules;
+ struct rk_rule* p;
+ struct rk_map* map;
+ int toggle = opt->toggle;
+ char *work;
+ char* w;
+ int c;
+ int nr_rule;
+ char buf[2];
+
+ nr_rule = count_rk_rule_ent(opt, map_no);
+
+ rk_var_part = alloca(sizeof(struct rk_rule) *(nr_rule + 2));
+ work = alloca(2*128 + 8);
+ p = rk_var_part;
+ w = work;
+
+ /* 一文字のものをrk_var_partに書き込んでいく */
+ /* トグルの場合 */
+ buf[0] = toggle;
+ buf[1] = 0;
+ w[0] = toggle;
+ w[1] = '\0';
+ w[2] = '\xff';
+ w[3] = '0' + RKMAP_SHIFT_ASCII;
+ w[4] = '\0';
+ rkrule_set(p++, w, w + 2, NULL);
+ w[5] = toggle;
+ w[6] = toggle;
+ w[7] = '\0';
+ tab = find_rk_conf_ent(opt, map_no, buf, 0);
+ if (tab && tab->rhs) {
+ rkrule_set(p++, w + 5, tab->rhs, NULL);
+ } else {
+ rkrule_set(p++, w + 5, rk_default_symbol[toggle], NULL);
+ }
+ w += 8;
+ /* トグル以外 */
+ for (c = 0; c < 128; c++) {
+ if (c != toggle) {
+ buf[0] = c;
+ buf[1] = 0;
+ /* 一文字のもの */
+ w[0] = c;
+ w[1] = '\0';
+ tab = find_rk_conf_ent(opt, map_no, buf, 0);
+ if (tab && tab->rhs) {
+ /* カスタマイズ済のがある */
+ rkrule_set(p++, w, tab->rhs, NULL);
+ } else if (rk_default_symbol[c]) {
+ /* 記号など */
+ rkrule_set(p++, w, rk_default_symbol[c], NULL);
+ }
+ w += 2;
+ /* 二文字以上のもの */
+ if (tab) {
+ for (tab = tab->next; tab; tab = tab->next) {
+ rkrule_set(p++, tab->lhs, tab->rhs, NULL);
+ }
+ }
+ }
+ }
+ p->lhs = NULL;
+
+ if (opt->enable_default) {
+ complete_rules = rk_merge_rules(rule, rk_var_part);
+ map = rk_map_create(complete_rules);
+ rk_rules_free(complete_rules);
+ } else {
+ map = rk_map_create(rk_var_part);
+ }
+
+ return map;
+}
+
+struct rk_map*
+make_rkmap_hiragana(struct rk_option* opt)
+{
+ return make_rkmap_hirakata(rk_rule_hiragana,
+ opt, RKMAP_HIRAGANA);
+}
+
+struct rk_map*
+make_rkmap_katakana(struct rk_option* opt)
+{
+ return make_rkmap_hirakata(rk_rule_katakana,
+ opt, RKMAP_KATAKANA);
+}
+
+struct rk_map *
+make_rkmap_hankaku_kana(struct rk_option *opt)
+{
+ return make_rkmap_hirakata(rk_rule_hankaku_kana,
+ opt, RKMAP_HANKAKU_KANA);
+}
diff --git a/src-util/rkhelper.h b/src-util/rkhelper.h
new file mode 100644
index 0000000..2e4d491
--- /dev/null
+++ b/src-util/rkhelper.h
@@ -0,0 +1,41 @@
+/*
+ * Funded by IPA未踏ソフトウェア創造事業 2001
+ * Copyright (C) 2001-2002 UGAWA Tomoharu
+ */
+
+#ifndef RKHELPER_H_INCLUDE
+#define RKHELPER_H_INCLUDE
+
+#define RKOPT_US 0
+#define RKOPT_JP 1
+
+enum {
+ RKMAP_ASCII, RKMAP_SHIFT_ASCII,
+ RKMAP_HIRAGANA, RKMAP_KATAKANA,
+ RKMAP_WASCII, RKMAP_HANKAKU_KANA,
+ NR_RKMAP
+};
+
+#define RK_OPTION_SYMBOL 0
+#define RK_OPTION_TOGGLE 1
+#define RK_OPTION_ERROR -1
+
+struct rk_option;
+
+/* rk_optionの初期化と変更 */
+struct rk_option *anthy_input_create_rk_option(void);
+int anthy_input_free_rk_option(struct rk_option *opt);
+int anthy_input_do_edit_rk_option(struct rk_option* opt, int map,
+ const char* from, const char* to, const char *follow);
+int anthy_input_do_edit_toggle_option(struct rk_option *opt, char toggle);
+int anthy_input_do_clear_rk_option(struct rk_option *opt, int enable_default);
+
+/* rk_mapの生成 */
+struct rk_map* make_rkmap_ascii(struct rk_option* opt);
+struct rk_map* make_rkmap_wascii(struct rk_option* opt);
+struct rk_map* make_rkmap_shiftascii(struct rk_option* opt);
+struct rk_map* make_rkmap_hiragana(struct rk_option* opt);
+struct rk_map* make_rkmap_katakana(struct rk_option* opt);
+struct rk_map* make_rkmap_hankaku_kana(struct rk_option* opt);
+
+#endif /* RKHELPER_H_INCLUDE */
diff --git a/src-util/rkmap.h b/src-util/rkmap.h
new file mode 100644
index 0000000..487e735
--- /dev/null
+++ b/src-util/rkmap.h
@@ -0,0 +1,954 @@
+/*
+ * roma kana converter rule structure
+ *
+ * $Id: rkmap.h,v 1.6 2002/11/05 15:38:58 yusuke Exp $
+ */
+
+static const struct rk_rule rk_rule_alphabet[] =
+{
+ {"a", "a", NULL},
+ {"b", "b", NULL},
+ {"c", "c", NULL},
+ {"d", "d", NULL},
+ {"e", "e", NULL},
+ {"f", "f", NULL},
+ {"g", "g", NULL},
+ {"h", "h", NULL},
+ {"i", "i", NULL},
+ {"j", "j", NULL},
+ {"k", "k", NULL},
+ {"l", "l", NULL},
+ {"m", "m", NULL},
+ {"n", "n", NULL},
+ {"o", "o", NULL},
+ {"p", "p", NULL},
+ {"q", "q", NULL},
+ {"r", "r", NULL},
+ {"s", "s", NULL},
+ {"t", "t", NULL},
+ {"u", "u", NULL},
+ {"v", "v", NULL},
+ {"w", "w", NULL},
+ {"x", "x", NULL},
+ {"y", "y", NULL},
+ {"z", "z", NULL},
+ {"A", "A", NULL},
+ {"B", "B", NULL},
+ {"C", "C", NULL},
+ {"D", "D", NULL},
+ {"E", "E", NULL},
+ {"F", "F", NULL},
+ {"G", "G", NULL},
+ {"H", "H", NULL},
+ {"I", "I", NULL},
+ {"J", "J", NULL},
+ {"K", "K", NULL},
+ {"L", "L", NULL},
+ {"M", "M", NULL},
+ {"N", "N", NULL},
+ {"O", "O", NULL},
+ {"P", "P", NULL},
+ {"Q", "Q", NULL},
+ {"R", "R", NULL},
+ {"S", "S", NULL},
+ {"T", "T", NULL},
+ {"U", "U", NULL},
+ {"V", "V", NULL},
+ {"W", "W", NULL},
+ {"X", "X", NULL},
+ {"Y", "Y", NULL},
+ {"Z", "Z", NULL},
+
+ {NULL, NULL, NULL}
+};
+
+static const struct rk_rule rk_rule_walphabet[] =
+{
+ {"a", "a", NULL},
+ {"b", "b", NULL},
+ {"c", "c", NULL},
+ {"d", "d", NULL},
+ {"e", "e", NULL},
+ {"f", "f", NULL},
+ {"g", "g", NULL},
+ {"h", "h", NULL},
+ {"i", "i", NULL},
+ {"j", "j", NULL},
+ {"k", "k", NULL},
+ {"l", "l", NULL},
+ {"m", "m", NULL},
+ {"n", "n", NULL},
+ {"o", "o", NULL},
+ {"p", "p", NULL},
+ {"q", "q", NULL},
+ {"r", "r", NULL},
+ {"s", "s", NULL},
+ {"t", "t", NULL},
+ {"u", "u", NULL},
+ {"v", "v", NULL},
+ {"w", "w", NULL},
+ {"x", "x", NULL},
+ {"y", "y", NULL},
+ {"z", "z", NULL},
+ {"A", "A", NULL},
+ {"B", "B", NULL},
+ {"C", "C", NULL},
+ {"D", "D", NULL},
+ {"E", "E", NULL},
+ {"F", "F", NULL},
+ {"G", "G", NULL},
+ {"H", "H", NULL},
+ {"I", "I", NULL},
+ {"J", "J", NULL},
+ {"K", "K", NULL},
+ {"L", "L", NULL},
+ {"M", "M", NULL},
+ {"N", "N", NULL},
+ {"O", "O", NULL},
+ {"P", "P", NULL},
+ {"Q", "Q", NULL},
+ {"R", "R", NULL},
+ {"S", "S", NULL},
+ {"T", "T", NULL},
+ {"U", "U", NULL},
+ {"V", "V", NULL},
+ {"W", "W", NULL},
+ {"X", "X", NULL},
+ {"Y", "Y", NULL},
+ {"Z", "Z", NULL},
+
+ {NULL, NULL, NULL}
+};
+
+#define SKK_LIKE_KIGO_MAP \
+ {"z/", "・", NULL}, \
+ {"z[", "「", NULL}, \
+ {"z]", "」", NULL}, \
+ {"z,", "‥", NULL}, \
+ {"z.", "…", NULL}, \
+ {"z-", "〜", NULL}, \
+ {"zh", "←", NULL}, \
+ {"zj", "↓", NULL}, \
+ {"zk", "↑", NULL}, \
+ {"zl", "→", NULL}
+
+static const struct rk_rule rk_rule_hiragana[] =
+{
+ SKK_LIKE_KIGO_MAP,
+
+ {"a", "あ", NULL},
+ {"i", "い", NULL},
+ {"u", "う", NULL},
+ {"e", "え", NULL},
+ {"o", "お", NULL},
+
+ {"xa", "ぁ", NULL},
+ {"xi", "ぃ", NULL},
+ {"xu", "ぅ", NULL},
+ {"xe", "ぇ", NULL},
+ {"xo", "ぉ", NULL},
+
+ {"ka", "か", NULL},
+ {"ki", "き", NULL},
+ {"ku", "く", NULL},
+ {"ke", "け", NULL},
+ {"ko", "こ", NULL},
+
+ {"kya", "きゃ", NULL},
+ {"kyi", "きぃ", NULL},
+ {"kyu", "きゅ", NULL},
+ {"kye", "きぇ", NULL},
+ {"kyo", "きょ", NULL},
+
+ {"k", "っ", "k"},
+
+ {"ga", "が", NULL},
+ {"gi", "ぎ", NULL},
+ {"gu", "ぐ", NULL},
+ {"ge", "げ", NULL},
+ {"go", "ご", NULL},
+
+ {"gya", "ぎゃ", NULL},
+ {"gyi", "ぎぃ", NULL},
+ {"gyu", "ぎゅ", NULL},
+ {"gye", "ぎぇ", NULL},
+ {"gyo", "ぎょ", NULL},
+
+ {"g", "っ", "g"},
+
+ {"sa", "さ", NULL},
+ {"si", "し", NULL},
+ {"su", "す", NULL},
+ {"se", "せ", NULL},
+ {"so", "そ", NULL},
+
+ {"sya", "しゃ", NULL},
+ {"syi", "しぃ", NULL},
+ {"syu", "しゅ", NULL},
+ {"sye", "しぇ", NULL},
+ {"syo", "しょ", NULL},
+
+ {"sha", "しゃ", NULL},
+ {"shi", "し", NULL},
+ {"shu", "しゅ", NULL},
+ {"she", "しぇ", NULL},
+ {"sho", "しょ", NULL},
+
+ {"s", "っ", "s"},
+
+ {"za", "ざ", NULL},
+ {"zi", "じ", NULL},
+ {"zu", "ず", NULL},
+ {"ze", "ぜ", NULL},
+ {"zo", "ぞ", NULL},
+
+ {"zya", "じゃ", NULL},
+ {"zyi", "じぃ", NULL},
+ {"zyu", "じゅ", NULL},
+ {"zye", "じぇ", NULL},
+ {"zyo", "じょ", NULL},
+
+ {"z", "っ", "z"},
+
+ {"ja", "じゃ", NULL},
+ {"ji", "じ", NULL},
+ {"ju", "じゅ", NULL},
+ {"je", "じぇ", NULL},
+ {"jo", "じょ", NULL},
+
+ {"jya", "じゃ", NULL},
+ {"jyi", "じぃ", NULL},
+ {"jyu", "じゅ", NULL},
+ {"jye", "じぇ", NULL},
+ {"jyo", "じょ", NULL},
+
+ {"j", "っ", "j"},
+
+ {"ta", "た", NULL},
+ {"ti", "ち", NULL},
+ {"tu", "つ", NULL},
+ {"te", "て", NULL},
+ {"to", "と", NULL},
+ {"t.", "t", NULL}, /* 最新版の alt-cannadic の単漢字辞書への対応 */
+
+ {"tya", "ちゃ", NULL},
+ {"tyi", "ちぃ", NULL},
+ {"tyu", "ちゅ", NULL},
+ {"tye", "ちぇ", NULL},
+ {"tyo", "ちょ", NULL},
+
+ {"tha", "てぁ", NULL},
+ {"thi", "てぃ", NULL},
+ {"thu", "てゅ", NULL},
+ {"the", "てぇ", NULL},
+ {"tho", "てょ", NULL},
+
+ {"t", "っ", "tc"},
+
+ {"cha", "ちゃ", NULL},
+ {"chi", "ち", NULL},
+ {"chu", "ちゅ", NULL},
+ {"che", "ちぇ", NULL},
+ {"cho", "ちょ", NULL},
+
+ {"tsu", "つ", NULL},
+ {"xtu", "っ", NULL},
+ {"xtsu", "っ", NULL},
+
+ {"c", "っ", "c"},
+
+ {"da", "だ", NULL},
+ {"di", "ぢ", NULL},
+ {"du", "づ", NULL},
+ {"de", "で", NULL},
+ {"do", "ど", NULL},
+
+ {"dya", "ぢゃ", NULL},
+ {"dyi", "ぢぃ", NULL},
+ {"dyu", "ぢゅ", NULL},
+ {"dye", "ぢぇ", NULL},
+ {"dyo", "ぢょ", NULL},
+
+ {"dha", "でゃ", NULL},
+ {"dhi", "でぃ", NULL},
+ {"dhu", "でゅ", NULL},
+ {"dhe", "でぇ", NULL},
+ {"dho", "でょ", NULL},
+
+ {"d", "っ", "d"},
+
+ {"na", "な", NULL},
+ {"ni", "に", NULL},
+ {"nu", "ぬ", NULL},
+ {"ne", "ね", NULL},
+ {"no", "の", NULL},
+
+ {"nya", "にゃ", NULL},
+ {"nyi", "にぃ", NULL},
+ {"nyu", "にゅ", NULL},
+ {"nye", "にぇ", NULL},
+ {"nyo", "にょ", NULL},
+
+ {"n", "ん", NULL},
+ {"nn", "ん", NULL},
+
+ {"ha", "は", NULL},
+ {"hi", "ひ", NULL},
+ {"hu", "ふ", NULL},
+ {"he", "へ", NULL},
+ {"ho", "ほ", NULL},
+
+ {"hya", "ひゃ", NULL},
+ {"hyi", "ひぃ", NULL},
+ {"hyu", "ひゅ", NULL},
+ {"hye", "ひぇ", NULL},
+ {"hyo", "ひょ", NULL},
+
+ {"h", "っ", "h"},
+
+ {"fa", "ふぁ", NULL},
+ {"fi", "ふぃ", NULL},
+ {"fu", "ふ", NULL},
+ {"fe", "ふぇ", NULL},
+ {"fo", "ふぉ", NULL},
+
+ {"fya", "ふゃ", NULL},
+ {"fyi", "ふぃ", NULL},
+ {"fyu", "ふゅ", NULL},
+ {"fye", "ふぇ", NULL},
+ {"fyo", "ふょ", NULL},
+
+ {"f", "っ", "f"},
+
+ {"ba", "ば", NULL},
+ {"bi", "び", NULL},
+ {"bu", "ぶ", NULL},
+ {"be", "べ", NULL},
+ {"bo", "ぼ", NULL},
+
+ {"bya", "びゃ", NULL},
+ {"byi", "びぃ", NULL},
+ {"byu", "びゅ", NULL},
+ {"bye", "びぇ", NULL},
+ {"byo", "びょ", NULL},
+
+ {"b", "っ", "b" },
+
+ {"pa", "ぱ", NULL},
+ {"pi", "ぴ", NULL},
+ {"pu", "ぷ", NULL},
+ {"pe", "ぺ", NULL},
+ {"po", "ぽ", NULL},
+
+ {"pya", "ぴゃ", NULL},
+ {"pyi", "ぴぃ", NULL},
+ {"pyu", "ぴゅ", NULL},
+ {"pye", "ぴぇ", NULL},
+ {"pyo", "ぴょ", NULL},
+
+ {"p", "っ", "p"},
+
+ {"ma", "ま", NULL},
+ {"mi", "み", NULL},
+ {"mu", "む", NULL},
+ {"me", "め", NULL},
+ {"mo", "も", NULL},
+
+ {"mya", "みゃ", NULL},
+ {"myi", "みぃ", NULL},
+ {"myu", "みゅ", NULL},
+ {"mye", "みぇ", NULL},
+ {"myo", "みょ", NULL},
+
+ {"m", "ん", "bp"},
+ {"m", "っ", "m"},
+
+ {"y", "っ", "y"},
+ {"ya", "や", NULL},
+ {"yu", "ゆ", NULL},
+ {"yo", "よ", NULL},
+
+ {"xya", "ゃ", NULL},
+ {"xyu", "ゅ", NULL},
+ {"xyo", "ょ", NULL},
+
+ {"r", "っ", "r"},
+ {"ra", "ら", NULL},
+ {"ri", "り", NULL},
+ {"ru", "る", NULL},
+ {"re", "れ", NULL},
+ {"ro", "ろ", NULL},
+
+ {"rya", "りゃ", NULL},
+ {"ryi", "りぃ", NULL},
+ {"ryu", "りゅ", NULL},
+ {"rye", "りぇ", NULL},
+ {"ryo", "りょ", NULL},
+
+ {"xwa", "ゎ", NULL},
+ {"wa", "わ", NULL},
+ {"wi", "うぃ", NULL},
+ {"xwi", "ゐ", NULL},
+ {"we", "うぇ", NULL},
+ {"xwe", "ゑ", NULL},
+ {"wo", "を", NULL},
+
+ {"va", "う゛ぁ", NULL},
+ {"vi", "う゛ぃ", NULL},
+ {"vu", "う゛", NULL},
+ {"ve", "う゛ぇ", NULL},
+ {"vo", "う゛ぉ", NULL},
+
+ {"VA", "ヴァ", NULL}, /* Debian系由来?の「ヴ」パッチの動作試験用 */
+ {"VI", "ヴィ", NULL},
+ {"VU", "ヴ", NULL},
+ {"VE", "ヴェ", NULL},
+ {"VO", "ヴォ", NULL},
+
+ {NULL, NULL, NULL}
+};
+
+static const struct rk_rule rk_rule_katakana[] =
+{
+ SKK_LIKE_KIGO_MAP,
+
+ {"a", "ア", NULL},
+ {"i", "イ", NULL},
+ {"u", "ウ", NULL},
+ {"e", "エ", NULL},
+ {"o", "オ", NULL},
+
+ {"xa", "ァ", NULL},
+ {"xi", "ィ", NULL},
+ {"xu", "ゥ", NULL},
+ {"xe", "ェ", NULL},
+ {"xo", "ォ", NULL},
+
+ {"ka", "カ", NULL},
+ {"ki", "キ", NULL},
+ {"ku", "ク", NULL},
+ {"ke", "ケ", NULL},
+ {"ko", "コ", NULL},
+
+ {"kya", "キャ", NULL},
+ {"kyi", "キィ", NULL},
+ {"kyu", "キュ", NULL},
+ {"kye", "キェ", NULL},
+ {"kyo", "キョ", NULL},
+
+ {"k", "ッ", "k"},
+
+ {"ga", "ガ", NULL},
+ {"gi", "ギ", NULL},
+ {"gu", "グ", NULL},
+ {"ge", "ゲ", NULL},
+ {"go", "ゴ", NULL},
+
+ {"gya", "ギャ", NULL},
+ {"gyi", "ギィ", NULL},
+ {"gyu", "ギュ", NULL},
+ {"gye", "ギェ", NULL},
+ {"gyo", "ギョ", NULL},
+
+ {"g", "ッ", "g"},
+
+ {"sa", "サ", NULL},
+ {"si", "シ", NULL},
+ {"su", "ス", NULL},
+ {"se", "セ", NULL},
+ {"so", "ソ", NULL},
+
+ {"sya", "シャ", NULL},
+ {"syi", "シィ", NULL},
+ {"syu", "シュ", NULL},
+ {"sye", "シェ", NULL},
+ {"syo", "ショ", NULL},
+
+ {"sha", "シャ", NULL},
+ {"shi", "シ", NULL},
+ {"shu", "シュ", NULL},
+ {"she", "シェ", NULL},
+ {"sho", "ショ", NULL},
+
+ {"s", "ッ", "s"},
+
+ {"za", "ザ", NULL},
+ {"zi", "ジ", NULL},
+ {"zu", "ズ", NULL},
+ {"ze", "ゼ", NULL},
+ {"zo", "ゾ", NULL},
+
+ {"zya", "ジャ", NULL},
+ {"zyi", "ジィ", NULL},
+ {"zyu", "ジュ", NULL},
+ {"zye", "ジェ", NULL},
+ {"zyo", "ジョ", NULL},
+
+ {"z", "ッ", "z"},
+
+ {"ja", "ジャ", NULL},
+ {"ji", "ジ", NULL},
+ {"ju", "ジュ", NULL},
+ {"je", "ジェ", NULL},
+ {"jo", "ジョ", NULL},
+
+ {"jya", "ジャ", NULL},
+ {"jyi", "ジィ", NULL},
+ {"jyu", "ジュ", NULL},
+ {"jye", "ジェ", NULL},
+ {"jyo", "ジョ", NULL},
+
+ {"j", "ッ", "j"},
+
+ {"ta", "タ", NULL},
+ {"ti", "チ", NULL},
+ {"tu", "ツ", NULL},
+ {"te", "テ", NULL},
+ {"to", "ト", NULL},
+ {"t.", "t", NULL}, /* 最新版の alt-cannadic の単漢字辞書への対応 */
+
+ {"tya", "チャ", NULL},
+ {"tyi", "チィ", NULL},
+ {"tyu", "チュ", NULL},
+ {"tye", "チェ", NULL},
+ {"tyo", "チョ", NULL},
+
+ {"tha", "テァ", NULL},
+ {"thi", "ティ", NULL},
+ {"thu", "テュ", NULL},
+ {"the", "テェ", NULL},
+ {"tho", "テョ", NULL},
+
+ {"t", "ッ", "tc"},
+
+ {"cha", "チャ", NULL},
+ {"chi", "チ", NULL},
+ {"chu", "チュ", NULL},
+ {"che", "チェ", NULL},
+ {"cho", "チョ", NULL},
+
+ {"tsu", "ツ", NULL},
+ {"xtu", "ッ", NULL},
+ {"xtsu", "ッ", NULL},
+
+ {"c", "ッ", "c"},
+
+ {"da", "ダ", NULL},
+ {"di", "ヂ", NULL},
+ {"du", "ヅ", NULL},
+ {"de", "デ", NULL},
+ {"do", "ド", NULL},
+
+ {"dya", "ヂャ", NULL},
+ {"dyi", "ヂィ", NULL},
+ {"dyu", "ヂュ", NULL},
+ {"dye", "ヂェ", NULL},
+ {"dyo", "ヂョ", NULL},
+
+ {"dha", "デャ", NULL},
+ {"dhi", "ディ", NULL},
+ {"dhu", "デュ", NULL},
+ {"dhe", "デェ", NULL},
+ {"dho", "デョ", NULL},
+
+ {"d", "ッ", "d"},
+
+ {"na", "ナ", NULL},
+ {"ni", "ニ", NULL},
+ {"nu", "ヌ", NULL},
+ {"ne", "ネ", NULL},
+ {"no", "ノ", NULL},
+
+ {"nya", "ニャ", NULL},
+ {"nyi", "ニィ", NULL},
+ {"nyu", "ニュ", NULL},
+ {"nye", "ニェ", NULL},
+ {"nyo", "ニョ", NULL},
+
+ {"n", "ン", NULL},
+ {"nn", "ン", NULL},
+
+ {"ha", "ハ", NULL},
+ {"hi", "ヒ", NULL},
+ {"hu", "フ", NULL},
+ {"he", "ヘ", NULL},
+ {"ho", "ホ", NULL},
+
+ {"hya", "ヒャ", NULL},
+ {"hyi", "ヒィ", NULL},
+ {"hyu", "ヒュ", NULL},
+ {"hye", "ヒェ", NULL},
+ {"hyo", "ヒョ", NULL},
+
+ {"h", "ッ", "h"},
+
+ {"fa", "ファ", NULL},
+ {"fi", "フィ", NULL},
+ {"fu", "フ", NULL},
+ {"fe", "フェ", NULL},
+ {"fo", "フォ", NULL},
+
+ {"fya", "フャ", NULL},
+ {"fyi", "フィ", NULL},
+ {"fyu", "フュ", NULL},
+ {"fye", "フェ", NULL},
+ {"fyo", "フョ", NULL},
+
+ {"f", "ッ", "f"},
+
+ {"ba", "バ", NULL},
+ {"bi", "ビ", NULL},
+ {"bu", "ブ", NULL},
+ {"be", "ベ", NULL},
+ {"bo", "ボ", NULL},
+
+ {"bya", "ビャ", NULL},
+ {"byi", "ビィ", NULL},
+ {"byu", "ビュ", NULL},
+ {"bye", "ビェ", NULL},
+ {"byo", "ビョ", NULL},
+
+ {"b", "ッ", NULL},
+
+ {"pa", "パ", NULL},
+ {"pi", "ピ", NULL},
+ {"pu", "プ", NULL},
+ {"pe", "ペ", NULL},
+ {"po", "ポ", NULL},
+
+ {"pya", "ピャ", NULL},
+ {"pyi", "ピィ", NULL},
+ {"pyu", "ピュ", NULL},
+ {"pye", "ピェ", NULL},
+ {"pyo", "ピョ", NULL},
+
+ {"p", "ッ", "p"},
+
+ {"ma", "マ", NULL},
+ {"mi", "ミ", NULL},
+ {"mu", "ム", NULL},
+ {"me", "メ", NULL},
+ {"mo", "モ", NULL},
+
+ {"mya", "ミャ", NULL},
+ {"myi", "ミィ", NULL},
+ {"myu", "ミュ", NULL},
+ {"mye", "ミェ", NULL},
+ {"myo", "ミョ", NULL},
+
+ {"m", "ン", "bp"},
+
+ {"y", "ッ", "y"},
+ {"ya", "ヤ", NULL},
+ {"yu", "ユ", NULL},
+ {"yo", "ヨ", NULL},
+
+ {"xya", "ャ", NULL},
+ {"xyu", "ュ", NULL},
+ {"xyo", "ョ", NULL},
+
+ {"r", "ッ", "r"},
+ {"ra", "ラ", NULL},
+ {"ri", "リ", NULL},
+ {"ru", "ル", NULL},
+ {"re", "レ", NULL},
+ {"ro", "ロ", NULL},
+
+ {"rya", "リャ", NULL},
+ {"ryi", "リィ", NULL},
+ {"ryu", "リュ", NULL},
+ {"rye", "リェ", NULL},
+ {"ryo", "リョ", NULL},
+
+ {"xwa", "ヮ", NULL},
+ {"wa", "ワ", NULL},
+ {"wi", "ウィ", NULL},
+ {"xwi", "ヰ", NULL},
+ {"we", "ウェ", NULL},
+ {"xwe", "ヱ", NULL},
+ {"wo", "ヲ", NULL},
+
+ {"va", "ヴァ", NULL},
+ {"vi", "ヴィ", NULL},
+ {"vu", "ヴ", NULL},
+ {"ve", "ヴェ", NULL},
+ {"vo", "ヴォ", NULL},
+
+ {NULL, NULL, NULL}
+};
+
+static const struct rk_rule rk_rule_hankaku_kana[] =
+{
+ SKK_LIKE_KIGO_MAP,
+
+ {"a", "ア", NULL},
+ {"i", "イ", NULL},
+ {"u", "ウ", NULL},
+ {"e", "エ", NULL},
+ {"o", "オ", NULL},
+
+ {"xa", "ァ", NULL},
+ {"xi", "ィ", NULL},
+ {"xu", "ゥ", NULL},
+ {"xe", "ェ", NULL},
+ {"xo", "ォ", NULL},
+
+ {"ka", "カ", NULL},
+ {"ki", "キ", NULL},
+ {"ku", "ク", NULL},
+ {"ke", "ケ", NULL},
+ {"ko", "コ", NULL},
+
+ {"kya", "キャ", NULL},
+ {"kyi", "kイ", NULL},
+ {"kyu", "キュ", NULL},
+ {"kye", "キェ", NULL},
+ {"kyo", "キョ", NULL},
+
+ {"k", "ッ", "k"},
+
+ {"ga", "ガ", NULL},
+ {"gi", "ギ", NULL},
+ {"gu", "グ", NULL},
+ {"ge", "ゲ", NULL},
+ {"go", "ゴ", NULL},
+
+ {"gya", "ギャ", NULL},
+ {"gyi", "ギィ", NULL},
+ {"gyu", "ギュ", NULL},
+ {"gye", "ギェ", NULL},
+ {"gyo", "ギョ", NULL},
+
+ {"g", "ッ", "g"},
+
+ {"sa", "サ", NULL},
+ {"si", "シ", NULL},
+ {"su", "ス", NULL},
+ {"se", "セ", NULL},
+ {"so", "ソ", NULL},
+
+ {"sya", "シャ", NULL},
+ {"syi", "シィ", NULL},
+ {"syu", "シュ", NULL},
+ {"sye", "シェ", NULL},
+ {"syo", "ショ", NULL},
+
+ {"sha", "シャ", NULL},
+ {"shi", "シ", NULL},
+ {"shu", "シュ", NULL},
+ {"she", "シェ", NULL},
+ {"sho", "ショ", NULL},
+
+ {"s", "ッ", "s"},
+
+ {"za", "ザ", NULL},
+ {"zi", "ジ", NULL},
+ {"zu", "ズ", NULL},
+ {"ze", "ゼ", NULL},
+ {"zo", "ゾ", NULL},
+
+ {"zya", "ジャ", NULL},
+ {"zyi", "ジィ", NULL},
+ {"zyu", "ジュ", NULL},
+ {"zye", "ジェ", NULL},
+ {"zyo", "ジョ", NULL},
+
+ {"z", "ッ", "z"},
+
+ {"ja", "ジャ", NULL},
+ {"ji", "ジ", NULL},
+ {"ju", "ジュ", NULL},
+ {"je", "ジェ", NULL},
+ {"jo", "ジョ", NULL},
+
+ {"jya", "ジャ", NULL},
+ {"jyi", "ジィ", NULL},
+ {"jyu", "ジュ", NULL},
+ {"jye", "ジェ", NULL},
+ {"jyo", "ジョ", NULL},
+
+ {"j", "ッ", "j"},
+
+ {"ta", "タ", NULL},
+ {"ti", "チ", NULL},
+ {"tu", "ツ", NULL},
+ {"te", "テ", NULL},
+ {"to", "ト", NULL},
+ {"t.", "t", NULL}, /* 最新版の alt-cannadic の単漢字辞書への対応 */
+
+ {"tya", "チャ", NULL},
+ {"tyi", "チィ", NULL},
+ {"tyu", "チュ", NULL},
+ {"tye", "チェ", NULL},
+ {"tyo", "チョ", NULL},
+
+ {"tha", "テァ", NULL},
+ {"thi", "ティ", NULL},
+ {"thu", "チュ", NULL},
+ {"the", "チェ", NULL},
+ {"tho", "チョ", NULL},
+
+ {"t", "ッ", "tc"},
+
+ {"cha", "チャ", NULL},
+ {"chi", "チ", NULL},
+ {"chu", "チュ", NULL},
+ {"che", "チェ", NULL},
+ {"cho", "チョ", NULL},
+
+ {"tsu", "ツ", NULL},
+ {"xtu", "ッ", NULL},
+ {"xtsu", "ッ", NULL},
+
+ {"c", "ッ", "c"},
+
+ {"da", "ダ", NULL},
+ {"di", "ヂ", NULL},
+ {"du", "ヅ", NULL},
+ {"de", "デ", NULL},
+ {"do", "ド", NULL},
+
+ {"dya", "ヂャ", NULL},
+ {"dyi", "ヂィ", NULL},
+ {"dyu", "ヂゥ", NULL},
+ {"dye", "ヂェ", NULL},
+ {"dyo", "ヂョ", NULL},
+
+ {"dha", "デャ", NULL},
+ {"dhi", "ディ", NULL},
+ {"dhu", "デュ", NULL},
+ {"dhe", "デェ", NULL},
+ {"dho", "デョ", NULL},
+
+ {"d", "ッ", "d"},
+
+ {"na", "ナ", NULL},
+ {"ni", "ニ", NULL},
+ {"nu", "ヌ", NULL},
+ {"ne", "ネ", NULL},
+ {"no", "ノ", NULL},
+
+ {"nya", "ニャ", NULL},
+ {"nyi", "ニィ", NULL},
+ {"nyu", "ニュ", NULL},
+ {"nye", "ニェ", NULL},
+ {"nyo", "ニョ", NULL},
+
+ {"n", "ン", NULL},
+ {"nn", "ン", NULL},
+
+ {"ha", "ハ", NULL},
+ {"hi", "ヒ", NULL},
+ {"hu", "フ", NULL},
+ {"he", "ヘ", NULL},
+ {"ho", "ホ", NULL},
+
+ {"hya", "ヒャ", NULL},
+ {"hyi", "ヒィ", NULL},
+ {"hyu", "ヒュ", NULL},
+ {"hye", "ヒェ", NULL},
+ {"hyo", "ヒョ", NULL},
+
+ {"h", "ッ", "h"},
+
+ {"fa", "ファ", NULL},
+ {"fi", "フィ", NULL},
+ {"fu", "フ", NULL},
+ {"fe", "フェ", NULL},
+ {"fo", "フォ", NULL},
+
+ {"fya", "フャ", NULL},
+ {"fyi", "フィ", NULL},
+ {"fyu", "フュ", NULL},
+ {"fye", "フェ", NULL},
+ {"fyo", "フョ", NULL},
+
+ {"f", "ッ", "f"},
+
+ {"ba", "バ", NULL},
+ {"bi", "ビ", NULL},
+ {"bu", "ブ", NULL},
+ {"be", "ベ", NULL},
+ {"bo", "ボ", NULL},
+
+ {"bya", "ビャ", NULL},
+ {"byi", "ビィ", NULL},
+ {"byu", "ビュ", NULL},
+ {"bye", "ビェ", NULL},
+ {"byo", "ビョ", NULL},
+
+ {"b", "ッ", NULL},
+
+ {"pa", "パ", NULL},
+ {"pi", "ピ", NULL},
+ {"pu", "プ", NULL},
+ {"pe", "ペ", NULL},
+ {"po", "ポ", NULL},
+
+ {"pya", "ピャ", NULL},
+ {"pyi", "ピィ", NULL},
+ {"pyu", "ピュ", NULL},
+ {"pye", "ピェ", NULL},
+ {"pyo", "ピョ", NULL},
+
+ {"p", "ッ", "p"},
+
+ {"ma", "マ", NULL},
+ {"mi", "ミ", NULL},
+ {"mu", "ム", NULL},
+ {"me", "メ", NULL},
+ {"mo", "モ", NULL},
+
+ {"mya", "ミャ", NULL},
+ {"myi", "ミィ", NULL},
+ {"myu", "ミュ", NULL},
+ {"mye", "ミェ", NULL},
+ {"myo", "ミョ", NULL},
+
+ {"m", "ン", "bp"},
+
+ {"y", "ッ", "y"},
+ {"ya", "ヤ", NULL},
+ {"yu", "ユ", NULL},
+ {"yo", "ヨ", NULL},
+
+ {"xya", "ャ", NULL},
+ {"xyu", "ュ", NULL},
+ {"xyo", "ョ", NULL},
+
+ {"r", "ッ", "r"},
+ {"ra", "ラ", NULL},
+ {"ri", "リ", NULL},
+ {"ru", "ル", NULL},
+ {"re", "レ", NULL},
+ {"ro", "ロ", NULL},
+
+ {"rya", "リャ", NULL},
+ {"ryi", "リィ", NULL},
+ {"ryu", "リュ", NULL},
+ {"rye", "リェ", NULL},
+ {"ryo", "リョ", NULL},
+
+ {"xwa", "ワ", NULL},
+ {"wa", "ワ", NULL},
+ {"wi", "ウィ", NULL},
+ {"xwi", "ウィ", NULL},
+ {"we", "ウェ", NULL},
+ {"xwe", "ウェ", NULL},
+ {"wo", "ヲ", NULL},
+
+ {"va", "ヴァ", NULL},
+ {"vi", "ヴィ", NULL},
+ {"vu", "ヴ", NULL},
+ {"ve", "ヴェ", NULL},
+ {"vo", "ヴォ", NULL},
+
+ {NULL, NULL, NULL}
+};
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/src-util/typetab b/src-util/typetab
new file mode 100644
index 0000000..a850735
--- /dev/null
+++ b/src-util/typetab
@@ -0,0 +1,477 @@
+#
+# ユーザが指定した品詞のパラメータから内部の品詞に変換するための表
+#
+# TODO: 抜けている品詞がある。動詞のパラメータの妥当性をチェック
+#
+T00
+品詞 = 名詞
+な接続 = y
+さ接続 = y
+する接続 = y
+語幹のみで文節 = y
+格助詞接続 = y
+
+T02
+品詞 = 名詞
+な接続 = y
+さ接続 = y
+する接続 = y
+語幹のみで文節 = y
+格助詞接続 = n
+
+T03
+品詞 = 名詞
+な接続 = y
+さ接続 = y
+する接続 = y
+語幹のみで文節 = n
+格助詞接続 = y
+
+T04
+品詞 = 名詞
+な接続 = y
+さ接続 = y
+する接続 = y
+語幹のみで文節 = n
+格助詞接続 = n
+
+T05
+品詞 = 名詞
+な接続 = y
+さ接続 = y
+する接続 = n
+語幹のみで文節 = y
+格助詞接続 = y
+
+T07
+品詞 = 名詞
+な接続 = y
+さ接続 = y
+する接続 = n
+語幹のみで文節 = y
+格助詞接続 = n
+
+T08
+品詞 = 名詞
+な接続 = y
+さ接続 = y
+する接続 = n
+語幹のみで文節 = n
+格助詞接続 = y
+
+T09
+品詞 = 名詞
+な接続 = y
+さ接続 = y
+する接続 = n
+語幹のみで文節 = n
+格助詞接続 = n
+
+T10
+品詞 = 名詞
+な接続 = y
+さ接続 = n
+する接続 = y
+語幹のみで文節 = y
+格助詞接続 = y
+
+T12
+品詞 = 名詞
+な接続 = y
+さ接続 = n
+する接続 = y
+語幹のみで文節 = y
+格助詞接続 = n
+
+T13
+品詞 = 名詞
+な接続 = y
+さ接続 = n
+する接続 = y
+語幹のみで文節 = n
+格助詞接続 = y
+
+T14
+品詞 = 名詞
+な接続 = y
+さ接続 = n
+する接続 = y
+語幹のみで文節 = n
+格助詞接続 = n
+
+T15
+品詞 = 名詞
+な接続 = y
+さ接続 = n
+する接続 = n
+語幹のみで文節 = y
+格助詞接続 = y
+
+T17
+品詞 = 名詞
+な接続 = y
+さ接続 = n
+する接続 = n
+語幹のみで文節 = y
+格助詞接続 = n
+
+T18
+品詞 = 名詞
+な接続 = y
+さ接続 = n
+する接続 = n
+語幹のみで文節 = n
+格助詞接続 = y
+
+T19
+品詞 = 名詞
+な接続 = y
+さ接続 = n
+する接続 = n
+語幹のみで文節 = n
+格助詞接続 = n
+
+T20
+品詞 = 名詞
+な接続 = n
+さ接続 = y
+する接続 = y
+語幹のみで文節 = y
+格助詞接続 = y
+
+T22
+品詞 = 名詞
+な接続 = n
+さ接続 = y
+する接続 = y
+語幹のみで文節 = y
+格助詞接続 = n
+
+T23
+品詞 = 名詞
+な接続 = n
+さ接続 = y
+する接続 = y
+語幹のみで文節 = n
+格助詞接続 = y
+
+T24
+品詞 = 名詞
+な接続 = n
+さ接続 = y
+する接続 = y
+語幹のみで文節 = n
+格助詞接続 = n
+
+T25
+品詞 = 名詞
+な接続 = n
+さ接続 = y
+する接続 = n
+語幹のみで文節 = y
+格助詞接続 = y
+
+T27
+品詞 = 名詞
+な接続 = n
+さ接続 = y
+する接続 = n
+語幹のみで文節 = y
+格助詞接続 = n
+
+T28
+品詞 = 名詞
+な接続 = n
+さ接続 = y
+する接続 = n
+語幹のみで文節 = n
+格助詞接続 = y
+
+T29
+品詞 = 名詞
+な接続 = n
+さ接続 = y
+する接続 = n
+語幹のみで文節 = n
+格助詞接続 = n
+
+T30
+品詞 = 名詞
+な接続 = n
+さ接続 = n
+する接続 = y
+語幹のみで文節 = y
+格助詞接続 = y
+
+T32
+品詞 = 名詞
+な接続 = n
+さ接続 = n
+する接続 = y
+語幹のみで文節 = y
+格助詞接続 = n
+
+T33
+品詞 = 名詞
+な接続 = n
+さ接続 = n
+する接続 = y
+語幹のみで文節 = n
+格助詞接続 = y
+
+T34
+品詞 = 名詞
+な接続 = n
+さ接続 = n
+する接続 = y
+語幹のみで文節 = n
+格助詞接続 = n
+
+T35
+品詞 = 名詞
+な接続 = n
+さ接続 = n
+する接続 = n
+語幹のみで文節 = y
+格助詞接続 = y
+
+T37
+品詞 = 名詞
+な接続 = n
+さ接続 = n
+する接続 = n
+語幹のみで文節 = y
+格助詞接続 = n
+
+T38
+品詞 = 名詞
+な接続 = n
+さ接続 = n
+する接続 = n
+語幹のみで文節 = n
+格助詞接続 = y
+
+T39
+品詞 = 名詞
+な接続 = n
+さ接続 = n
+する接続 = n
+語幹のみで文節 = n
+格助詞接続 = n
+
+F00
+品詞 = 副詞
+と接続 = y
+たる接続 = y
+する接続 = y
+語幹のみで文節 = y
+
+F01
+品詞 = 副詞
+と接続 = y
+たる接続 = y
+する接続 = y
+語幹のみで文節 = n
+
+F02
+品詞 = 副詞
+と接続 = y
+たる接続 = y
+する接続 = n
+語幹のみで文節 = y
+
+F03
+品詞 = 副詞
+と接続 = y
+たる接続 = y
+する接続 = n
+語幹のみで文節 = n
+
+F04
+品詞 = 副詞
+と接続 = y
+たる接続 = n
+する接続 = y
+語幹のみで文節 = y
+
+F05
+品詞 = 副詞
+と接続 = y
+たる接続 = n
+する接続 = y
+語幹のみで文節 = n
+
+F06
+品詞 = 副詞
+と接続 = y
+たる接続 = n
+する接続 = n
+語幹のみで文節 = y
+
+F07
+品詞 = 副詞
+と接続 = y
+たる接続 = n
+する接続 = n
+語幹のみで文節 = n
+
+F08
+品詞 = 副詞
+と接続 = n
+たる接続 = y
+する接続 = y
+語幹のみで文節 = y
+
+F09
+品詞 = 副詞
+と接続 = n
+たる接続 = y
+する接続 = y
+語幹のみで文節 = n
+
+F10
+品詞 = 副詞
+と接続 = n
+たる接続 = y
+する接続 = n
+語幹のみで文節 = y
+
+F11
+品詞 = 副詞
+と接続 = n
+たる接続 = y
+する接続 = n
+語幹のみで文節 = n
+
+F12
+品詞 = 副詞
+と接続 = n
+たる接続 = n
+する接続 = y
+語幹のみで文節 = y
+
+F13
+品詞 = 副詞
+と接続 = n
+たる接続 = n
+する接続 = y
+語幹のみで文節 = n
+
+F14
+品詞 = 副詞
+と接続 = n
+たる接続 = n
+する接続 = n
+語幹のみで文節 = y
+
+JNM
+品詞 = 人名
+
+CN
+品詞 = 地名
+
+KY
+品詞 = 形容詞
+
+B5
+品詞 = 動詞
+活用 = バ行五段
+連用形の名詞化 = n
+
+B5r
+品詞 = 動詞
+活用 = バ行五段
+連用形の名詞化 = y
+
+#C5
+
+G5
+品詞 = 動詞
+活用 = ガ行五段
+連用形の名詞化 = n
+
+G5r
+品詞 = 動詞
+活用 = ガ行五段
+連用形の名詞化 = y
+
+K5
+品詞 = 動詞
+活用 = カ行五段
+連用形の名詞化 = n
+
+K5r
+品詞 = 動詞
+活用 = カ行五段
+連用形の名詞化 = y
+
+#KS
+#L5
+
+M5
+品詞 = 動詞
+活用 = マ行五段
+連用形の名詞化 = n
+
+M5r
+品詞 = 動詞
+活用 = マ行五段
+連用形の名詞化 = y
+
+N5
+品詞 = 動詞
+活用 = ナ行五段
+連用形の名詞化 = n
+
+N5r
+品詞 = 動詞
+活用 = ナ行五段
+連用形の名詞化 = y
+
+#OKX
+
+R5
+品詞 = 動詞
+活用 = ラ行五段
+連用形の名詞化 = n
+
+R5r
+品詞 = 動詞
+活用 = ラ行五段
+連用形の名詞化 = y
+
+S5
+品詞 = 動詞
+活用 = サ行五段
+連用形の名詞化 = n
+
+S5r
+品詞 = 動詞
+活用 = サ行五段
+連用形の名詞化 = y
+
+#SX
+
+T5
+品詞 = 動詞
+活用 = タ行五段
+連用形の名詞化 = n
+
+T5r
+品詞 = 動詞
+活用 = タ行五段
+連用形の名詞化 = y
+
+#U5
+
+W5
+品詞 = 動詞
+活用 = ワ行五段
+連用形の名詞化 = n
+
+W5r
+品詞 = 動詞
+活用 = ワ行五段
+連用形の名詞化 = y
+
+#ZX