Initial commit to support emacs 52/1752/1 1.0 1.0_branch accepted/trunk/20120915.000046 submit/trunk/20120915.001735
authorGraydon, Tracy <tracy.graydon@intel.com>
Sat, 15 Sep 2012 00:17:28 +0000 (17:17 -0700)
committerGraydon, Tracy <tracy.graydon@intel.com>
Sat, 15 Sep 2012 00:17:28 +0000 (17:17 -0700)
204 files changed:
ABOUT-NLS [new file with mode: 0644]
AUTHORS [new file with mode: 0644]
COPYING [new file with mode: 0644]
ChangeLog [new file with mode: 0644]
INSTALL [new file with mode: 0644]
Makefile.am [new file with mode: 0644]
Makefile.in [new file with mode: 0644]
NEWS [new file with mode: 0644]
README [new file with mode: 0644]
TODO [new file with mode: 0644]
aclocal.m4 [new file with mode: 0644]
bootstrap.sh [new file with mode: 0755]
config.guess [new file with mode: 0755]
config.rpath [new file with mode: 0755]
config.sub [new file with mode: 0755]
configure [new file with mode: 0755]
configure.ac [new file with mode: 0644]
depcomp [new file with mode: 0755]
example/.gdb.util [new file with mode: 0644]
example/.gdbinit [new file with mode: 0644]
example/ChangeLog [new file with mode: 0644]
example/HELLO-ja.utf8 [new file with mode: 0644]
example/HELLO-ja.xml [new file with mode: 0644]
example/HELLO.html [new file with mode: 0644]
example/HELLO.utf8 [new file with mode: 0644]
example/HELLO.xml [new file with mode: 0644]
example/M17NEdit.ja [new file with mode: 0644]
example/Makefile.am [new file with mode: 0644]
example/Makefile.in [new file with mode: 0644]
example/mconv.c [new file with mode: 0644]
example/mdate.c [new file with mode: 0644]
example/mdump.c [new file with mode: 0644]
example/medit.c [new file with mode: 0644]
example/mimx-anthy.c [new file with mode: 0644]
example/mimx-ispell.c [new file with mode: 0644]
example/mview.c [new file with mode: 0644]
install-sh [new file with mode: 0755]
intl/ChangeLog [new file with mode: 0644]
intl/Makefile.in [new file with mode: 0644]
intl/VERSION [new file with mode: 0644]
intl/bindtextdom.c [new file with mode: 0644]
intl/config.charset [new file with mode: 0755]
intl/dcgettext.c [new file with mode: 0644]
intl/dcigettext.c [new file with mode: 0644]
intl/dcngettext.c [new file with mode: 0644]
intl/dgettext.c [new file with mode: 0644]
intl/dngettext.c [new file with mode: 0644]
intl/eval-plural.h [new file with mode: 0644]
intl/explodename.c [new file with mode: 0644]
intl/finddomain.c [new file with mode: 0644]
intl/gettext.c [new file with mode: 0644]
intl/gettextP.h [new file with mode: 0644]
intl/gmo.h [new file with mode: 0644]
intl/hash-string.h [new file with mode: 0644]
intl/intl-compat.c [new file with mode: 0644]
intl/l10nflist.c [new file with mode: 0644]
intl/langprefs.c [new file with mode: 0644]
intl/libgnuintl.h.in [new file with mode: 0644]
intl/loadinfo.h [new file with mode: 0644]
intl/loadmsgcat.c [new file with mode: 0644]
intl/localcharset.c [new file with mode: 0644]
intl/localcharset.h [new file with mode: 0644]
intl/locale.alias [new file with mode: 0644]
intl/localealias.c [new file with mode: 0644]
intl/localename.c [new file with mode: 0644]
intl/log.c [new file with mode: 0644]
intl/ngettext.c [new file with mode: 0644]
intl/os2compat.c [new file with mode: 0644]
intl/os2compat.h [new file with mode: 0644]
intl/osdep.c [new file with mode: 0644]
intl/plural-exp.c [new file with mode: 0644]
intl/plural-exp.h [new file with mode: 0644]
intl/plural.c [new file with mode: 0644]
intl/plural.y [new file with mode: 0644]
intl/printf-args.c [new file with mode: 0644]
intl/printf-args.h [new file with mode: 0644]
intl/printf-parse.c [new file with mode: 0644]
intl/printf-parse.h [new file with mode: 0644]
intl/printf.c [new file with mode: 0644]
intl/ref-add.sin [new file with mode: 0644]
intl/ref-del.sin [new file with mode: 0644]
intl/relocatable.c [new file with mode: 0644]
intl/relocatable.h [new file with mode: 0644]
intl/textdomain.c [new file with mode: 0644]
intl/vasnprintf.c [new file with mode: 0644]
intl/vasnprintf.h [new file with mode: 0644]
intl/vasnwprintf.h [new file with mode: 0644]
intl/wprintf-parse.h [new file with mode: 0644]
intl/xsize.h [new file with mode: 0644]
ltmain.sh [new file with mode: 0755]
m17n-config.in [new file with mode: 0644]
m17n-core.pc.in [new file with mode: 0644]
m17n-flt.pc.in [new file with mode: 0644]
m17n-gui.pc.in [new file with mode: 0644]
m17n-shell.pc.in [new file with mode: 0644]
m4/ChangeLog [new file with mode: 0644]
m4/codeset.m4 [new file with mode: 0644]
m4/gettext.m4 [new file with mode: 0644]
m4/glibc2.m4 [new file with mode: 0644]
m4/glibc21.m4 [new file with mode: 0644]
m4/iconv.m4 [new file with mode: 0644]
m4/intdiv0.m4 [new file with mode: 0644]
m4/intmax.m4 [new file with mode: 0644]
m4/inttypes-pri.m4 [new file with mode: 0644]
m4/inttypes.m4 [new file with mode: 0644]
m4/inttypes_h.m4 [new file with mode: 0644]
m4/isc-posix.m4 [new file with mode: 0644]
m4/lcmessage.m4 [new file with mode: 0644]
m4/lib-ld.m4 [new file with mode: 0644]
m4/lib-link.m4 [new file with mode: 0644]
m4/lib-prefix.m4 [new file with mode: 0644]
m4/libtool.m4 [new file with mode: 0644]
m4/longdouble.m4 [new file with mode: 0644]
m4/longlong.m4 [new file with mode: 0644]
m4/ltoptions.m4 [new file with mode: 0644]
m4/ltsugar.m4 [new file with mode: 0644]
m4/ltversion.m4 [new file with mode: 0644]
m4/lt~obsolete.m4 [new file with mode: 0644]
m4/nls.m4 [new file with mode: 0644]
m4/po.m4 [new file with mode: 0644]
m4/printf-posix.m4 [new file with mode: 0644]
m4/progtest.m4 [new file with mode: 0644]
m4/signed.m4 [new file with mode: 0644]
m4/size_max.m4 [new file with mode: 0644]
m4/stdint_h.m4 [new file with mode: 0644]
m4/uintmax_t.m4 [new file with mode: 0644]
m4/ulonglong.m4 [new file with mode: 0644]
m4/wchar_t.m4 [new file with mode: 0644]
m4/wint_t.m4 [new file with mode: 0644]
m4/xsize.m4 [new file with mode: 0644]
missing [new file with mode: 0755]
mkinstalldirs [new file with mode: 0755]
packaging/m17n-lib-nobuild-examples.patch [new file with mode: 0644]
packaging/m17n-lib.changes [new file with mode: 0644]
packaging/m17n-lib.spec [new file with mode: 0644]
po/ChangeLog [new file with mode: 0644]
po/Makefile.in.in [new file with mode: 0644]
po/Makevars [new file with mode: 0644]
po/POTFILES.in [new file with mode: 0644]
po/Rules-quot [new file with mode: 0644]
po/boldquot.sed [new file with mode: 0644]
po/en@boldquot.header [new file with mode: 0644]
po/en@quot.header [new file with mode: 0644]
po/insert-header.sin [new file with mode: 0644]
po/quot.sed [new file with mode: 0644]
po/remove-potcdate.sin [new file with mode: 0644]
src/ChangeLog [new file with mode: 0644]
src/Makefile.am [new file with mode: 0644]
src/Makefile.in [new file with mode: 0644]
src/README [new file with mode: 0644]
src/character.c [new file with mode: 0644]
src/character.h [new file with mode: 0644]
src/charset.c [new file with mode: 0644]
src/charset.h [new file with mode: 0644]
src/chartab.c [new file with mode: 0644]
src/chartab.h [new file with mode: 0644]
src/coding.c [new file with mode: 0644]
src/coding.h [new file with mode: 0644]
src/config.h.in [new file with mode: 0644]
src/database.c [new file with mode: 0644]
src/database.h [new file with mode: 0644]
src/draw.c [new file with mode: 0644]
src/face.c [new file with mode: 0644]
src/face.h [new file with mode: 0644]
src/font-ft.c [new file with mode: 0644]
src/font.c [new file with mode: 0644]
src/font.h [new file with mode: 0644]
src/fontset.c [new file with mode: 0644]
src/fontset.h [new file with mode: 0644]
src/input-gui.c [new file with mode: 0644]
src/input.c [new file with mode: 0644]
src/input.h [new file with mode: 0644]
src/internal-flt.h [new file with mode: 0644]
src/internal-gui.h [new file with mode: 0644]
src/internal.h [new file with mode: 0644]
src/language.c [new file with mode: 0644]
src/language.h [new file with mode: 0644]
src/linkcore.c [new file with mode: 0644]
src/linkgui.c [new file with mode: 0644]
src/linkshell.c [new file with mode: 0644]
src/locale.c [new file with mode: 0644]
src/m17n-X.c [new file with mode: 0644]
src/m17n-X.h [new file with mode: 0644]
src/m17n-core.c [new file with mode: 0644]
src/m17n-core.h [new file with mode: 0644]
src/m17n-flt.c [new file with mode: 0644]
src/m17n-flt.h [new file with mode: 0644]
src/m17n-gd.c [new file with mode: 0644]
src/m17n-gui.c [new file with mode: 0644]
src/m17n-gui.h [new file with mode: 0644]
src/m17n-misc.h [new file with mode: 0644]
src/m17n.c [new file with mode: 0644]
src/m17n.h [new file with mode: 0644]
src/mlocale.h [new file with mode: 0644]
src/mtext-lbrk.c [new file with mode: 0644]
src/mtext-wseg.c [new file with mode: 0644]
src/mtext.c [new file with mode: 0644]
src/mtext.h [new file with mode: 0644]
src/plist.c [new file with mode: 0644]
src/plist.h [new file with mode: 0644]
src/symbol.c [new file with mode: 0644]
src/symbol.h [new file with mode: 0644]
src/textprop.c [new file with mode: 0644]
src/textprop.h [new file with mode: 0644]

diff --git a/ABOUT-NLS b/ABOUT-NLS
new file mode 100644 (file)
index 0000000..ed3565a
--- /dev/null
+++ b/ABOUT-NLS
@@ -0,0 +1,986 @@
+1 Notes on the Free Translation Project
+***************************************
+
+Free software is going international!  The Free Translation Project is
+a way to get maintainers of free software, translators, and users all
+together, so that free software will gradually become able to speak many
+languages.  A few packages already provide translations for their
+messages.
+
+   If you found this `ABOUT-NLS' file inside a distribution, you may
+assume that the distributed package does use GNU `gettext' internally,
+itself available at your nearest GNU archive site.  But you do _not_
+need to install GNU `gettext' prior to configuring, installing or using
+this package with messages translated.
+
+   Installers will find here some useful hints.  These notes also
+explain how users should proceed for getting the programs to use the
+available translations.  They tell how people wanting to contribute and
+work on translations can contact the appropriate team.
+
+   When reporting bugs in the `intl/' directory or bugs which may be
+related to internationalization, you should tell about the version of
+`gettext' which is used.  The information can be found in the
+`intl/VERSION' file, in internationalized packages.
+
+1.1 Quick configuration advice
+==============================
+
+If you want to exploit the full power of internationalization, you
+should configure it using
+
+     ./configure --with-included-gettext
+
+to force usage of internationalizing routines provided within this
+package, despite the existence of internationalizing capabilities in the
+operating system where this package is being installed.  So far, only
+the `gettext' implementation in the GNU C library version 2 provides as
+many features (such as locale alias, message inheritance, automatic
+charset conversion or plural form handling) as the implementation here.
+It is also not possible to offer this additional functionality on top
+of a `catgets' implementation.  Future versions of GNU `gettext' will
+very likely convey even more functionality.  So it might be a good idea
+to change to GNU `gettext' as soon as possible.
+
+   So you need _not_ provide this option if you are using GNU libc 2 or
+you have installed a recent copy of the GNU gettext package with the
+included `libintl'.
+
+1.2 INSTALL Matters
+===================
+
+Some packages are "localizable" when properly installed; the programs
+they contain can be made to speak your own native language.  Most such
+packages use GNU `gettext'.  Other packages have their own ways to
+internationalization, predating GNU `gettext'.
+
+   By default, this package will be installed to allow translation of
+messages.  It will automatically detect whether the system already
+provides the GNU `gettext' functions.  If not, the included GNU
+`gettext' library will be used.  This library is wholly contained
+within this package, usually in the `intl/' subdirectory, so prior
+installation of the GNU `gettext' package is _not_ required.
+Installers may use special options at configuration time for changing
+the default behaviour.  The commands:
+
+     ./configure --with-included-gettext
+     ./configure --disable-nls
+
+will, respectively, bypass any pre-existing `gettext' to use the
+internationalizing routines provided within this package, or else,
+_totally_ disable translation of messages.
+
+   When you already have GNU `gettext' installed on your system and run
+configure without an option for your new package, `configure' will
+probably detect the previously built and installed `libintl.a' file and
+will decide to use this.  This might not be desirable.  You should use
+the more recent version of the GNU `gettext' library.  I.e. if the file
+`intl/VERSION' shows that the library which comes with this package is
+more recent, you should use
+
+     ./configure --with-included-gettext
+
+to prevent auto-detection.
+
+   The configuration process will not test for the `catgets' function
+and therefore it will not be used.  The reason is that even an
+emulation of `gettext' on top of `catgets' could not provide all the
+extensions of the GNU `gettext' library.
+
+   Internationalized packages usually have many `po/LL.po' files, where
+LL gives an ISO 639 two-letter code identifying the language.  Unless
+translations have been forbidden at `configure' time by using the
+`--disable-nls' switch, all available translations are installed
+together with the package.  However, the environment variable `LINGUAS'
+may be set, prior to configuration, to limit the installed set.
+`LINGUAS' should then contain a space separated list of two-letter
+codes, stating which languages are allowed.
+
+1.3 Using This Package
+======================
+
+As a user, if your language has been installed for this package, you
+only have to set the `LANG' environment variable to the appropriate
+`LL_CC' combination.  Here `LL' is an ISO 639 two-letter language code,
+and `CC' is an ISO 3166 two-letter country code.  For example, let's
+suppose that you speak German and live in Germany.  At the shell
+prompt, merely execute `setenv LANG de_DE' (in `csh'),
+`export LANG; LANG=de_DE' (in `sh') or `export LANG=de_DE' (in `bash').
+This can be done from your `.login' or `.profile' file, once and for
+all.
+
+   You might think that the country code specification is redundant.
+But in fact, some languages have dialects in different countries.  For
+example, `de_AT' is used for Austria, and `pt_BR' for Brazil.  The
+country code serves to distinguish the dialects.
+
+   The locale naming convention of `LL_CC', with `LL' denoting the
+language and `CC' denoting the country, is the one use on systems based
+on GNU libc.  On other systems, some variations of this scheme are
+used, such as `LL' or `LL_CC.ENCODING'.  You can get the list of
+locales supported by your system for your country by running the command
+`locale -a | grep '^LL''.
+
+   Not all programs have translations for all languages.  By default, an
+English message is shown in place of a nonexistent translation.  If you
+understand other languages, you can set up a priority list of languages.
+This is done through a different environment variable, called
+`LANGUAGE'.  GNU `gettext' gives preference to `LANGUAGE' over `LANG'
+for the purpose of message handling, but you still need to have `LANG'
+set to the primary language; this is required by other parts of the
+system libraries.  For example, some Swedish users who would rather
+read translations in German than English for when Swedish is not
+available, set `LANGUAGE' to `sv:de' while leaving `LANG' to `sv_SE'.
+
+   Special advice for Norwegian users: The language code for Norwegian
+bokma*l changed from `no' to `nb' recently (in 2003).  During the
+transition period, while some message catalogs for this language are
+installed under `nb' and some older ones under `no', it's recommended
+for Norwegian users to set `LANGUAGE' to `nb:no' so that both newer and
+older translations are used.
+
+   In the `LANGUAGE' environment variable, but not in the `LANG'
+environment variable, `LL_CC' combinations can be abbreviated as `LL'
+to denote the language's main dialect.  For example, `de' is equivalent
+to `de_DE' (German as spoken in Germany), and `pt' to `pt_PT'
+(Portuguese as spoken in Portugal) in this context.
+
+1.4 Translating Teams
+=====================
+
+For the Free Translation Project to be a success, we need interested
+people who like their own language and write it well, and who are also
+able to synergize with other translators speaking the same language.
+Each translation team has its own mailing list.  The up-to-date list of
+teams can be found at the Free Translation Project's homepage,
+`http://www.iro.umontreal.ca/contrib/po/HTML/', in the "National teams"
+area.
+
+   If you'd like to volunteer to _work_ at translating messages, you
+should become a member of the translating team for your own language.
+The subscribing address is _not_ the same as the list itself, it has
+`-request' appended.  For example, speakers of Swedish can send a
+message to `sv-request@li.org', having this message body:
+
+     subscribe
+
+   Keep in mind that team members are expected to participate
+_actively_ in translations, or at solving translational difficulties,
+rather than merely lurking around.  If your team does not exist yet and
+you want to start one, or if you are unsure about what to do or how to
+get started, please write to `translation@iro.umontreal.ca' to reach the
+coordinator for all translator teams.
+
+   The English team is special.  It works at improving and uniformizing
+the terminology in use.  Proven linguistic skill are praised more than
+programming skill, here.
+
+1.5 Available Packages
+======================
+
+Languages are not equally supported in all packages.  The following
+matrix shows the current state of internationalization, as of April
+2005.  The matrix shows, in regard of each package, for which languages
+PO files have been submitted to translation coordination, with a
+translation percentage of at least 50%.
+
+     Ready PO files       af am ar az be bg bs ca cs cy da de el en en_GB
+                        +-------------------------------------------------+
+     GNUnet             |                                                 |
+     a2ps               |             []                [] [] []     []   |
+     aegis              |                                  ()             |
+     ant-phone          |                                  ()             |
+     anubis             |                                  []             |
+     ap-utils           |                                                 |
+     aspell             |                         []    [] []        []   |
+     bash               |                      []          []             |
+     batchelor          |                                  []             |
+     bfd                |                                                 |
+     bibshelf           |                                  []             |
+     binutils           |                               []                |
+     bison              |                               [] []             |
+     bluez-pin          | []                      []       [] []          |
+     clisp              |                                  []    []       |
+     console-tools      |                         []       []             |
+     coreutils          |                []    []       [] []             |
+     cpio               |                                                 |
+     cpplib             |                      []       [] []             |
+     darkstat           |                []             () []             |
+     dialog             |                      [] [] [] [] [] []          |
+     diffutils          |                      [] []    [] [] []          |
+     doodle             |                                  []             |
+     e2fsprogs          |                         []       []             |
+     enscript           |                      []       [] []        []   |
+     error              |                      []       [] []        []   |
+     fetchmail          |                      [] ()    [] [] []          |
+     fileutils          |                               [] []             |
+     findutils          |                      []       []    []          |
+     flex               |                      []       [] []             |
+     fslint             |                                  []             |
+     gas                |                                                 |
+     gawk               |                      []       [] []             |
+     gbiff              |                                  []             |
+     gcal               |                      []                         |
+     gcc                |                                  []             |
+     gettext-examples   | []                   []          [] []          |
+     gettext-runtime    |             []       []       [] []             |
+     gettext-tools      |                      []          []             |
+     gimp-print         |                         []    [] []        []   |
+     gip                |                                                 |
+     gliv               |                                  []             |
+     glunarclock        |                                                 |
+     gmult              | []                               []             |
+     gnubiff            |                                  ()             |
+     gnucash            |                         []       () ()     []   |
+     gnucash-glossary   |                               [] ()             |
+     gpe-aerial         |                         []       []             |
+     gpe-beam           |                         []       []             |
+     gpe-calendar       |                         []       []             |
+     gpe-clock          |                         []       []             |
+     gpe-conf           |                         []       []             |
+     gpe-contacts       |                                                 |
+     gpe-edit           |                         []                      |
+     gpe-go             |                         []                      |
+     gpe-login          |                         []       []             |
+     gpe-ownerinfo      |                         []       []             |
+     gpe-sketchbook     |                         []       []             |
+     gpe-su             |                         []       []             |
+     gpe-taskmanager    |                         []       []             |
+     gpe-timesheet      |                         []                      |
+     gpe-today          |                         []       []             |
+     gpe-todo           |                         []       []             |
+     gphoto2            |                         []    [] []        []   |
+     gprof              |                               [] []             |
+     gpsdrive           |                                  ()    ()       |
+     gramadoir          | []                               []             |
+     grep               | []          [] []    []          [] []          |
+     gretl              |                                                 |
+     gsasl              |                                  []             |
+     gss                |                                                 |
+     gst-plugins        | []       []          [] []       []        []   |
+     gstreamer          | []                   [] []       []        []   |
+     gtick              | []                               ()             |
+     gtkspell           |             []                   [] []          |
+     hello              |                      []       [] [] []          |
+     id-utils           |                               [] []             |
+     impost             |                                                 |
+     indent             |                      []          []             |
+     iso_3166           |                                                 |
+     iso_3166_1         |                      [] []    [] [] []          |
+     iso_3166_2         |                                                 |
+     iso_3166_3         |                                  []             |
+     iso_4217           |                                                 |
+     iso_639            |                                                 |
+     jpilot             |                         []                      |
+     jtag               |                                                 |
+     jwhois             |                                                 |
+     kbd                |                         []    [] [] []          |
+     latrine            |                                  ()             |
+     ld                 |                               []                |
+     libc               |                      [] []    [] [] []          |
+     libextractor       |                                                 |
+     libgpewidget       |                         []    [] []             |
+     libgsasl           |                                                 |
+     libiconv           | []                   []       [] [] []          |
+     libidn             |                                                 |
+     lifelines          |                               [] ()             |
+     lilypond           |                                  []             |
+     lingoteach         |                                                 |
+     lynx               |                      [] []    [] []             |
+     m4                 |                         []    [] [] []          |
+     mailutils          |                      []                         |
+     make               |                               [] []             |
+     man-db             |                      [] ()    [] []             |
+     minicom            |                         []       []             |
+     mysecretdiary      |                               [] []             |
+     nano               |                      [] ()       []             |
+     nano_1_0           |                      [] ()    [] []             |
+     opcodes            |                                  []             |
+     parted             |                      [] []    [] []             |
+     psmisc             |                                                 |
+     ptx                |                      []       [] []             |
+     pwdutils           |                                                 |
+     python             |                                                 |
+     radius             |                      []                         |
+     recode             |             []       []       [] [] []          |
+     rpm                |                         []    []                |
+     screem             |                                                 |
+     scrollkeeper       |          [] []       [] [] [] [] []        []   |
+     sed                |                      []          []             |
+     sh-utils           |                               [] []             |
+     shared-mime-info   |                         [] []                   |
+     sharutils          |                      [] []    [] [] []          |
+     silky              |                                                 |
+     skencil            |                               [] ()             |
+     sketch             |                               [] ()             |
+     solfege            |                                  []             |
+     soundtracker       |                               [] []             |
+     sp                 |                                  []             |
+     stardict           |                         []                      |
+     tar                |                                                 |
+     texinfo            |                               [] []             |
+     textutils          |                      []       [] []             |
+     tin                |                                  ()        ()   |
+     tp-robot           |                                  []             |
+     tuxpaint           | []                   [] []    [] [] []     []   |
+     unicode-han-tra... |                                                 |
+     unicode-transla... |                                                 |
+     util-linux         |                      [] []    [] []             |
+     vorbis-tools       |             []          []    []           []   |
+     wastesedge         |                                  ()             |
+     wdiff              |                      []       [] []        []   |
+     wget               |                []    []       [] [] []     []   |
+     xchat              |                      []          [] []     []   |
+     xkeyboard-config   |                                                 |
+     xpad               |                                                 |
+                        +-------------------------------------------------+
+                          af am ar az be bg bs ca cs cy da de el en en_GB
+                          10  0  0  2  7  4  0 41 43  3 52 90 20  1  15
+
+                          eo es et eu fa fi fr  ga gl he hr hu id is it
+                        +-----------------------------------------------+
+     GNUnet             |                                               |
+     a2ps               |       []       [] []                       () |
+     aegis              |                                               |
+     ant-phone          |                   []                          |
+     anubis             |                   []                          |
+     ap-utils           |                   []                          |
+     aspell             |                   []  []                      |
+     bash               | [] []             []              []          |
+     batchelor          |                   []  []                      |
+     bfd                |    []                                         |
+     bibshelf           |    []                 []                   [] |
+     binutils           |    []             []                          |
+     bison              |    [] []          []  []             []    [] |
+     bluez-pin          | []             [] []  []          [] []       |
+     clisp              |    []             []                          |
+     console-tools      |                                               |
+     coreutils          |    [] []       [] []  []                      |
+     cpio               |    []             []                          |
+     cpplib             |    []             []                          |
+     darkstat           |    []             ()  []          [] []       |
+     dialog             |    [] [] []    [] []  []          []       [] |
+     diffutils          | [] []          [] []  [] [] []    [] []    [] |
+     doodle             |                       []                   [] |
+     e2fsprogs          |    []             []                       [] |
+     enscript           |                   []           []             |
+     error              |    []          [] []  []          []          |
+     fetchmail          |    []                                         |
+     fileutils          |    [] []          []  []          []       [] |
+     findutils          |    [] []          []  []                   [] |
+     flex               |    []             []  []                      |
+     fslint             |                   []                          |
+     gas                |    []             []                          |
+     gawk               |    []             []  []    []                |
+     gbiff              |                   []                          |
+     gcal               |    []             []                          |
+     gcc                |    []                                         |
+     gettext-examples   |    []             []  []                   [] |
+     gettext-runtime    |    []          [] []  []             []    [] |
+     gettext-tools      |    []             []                       [] |
+     gimp-print         |    []             []                          |
+     gip                |    []    []       []                          |
+     gliv               |                   ()                          |
+     glunarclock        |                []     []          []          |
+     gmult              |          []       []                       [] |
+     gnubiff            |                   ()                       () |
+     gnucash            |    []                             ()       [] |
+     gnucash-glossary   |    []                                      [] |
+     gpe-aerial         |    []             []                          |
+     gpe-beam           |    []             []                          |
+     gpe-calendar       |    []             []              [] []       |
+     gpe-clock          |    []          [] []                          |
+     gpe-conf           |                   []                          |
+     gpe-contacts       |                   []                          |
+     gpe-edit           |                   []                 []       |
+     gpe-go             |    []             []                          |
+     gpe-login          |    []             []              []          |
+     gpe-ownerinfo      |    []          [] []              [] []       |
+     gpe-sketchbook     |    []             []                          |
+     gpe-su             |    []          [] []                          |
+     gpe-taskmanager    |    []          [] []                          |
+     gpe-timesheet      |    []             []  []             []       |
+     gpe-today          |    []          [] []  []                      |
+     gpe-todo           |    []             []                 []       |
+     gphoto2            |    []          [] []              []       [] |
+     gprof              |    []             []                 []       |
+     gpsdrive           |    ()             ()              []       () |
+     gramadoir          |                   []  []                      |
+     grep               |    [] [] []    [] []  [] [] [] [] [] []    [] |
+     gretl              |    []             []                       [] |
+     gsasl              |          []       []  []                      |
+     gss                |                   []                          |
+     gst-plugins        |                   []              []       [] |
+     gstreamer          |                                            [] |
+     gtick              |          []    [] []  []                   [] |
+     gtkspell           | [] []    []       []  []                   [] |
+     hello              | [] [] [] [] [] [] []  [] [] [] [] [] []    [] |
+     id-utils           |                   []              [] []    [] |
+     impost             |                   []  []                      |
+     indent             | [] [] [] []    [] []  [] []       [] []    [] |
+     iso_3166           | []             [] []                          |
+     iso_3166_1         |    []    []    [] []  []          [] []       |
+     iso_3166_2         |                   []                          |
+     iso_3166_3         |                   []                          |
+     iso_4217           |       []       []        []                   |
+     iso_639            | []          [] [] []                          |
+     jpilot             |    []             []                          |
+     jtag               |                   []                          |
+     jwhois             |    []             []              [] []    [] |
+     kbd                |    []             []                          |
+     latrine            |                   []  []                   [] |
+     ld                 |    []             []                          |
+     libc               |    []          [] []     []       []          |
+     libextractor       |                                               |
+     libgpewidget       |    []             []  []          [] []       |
+     libgsasl           |                   []  []                      |
+     libiconv           | [] [] []       [] []  [] []    [] [] []    [] |
+     libidn             |                   []                       [] |
+     lifelines          |                   ()                          |
+     lilypond           |                   []                          |
+     lingoteach         |                   []                 []    [] |
+     lynx               |       []                          []       [] |
+     m4                 |                   []  [] []          []       |
+     mailutils          |    []             []                          |
+     make               |    []          [] []  [] [] [] []             |
+     man-db             |    ()                                         |
+     minicom            |    []          [] []              []          |
+     mysecretdiary      |    []             []                 []       |
+     nano               |    []    []    () []                       [] |
+     nano_1_0           |    []             []     []          []    [] |
+     opcodes            |    []             []                          |
+     parted             |    []             []     []                [] |
+     psmisc             |          []                                [] |
+     ptx                | [] [] []       [] []  [] []       [] []       |
+     pwdutils           |                                               |
+     python             |                                               |
+     radius             |    []             []                          |
+     recode             | [] []             []     [] []    [] []    [] |
+     rpm                |                   []                          |
+     screem             |                                               |
+     scrollkeeper       |    []          []                 []          |
+     sed                |    [] []          []  []          []          |
+     sh-utils           |    [] []       [] []  []          []       [] |
+     shared-mime-info   | [] []    []    [] []              []          |
+     sharutils          |    [] []       [] []     []       []       [] |
+     silky              |                   []                          |
+     skencil            |    []             []                          |
+     sketch             |    []             []                          |
+     solfege            |                                            [] |
+     soundtracker       |    []             []                       [] |
+     sp                 |                   []                          |
+     stardict           |                                   []          |
+     tar                |    [] []          []  []                   [] |
+     texinfo            | []                []        []                |
+     textutils          |    []             []  [] []       []          |
+     tin                |       []          ()                          |
+     tp-robot           |                   []              []          |
+     tuxpaint           |    []          [] []  []    []    [] [] [] [] |
+     unicode-han-tra... |                                               |
+     unicode-transla... |                   []  []                      |
+     util-linux         |    [] []       [] []              []       [] |
+     vorbis-tools       |    []             []                          |
+     wastesedge         |                   ()                          |
+     wdiff              |    [] []          []  [] []       [] []    [] |
+     wget               |    [] [] []    [] []  [] []    [] []       [] |
+     xchat              |    []    []    [] []                       [] |
+     xkeyboard-config   |                                               |
+     xpad               |    []                 []          []          |
+                        +-----------------------------------------------+
+                          eo es et eu fa fi fr  ga gl he hr hu id is it
+                          13 85 21 15  2 35 115 45 17  8  6 40 27  1 45
+
+                          ja ko ku lg lt lv mk mn ms mt nb nl nn no nso
+                        +-----------------------------------------------+
+     GNUnet             |                                               |
+     a2ps               |    ()                   []       []    ()     |
+     aegis              |                                  ()           |
+     ant-phone          |                                  []           |
+     anubis             |                         []    [] []           |
+     ap-utils           |                                               |
+     aspell             |                      []          []           |
+     bash               |                                  []           |
+     batchelor          |                                  []           |
+     bfd                |                                               |
+     bibshelf           |                                               |
+     binutils           |                                               |
+     bison              |                         []    [] []           |
+     bluez-pin          |                                  []           |
+     clisp              |                                  []           |
+     console-tools      |                                               |
+     coreutils          | []                               []           |
+     cpio               |                                               |
+     cpplib             |                                               |
+     darkstat           |                         []       []           |
+     dialog             |                                  []           |
+     diffutils          | []                      []       []           |
+     doodle             |                                               |
+     e2fsprogs          |                                               |
+     enscript           |                                  []           |
+     error              |                                  []           |
+     fetchmail          | []                               []           |
+     fileutils          | []       []                                   |
+     findutils          |                                  []           |
+     flex               |    []                            []           |
+     fslint             |                                  []           |
+     gas                |                                               |
+     gawk               | []                               []           |
+     gbiff              |                                  []           |
+     gcal               |                                               |
+     gcc                |                                               |
+     gettext-examples   | []                               []           |
+     gettext-runtime    | [] []                            []           |
+     gettext-tools      | [] []                                         |
+     gimp-print         | []                               []           |
+     gip                |                                  []           |
+     gliv               |                                  []           |
+     glunarclock        |                         []       []           |
+     gmult              | []                                            |
+     gnubiff            |                                               |
+     gnucash            | ()                            () []           |
+     gnucash-glossary   |                                  []           |
+     gpe-aerial         |                                  []           |
+     gpe-beam           |                                  []           |
+     gpe-calendar       |                                  []           |
+     gpe-clock          |                                  []           |
+     gpe-conf           |                                  []           |
+     gpe-contacts       |                                               |
+     gpe-edit           |                                  []           |
+     gpe-go             |                                  []           |
+     gpe-login          |                                  []           |
+     gpe-ownerinfo      |                                  []           |
+     gpe-sketchbook     |                                  []           |
+     gpe-su             |                                  []           |
+     gpe-taskmanager    |       []                         []           |
+     gpe-timesheet      |                                  []           |
+     gpe-today          |                                  []           |
+     gpe-todo           |                                  []           |
+     gphoto2            | []                               []           |
+     gprof              |                                               |
+     gpsdrive           | ()                               ()    ()     |
+     gramadoir          |                                  ()           |
+     grep               | []                            [] []           |
+     gretl              |                                               |
+     gsasl              |                                  []           |
+     gss                |                                               |
+     gst-plugins        |                                  []           |
+     gstreamer          |                                  []           |
+     gtick              |                                  []           |
+     gtkspell           |                      []          []           |
+     hello              | [] []          []       []    [] [] [] []     |
+     id-utils           |                                  []           |
+     impost             |                                               |
+     indent             | []                               []           |
+     iso_3166           |                                  []           |
+     iso_3166_1         |                                  []    []     |
+     iso_3166_2         |                                  []           |
+     iso_3166_3         |                                  []           |
+     iso_4217           | []                   []          []           |
+     iso_639            | []                               [] []        |
+     jpilot             | ()                               ()    ()     |
+     jtag               |                                               |
+     jwhois             |                                  []           |
+     kbd                |                                  []           |
+     latrine            |                                  []           |
+     ld                 |                                               |
+     libc               | [] []                         [] []    []     |
+     libextractor       |                                               |
+     libgpewidget       |                                  []           |
+     libgsasl           |                                  []           |
+     libiconv           |                                  []           |
+     libidn             |                                               |
+     lifelines          |                                  []           |
+     lilypond           |                                  []           |
+     lingoteach         |                                  []           |
+     lynx               | []                               []           |
+     m4                 | []                               []           |
+     mailutils          |                                               |
+     make               | [] []                            []           |
+     man-db             | ()                                            |
+     minicom            | []                                            |
+     mysecretdiary      |                                  []           |
+     nano               |                         []    []              |
+     nano_1_0           |                         []    []    []        |
+     opcodes            |                                  []           |
+     parted             | []                                  []        |
+     psmisc             |                               [] []           |
+     ptx                |                               [] []    []     |
+     pwdutils           |                                               |
+     python             |                                               |
+     radius             |                                               |
+     recode             |                                  []           |
+     rpm                | [] []                                         |
+     screem             | []                                            |
+     scrollkeeper       |                               [] [] []        |
+     sed                | []                               []           |
+     sh-utils           | []                            []              |
+     shared-mime-info   |    []                         [] [] []        |
+     sharutils          | []                               []           |
+     silky              |                                  []           |
+     skencil            |                                               |
+     sketch             |                                               |
+     solfege            |                                  []    []     |
+     soundtracker       |                                               |
+     sp                 | ()                                            |
+     stardict           |                   []             []           |
+     tar                | []                               []           |
+     texinfo            | []                            [] []           |
+     textutils          | [] []                         []              |
+     tin                |                                               |
+     tp-robot           |                                  []           |
+     tuxpaint           | [] []       []          []       [] []        |
+     unicode-han-tra... |                                               |
+     unicode-transla... |                                               |
+     util-linux         | []                               []           |
+     vorbis-tools       |                                  []           |
+     wastesedge         |                                  []           |
+     wdiff              |                         []    []              |
+     wget               | []                               []           |
+     xchat              |    []          [] []             []           |
+     xkeyboard-config   |                                  []           |
+     xpad               |                                  []           |
+                        +-----------------------------------------------+
+                          ja ko ku lg lt lv mk mn ms mt nb nl nn no nso
+                          33 11  1  1  1  2  2  3 11  0 15 96  7  5  0
+
+                          or pa pl pt pt_BR rm ro ru rw sk sl sq sr sv ta
+                        +-------------------------------------------------+
+     GNUnet             |                                                 |
+     a2ps               |       ()     []      [] []       []    [] []    |
+     aegis              |                      () ()                      |
+     ant-phone          |                      []                         |
+     anubis             |       []             [] []                      |
+     ap-utils           |       ()                                        |
+     aspell             |                      [] []                      |
+     bash               |              []      [] []                      |
+     batchelor          |                      []                         |
+     bfd                |                                                 |
+     bibshelf           |                                                 |
+     binutils           |                         []                []    |
+     bison              |       []     []      [] []                []    |
+     bluez-pin          |       []     []   [] [] []    []       [] []    |
+     clisp              |                         []                      |
+     console-tools      |                         []                      |
+     coreutils          |       []                []       []       []    |
+     cpio               |       []                                  []    |
+     cpplib             |                                                 |
+     darkstat           |       []     []      []       []       [] []    |
+     dialog             |       [] []  []   [] [] [] []                   |
+     diffutils          |       []     []      [] []             [] []    |
+     doodle             |                                     []          |
+     e2fsprogs          |       []                                  []    |
+     enscript           |              []      [] []                []    |
+     error              |              []      []       []                |
+     fetchmail          |       []     ()         []    []    []          |
+     fileutils          |       []             [] []       []       []    |
+     findutils          |       [] []          []       []       [] []    |
+     flex               |       []     []      [] []                []    |
+     fslint             |              []      []                []       |
+     gas                |                                                 |
+     gawk               |       []     []      []                   []    |
+     gbiff              |                      []                         |
+     gcal               |                                           []    |
+     gcc                |                                                 |
+     gettext-examples   |       []             [] []    []       [] []    |
+     gettext-runtime    |       []             [] []    [] []    [] []    |
+     gettext-tools      |       []             [] []    [] []    [] []    |
+     gimp-print         |                               []          []    |
+     gip                |                   []          []       []       |
+     gliv               |              []      []       []                |
+     glunarclock        |              []      [] []    []       [] []    |
+     gmult              |              []   [] []                []       |
+     gnubiff            |                      ()                   []    |
+     gnucash            |       () []             []    []          []    |
+     gnucash-glossary   |          []                   []          []    |
+     gpe-aerial         |          []  []      [] []             [] []    |
+     gpe-beam           |          []  []      [] []             [] []    |
+     gpe-calendar       |          []  []      [] []    []       [] []    |
+     gpe-clock          |          []  []      [] []    []       [] []    |
+     gpe-conf           |          []  []      [] []    []          []    |
+     gpe-contacts       |                      [] []                []    |
+     gpe-edit           |          []  []      [] []    []       [] []    |
+     gpe-go             |              []      [] []             [] []    |
+     gpe-login          |          []  []      [] []    []       [] []    |
+     gpe-ownerinfo      |          []  []      [] []    []       [] []    |
+     gpe-sketchbook     |          []  []      [] []    []       [] []    |
+     gpe-su             |          []  []      [] []    []       [] []    |
+     gpe-taskmanager    |          []  []      [] []    []       [] []    |
+     gpe-timesheet      |          []  []      [] []    []       [] []    |
+     gpe-today          |          []  []      [] []    []       [] []    |
+     gpe-todo           |          []  []      [] []    []       [] []    |
+     gphoto2            |                      []       []       [] []    |
+     gprof              |              []      []                   []    |
+     gpsdrive           |                      []                         |
+     gramadoir          |                               []                |
+     grep               |       [] []  []      [] []       []    []       |
+     gretl              |       []                                        |
+     gsasl              |       []             []             [] [] []    |
+     gss                |       []             []                   []    |
+     gst-plugins        | []                                  [] [] []    |
+     gstreamer          |                         []          [] [] []    |
+     gtick              |                      [] []                []    |
+     gtkspell           |              []   [] [] []    []       []       |
+     hello              |       []     []      [] []    []       [] []    |
+     id-utils           |              []      [] []                []    |
+     impost             |                                                 |
+     indent             |              []      [] []    []       [] []    |
+     iso_3166           |          []                []       [] [] []    |
+     iso_3166_1         |                               [] [] [] []       |
+     iso_3166_2         |                                                 |
+     iso_3166_3         |                      []    []          []       |
+     iso_4217           |                            []          []       |
+     iso_639            |                            []          [] []    |
+     jpilot             |                                                 |
+     jtag               |                               []                |
+     jwhois             |       []     []      [] ()                ()    |
+     kbd                |       []             []                   []    |
+     latrine            |                      []                   []    |
+     ld                 |                                           []    |
+     libc               |       []     []         []    []          []    |
+     libextractor       |                      []                         |
+     libgpewidget       |          []  []      []       []       [] []    |
+     libgsasl           |       []             []                []       |
+     libiconv           |       []     []   [] [] []    [] [] [] [] []    |
+     libidn             |       []                                  ()    |
+     lifelines          |       []                                  []    |
+     lilypond           |                                           []    |
+     lingoteach         |              []                                 |
+     lynx               |              []         []                []    |
+     m4                 |       []     []      [] []                []    |
+     mailutils          |       []             [] []                      |
+     make               |       []     []         []                []    |
+     man-db             |                      []                   []    |
+     minicom            |       []     []      [] []                      |
+     mysecretdiary      |              []      [] []                []    |
+     nano               |              []      []                   []    |
+     nano_1_0           |       []             [] []                []    |
+     opcodes            |                      []                   []    |
+     parted             |       [] []  []                           []    |
+     psmisc             |       []             []                         |
+     ptx                |       [] []  []      [] []                []    |
+     pwdutils           |       []                                        |
+     python             |                                                 |
+     radius             |       []                []                      |
+     recode             |       []     []      [] []       []       []    |
+     rpm                |       [] []             []                []    |
+     screem             |                                                 |
+     scrollkeeper       |       []             [] []    []    [] [] []    |
+     sed                |       [] []  []      [] []    []       [] []    |
+     sh-utils           |                         []       []    []       |
+     shared-mime-info   |          []  []                     [] [] []    |
+     sharutils          |                         []             [] []    |
+     silky              |                               []                |
+     skencil            |          []  []                           []    |
+     sketch             |          []  []                           []    |
+     solfege            |                                                 |
+     soundtracker       |                               []          []    |
+     sp                 |                                                 |
+     stardict           |                         []    []                |
+     tar                |       []             [] []                []    |
+     texinfo            |       []             [] []                []    |
+     textutils          |                         []       []       []    |
+     tin                |                                                 |
+     tp-robot           |                         []                      |
+     tuxpaint           |       [] []  []      []       []    [] [] []    |
+     unicode-han-tra... |                                                 |
+     unicode-transla... |                                                 |
+     util-linux         |              []         []                []    |
+     vorbis-tools       |                      [] []                      |
+     wastesedge         |                                                 |
+     wdiff              |       []     []      [] []    []          []    |
+     wget               |       [] []  []      [] []    [] []    [] []    |
+     xchat              |                         []    [] [] [] [] []    |
+     xkeyboard-config   |                                                 |
+     xpad               |                                                 |
+                        +-------------------------------------------------+
+                          or pa pl pt pt_BR rm ro ru rw sk sl sq sr sv ta
+                           1  0 48 30  58    6 79 71  5 45 13 12 50 86  0
+
+                          tg th tk tr uk ven vi wa xh zh_CN zh_TW zu
+                        +--------------------------------------------+
+     GNUnet             |                                            |  0
+     a2ps               |          [] []     []                      | 19
+     aegis              |                                            |  0
+     ant-phone          |          []                                |  4
+     anubis             |          []                                |  9
+     ap-utils           |             ()                             |  1
+     aspell             |             []     [] []                   | 13
+     bash               |                                            | 10
+     batchelor          |          []        []                      |  7
+     bfd                |                                            |  1
+     bibshelf           |                    []                      |  5
+     binutils           |          []                                |  6
+     bison              |          []                                | 17
+     bluez-pin          |          [] []     [] []     []            | 24
+     clisp              |                                            |  7
+     console-tools      |          []                                |  4
+     coreutils          |          []                                | 16
+     cpio               |          []        []                      |  6
+     cpplib             |          []        []                      |  7
+     darkstat           |                    []        ()    ()      | 15
+     dialog             |          [] []     []                      | 25
+     diffutils          |          []        []        []    []      | 28
+     doodle             |                    []                      |  5
+     e2fsprogs          |          []                                |  8
+     enscript           |          []                                | 12
+     error              |          []        []              []      | 16
+     fetchmail          |          []                                | 12
+     fileutils          |          []                  []    []      | 18
+     findutils          |          []        []                      | 17
+     flex               |          []        []                      | 15
+     fslint             |                    []                      |  7
+     gas                |          []                                |  3
+     gawk               |          []                                | 14
+     gbiff              |                                            |  4
+     gcal               |          []                                |  5
+     gcc                |          []                                |  3
+     gettext-examples   |          [] []     []        []            | 20
+     gettext-runtime    |          [] []     []        []    []      | 25
+     gettext-tools      |          [] []               []            | 17
+     gimp-print         |             []                             | 11
+     gip                |                    []                      |  8
+     gliv               |          []                                |  6
+     glunarclock        |                    [] []                   | 13
+     gmult              |          []        []        []            | 13
+     gnubiff            |                    []                      |  3
+     gnucash            |          ()                        []      | 10
+     gnucash-glossary   |                                    []      |  8
+     gpe-aerial         |                    []        []            | 13
+     gpe-beam           |                    []        []            | 13
+     gpe-calendar       |                    [] []     []    []      | 18
+     gpe-clock          |          []        [] []     []            | 17
+     gpe-conf           |                    []        []            | 12
+     gpe-contacts       |                    []        []            |  6
+     gpe-edit           |          []        [] []           []      | 15
+     gpe-go             |          []        []                      | 11
+     gpe-login          |          []        [] []     []    []      | 18
+     gpe-ownerinfo      |          []        []        []    []      | 19
+     gpe-sketchbook     |          []        []                      | 14
+     gpe-su             |          []        []        []            | 16
+     gpe-taskmanager    |          []        []        []            | 17
+     gpe-timesheet      |          []        []        []    []      | 17
+     gpe-today          |          []        [] []     []    []      | 19
+     gpe-todo           |                    [] []           []      | 16
+     gphoto2            |             []               []            | 17
+     gprof              |          []        []                      | 10
+     gpsdrive           |                                            |  2
+     gramadoir          |                    []                      |  6
+     grep               |          [] []     []              []      | 32
+     gretl              |                                            |  4
+     gsasl              |                    []        []            | 12
+     gss                |                    []                      |  5
+     gst-plugins        |             []     []                      | 16
+     gstreamer          |          [] []     []                      | 14
+     gtick              |                    []                      | 11
+     gtkspell           |                    [] []     []            | 20
+     hello              |          [] []     []        []            | 37
+     id-utils           |          []        []                      | 13
+     impost             |                    []                      |  3
+     indent             |          []        []        []            | 24
+     iso_3166           |       [] []        []                      | 12
+     iso_3166_1         |          []           []                   | 20
+     iso_3166_2         |                                            |  2
+     iso_3166_3         |                       []     []            |  8
+     iso_4217           |          []        []                      | 10
+     iso_639            |                    [] []                   | 12
+     jpilot             |          [] []               []            |  6
+     jtag               |                                            |  2
+     jwhois             |          []        []              []      | 12
+     kbd                |          []        []                      | 12
+     latrine            |          []        []                      |  8
+     ld                 |          []                                |  5
+     libc               |          []                  []            | 22
+     libextractor       |                                            |  1
+     libgpewidget       |                    [] []                   | 17
+     libgsasl           |                    []                      |  7
+     libiconv           |          [] []     [] []     []            | 32
+     libidn             |                    []        []            |  5
+     lifelines          |                                            |  4
+     lilypond           |          []                                |  5
+     lingoteach         |                                            |  5
+     lynx               |          [] []                             | 14
+     m4                 |                    []        []            | 17
+     mailutils          |             []                             |  7
+     make               |          []                  []            | 18
+     man-db             |                                            |  5
+     minicom            |                                            | 11
+     mysecretdiary      |          []        []                      | 12
+     nano               |                                            | 11
+     nano_1_0           |          [] []                             | 17
+     opcodes            |          []                                |  7
+     parted             |          [] []               []            | 17
+     psmisc             |                    []                      |  7
+     ptx                |          []                  []            | 23
+     pwdutils           |                                            |  1
+     python             |                                            |  0
+     radius             |             []                             |  6
+     recode             |          []        []                      | 22
+     rpm                |          [] []                             | 11
+     screem             |                                            |  1
+     scrollkeeper       |          [] []                             | 23
+     sed                |          []        []                      | 19
+     sh-utils           |          []                                | 15
+     shared-mime-info   |             []               []            | 19
+     sharutils          |          []        []              []      | 20
+     silky              |                                            |  3
+     skencil            |                                            |  6
+     sketch             |                                            |  6
+     solfege            |                                            |  4
+     soundtracker       |          []                                |  8
+     sp                 |          []                                |  3
+     stardict           |             []     []        []    []      | 10
+     tar                |          [] []                             | 13
+     texinfo            |          []                  []            | 14
+     textutils          |          []                  []    []      | 17
+     tin                |                                            |  1
+     tp-robot           |                              []    []      |  7
+     tuxpaint           |          []        [] []     []            | 34
+     unicode-han-tra... |                                            |  0
+     unicode-transla... |                                            |  2
+     util-linux         |          [] []                             | 17
+     vorbis-tools       |             []                             | 10
+     wastesedge         |                                            |  1
+     wdiff              |          []        []                      | 22
+     wget               |          [] []               []    []      | 31
+     xchat              |             []     []        []            | 22
+     xkeyboard-config   |                                            |  1
+     xpad               |                    []                      |  5
+                        +--------------------------------------------+
+       72 teams           tg th tk tr uk ven vi wa xh zh_CN zh_TW zu
+      147 domains          0  0  1 78 29  0  71 16  0  41    20    0  1711
+
+   Some counters in the preceding matrix are higher than the number of
+visible blocks let us expect.  This is because a few extra PO files are
+used for implementing regional variants of languages, or language
+dialects.
+
+   For a PO file in the matrix above to be effective, the package to
+which it applies should also have been internationalized and
+distributed as such by its maintainer.  There might be an observable
+lag between the mere existence a PO file and its wide availability in a
+distribution.
+
+   If April 2005 seems to be old, you may fetch a more recent copy of
+this `ABOUT-NLS' file on most GNU archive sites.  The most up-to-date
+matrix with full percentage details can be found at
+`http://www.iro.umontreal.ca/contrib/po/HTML/matrix.html'.
+
+1.6 Using `gettext' in new packages
+===================================
+
+If you are writing a freely available program and want to
+internationalize it you are welcome to use GNU `gettext' in your
+package.  Of course you have to respect the GNU Library General Public
+License which covers the use of the GNU `gettext' library.  This means
+in particular that even non-free programs can use `libintl' as a shared
+library, whereas only free software can use `libintl' as a static
+library or use modified versions of `libintl'.
+
+   Once the sources are changed appropriately and the setup can handle
+the use of `gettext' the only thing missing are the translations.  The
+Free Translation Project is also available for packages which are not
+developed inside the GNU project.  Therefore the information given above
+applies also for every other Free Software Project.  Contact
+`translation@iro.umontreal.ca' to make the `.pot' files available to
+the translation teams.
+
diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..9450e08
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,11 @@
+Kenichi Handa <handa@m17n.org>
+       Core developer.
+
+Mikiko Nishikimi <nisikimi@m17n.org>
+       Core developer.
+
+Naoto Takahashi <ntakahas@m17n.org>
+       Core developer.
+
+Satoru Tomura <tomura@m17n.org>
+       Core developer.
diff --git a/COPYING b/COPYING
new file mode 100644 (file)
index 0000000..5ab7695
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,504 @@
+                 GNU LESSER GENERAL PUBLIC LICENSE
+                      Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+                           Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it.  You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+  When we speak of free software, we are referring to freedom of use,
+not price.  Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+  To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights.  These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  To protect each distributor, we want to make it very clear that
+there is no warranty for the free library.  Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+\f
+  Finally, software patents pose a constant threat to the existence of
+any free program.  We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder.  Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+  Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License.  This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License.  We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+  When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library.  The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom.  The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+  We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License.  It also provides other free software developers Less
+of an advantage over competing non-free programs.  These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries.  However, the Lesser license provides advantages in certain
+special circumstances.
+
+  For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard.  To achieve this, non-free programs must be
+allowed to use the library.  A more frequent case is that a free
+library does the same job as widely used non-free libraries.  In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+  In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software.  For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+  Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+\f
+                 GNU LESSER GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+  
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+\f
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+\f
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+\f
+  6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Use a suitable shared library mechanism for linking with the
+    Library.  A suitable mechanism is one that (1) uses at run time a
+    copy of the library already present on the user's computer system,
+    rather than copying library functions into the executable, and (2)
+    will operate properly with a modified version of the library, if
+    the user installs one, as long as the modified version is
+    interface-compatible with the version that the work was made with.
+
+    c) Accompany the work with a written offer, valid for at
+    least three years, to give the same user the materials
+    specified in Subsection 6a, above, for a charge no more
+    than the cost of performing this distribution.
+
+    d) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    e) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+\f
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+\f
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded.  In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+\f
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+                           NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                    END OF TERMS AND CONDITIONS
+\f
+           How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.  It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the library's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/ChangeLog b/ChangeLog
new file mode 100644 (file)
index 0000000..0b6040f
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,450 @@
+2010-04-23  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.6.1 released.
+
+2010-04-07  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.pc.in (moduledir): New variable.
+
+       * m17n-flt.pc.in (moduledir): New variable.
+
+       * m17n-shell.pc.in (moduledir): New variable.
+
+       * m17n-core.pc.in (moduledir): New variable.
+
+2010-04-06  Kenichi Handa  <handa@m17n.org>
+
+       * .cvsignore: Add mkinstalldirs, ltmain.sh.
+
+2010-04-04  handa  <handa@m17n.org>
+
+       * configure.ac: Add AC_PROG_LIBTOOL.  Comment out LT_PREREQ and
+       LT_INIT.
+
+2010-04-02  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Version changed to 1.6.1.
+
+2010-03-30  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.6.0 released.
+
+2010-03-30  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Version changed to 1.6.0.
+
+2010-03-19  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Version changed to 1.6.0pre.
+
+2010-02-18  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac (M17N_BINARY_VERSION): New variable.
+       (M17N_MODULE_DIR): New variable.  AC_SUBST it.
+
+2009-11-05  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Check if the OTF library has OTF_drive_gpos2 ().
+
+2009-10-05  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Version changed to 1.6.0.
+       (API_VERSION): Changed to 4.0.4.
+
+2009-08-13  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.5.5 released.
+
+2009-07-29  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Add AC_CONFIG_MACRO_DIR([m4]).  Update by
+       autoupdate program.
+
+       * mkinstalldirs: Removed.
+
+       * bootstrap.sh: Simplified by using autoreconf.
+
+2009-07-28  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Version changed to 1.5.5.
+
+2009-03-02  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.5.4 released.
+
+2009-02-25  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Version changed to 1.5.4.
+
+2008-10-20  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.5.3 released.
+
+2008-09-24  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Versions changed to 1.5.3.
+
+2008-06-23  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.5.2 released.
+
+2008-05-30  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Versions changed to 1.5.2.
+
+2008-01-31  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * Version 1.5.1 released.
+
+2008-01-15  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * configure.ac: Versions changed to 1.5.1.
+
+2007-12-28  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * Version 1.5.0 released.
+
+2007-11-13  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * configure.ac: Version changed to 1.5.0
+       (API_VERSION): Updated to 3:0:3.
+
+       * m17n-config.in: Add FLT support.
+
+2007-10-12  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.pc.in: Don't require m17n-shell.
+
+2007-08-15  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.pc.in (prefix): New file.
+
+       * configure.ac (AC_CONFIG_FILES): Add m17n-flt.pc.
+
+       * Makefile.am (EXTRA_DIST): Add m17n-flt.pc.in.
+       (BASICDATA): Add m17n-flt.pc.
+
+2007-07-13  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.4.0 released.
+
+2007-05-24  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac (HAVE_ANTHY): Use PKG_CHECK_MODULES to check it.
+
+2007-05-16  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Version changed to 1.4.0
+       (API_VERSION): Updated to 2:0:2.
+
+2007-02-28  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Version changed to 1.3.5.
+
+2006-12-14  Kenichi Handa  <handa@m17n.org>
+
+       * .cvsignore: Add INSTALL, depcomp, install-sh, and missing.
+
+2006-12-07  TAKAHASHI Naoto  <ntakahas@m17n.org>
+
+       * Update FSF postal address.
+
+2006-12-06  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.4 released.
+
+2006-09-21  Kenichi Handa  <handa@m17n.org>
+
+       * mkinstalldirs: New file.
+
+       * bootstrap.sh: Don't delete mkinstalldirs.  Change order of
+       calling auto tools.
+
+       * ABOUT-NLS: New file.
+
+       * intl, m4, po: New directories.
+
+2006-09-21  gettextize  <bug-gnu-gettext@gnu.org>
+
+       * Makefile.am (SUBDIRS): Add intl.
+       * configure.ac (AC_CONFIG_FILES): Add intl/Makefile.
+
+2006-09-17  gettextize  <bug-gnu-gettext@gnu.org>
+
+       * Makefile.am (SUBDIRS): Add po.
+       (ACLOCAL_AMFLAGS): New variable.
+       (EXTRA_DIST): Add config.rpath, mkinstalldirs, m4/ChangeLog.
+       * configure.ac (AC_CONFIG_FILES): Add po/Makefile.in.
+
+2006-09-17  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Add AM_GNU_GETTEXT.
+       (GETTEXTDIR): New variable.  AC_SUBST it.
+
+2006-07-19  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Include the result of `libotf-config --cflags` in
+       CPPFLAGS.
+
+2006-07-14  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Version changed to 1.3.4.  Delete args to
+       AM_INIT_AUTOMAKE.
+
+2006-06-23  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (PKGDATA): Don't increment it conditionally.
+
+       * configure.ac: Add "--with-fontconfig" arg.
+
+2006-05-29  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-config.in: For for --libtool.
+
+2006-04-24  TAKAHASHI Naoto  <ntakahas@m17n.org>
+
+       * README: Insert libthai reference site.
+
+2006-02-22  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.3 released.
+
+2006-02-22  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Version changed to 1.3.1.
+       (HAVE_DLOPEN): Fix typo in a message.
+
+2006-02-06  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.2 released.
+
+2006-02-06  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (EXTRA_DIST): Add bootstrap.sh.
+
+2006-02-03  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Version changed to 1.3.1.
+
+2006-01-17  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: If GD library is available, define HAVE_GD as 1 or
+       2 in CONFIG_FLAGS.
+
+2006-01-16  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.1 released.
+
+2006-01-16  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Version changed to 1.3.1.
+
+2005-12-22  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.0 released.
+
+2005-12-22  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Check availability of OTF_check_features.
+
+2005-12-05  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-shell.pc.in (Description): Fix typo.
+
+2005-11-21  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (pkgconfig_DATA): Define it conditionally on
+       WITH_GUI.
+
+       * configure.ac: Handle --with-gui/--without-gui arg.
+
+2005-11-18  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Add --with-libotf option.  Use AC_HELP_STRING.
+
+2005-09-05  Kenichi Handa  <handa@m17n.org>
+
+       * bootstrap.sh: Call automake with -a -c. 
+
+       * configure.ac: Add AM_MAINTAINER_MODE.
+       (X11_LD_FLAGS): New variable.
+       (--with-gd): New AC_ARG_WITH.
+       (HAVE_FRIBIDI_CONFIG): Fix typo for testing it.
+
+2005-09-01  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac (CONFIG_FLAGS): Setup this variable and AC_SUBST it.
+
+2005-08-18  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Version changed to 1.3.0.
+
+2005-05-12  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Define HAVE_X11_XAW_COMMAND explicitly.
+
+2005-04-28  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Check the availability of libXaw.
+
+2005-04-27  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Check libthat at first and if that fail check
+       wordcut library.
+
+2005-04-15  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Check the version of wordcut library and
+       HAVE_WORDCUT or HAVE_WORDCUT_OLD.
+       (DLOPEN_SHLIB_EXT): Define it.
+
+2004-12-27  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.2.0 released.
+
+2004-12-27  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-config.in: Fix documentation.  Doxygen's section name fixed.
+
+2004-12-10  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Versions changed to 1.2.0.
+
+2004-10-14  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac (M17N_EXT_LIBS): New variable to accumulate
+       available external libraries.
+
+2004-10-13  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Check if <freetype/ftbdf.h> is available or not.
+
+2004-10-12  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Use pkg-config (if available) for Xft.
+
+2004-10-11  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.pc.in, m17n-shell.pc.in, m17n-gui.pc.in: New files.
+
+       * configure.ac: Include m17n-core.pc, m17n-shell.pc, and
+       m17n-gui.pc in AC_CONFIG_FILES.
+
+       * Makefile.am (EXTRA_DIST, pkgconfigdir, pkgconfig_DATA): New
+       variables.
+
+2004-08-16  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.1.0 released.
+
+2004-07-06  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-config.in: Cancel previous change.
+
+2004-06-30  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-config.in: Add -lm17n-X and -lm17n-gd if necessary.
+
+2004-06-14  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Check the program m17n-db.
+
+2004-06-03  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Run freetype-config with --libs instead of
+       --libtool.
+
+2004-05-31  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Check the availability of dlopen.  Append
+       $X_CFLAGS to CPPFLAGS.
+
+2004-05-28  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: New variable API_VERSION.
+
+       * m17n-config.in: Accept "GUI" flag and adjusted for the new
+       configuration.
+
+2004-05-27  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Check fontconfig even if Xft is available.  Check
+       gd library.  If Xft is not available, set XFT2_LD_FLAGS to null.
+       Likewise for xml2.
+
+       * bootstrap.sh: Clean old files at first.
+
+2004-05-24  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Fix typo (pkg-conifg ->pkg-config).  Fix
+       AC_CHECK_LIB arg for fontconfig.
+
+2004-05-21  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac (HAVE_FRIBIDI): Unset FRIBIDI_LD_FLAGS if fribidi
+       library is not found.
+
+2004-05-18  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: If libotf is not available, clear OTF_LD_FLAGS.
+       Double quaote several variables.  Even if xft-config is not
+       available, check if Xft library is available.  Setup
+       HAVE_FONTCONFIG.
+
+2004-05-07  Kenichi Handa  <handa@redhat.m17n.org>
+
+       * configure.ac: Fix previous change.  Comment out xom and effence
+       related codes.
+
+2004-05-03  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Use fribidi-config and xft-config if they are
+       available.
+
+2004-04-27  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Check if Xft2 library is available.
+       (OTF_LD_FLAGS): Set to `libotf-config --libs`.
+       (FREETYPE_LD_FLAGS): Set to `freetype-config --libtool`.
+
+2004-03-29  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.0 Patch Level 2 released.
+
+2004-03-29  Kenichi Handa  <handa@etlken2>
+
+       * configure.ac: Version changed to 1.0.2.
+
+2004-03-19  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.0 Patch Level 1 released.
+
+2004-03-19  Kenichi Handa  <handa@m17n.org>
+
+       * configure.ac: Version changed to 1.0.1.
+
+2004-03-01  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.0 released.
+
+\f
+Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+  National Institute of Advanced Industrial Science and Technology (AIST)
+  Registration Number H15PRO112
+
+This file is part of the m17n library.
+
+The m17n 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.1 of
+the License, or (at your option) any later version.
+
+The m17n 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 the m17n library; if not, write to the Free
+Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
diff --git a/INSTALL b/INSTALL
new file mode 100644 (file)
index 0000000..2550dab
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,302 @@
+Installation Instructions
+*************************
+
+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
+2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+
+   This file is free documentation; the Free Software Foundation gives
+unlimited permission to copy, distribute and modify it.
+
+Basic Installation
+==================
+
+   Briefly, the shell commands `./configure; make; make install' should
+configure, build, and install this package.  The following
+more-detailed instructions are generic; see the `README' file for
+instructions specific to this package.
+
+   The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation.  It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions.  Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, and a
+file `config.log' containing compiler output (useful mainly for
+debugging `configure').
+
+   It can also use an optional file (typically called `config.cache'
+and enabled with `--cache-file=config.cache' or simply `-C') that saves
+the results of its tests to speed up reconfiguring.  Caching is
+disabled by default to prevent problems with accidental use of stale
+cache files.
+
+   If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release.  If you are using the cache, and at
+some point `config.cache' contains results you don't want to keep, you
+may remove or edit it.
+
+   The file `configure.ac' (or `configure.in') is used to create
+`configure' by a program called `autoconf'.  You need `configure.ac' if
+you want to change it or regenerate `configure' using a newer version
+of `autoconf'.
+
+The simplest way to compile this package is:
+
+  1. `cd' to the directory containing the package's source code and type
+     `./configure' to configure the package for your system.
+
+     Running `configure' might take a while.  While running, it prints
+     some messages telling which features it is checking for.
+
+  2. Type `make' to compile the package.
+
+  3. Optionally, type `make check' to run any self-tests that come with
+     the package.
+
+  4. Type `make install' to install the programs and any data files and
+     documentation.
+
+  5. You can remove the program binaries and object files from the
+     source code directory by typing `make clean'.  To also remove the
+     files that `configure' created (so you can compile the package for
+     a different kind of computer), type `make distclean'.  There is
+     also a `make maintainer-clean' target, but that is intended mainly
+     for the package's developers.  If you use it, you may have to get
+     all sorts of other programs in order to regenerate files that came
+     with the distribution.
+
+  6. Often, you can also type `make uninstall' to remove the installed
+     files again.
+
+Compilers and Options
+=====================
+
+   Some systems require unusual options for compilation or linking that
+the `configure' script does not know about.  Run `./configure --help'
+for details on some of the pertinent environment variables.
+
+   You can give `configure' initial values for configuration parameters
+by setting variables in the command line or in the environment.  Here
+is an example:
+
+     ./configure CC=c99 CFLAGS=-g LIBS=-lposix
+
+   *Note Defining Variables::, for more details.
+
+Compiling For Multiple Architectures
+====================================
+
+   You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory.  To do this, you can use GNU `make'.  `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script.  `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+   With a non-GNU `make', it is safer to compile the package for one
+architecture at a time in the source code directory.  After you have
+installed the package for one architecture, use `make distclean' before
+reconfiguring for another architecture.
+
+   On MacOS X 10.5 and later systems, you can create libraries and
+executables that work on multiple system types--known as "fat" or
+"universal" binaries--by specifying multiple `-arch' options to the
+compiler but only a single `-arch' option to the preprocessor.  Like
+this:
+
+     ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
+                 CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
+                 CPP="gcc -E" CXXCPP="g++ -E"
+
+   This is not guaranteed to produce working output in all cases, you
+may have to build one architecture at a time and combine the results
+using the `lipo' tool if you have problems.
+
+Installation Names
+==================
+
+   By default, `make install' installs the package's commands under
+`/usr/local/bin', include files under `/usr/local/include', etc.  You
+can specify an installation prefix other than `/usr/local' by giving
+`configure' the option `--prefix=PREFIX'.
+
+   You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files.  If you
+pass the option `--exec-prefix=PREFIX' to `configure', the package uses
+PREFIX as the prefix for installing programs and libraries.
+Documentation and other data files still use the regular prefix.
+
+   In addition, if you use an unusual directory layout you can give
+options like `--bindir=DIR' to specify different values for particular
+kinds of files.  Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+   If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+   Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System).  The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+   For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Particular systems
+==================
+
+   On HP-UX, the default C compiler is not ANSI C compatible.  If GNU
+CC is not installed, it is recommended to use the following options in
+order to use an ANSI C compiler:
+
+     ./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
+
+and if that doesn't work, install pre-built binaries of GCC for HP-UX.
+
+   On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
+parse its `<wchar.h>' header file.  The option `-nodtk' can be used as
+a workaround.  If GNU CC is not installed, it is therefore recommended
+to try
+
+     ./configure CC="cc"
+
+and if that doesn't work, try
+
+     ./configure CC="cc -nodtk"
+
+   On Solaris, don't put `/usr/ucb' early in your `PATH'.  This
+directory contains several dysfunctional programs; working variants of
+these programs are available in `/usr/bin'.  So, if you need `/usr/ucb'
+in your `PATH', put it _after_ `/usr/bin'.
+
+   On Haiku, software installed for all users goes in `/boot/common',
+not `/usr/local'.  It is recommended to use the following options:
+
+     ./configure --prefix=/boot/common
+
+Specifying the System Type
+==========================
+
+   There may be some features `configure' cannot figure out
+automatically, but needs to determine by the type of machine the package
+will run on.  Usually, assuming the package is built to be run on the
+_same_ architectures, `configure' can figure that out, but if it prints
+a message saying it cannot guess the machine type, give it the
+`--build=TYPE' option.  TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name which has the form:
+
+     CPU-COMPANY-SYSTEM
+
+where SYSTEM can have one of these forms:
+
+     OS
+     KERNEL-OS
+
+   See the file `config.sub' for the possible values of each field.  If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the machine type.
+
+   If you are _building_ compiler tools for cross-compiling, you should
+use the option `--target=TYPE' to select the type of system they will
+produce code for.
+
+   If you want to _use_ a cross compiler, that generates code for a
+platform different from the build platform, you should specify the
+"host" platform (i.e., that on which the generated programs will
+eventually be run) with `--host=TYPE'.
+
+Sharing Defaults
+================
+
+   If you want to set default values for `configure' scripts to share,
+you can create a site shell script called `config.site' that gives
+default values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists.  Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Defining Variables
+==================
+
+   Variables not defined in a site shell script can be set in the
+environment passed to `configure'.  However, some packages may run
+configure again during the build, and the customized values of these
+variables may be lost.  In order to avoid this problem, you should set
+them in the `configure' command line, using `VAR=value'.  For example:
+
+     ./configure CC=/usr/local2/bin/gcc
+
+causes the specified `gcc' to be used as the C compiler (unless it is
+overridden in the site shell script).
+
+Unfortunately, this technique does not work for `CONFIG_SHELL' due to
+an Autoconf bug.  Until the bug is fixed you can use this workaround:
+
+     CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
+
+`configure' Invocation
+======================
+
+   `configure' recognizes the following options to control how it
+operates.
+
+`--help'
+`-h'
+     Print a summary of all of the options to `configure', and exit.
+
+`--help=short'
+`--help=recursive'
+     Print a summary of the options unique to this package's
+     `configure', and exit.  The `short' variant lists options used
+     only in the top level, while the `recursive' variant lists options
+     also present in any nested packages.
+
+`--version'
+`-V'
+     Print the version of Autoconf used to generate the `configure'
+     script, and exit.
+
+`--cache-file=FILE'
+     Enable the cache: use and save the results of the tests in FILE,
+     traditionally `config.cache'.  FILE defaults to `/dev/null' to
+     disable caching.
+
+`--config-cache'
+`-C'
+     Alias for `--cache-file=config.cache'.
+
+`--quiet'
+`--silent'
+`-q'
+     Do not print messages saying which checks are being made.  To
+     suppress all normal output, redirect it to `/dev/null' (any error
+     messages will still be shown).
+
+`--srcdir=DIR'
+     Look for the package's source code in directory DIR.  Usually
+     `configure' can determine that directory automatically.
+
+`--prefix=DIR'
+     Use DIR as the installation prefix.  *Note Installation Names::
+     for more details, including other options available for fine-tuning
+     the installation locations.
+
+`--no-create'
+`-n'
+     Run the configure checks, but stop before creating any output
+     files.
+
+`configure' also accepts some other, not widely useful, options.  Run
+`configure --help' for more details.
+
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..66687f7
--- /dev/null
@@ -0,0 +1,42 @@
+# Makefile.am -- top level Makefile for the m17n library.
+# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+#   National Institute of Advanced Industrial Science and Technology (AIST)
+#   Registration Number H15PRO112
+
+# This file is part of the m17n library.
+
+# The m17n 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.1 of
+# the License, or (at your option) any later version.
+
+# The m17n 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 the m17n library; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+## Process this file with Automake to create Makefile.in
+
+SUBDIRS = intl po src example
+
+bin_SCRIPTS = m17n-config
+
+EXTRA_DIST = m4/ChangeLog config.rpath mkinstalldirs \
+       m17n-core.pc.in m17n-shell.pc.in m17n-flt.pc.in m17n-gui.pc.in bootstrap.sh
+
+pkgconfigdir = ${libdir}/pkgconfig
+
+BASICDATA = m17n-core.pc m17n-shell.pc m17n-flt.pc
+if WITH_GUI
+PKGDATA = $(BASICDATA) m17n-gui.pc
+else
+PKGDATA = $(BASICDATA)
+endif
+pkgconfig_DATA = $(PKGDATA)
+
+ACLOCAL_AMFLAGS = -I m4
diff --git a/Makefile.in b/Makefile.in
new file mode 100644 (file)
index 0000000..429eda9
--- /dev/null
@@ -0,0 +1,915 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  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@
+
+# Makefile.am -- top level Makefile for the m17n library.
+# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+#   National Institute of Advanced Industrial Science and Technology (AIST)
+#   Registration Number H15PRO112
+
+# This file is part of the m17n library.
+
+# The m17n 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.1 of
+# the License, or (at your option) any later version.
+
+# The m17n 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 the m17n library; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+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@
+subdir = .
+DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
+       $(srcdir)/Makefile.in $(srcdir)/m17n-config.in \
+       $(srcdir)/m17n-core.pc.in $(srcdir)/m17n-flt.pc.in \
+       $(srcdir)/m17n-gui.pc.in $(srcdir)/m17n-shell.pc.in \
+       $(top_srcdir)/configure $(top_srcdir)/intl/Makefile.in \
+       ABOUT-NLS AUTHORS COPYING ChangeLog INSTALL NEWS TODO \
+       config.guess config.rpath config.sub depcomp install-sh \
+       ltmain.sh missing mkinstalldirs
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/codeset.m4 \
+       $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/glibc2.m4 \
+       $(top_srcdir)/m4/glibc21.m4 $(top_srcdir)/m4/iconv.m4 \
+       $(top_srcdir)/m4/intdiv0.m4 $(top_srcdir)/m4/intmax.m4 \
+       $(top_srcdir)/m4/inttypes-pri.m4 $(top_srcdir)/m4/inttypes.m4 \
+       $(top_srcdir)/m4/inttypes_h.m4 $(top_srcdir)/m4/isc-posix.m4 \
+       $(top_srcdir)/m4/lcmessage.m4 $(top_srcdir)/m4/lib-ld.m4 \
+       $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
+       $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/longdouble.m4 \
+       $(top_srcdir)/m4/longlong.m4 $(top_srcdir)/m4/ltoptions.m4 \
+       $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+       $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \
+       $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/printf-posix.m4 \
+       $(top_srcdir)/m4/progtest.m4 $(top_srcdir)/m4/signed.m4 \
+       $(top_srcdir)/m4/size_max.m4 $(top_srcdir)/m4/stdint_h.m4 \
+       $(top_srcdir)/m4/uintmax_t.m4 $(top_srcdir)/m4/ulonglong.m4 \
+       $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/m4/wint_t.m4 \
+       $(top_srcdir)/m4/xsize.m4 $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+       $(ACLOCAL_M4)
+am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
+ configure.lineno config.status.lineno
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/src/config.h
+CONFIG_CLEAN_FILES = intl/Makefile m17n-config m17n-core.pc \
+       m17n-shell.pc m17n-flt.pc m17n-gui.pc
+CONFIG_CLEAN_VPATH_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 = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(pkgconfigdir)"
+SCRIPTS = $(bin_SCRIPTS)
+SOURCES =
+DIST_SOURCES =
+RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
+       html-recursive info-recursive install-data-recursive \
+       install-dvi-recursive install-exec-recursive \
+       install-html-recursive install-info-recursive \
+       install-pdf-recursive install-ps-recursive install-recursive \
+       installcheck-recursive installdirs-recursive pdf-recursive \
+       ps-recursive uninstall-recursive
+DATA = $(pkgconfig_DATA)
+RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive        \
+  distclean-recursive maintainer-clean-recursive
+AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
+       $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
+       distdir dist dist-all distcheck
+ETAGS = etags
+CTAGS = ctags
+DIST_SUBDIRS = $(SUBDIRS)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+distdir = $(PACKAGE)-$(VERSION)
+top_distdir = $(distdir)
+am__remove_distdir = \
+  { test ! -d "$(distdir)" \
+    || { find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
+         && rm -fr "$(distdir)"; }; }
+am__relativize = \
+  dir0=`pwd`; \
+  sed_first='s,^\([^/]*\)/.*$$,\1,'; \
+  sed_rest='s,^[^/]*/*,,'; \
+  sed_last='s,^.*/\([^/]*\)$$,\1,'; \
+  sed_butlast='s,/*[^/]*$$,,'; \
+  while test -n "$$dir1"; do \
+    first=`echo "$$dir1" | sed -e "$$sed_first"`; \
+    if test "$$first" != "."; then \
+      if test "$$first" = ".."; then \
+        dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \
+        dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \
+      else \
+        first2=`echo "$$dir2" | sed -e "$$sed_first"`; \
+        if test "$$first2" = "$$first"; then \
+          dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \
+        else \
+          dir2="../$$dir2"; \
+        fi; \
+        dir0="$$dir0"/"$$first"; \
+      fi; \
+    fi; \
+    dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
+  done; \
+  reldir="$$dir2"
+DIST_ARCHIVES = $(distdir).tar.gz
+GZIP_ENV = --best
+distuninstallcheck_listfiles = find . -type f -print
+distcleancheck_listfiles = find . -type f -print
+ACLOCAL = @ACLOCAL@
+ALLOCA = @ALLOCA@
+AMTAR = @AMTAR@
+ANTHY_CFLAGS = @ANTHY_CFLAGS@
+ANTHY_LD_FLAGS = @ANTHY_LD_FLAGS@
+ANTHY_LIBS = @ANTHY_LIBS@
+API_VERSION = @API_VERSION@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@
+CATOBJEXT = @CATOBJEXT@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CONFIG_FLAGS = @CONFIG_FLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DATADIRNAME = @DATADIRNAME@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+FONTCONFIG_LD_FLAGS = @FONTCONFIG_LD_FLAGS@
+FREETYPE_LD_FLAGS = @FREETYPE_LD_FLAGS@
+FRIBIDI_LD_FLAGS = @FRIBIDI_LD_FLAGS@
+GD_LD_FLAGS = @GD_LD_FLAGS@
+GENCAT = @GENCAT@
+GETTEXTDIR = @GETTEXTDIR@
+GLIBC2 = @GLIBC2@
+GLIBC21 = @GLIBC21@
+GLIB_2_0_CFLAGS = @GLIB_2_0_CFLAGS@
+GLIB_2_0_LIBS = @GLIB_2_0_LIBS@
+GMSGFMT = @GMSGFMT@
+GREP = @GREP@
+HAVE_ASPRINTF = @HAVE_ASPRINTF@
+HAVE_FREETYPE_CONFIG = @HAVE_FREETYPE_CONFIG@
+HAVE_FRIBIDI_CONFIG = @HAVE_FRIBIDI_CONFIG@
+HAVE_ISPELL = @HAVE_ISPELL@
+HAVE_M17N_DB = @HAVE_M17N_DB@
+HAVE_OTFLIB_CONFIG = @HAVE_OTFLIB_CONFIG@
+HAVE_PKG_CONFIG = @HAVE_PKG_CONFIG@
+HAVE_POSIX_PRINTF = @HAVE_POSIX_PRINTF@
+HAVE_SNPRINTF = @HAVE_SNPRINTF@
+HAVE_WPRINTF = @HAVE_WPRINTF@
+HAVE_XFT_CONFIG = @HAVE_XFT_CONFIG@
+HAVE_XML2_CONFIG = @HAVE_XML2_CONFIG@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+INSTOBJEXT = @INSTOBJEXT@
+INTLBISON = @INTLBISON@
+INTLLIBS = @INTLLIBS@
+INTLOBJS = @INTLOBJS@
+INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@
+INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBICONV = @LIBICONV@
+LIBINTL = @LIBINTL@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTHAI_CFLAGS = @LIBTHAI_CFLAGS@
+LIBTHAI_LIBS = @LIBTHAI_LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBICONV = @LTLIBICONV@
+LTLIBINTL = @LTLIBINTL@
+LTLIBOBJS = @LTLIBOBJS@
+M17NDIR = @M17NDIR@
+M17N_MODULE_DIR = @M17N_MODULE_DIR@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+MKINSTALLDIRS = @MKINSTALLDIRS@
+MSGFMT = @MSGFMT@
+MSGMERGE = @MSGMERGE@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTF_LD_FLAGS = @OTF_LD_FLAGS@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+POSUB = @POSUB@
+POW_LIB = @POW_LIB@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+THAI_WORDSEG_LD_FLAGS = @THAI_WORDSEG_LD_FLAGS@
+USE_INCLUDED_LIBINTL = @USE_INCLUDED_LIBINTL@
+USE_NLS = @USE_NLS@
+VERSION = @VERSION@
+WORDCUT_CFLAGS = @WORDCUT_CFLAGS@
+WORDCUT_LIBS = @WORDCUT_LIBS@
+X11_LD_FLAGS = @X11_LD_FLAGS@
+XAW_LD_FLAGS = @XAW_LD_FLAGS@
+XFT2_LD_FLAGS = @XFT2_LD_FLAGS@
+XGETTEXT = @XGETTEXT@
+XMKMF = @XMKMF@
+XML2_LD_FLAGS = @XML2_LD_FLAGS@
+X_CFLAGS = @X_CFLAGS@
+X_EXTRA_LIBS = @X_EXTRA_LIBS@
+X_LIBS = @X_LIBS@
+X_PRE_LIBS = @X_PRE_LIBS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+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@
+builddir = @builddir@
+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@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+SUBDIRS = intl po src example
+bin_SCRIPTS = m17n-config
+EXTRA_DIST = m4/ChangeLog config.rpath mkinstalldirs \
+       m17n-core.pc.in m17n-shell.pc.in m17n-flt.pc.in m17n-gui.pc.in bootstrap.sh
+
+pkgconfigdir = ${libdir}/pkgconfig
+BASICDATA = m17n-core.pc m17n-shell.pc m17n-flt.pc
+@WITH_GUI_FALSE@PKGDATA = $(BASICDATA)
+@WITH_GUI_TRUE@PKGDATA = $(BASICDATA) m17n-gui.pc
+pkgconfig_DATA = $(PKGDATA)
+ACLOCAL_AMFLAGS = -I m4
+all: all-recursive
+
+.SUFFIXES:
+am--refresh:
+       @:
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+       @for dep in $?; do \
+         case '$(am__configure_deps)' in \
+           *$$dep*) \
+             echo ' cd $(srcdir) && $(AUTOMAKE) --gnu'; \
+             $(am__cd) $(srcdir) && $(AUTOMAKE) --gnu \
+               && exit 0; \
+             exit 1;; \
+         esac; \
+       done; \
+       echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \
+       $(am__cd) $(top_srcdir) && \
+         $(AUTOMAKE) --gnu Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+       @case '$?' in \
+         *config.status*) \
+           echo ' $(SHELL) ./config.status'; \
+           $(SHELL) ./config.status;; \
+         *) \
+           echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
+           cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \
+       esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+       $(SHELL) ./config.status --recheck
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+       $(am__cd) $(srcdir) && $(AUTOCONF)
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+       $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
+$(am__aclocal_m4_deps):
+intl/Makefile: $(top_builddir)/config.status $(top_srcdir)/intl/Makefile.in
+       cd $(top_builddir) && $(SHELL) ./config.status $@
+m17n-config: $(top_builddir)/config.status $(srcdir)/m17n-config.in
+       cd $(top_builddir) && $(SHELL) ./config.status $@
+m17n-core.pc: $(top_builddir)/config.status $(srcdir)/m17n-core.pc.in
+       cd $(top_builddir) && $(SHELL) ./config.status $@
+m17n-shell.pc: $(top_builddir)/config.status $(srcdir)/m17n-shell.pc.in
+       cd $(top_builddir) && $(SHELL) ./config.status $@
+m17n-flt.pc: $(top_builddir)/config.status $(srcdir)/m17n-flt.pc.in
+       cd $(top_builddir) && $(SHELL) ./config.status $@
+m17n-gui.pc: $(top_builddir)/config.status $(srcdir)/m17n-gui.pc.in
+       cd $(top_builddir) && $(SHELL) ./config.status $@
+install-binSCRIPTS: $(bin_SCRIPTS)
+       @$(NORMAL_INSTALL)
+       test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
+       @list='$(bin_SCRIPTS)'; test -n "$(bindir)" || list=; \
+       for p in $$list; do \
+         if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+         if test -f "$$d$$p"; then echo "$$d$$p"; echo "$$p"; else :; fi; \
+       done | \
+       sed -e 'p;s,.*/,,;n' \
+           -e 'h;s|.*|.|' \
+           -e 'p;x;s,.*/,,;$(transform)' | sed 'N;N;N;s,\n, ,g' | \
+       $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1; } \
+         { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+           if ($$2 == $$4) { files[d] = files[d] " " $$1; \
+             if (++n[d] == $(am__install_max)) { \
+               print "f", d, files[d]; n[d] = 0; files[d] = "" } } \
+           else { print "f", d "/" $$4, $$1 } } \
+         END { for (d in files) print "f", d, files[d] }' | \
+       while read type dir files; do \
+            if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+            test -z "$$files" || { \
+              echo " $(INSTALL_SCRIPT) $$files '$(DESTDIR)$(bindir)$$dir'"; \
+              $(INSTALL_SCRIPT) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
+            } \
+       ; done
+
+uninstall-binSCRIPTS:
+       @$(NORMAL_UNINSTALL)
+       @list='$(bin_SCRIPTS)'; test -n "$(bindir)" || exit 0; \
+       files=`for p in $$list; do echo "$$p"; done | \
+              sed -e 's,.*/,,;$(transform)'`; \
+       test -n "$$list" || exit 0; \
+       echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
+       cd "$(DESTDIR)$(bindir)" && rm -f $$files
+
+mostlyclean-libtool:
+       -rm -f *.lo
+
+clean-libtool:
+       -rm -rf .libs _libs
+
+distclean-libtool:
+       -rm -f libtool config.lt
+install-pkgconfigDATA: $(pkgconfig_DATA)
+       @$(NORMAL_INSTALL)
+       test -z "$(pkgconfigdir)" || $(MKDIR_P) "$(DESTDIR)$(pkgconfigdir)"
+       @list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \
+       for p in $$list; do \
+         if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+         echo "$$d$$p"; \
+       done | $(am__base_list) | \
+       while read files; do \
+         echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pkgconfigdir)'"; \
+         $(INSTALL_DATA) $$files "$(DESTDIR)$(pkgconfigdir)" || exit $$?; \
+       done
+
+uninstall-pkgconfigDATA:
+       @$(NORMAL_UNINSTALL)
+       @list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \
+       files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+       test -n "$$files" || exit 0; \
+       echo " ( cd '$(DESTDIR)$(pkgconfigdir)' && rm -f" $$files ")"; \
+       cd "$(DESTDIR)$(pkgconfigdir)" && rm -f $$files
+
+# 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; \
+         ($(am__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"
+
+$(RECURSIVE_CLEAN_TARGETS):
+       @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; \
+         ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+         || eval $$failcom; \
+       done && test -z "$$fail"
+tags-recursive:
+       list='$(SUBDIRS)'; for subdir in $$list; do \
+         test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
+       done
+ctags-recursive:
+       list='$(SUBDIRS)'; for subdir in $$list; do \
+         test "$$subdir" = . || ($(am__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; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       mkid -fID $$unique
+tags: TAGS
+
+TAGS: tags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+               $(TAGS_FILES) $(LISP)
+       set x; \
+       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 || \
+             set "$$@" "$$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; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       shift; \
+       if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+         test -n "$$unique" || unique=$$empty_fix; \
+         if test $$# -gt 0; then \
+           $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+             "$$@" $$unique; \
+         else \
+           $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+             $$unique; \
+         fi; \
+       fi
+ctags: CTAGS
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+               $(TAGS_FILES) $(LISP)
+       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; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       test -z "$(CTAGS_ARGS)$$unique" \
+         || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+            $$unique
+
+GTAGS:
+       here=`$(am__cd) $(top_builddir) && pwd` \
+         && $(am__cd) $(top_srcdir) \
+         && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+       -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+       $(am__remove_distdir)
+       test -d "$(distdir)" || mkdir "$(distdir)"
+       @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       list='$(DISTFILES)'; \
+         dist_files=`for file in $$list; do echo $$file; done | \
+         sed -e "s|^$$srcdirstrip/||;t" \
+             -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+       case $$dist_files in \
+         */*) $(MKDIR_P) `echo "$$dist_files" | \
+                          sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+                          sort -u` ;; \
+       esac; \
+       for file in $$dist_files; do \
+         if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+         if test -d $$d/$$file; then \
+           dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+           if test -d "$(distdir)/$$file"; then \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+             cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           cp -fpR $$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; \
+         fi; \
+       done
+       @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+         if test "$$subdir" = .; then :; else \
+           dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
+           $(am__relativize); \
+           new_distdir=$$reldir; \
+           dir1=$$subdir; dir2="$(top_distdir)"; \
+           $(am__relativize); \
+           new_top_distdir=$$reldir; \
+           echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \
+           echo "     am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \
+           ($(am__cd) $$subdir && \
+             $(MAKE) $(AM_MAKEFLAGS) \
+               top_distdir="$$new_top_distdir" \
+               distdir="$$new_distdir" \
+               am__remove_distdir=: \
+               am__skip_length_check=: \
+               am__skip_mode_fix=: \
+               distdir) \
+             || exit 1; \
+         fi; \
+       done
+       -test -n "$(am__skip_mode_fix)" \
+       || find "$(distdir)" -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
+         ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
+         ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
+         ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \
+       || chmod -R a+r "$(distdir)"
+dist-gzip: distdir
+       tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+       $(am__remove_distdir)
+
+dist-bzip2: distdir
+       tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
+       $(am__remove_distdir)
+
+dist-lzma: distdir
+       tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma
+       $(am__remove_distdir)
+
+dist-xz: distdir
+       tardir=$(distdir) && $(am__tar) | xz -c >$(distdir).tar.xz
+       $(am__remove_distdir)
+
+dist-tarZ: distdir
+       tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
+       $(am__remove_distdir)
+
+dist-shar: distdir
+       shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
+       $(am__remove_distdir)
+
+dist-zip: distdir
+       -rm -f $(distdir).zip
+       zip -rq $(distdir).zip $(distdir)
+       $(am__remove_distdir)
+
+dist dist-all: distdir
+       tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+       $(am__remove_distdir)
+
+# This target untars the dist file and tries a VPATH configuration.  Then
+# it guarantees that the distribution is self-contained by making another
+# tarfile.
+distcheck: dist
+       case '$(DIST_ARCHIVES)' in \
+       *.tar.gz*) \
+         GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(am__untar) ;;\
+       *.tar.bz2*) \
+         bunzip2 -c $(distdir).tar.bz2 | $(am__untar) ;;\
+       *.tar.lzma*) \
+         unlzma -c $(distdir).tar.lzma | $(am__untar) ;;\
+       *.tar.xz*) \
+         xz -dc $(distdir).tar.xz | $(am__untar) ;;\
+       *.tar.Z*) \
+         uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
+       *.shar.gz*) \
+         GZIP=$(GZIP_ENV) gunzip -c $(distdir).shar.gz | unshar ;;\
+       *.zip*) \
+         unzip $(distdir).zip ;;\
+       esac
+       chmod -R a-w $(distdir); chmod a+w $(distdir)
+       mkdir $(distdir)/_build
+       mkdir $(distdir)/_inst
+       chmod a-w $(distdir)
+       test -d $(distdir)/_build || exit 0; \
+       dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
+         && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
+         && am__cwd=`pwd` \
+         && $(am__cd) $(distdir)/_build \
+         && ../configure --srcdir=.. --prefix="$$dc_install_base" \
+           --with-included-gettext \
+           $(DISTCHECK_CONFIGURE_FLAGS) \
+         && $(MAKE) $(AM_MAKEFLAGS) \
+         && $(MAKE) $(AM_MAKEFLAGS) dvi \
+         && $(MAKE) $(AM_MAKEFLAGS) check \
+         && $(MAKE) $(AM_MAKEFLAGS) install \
+         && $(MAKE) $(AM_MAKEFLAGS) installcheck \
+         && $(MAKE) $(AM_MAKEFLAGS) uninstall \
+         && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
+               distuninstallcheck \
+         && chmod -R a-w "$$dc_install_base" \
+         && ({ \
+              (cd ../.. && umask 077 && mkdir "$$dc_destdir") \
+              && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \
+              && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \
+              && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \
+                   distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \
+             } || { rm -rf "$$dc_destdir"; exit 1; }) \
+         && rm -rf "$$dc_destdir" \
+         && $(MAKE) $(AM_MAKEFLAGS) dist \
+         && rm -rf $(DIST_ARCHIVES) \
+         && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \
+         && cd "$$am__cwd" \
+         || exit 1
+       $(am__remove_distdir)
+       @(echo "$(distdir) archives ready for distribution: "; \
+         list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
+         sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x'
+distuninstallcheck:
+       @$(am__cd) '$(distuninstallcheck_dir)' \
+       && test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
+          || { echo "ERROR: files left after uninstall:" ; \
+               if test -n "$(DESTDIR)"; then \
+                 echo "  (check DESTDIR support)"; \
+               fi ; \
+               $(distuninstallcheck_listfiles) ; \
+               exit 1; } >&2
+distcleancheck: distclean
+       @if test '$(srcdir)' = . ; then \
+         echo "ERROR: distcleancheck can only run from a VPATH build" ; \
+         exit 1 ; \
+       fi
+       @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
+         || { echo "ERROR: files left in build directory after distclean:" ; \
+              $(distcleancheck_listfiles) ; \
+              exit 1; } >&2
+check-am: all-am
+check: check-recursive
+all-am: Makefile $(SCRIPTS) $(DATA)
+installdirs: installdirs-recursive
+installdirs-am:
+       for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(pkgconfigdir)"; 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)
+       -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_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-generic clean-libtool mostlyclean-am
+
+distclean: distclean-recursive
+       -rm -f $(am__CONFIG_DISTCLEAN_FILES)
+       -rm -f Makefile
+distclean-am: clean-am distclean-generic distclean-libtool \
+       distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+html: html-recursive
+
+html-am:
+
+info: info-recursive
+
+info-am:
+
+install-data-am: install-pkgconfigDATA
+
+install-dvi: install-dvi-recursive
+
+install-dvi-am:
+
+install-exec-am: install-binSCRIPTS
+
+install-html: install-html-recursive
+
+install-html-am:
+
+install-info: install-info-recursive
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-recursive
+
+install-pdf-am:
+
+install-ps: install-ps-recursive
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+       -rm -f $(am__CONFIG_DISTCLEAN_FILES)
+       -rm -rf $(top_srcdir)/autom4te.cache
+       -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-generic mostlyclean-libtool
+
+pdf: pdf-recursive
+
+pdf-am:
+
+ps: ps-recursive
+
+ps-am:
+
+uninstall-am: uninstall-binSCRIPTS uninstall-pkgconfigDATA
+
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \
+       install-am install-strip tags-recursive
+
+.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
+       all all-am am--refresh check check-am clean clean-generic \
+       clean-libtool ctags ctags-recursive dist dist-all dist-bzip2 \
+       dist-gzip dist-lzma dist-shar dist-tarZ dist-xz dist-zip \
+       distcheck distclean distclean-generic distclean-libtool \
+       distclean-tags distcleancheck distdir distuninstallcheck dvi \
+       dvi-am html html-am info info-am install install-am \
+       install-binSCRIPTS install-data install-data-am install-dvi \
+       install-dvi-am install-exec install-exec-am install-html \
+       install-html-am install-info install-info-am install-man \
+       install-pdf install-pdf-am install-pkgconfigDATA install-ps \
+       install-ps-am install-strip installcheck installcheck-am \
+       installdirs installdirs-am maintainer-clean \
+       maintainer-clean-generic mostlyclean mostlyclean-generic \
+       mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \
+       uninstall uninstall-am uninstall-binSCRIPTS \
+       uninstall-pkgconfigDATA
+
+
+# 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/NEWS b/NEWS
new file mode 100644 (file)
index 0000000..ae30502
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,236 @@
+* NEWS -- What's new in the m17n library.                      -*- outline -*-
+Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+  National Institute of Advanced Industrial Science and Technology (AIST)
+  Registration Number H15PRO112
+See the end for copying conditions.
+
+\f
+* Changes in the m17n library 1.6.0
+
+** Libtool 1.5.26 can be used to build the library from CVS source.
+
+\f
+* Changes in the m17n library 1.6.0
+
+** For handling new spec in the Unicode 5.2, these new APIs are added
+to m17n-flt.h.
+   mflt_enable_new_feature
+   mflt_iterate_otf_feature
+   mflt_font_id
+   mflt_try_otf
+
+\f
+* Changes in the m17n library 1.5.5
+
+** Now libtool 2.2.4 or the later is required to build the library
+from CVS source.
+
+\f
+* Changes in the m17n library 1.5.4
+
+** New coding system names "Shift_JIS" and "windows-XXXX" are
+recognized.
+
+\f
+* Changes in the m17n library 1.5.3
+
+This release is just for bug fixing.
+
+\f
+* Changes in the m17n library 1.5.2
+
+This release is just for bug fixing.
+
+\f
+* Changes in the m17n library 1.5.1
+
+This release is just for bug fixing.
+
+\f
+* Changes in the m17n library 1.5.0
+
+** New API layer FLT is created.
+
+** New environment variable MDEBUG_FLT is available to turn on
+printing debug information for FLT, and these are now obsolete;
+MDEBUG_FONT_FLT, MDEBUG_FONT_OTF.
+
+** New functions mchartable_min_char () returns the mininum character.
+that is set some value in a char-table.  New funcion
+mchartable_min_char () is for the maximum character.
+
+\f
+* Changes in the m17n library 1.4.0
+
+** If the environment variable "M17NDIR" is not set, the directory
+"~/.m17n.d" is serched for database files.
+
+** New function mfont_list_family_names () returns a list of available
+font family names.
+
+** New functions mlanguage_list (), mlanguage_code (),
+mlanguage_name_list (), and mlanguage_text () return various
+language-related information.
+
+** New functions mscript_list () and mscript_language_list () return
+various script-related information.
+
+** New function msymbol_put_func (), msymbol_get_func (),
+mplist_put_func (), mplist_get_func (), mface_put_hook (), and
+mface_get_hook () are available to avoid unsafe casting of function
+pointer.  New macro M17N_FUNC and new type M17NFunc are also
+introduced.
+
+\f
+* Changes in the m17n library 1.3.0
+
+** The `configure' script accepts the argument "--without-gui" to
+suppress building GUI libraries.
+
+** The environment variable MDEBUG_OUTPUT_FILE can specify a file to
+output the debugging log messages.
+
+** The member `candidate_changed' of MInputContext carries more
+information; i.e. the list itself is changed, only an index is
+changed, etc.
+
+** The member `callback_list' of MInputDriver can have callback
+functions `input-get-surrounding-text' and
+`input-delete-surrounding-text'.
+
+** The minput_filter () function accepts special events
+`input-focus-move', `input-focus-in', and `input-focus-out'.
+
+** Three letter codes of ISO639-2 are also accepted as language
+symbols.
+
+** New functions minput_get_description (), minput_get_commands (),
+minput_assign_command_keys (), minput_get_variables (), and
+minput_set_variable(), minput_get_title_icon() are introduced for
+handling input methods.
+
+** New fucntions mtext_insert () and and mtext_replace () for
+modifying M-text.
+
+** New functions mtext_uppercase (), mtext_titlecase (),
+mtext_lowercase () implement "3.13 Default Case Operations" of The
+Unicode Standard 4.0.
+
+** New function mtext_line_break () implements the line breaking
+algorithm of The Unicode Standard 4.0 UAX#14.  The algorithm can be
+controlled by the variable mdraw_line_break_option.
+
+** New function msymbol_is_managing_key () checks if a symbol is a
+managing key or not.
+
+** New function mtext_data () exports various information about
+M-text.
+
+** Function mfont_get_prop () accept properties `fontfile',
+`font-acsent', `font-descent', and `max-advance'.
+
+** New function mfont_check () checks if a specific font can be used
+for a specific script and language.
+
+** New function mface_equal () checks if two faces are equal or not.
+
+\f
+* Changes in the m17n library 1.2.0
+
+** Two new variables MTEXT_FORMAT_UTF_16 and MTEXT_FORMAT_UTF_32.
+They are initialized to one of MTEXT_FORMAT_UTF_16LE,
+MTEXT_FORMAT_UTF_16BE,  MTEXT_FORMAT_UTF_LE,  MTEXT_FORMAT_UTF_32BE
+dependending on the systems's endianess.
+
+** In the argument PLIST of mframe (), the key Mfont can be used to
+specify which font-backend to use.  The value must be Mx or Mfreetype.
+
+** New function mfont_list () returns a list of matching fonts.
+
+** New function m17n_status () returns the current initialization
+status.
+
+** New function minput_reset () resets the current input context.
+
+** Names of sample programs have prefix "m17n-" instead of single "m".
+This is to avoid confiliction of program names included in the other
+packages.
+
+\f
+* Changes in the m17n library 1.1.0
+
+** The "configure" script now detects Fontconfig, Xft2, and GD
+libraries.
+
+If Fontconfig library is found, the library find local font files
+(that are to be handled by the Freetype library) by fontconfig, and if
+Xft2 library is also found, draw text by Xft.
+
+** Mdevice (new symbol) is recoginized as a key in the argument PLIST
+of mframe ().
+
+The value must be Mx (new symbol), Mgd (new symbol), or Mnil.  See the
+documentation of mframe () for more detail.
+
+** MDrawControl has a new member `anti_alias'.
+
+If MDrawControl->anti_alias is nonzero, try to draw anti-aliased text
+if local fonts are used for that text via Freetype.  If Xft2 library
+can be used, the anti-alias processing is done by Xft2's drawing
+routine.  Otherwise, the m17n library itself does it by assumming that
+the background color is `background' property of a face.
+
+** Modification of face is now automatically refelected to the next
+drawing.
+
+So, for instance, an application can change the default face of a
+frame after the frame is created.  The sample program "medit" utilize
+it now.
+
+** New function mfontset_lookup () reports contents of a fontset.
+
+** New function mplist_deseriaze () parses an M-Text and generates a
+plist.
+
+** The functions mfont_name () and mfont_from_name () are now obsolete
+(still kept for backward compatibility).  Use mfont_parse_name () and
+mfont_unparse_name () instead.
+
+** The sample program "mdump" generates PNG image file instead of PBM.
+
+It now runs only when the m17n library is configured with the Freetype
+library and the GD library.
+
+\f
+* Changes in the m17n library 1.0
+
+** Released.
+
+\f
+* Copyright information
+
+Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+  National Institute of Advanced Industrial Science and Technology (AIST)
+  Registration Number H15PRO112
+
+This file is part of the m17n library.
+
+The m17n 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.1 of
+the License, or (at your option) any later version.
+
+The m17n 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 the m17n library; if not, write to the Free
+Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
+\f
+Local Variables:
+mode: outline
+paragraph-separate: "[         \f]*$"
+End:
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..4516443
--- /dev/null
+++ b/README
@@ -0,0 +1,170 @@
+This directory tree holds version 1.6.1 of the m17n library.   -*- text -*-
+
+Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+  National Institute of Advanced Industrial Science and Technology (AIST)
+  Registration Number H15PRO112
+See the end for copying conditions.
+
+The m17n library is a multilingual text processing library for the C
+language.
+
+
+(1) INSTALLATION
+
+(1-1) From CVS working directory.
+
+Run the script "bootstrap.sh" in this directory.  It is tested that
+the script runs successfully with these versions of tools.
+
+               libtool automake autoconf pkg-config
+  Debian Lenny   1.5.26   1.10.1     2.61       0.22
+  Ubunto 9.10     2.2.4    1.9.6     2.61       0.22
+  Fedra 12       2.2.6b   1.11.1     2.63       0.23
+
+Then, proceed to the next step.
+
+(1-2) From the tarball.
+
+The m17n library utilizes these extra libraries.  It is recommended to
+install all of them before running the "configure" script.  The script
+will find out the existence of them automatically.
+
+       libxml2         -- http://xmlsoft.org/
+       fribidi         -- http://fribidi.sourceforge.net/
+       freetype        -- http://www.freetype.org/
+       libotf          -- http://www.m17n.org/libotf/
+       fontconfig      -- http://freedesktop.org/Software/fontconfig
+       xft             -- http://freedesktop.org/Software/Xft
+       gd              -- http://www.boutell.com/gd/
+
+In addition, for finding a word boundary in Thai text, "configure"
+checks the existence of these libraries (libthai is preferred):
+
+       libthai         -- http://sourceforge.net/projects/libthai
+       wordcut         -- http://thaiwordseg.sourceforge.net/
+
+The sample program m17n-edit utilizes this Japanese inputting system.
+It is also recommended to install it.
+
+       anthy           -- http://anthy.sourceforge.jp/
+
+Then, type the followings on the command line.
+
+       % ./configure
+       % make
+       % make install
+
+Note that this package assumes an ANSI C compiler such as gcc.  It
+will not compile with an old-style K&R compiler.
+
+The default installation path is "/usr/local".
+Thus, these header files are installed in /usr/local/include:
+       m17n-core.h, m17n.h, m17n-gui.h, m17n-err.h, m17n-X.h, m17n-flt.h
+
+These library files are installed in /usr/local/lib:
+       libm17n-core.{a,so*,la}
+       libm17n.{a,so*,la}
+       libm17n-gui.{a,so*,la}
+       libm17n-flt.{a,so*,la}
+
+These modules are installed in /usr/local/lib/m17n/1.0:
+       libm17n-X.{a,so*,la}
+       libm17n-gd.{a,so*,la}
+       libimx-anthy.{a,so*,la},
+       libimx-ispell.{a,so*,la},
+
+This shell script is installed in /usr/local/bin:
+       m17n-config
+
+These pkgconfig metadata files are installed in
+/usr/local/lib/pkgconfig:
+       m17n-core.pc, m17n-shell.pc, m17n-flt.pc, m17n-gui.pc
+
+These sample programs are installed in /usr/local/bin too:
+       m17n-conv, m17n-date, m17n-view, m17n-dump, m17n-edit
+
+If you don't need GUI libraries (libm17n-gui.so and etc.), you can
+instruct the `configure' script not to build them as below:
+
+       % ./configure --without-gui
+
+This file under `example' sub-directory is a Japanese resource file
+for m17n-edit.  It is not installed but useful in Japanese locale.  Copy
+it to your home directory (or, for instance,
+/usr/X11R6/lib/X11/ja/app-defaults) and rename it to "M17NEdit" if you
+want to see labels in Japanese:
+       M17NEdit.ja
+
+These text files under `example' sub-directory are not installed but
+useful for testing the rendering engine of the m17n library:
+       HELLO.utf8 HELLO.xml HELLO-ja.utf8 HELLO-ja.xml HELLO.html
+XXX.xml are generated from XXX.utf8 by attaching text property
+`language' and serializing.
+
+Please read also INSTALL for the generic installation instructions.
+
+
+(2) DATABASE
+
+The m17n library utilizes the m17n database available at:
+       http://www.m17n.org/m17n-lib/m17n-db
+Without this database, the m17n library loses half its value.  Please
+install it (Ver.1.4.0 or the later is required) too before you try the
+above sample programs or develop a program that uses the m17n library.
+
+
+(3) DOCUMENTATION
+
+This page has a link to full documentation of the m17n library:
+       http://www.m17n.org/m17n-lib
+
+Actually, the documentation was generated by Doxygen using comments in
+the source files.  There are English and Japanese comments in
+parallel.
+
+
+(4) USAGE
+
+The library provides three levels of APIs, CORE, SHELL, and GUI.  For
+CORE API, include <m17n-core.h>, for SHELL API, include <m17n.h>, and
+for GUI API, include <m17n-gui.h >.  In addition, for those who need
+only text shaping facility that uses FLT (Font Layout Table), the
+library provides FLT API.  To use it, include <m17n-flt.h>.
+
+See the documentation above, or the manual of m17nIntro(3) for more
+detail.
+
+The shell script "m17n-config" helps compiling and linking of a
+program that uses the m17n library.  For instance this compiles PROG.c
+that uses SHELL API and builds executable PROG.
+
+       % gcc -o PROG `m17n-config --cflags` `m17n-config --libs` PROG.c
+
+This compiles PROX.c that uses GUI API and builds executable PROX.
+
+       % gcc -o PROX `m17n-config GUI --cflags` `m17n-config GUI --libs` PROX.c
+
+
+----------------------------------------------------------------------
+Copyright information
+
+Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+  National Institute of Advanced Industrial Science and Technology (AIST)
+  Registration Number H15PRO112
+
+This file is part of the m17n library.
+
+The m17n 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.1 of
+the License, or (at your option) any later version.
+
+The m17n 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 the m17n library; if not, write to the Free
+Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
diff --git a/TODO b/TODO
new file mode 100644 (file)
index 0000000..cf8eb85
--- /dev/null
+++ b/TODO
@@ -0,0 +1,60 @@
+TODO -- todo list for the m17n library.                        -*- outline -*-
+Copyright (C) 2003, 2004
+  National Institute of Advanced Industrial Science and Technology (AIST)
+  Registration Number H15PRO112
+See the end for copying conditions.
+
+\f
+* soon
+
+** Explicitely list up managed objects and describe them.
+
+** Allow properties to M-text itself, not to a specific region.
+
+\f
+* later
+
+** Add <plist> in MFont to allow any property.
+
+** Allow regex for font properties.
+
+** Should we change the type of property value from (void *) to
+MPropValue?
+
+** Vietnames FLT needs compositions.
+
+** Lock and unlock M-text.
+
+** Improve the handling of scratch gstring.
+
+\f
+* done
+
+** Make such an M-text modifiable that has a format other than
+MTEXT_FORMAT_UTF_8.
+
+** Imporve the font selection for characters of the same script.
+
+\f
+* Copyright information
+
+Copyright (C) 2003, 2004
+  National Institute of Advanced Industrial Science and Technology (AIST)
+  Registration Number H15PRO112
+
+This file is part of the m17n library.
+
+The m17n 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.1 of
+the License, or (at your option) any later version.
+
+The m17n 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 the m17n library; if not, write to the Free
+Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
diff --git a/aclocal.m4 b/aclocal.m4
new file mode 100644 (file)
index 0000000..f14f685
--- /dev/null
@@ -0,0 +1,1183 @@
+# generated automatically by aclocal 1.11 -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+# 2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
+# This file 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.
+
+m4_ifndef([AC_AUTOCONF_VERSION],
+  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
+m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.64],,
+[m4_warning([this file was generated for autoconf 2.64.
+You have another version of autoconf.  It may work, but is not guaranteed to.
+If you have problems, you may need to regenerate the build system entirely.
+To do so, use the procedure documented by the package, typically `autoreconf'.])])
+
+# pkg.m4 - Macros to locate and utilise pkg-config.            -*- Autoconf -*-
+# 
+# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# PKG_PROG_PKG_CONFIG([MIN-VERSION])
+# ----------------------------------
+AC_DEFUN([PKG_PROG_PKG_CONFIG],
+[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
+m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
+AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl
+if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
+       AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
+fi
+if test -n "$PKG_CONFIG"; then
+       _pkg_min_version=m4_default([$1], [0.9.0])
+       AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
+       if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
+               AC_MSG_RESULT([yes])
+       else
+               AC_MSG_RESULT([no])
+               PKG_CONFIG=""
+       fi
+               
+fi[]dnl
+])# PKG_PROG_PKG_CONFIG
+
+# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+#
+# Check to see whether a particular set of modules exists.  Similar
+# to PKG_CHECK_MODULES(), but does not set variables or print errors.
+#
+#
+# Similar to PKG_CHECK_MODULES, make sure that the first instance of
+# this or PKG_CHECK_MODULES is called, or make sure to call
+# PKG_CHECK_EXISTS manually
+# --------------------------------------------------------------
+AC_DEFUN([PKG_CHECK_EXISTS],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+if test -n "$PKG_CONFIG" && \
+    AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
+  m4_ifval([$2], [$2], [:])
+m4_ifvaln([$3], [else
+  $3])dnl
+fi])
+
+
+# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
+# ---------------------------------------------
+m4_define([_PKG_CONFIG],
+[if test -n "$PKG_CONFIG"; then
+    if test -n "$$1"; then
+        pkg_cv_[]$1="$$1"
+    else
+        PKG_CHECK_EXISTS([$3],
+                         [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
+                        [pkg_failed=yes])
+    fi
+else
+       pkg_failed=untried
+fi[]dnl
+])# _PKG_CONFIG
+
+# _PKG_SHORT_ERRORS_SUPPORTED
+# -----------------------------
+AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi[]dnl
+])# _PKG_SHORT_ERRORS_SUPPORTED
+
+
+# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
+# [ACTION-IF-NOT-FOUND])
+#
+#
+# Note that if there is a possibility the first call to
+# PKG_CHECK_MODULES might not happen, you should be sure to include an
+# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
+#
+#
+# --------------------------------------------------------------
+AC_DEFUN([PKG_CHECK_MODULES],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
+AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
+
+pkg_failed=no
+AC_MSG_CHECKING([for $1])
+
+_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
+_PKG_CONFIG([$1][_LIBS], [libs], [$2])
+
+m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
+and $1[]_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.])
+
+if test $pkg_failed = yes; then
+        _PKG_SHORT_ERRORS_SUPPORTED
+        if test $_pkg_short_errors_supported = yes; then
+               $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "$2"`
+        else 
+               $1[]_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
+        fi
+       # Put the nasty error message in config.log where it belongs
+       echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
+
+       ifelse([$4], , [AC_MSG_ERROR(dnl
+[Package requirements ($2) were not met:
+
+$$1_PKG_ERRORS
+
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
+
+_PKG_TEXT
+])],
+               [AC_MSG_RESULT([no])
+                $4])
+elif test $pkg_failed = untried; then
+       ifelse([$4], , [AC_MSG_FAILURE(dnl
+[The pkg-config script could not be found or is too old.  Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
+
+_PKG_TEXT
+
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.])],
+               [$4])
+else
+       $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
+       $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
+        AC_MSG_RESULT([yes])
+       ifelse([$3], , :, [$3])
+fi[]dnl
+])# PKG_CHECK_MODULES
+
+# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
+#
+# This file 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.
+
+# AM_AUTOMAKE_VERSION(VERSION)
+# ----------------------------
+# Automake X.Y traces this macro to ensure aclocal.m4 has been
+# generated from the m4 files accompanying Automake X.Y.
+# (This private macro should not be called outside this file.)
+AC_DEFUN([AM_AUTOMAKE_VERSION],
+[am__api_version='1.11'
+dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
+dnl require some minimum version.  Point them to the right macro.
+m4_if([$1], [1.11], [],
+      [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
+])
+
+# _AM_AUTOCONF_VERSION(VERSION)
+# -----------------------------
+# aclocal traces this macro to find the Autoconf version.
+# This is a private macro too.  Using m4_define simplifies
+# the logic in aclocal, which can simply ignore this definition.
+m4_define([_AM_AUTOCONF_VERSION], [])
+
+# AM_SET_CURRENT_AUTOMAKE_VERSION
+# -------------------------------
+# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
+# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
+AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
+[AM_AUTOMAKE_VERSION([1.11])dnl
+m4_ifndef([AC_AUTOCONF_VERSION],
+  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
+_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
+
+# AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
+
+# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+#
+# This file 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.
+
+# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
+# $ac_aux_dir to `$srcdir/foo'.  In other projects, it is set to
+# `$srcdir', `$srcdir/..', or `$srcdir/../..'.
+#
+# Of course, Automake must honor this variable whenever it calls a
+# tool from the auxiliary directory.  The problem is that $srcdir (and
+# therefore $ac_aux_dir as well) can be either absolute or relative,
+# depending on how configure is run.  This is pretty annoying, since
+# it makes $ac_aux_dir quite unusable in subdirectories: in the top
+# source directory, any form will work fine, but in subdirectories a
+# relative path needs to be adjusted first.
+#
+# $ac_aux_dir/missing
+#    fails when called from a subdirectory if $ac_aux_dir is relative
+# $top_srcdir/$ac_aux_dir/missing
+#    fails if $ac_aux_dir is absolute,
+#    fails when called from a subdirectory in a VPATH build with
+#          a relative $ac_aux_dir
+#
+# The reason of the latter failure is that $top_srcdir and $ac_aux_dir
+# are both prefixed by $srcdir.  In an in-source build this is usually
+# harmless because $srcdir is `.', but things will broke when you
+# start a VPATH build or use an absolute $srcdir.
+#
+# So we could use something similar to $top_srcdir/$ac_aux_dir/missing,
+# iff we strip the leading $srcdir from $ac_aux_dir.  That would be:
+#   am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"`
+# and then we would define $MISSING as
+#   MISSING="\${SHELL} $am_aux_dir/missing"
+# This will work as long as MISSING is not called from configure, because
+# unfortunately $(top_srcdir) has no meaning in configure.
+# However there are other variables, like CC, which are often used in
+# configure, and could therefore not use this "fixed" $ac_aux_dir.
+#
+# Another solution, used here, is to always expand $ac_aux_dir to an
+# absolute PATH.  The drawback is that using absolute paths prevent a
+# configured tree to be moved without reconfiguration.
+
+AC_DEFUN([AM_AUX_DIR_EXPAND],
+[dnl Rely on autoconf to set up CDPATH properly.
+AC_PREREQ([2.50])dnl
+# expand $ac_aux_dir to an absolute path
+am_aux_dir=`cd $ac_aux_dir && pwd`
+])
+
+# AM_CONDITIONAL                                            -*- Autoconf -*-
+
+# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008
+# Free Software Foundation, Inc.
+#
+# This file 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.
+
+# serial 9
+
+# AM_CONDITIONAL(NAME, SHELL-CONDITION)
+# -------------------------------------
+# Define a conditional.
+AC_DEFUN([AM_CONDITIONAL],
+[AC_PREREQ(2.52)dnl
+ ifelse([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
+       [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
+AC_SUBST([$1_TRUE])dnl
+AC_SUBST([$1_FALSE])dnl
+_AM_SUBST_NOTMAKE([$1_TRUE])dnl
+_AM_SUBST_NOTMAKE([$1_FALSE])dnl
+m4_define([_AM_COND_VALUE_$1], [$2])dnl
+if $2; then
+  $1_TRUE=
+  $1_FALSE='#'
+else
+  $1_TRUE='#'
+  $1_FALSE=
+fi
+AC_CONFIG_COMMANDS_PRE(
+[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
+  AC_MSG_ERROR([[conditional "$1" was never defined.
+Usually this means the macro was only invoked conditionally.]])
+fi])])
+
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009
+# Free Software Foundation, Inc.
+#
+# This file 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.
+
+# serial 10
+
+# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be
+# written in clear, in which case automake, when reading aclocal.m4,
+# will think it sees a *use*, and therefore will trigger all it's
+# C support machinery.  Also note that it means that autoscan, seeing
+# CC etc. in the Makefile, will ask for an AC_PROG_CC use...
+
+
+# _AM_DEPENDENCIES(NAME)
+# ----------------------
+# See how the compiler implements dependency checking.
+# NAME is "CC", "CXX", "GCJ", or "OBJC".
+# We try a few techniques and use that to set a single cache variable.
+#
+# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was
+# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular
+# dependency, and given that the user is not expected to run this macro,
+# just rely on AC_PROG_CC.
+AC_DEFUN([_AM_DEPENDENCIES],
+[AC_REQUIRE([AM_SET_DEPDIR])dnl
+AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl
+AC_REQUIRE([AM_MAKE_INCLUDE])dnl
+AC_REQUIRE([AM_DEP_TRACK])dnl
+
+ifelse([$1], CC,   [depcc="$CC"   am_compiler_list=],
+       [$1], CXX,  [depcc="$CXX"  am_compiler_list=],
+       [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
+       [$1], UPC,  [depcc="$UPC"  am_compiler_list=],
+       [$1], GCJ,  [depcc="$GCJ"  am_compiler_list='gcc3 gcc'],
+                   [depcc="$$1"   am_compiler_list=])
+
+AC_CACHE_CHECK([dependency style of $depcc],
+               [am_cv_$1_dependencies_compiler_type],
+[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named `D' -- because `-MD' means `put the output
+  # in D'.
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_$1_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp`
+  fi
+  am__universal=false
+  m4_case([$1], [CC],
+    [case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac],
+    [CXX],
+    [case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac])
+
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+      # Solaris 8's {/usr,}/bin/sh.
+      touch sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    # We check with `-c' and `-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle `-M -o', and we need to detect this.  Also, some Intel
+    # versions had trouble with output in subdirs
+    am__obj=sub/conftest.${OBJEXT-o}
+    am__minus_obj="-o $am__obj"
+    case $depmode in
+    gcc)
+      # This depmode causes a compiler race in universal mode.
+      test "$am__universal" = false || continue
+      ;;
+    nosideeffect)
+      # after this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested
+      if test "x$enable_dependency_tracking" = xyes; then
+       continue
+      else
+       break
+      fi
+      ;;
+    msvisualcpp | msvcmsys)
+      # This compiler won't grok `-c -o', but also, the minuso test has
+      # not run yet.  These depmodes are late enough in the game, and
+      # so weak that their functioning should not be impacted.
+      am__obj=conftest.${OBJEXT-o}
+      am__minus_obj=
+      ;;
+    none) break ;;
+    esac
+    if depmode=$depmode \
+       source=sub/conftest.c object=$am__obj \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_$1_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_$1_dependencies_compiler_type=none
+fi
+])
+AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type])
+AM_CONDITIONAL([am__fastdep$1], [
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_$1_dependencies_compiler_type" = gcc3])
+])
+
+
+# AM_SET_DEPDIR
+# -------------
+# Choose a directory name for dependency files.
+# This macro is AC_REQUIREd in _AM_DEPENDENCIES
+AC_DEFUN([AM_SET_DEPDIR],
+[AC_REQUIRE([AM_SET_LEADING_DOT])dnl
+AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl
+])
+
+
+# AM_DEP_TRACK
+# ------------
+AC_DEFUN([AM_DEP_TRACK],
+[AC_ARG_ENABLE(dependency-tracking,
+[  --disable-dependency-tracking  speeds up one-time build
+  --enable-dependency-tracking   do not reject slow dependency extractors])
+if test "x$enable_dependency_tracking" != xno; then
+  am_depcomp="$ac_aux_dir/depcomp"
+  AMDEPBACKSLASH='\'
+fi
+AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
+AC_SUBST([AMDEPBACKSLASH])dnl
+_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
+])
+
+# Generate code to set up dependency tracking.              -*- Autoconf -*-
+
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file 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.
+
+#serial 5
+
+# _AM_OUTPUT_DEPENDENCY_COMMANDS
+# ------------------------------
+AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
+[{
+  # Autoconf 2.62 quotes --file arguments for eval, but not when files
+  # are listed without --file.  Let's play safe and only enable the eval
+  # if we detect the quoting.
+  case $CONFIG_FILES in
+  *\'*) eval set x "$CONFIG_FILES" ;;
+  *)   set x $CONFIG_FILES ;;
+  esac
+  shift
+  for mf
+  do
+    # Strip MF so we end up with the name of the file.
+    mf=`echo "$mf" | sed -e 's/:.*$//'`
+    # Check whether this is an Automake generated Makefile or not.
+    # We used to match only the files named `Makefile.in', but
+    # some people rename them; so instead we look at the file content.
+    # Grep'ing the first line is not enough: some people post-process
+    # each Makefile.in and add a new line on top of each file to say so.
+    # Grep'ing the whole file is not good either: AIX grep has a line
+    # limit of 2048, but all sed's we know have understand at least 4000.
+    if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
+      dirpart=`AS_DIRNAME("$mf")`
+    else
+      continue
+    fi
+    # Extract the definition of DEPDIR, am__include, and am__quote
+    # from the Makefile without running `make'.
+    DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
+    test -z "$DEPDIR" && continue
+    am__include=`sed -n 's/^am__include = //p' < "$mf"`
+    test -z "am__include" && continue
+    am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
+    # When using ansi2knr, U may be empty or an underscore; expand it
+    U=`sed -n 's/^U = //p' < "$mf"`
+    # Find all dependency output files, they are included files with
+    # $(DEPDIR) in their names.  We invoke sed twice because it is the
+    # simplest approach to changing $(DEPDIR) to its actual value in the
+    # expansion.
+    for file in `sed -n "
+      s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
+        sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
+      # Make sure the directory exists.
+      test -f "$dirpart/$file" && continue
+      fdir=`AS_DIRNAME(["$file"])`
+      AS_MKDIR_P([$dirpart/$fdir])
+      # echo "creating $dirpart/$file"
+      echo '# dummy' > "$dirpart/$file"
+    done
+  done
+}
+])# _AM_OUTPUT_DEPENDENCY_COMMANDS
+
+
+# AM_OUTPUT_DEPENDENCY_COMMANDS
+# -----------------------------
+# This macro should only be invoked once -- use via AC_REQUIRE.
+#
+# This code is only required when automatic dependency tracking
+# is enabled.  FIXME.  This creates each `.P' file that we will
+# need in order to bootstrap the dependency handling code.
+AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
+[AC_CONFIG_COMMANDS([depfiles],
+     [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
+     [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
+])
+
+# Do all the work for Automake.                             -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+# 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
+#
+# This file 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.
+
+# serial 16
+
+# This macro actually does too much.  Some checks are only needed if
+# your package does certain things.  But this isn't really a big deal.
+
+# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
+# AM_INIT_AUTOMAKE([OPTIONS])
+# -----------------------------------------------
+# The call with PACKAGE and VERSION arguments is the old style
+# call (pre autoconf-2.50), which is being phased out.  PACKAGE
+# and VERSION should now be passed to AC_INIT and removed from
+# the call to AM_INIT_AUTOMAKE.
+# We support both call styles for the transition.  After
+# the next Automake release, Autoconf can make the AC_INIT
+# arguments mandatory, and then we can depend on a new Autoconf
+# release and drop the old call support.
+AC_DEFUN([AM_INIT_AUTOMAKE],
+[AC_PREREQ([2.62])dnl
+dnl Autoconf wants to disallow AM_ names.  We explicitly allow
+dnl the ones we care about.
+m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
+AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl
+AC_REQUIRE([AC_PROG_INSTALL])dnl
+if test "`cd $srcdir && pwd`" != "`pwd`"; then
+  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
+  # is not polluted with repeated "-I."
+  AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl
+  # test to see if srcdir already configured
+  if test -f $srcdir/config.status; then
+    AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
+  fi
+fi
+
+# test whether we have cygpath
+if test -z "$CYGPATH_W"; then
+  if (cygpath --version) >/dev/null 2>/dev/null; then
+    CYGPATH_W='cygpath -w'
+  else
+    CYGPATH_W=echo
+  fi
+fi
+AC_SUBST([CYGPATH_W])
+
+# Define the identity of the package.
+dnl Distinguish between old-style and new-style calls.
+m4_ifval([$2],
+[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
+ AC_SUBST([PACKAGE], [$1])dnl
+ AC_SUBST([VERSION], [$2])],
+[_AM_SET_OPTIONS([$1])dnl
+dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT.
+m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,,
+  [m4_fatal([AC_INIT should be called with package and version arguments])])dnl
+ AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
+ AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl
+
+_AM_IF_OPTION([no-define],,
+[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
+ AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl
+
+# Some tools Automake needs.
+AC_REQUIRE([AM_SANITY_CHECK])dnl
+AC_REQUIRE([AC_ARG_PROGRAM])dnl
+AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version})
+AM_MISSING_PROG(AUTOCONF, autoconf)
+AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version})
+AM_MISSING_PROG(AUTOHEADER, autoheader)
+AM_MISSING_PROG(MAKEINFO, makeinfo)
+AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
+AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl
+AC_REQUIRE([AM_PROG_MKDIR_P])dnl
+# We need awk for the "check" target.  The system "awk" is bad on
+# some platforms.
+AC_REQUIRE([AC_PROG_AWK])dnl
+AC_REQUIRE([AC_PROG_MAKE_SET])dnl
+AC_REQUIRE([AM_SET_LEADING_DOT])dnl
+_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
+             [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
+                            [_AM_PROG_TAR([v7])])])
+_AM_IF_OPTION([no-dependencies],,
+[AC_PROVIDE_IFELSE([AC_PROG_CC],
+                 [_AM_DEPENDENCIES(CC)],
+                 [define([AC_PROG_CC],
+                         defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_CXX],
+                 [_AM_DEPENDENCIES(CXX)],
+                 [define([AC_PROG_CXX],
+                         defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_OBJC],
+                 [_AM_DEPENDENCIES(OBJC)],
+                 [define([AC_PROG_OBJC],
+                         defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl
+])
+_AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl
+dnl The `parallel-tests' driver may need to know about EXEEXT, so add the
+dnl `am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen.  This macro
+dnl is hooked onto _AC_COMPILER_EXEEXT early, see below.
+AC_CONFIG_COMMANDS_PRE(dnl
+[m4_provide_if([_AM_COMPILER_EXEEXT],
+  [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl
+])
+
+dnl Hook into `_AC_COMPILER_EXEEXT' early to learn its expansion.  Do not
+dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
+dnl mangled by Autoconf and run in a shell conditional statement.
+m4_define([_AC_COMPILER_EXEEXT],
+m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])])
+
+
+# When config.status generates a header, we must update the stamp-h file.
+# This file resides in the same directory as the config header
+# that is generated.  The stamp files are numbered to have different names.
+
+# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the
+# loop where config.status creates the headers, so we can generate
+# our stamp files there.
+AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK],
+[# Compute $1's index in $config_headers.
+_am_arg=$1
+_am_stamp_count=1
+for _am_header in $config_headers :; do
+  case $_am_header in
+    $_am_arg | $_am_arg:* )
+      break ;;
+    * )
+      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
+  esac
+done
+echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
+
+# Copyright (C) 2001, 2003, 2005, 2008  Free Software Foundation, Inc.
+#
+# This file 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.
+
+# AM_PROG_INSTALL_SH
+# ------------------
+# Define $install_sh.
+AC_DEFUN([AM_PROG_INSTALL_SH],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+if test x"${install_sh}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\    *)
+    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
+  *)
+    install_sh="\${SHELL} $am_aux_dir/install-sh"
+  esac
+fi
+AC_SUBST(install_sh)])
+
+# Copyright (C) 2003, 2005  Free Software Foundation, Inc.
+#
+# This file 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.
+
+# serial 2
+
+# Check whether the underlying file-system supports filenames
+# with a leading dot.  For instance MS-DOS doesn't.
+AC_DEFUN([AM_SET_LEADING_DOT],
+[rm -rf .tst 2>/dev/null
+mkdir .tst 2>/dev/null
+if test -d .tst; then
+  am__leading_dot=.
+else
+  am__leading_dot=_
+fi
+rmdir .tst 2>/dev/null
+AC_SUBST([am__leading_dot])])
+
+# Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
+# From Jim Meyering
+
+# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file 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.
+
+# serial 5
+
+# AM_MAINTAINER_MODE([DEFAULT-MODE])
+# ----------------------------------
+# Control maintainer-specific portions of Makefiles.
+# Default is to disable them, unless `enable' is passed literally.
+# For symmetry, `disable' may be passed as well.  Anyway, the user
+# can override the default with the --enable/--disable switch.
+AC_DEFUN([AM_MAINTAINER_MODE],
+[m4_case(m4_default([$1], [disable]),
+       [enable], [m4_define([am_maintainer_other], [disable])],
+       [disable], [m4_define([am_maintainer_other], [enable])],
+       [m4_define([am_maintainer_other], [enable])
+        m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])])
+AC_MSG_CHECKING([whether to am_maintainer_other maintainer-specific portions of Makefiles])
+  dnl maintainer-mode's default is 'disable' unless 'enable' is passed
+  AC_ARG_ENABLE([maintainer-mode],
+[  --][am_maintainer_other][-maintainer-mode  am_maintainer_other make rules and dependencies not useful
+                         (and sometimes confusing) to the casual installer],
+      [USE_MAINTAINER_MODE=$enableval],
+      [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes]))
+  AC_MSG_RESULT([$USE_MAINTAINER_MODE])
+  AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes])
+  MAINT=$MAINTAINER_MODE_TRUE
+  AC_SUBST([MAINT])dnl
+]
+)
+
+AU_DEFUN([jm_MAINTAINER_MODE], [AM_MAINTAINER_MODE])
+
+# Check to see how 'make' treats includes.                 -*- Autoconf -*-
+
+# Copyright (C) 2001, 2002, 2003, 2005, 2009  Free Software Foundation, Inc.
+#
+# This file 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.
+
+# serial 4
+
+# AM_MAKE_INCLUDE()
+# -----------------
+# Check to see how make treats includes.
+AC_DEFUN([AM_MAKE_INCLUDE],
+[am_make=${MAKE-make}
+cat > confinc << 'END'
+am__doit:
+       @echo this is the am__doit target
+.PHONY: am__doit
+END
+# If we don't find an include directive, just comment out the code.
+AC_MSG_CHECKING([for style of include used by $am_make])
+am__include="#"
+am__quote=
+_am_result=none
+# First try GNU make style include.
+echo "include confinc" > confmf
+# Ignore all kinds of additional output from `make'.
+case `$am_make -s -f confmf 2> /dev/null` in #(
+*the\ am__doit\ target*)
+  am__include=include
+  am__quote=
+  _am_result=GNU
+  ;;
+esac
+# Now try BSD make style include.
+if test "$am__include" = "#"; then
+   echo '.include "confinc"' > confmf
+   case `$am_make -s -f confmf 2> /dev/null` in #(
+   *the\ am__doit\ target*)
+     am__include=.include
+     am__quote="\""
+     _am_result=BSD
+     ;;
+   esac
+fi
+AC_SUBST([am__include])
+AC_SUBST([am__quote])
+AC_MSG_RESULT([$_am_result])
+rm -f confinc confmf
+])
+
+# Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
+
+# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file 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.
+
+# serial 6
+
+# AM_MISSING_PROG(NAME, PROGRAM)
+# ------------------------------
+AC_DEFUN([AM_MISSING_PROG],
+[AC_REQUIRE([AM_MISSING_HAS_RUN])
+$1=${$1-"${am_missing_run}$2"}
+AC_SUBST($1)])
+
+
+# AM_MISSING_HAS_RUN
+# ------------------
+# Define MISSING if not defined so far and test if it supports --run.
+# If it does, set am_missing_run to use it, otherwise, to nothing.
+AC_DEFUN([AM_MISSING_HAS_RUN],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+AC_REQUIRE_AUX_FILE([missing])dnl
+if test x"${MISSING+set}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\    *)
+    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
+  *)
+    MISSING="\${SHELL} $am_aux_dir/missing" ;;
+  esac
+fi
+# Use eval to expand $SHELL
+if eval "$MISSING --run true"; then
+  am_missing_run="$MISSING --run "
+else
+  am_missing_run=
+  AC_MSG_WARN([`missing' script is too old or missing])
+fi
+])
+
+# Copyright (C) 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
+#
+# This file 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.
+
+# AM_PROG_MKDIR_P
+# ---------------
+# Check for `mkdir -p'.
+AC_DEFUN([AM_PROG_MKDIR_P],
+[AC_PREREQ([2.60])dnl
+AC_REQUIRE([AC_PROG_MKDIR_P])dnl
+dnl Automake 1.8 to 1.9.6 used to define mkdir_p.  We now use MKDIR_P,
+dnl while keeping a definition of mkdir_p for backward compatibility.
+dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile.
+dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of
+dnl Makefile.ins that do not define MKDIR_P, so we do our own
+dnl adjustment using top_builddir (which is defined more often than
+dnl MKDIR_P).
+AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl
+case $mkdir_p in
+  [[\\/$]]* | ?:[[\\/]]*) ;;
+  */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
+esac
+])
+
+# Helper functions for option handling.                     -*- Autoconf -*-
+
+# Copyright (C) 2001, 2002, 2003, 2005, 2008  Free Software Foundation, Inc.
+#
+# This file 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.
+
+# serial 4
+
+# _AM_MANGLE_OPTION(NAME)
+# -----------------------
+AC_DEFUN([_AM_MANGLE_OPTION],
+[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
+
+# _AM_SET_OPTION(NAME)
+# ------------------------------
+# Set option NAME.  Presently that only means defining a flag for this option.
+AC_DEFUN([_AM_SET_OPTION],
+[m4_define(_AM_MANGLE_OPTION([$1]), 1)])
+
+# _AM_SET_OPTIONS(OPTIONS)
+# ----------------------------------
+# OPTIONS is a space-separated list of Automake options.
+AC_DEFUN([_AM_SET_OPTIONS],
+[m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
+
+# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
+# -------------------------------------------
+# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
+AC_DEFUN([_AM_IF_OPTION],
+[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
+
+# Check to make sure that the build environment is sane.    -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file 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.
+
+# serial 5
+
+# AM_SANITY_CHECK
+# ---------------
+AC_DEFUN([AM_SANITY_CHECK],
+[AC_MSG_CHECKING([whether build environment is sane])
+# Just in case
+sleep 1
+echo timestamp > conftest.file
+# Reject unsafe characters in $srcdir or the absolute working directory
+# name.  Accept space and tab only in the latter.
+am_lf='
+'
+case `pwd` in
+  *[[\\\"\#\$\&\'\`$am_lf]]*)
+    AC_MSG_ERROR([unsafe absolute working directory name]);;
+esac
+case $srcdir in
+  *[[\\\"\#\$\&\'\`$am_lf\ \   ]]*)
+    AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);;
+esac
+
+# Do `set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
+   if test "$[*]" = "X"; then
+      # -L didn't work.
+      set X `ls -t "$srcdir/configure" conftest.file`
+   fi
+   rm -f conftest.file
+   if test "$[*]" != "X $srcdir/configure conftest.file" \
+      && test "$[*]" != "X conftest.file $srcdir/configure"; then
+
+      # If neither matched, then we have a broken ls.  This can happen
+      # if, for instance, CONFIG_SHELL is bash and it inherits a
+      # broken ls alias from the environment.  This has actually
+      # happened.  Such a system could not be considered "sane".
+      AC_MSG_ERROR([ls -t appears to fail.  Make sure there is not a broken
+alias in your environment])
+   fi
+
+   test "$[2]" = conftest.file
+   )
+then
+   # Ok.
+   :
+else
+   AC_MSG_ERROR([newly created file is older than distributed files!
+Check your system clock])
+fi
+AC_MSG_RESULT(yes)])
+
+# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+#
+# This file 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.
+
+# AM_PROG_INSTALL_STRIP
+# ---------------------
+# One issue with vendor `install' (even GNU) is that you can't
+# specify the program used to strip binaries.  This is especially
+# annoying in cross-compiling environments, where the build's strip
+# is unlikely to handle the host's binaries.
+# Fortunately install-sh will honor a STRIPPROG variable, so we
+# always use install-sh in `make install-strip', and initialize
+# STRIPPROG with the value of the STRIP variable (set by the user).
+AC_DEFUN([AM_PROG_INSTALL_STRIP],
+[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
+# Installed binaries are usually stripped using `strip' when the user
+# run `make install-strip'.  However `strip' might not be the right
+# tool to use in cross-compilation environments, therefore Automake
+# will honor the `STRIP' environment variable to overrule this program.
+dnl Don't test for $cross_compiling = yes, because it might be `maybe'.
+if test "$cross_compiling" != no; then
+  AC_CHECK_TOOL([STRIP], [strip], :)
+fi
+INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
+AC_SUBST([INSTALL_STRIP_PROGRAM])])
+
+# Copyright (C) 2006, 2008  Free Software Foundation, Inc.
+#
+# This file 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.
+
+# serial 2
+
+# _AM_SUBST_NOTMAKE(VARIABLE)
+# ---------------------------
+# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in.
+# This macro is traced by Automake.
+AC_DEFUN([_AM_SUBST_NOTMAKE])
+
+# AM_SUBST_NOTMAKE(VARIABLE)
+# ---------------------------
+# Public sister of _AM_SUBST_NOTMAKE.
+AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
+
+# Check how to create a tarball.                            -*- Autoconf -*-
+
+# Copyright (C) 2004, 2005  Free Software Foundation, Inc.
+#
+# This file 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.
+
+# serial 2
+
+# _AM_PROG_TAR(FORMAT)
+# --------------------
+# Check how to create a tarball in format FORMAT.
+# FORMAT should be one of `v7', `ustar', or `pax'.
+#
+# Substitute a variable $(am__tar) that is a command
+# writing to stdout a FORMAT-tarball containing the directory
+# $tardir.
+#     tardir=directory && $(am__tar) > result.tar
+#
+# Substitute a variable $(am__untar) that extract such
+# a tarball read from stdin.
+#     $(am__untar) < result.tar
+AC_DEFUN([_AM_PROG_TAR],
+[# Always define AMTAR for backward compatibility.
+AM_MISSING_PROG([AMTAR], [tar])
+m4_if([$1], [v7],
+     [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'],
+     [m4_case([$1], [ustar],, [pax],,
+              [m4_fatal([Unknown tar format])])
+AC_MSG_CHECKING([how to create a $1 tar archive])
+# Loop over all known methods to create a tar archive until one works.
+_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none'
+_am_tools=${am_cv_prog_tar_$1-$_am_tools}
+# Do not fold the above two line into one, because Tru64 sh and
+# Solaris sh will not grok spaces in the rhs of `-'.
+for _am_tool in $_am_tools
+do
+  case $_am_tool in
+  gnutar)
+    for _am_tar in tar gnutar gtar;
+    do
+      AM_RUN_LOG([$_am_tar --version]) && break
+    done
+    am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"'
+    am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"'
+    am__untar="$_am_tar -xf -"
+    ;;
+  plaintar)
+    # Must skip GNU tar: if it does not support --format= it doesn't create
+    # ustar tarball either.
+    (tar --version) >/dev/null 2>&1 && continue
+    am__tar='tar chf - "$$tardir"'
+    am__tar_='tar chf - "$tardir"'
+    am__untar='tar xf -'
+    ;;
+  pax)
+    am__tar='pax -L -x $1 -w "$$tardir"'
+    am__tar_='pax -L -x $1 -w "$tardir"'
+    am__untar='pax -r'
+    ;;
+  cpio)
+    am__tar='find "$$tardir" -print | cpio -o -H $1 -L'
+    am__tar_='find "$tardir" -print | cpio -o -H $1 -L'
+    am__untar='cpio -i -H $1 -d'
+    ;;
+  none)
+    am__tar=false
+    am__tar_=false
+    am__untar=false
+    ;;
+  esac
+
+  # If the value was cached, stop now.  We just wanted to have am__tar
+  # and am__untar set.
+  test -n "${am_cv_prog_tar_$1}" && break
+
+  # tar/untar a dummy directory, and stop if the command works
+  rm -rf conftest.dir
+  mkdir conftest.dir
+  echo GrepMe > conftest.dir/file
+  AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar])
+  rm -rf conftest.dir
+  if test -s conftest.tar; then
+    AM_RUN_LOG([$am__untar <conftest.tar])
+    grep GrepMe conftest.dir/file >/dev/null 2>&1 && break
+  fi
+done
+rm -rf conftest.dir
+
+AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool])
+AC_MSG_RESULT([$am_cv_prog_tar_$1])])
+AC_SUBST([am__tar])
+AC_SUBST([am__untar])
+]) # _AM_PROG_TAR
+
+m4_include([m4/codeset.m4])
+m4_include([m4/gettext.m4])
+m4_include([m4/glibc2.m4])
+m4_include([m4/glibc21.m4])
+m4_include([m4/iconv.m4])
+m4_include([m4/intdiv0.m4])
+m4_include([m4/intmax.m4])
+m4_include([m4/inttypes-pri.m4])
+m4_include([m4/inttypes.m4])
+m4_include([m4/inttypes_h.m4])
+m4_include([m4/isc-posix.m4])
+m4_include([m4/lcmessage.m4])
+m4_include([m4/lib-ld.m4])
+m4_include([m4/lib-link.m4])
+m4_include([m4/lib-prefix.m4])
+m4_include([m4/libtool.m4])
+m4_include([m4/longdouble.m4])
+m4_include([m4/longlong.m4])
+m4_include([m4/ltoptions.m4])
+m4_include([m4/ltsugar.m4])
+m4_include([m4/ltversion.m4])
+m4_include([m4/lt~obsolete.m4])
+m4_include([m4/nls.m4])
+m4_include([m4/po.m4])
+m4_include([m4/printf-posix.m4])
+m4_include([m4/progtest.m4])
+m4_include([m4/signed.m4])
+m4_include([m4/size_max.m4])
+m4_include([m4/stdint_h.m4])
+m4_include([m4/uintmax_t.m4])
+m4_include([m4/ulonglong.m4])
+m4_include([m4/wchar_t.m4])
+m4_include([m4/wint_t.m4])
+m4_include([m4/xsize.m4])
diff --git a/bootstrap.sh b/bootstrap.sh
new file mode 100755 (executable)
index 0000000..bbc2cb8
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/sh
+# bootstrap.sh -- shell script to build the m17n library from CVS.
+# Copyright (C) 2003, 2004, 2005, 2006, 2009
+#   National Institute of Advanced Industrial Science and Technology (AIST)
+#   Registration Number H15PRO112
+
+# This file is part of the m17n library.
+
+# The m17n 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.1 of
+# the License, or (at your option) any later version.
+
+# The m17n 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 the m17n library; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+echo "Running autoreconf -v -f -i"
+autoreconf -v -f -i
+echo "The remaining steps to install this library are:"
+echo "  % ./configure"
+echo "  % make"
+echo "  % make install"
diff --git a/config.guess b/config.guess
new file mode 100755 (executable)
index 0000000..da83314
--- /dev/null
@@ -0,0 +1,1561 @@
+#! /bin/sh
+# Attempt to guess a canonical system name.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+#   Free Software Foundation, Inc.
+
+timestamp='2009-04-27'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+
+# Originally written by Per Bothner <per@bothner.com>.
+# Please send patches to <config-patches@gnu.org>.  Submit a context
+# diff and a properly formatted ChangeLog entry.
+#
+# This script attempts to guess a canonical system name similar to
+# config.sub.  If it succeeds, it prints the system name on stdout, and
+# exits with 0.  Otherwise, it exits with 1.
+#
+# The plan is that this can be called by configure scripts if you
+# don't specify an explicit build system type.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION]
+
+Output the configuration name of the system \`$me' is run on.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches@gnu.org>."
+
+version="\
+GNU config.guess ($timestamp)
+
+Originally written by Per Bothner.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit ;;
+    --version | -v )
+       echo "$version" ; exit ;;
+    --help | --h* | -h )
+       echo "$usage"; exit ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )        # Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help" >&2
+       exit 1 ;;
+    * )
+       break ;;
+  esac
+done
+
+if test $# != 0; then
+  echo "$me: too many arguments$help" >&2
+  exit 1
+fi
+
+trap 'exit 1' 1 2 15
+
+# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
+# compiler to aid in system detection is discouraged as it requires
+# temporary files to be created and, as you can see below, it is a
+# headache to deal with in a portable fashion.
+
+# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
+# use `HOST_CC' if defined, but it is deprecated.
+
+# Portable tmp directory creation inspired by the Autoconf team.
+
+set_cc_for_build='
+trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
+trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
+: ${TMPDIR=/tmp} ;
+ { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
+ { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
+ { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
+dummy=$tmp/dummy ;
+tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
+case $CC_FOR_BUILD,$HOST_CC,$CC in
+ ,,)    echo "int x;" > $dummy.c ;
+       for c in cc gcc c89 c99 ; do
+         if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
+            CC_FOR_BUILD="$c"; break ;
+         fi ;
+       done ;
+       if test x"$CC_FOR_BUILD" = x ; then
+         CC_FOR_BUILD=no_compiler_found ;
+       fi
+       ;;
+ ,,*)   CC_FOR_BUILD=$CC ;;
+ ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
+esac ; set_cc_for_build= ;'
+
+# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
+# (ghazi@noc.rutgers.edu 1994-08-24)
+if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+       PATH=$PATH:/.attbin ; export PATH
+fi
+
+UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
+UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
+UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
+
+# Note: order is significant - the case branches are not exclusive.
+
+case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
+    *:NetBSD:*:*)
+       # NetBSD (nbsd) targets should (where applicable) match one or
+       # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
+       # *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently
+       # switched to ELF, *-*-netbsd* would select the old
+       # object file format.  This provides both forward
+       # compatibility and a consistent mechanism for selecting the
+       # object file format.
+       #
+       # Note: NetBSD doesn't particularly care about the vendor
+       # portion of the name.  We always set it to "unknown".
+       sysctl="sysctl -n hw.machine_arch"
+       UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
+           /usr/sbin/$sysctl 2>/dev/null || echo unknown)`
+       case "${UNAME_MACHINE_ARCH}" in
+           armeb) machine=armeb-unknown ;;
+           arm*) machine=arm-unknown ;;
+           sh3el) machine=shl-unknown ;;
+           sh3eb) machine=sh-unknown ;;
+           sh5el) machine=sh5le-unknown ;;
+           *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
+       esac
+       # The Operating System including object format, if it has switched
+       # to ELF recently, or will in the future.
+       case "${UNAME_MACHINE_ARCH}" in
+           arm*|i386|m68k|ns32k|sh3*|sparc|vax)
+               eval $set_cc_for_build
+               if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
+                       | grep __ELF__ >/dev/null
+               then
+                   # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
+                   # Return netbsd for either.  FIX?
+                   os=netbsd
+               else
+                   os=netbsdelf
+               fi
+               ;;
+           *)
+               os=netbsd
+               ;;
+       esac
+       # The OS release
+       # Debian GNU/NetBSD machines have a different userland, and
+       # thus, need a distinct triplet. However, they do not need
+       # kernel version information, so it can be replaced with a
+       # suitable tag, in the style of linux-gnu.
+       case "${UNAME_VERSION}" in
+           Debian*)
+               release='-gnu'
+               ;;
+           *)
+               release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+               ;;
+       esac
+       # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
+       # contains redundant information, the shorter form:
+       # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
+       echo "${machine}-${os}${release}"
+       exit ;;
+    *:OpenBSD:*:*)
+       UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
+       echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
+       exit ;;
+    *:ekkoBSD:*:*)
+       echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
+       exit ;;
+    *:SolidBSD:*:*)
+       echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
+       exit ;;
+    macppc:MirBSD:*:*)
+       echo powerpc-unknown-mirbsd${UNAME_RELEASE}
+       exit ;;
+    *:MirBSD:*:*)
+       echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
+       exit ;;
+    alpha:OSF1:*:*)
+       case $UNAME_RELEASE in
+       *4.0)
+               UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
+               ;;
+       *5.*)
+               UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
+               ;;
+       esac
+       # According to Compaq, /usr/sbin/psrinfo has been available on
+       # OSF/1 and Tru64 systems produced since 1995.  I hope that
+       # covers most systems running today.  This code pipes the CPU
+       # types through head -n 1, so we only detect the type of CPU 0.
+       ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^  The alpha \(.*\) processor.*$/\1/p' | head -n 1`
+       case "$ALPHA_CPU_TYPE" in
+           "EV4 (21064)")
+               UNAME_MACHINE="alpha" ;;
+           "EV4.5 (21064)")
+               UNAME_MACHINE="alpha" ;;
+           "LCA4 (21066/21068)")
+               UNAME_MACHINE="alpha" ;;
+           "EV5 (21164)")
+               UNAME_MACHINE="alphaev5" ;;
+           "EV5.6 (21164A)")
+               UNAME_MACHINE="alphaev56" ;;
+           "EV5.6 (21164PC)")
+               UNAME_MACHINE="alphapca56" ;;
+           "EV5.7 (21164PC)")
+               UNAME_MACHINE="alphapca57" ;;
+           "EV6 (21264)")
+               UNAME_MACHINE="alphaev6" ;;
+           "EV6.7 (21264A)")
+               UNAME_MACHINE="alphaev67" ;;
+           "EV6.8CB (21264C)")
+               UNAME_MACHINE="alphaev68" ;;
+           "EV6.8AL (21264B)")
+               UNAME_MACHINE="alphaev68" ;;
+           "EV6.8CX (21264D)")
+               UNAME_MACHINE="alphaev68" ;;
+           "EV6.9A (21264/EV69A)")
+               UNAME_MACHINE="alphaev69" ;;
+           "EV7 (21364)")
+               UNAME_MACHINE="alphaev7" ;;
+           "EV7.9 (21364A)")
+               UNAME_MACHINE="alphaev79" ;;
+       esac
+       # A Pn.n version is a patched version.
+       # A Vn.n version is a released version.
+       # A Tn.n version is a released field test version.
+       # A Xn.n version is an unreleased experimental baselevel.
+       # 1.2 uses "1.2" for uname -r.
+       echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+       exit ;;
+    Alpha\ *:Windows_NT*:*)
+       # How do we know it's Interix rather than the generic POSIX subsystem?
+       # Should we change UNAME_MACHINE based on the output of uname instead
+       # of the specific Alpha model?
+       echo alpha-pc-interix
+       exit ;;
+    21064:Windows_NT:50:3)
+       echo alpha-dec-winnt3.5
+       exit ;;
+    Amiga*:UNIX_System_V:4.0:*)
+       echo m68k-unknown-sysv4
+       exit ;;
+    *:[Aa]miga[Oo][Ss]:*:*)
+       echo ${UNAME_MACHINE}-unknown-amigaos
+       exit ;;
+    *:[Mm]orph[Oo][Ss]:*:*)
+       echo ${UNAME_MACHINE}-unknown-morphos
+       exit ;;
+    *:OS/390:*:*)
+       echo i370-ibm-openedition
+       exit ;;
+    *:z/VM:*:*)
+       echo s390-ibm-zvmoe
+       exit ;;
+    *:OS400:*:*)
+        echo powerpc-ibm-os400
+       exit ;;
+    arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
+       echo arm-acorn-riscix${UNAME_RELEASE}
+       exit ;;
+    arm:riscos:*:*|arm:RISCOS:*:*)
+       echo arm-unknown-riscos
+       exit ;;
+    SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
+       echo hppa1.1-hitachi-hiuxmpp
+       exit ;;
+    Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
+       # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
+       if test "`(/bin/universe) 2>/dev/null`" = att ; then
+               echo pyramid-pyramid-sysv3
+       else
+               echo pyramid-pyramid-bsd
+       fi
+       exit ;;
+    NILE*:*:*:dcosx)
+       echo pyramid-pyramid-svr4
+       exit ;;
+    DRS?6000:unix:4.0:6*)
+       echo sparc-icl-nx6
+       exit ;;
+    DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
+       case `/usr/bin/uname -p` in
+           sparc) echo sparc-icl-nx7; exit ;;
+       esac ;;
+    s390x:SunOS:*:*)
+       echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit ;;
+    sun4H:SunOS:5.*:*)
+       echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit ;;
+    sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
+       echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit ;;
+    i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
+       eval $set_cc_for_build
+       SUN_ARCH="i386"
+       # If there is a compiler, see if it is configured for 64-bit objects.
+       # Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
+       # This test works for both compilers.
+       if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+           if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
+               (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+               grep IS_64BIT_ARCH >/dev/null
+           then
+               SUN_ARCH="x86_64"
+           fi
+       fi
+       echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit ;;
+    sun4*:SunOS:6*:*)
+       # According to config.sub, this is the proper way to canonicalize
+       # SunOS6.  Hard to guess exactly what SunOS6 will be like, but
+       # it's likely to be more like Solaris than SunOS4.
+       echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit ;;
+    sun4*:SunOS:*:*)
+       case "`/usr/bin/arch -k`" in
+           Series*|S4*)
+               UNAME_RELEASE=`uname -v`
+               ;;
+       esac
+       # Japanese Language versions have a version number like `4.1.3-JL'.
+       echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
+       exit ;;
+    sun3*:SunOS:*:*)
+       echo m68k-sun-sunos${UNAME_RELEASE}
+       exit ;;
+    sun*:*:4.2BSD:*)
+       UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
+       test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
+       case "`/bin/arch`" in
+           sun3)
+               echo m68k-sun-sunos${UNAME_RELEASE}
+               ;;
+           sun4)
+               echo sparc-sun-sunos${UNAME_RELEASE}
+               ;;
+       esac
+       exit ;;
+    aushp:SunOS:*:*)
+       echo sparc-auspex-sunos${UNAME_RELEASE}
+       exit ;;
+    # The situation for MiNT is a little confusing.  The machine name
+    # can be virtually everything (everything which is not
+    # "atarist" or "atariste" at least should have a processor
+    # > m68000).  The system name ranges from "MiNT" over "FreeMiNT"
+    # to the lowercase version "mint" (or "freemint").  Finally
+    # the system name "TOS" denotes a system which is actually not
+    # MiNT.  But MiNT is downward compatible to TOS, so this should
+    # be no problem.
+    atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
+        echo m68k-atari-mint${UNAME_RELEASE}
+       exit ;;
+    atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
+       echo m68k-atari-mint${UNAME_RELEASE}
+        exit ;;
+    *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
+        echo m68k-atari-mint${UNAME_RELEASE}
+       exit ;;
+    milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
+        echo m68k-milan-mint${UNAME_RELEASE}
+        exit ;;
+    hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
+        echo m68k-hades-mint${UNAME_RELEASE}
+        exit ;;
+    *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
+        echo m68k-unknown-mint${UNAME_RELEASE}
+        exit ;;
+    m68k:machten:*:*)
+       echo m68k-apple-machten${UNAME_RELEASE}
+       exit ;;
+    powerpc:machten:*:*)
+       echo powerpc-apple-machten${UNAME_RELEASE}
+       exit ;;
+    RISC*:Mach:*:*)
+       echo mips-dec-mach_bsd4.3
+       exit ;;
+    RISC*:ULTRIX:*:*)
+       echo mips-dec-ultrix${UNAME_RELEASE}
+       exit ;;
+    VAX*:ULTRIX*:*:*)
+       echo vax-dec-ultrix${UNAME_RELEASE}
+       exit ;;
+    2020:CLIX:*:* | 2430:CLIX:*:*)
+       echo clipper-intergraph-clix${UNAME_RELEASE}
+       exit ;;
+    mips:*:*:UMIPS | mips:*:*:RISCos)
+       eval $set_cc_for_build
+       sed 's/^        //' << EOF >$dummy.c
+#ifdef __cplusplus
+#include <stdio.h>  /* for printf() prototype */
+       int main (int argc, char *argv[]) {
+#else
+       int main (argc, argv) int argc; char *argv[]; {
+#endif
+       #if defined (host_mips) && defined (MIPSEB)
+       #if defined (SYSTYPE_SYSV)
+         printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
+       #endif
+       #if defined (SYSTYPE_SVR4)
+         printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
+       #endif
+       #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
+         printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
+       #endif
+       #endif
+         exit (-1);
+       }
+EOF
+       $CC_FOR_BUILD -o $dummy $dummy.c &&
+         dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
+         SYSTEM_NAME=`$dummy $dummyarg` &&
+           { echo "$SYSTEM_NAME"; exit; }
+       echo mips-mips-riscos${UNAME_RELEASE}
+       exit ;;
+    Motorola:PowerMAX_OS:*:*)
+       echo powerpc-motorola-powermax
+       exit ;;
+    Motorola:*:4.3:PL8-*)
+       echo powerpc-harris-powermax
+       exit ;;
+    Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
+       echo powerpc-harris-powermax
+       exit ;;
+    Night_Hawk:Power_UNIX:*:*)
+       echo powerpc-harris-powerunix
+       exit ;;
+    m88k:CX/UX:7*:*)
+       echo m88k-harris-cxux7
+       exit ;;
+    m88k:*:4*:R4*)
+       echo m88k-motorola-sysv4
+       exit ;;
+    m88k:*:3*:R3*)
+       echo m88k-motorola-sysv3
+       exit ;;
+    AViiON:dgux:*:*)
+        # DG/UX returns AViiON for all architectures
+        UNAME_PROCESSOR=`/usr/bin/uname -p`
+       if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
+       then
+           if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
+              [ ${TARGET_BINARY_INTERFACE}x = x ]
+           then
+               echo m88k-dg-dgux${UNAME_RELEASE}
+           else
+               echo m88k-dg-dguxbcs${UNAME_RELEASE}
+           fi
+       else
+           echo i586-dg-dgux${UNAME_RELEASE}
+       fi
+       exit ;;
+    M88*:DolphinOS:*:*)        # DolphinOS (SVR3)
+       echo m88k-dolphin-sysv3
+       exit ;;
+    M88*:*:R3*:*)
+       # Delta 88k system running SVR3
+       echo m88k-motorola-sysv3
+       exit ;;
+    XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
+       echo m88k-tektronix-sysv3
+       exit ;;
+    Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
+       echo m68k-tektronix-bsd
+       exit ;;
+    *:IRIX*:*:*)
+       echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
+       exit ;;
+    ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
+       echo romp-ibm-aix     # uname -m gives an 8 hex-code CPU id
+       exit ;;               # Note that: echo "'`uname -s`'" gives 'AIX '
+    i*86:AIX:*:*)
+       echo i386-ibm-aix
+       exit ;;
+    ia64:AIX:*:*)
+       if [ -x /usr/bin/oslevel ] ; then
+               IBM_REV=`/usr/bin/oslevel`
+       else
+               IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+       fi
+       echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
+       exit ;;
+    *:AIX:2:3)
+       if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
+               eval $set_cc_for_build
+               sed 's/^                //' << EOF >$dummy.c
+               #include <sys/systemcfg.h>
+
+               main()
+                       {
+                       if (!__power_pc())
+                               exit(1);
+                       puts("powerpc-ibm-aix3.2.5");
+                       exit(0);
+                       }
+EOF
+               if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
+               then
+                       echo "$SYSTEM_NAME"
+               else
+                       echo rs6000-ibm-aix3.2.5
+               fi
+       elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
+               echo rs6000-ibm-aix3.2.4
+       else
+               echo rs6000-ibm-aix3.2
+       fi
+       exit ;;
+    *:AIX:*:[456])
+       IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
+       if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
+               IBM_ARCH=rs6000
+       else
+               IBM_ARCH=powerpc
+       fi
+       if [ -x /usr/bin/oslevel ] ; then
+               IBM_REV=`/usr/bin/oslevel`
+       else
+               IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+       fi
+       echo ${IBM_ARCH}-ibm-aix${IBM_REV}
+       exit ;;
+    *:AIX:*:*)
+       echo rs6000-ibm-aix
+       exit ;;
+    ibmrt:4.4BSD:*|romp-ibm:BSD:*)
+       echo romp-ibm-bsd4.4
+       exit ;;
+    ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
+       echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
+       exit ;;                             # report: romp-ibm BSD 4.3
+    *:BOSX:*:*)
+       echo rs6000-bull-bosx
+       exit ;;
+    DPX/2?00:B.O.S.:*:*)
+       echo m68k-bull-sysv3
+       exit ;;
+    9000/[34]??:4.3bsd:1.*:*)
+       echo m68k-hp-bsd
+       exit ;;
+    hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
+       echo m68k-hp-bsd4.4
+       exit ;;
+    9000/[34678]??:HP-UX:*:*)
+       HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+       case "${UNAME_MACHINE}" in
+           9000/31? )            HP_ARCH=m68000 ;;
+           9000/[34]?? )         HP_ARCH=m68k ;;
+           9000/[678][0-9][0-9])
+               if [ -x /usr/bin/getconf ]; then
+                   sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
+                    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
+                    case "${sc_cpu_version}" in
+                      523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
+                      528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
+                      532)                      # CPU_PA_RISC2_0
+                        case "${sc_kernel_bits}" in
+                          32) HP_ARCH="hppa2.0n" ;;
+                          64) HP_ARCH="hppa2.0w" ;;
+                         '') HP_ARCH="hppa2.0" ;;   # HP-UX 10.20
+                        esac ;;
+                    esac
+               fi
+               if [ "${HP_ARCH}" = "" ]; then
+                   eval $set_cc_for_build
+                   sed 's/^              //' << EOF >$dummy.c
+
+              #define _HPUX_SOURCE
+              #include <stdlib.h>
+              #include <unistd.h>
+
+              int main ()
+              {
+              #if defined(_SC_KERNEL_BITS)
+                  long bits = sysconf(_SC_KERNEL_BITS);
+              #endif
+                  long cpu  = sysconf (_SC_CPU_VERSION);
+
+                  switch (cpu)
+               {
+               case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
+               case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
+               case CPU_PA_RISC2_0:
+              #if defined(_SC_KERNEL_BITS)
+                   switch (bits)
+                       {
+                       case 64: puts ("hppa2.0w"); break;
+                       case 32: puts ("hppa2.0n"); break;
+                       default: puts ("hppa2.0"); break;
+                       } break;
+              #else  /* !defined(_SC_KERNEL_BITS) */
+                   puts ("hppa2.0"); break;
+              #endif
+               default: puts ("hppa1.0"); break;
+               }
+                  exit (0);
+              }
+EOF
+                   (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
+                   test -z "$HP_ARCH" && HP_ARCH=hppa
+               fi ;;
+       esac
+       if [ ${HP_ARCH} = "hppa2.0w" ]
+       then
+           eval $set_cc_for_build
+
+           # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
+           # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler
+           # generating 64-bit code.  GNU and HP use different nomenclature:
+           #
+           # $ CC_FOR_BUILD=cc ./config.guess
+           # => hppa2.0w-hp-hpux11.23
+           # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
+           # => hppa64-hp-hpux11.23
+
+           if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
+               grep __LP64__ >/dev/null
+           then
+               HP_ARCH="hppa2.0w"
+           else
+               HP_ARCH="hppa64"
+           fi
+       fi
+       echo ${HP_ARCH}-hp-hpux${HPUX_REV}
+       exit ;;
+    ia64:HP-UX:*:*)
+       HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+       echo ia64-hp-hpux${HPUX_REV}
+       exit ;;
+    3050*:HI-UX:*:*)
+       eval $set_cc_for_build
+       sed 's/^        //' << EOF >$dummy.c
+       #include <unistd.h>
+       int
+       main ()
+       {
+         long cpu = sysconf (_SC_CPU_VERSION);
+         /* The order matters, because CPU_IS_HP_MC68K erroneously returns
+            true for CPU_PA_RISC1_0.  CPU_IS_PA_RISC returns correct
+            results, however.  */
+         if (CPU_IS_PA_RISC (cpu))
+           {
+             switch (cpu)
+               {
+                 case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
+                 case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
+                 case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
+                 default: puts ("hppa-hitachi-hiuxwe2"); break;
+               }
+           }
+         else if (CPU_IS_HP_MC68K (cpu))
+           puts ("m68k-hitachi-hiuxwe2");
+         else puts ("unknown-hitachi-hiuxwe2");
+         exit (0);
+       }
+EOF
+       $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
+               { echo "$SYSTEM_NAME"; exit; }
+       echo unknown-hitachi-hiuxwe2
+       exit ;;
+    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
+       echo hppa1.1-hp-bsd
+       exit ;;
+    9000/8??:4.3bsd:*:*)
+       echo hppa1.0-hp-bsd
+       exit ;;
+    *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
+       echo hppa1.0-hp-mpeix
+       exit ;;
+    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
+       echo hppa1.1-hp-osf
+       exit ;;
+    hp8??:OSF1:*:*)
+       echo hppa1.0-hp-osf
+       exit ;;
+    i*86:OSF1:*:*)
+       if [ -x /usr/sbin/sysversion ] ; then
+           echo ${UNAME_MACHINE}-unknown-osf1mk
+       else
+           echo ${UNAME_MACHINE}-unknown-osf1
+       fi
+       exit ;;
+    parisc*:Lites*:*:*)
+       echo hppa1.1-hp-lites
+       exit ;;
+    C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
+       echo c1-convex-bsd
+        exit ;;
+    C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
+       if getsysinfo -f scalar_acc
+       then echo c32-convex-bsd
+       else echo c2-convex-bsd
+       fi
+        exit ;;
+    C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
+       echo c34-convex-bsd
+        exit ;;
+    C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
+       echo c38-convex-bsd
+        exit ;;
+    C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
+       echo c4-convex-bsd
+        exit ;;
+    CRAY*Y-MP:*:*:*)
+       echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+       exit ;;
+    CRAY*[A-Z]90:*:*:*)
+       echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
+       | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
+             -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
+             -e 's/\.[^.]*$/.X/'
+       exit ;;
+    CRAY*TS:*:*:*)
+       echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+       exit ;;
+    CRAY*T3E:*:*:*)
+       echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+       exit ;;
+    CRAY*SV1:*:*:*)
+       echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+       exit ;;
+    *:UNICOS/mp:*:*)
+       echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+       exit ;;
+    F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
+       FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+        FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
+        echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+        exit ;;
+    5000:UNIX_System_V:4.*:*)
+        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+        FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
+        echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+       exit ;;
+    i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
+       echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
+       exit ;;
+    sparc*:BSD/OS:*:*)
+       echo sparc-unknown-bsdi${UNAME_RELEASE}
+       exit ;;
+    *:BSD/OS:*:*)
+       echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
+       exit ;;
+    *:FreeBSD:*:*)
+       case ${UNAME_MACHINE} in
+           pc98)
+               echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+           amd64)
+               echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+           *)
+               echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+       esac
+       exit ;;
+    i*:CYGWIN*:*)
+       echo ${UNAME_MACHINE}-pc-cygwin
+       exit ;;
+    *:MINGW*:*)
+       echo ${UNAME_MACHINE}-pc-mingw32
+       exit ;;
+    i*:windows32*:*)
+       # uname -m includes "-pc" on this system.
+       echo ${UNAME_MACHINE}-mingw32
+       exit ;;
+    i*:PW*:*)
+       echo ${UNAME_MACHINE}-pc-pw32
+       exit ;;
+    *:Interix*:[3456]*)
+       case ${UNAME_MACHINE} in
+           x86)
+               echo i586-pc-interix${UNAME_RELEASE}
+               exit ;;
+           EM64T | authenticamd | genuineintel)
+               echo x86_64-unknown-interix${UNAME_RELEASE}
+               exit ;;
+           IA64)
+               echo ia64-unknown-interix${UNAME_RELEASE}
+               exit ;;
+       esac ;;
+    [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
+       echo i${UNAME_MACHINE}-pc-mks
+       exit ;;
+    i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
+       # How do we know it's Interix rather than the generic POSIX subsystem?
+       # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
+       # UNAME_MACHINE based on the output of uname instead of i386?
+       echo i586-pc-interix
+       exit ;;
+    i*:UWIN*:*)
+       echo ${UNAME_MACHINE}-pc-uwin
+       exit ;;
+    amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
+       echo x86_64-unknown-cygwin
+       exit ;;
+    p*:CYGWIN*:*)
+       echo powerpcle-unknown-cygwin
+       exit ;;
+    prep*:SunOS:5.*:*)
+       echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit ;;
+    *:GNU:*:*)
+       # the GNU system
+       echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
+       exit ;;
+    *:GNU/*:*:*)
+       # other systems with GNU libc and userland
+       echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
+       exit ;;
+    i*86:Minix:*:*)
+       echo ${UNAME_MACHINE}-pc-minix
+       exit ;;
+    arm*:Linux:*:*)
+       eval $set_cc_for_build
+       if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
+           | grep -q __ARM_EABI__
+       then
+           echo ${UNAME_MACHINE}-unknown-linux-gnu
+       else
+           echo ${UNAME_MACHINE}-unknown-linux-gnueabi
+       fi
+       exit ;;
+    avr32*:Linux:*:*)
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
+       exit ;;
+    cris:Linux:*:*)
+       echo cris-axis-linux-gnu
+       exit ;;
+    crisv32:Linux:*:*)
+       echo crisv32-axis-linux-gnu
+       exit ;;
+    frv:Linux:*:*)
+       echo frv-unknown-linux-gnu
+       exit ;;
+    ia64:Linux:*:*)
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
+       exit ;;
+    m32r*:Linux:*:*)
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
+       exit ;;
+    m68*:Linux:*:*)
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
+       exit ;;
+    mips:Linux:*:*)
+       eval $set_cc_for_build
+       sed 's/^        //' << EOF >$dummy.c
+       #undef CPU
+       #undef mips
+       #undef mipsel
+       #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+       CPU=mipsel
+       #else
+       #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+       CPU=mips
+       #else
+       CPU=
+       #endif
+       #endif
+EOF
+       eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+           /^CPU/{
+               s: ::g
+               p
+           }'`"
+       test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
+       ;;
+    mips64:Linux:*:*)
+       eval $set_cc_for_build
+       sed 's/^        //' << EOF >$dummy.c
+       #undef CPU
+       #undef mips64
+       #undef mips64el
+       #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+       CPU=mips64el
+       #else
+       #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+       CPU=mips64
+       #else
+       CPU=
+       #endif
+       #endif
+EOF
+       eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+           /^CPU/{
+               s: ::g
+               p
+           }'`"
+       test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
+       ;;
+    or32:Linux:*:*)
+       echo or32-unknown-linux-gnu
+       exit ;;
+    ppc:Linux:*:*)
+       echo powerpc-unknown-linux-gnu
+       exit ;;
+    ppc64:Linux:*:*)
+       echo powerpc64-unknown-linux-gnu
+       exit ;;
+    alpha:Linux:*:*)
+       case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
+         EV5)   UNAME_MACHINE=alphaev5 ;;
+         EV56)  UNAME_MACHINE=alphaev56 ;;
+         PCA56) UNAME_MACHINE=alphapca56 ;;
+         PCA57) UNAME_MACHINE=alphapca56 ;;
+         EV6)   UNAME_MACHINE=alphaev6 ;;
+         EV67)  UNAME_MACHINE=alphaev67 ;;
+         EV68*) UNAME_MACHINE=alphaev68 ;;
+        esac
+       objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null
+       if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
+       echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
+       exit ;;
+    padre:Linux:*:*)
+       echo sparc-unknown-linux-gnu
+       exit ;;
+    parisc:Linux:*:* | hppa:Linux:*:*)
+       # Look for CPU level
+       case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
+         PA7*) echo hppa1.1-unknown-linux-gnu ;;
+         PA8*) echo hppa2.0-unknown-linux-gnu ;;
+         *)    echo hppa-unknown-linux-gnu ;;
+       esac
+       exit ;;
+    parisc64:Linux:*:* | hppa64:Linux:*:*)
+       echo hppa64-unknown-linux-gnu
+       exit ;;
+    s390:Linux:*:* | s390x:Linux:*:*)
+       echo ${UNAME_MACHINE}-ibm-linux
+       exit ;;
+    sh64*:Linux:*:*)
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
+       exit ;;
+    sh*:Linux:*:*)
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
+       exit ;;
+    sparc:Linux:*:* | sparc64:Linux:*:*)
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
+       exit ;;
+    vax:Linux:*:*)
+       echo ${UNAME_MACHINE}-dec-linux-gnu
+       exit ;;
+    x86_64:Linux:*:*)
+       echo x86_64-unknown-linux-gnu
+       exit ;;
+    xtensa*:Linux:*:*)
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
+       exit ;;
+    i*86:Linux:*:*)
+       # The BFD linker knows what the default object file format is, so
+       # first see if it will tell us. cd to the root directory to prevent
+       # problems with other programs or directories called `ld' in the path.
+       # Set LC_ALL=C to ensure ld outputs messages in English.
+       ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \
+                        | sed -ne '/supported targets:/!d
+                                   s/[         ][      ]*/ /g
+                                   s/.*supported targets: *//
+                                   s/ .*//
+                                   p'`
+        case "$ld_supported_targets" in
+         elf32-i386)
+               TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu"
+               ;;
+         a.out-i386-linux)
+               echo "${UNAME_MACHINE}-pc-linux-gnuaout"
+               exit ;;
+         "")
+               # Either a pre-BFD a.out linker (linux-gnuoldld) or
+               # one that does not give us useful --help.
+               echo "${UNAME_MACHINE}-pc-linux-gnuoldld"
+               exit ;;
+       esac
+       # Determine whether the default compiler is a.out or elf
+       eval $set_cc_for_build
+       sed 's/^        //' << EOF >$dummy.c
+       #include <features.h>
+       #ifdef __ELF__
+       # ifdef __GLIBC__
+       #  if __GLIBC__ >= 2
+       LIBC=gnu
+       #  else
+       LIBC=gnulibc1
+       #  endif
+       # else
+       LIBC=gnulibc1
+       # endif
+       #else
+       #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+       LIBC=gnu
+       #else
+       LIBC=gnuaout
+       #endif
+       #endif
+       #ifdef __dietlibc__
+       LIBC=dietlibc
+       #endif
+EOF
+       eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+           /^LIBC/{
+               s: ::g
+               p
+           }'`"
+       test x"${LIBC}" != x && {
+               echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
+               exit
+       }
+       test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; }
+       ;;
+    i*86:DYNIX/ptx:4*:*)
+       # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
+       # earlier versions are messed up and put the nodename in both
+       # sysname and nodename.
+       echo i386-sequent-sysv4
+       exit ;;
+    i*86:UNIX_SV:4.2MP:2.*)
+        # Unixware is an offshoot of SVR4, but it has its own version
+        # number series starting with 2...
+        # I am not positive that other SVR4 systems won't match this,
+       # I just have to hope.  -- rms.
+        # Use sysv4.2uw... so that sysv4* matches it.
+       echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
+       exit ;;
+    i*86:OS/2:*:*)
+       # If we were able to find `uname', then EMX Unix compatibility
+       # is probably installed.
+       echo ${UNAME_MACHINE}-pc-os2-emx
+       exit ;;
+    i*86:XTS-300:*:STOP)
+       echo ${UNAME_MACHINE}-unknown-stop
+       exit ;;
+    i*86:atheos:*:*)
+       echo ${UNAME_MACHINE}-unknown-atheos
+       exit ;;
+    i*86:syllable:*:*)
+       echo ${UNAME_MACHINE}-pc-syllable
+       exit ;;
+    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
+       echo i386-unknown-lynxos${UNAME_RELEASE}
+       exit ;;
+    i*86:*DOS:*:*)
+       echo ${UNAME_MACHINE}-pc-msdosdjgpp
+       exit ;;
+    i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
+       UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
+       if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
+               echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
+       else
+               echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
+       fi
+       exit ;;
+    i*86:*:5:[678]*)
+       # UnixWare 7.x, OpenUNIX and OpenServer 6.
+       case `/bin/uname -X | grep "^Machine"` in
+           *486*)           UNAME_MACHINE=i486 ;;
+           *Pentium)        UNAME_MACHINE=i586 ;;
+           *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
+       esac
+       echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
+       exit ;;
+    i*86:*:3.2:*)
+       if test -f /usr/options/cb.name; then
+               UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
+               echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
+       elif /bin/uname -X 2>/dev/null >/dev/null ; then
+               UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
+               (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
+               (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
+                       && UNAME_MACHINE=i586
+               (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
+                       && UNAME_MACHINE=i686
+               (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
+                       && UNAME_MACHINE=i686
+               echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
+       else
+               echo ${UNAME_MACHINE}-pc-sysv32
+       fi
+       exit ;;
+    pc:*:*:*)
+       # Left here for compatibility:
+        # uname -m prints for DJGPP always 'pc', but it prints nothing about
+        # the processor, so we play safe by assuming i586.
+       # Note: whatever this is, it MUST be the same as what config.sub
+       # prints for the "djgpp" host, or else GDB configury will decide that
+       # this is a cross-build.
+       echo i586-pc-msdosdjgpp
+        exit ;;
+    Intel:Mach:3*:*)
+       echo i386-pc-mach3
+       exit ;;
+    paragon:*:*:*)
+       echo i860-intel-osf1
+       exit ;;
+    i860:*:4.*:*) # i860-SVR4
+       if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
+         echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
+       else # Add other i860-SVR4 vendors below as they are discovered.
+         echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
+       fi
+       exit ;;
+    mini*:CTIX:SYS*5:*)
+       # "miniframe"
+       echo m68010-convergent-sysv
+       exit ;;
+    mc68k:UNIX:SYSTEM5:3.51m)
+       echo m68k-convergent-sysv
+       exit ;;
+    M680?0:D-NIX:5.3:*)
+       echo m68k-diab-dnix
+       exit ;;
+    M68*:*:R3V[5678]*:*)
+       test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
+    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
+       OS_REL=''
+       test -r /etc/.relid \
+       && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+       /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+         && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+       /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+         && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+    3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
+        /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+          && { echo i486-ncr-sysv4; exit; } ;;
+    NCR*:*:4.2:* | MPRAS*:*:4.2:*)
+       OS_REL='.3'
+       test -r /etc/.relid \
+           && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+       /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+           && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+       /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+           && { echo i586-ncr-sysv4.3${OS_REL}; exit; }
+       /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
+           && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+    m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
+       echo m68k-unknown-lynxos${UNAME_RELEASE}
+       exit ;;
+    mc68030:UNIX_System_V:4.*:*)
+       echo m68k-atari-sysv4
+       exit ;;
+    TSUNAMI:LynxOS:2.*:*)
+       echo sparc-unknown-lynxos${UNAME_RELEASE}
+       exit ;;
+    rs6000:LynxOS:2.*:*)
+       echo rs6000-unknown-lynxos${UNAME_RELEASE}
+       exit ;;
+    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
+       echo powerpc-unknown-lynxos${UNAME_RELEASE}
+       exit ;;
+    SM[BE]S:UNIX_SV:*:*)
+       echo mips-dde-sysv${UNAME_RELEASE}
+       exit ;;
+    RM*:ReliantUNIX-*:*:*)
+       echo mips-sni-sysv4
+       exit ;;
+    RM*:SINIX-*:*:*)
+       echo mips-sni-sysv4
+       exit ;;
+    *:SINIX-*:*:*)
+       if uname -p 2>/dev/null >/dev/null ; then
+               UNAME_MACHINE=`(uname -p) 2>/dev/null`
+               echo ${UNAME_MACHINE}-sni-sysv4
+       else
+               echo ns32k-sni-sysv
+       fi
+       exit ;;
+    PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
+                      # says <Richard.M.Bartel@ccMail.Census.GOV>
+        echo i586-unisys-sysv4
+        exit ;;
+    *:UNIX_System_V:4*:FTX*)
+       # From Gerald Hewes <hewes@openmarket.com>.
+       # How about differentiating between stratus architectures? -djm
+       echo hppa1.1-stratus-sysv4
+       exit ;;
+    *:*:*:FTX*)
+       # From seanf@swdc.stratus.com.
+       echo i860-stratus-sysv4
+       exit ;;
+    i*86:VOS:*:*)
+       # From Paul.Green@stratus.com.
+       echo ${UNAME_MACHINE}-stratus-vos
+       exit ;;
+    *:VOS:*:*)
+       # From Paul.Green@stratus.com.
+       echo hppa1.1-stratus-vos
+       exit ;;
+    mc68*:A/UX:*:*)
+       echo m68k-apple-aux${UNAME_RELEASE}
+       exit ;;
+    news*:NEWS-OS:6*:*)
+       echo mips-sony-newsos6
+       exit ;;
+    R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
+       if [ -d /usr/nec ]; then
+               echo mips-nec-sysv${UNAME_RELEASE}
+       else
+               echo mips-unknown-sysv${UNAME_RELEASE}
+       fi
+        exit ;;
+    BeBox:BeOS:*:*)    # BeOS running on hardware made by Be, PPC only.
+       echo powerpc-be-beos
+       exit ;;
+    BeMac:BeOS:*:*)    # BeOS running on Mac or Mac clone, PPC only.
+       echo powerpc-apple-beos
+       exit ;;
+    BePC:BeOS:*:*)     # BeOS running on Intel PC compatible.
+       echo i586-pc-beos
+       exit ;;
+    BePC:Haiku:*:*)    # Haiku running on Intel PC compatible.
+       echo i586-pc-haiku
+       exit ;;
+    SX-4:SUPER-UX:*:*)
+       echo sx4-nec-superux${UNAME_RELEASE}
+       exit ;;
+    SX-5:SUPER-UX:*:*)
+       echo sx5-nec-superux${UNAME_RELEASE}
+       exit ;;
+    SX-6:SUPER-UX:*:*)
+       echo sx6-nec-superux${UNAME_RELEASE}
+       exit ;;
+    SX-7:SUPER-UX:*:*)
+       echo sx7-nec-superux${UNAME_RELEASE}
+       exit ;;
+    SX-8:SUPER-UX:*:*)
+       echo sx8-nec-superux${UNAME_RELEASE}
+       exit ;;
+    SX-8R:SUPER-UX:*:*)
+       echo sx8r-nec-superux${UNAME_RELEASE}
+       exit ;;
+    Power*:Rhapsody:*:*)
+       echo powerpc-apple-rhapsody${UNAME_RELEASE}
+       exit ;;
+    *:Rhapsody:*:*)
+       echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
+       exit ;;
+    *:Darwin:*:*)
+       UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
+       case $UNAME_PROCESSOR in
+           unknown) UNAME_PROCESSOR=powerpc ;;
+       esac
+       echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
+       exit ;;
+    *:procnto*:*:* | *:QNX:[0123456789]*:*)
+       UNAME_PROCESSOR=`uname -p`
+       if test "$UNAME_PROCESSOR" = "x86"; then
+               UNAME_PROCESSOR=i386
+               UNAME_MACHINE=pc
+       fi
+       echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
+       exit ;;
+    *:QNX:*:4*)
+       echo i386-pc-qnx
+       exit ;;
+    NSE-?:NONSTOP_KERNEL:*:*)
+       echo nse-tandem-nsk${UNAME_RELEASE}
+       exit ;;
+    NSR-?:NONSTOP_KERNEL:*:*)
+       echo nsr-tandem-nsk${UNAME_RELEASE}
+       exit ;;
+    *:NonStop-UX:*:*)
+       echo mips-compaq-nonstopux
+       exit ;;
+    BS2000:POSIX*:*:*)
+       echo bs2000-siemens-sysv
+       exit ;;
+    DS/*:UNIX_System_V:*:*)
+       echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
+       exit ;;
+    *:Plan9:*:*)
+       # "uname -m" is not consistent, so use $cputype instead. 386
+       # is converted to i386 for consistency with other x86
+       # operating systems.
+       if test "$cputype" = "386"; then
+           UNAME_MACHINE=i386
+       else
+           UNAME_MACHINE="$cputype"
+       fi
+       echo ${UNAME_MACHINE}-unknown-plan9
+       exit ;;
+    *:TOPS-10:*:*)
+       echo pdp10-unknown-tops10
+       exit ;;
+    *:TENEX:*:*)
+       echo pdp10-unknown-tenex
+       exit ;;
+    KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
+       echo pdp10-dec-tops20
+       exit ;;
+    XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
+       echo pdp10-xkl-tops20
+       exit ;;
+    *:TOPS-20:*:*)
+       echo pdp10-unknown-tops20
+       exit ;;
+    *:ITS:*:*)
+       echo pdp10-unknown-its
+       exit ;;
+    SEI:*:*:SEIUX)
+        echo mips-sei-seiux${UNAME_RELEASE}
+       exit ;;
+    *:DragonFly:*:*)
+       echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
+       exit ;;
+    *:*VMS:*:*)
+       UNAME_MACHINE=`(uname -p) 2>/dev/null`
+       case "${UNAME_MACHINE}" in
+           A*) echo alpha-dec-vms ; exit ;;
+           I*) echo ia64-dec-vms ; exit ;;
+           V*) echo vax-dec-vms ; exit ;;
+       esac ;;
+    *:XENIX:*:SysV)
+       echo i386-pc-xenix
+       exit ;;
+    i*86:skyos:*:*)
+       echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
+       exit ;;
+    i*86:rdos:*:*)
+       echo ${UNAME_MACHINE}-pc-rdos
+       exit ;;
+    i*86:AROS:*:*)
+       echo ${UNAME_MACHINE}-pc-aros
+       exit ;;
+esac
+
+#echo '(No uname command or uname output not recognized.)' 1>&2
+#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
+
+eval $set_cc_for_build
+cat >$dummy.c <<EOF
+#ifdef _SEQUENT_
+# include <sys/types.h>
+# include <sys/utsname.h>
+#endif
+main ()
+{
+#if defined (sony)
+#if defined (MIPSEB)
+  /* BFD wants "bsd" instead of "newsos".  Perhaps BFD should be changed,
+     I don't know....  */
+  printf ("mips-sony-bsd\n"); exit (0);
+#else
+#include <sys/param.h>
+  printf ("m68k-sony-newsos%s\n",
+#ifdef NEWSOS4
+          "4"
+#else
+         ""
+#endif
+         ); exit (0);
+#endif
+#endif
+
+#if defined (__arm) && defined (__acorn) && defined (__unix)
+  printf ("arm-acorn-riscix\n"); exit (0);
+#endif
+
+#if defined (hp300) && !defined (hpux)
+  printf ("m68k-hp-bsd\n"); exit (0);
+#endif
+
+#if defined (NeXT)
+#if !defined (__ARCHITECTURE__)
+#define __ARCHITECTURE__ "m68k"
+#endif
+  int version;
+  version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
+  if (version < 4)
+    printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
+  else
+    printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
+  exit (0);
+#endif
+
+#if defined (MULTIMAX) || defined (n16)
+#if defined (UMAXV)
+  printf ("ns32k-encore-sysv\n"); exit (0);
+#else
+#if defined (CMU)
+  printf ("ns32k-encore-mach\n"); exit (0);
+#else
+  printf ("ns32k-encore-bsd\n"); exit (0);
+#endif
+#endif
+#endif
+
+#if defined (__386BSD__)
+  printf ("i386-pc-bsd\n"); exit (0);
+#endif
+
+#if defined (sequent)
+#if defined (i386)
+  printf ("i386-sequent-dynix\n"); exit (0);
+#endif
+#if defined (ns32000)
+  printf ("ns32k-sequent-dynix\n"); exit (0);
+#endif
+#endif
+
+#if defined (_SEQUENT_)
+    struct utsname un;
+
+    uname(&un);
+
+    if (strncmp(un.version, "V2", 2) == 0) {
+       printf ("i386-sequent-ptx2\n"); exit (0);
+    }
+    if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
+       printf ("i386-sequent-ptx1\n"); exit (0);
+    }
+    printf ("i386-sequent-ptx\n"); exit (0);
+
+#endif
+
+#if defined (vax)
+# if !defined (ultrix)
+#  include <sys/param.h>
+#  if defined (BSD)
+#   if BSD == 43
+      printf ("vax-dec-bsd4.3\n"); exit (0);
+#   else
+#    if BSD == 199006
+      printf ("vax-dec-bsd4.3reno\n"); exit (0);
+#    else
+      printf ("vax-dec-bsd\n"); exit (0);
+#    endif
+#   endif
+#  else
+    printf ("vax-dec-bsd\n"); exit (0);
+#  endif
+# else
+    printf ("vax-dec-ultrix\n"); exit (0);
+# endif
+#endif
+
+#if defined (alliant) && defined (i860)
+  printf ("i860-alliant-bsd\n"); exit (0);
+#endif
+
+  exit (1);
+}
+EOF
+
+$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` &&
+       { echo "$SYSTEM_NAME"; exit; }
+
+# Apollos put the system type in the environment.
+
+test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; }
+
+# Convex versions that predate uname can use getsysinfo(1)
+
+if [ -x /usr/convex/getsysinfo ]
+then
+    case `getsysinfo -f cpu_type` in
+    c1*)
+       echo c1-convex-bsd
+       exit ;;
+    c2*)
+       if getsysinfo -f scalar_acc
+       then echo c32-convex-bsd
+       else echo c2-convex-bsd
+       fi
+       exit ;;
+    c34*)
+       echo c34-convex-bsd
+       exit ;;
+    c38*)
+       echo c38-convex-bsd
+       exit ;;
+    c4*)
+       echo c4-convex-bsd
+       exit ;;
+    esac
+fi
+
+cat >&2 <<EOF
+$0: unable to guess system type
+
+This script, last modified $timestamp, has failed to recognize
+the operating system you are using. It is advised that you
+download the most up to date version of the config scripts from
+
+  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+and
+  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+
+If the version you run ($0) is already up to date, please
+send the following data and any information you think might be
+pertinent to <config-patches@gnu.org> in order to provide the needed
+information to handle your system.
+
+config.guess timestamp = $timestamp
+
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null`
+
+hostinfo               = `(hostinfo) 2>/dev/null`
+/bin/universe          = `(/bin/universe) 2>/dev/null`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null`
+/bin/arch              = `(/bin/arch) 2>/dev/null`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
+
+UNAME_MACHINE = ${UNAME_MACHINE}
+UNAME_RELEASE = ${UNAME_RELEASE}
+UNAME_SYSTEM  = ${UNAME_SYSTEM}
+UNAME_VERSION = ${UNAME_VERSION}
+EOF
+
+exit 1
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/config.rpath b/config.rpath
new file mode 100755 (executable)
index 0000000..c492a93
--- /dev/null
@@ -0,0 +1,614 @@
+#! /bin/sh
+# Output a system dependent set of variables, describing how to set the
+# run time search path of shared libraries in an executable.
+#
+#   Copyright 1996-2006 Free Software Foundation, Inc.
+#   Taken from GNU libtool, 2001
+#   Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
+#
+#   This file 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.
+#
+# The first argument passed to this file is the canonical host specification,
+#    CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or
+#    CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# The environment variables CC, GCC, LDFLAGS, LD, with_gnu_ld
+# should be set by the caller.
+#
+# The set of defined variables is at the end of this script.
+
+# Known limitations:
+# - On IRIX 6.5 with CC="cc", the run time search patch must not be longer
+#   than 256 bytes, otherwise the compiler driver will dump core. The only
+#   known workaround is to choose shorter directory names for the build
+#   directory and/or the installation directory.
+
+# All known linkers require a `.a' archive for static linking (except MSVC,
+# which needs '.lib').
+libext=a
+shrext=.so
+
+host="$1"
+host_cpu=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
+host_vendor=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
+host_os=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+
+# Code taken from libtool.m4's _LT_CC_BASENAME.
+
+for cc_temp in $CC""; do
+  case $cc_temp in
+    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`echo "$cc_temp" | sed -e 's%^.*/%%'`
+
+# Code taken from libtool.m4's AC_LIBTOOL_PROG_COMPILER_PIC.
+
+wl=
+if test "$GCC" = yes; then
+  wl='-Wl,'
+else
+  case "$host_os" in
+    aix*)
+      wl='-Wl,'
+      ;;
+    darwin*)
+      case $cc_basename in
+        xlc*)
+          wl='-Wl,'
+          ;;
+      esac
+      ;;
+    mingw* | pw32* | os2*)
+      ;;
+    hpux9* | hpux10* | hpux11*)
+      wl='-Wl,'
+      ;;
+    irix5* | irix6* | nonstopux*)
+      wl='-Wl,'
+      ;;
+    newsos6)
+      ;;
+    linux*)
+      case $cc_basename in
+        icc* | ecc*)
+          wl='-Wl,'
+          ;;
+        pgcc | pgf77 | pgf90)
+          wl='-Wl,'
+          ;;
+        ccc*)
+          wl='-Wl,'
+          ;;
+        como)
+          wl='-lopt='
+          ;;
+        *)
+          case `$CC -V 2>&1 | sed 5q` in
+            *Sun\ C*)
+              wl='-Wl,'
+              ;;
+          esac
+          ;;
+      esac
+      ;;
+    osf3* | osf4* | osf5*)
+      wl='-Wl,'
+      ;;
+    sco3.2v5*)
+      ;;
+    solaris*)
+      wl='-Wl,'
+      ;;
+    sunos4*)
+      wl='-Qoption ld '
+      ;;
+    sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
+      wl='-Wl,'
+      ;;
+    sysv4*MP*)
+      ;;
+    unicos*)
+      wl='-Wl,'
+      ;;
+    uts4*)
+      ;;
+  esac
+fi
+
+# Code taken from libtool.m4's AC_LIBTOOL_PROG_LD_SHLIBS.
+
+hardcode_libdir_flag_spec=
+hardcode_libdir_separator=
+hardcode_direct=no
+hardcode_minus_L=no
+
+case "$host_os" in
+  cygwin* | mingw* | pw32*)
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
+    # When not using gcc, we currently assume that we are using
+    # Microsoft Visual C++.
+    if test "$GCC" != yes; then
+      with_gnu_ld=no
+    fi
+    ;;
+  interix*)
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
+    with_gnu_ld=yes
+    ;;
+  openbsd*)
+    with_gnu_ld=no
+    ;;
+esac
+
+ld_shlibs=yes
+if test "$with_gnu_ld" = yes; then
+  # Set some defaults for GNU ld with shared library support. These
+  # are reset later if shared libraries are not supported. Putting them
+  # here allows them to be overridden if necessary.
+  # Unlike libtool, we use -rpath here, not --rpath, since the documented
+  # option of GNU ld is called -rpath, not --rpath.
+  hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+  case "$host_os" in
+    aix3* | aix4* | aix5*)
+      # On AIX/PPC, the GNU linker is very broken
+      if test "$host_cpu" != ia64; then
+        ld_shlibs=no
+      fi
+      ;;
+    amigaos*)
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_minus_L=yes
+      # Samuel A. Falvo II <kc5tja@dolphin.openprojects.net> reports
+      # that the semantics of dynamic libraries on AmigaOS, at least up
+      # to version 4, is to share data among multiple programs linked
+      # with the same dynamic library.  Since this doesn't match the
+      # behavior of shared libraries on other platforms, we cannot use
+      # them.
+      ld_shlibs=no
+      ;;
+    beos*)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+        :
+      else
+        ld_shlibs=no
+      fi
+      ;;
+    cygwin* | mingw* | pw32*)
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      hardcode_libdir_flag_spec='-L$libdir'
+      if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then
+        :
+      else
+        ld_shlibs=no
+      fi
+      ;;
+    interix3*)
+      hardcode_direct=no
+      hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+      ;;
+    linux*)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+        :
+      else
+        ld_shlibs=no
+      fi
+      ;;
+    netbsd*)
+      ;;
+    solaris*)
+      if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then
+        ld_shlibs=no
+      elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+        :
+      else
+        ld_shlibs=no
+      fi
+      ;;
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+      case `$LD -v 2>&1` in
+        *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*)
+          ld_shlibs=no
+          ;;
+        *)
+          if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+            hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`'
+          else
+            ld_shlibs=no
+          fi
+          ;;
+      esac
+      ;;
+    sunos4*)
+      hardcode_direct=yes
+      ;;
+    *)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+        :
+      else
+        ld_shlibs=no
+      fi
+      ;;
+  esac
+  if test "$ld_shlibs" = no; then
+    hardcode_libdir_flag_spec=
+  fi
+else
+  case "$host_os" in
+    aix3*)
+      # Note: this linker hardcodes the directories in LIBPATH if there
+      # are no directories specified by -L.
+      hardcode_minus_L=yes
+      if test "$GCC" = yes; then
+        # Neither direct hardcoding nor static linking is supported with a
+        # broken collect2.
+        hardcode_direct=unsupported
+      fi
+      ;;
+    aix4* | aix5*)
+      if test "$host_cpu" = ia64; then
+        # On IA64, the linker does run time linking by default, so we don't
+        # have to do anything special.
+        aix_use_runtimelinking=no
+      else
+        aix_use_runtimelinking=no
+        # Test if we are trying to use run time linking or normal
+        # AIX style linking. If -brtl is somewhere in LDFLAGS, we
+        # need to do runtime linking.
+        case $host_os in aix4.[23]|aix4.[23].*|aix5*)
+          for ld_flag in $LDFLAGS; do
+            if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
+              aix_use_runtimelinking=yes
+              break
+            fi
+          done
+          ;;
+        esac
+      fi
+      hardcode_direct=yes
+      hardcode_libdir_separator=':'
+      if test "$GCC" = yes; then
+        case $host_os in aix4.[012]|aix4.[012].*)
+          collect2name=`${CC} -print-prog-name=collect2`
+          if test -f "$collect2name" && \
+            strings "$collect2name" | grep resolve_lib_name >/dev/null
+          then
+            # We have reworked collect2
+            hardcode_direct=yes
+          else
+            # We have old collect2
+            hardcode_direct=unsupported
+            hardcode_minus_L=yes
+            hardcode_libdir_flag_spec='-L$libdir'
+            hardcode_libdir_separator=
+          fi
+          ;;
+        esac
+      fi
+      # Begin _LT_AC_SYS_LIBPATH_AIX.
+      echo 'int main () { return 0; }' > conftest.c
+      ${CC} ${LDFLAGS} conftest.c -o conftest
+      aix_libpath=`dump -H conftest 2>/dev/null | sed -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0  *\(.*\)$/\1/; p; }
+}'`
+      if test -z "$aix_libpath"; then
+        aix_libpath=`dump -HX64 conftest 2>/dev/null | sed -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0  *\(.*\)$/\1/; p; }
+}'`
+      fi
+      if test -z "$aix_libpath"; then
+        aix_libpath="/usr/lib:/lib"
+      fi
+      rm -f conftest.c conftest
+      # End _LT_AC_SYS_LIBPATH_AIX.
+      if test "$aix_use_runtimelinking" = yes; then
+        hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
+      else
+        if test "$host_cpu" = ia64; then
+          hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib'
+        else
+          hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
+        fi
+      fi
+      ;;
+    amigaos*)
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_minus_L=yes
+      # see comment about different semantics on the GNU ld section
+      ld_shlibs=no
+      ;;
+    bsdi[45]*)
+      ;;
+    cygwin* | mingw* | pw32*)
+      # When not using gcc, we currently assume that we are using
+      # Microsoft Visual C++.
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      hardcode_libdir_flag_spec=' '
+      libext=lib
+      ;;
+    darwin* | rhapsody*)
+      hardcode_direct=no
+      if test "$GCC" = yes ; then
+        :
+      else
+        case $cc_basename in
+          xlc*)
+            ;;
+          *)
+            ld_shlibs=no
+            ;;
+        esac
+      fi
+      ;;
+    dgux*)
+      hardcode_libdir_flag_spec='-L$libdir'
+      ;;
+    freebsd1*)
+      ld_shlibs=no
+      ;;
+    freebsd2.2*)
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      ;;
+    freebsd2*)
+      hardcode_direct=yes
+      hardcode_minus_L=yes
+      ;;
+    freebsd* | kfreebsd*-gnu | dragonfly*)
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      ;;
+    hpux9*)
+      hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+      hardcode_libdir_separator=:
+      hardcode_direct=yes
+      # hardcode_minus_L: Not really in the search PATH,
+      # but as the default location of the library.
+      hardcode_minus_L=yes
+      ;;
+    hpux10*)
+      if test "$with_gnu_ld" = no; then
+        hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+        hardcode_libdir_separator=:
+        hardcode_direct=yes
+        # hardcode_minus_L: Not really in the search PATH,
+        # but as the default location of the library.
+        hardcode_minus_L=yes
+      fi
+      ;;
+    hpux11*)
+      if test "$with_gnu_ld" = no; then
+        hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+        hardcode_libdir_separator=:
+        case $host_cpu in
+          hppa*64*|ia64*)
+            hardcode_direct=no
+            ;;
+          *)
+            hardcode_direct=yes
+            # hardcode_minus_L: Not really in the search PATH,
+            # but as the default location of the library.
+            hardcode_minus_L=yes
+            ;;
+        esac
+      fi
+      ;;
+    irix5* | irix6* | nonstopux*)
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      ;;
+    netbsd*)
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      ;;
+    newsos6)
+      hardcode_direct=yes
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      ;;
+    openbsd*)
+      hardcode_direct=yes
+      if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+        hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+      else
+        case "$host_os" in
+          openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*)
+            hardcode_libdir_flag_spec='-R$libdir'
+            ;;
+          *)
+            hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+            ;;
+        esac
+      fi
+      ;;
+    os2*)
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_minus_L=yes
+      ;;
+    osf3*)
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      ;;
+    osf4* | osf5*)
+      if test "$GCC" = yes; then
+        hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      else
+        # Both cc and cxx compiler support -rpath directly
+        hardcode_libdir_flag_spec='-rpath $libdir'
+      fi
+      hardcode_libdir_separator=:
+      ;;
+    solaris*)
+      hardcode_libdir_flag_spec='-R$libdir'
+      ;;
+    sunos4*)
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_direct=yes
+      hardcode_minus_L=yes
+      ;;
+    sysv4)
+      case $host_vendor in
+        sni)
+          hardcode_direct=yes # is this really true???
+          ;;
+        siemens)
+          hardcode_direct=no
+          ;;
+        motorola)
+          hardcode_direct=no #Motorola manual says yes, but my tests say they lie
+          ;;
+      esac
+      ;;
+    sysv4.3*)
+      ;;
+    sysv4*MP*)
+      if test -d /usr/nec; then
+        ld_shlibs=yes
+      fi
+      ;;
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7*)
+      ;;
+    sysv5* | sco3.2v5* | sco5v6*)
+      hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`'
+      hardcode_libdir_separator=':'
+      ;;
+    uts4*)
+      hardcode_libdir_flag_spec='-L$libdir'
+      ;;
+    *)
+      ld_shlibs=no
+      ;;
+  esac
+fi
+
+# Check dynamic linker characteristics
+# Code taken from libtool.m4's AC_LIBTOOL_SYS_DYNAMIC_LINKER.
+libname_spec='lib$name'
+case "$host_os" in
+  aix3*)
+    ;;
+  aix4* | aix5*)
+    ;;
+  amigaos*)
+    ;;
+  beos*)
+    ;;
+  bsdi[45]*)
+    ;;
+  cygwin* | mingw* | pw32*)
+    shrext=.dll
+    ;;
+  darwin* | rhapsody*)
+    shrext=.dylib
+    ;;
+  dgux*)
+    ;;
+  freebsd1*)
+    ;;
+  kfreebsd*-gnu)
+    ;;
+  freebsd* | dragonfly*)
+    ;;
+  gnu*)
+    ;;
+  hpux9* | hpux10* | hpux11*)
+    case $host_cpu in
+      ia64*)
+        shrext=.so
+        ;;
+      hppa*64*)
+        shrext=.sl
+        ;;
+      *)
+        shrext=.sl
+        ;;
+    esac
+    ;;
+  interix3*)
+    ;;
+  irix5* | irix6* | nonstopux*)
+    case "$host_os" in
+      irix5* | nonstopux*)
+        libsuff= shlibsuff=
+        ;;
+      *)
+        case $LD in
+          *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") libsuff= shlibsuff= ;;
+          *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") libsuff=32 shlibsuff=N32 ;;
+          *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") libsuff=64 shlibsuff=64 ;;
+          *) libsuff= shlibsuff= ;;
+        esac
+        ;;
+    esac
+    ;;
+  linux*oldld* | linux*aout* | linux*coff*)
+    ;;
+  linux*)
+    ;;
+  knetbsd*-gnu)
+    ;;
+  netbsd*)
+    ;;
+  newsos6)
+    ;;
+  nto-qnx*)
+    ;;
+  openbsd*)
+    ;;
+  os2*)
+    libname_spec='$name'
+    shrext=.dll
+    ;;
+  osf3* | osf4* | osf5*)
+    ;;
+  solaris*)
+    ;;
+  sunos4*)
+    ;;
+  sysv4 | sysv4.3*)
+    ;;
+  sysv4*MP*)
+    ;;
+  sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+    ;;
+  uts4*)
+    ;;
+esac
+
+sed_quote_subst='s/\(["`$\\]\)/\\\1/g'
+escaped_wl=`echo "X$wl" | sed -e 's/^X//' -e "$sed_quote_subst"`
+shlibext=`echo "$shrext" | sed -e 's,^\.,,'`
+escaped_hardcode_libdir_flag_spec=`echo "X$hardcode_libdir_flag_spec" | sed -e 's/^X//' -e "$sed_quote_subst"`
+
+LC_ALL=C sed -e 's/^\([a-zA-Z0-9_]*\)=/acl_cv_\1=/' <<EOF
+
+# How to pass a linker flag through the compiler.
+wl="$escaped_wl"
+
+# Static library suffix (normally "a").
+libext="$libext"
+
+# Shared library suffix (normally "so").
+shlibext="$shlibext"
+
+# Flag to hardcode \$libdir into a binary during linking.
+# This must work even if \$libdir does not exist.
+hardcode_libdir_flag_spec="$escaped_hardcode_libdir_flag_spec"
+
+# Whether we need a single -rpath flag with a separated argument.
+hardcode_libdir_separator="$hardcode_libdir_separator"
+
+# Set to yes if using DIR/libNAME.so during linking hardcodes DIR into the
+# resulting binary.
+hardcode_direct="$hardcode_direct"
+
+# Set to yes if using the -LDIR flag during linking hardcodes DIR into the
+# resulting binary.
+hardcode_minus_L="$hardcode_minus_L"
+
+EOF
diff --git a/config.sub b/config.sub
new file mode 100755 (executable)
index 0000000..a39437d
--- /dev/null
@@ -0,0 +1,1686 @@
+#! /bin/sh
+# Configuration validation subroutine script.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+#   Free Software Foundation, Inc.
+
+timestamp='2009-04-17'
+
+# This file is (in principle) common to ALL GNU software.
+# The presence of a machine in this file suggests that SOME GNU software
+# can handle that machine.  It does not imply ALL GNU software can.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+
+# Please send patches to <config-patches@gnu.org>.  Submit a context
+# diff and a properly formatted ChangeLog entry.
+#
+# Configuration subroutine to validate and canonicalize a configuration type.
+# Supply the specified configuration type as an argument.
+# If it is invalid, we print an error message on stderr and exit with code 1.
+# Otherwise, we print the canonical config type on stdout and succeed.
+
+# This file is supposed to be the same for all GNU packages
+# and recognize all the CPU types, system types and aliases
+# that are meaningful with *any* GNU software.
+# Each package is responsible for reporting which valid configurations
+# it does not support.  The user should be able to distinguish
+# a failure to support a valid configuration from a meaningless
+# configuration.
+
+# The goal of this file is to map all the various variations of a given
+# machine specification into a single specification in the form:
+#      CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or in some cases, the newer four-part form:
+#      CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# It is wrong to echo any other type of specification.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION] CPU-MFR-OPSYS
+       $0 [OPTION] ALIAS
+
+Canonicalize a configuration name.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches@gnu.org>."
+
+version="\
+GNU config.sub ($timestamp)
+
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit ;;
+    --version | -v )
+       echo "$version" ; exit ;;
+    --help | --h* | -h )
+       echo "$usage"; exit ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )        # Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help"
+       exit 1 ;;
+
+    *local*)
+       # First pass through any local machine types.
+       echo $1
+       exit ;;
+
+    * )
+       break ;;
+  esac
+done
+
+case $# in
+ 0) echo "$me: missing argument$help" >&2
+    exit 1;;
+ 1) ;;
+ *) echo "$me: too many arguments$help" >&2
+    exit 1;;
+esac
+
+# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
+# Here we must recognize all the valid KERNEL-OS combinations.
+maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+case $maybe_os in
+  nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
+  uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
+  kopensolaris*-gnu* | \
+  storm-chaos* | os2-emx* | rtmk-nova*)
+    os=-$maybe_os
+    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+    ;;
+  *)
+    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
+    if [ $basic_machine != $1 ]
+    then os=`echo $1 | sed 's/.*-/-/'`
+    else os=; fi
+    ;;
+esac
+
+### Let's recognize common machines as not being operating systems so
+### that things like config.sub decstation-3100 work.  We also
+### recognize some manufacturers as not being operating systems, so we
+### can provide default operating systems below.
+case $os in
+       -sun*os*)
+               # Prevent following clause from handling this invalid input.
+               ;;
+       -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
+       -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
+       -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
+       -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
+       -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
+       -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
+       -apple | -axis | -knuth | -cray)
+               os=
+               basic_machine=$1
+               ;;
+       -sim | -cisco | -oki | -wec | -winbond)
+               os=
+               basic_machine=$1
+               ;;
+       -scout)
+               ;;
+       -wrs)
+               os=-vxworks
+               basic_machine=$1
+               ;;
+       -chorusos*)
+               os=-chorusos
+               basic_machine=$1
+               ;;
+       -chorusrdb)
+               os=-chorusrdb
+               basic_machine=$1
+               ;;
+       -hiux*)
+               os=-hiuxwe2
+               ;;
+       -sco6)
+               os=-sco5v6
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -sco5)
+               os=-sco3.2v5
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -sco4)
+               os=-sco3.2v4
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -sco3.2.[4-9]*)
+               os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -sco3.2v[4-9]*)
+               # Don't forget version if it is 3.2v4 or newer.
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -sco5v6*)
+               # Don't forget version if it is 3.2v4 or newer.
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -sco*)
+               os=-sco3.2v2
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -udk*)
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -isc)
+               os=-isc2.2
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -clix*)
+               basic_machine=clipper-intergraph
+               ;;
+       -isc*)
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -lynx*)
+               os=-lynxos
+               ;;
+       -ptx*)
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
+               ;;
+       -windowsnt*)
+               os=`echo $os | sed -e 's/windowsnt/winnt/'`
+               ;;
+       -psos*)
+               os=-psos
+               ;;
+       -mint | -mint[0-9]*)
+               basic_machine=m68k-atari
+               os=-mint
+               ;;
+esac
+
+# Decode aliases for certain CPU-COMPANY combinations.
+case $basic_machine in
+       # Recognize the basic CPU types without company name.
+       # Some are omitted here because they have special meanings below.
+       1750a | 580 \
+       | a29k \
+       | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
+       | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
+       | am33_2.0 \
+       | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
+       | bfin \
+       | c4x | clipper \
+       | d10v | d30v | dlx | dsp16xx \
+       | fido | fr30 | frv \
+       | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
+       | i370 | i860 | i960 | ia64 \
+       | ip2k | iq2000 \
+       | lm32 \
+       | m32c | m32r | m32rle | m68000 | m68k | m88k \
+       | maxq | mb | microblaze | mcore | mep | metag \
+       | mips | mipsbe | mipseb | mipsel | mipsle \
+       | mips16 \
+       | mips64 | mips64el \
+       | mips64octeon | mips64octeonel \
+       | mips64orion | mips64orionel \
+       | mips64r5900 | mips64r5900el \
+       | mips64vr | mips64vrel \
+       | mips64vr4100 | mips64vr4100el \
+       | mips64vr4300 | mips64vr4300el \
+       | mips64vr5000 | mips64vr5000el \
+       | mips64vr5900 | mips64vr5900el \
+       | mipsisa32 | mipsisa32el \
+       | mipsisa32r2 | mipsisa32r2el \
+       | mipsisa64 | mipsisa64el \
+       | mipsisa64r2 | mipsisa64r2el \
+       | mipsisa64sb1 | mipsisa64sb1el \
+       | mipsisa64sr71k | mipsisa64sr71kel \
+       | mipstx39 | mipstx39el \
+       | mn10200 | mn10300 \
+       | moxie \
+       | mt \
+       | msp430 \
+       | nios | nios2 \
+       | ns16k | ns32k \
+       | or32 \
+       | pdp10 | pdp11 | pj | pjl \
+       | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
+       | pyramid \
+       | score \
+       | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
+       | sh64 | sh64le \
+       | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
+       | sparcv8 | sparcv9 | sparcv9b | sparcv9v \
+       | spu | strongarm \
+       | tahoe | thumb | tic4x | tic80 | tron \
+       | v850 | v850e \
+       | we32k \
+       | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
+       | z8k | z80)
+               basic_machine=$basic_machine-unknown
+               ;;
+       m6811 | m68hc11 | m6812 | m68hc12)
+               # Motorola 68HC11/12.
+               basic_machine=$basic_machine-unknown
+               os=-none
+               ;;
+       m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
+               ;;
+       ms1)
+               basic_machine=mt-unknown
+               ;;
+
+       # We use `pc' rather than `unknown'
+       # because (1) that's what they normally are, and
+       # (2) the word "unknown" tends to confuse beginning users.
+       i*86 | x86_64)
+         basic_machine=$basic_machine-pc
+         ;;
+       # Object if more than one company name word.
+       *-*-*)
+               echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+               exit 1
+               ;;
+       # Recognize the basic CPU types with company name.
+       580-* \
+       | a29k-* \
+       | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
+       | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
+       | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
+       | arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
+       | avr-* | avr32-* \
+       | bfin-* | bs2000-* \
+       | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
+       | clipper-* | craynv-* | cydra-* \
+       | d10v-* | d30v-* | dlx-* \
+       | elxsi-* \
+       | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
+       | h8300-* | h8500-* \
+       | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
+       | i*86-* | i860-* | i960-* | ia64-* \
+       | ip2k-* | iq2000-* \
+       | lm32-* \
+       | m32c-* | m32r-* | m32rle-* \
+       | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
+       | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
+       | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
+       | mips16-* \
+       | mips64-* | mips64el-* \
+       | mips64octeon-* | mips64octeonel-* \
+       | mips64orion-* | mips64orionel-* \
+       | mips64r5900-* | mips64r5900el-* \
+       | mips64vr-* | mips64vrel-* \
+       | mips64vr4100-* | mips64vr4100el-* \
+       | mips64vr4300-* | mips64vr4300el-* \
+       | mips64vr5000-* | mips64vr5000el-* \
+       | mips64vr5900-* | mips64vr5900el-* \
+       | mipsisa32-* | mipsisa32el-* \
+       | mipsisa32r2-* | mipsisa32r2el-* \
+       | mipsisa64-* | mipsisa64el-* \
+       | mipsisa64r2-* | mipsisa64r2el-* \
+       | mipsisa64sb1-* | mipsisa64sb1el-* \
+       | mipsisa64sr71k-* | mipsisa64sr71kel-* \
+       | mipstx39-* | mipstx39el-* \
+       | mmix-* \
+       | mt-* \
+       | msp430-* \
+       | nios-* | nios2-* \
+       | none-* | np1-* | ns16k-* | ns32k-* \
+       | orion-* \
+       | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
+       | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
+       | pyramid-* \
+       | romp-* | rs6000-* \
+       | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
+       | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
+       | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
+       | sparclite-* \
+       | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \
+       | tahoe-* | thumb-* \
+       | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* | tile-* \
+       | tron-* \
+       | v850-* | v850e-* | vax-* \
+       | we32k-* \
+       | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
+       | xstormy16-* | xtensa*-* \
+       | ymp-* \
+       | z8k-* | z80-*)
+               ;;
+       # Recognize the basic CPU types without company name, with glob match.
+       xtensa*)
+               basic_machine=$basic_machine-unknown
+               ;;
+       # Recognize the various machine names and aliases which stand
+       # for a CPU type and a company and sometimes even an OS.
+       386bsd)
+               basic_machine=i386-unknown
+               os=-bsd
+               ;;
+       3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
+               basic_machine=m68000-att
+               ;;
+       3b*)
+               basic_machine=we32k-att
+               ;;
+       a29khif)
+               basic_machine=a29k-amd
+               os=-udi
+               ;;
+       abacus)
+               basic_machine=abacus-unknown
+               ;;
+       adobe68k)
+               basic_machine=m68010-adobe
+               os=-scout
+               ;;
+       alliant | fx80)
+               basic_machine=fx80-alliant
+               ;;
+       altos | altos3068)
+               basic_machine=m68k-altos
+               ;;
+       am29k)
+               basic_machine=a29k-none
+               os=-bsd
+               ;;
+       amd64)
+               basic_machine=x86_64-pc
+               ;;
+       amd64-*)
+               basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       amdahl)
+               basic_machine=580-amdahl
+               os=-sysv
+               ;;
+       amiga | amiga-*)
+               basic_machine=m68k-unknown
+               ;;
+       amigaos | amigados)
+               basic_machine=m68k-unknown
+               os=-amigaos
+               ;;
+       amigaunix | amix)
+               basic_machine=m68k-unknown
+               os=-sysv4
+               ;;
+       apollo68)
+               basic_machine=m68k-apollo
+               os=-sysv
+               ;;
+       apollo68bsd)
+               basic_machine=m68k-apollo
+               os=-bsd
+               ;;
+       aros)
+               basic_machine=i386-pc
+               os=-aros
+               ;;
+       aux)
+               basic_machine=m68k-apple
+               os=-aux
+               ;;
+       balance)
+               basic_machine=ns32k-sequent
+               os=-dynix
+               ;;
+       blackfin)
+               basic_machine=bfin-unknown
+               os=-linux
+               ;;
+       blackfin-*)
+               basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
+               os=-linux
+               ;;
+       c90)
+               basic_machine=c90-cray
+               os=-unicos
+               ;;
+        cegcc)
+               basic_machine=arm-unknown
+               os=-cegcc
+               ;;
+       convex-c1)
+               basic_machine=c1-convex
+               os=-bsd
+               ;;
+       convex-c2)
+               basic_machine=c2-convex
+               os=-bsd
+               ;;
+       convex-c32)
+               basic_machine=c32-convex
+               os=-bsd
+               ;;
+       convex-c34)
+               basic_machine=c34-convex
+               os=-bsd
+               ;;
+       convex-c38)
+               basic_machine=c38-convex
+               os=-bsd
+               ;;
+       cray | j90)
+               basic_machine=j90-cray
+               os=-unicos
+               ;;
+       craynv)
+               basic_machine=craynv-cray
+               os=-unicosmp
+               ;;
+       cr16)
+               basic_machine=cr16-unknown
+               os=-elf
+               ;;
+       crds | unos)
+               basic_machine=m68k-crds
+               ;;
+       crisv32 | crisv32-* | etraxfs*)
+               basic_machine=crisv32-axis
+               ;;
+       cris | cris-* | etrax*)
+               basic_machine=cris-axis
+               ;;
+       crx)
+               basic_machine=crx-unknown
+               os=-elf
+               ;;
+       da30 | da30-*)
+               basic_machine=m68k-da30
+               ;;
+       decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
+               basic_machine=mips-dec
+               ;;
+       decsystem10* | dec10*)
+               basic_machine=pdp10-dec
+               os=-tops10
+               ;;
+       decsystem20* | dec20*)
+               basic_machine=pdp10-dec
+               os=-tops20
+               ;;
+       delta | 3300 | motorola-3300 | motorola-delta \
+             | 3300-motorola | delta-motorola)
+               basic_machine=m68k-motorola
+               ;;
+       delta88)
+               basic_machine=m88k-motorola
+               os=-sysv3
+               ;;
+       dicos)
+               basic_machine=i686-pc
+               os=-dicos
+               ;;
+       djgpp)
+               basic_machine=i586-pc
+               os=-msdosdjgpp
+               ;;
+       dpx20 | dpx20-*)
+               basic_machine=rs6000-bull
+               os=-bosx
+               ;;
+       dpx2* | dpx2*-bull)
+               basic_machine=m68k-bull
+               os=-sysv3
+               ;;
+       ebmon29k)
+               basic_machine=a29k-amd
+               os=-ebmon
+               ;;
+       elxsi)
+               basic_machine=elxsi-elxsi
+               os=-bsd
+               ;;
+       encore | umax | mmax)
+               basic_machine=ns32k-encore
+               ;;
+       es1800 | OSE68k | ose68k | ose | OSE)
+               basic_machine=m68k-ericsson
+               os=-ose
+               ;;
+       fx2800)
+               basic_machine=i860-alliant
+               ;;
+       genix)
+               basic_machine=ns32k-ns
+               ;;
+       gmicro)
+               basic_machine=tron-gmicro
+               os=-sysv
+               ;;
+       go32)
+               basic_machine=i386-pc
+               os=-go32
+               ;;
+       h3050r* | hiux*)
+               basic_machine=hppa1.1-hitachi
+               os=-hiuxwe2
+               ;;
+       h8300hms)
+               basic_machine=h8300-hitachi
+               os=-hms
+               ;;
+       h8300xray)
+               basic_machine=h8300-hitachi
+               os=-xray
+               ;;
+       h8500hms)
+               basic_machine=h8500-hitachi
+               os=-hms
+               ;;
+       harris)
+               basic_machine=m88k-harris
+               os=-sysv3
+               ;;
+       hp300-*)
+               basic_machine=m68k-hp
+               ;;
+       hp300bsd)
+               basic_machine=m68k-hp
+               os=-bsd
+               ;;
+       hp300hpux)
+               basic_machine=m68k-hp
+               os=-hpux
+               ;;
+       hp3k9[0-9][0-9] | hp9[0-9][0-9])
+               basic_machine=hppa1.0-hp
+               ;;
+       hp9k2[0-9][0-9] | hp9k31[0-9])
+               basic_machine=m68000-hp
+               ;;
+       hp9k3[2-9][0-9])
+               basic_machine=m68k-hp
+               ;;
+       hp9k6[0-9][0-9] | hp6[0-9][0-9])
+               basic_machine=hppa1.0-hp
+               ;;
+       hp9k7[0-79][0-9] | hp7[0-79][0-9])
+               basic_machine=hppa1.1-hp
+               ;;
+       hp9k78[0-9] | hp78[0-9])
+               # FIXME: really hppa2.0-hp
+               basic_machine=hppa1.1-hp
+               ;;
+       hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
+               # FIXME: really hppa2.0-hp
+               basic_machine=hppa1.1-hp
+               ;;
+       hp9k8[0-9][13679] | hp8[0-9][13679])
+               basic_machine=hppa1.1-hp
+               ;;
+       hp9k8[0-9][0-9] | hp8[0-9][0-9])
+               basic_machine=hppa1.0-hp
+               ;;
+       hppa-next)
+               os=-nextstep3
+               ;;
+       hppaosf)
+               basic_machine=hppa1.1-hp
+               os=-osf
+               ;;
+       hppro)
+               basic_machine=hppa1.1-hp
+               os=-proelf
+               ;;
+       i370-ibm* | ibm*)
+               basic_machine=i370-ibm
+               ;;
+# I'm not sure what "Sysv32" means.  Should this be sysv3.2?
+       i*86v32)
+               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+               os=-sysv32
+               ;;
+       i*86v4*)
+               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+               os=-sysv4
+               ;;
+       i*86v)
+               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+               os=-sysv
+               ;;
+       i*86sol2)
+               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+               os=-solaris2
+               ;;
+       i386mach)
+               basic_machine=i386-mach
+               os=-mach
+               ;;
+       i386-vsta | vsta)
+               basic_machine=i386-unknown
+               os=-vsta
+               ;;
+       iris | iris4d)
+               basic_machine=mips-sgi
+               case $os in
+                   -irix*)
+                       ;;
+                   *)
+                       os=-irix4
+                       ;;
+               esac
+               ;;
+       isi68 | isi)
+               basic_machine=m68k-isi
+               os=-sysv
+               ;;
+       m68knommu)
+               basic_machine=m68k-unknown
+               os=-linux
+               ;;
+       m68knommu-*)
+               basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
+               os=-linux
+               ;;
+       m88k-omron*)
+               basic_machine=m88k-omron
+               ;;
+       magnum | m3230)
+               basic_machine=mips-mips
+               os=-sysv
+               ;;
+       merlin)
+               basic_machine=ns32k-utek
+               os=-sysv
+               ;;
+       mingw32)
+               basic_machine=i386-pc
+               os=-mingw32
+               ;;
+       mingw32ce)
+               basic_machine=arm-unknown
+               os=-mingw32ce
+               ;;
+       miniframe)
+               basic_machine=m68000-convergent
+               ;;
+       *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
+               basic_machine=m68k-atari
+               os=-mint
+               ;;
+       mips3*-*)
+               basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+               ;;
+       mips3*)
+               basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
+               ;;
+       monitor)
+               basic_machine=m68k-rom68k
+               os=-coff
+               ;;
+       morphos)
+               basic_machine=powerpc-unknown
+               os=-morphos
+               ;;
+       msdos)
+               basic_machine=i386-pc
+               os=-msdos
+               ;;
+       ms1-*)
+               basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
+               ;;
+       mvs)
+               basic_machine=i370-ibm
+               os=-mvs
+               ;;
+       ncr3000)
+               basic_machine=i486-ncr
+               os=-sysv4
+               ;;
+       netbsd386)
+               basic_machine=i386-unknown
+               os=-netbsd
+               ;;
+       netwinder)
+               basic_machine=armv4l-rebel
+               os=-linux
+               ;;
+       news | news700 | news800 | news900)
+               basic_machine=m68k-sony
+               os=-newsos
+               ;;
+       news1000)
+               basic_machine=m68030-sony
+               os=-newsos
+               ;;
+       news-3600 | risc-news)
+               basic_machine=mips-sony
+               os=-newsos
+               ;;
+       necv70)
+               basic_machine=v70-nec
+               os=-sysv
+               ;;
+       next | m*-next )
+               basic_machine=m68k-next
+               case $os in
+                   -nextstep* )
+                       ;;
+                   -ns2*)
+                     os=-nextstep2
+                       ;;
+                   *)
+                     os=-nextstep3
+                       ;;
+               esac
+               ;;
+       nh3000)
+               basic_machine=m68k-harris
+               os=-cxux
+               ;;
+       nh[45]000)
+               basic_machine=m88k-harris
+               os=-cxux
+               ;;
+       nindy960)
+               basic_machine=i960-intel
+               os=-nindy
+               ;;
+       mon960)
+               basic_machine=i960-intel
+               os=-mon960
+               ;;
+       nonstopux)
+               basic_machine=mips-compaq
+               os=-nonstopux
+               ;;
+       np1)
+               basic_machine=np1-gould
+               ;;
+       nsr-tandem)
+               basic_machine=nsr-tandem
+               ;;
+       op50n-* | op60c-*)
+               basic_machine=hppa1.1-oki
+               os=-proelf
+               ;;
+       openrisc | openrisc-*)
+               basic_machine=or32-unknown
+               ;;
+       os400)
+               basic_machine=powerpc-ibm
+               os=-os400
+               ;;
+       OSE68000 | ose68000)
+               basic_machine=m68000-ericsson
+               os=-ose
+               ;;
+       os68k)
+               basic_machine=m68k-none
+               os=-os68k
+               ;;
+       pa-hitachi)
+               basic_machine=hppa1.1-hitachi
+               os=-hiuxwe2
+               ;;
+       paragon)
+               basic_machine=i860-intel
+               os=-osf
+               ;;
+       parisc)
+               basic_machine=hppa-unknown
+               os=-linux
+               ;;
+       parisc-*)
+               basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
+               os=-linux
+               ;;
+       pbd)
+               basic_machine=sparc-tti
+               ;;
+       pbb)
+               basic_machine=m68k-tti
+               ;;
+       pc532 | pc532-*)
+               basic_machine=ns32k-pc532
+               ;;
+       pc98)
+               basic_machine=i386-pc
+               ;;
+       pc98-*)
+               basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       pentium | p5 | k5 | k6 | nexgen | viac3)
+               basic_machine=i586-pc
+               ;;
+       pentiumpro | p6 | 6x86 | athlon | athlon_*)
+               basic_machine=i686-pc
+               ;;
+       pentiumii | pentium2 | pentiumiii | pentium3)
+               basic_machine=i686-pc
+               ;;
+       pentium4)
+               basic_machine=i786-pc
+               ;;
+       pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
+               basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       pentiumpro-* | p6-* | 6x86-* | athlon-*)
+               basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
+               basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       pentium4-*)
+               basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       pn)
+               basic_machine=pn-gould
+               ;;
+       power)  basic_machine=power-ibm
+               ;;
+       ppc)    basic_machine=powerpc-unknown
+               ;;
+       ppc-*)  basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       ppcle | powerpclittle | ppc-le | powerpc-little)
+               basic_machine=powerpcle-unknown
+               ;;
+       ppcle-* | powerpclittle-*)
+               basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       ppc64)  basic_machine=powerpc64-unknown
+               ;;
+       ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       ppc64le | powerpc64little | ppc64-le | powerpc64-little)
+               basic_machine=powerpc64le-unknown
+               ;;
+       ppc64le-* | powerpc64little-*)
+               basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       ps2)
+               basic_machine=i386-ibm
+               ;;
+       pw32)
+               basic_machine=i586-unknown
+               os=-pw32
+               ;;
+       rdos)
+               basic_machine=i386-pc
+               os=-rdos
+               ;;
+       rom68k)
+               basic_machine=m68k-rom68k
+               os=-coff
+               ;;
+       rm[46]00)
+               basic_machine=mips-siemens
+               ;;
+       rtpc | rtpc-*)
+               basic_machine=romp-ibm
+               ;;
+       s390 | s390-*)
+               basic_machine=s390-ibm
+               ;;
+       s390x | s390x-*)
+               basic_machine=s390x-ibm
+               ;;
+       sa29200)
+               basic_machine=a29k-amd
+               os=-udi
+               ;;
+       sb1)
+               basic_machine=mipsisa64sb1-unknown
+               ;;
+       sb1el)
+               basic_machine=mipsisa64sb1el-unknown
+               ;;
+       sde)
+               basic_machine=mipsisa32-sde
+               os=-elf
+               ;;
+       sei)
+               basic_machine=mips-sei
+               os=-seiux
+               ;;
+       sequent)
+               basic_machine=i386-sequent
+               ;;
+       sh)
+               basic_machine=sh-hitachi
+               os=-hms
+               ;;
+       sh5el)
+               basic_machine=sh5le-unknown
+               ;;
+       sh64)
+               basic_machine=sh64-unknown
+               ;;
+       sparclite-wrs | simso-wrs)
+               basic_machine=sparclite-wrs
+               os=-vxworks
+               ;;
+       sps7)
+               basic_machine=m68k-bull
+               os=-sysv2
+               ;;
+       spur)
+               basic_machine=spur-unknown
+               ;;
+       st2000)
+               basic_machine=m68k-tandem
+               ;;
+       stratus)
+               basic_machine=i860-stratus
+               os=-sysv4
+               ;;
+       sun2)
+               basic_machine=m68000-sun
+               ;;
+       sun2os3)
+               basic_machine=m68000-sun
+               os=-sunos3
+               ;;
+       sun2os4)
+               basic_machine=m68000-sun
+               os=-sunos4
+               ;;
+       sun3os3)
+               basic_machine=m68k-sun
+               os=-sunos3
+               ;;
+       sun3os4)
+               basic_machine=m68k-sun
+               os=-sunos4
+               ;;
+       sun4os3)
+               basic_machine=sparc-sun
+               os=-sunos3
+               ;;
+       sun4os4)
+               basic_machine=sparc-sun
+               os=-sunos4
+               ;;
+       sun4sol2)
+               basic_machine=sparc-sun
+               os=-solaris2
+               ;;
+       sun3 | sun3-*)
+               basic_machine=m68k-sun
+               ;;
+       sun4)
+               basic_machine=sparc-sun
+               ;;
+       sun386 | sun386i | roadrunner)
+               basic_machine=i386-sun
+               ;;
+       sv1)
+               basic_machine=sv1-cray
+               os=-unicos
+               ;;
+       symmetry)
+               basic_machine=i386-sequent
+               os=-dynix
+               ;;
+       t3e)
+               basic_machine=alphaev5-cray
+               os=-unicos
+               ;;
+       t90)
+               basic_machine=t90-cray
+               os=-unicos
+               ;;
+       tic54x | c54x*)
+               basic_machine=tic54x-unknown
+               os=-coff
+               ;;
+       tic55x | c55x*)
+               basic_machine=tic55x-unknown
+               os=-coff
+               ;;
+       tic6x | c6x*)
+               basic_machine=tic6x-unknown
+               os=-coff
+               ;;
+       tile*)
+               basic_machine=tile-unknown
+               os=-linux-gnu
+               ;;
+       tx39)
+               basic_machine=mipstx39-unknown
+               ;;
+       tx39el)
+               basic_machine=mipstx39el-unknown
+               ;;
+       toad1)
+               basic_machine=pdp10-xkl
+               os=-tops20
+               ;;
+       tower | tower-32)
+               basic_machine=m68k-ncr
+               ;;
+       tpf)
+               basic_machine=s390x-ibm
+               os=-tpf
+               ;;
+       udi29k)
+               basic_machine=a29k-amd
+               os=-udi
+               ;;
+       ultra3)
+               basic_machine=a29k-nyu
+               os=-sym1
+               ;;
+       v810 | necv810)
+               basic_machine=v810-nec
+               os=-none
+               ;;
+       vaxv)
+               basic_machine=vax-dec
+               os=-sysv
+               ;;
+       vms)
+               basic_machine=vax-dec
+               os=-vms
+               ;;
+       vpp*|vx|vx-*)
+               basic_machine=f301-fujitsu
+               ;;
+       vxworks960)
+               basic_machine=i960-wrs
+               os=-vxworks
+               ;;
+       vxworks68)
+               basic_machine=m68k-wrs
+               os=-vxworks
+               ;;
+       vxworks29k)
+               basic_machine=a29k-wrs
+               os=-vxworks
+               ;;
+       w65*)
+               basic_machine=w65-wdc
+               os=-none
+               ;;
+       w89k-*)
+               basic_machine=hppa1.1-winbond
+               os=-proelf
+               ;;
+       xbox)
+               basic_machine=i686-pc
+               os=-mingw32
+               ;;
+       xps | xps100)
+               basic_machine=xps100-honeywell
+               ;;
+       ymp)
+               basic_machine=ymp-cray
+               os=-unicos
+               ;;
+       z8k-*-coff)
+               basic_machine=z8k-unknown
+               os=-sim
+               ;;
+       z80-*-coff)
+               basic_machine=z80-unknown
+               os=-sim
+               ;;
+       none)
+               basic_machine=none-none
+               os=-none
+               ;;
+
+# Here we handle the default manufacturer of certain CPU types.  It is in
+# some cases the only manufacturer, in others, it is the most popular.
+       w89k)
+               basic_machine=hppa1.1-winbond
+               ;;
+       op50n)
+               basic_machine=hppa1.1-oki
+               ;;
+       op60c)
+               basic_machine=hppa1.1-oki
+               ;;
+       romp)
+               basic_machine=romp-ibm
+               ;;
+       mmix)
+               basic_machine=mmix-knuth
+               ;;
+       rs6000)
+               basic_machine=rs6000-ibm
+               ;;
+       vax)
+               basic_machine=vax-dec
+               ;;
+       pdp10)
+               # there are many clones, so DEC is not a safe bet
+               basic_machine=pdp10-unknown
+               ;;
+       pdp11)
+               basic_machine=pdp11-dec
+               ;;
+       we32k)
+               basic_machine=we32k-att
+               ;;
+       sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
+               basic_machine=sh-unknown
+               ;;
+       sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
+               basic_machine=sparc-sun
+               ;;
+       cydra)
+               basic_machine=cydra-cydrome
+               ;;
+       orion)
+               basic_machine=orion-highlevel
+               ;;
+       orion105)
+               basic_machine=clipper-highlevel
+               ;;
+       mac | mpw | mac-mpw)
+               basic_machine=m68k-apple
+               ;;
+       pmac | pmac-mpw)
+               basic_machine=powerpc-apple
+               ;;
+       *-unknown)
+               # Make sure to match an already-canonicalized machine name.
+               ;;
+       *)
+               echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+               exit 1
+               ;;
+esac
+
+# Here we canonicalize certain aliases for manufacturers.
+case $basic_machine in
+       *-digital*)
+               basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
+               ;;
+       *-commodore*)
+               basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
+               ;;
+       *)
+               ;;
+esac
+
+# Decode manufacturer-specific aliases for certain operating systems.
+
+if [ x"$os" != x"" ]
+then
+case $os in
+        # First match some system type aliases
+        # that might get confused with valid system types.
+       # -solaris* is a basic system type, with this one exception.
+       -solaris1 | -solaris1.*)
+               os=`echo $os | sed -e 's|solaris1|sunos4|'`
+               ;;
+       -solaris)
+               os=-solaris2
+               ;;
+       -svr4*)
+               os=-sysv4
+               ;;
+       -unixware*)
+               os=-sysv4.2uw
+               ;;
+       -gnu/linux*)
+               os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+               ;;
+       # First accept the basic system types.
+       # The portable systems comes first.
+       # Each alternative MUST END IN A *, to match a version number.
+       # -sysv* is not here because it comes later, after sysvr4.
+       -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
+             | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
+             | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
+             | -kopensolaris* \
+             | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
+             | -aos* | -aros* \
+             | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
+             | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
+             | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
+             | -openbsd* | -solidbsd* \
+             | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
+             | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+             | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
+             | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+             | -chorusos* | -chorusrdb* | -cegcc* \
+             | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+             | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
+             | -uxpv* | -beos* | -mpeix* | -udk* \
+             | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
+             | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
+             | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
+             | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
+             | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
+             | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
+             | -skyos* | -haiku* | -rdos* | -toppers* | -drops*)
+       # Remember, each alternative MUST END IN *, to match a version number.
+               ;;
+       -qnx*)
+               case $basic_machine in
+                   x86-* | i*86-*)
+                       ;;
+                   *)
+                       os=-nto$os
+                       ;;
+               esac
+               ;;
+       -nto-qnx*)
+               ;;
+       -nto*)
+               os=`echo $os | sed -e 's|nto|nto-qnx|'`
+               ;;
+       -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
+             | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
+             | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
+               ;;
+       -mac*)
+               os=`echo $os | sed -e 's|mac|macos|'`
+               ;;
+       -linux-dietlibc)
+               os=-linux-dietlibc
+               ;;
+       -linux*)
+               os=`echo $os | sed -e 's|linux|linux-gnu|'`
+               ;;
+       -sunos5*)
+               os=`echo $os | sed -e 's|sunos5|solaris2|'`
+               ;;
+       -sunos6*)
+               os=`echo $os | sed -e 's|sunos6|solaris3|'`
+               ;;
+       -opened*)
+               os=-openedition
+               ;;
+        -os400*)
+               os=-os400
+               ;;
+       -wince*)
+               os=-wince
+               ;;
+       -osfrose*)
+               os=-osfrose
+               ;;
+       -osf*)
+               os=-osf
+               ;;
+       -utek*)
+               os=-bsd
+               ;;
+       -dynix*)
+               os=-bsd
+               ;;
+       -acis*)
+               os=-aos
+               ;;
+       -atheos*)
+               os=-atheos
+               ;;
+       -syllable*)
+               os=-syllable
+               ;;
+       -386bsd)
+               os=-bsd
+               ;;
+       -ctix* | -uts*)
+               os=-sysv
+               ;;
+       -nova*)
+               os=-rtmk-nova
+               ;;
+       -ns2 )
+               os=-nextstep2
+               ;;
+       -nsk*)
+               os=-nsk
+               ;;
+       # Preserve the version number of sinix5.
+       -sinix5.*)
+               os=`echo $os | sed -e 's|sinix|sysv|'`
+               ;;
+       -sinix*)
+               os=-sysv4
+               ;;
+        -tpf*)
+               os=-tpf
+               ;;
+       -triton*)
+               os=-sysv3
+               ;;
+       -oss*)
+               os=-sysv3
+               ;;
+       -svr4)
+               os=-sysv4
+               ;;
+       -svr3)
+               os=-sysv3
+               ;;
+       -sysvr4)
+               os=-sysv4
+               ;;
+       # This must come after -sysvr4.
+       -sysv*)
+               ;;
+       -ose*)
+               os=-ose
+               ;;
+       -es1800*)
+               os=-ose
+               ;;
+       -xenix)
+               os=-xenix
+               ;;
+       -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+               os=-mint
+               ;;
+       -aros*)
+               os=-aros
+               ;;
+       -kaos*)
+               os=-kaos
+               ;;
+       -zvmoe)
+               os=-zvmoe
+               ;;
+       -dicos*)
+               os=-dicos
+               ;;
+       -none)
+               ;;
+       *)
+               # Get rid of the `-' at the beginning of $os.
+               os=`echo $os | sed 's/[^-]*-//'`
+               echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
+               exit 1
+               ;;
+esac
+else
+
+# Here we handle the default operating systems that come with various machines.
+# The value should be what the vendor currently ships out the door with their
+# machine or put another way, the most popular os provided with the machine.
+
+# Note that if you're going to try to match "-MANUFACTURER" here (say,
+# "-sun"), then you have to tell the case statement up towards the top
+# that MANUFACTURER isn't an operating system.  Otherwise, code above
+# will signal an error saying that MANUFACTURER isn't an operating
+# system, and we'll never get to this point.
+
+case $basic_machine in
+        score-*)
+               os=-elf
+               ;;
+        spu-*)
+               os=-elf
+               ;;
+       *-acorn)
+               os=-riscix1.2
+               ;;
+       arm*-rebel)
+               os=-linux
+               ;;
+       arm*-semi)
+               os=-aout
+               ;;
+        c4x-* | tic4x-*)
+               os=-coff
+               ;;
+       # This must come before the *-dec entry.
+       pdp10-*)
+               os=-tops20
+               ;;
+       pdp11-*)
+               os=-none
+               ;;
+       *-dec | vax-*)
+               os=-ultrix4.2
+               ;;
+       m68*-apollo)
+               os=-domain
+               ;;
+       i386-sun)
+               os=-sunos4.0.2
+               ;;
+       m68000-sun)
+               os=-sunos3
+               # This also exists in the configure program, but was not the
+               # default.
+               # os=-sunos4
+               ;;
+       m68*-cisco)
+               os=-aout
+               ;;
+        mep-*)
+               os=-elf
+               ;;
+       mips*-cisco)
+               os=-elf
+               ;;
+       mips*-*)
+               os=-elf
+               ;;
+       or32-*)
+               os=-coff
+               ;;
+       *-tti)  # must be before sparc entry or we get the wrong os.
+               os=-sysv3
+               ;;
+       sparc-* | *-sun)
+               os=-sunos4.1.1
+               ;;
+       *-be)
+               os=-beos
+               ;;
+       *-haiku)
+               os=-haiku
+               ;;
+       *-ibm)
+               os=-aix
+               ;;
+       *-knuth)
+               os=-mmixware
+               ;;
+       *-wec)
+               os=-proelf
+               ;;
+       *-winbond)
+               os=-proelf
+               ;;
+       *-oki)
+               os=-proelf
+               ;;
+       *-hp)
+               os=-hpux
+               ;;
+       *-hitachi)
+               os=-hiux
+               ;;
+       i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
+               os=-sysv
+               ;;
+       *-cbm)
+               os=-amigaos
+               ;;
+       *-dg)
+               os=-dgux
+               ;;
+       *-dolphin)
+               os=-sysv3
+               ;;
+       m68k-ccur)
+               os=-rtu
+               ;;
+       m88k-omron*)
+               os=-luna
+               ;;
+       *-next )
+               os=-nextstep
+               ;;
+       *-sequent)
+               os=-ptx
+               ;;
+       *-crds)
+               os=-unos
+               ;;
+       *-ns)
+               os=-genix
+               ;;
+       i370-*)
+               os=-mvs
+               ;;
+       *-next)
+               os=-nextstep3
+               ;;
+       *-gould)
+               os=-sysv
+               ;;
+       *-highlevel)
+               os=-bsd
+               ;;
+       *-encore)
+               os=-bsd
+               ;;
+       *-sgi)
+               os=-irix
+               ;;
+       *-siemens)
+               os=-sysv4
+               ;;
+       *-masscomp)
+               os=-rtu
+               ;;
+       f30[01]-fujitsu | f700-fujitsu)
+               os=-uxpv
+               ;;
+       *-rom68k)
+               os=-coff
+               ;;
+       *-*bug)
+               os=-coff
+               ;;
+       *-apple)
+               os=-macos
+               ;;
+       *-atari*)
+               os=-mint
+               ;;
+       *)
+               os=-none
+               ;;
+esac
+fi
+
+# Here we handle the case where we know the os, and the CPU type, but not the
+# manufacturer.  We pick the logical manufacturer.
+vendor=unknown
+case $basic_machine in
+       *-unknown)
+               case $os in
+                       -riscix*)
+                               vendor=acorn
+                               ;;
+                       -sunos*)
+                               vendor=sun
+                               ;;
+                       -aix*)
+                               vendor=ibm
+                               ;;
+                       -beos*)
+                               vendor=be
+                               ;;
+                       -hpux*)
+                               vendor=hp
+                               ;;
+                       -mpeix*)
+                               vendor=hp
+                               ;;
+                       -hiux*)
+                               vendor=hitachi
+                               ;;
+                       -unos*)
+                               vendor=crds
+                               ;;
+                       -dgux*)
+                               vendor=dg
+                               ;;
+                       -luna*)
+                               vendor=omron
+                               ;;
+                       -genix*)
+                               vendor=ns
+                               ;;
+                       -mvs* | -opened*)
+                               vendor=ibm
+                               ;;
+                       -os400*)
+                               vendor=ibm
+                               ;;
+                       -ptx*)
+                               vendor=sequent
+                               ;;
+                       -tpf*)
+                               vendor=ibm
+                               ;;
+                       -vxsim* | -vxworks* | -windiss*)
+                               vendor=wrs
+                               ;;
+                       -aux*)
+                               vendor=apple
+                               ;;
+                       -hms*)
+                               vendor=hitachi
+                               ;;
+                       -mpw* | -macos*)
+                               vendor=apple
+                               ;;
+                       -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+                               vendor=atari
+                               ;;
+                       -vos*)
+                               vendor=stratus
+                               ;;
+               esac
+               basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+               ;;
+esac
+
+echo $basic_machine$os
+exit
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/configure b/configure
new file mode 100755 (executable)
index 0000000..0391e00
--- /dev/null
+++ b/configure
@@ -0,0 +1,21328 @@
+#! /bin/sh
+# Guess values for system-dependent variables and create Makefiles.
+# Generated by GNU Autoconf 2.64 for m17n-lib 1.6.1.
+#
+# Report bugs to <m17n-lib-bug@m17n.org>.
+#
+# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
+# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software
+# Foundation, Inc.
+#
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in #(
+      *"$as_nl"*)
+       expr "X$arg" : "X\\(.*\\)$as_nl";
+       arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" ""       $as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+case $0 in #((
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+  done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there.  '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+if test "x$CONFIG_SHELL" = x; then
+  as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '\${1+\"\$@\"}'='\"\$@\"'
+  setopt NO_GLOB_SUBST
+else
+  case \`(set -o) 2>/dev/null\` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+"
+  as_required="as_fn_return () { (exit \$1); }
+as_fn_success () { as_fn_return 0; }
+as_fn_failure () { as_fn_return 1; }
+as_fn_ret_success () { return 0; }
+as_fn_ret_failure () { return 1; }
+
+exitcode=0
+as_fn_success || { exitcode=1; echo as_fn_success failed.; }
+as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
+as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
+as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
+if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
+
+else
+  exitcode=1; echo positional parameters were not saved.
+fi
+test x\$exitcode = x0 || exit 1"
+  as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
+  as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
+  eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
+  test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
+test \$(( 1 + 1 )) = 2 || exit 1"
+  if (eval "$as_required") 2>/dev/null; then :
+  as_have_required=yes
+else
+  as_have_required=no
+fi
+  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
+
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_found=false
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  as_found=:
+  case $as_dir in #(
+        /*)
+          for as_base in sh bash ksh sh5; do
+            # Try only shells that exist, to save several forks.
+            as_shell=$as_dir/$as_base
+            if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
+                   { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
+  CONFIG_SHELL=$as_shell as_have_required=yes
+                  if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
+  break 2
+fi
+fi
+          done;;
+       esac
+  as_found=false
+done
+$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
+             { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
+  CONFIG_SHELL=$SHELL as_have_required=yes
+fi; }
+IFS=$as_save_IFS
+
+
+      if test "x$CONFIG_SHELL" != x; then :
+  # We cannot yet assume a decent shell, so we have to provide a
+       # neutralization value for shells without unset; and this also
+       # works around shells that cannot unset nonexistent variables.
+       BASH_ENV=/dev/null
+       ENV=/dev/null
+       (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+       export CONFIG_SHELL
+       exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"}
+fi
+
+    if test x$as_have_required = xno; then :
+  $as_echo "$0: This script requires a shell more modern than all"
+  $as_echo "$0: the shells that I found on your system."
+  if test x${ZSH_VERSION+set} = xset ; then
+    $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
+    $as_echo "$0: be upgraded to zsh 4.3.4 or later."
+  else
+    $as_echo "$0: Please tell bug-autoconf@gnu.org and
+$0: m17n-lib-bug@m17n.org about your system, including any
+$0: error possibly output before this message. Then install
+$0: a modern shell, or manually run the script under such a
+$0: shell if you do have one."
+  fi
+  exit 1
+fi
+fi
+fi
+SHELL=${CONFIG_SHELL-/bin/sh}
+export SHELL
+# Unset more variables known to interfere with behavior of common tools.
+CLICOLOR_FORCE= GREP_OPTIONS=
+unset CLICOLOR_FORCE GREP_OPTIONS
+
+## --------------------- ##
+## M4sh Shell Functions. ##
+## --------------------- ##
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+  { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+  return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+  set +e
+  as_fn_set_status $1
+  exit $1
+} # as_fn_exit
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || eval $as_mkdir_p || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+        X"$as_dir" : 'X\(//\)[^/]' \| \
+        X"$as_dir" : 'X\(//\)$' \| \
+        X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)[^/].*/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || as_fn_error "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+  eval 'as_fn_append ()
+  {
+    eval $1+=\$2
+  }'
+else
+  as_fn_append ()
+  {
+    eval $1=\$$1\$2
+  }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+  eval 'as_fn_arith ()
+  {
+    as_val=$(( $* ))
+  }'
+else
+  as_fn_arith ()
+  {
+    as_val=`expr "$@" || test $? -eq 1`
+  }
+fi # as_fn_arith
+
+
+# as_fn_error ERROR [LINENO LOG_FD]
+# ---------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with status $?, using 1 if that was 0.
+as_fn_error ()
+{
+  as_status=$?; test $as_status -eq 0 && as_status=1
+  if test "$3"; then
+    as_lineno=${as_lineno-"$2"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $1" >&$3
+  fi
+  $as_echo "$as_me: error: $1" >&2
+  as_fn_exit $as_status
+} # as_fn_error
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+        X"$0" : 'X\(//\)$' \| \
+        X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+           s//\1/
+           q
+         }
+         /^X\/\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\/\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+
+  as_lineno_1=$LINENO as_lineno_1a=$LINENO
+  as_lineno_2=$LINENO as_lineno_2a=$LINENO
+  eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" &&
+  test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
+  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)
+  sed -n '
+    p
+    /[$]LINENO/=
+  ' <$as_myself |
+    sed '
+      s/[$]LINENO.*/&-/
+      t lineno
+      b
+      :lineno
+      N
+      :loop
+      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
+      t loop
+      s/-\n.*//
+    ' >$as_me.lineno &&
+  chmod +x "$as_me.lineno" ||
+    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
+
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensitive to this).
+  . "./$as_me.lineno"
+  # Exit status is that of the last command.
+  exit
+}
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+  case `echo 'xy\c'` in
+  *c*) ECHO_T='        ';;     # ECHO_T is single tab character.
+  xy)  ECHO_C='\c';;
+  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
+       ECHO_T='        ';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -p'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -p'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
+    as_ln_s='cp -p'
+  fi
+else
+  as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p='mkdir -p "$as_dir"'
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+       test -d "$1/.";
+      else
+       case $1 in #(
+       -*)set "./$1";;
+       esac;
+       case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
+       ???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+
+# Check that we are running under the correct shell.
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+case X$lt_ECHO in
+X*--fallback-echo)
+  # Remove one level of quotation (which was required for Make).
+  ECHO=`echo "$lt_ECHO" | sed 's,\\\\\$\\$0,'$0','`
+  ;;
+esac
+
+ECHO=${lt_ECHO-echo}
+if test "X$1" = X--no-reexec; then
+  # Discard the --no-reexec flag, and continue.
+  shift
+elif test "X$1" = X--fallback-echo; then
+  # Avoid inline document here, it may be left over
+  :
+elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then
+  # Yippee, $ECHO works!
+  :
+else
+  # Restart under the correct shell.
+  exec $SHELL "$0" --no-reexec ${1+"$@"}
+fi
+
+if test "X$1" = X--fallback-echo; then
+  # used as fallback echo
+  shift
+  cat <<_LT_EOF
+$*
+_LT_EOF
+  exit 0
+fi
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+if test -z "$lt_ECHO"; then
+  if test "X${echo_test_string+set}" != Xset; then
+    # find a string as large as possible, as long as the shell can cope with it
+    for cmd in 'sed 50q "$0"' 'sed 20q "$0"' 'sed 10q "$0"' 'sed 2q "$0"' 'echo test'; do
+      # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ...
+      if { echo_test_string=`eval $cmd`; } 2>/dev/null &&
+        { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null
+      then
+        break
+      fi
+    done
+  fi
+
+  if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
+     echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
+     test "X$echo_testing_string" = "X$echo_test_string"; then
+    :
+  else
+    # The Solaris, AIX, and Digital Unix default echo programs unquote
+    # backslashes.  This makes it impossible to quote backslashes using
+    #   echo "$something" | sed 's/\\/\\\\/g'
+    #
+    # So, first we look for a working echo in the user's PATH.
+
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for dir in $PATH /usr/ucb; do
+      IFS="$lt_save_ifs"
+      if (test -f $dir/echo || test -f $dir/echo$ac_exeext) &&
+         test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' &&
+         echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` &&
+         test "X$echo_testing_string" = "X$echo_test_string"; then
+        ECHO="$dir/echo"
+        break
+      fi
+    done
+    IFS="$lt_save_ifs"
+
+    if test "X$ECHO" = Xecho; then
+      # We didn't find a better echo, so look for alternatives.
+      if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' &&
+         echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` &&
+         test "X$echo_testing_string" = "X$echo_test_string"; then
+        # This shell has a builtin print -r that does the trick.
+        ECHO='print -r'
+      elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } &&
+          test "X$CONFIG_SHELL" != X/bin/ksh; then
+        # If we have ksh, try running configure again with it.
+        ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
+        export ORIGINAL_CONFIG_SHELL
+        CONFIG_SHELL=/bin/ksh
+        export CONFIG_SHELL
+        exec $CONFIG_SHELL "$0" --no-reexec ${1+"$@"}
+      else
+        # Try using printf.
+        ECHO='printf %s\n'
+        if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
+          echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
+          test "X$echo_testing_string" = "X$echo_test_string"; then
+         # Cool, printf works
+         :
+        elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` &&
+            test "X$echo_testing_string" = 'X\t' &&
+            echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
+            test "X$echo_testing_string" = "X$echo_test_string"; then
+         CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL
+         export CONFIG_SHELL
+         SHELL="$CONFIG_SHELL"
+         export SHELL
+         ECHO="$CONFIG_SHELL $0 --fallback-echo"
+        elif echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` &&
+            test "X$echo_testing_string" = 'X\t' &&
+            echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
+            test "X$echo_testing_string" = "X$echo_test_string"; then
+         ECHO="$CONFIG_SHELL $0 --fallback-echo"
+        else
+         # maybe with a smaller string...
+         prev=:
+
+         for cmd in 'echo test' 'sed 2q "$0"' 'sed 10q "$0"' 'sed 20q "$0"' 'sed 50q "$0"'; do
+           if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null
+           then
+             break
+           fi
+           prev="$cmd"
+         done
+
+         if test "$prev" != 'sed 50q "$0"'; then
+           echo_test_string=`eval $prev`
+           export echo_test_string
+           exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "$0" ${1+"$@"}
+         else
+           # Oops.  We lost completely, so just stick with echo.
+           ECHO=echo
+         fi
+        fi
+      fi
+    fi
+  fi
+fi
+
+# Copy echo and quote the copy suitably for passing to libtool from
+# the Makefile, instead of quoting the original, which is used later.
+lt_ECHO=$ECHO
+if test "X$lt_ECHO" = "X$CONFIG_SHELL $0 --fallback-echo"; then
+   lt_ECHO="$CONFIG_SHELL \\\$\$0 --fallback-echo"
+fi
+
+
+
+
+exec 7<&0 </dev/null 6>&1
+
+# Name of the host.
+# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_clean_files=
+ac_config_libobj_dir=.
+LIBOBJS=
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+
+# Identity of this package.
+PACKAGE_NAME='m17n-lib'
+PACKAGE_TARNAME='m17n-lib'
+PACKAGE_VERSION='1.6.1'
+PACKAGE_STRING='m17n-lib 1.6.1'
+PACKAGE_BUGREPORT='m17n-lib-bug@m17n.org'
+PACKAGE_URL=''
+
+# Factoring default headers for most tests.
+ac_includes_default="\
+#include <stdio.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif
+#ifdef HAVE_STRING_H
+# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
+#  include <memory.h>
+# endif
+# include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif"
+
+ac_subst_vars='am__EXEEXT_FALSE
+am__EXEEXT_TRUE
+LTLIBOBJS
+CONFIG_FLAGS
+THAI_WORDSEG_LD_FLAGS
+GLIB_2_0_LIBS
+GLIB_2_0_CFLAGS
+WORDCUT_LIBS
+WORDCUT_CFLAGS
+LIBTHAI_LIBS
+LIBTHAI_CFLAGS
+HAVE_ISPELL
+ANTHY_LD_FLAGS
+ANTHY_LIBS
+ANTHY_CFLAGS
+PKG_CONFIG
+XML2_LD_FLAGS
+HAVE_XML2_CONFIG
+GD_LD_FLAGS
+FONTCONFIG_LD_FLAGS
+XFT2_LD_FLAGS
+HAVE_XFT_CONFIG
+FREETYPE_LD_FLAGS
+HAVE_FREETYPE_CONFIG
+OTF_LD_FLAGS
+HAVE_OTFLIB_CONFIG
+FRIBIDI_LD_FLAGS
+HAVE_FRIBIDI_CONFIG
+XAW_LD_FLAGS
+X11_LD_FLAGS
+HAVE_PKG_CONFIG
+WITH_GUI_FALSE
+WITH_GUI_TRUE
+M17NDIR
+HAVE_M17N_DB
+POW_LIB
+LIBOBJS
+X_EXTRA_LIBS
+X_LIBS
+X_PRE_LIBS
+X_CFLAGS
+XMKMF
+GETTEXTDIR
+POSUB
+LTLIBINTL
+LIBINTL
+INTLLIBS
+INTL_LIBTOOL_SUFFIX_PREFIX
+INTLOBJS
+GENCAT
+INSTOBJEXT
+DATADIRNAME
+CATOBJEXT
+USE_INCLUDED_LIBINTL
+BUILD_INCLUDED_LIBINTL
+INTLBISON
+LTLIBICONV
+LIBICONV
+HAVE_WPRINTF
+HAVE_SNPRINTF
+HAVE_ASPRINTF
+HAVE_POSIX_PRINTF
+INTL_MACOSX_LIBS
+GLIBC21
+ALLOCA
+GLIBC2
+MSGMERGE
+XGETTEXT
+GMSGFMT
+MSGFMT
+USE_NLS
+MKINSTALLDIRS
+M17N_MODULE_DIR
+API_VERSION
+MAINT
+MAINTAINER_MODE_FALSE
+MAINTAINER_MODE_TRUE
+CPP
+OTOOL64
+OTOOL
+LIPO
+NMEDIT
+DSYMUTIL
+lt_ECHO
+RANLIB
+AR
+OBJDUMP
+LN_S
+NM
+ac_ct_DUMPBIN
+DUMPBIN
+LD
+FGREP
+EGREP
+GREP
+SED
+am__fastdepCC_FALSE
+am__fastdepCC_TRUE
+CCDEPMODE
+AMDEPBACKSLASH
+AMDEP_FALSE
+AMDEP_TRUE
+am__quote
+am__include
+DEPDIR
+OBJEXT
+EXEEXT
+ac_ct_CC
+CPPFLAGS
+LDFLAGS
+CFLAGS
+CC
+host_os
+host_vendor
+host_cpu
+host
+build_os
+build_vendor
+build_cpu
+build
+LIBTOOL
+am__untar
+am__tar
+AMTAR
+am__leading_dot
+SET_MAKE
+AWK
+mkdir_p
+MKDIR_P
+INSTALL_STRIP_PROGRAM
+STRIP
+install_sh
+MAKEINFO
+AUTOHEADER
+AUTOMAKE
+AUTOCONF
+ACLOCAL
+VERSION
+PACKAGE
+CYGPATH_W
+am__isrc
+INSTALL_DATA
+INSTALL_SCRIPT
+INSTALL_PROGRAM
+target_alias
+host_alias
+build_alias
+LIBS
+ECHO_T
+ECHO_N
+ECHO_C
+DEFS
+mandir
+localedir
+libdir
+psdir
+pdfdir
+dvidir
+htmldir
+infodir
+docdir
+oldincludedir
+includedir
+localstatedir
+sharedstatedir
+sysconfdir
+datadir
+datarootdir
+libexecdir
+sbindir
+bindir
+program_transform_name
+prefix
+exec_prefix
+PACKAGE_URL
+PACKAGE_BUGREPORT
+PACKAGE_STRING
+PACKAGE_VERSION
+PACKAGE_TARNAME
+PACKAGE_NAME
+PATH_SEPARATOR
+SHELL'
+ac_subst_files=''
+ac_user_opts='
+enable_option_checking
+enable_shared
+enable_static
+with_pic
+enable_fast_install
+enable_dependency_tracking
+with_gnu_ld
+enable_libtool_lock
+enable_maintainer_mode
+enable_nls
+enable_rpath
+with_libiconv_prefix
+with_included_gettext
+with_libintl_prefix
+with_x
+enable_gui
+with_libotf
+with_fontconfig
+with_gd
+'
+      ac_precious_vars='build_alias
+host_alias
+target_alias
+CC
+CFLAGS
+LDFLAGS
+LIBS
+CPPFLAGS
+CPP
+XMKMF
+PKG_CONFIG
+ANTHY_CFLAGS
+ANTHY_LIBS
+LIBTHAI_CFLAGS
+LIBTHAI_LIBS
+WORDCUT_CFLAGS
+WORDCUT_LIBS
+GLIB_2_0_CFLAGS
+GLIB_2_0_LIBS'
+
+
+# Initialize some variables set by options.
+ac_init_help=
+ac_init_version=false
+ac_unrecognized_opts=
+ac_unrecognized_sep=
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+cache_file=/dev/null
+exec_prefix=NONE
+no_create=
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+verbose=
+x_includes=NONE
+x_libraries=NONE
+
+# Installation directory options.
+# These are left unexpanded so users can "make install exec_prefix=/foo"
+# and all the variables that are supposed to be based on exec_prefix
+# by default will actually change.
+# Use braces instead of parens because sh, perl, etc. also accept them.
+# (The list follows the same order as the GNU Coding Standards.)
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datarootdir='${prefix}/share'
+datadir='${datarootdir}'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
+infodir='${datarootdir}/info'
+htmldir='${docdir}'
+dvidir='${docdir}'
+pdfdir='${docdir}'
+psdir='${docdir}'
+libdir='${exec_prefix}/lib'
+localedir='${datarootdir}/locale'
+mandir='${datarootdir}/man'
+
+ac_prev=
+ac_dashdash=
+for ac_option
+do
+  # If the previous option needs an argument, assign it.
+  if test -n "$ac_prev"; then
+    eval $ac_prev=\$ac_option
+    ac_prev=
+    continue
+  fi
+
+  case $ac_option in
+  *=*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
+  *)   ac_optarg=yes ;;
+  esac
+
+  # Accept the important Cygnus configure options, so we can diagnose typos.
+
+  case $ac_dashdash$ac_option in
+  --)
+    ac_dashdash=yes ;;
+
+  -bindir | --bindir | --bindi | --bind | --bin | --bi)
+    ac_prev=bindir ;;
+  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+    bindir=$ac_optarg ;;
+
+  -build | --build | --buil | --bui | --bu)
+    ac_prev=build_alias ;;
+  -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+    build_alias=$ac_optarg ;;
+
+  -cache-file | --cache-file | --cache-fil | --cache-fi \
+  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+    ac_prev=cache_file ;;
+  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+    cache_file=$ac_optarg ;;
+
+  --config-cache | -C)
+    cache_file=config.cache ;;
+
+  -datadir | --datadir | --datadi | --datad)
+    ac_prev=datadir ;;
+  -datadir=* | --datadir=* | --datadi=* | --datad=*)
+    datadir=$ac_optarg ;;
+
+  -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \
+  | --dataroo | --dataro | --datar)
+    ac_prev=datarootdir ;;
+  -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \
+  | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
+    datarootdir=$ac_optarg ;;
+
+  -disable-* | --disable-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error "invalid feature name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
+        ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=no ;;
+
+  -docdir | --docdir | --docdi | --doc | --do)
+    ac_prev=docdir ;;
+  -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)
+    docdir=$ac_optarg ;;
+
+  -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)
+    ac_prev=dvidir ;;
+  -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
+    dvidir=$ac_optarg ;;
+
+  -enable-* | --enable-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error "invalid feature name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
+        ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=\$ac_optarg ;;
+
+  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+  | --exec | --exe | --ex)
+    ac_prev=exec_prefix ;;
+  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+  | --exec=* | --exe=* | --ex=*)
+    exec_prefix=$ac_optarg ;;
+
+  -gas | --gas | --ga | --g)
+    # Obsolete; use --with-gas.
+    with_gas=yes ;;
+
+  -help | --help | --hel | --he | -h)
+    ac_init_help=long ;;
+  -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
+    ac_init_help=recursive ;;
+  -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
+    ac_init_help=short ;;
+
+  -host | --host | --hos | --ho)
+    ac_prev=host_alias ;;
+  -host=* | --host=* | --hos=* | --ho=*)
+    host_alias=$ac_optarg ;;
+
+  -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)
+    ac_prev=htmldir ;;
+  -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \
+  | --ht=*)
+    htmldir=$ac_optarg ;;
+
+  -includedir | --includedir | --includedi | --included | --include \
+  | --includ | --inclu | --incl | --inc)
+    ac_prev=includedir ;;
+  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+  | --includ=* | --inclu=* | --incl=* | --inc=*)
+    includedir=$ac_optarg ;;
+
+  -infodir | --infodir | --infodi | --infod | --info | --inf)
+    ac_prev=infodir ;;
+  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+    infodir=$ac_optarg ;;
+
+  -libdir | --libdir | --libdi | --libd)
+    ac_prev=libdir ;;
+  -libdir=* | --libdir=* | --libdi=* | --libd=*)
+    libdir=$ac_optarg ;;
+
+  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+  | --libexe | --libex | --libe)
+    ac_prev=libexecdir ;;
+  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+  | --libexe=* | --libex=* | --libe=*)
+    libexecdir=$ac_optarg ;;
+
+  -localedir | --localedir | --localedi | --localed | --locale)
+    ac_prev=localedir ;;
+  -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)
+    localedir=$ac_optarg ;;
+
+  -localstatedir | --localstatedir | --localstatedi | --localstated \
+  | --localstate | --localstat | --localsta | --localst | --locals)
+    ac_prev=localstatedir ;;
+  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+  | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)
+    localstatedir=$ac_optarg ;;
+
+  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+    ac_prev=mandir ;;
+  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+    mandir=$ac_optarg ;;
+
+  -nfp | --nfp | --nf)
+    # Obsolete; use --without-fp.
+    with_fp=no ;;
+
+  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+  | --no-cr | --no-c | -n)
+    no_create=yes ;;
+
+  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+    no_recursion=yes ;;
+
+  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+  | --oldin | --oldi | --old | --ol | --o)
+    ac_prev=oldincludedir ;;
+  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+    oldincludedir=$ac_optarg ;;
+
+  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+    ac_prev=prefix ;;
+  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+    prefix=$ac_optarg ;;
+
+  -program-prefix | --program-prefix | --program-prefi | --program-pref \
+  | --program-pre | --program-pr | --program-p)
+    ac_prev=program_prefix ;;
+  -program-prefix=* | --program-prefix=* | --program-prefi=* \
+  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+    program_prefix=$ac_optarg ;;
+
+  -program-suffix | --program-suffix | --program-suffi | --program-suff \
+  | --program-suf | --program-su | --program-s)
+    ac_prev=program_suffix ;;
+  -program-suffix=* | --program-suffix=* | --program-suffi=* \
+  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+    program_suffix=$ac_optarg ;;
+
+  -program-transform-name | --program-transform-name \
+  | --program-transform-nam | --program-transform-na \
+  | --program-transform-n | --program-transform- \
+  | --program-transform | --program-transfor \
+  | --program-transfo | --program-transf \
+  | --program-trans | --program-tran \
+  | --progr-tra | --program-tr | --program-t)
+    ac_prev=program_transform_name ;;
+  -program-transform-name=* | --program-transform-name=* \
+  | --program-transform-nam=* | --program-transform-na=* \
+  | --program-transform-n=* | --program-transform-=* \
+  | --program-transform=* | --program-transfor=* \
+  | --program-transfo=* | --program-transf=* \
+  | --program-trans=* | --program-tran=* \
+  | --progr-tra=* | --program-tr=* | --program-t=*)
+    program_transform_name=$ac_optarg ;;
+
+  -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)
+    ac_prev=pdfdir ;;
+  -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)
+    pdfdir=$ac_optarg ;;
+
+  -psdir | --psdir | --psdi | --psd | --ps)
+    ac_prev=psdir ;;
+  -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
+    psdir=$ac_optarg ;;
+
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil)
+    silent=yes ;;
+
+  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+    ac_prev=sbindir ;;
+  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+  | --sbi=* | --sb=*)
+    sbindir=$ac_optarg ;;
+
+  -sharedstatedir | --sharedstatedir | --sharedstatedi \
+  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+  | --sharedst | --shareds | --shared | --share | --shar \
+  | --sha | --sh)
+    ac_prev=sharedstatedir ;;
+  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+  | --sha=* | --sh=*)
+    sharedstatedir=$ac_optarg ;;
+
+  -site | --site | --sit)
+    ac_prev=site ;;
+  -site=* | --site=* | --sit=*)
+    site=$ac_optarg ;;
+
+  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+    ac_prev=srcdir ;;
+  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+    srcdir=$ac_optarg ;;
+
+  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+  | --syscon | --sysco | --sysc | --sys | --sy)
+    ac_prev=sysconfdir ;;
+  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+    sysconfdir=$ac_optarg ;;
+
+  -target | --target | --targe | --targ | --tar | --ta | --t)
+    ac_prev=target_alias ;;
+  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+    target_alias=$ac_optarg ;;
+
+  -v | -verbose | --verbose | --verbos | --verbo | --verb)
+    verbose=yes ;;
+
+  -version | --version | --versio | --versi | --vers | -V)
+    ac_init_version=: ;;
+
+  -with-* | --with-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error "invalid package name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
+        ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=\$ac_optarg ;;
+
+  -without-* | --without-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error "invalid package name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
+        ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=no ;;
+
+  --x)
+    # Obsolete; use --with-x.
+    with_x=yes ;;
+
+  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+  | --x-incl | --x-inc | --x-in | --x-i)
+    ac_prev=x_includes ;;
+  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+    x_includes=$ac_optarg ;;
+
+  -x-libraries | --x-libraries | --x-librarie | --x-librari \
+  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+    ac_prev=x_libraries ;;
+  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+    x_libraries=$ac_optarg ;;
+
+  -*) as_fn_error "unrecognized option: \`$ac_option'
+Try \`$0 --help' for more information."
+    ;;
+
+  *=*)
+    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
+    # Reject names that are not valid shell variable names.
+    case $ac_envvar in #(
+      '' | [0-9]* | *[!_$as_cr_alnum]* )
+      as_fn_error "invalid variable name: \`$ac_envvar'" ;;
+    esac
+    eval $ac_envvar=\$ac_optarg
+    export $ac_envvar ;;
+
+  *)
+    # FIXME: should be removed in autoconf 3.0.
+    $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
+      $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+    : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
+    ;;
+
+  esac
+done
+
+if test -n "$ac_prev"; then
+  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
+  as_fn_error "missing argument to $ac_option"
+fi
+
+if test -n "$ac_unrecognized_opts"; then
+  case $enable_option_checking in
+    no) ;;
+    fatal) as_fn_error "unrecognized options: $ac_unrecognized_opts" ;;
+    *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
+  esac
+fi
+
+# Check all directory arguments for consistency.
+for ac_var in  exec_prefix prefix bindir sbindir libexecdir datarootdir \
+               datadir sysconfdir sharedstatedir localstatedir includedir \
+               oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
+               libdir localedir mandir
+do
+  eval ac_val=\$$ac_var
+  # Remove trailing slashes.
+  case $ac_val in
+    */ )
+      ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
+      eval $ac_var=\$ac_val;;
+  esac
+  # Be sure to have absolute directory names.
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* )  continue;;
+    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
+  esac
+  as_fn_error "expected an absolute directory name for --$ac_var: $ac_val"
+done
+
+# There might be people who depend on the old broken behavior: `$host'
+# used to hold the argument of --host etc.
+# FIXME: To remove some day.
+build=$build_alias
+host=$host_alias
+target=$target_alias
+
+# FIXME: To remove some day.
+if test "x$host_alias" != x; then
+  if test "x$build_alias" = x; then
+    cross_compiling=maybe
+    $as_echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host.
+    If a cross compiler is detected then cross compile mode will be used." >&2
+  elif test "x$build_alias" != "x$host_alias"; then
+    cross_compiling=yes
+  fi
+fi
+
+ac_tool_prefix=
+test -n "$host_alias" && ac_tool_prefix=$host_alias-
+
+test "$silent" = yes && exec 6>/dev/null
+
+
+ac_pwd=`pwd` && test -n "$ac_pwd" &&
+ac_ls_di=`ls -di .` &&
+ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
+  as_fn_error "working directory cannot be determined"
+test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
+  as_fn_error "pwd does not report name of working directory"
+
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+  ac_srcdir_defaulted=yes
+  # Try the directory containing this script, then the parent directory.
+  ac_confdir=`$as_dirname -- "$as_myself" ||
+$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+        X"$as_myself" : 'X\(//\)[^/]' \| \
+        X"$as_myself" : 'X\(//\)$' \| \
+        X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_myself" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)[^/].*/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`
+  srcdir=$ac_confdir
+  if test ! -r "$srcdir/$ac_unique_file"; then
+    srcdir=..
+  fi
+else
+  ac_srcdir_defaulted=no
+fi
+if test ! -r "$srcdir/$ac_unique_file"; then
+  test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
+  as_fn_error "cannot find sources ($ac_unique_file) in $srcdir"
+fi
+ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
+ac_abs_confdir=`(
+       cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error "$ac_msg"
+       pwd)`
+# When building in place, set srcdir=.
+if test "$ac_abs_confdir" = "$ac_pwd"; then
+  srcdir=.
+fi
+# Remove unnecessary trailing slashes from srcdir.
+# Double slashes in file names in object file debugging info
+# mess up M-x gdb in Emacs.
+case $srcdir in
+*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;;
+esac
+for ac_var in $ac_precious_vars; do
+  eval ac_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_env_${ac_var}_value=\$${ac_var}
+  eval ac_cv_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_cv_env_${ac_var}_value=\$${ac_var}
+done
+
+#
+# Report the --help message.
+#
+if test "$ac_init_help" = "long"; then
+  # Omit some internal or obsolete options to make the list less imposing.
+  # This message is too long to be a string in the A/UX 3.1 sh.
+  cat <<_ACEOF
+\`configure' configures m17n-lib 1.6.1 to adapt to many kinds of systems.
+
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE.  See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+      --help=short        display options specific to this package
+      --help=recursive    display the short help of all the included packages
+  -V, --version           display version information and exit
+  -q, --quiet, --silent   do not print \`checking...' messages
+      --cache-file=FILE   cache test results in FILE [disabled]
+  -C, --config-cache      alias for \`--cache-file=config.cache'
+  -n, --no-create         do not create output files
+      --srcdir=DIR        find the sources in DIR [configure dir or \`..']
+
+Installation directories:
+  --prefix=PREFIX         install architecture-independent files in PREFIX
+                          [$ac_default_prefix]
+  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
+                          [PREFIX]
+
+By default, \`make install' will install all the files in
+\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
+an installation prefix other than \`$ac_default_prefix' using \`--prefix',
+for instance \`--prefix=\$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+  --bindir=DIR            user executables [EPREFIX/bin]
+  --sbindir=DIR           system admin executables [EPREFIX/sbin]
+  --libexecdir=DIR        program executables [EPREFIX/libexec]
+  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
+  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
+  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
+  --libdir=DIR            object code libraries [EPREFIX/lib]
+  --includedir=DIR        C header files [PREFIX/include]
+  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
+  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
+  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
+  --infodir=DIR           info documentation [DATAROOTDIR/info]
+  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
+  --mandir=DIR            man documentation [DATAROOTDIR/man]
+  --docdir=DIR            documentation root [DATAROOTDIR/doc/m17n-lib]
+  --htmldir=DIR           html documentation [DOCDIR]
+  --dvidir=DIR            dvi documentation [DOCDIR]
+  --pdfdir=DIR            pdf documentation [DOCDIR]
+  --psdir=DIR             ps documentation [DOCDIR]
+_ACEOF
+
+  cat <<\_ACEOF
+
+Program names:
+  --program-prefix=PREFIX            prepend PREFIX to installed program names
+  --program-suffix=SUFFIX            append SUFFIX to installed program names
+  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names
+
+X features:
+  --x-includes=DIR    X include files are in DIR
+  --x-libraries=DIR   X library files are in DIR
+
+System types:
+  --build=BUILD     configure for building on BUILD [guessed]
+  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
+_ACEOF
+fi
+
+if test -n "$ac_init_help"; then
+  case $ac_init_help in
+     short | recursive ) echo "Configuration of m17n-lib 1.6.1:";;
+   esac
+  cat <<\_ACEOF
+
+Optional Features:
+  --disable-option-checking  ignore unrecognized --enable/--with options
+  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
+  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --enable-shared[=PKGS]  build shared libraries [default=yes]
+  --enable-static[=PKGS]  build static libraries [default=yes]
+  --enable-fast-install[=PKGS]
+                          optimize for fast installation [default=yes]
+  --disable-dependency-tracking  speeds up one-time build
+  --enable-dependency-tracking   do not reject slow dependency extractors
+  --disable-libtool-lock  avoid locking (might break parallel builds)
+  --enable-maintainer-mode  enable make rules and dependencies not useful
+                         (and sometimes confusing) to the casual installer
+  --disable-nls           do not use Native Language Support
+  --disable-rpath         do not hardcode runtime library paths
+  --with-gui              with GUI level APIs (default is YES)
+
+Optional Packages:
+  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
+  --with-pic              try to use only PIC/non-PIC objects [default=use
+                          both]
+  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+  --with-gnu-ld           assume the C compiler uses GNU ld default=no
+  --with-libiconv-prefix[=DIR]  search for libiconv in DIR/include and DIR/lib
+  --without-libiconv-prefix     don't search for libiconv in includedir and libdir
+  --with-included-gettext use the GNU gettext library included here
+  --with-libintl-prefix[=DIR]  search for libintl in DIR/include and DIR/lib
+  --without-libintl-prefix     don't search for libintl in includedir and libdir
+  --with-x                use the X Window System
+  --with-libotf           with OpenType font suport (default is YES)
+  --with-fontconfig       with FontConfig library (default is YES)
+  --with-gd               suport graphic device by GD library (default is YES)
+
+Some influential environment variables:
+  CC          C compiler command
+  CFLAGS      C compiler flags
+  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
+              nonstandard directory <lib dir>
+  LIBS        libraries to pass to the linker, e.g. -l<library>
+  CPPFLAGS    C/C++/Objective C preprocessor flags, e.g. -I<include dir> if
+              you have headers in a nonstandard directory <include dir>
+  CPP         C preprocessor
+  XMKMF       Path to xmkmf, Makefile generator for X Window System
+  PKG_CONFIG  path to pkg-config utility
+  ANTHY_CFLAGS
+              C compiler flags for ANTHY, overriding pkg-config
+  ANTHY_LIBS  linker flags for ANTHY, overriding pkg-config
+  LIBTHAI_CFLAGS
+              C compiler flags for LIBTHAI, overriding pkg-config
+  LIBTHAI_LIBS
+              linker flags for LIBTHAI, overriding pkg-config
+  WORDCUT_CFLAGS
+              C compiler flags for WORDCUT, overriding pkg-config
+  WORDCUT_LIBS
+              linker flags for WORDCUT, overriding pkg-config
+  GLIB_2_0_CFLAGS
+              C compiler flags for GLIB_2_0, overriding pkg-config
+  GLIB_2_0_LIBS
+              linker flags for GLIB_2_0, overriding pkg-config
+
+Use these variables to override the choices made by `configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+Report bugs to <m17n-lib-bug@m17n.org>.
+_ACEOF
+ac_status=$?
+fi
+
+if test "$ac_init_help" = "recursive"; then
+  # If there are subdirs, report their specific --help.
+  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
+    test -d "$ac_dir" ||
+      { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
+      continue
+    ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+  .)  # We are building in place.
+    ac_srcdir=.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+    cd "$ac_dir" || { ac_status=$?; continue; }
+    # Check for guested configure.
+    if test -f "$ac_srcdir/configure.gnu"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure.gnu" --help=recursive
+    elif test -f "$ac_srcdir/configure"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure" --help=recursive
+    else
+      $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+    fi || ac_status=$?
+    cd "$ac_pwd" || { ac_status=$?; break; }
+  done
+fi
+
+test -n "$ac_init_help" && exit $ac_status
+if $ac_init_version; then
+  cat <<\_ACEOF
+m17n-lib configure 1.6.1
+generated by GNU Autoconf 2.64
+
+Copyright (C) 2009 Free Software Foundation, Inc.
+This configure script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it.
+_ACEOF
+  exit
+fi
+
+## ------------------------ ##
+## Autoconf initialization. ##
+## ------------------------ ##
+
+# ac_fn_c_try_compile LINENO
+# --------------------------
+# Try to compile conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext
+  if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compile") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_retval=1
+fi
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  return $ac_retval
+
+} # ac_fn_c_try_compile
+
+# ac_fn_c_try_link LINENO
+# -----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_link ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext conftest$ac_exeext
+  if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+        test "$cross_compiling" = yes ||
+        $as_test_x conftest$ac_exeext
+       }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_retval=1
+fi
+  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
+  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
+  # interfere with the next link command; also delete a directory that is
+  # left behind by Apple's compiler.  We do this before executing the actions.
+  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  return $ac_retval
+
+} # ac_fn_c_try_link
+
+# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists and can be compiled using the include files in
+# INCLUDES, setting the cache variable VAR accordingly.
+ac_fn_c_check_header_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_c_check_header_compile
+
+# ac_fn_c_try_cpp LINENO
+# ----------------------
+# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_cpp ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { { ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } >/dev/null && {
+        test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+    ac_retval=1
+fi
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  return $ac_retval
+
+} # ac_fn_c_try_cpp
+
+# ac_fn_c_try_run LINENO
+# ----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
+# that executables *can* be run.
+ac_fn_c_try_run ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
+  { { case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: program exited with status $ac_status" >&5
+       $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_retval=$ac_status
+fi
+  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  return $ac_retval
+
+} # ac_fn_c_try_run
+
+# ac_fn_c_check_func LINENO FUNC VAR
+# ----------------------------------
+# Tests whether FUNC exists, setting the cache variable VAR accordingly
+ac_fn_c_check_func ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $2 innocuous_$2
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $2 (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $2
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $2 ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$2 || defined __stub___$2
+choke me
+#endif
+
+int
+main ()
+{
+return $2 ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_c_check_func
+
+# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
+# -------------------------------------------
+# Tests whether TYPE exists after having included INCLUDES, setting cache
+# variable VAR accordingly.
+ac_fn_c_check_type ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
+  $as_echo_n "(cached) " >&6
+else
+  eval "$3=no"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+if (sizeof ($2))
+        return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+if (sizeof (($2)))
+           return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+else
+  eval "$3=yes"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_c_check_type
+
+# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists, giving a warning if it cannot be compiled using
+# the include files in INCLUDES and setting the cache variable VAR
+# accordingly.
+ac_fn_c_check_header_mongrel ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
+  $as_echo_n "(cached) " >&6
+fi
+eval ac_res=\$$3
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+else
+  # Is the header compilable?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
+$as_echo_n "checking $2 usability... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_header_compiler=yes
+else
+  ac_header_compiler=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
+$as_echo "$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
+$as_echo_n "checking $2 presence... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <$2>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  ac_header_preproc=yes
+else
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
+$as_echo "$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((
+  yes:no: )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+    ;;
+  no:yes:* )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: $2:     check for missing prerequisite headers?" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+( cat <<\_ASBOX
+## ------------------------------------ ##
+## Report this to m17n-lib-bug@m17n.org ##
+## ------------------------------------ ##
+_ASBOX
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
+  $as_echo_n "(cached) " >&6
+else
+  eval "$3=\$ac_header_compiler"
+fi
+eval ac_res=\$$3
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+fi
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_c_check_header_mongrel
+
+# ac_fn_c_compute_int LINENO EXPR VAR INCLUDES
+# --------------------------------------------
+# Tries to find the compile-time value of EXPR in a program that includes
+# INCLUDES, setting VAR accordingly. Returns whether the value could be
+# computed
+ac_fn_c_compute_int ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if test "$cross_compiling" = yes; then
+    # Depending upon the size, compute the lo and hi bounds.
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) >= 0)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_lo=0 ac_mid=0
+  while :; do
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) <= $ac_mid)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_hi=$ac_mid; break
+else
+  as_fn_arith $ac_mid + 1 && ac_lo=$as_val
+                       if test $ac_lo -le $ac_mid; then
+                         ac_lo= ac_hi=
+                         break
+                       fi
+                       as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  done
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) < 0)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_hi=-1 ac_mid=-1
+  while :; do
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) >= $ac_mid)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_lo=$ac_mid; break
+else
+  as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val
+                       if test $ac_mid -le $ac_hi; then
+                         ac_lo= ac_hi=
+                         break
+                       fi
+                       as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  done
+else
+  ac_lo= ac_hi=
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+# Binary search between lo and hi bounds.
+while test "x$ac_lo" != "x$ac_hi"; do
+  as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) <= $ac_mid)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_hi=$ac_mid
+else
+  as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+case $ac_lo in #((
+?*) eval "$3=\$ac_lo"; ac_retval=0 ;;
+'') ac_retval=1 ;;
+esac
+  else
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+static long int longval () { return $2; }
+static unsigned long int ulongval () { return $2; }
+#include <stdio.h>
+#include <stdlib.h>
+int
+main ()
+{
+
+  FILE *f = fopen ("conftest.val", "w");
+  if (! f)
+    return 1;
+  if (($2) < 0)
+    {
+      long int i = longval ();
+      if (i != ($2))
+       return 1;
+      fprintf (f, "%ld", i);
+    }
+  else
+    {
+      unsigned long int i = ulongval ();
+      if (i != ($2))
+       return 1;
+      fprintf (f, "%lu", i);
+    }
+  /* Do not output a trailing newline, as this causes \r\n confusion
+     on some platforms.  */
+  return ferror (f) || fclose (f) != 0;
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  echo >>conftest.val; read $3 <conftest.val; ac_retval=0
+else
+  ac_retval=1
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+rm -f conftest.val
+
+  fi
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  return $ac_retval
+
+} # ac_fn_c_compute_int
+cat >config.log <<_ACEOF
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+It was created by m17n-lib $as_me 1.6.1, which was
+generated by GNU Autoconf 2.64.  Invocation command line was
+
+  $ $0 $@
+
+_ACEOF
+exec 5>>config.log
+{
+cat <<_ASUNAME
+## --------- ##
+## Platform. ##
+## --------- ##
+
+hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`
+
+/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
+/usr/bin/hostinfo      = `(/usr/bin/hostinfo) 2>/dev/null      || echo unknown`
+/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
+/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`
+
+_ASUNAME
+
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    $as_echo "PATH: $as_dir"
+  done
+IFS=$as_save_IFS
+
+} >&5
+
+cat >&5 <<_ACEOF
+
+
+## ----------- ##
+## Core tests. ##
+## ----------- ##
+
+_ACEOF
+
+
+# Keep a trace of the command line.
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Strip out --silent because we don't want to record it for future runs.
+# Also quote any args containing shell meta-characters.
+# Make two passes to allow for proper duplicate-argument suppression.
+ac_configure_args=
+ac_configure_args0=
+ac_configure_args1=
+ac_must_keep_next=false
+for ac_pass in 1 2
+do
+  for ac_arg
+  do
+    case $ac_arg in
+    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
+    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+    | -silent | --silent | --silen | --sile | --sil)
+      continue ;;
+    *\'*)
+      ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    case $ac_pass in
+    1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
+    2)
+      as_fn_append ac_configure_args1 " '$ac_arg'"
+      if test $ac_must_keep_next = true; then
+       ac_must_keep_next=false # Got value, back to normal.
+      else
+       case $ac_arg in
+         *=* | --config-cache | -C | -disable-* | --disable-* \
+         | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+         | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+         | -with-* | --with-* | -without-* | --without-* | --x)
+           case "$ac_configure_args0 " in
+             "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+           esac
+           ;;
+         -* ) ac_must_keep_next=true ;;
+       esac
+      fi
+      as_fn_append ac_configure_args " '$ac_arg'"
+      ;;
+    esac
+  done
+done
+{ ac_configure_args0=; unset ac_configure_args0;}
+{ ac_configure_args1=; unset ac_configure_args1;}
+
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log.  We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Use '\'' to represent an apostrophe within the trap.
+# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
+trap 'exit_status=$?
+  # Save into config.log some information that might help in debugging.
+  {
+    echo
+
+    cat <<\_ASBOX
+## ---------------- ##
+## Cache variables. ##
+## ---------------- ##
+_ASBOX
+    echo
+    # The following way of writing the cache mishandles newlines in values,
+(
+  for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) { eval $ac_var=; unset $ac_var;} ;;
+      esac ;;
+    esac
+  done
+  (set) 2>&1 |
+    case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
+      sed -n \
+       "s/'\''/'\''\\\\'\'''\''/g;
+         s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p"
+      ;; #(
+    *)
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+      ;;
+    esac |
+    sort
+)
+    echo
+
+    cat <<\_ASBOX
+## ----------------- ##
+## Output variables. ##
+## ----------------- ##
+_ASBOX
+    echo
+    for ac_var in $ac_subst_vars
+    do
+      eval ac_val=\$$ac_var
+      case $ac_val in
+      *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+      esac
+      $as_echo "$ac_var='\''$ac_val'\''"
+    done | sort
+    echo
+
+    if test -n "$ac_subst_files"; then
+      cat <<\_ASBOX
+## ------------------- ##
+## File substitutions. ##
+## ------------------- ##
+_ASBOX
+      echo
+      for ac_var in $ac_subst_files
+      do
+       eval ac_val=\$$ac_var
+       case $ac_val in
+       *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+       esac
+       $as_echo "$ac_var='\''$ac_val'\''"
+      done | sort
+      echo
+    fi
+
+    if test -s confdefs.h; then
+      cat <<\_ASBOX
+## ----------- ##
+## confdefs.h. ##
+## ----------- ##
+_ASBOX
+      echo
+      cat confdefs.h
+      echo
+    fi
+    test "$ac_signal" != 0 &&
+      $as_echo "$as_me: caught signal $ac_signal"
+    $as_echo "$as_me: exit $exit_status"
+  } >&5
+  rm -f core *.core core.conftest.* &&
+    rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
+    exit $exit_status
+' 0
+for ac_signal in 1 2 13 15; do
+  trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
+done
+ac_signal=0
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -f -r conftest* confdefs.h
+
+$as_echo "/* confdefs.h */" > confdefs.h
+
+# Predefined preprocessor variables.
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_NAME "$PACKAGE_NAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_STRING "$PACKAGE_STRING"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_URL "$PACKAGE_URL"
+_ACEOF
+
+
+# Let the site file select an alternate cache file if it wants to.
+# Prefer an explicitly selected file to automatically selected ones.
+ac_site_file1=NONE
+ac_site_file2=NONE
+if test -n "$CONFIG_SITE"; then
+  ac_site_file1=$CONFIG_SITE
+elif test "x$prefix" != xNONE; then
+  ac_site_file1=$prefix/share/config.site
+  ac_site_file2=$prefix/etc/config.site
+else
+  ac_site_file1=$ac_default_prefix/share/config.site
+  ac_site_file2=$ac_default_prefix/etc/config.site
+fi
+for ac_site_file in "$ac_site_file1" "$ac_site_file2"
+do
+  test "x$ac_site_file" = xNONE && continue
+  if test -r "$ac_site_file"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
+$as_echo "$as_me: loading site script $ac_site_file" >&6;}
+    sed 's/^/| /' "$ac_site_file" >&5
+    . "$ac_site_file"
+  fi
+done
+
+if test -r "$cache_file"; then
+  # Some versions of bash will fail to source /dev/null (special
+  # files actually), so we avoid doing that.
+  if test -f "$cache_file"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
+$as_echo "$as_me: loading cache $cache_file" >&6;}
+    case $cache_file in
+      [\\/]* | ?:[\\/]* ) . "$cache_file";;
+      *)                      . "./$cache_file";;
+    esac
+  fi
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
+$as_echo "$as_me: creating cache $cache_file" >&6;}
+  >$cache_file
+fi
+
+# Check that the precious variables saved in the cache have kept the same
+# value.
+ac_cache_corrupted=false
+for ac_var in $ac_precious_vars; do
+  eval ac_old_set=\$ac_cv_env_${ac_var}_set
+  eval ac_new_set=\$ac_env_${ac_var}_set
+  eval ac_old_val=\$ac_cv_env_${ac_var}_value
+  eval ac_new_val=\$ac_env_${ac_var}_value
+  case $ac_old_set,$ac_new_set in
+    set,)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,set)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,);;
+    *)
+      if test "x$ac_old_val" != "x$ac_new_val"; then
+       # differences in whitespace do not lead to failure.
+       ac_old_val_w=`echo x $ac_old_val`
+       ac_new_val_w=`echo x $ac_new_val`
+       if test "$ac_old_val_w" != "$ac_new_val_w"; then
+         { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
+$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+         ac_cache_corrupted=:
+       else
+         { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
+$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
+         eval $ac_var=\$ac_old_val
+       fi
+       { $as_echo "$as_me:${as_lineno-$LINENO}:   former value:  \`$ac_old_val'" >&5
+$as_echo "$as_me:   former value:  \`$ac_old_val'" >&2;}
+       { $as_echo "$as_me:${as_lineno-$LINENO}:   current value: \`$ac_new_val'" >&5
+$as_echo "$as_me:   current value: \`$ac_new_val'" >&2;}
+      fi;;
+  esac
+  # Pass precious variables to config.status.
+  if test "$ac_new_set" = set; then
+    case $ac_new_val in
+    *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+    *) ac_arg=$ac_var=$ac_new_val ;;
+    esac
+    case " $ac_configure_args " in
+      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
+      *) as_fn_append ac_configure_args " '$ac_arg'" ;;
+    esac
+  fi
+done
+if $ac_cache_corrupted; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
+$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+  as_fn_error "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
+fi
+## -------------------- ##
+## Main body of script. ##
+## -------------------- ##
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+am__api_version='1.11'
+
+ac_aux_dir=
+for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
+  for ac_t in install-sh install.sh shtool; do
+    if test -f "$ac_dir/$ac_t"; then
+      ac_aux_dir=$ac_dir
+      ac_install_sh="$ac_aux_dir/$ac_t -c"
+      break 2
+    fi
+  done
+done
+if test -z "$ac_aux_dir"; then
+  as_fn_error "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5
+fi
+
+# These three variables are undocumented and unsupported,
+# and are intended to be withdrawn in a future Autoconf release.
+# They can cause serious problems if a builder's source tree is in a directory
+# whose full name contains unusual characters.
+ac_config_guess="$SHELL $ac_aux_dir/config.guess"  # Please don't use this var.
+ac_config_sub="$SHELL $ac_aux_dir/config.sub"  # Please don't use this var.
+ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
+
+
+# Find a good install program.  We prefer a C program (faster),
+# so one script is as good as another.  But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AmigaOS /C/install, which installs bootblocks on floppy discs
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# OS/2's system install, which has a completely different semantic
+# ./install, which can be erroneously created by make from ./install.sh.
+# Reject install programs that cannot install multiple files.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5
+$as_echo_n "checking for a BSD-compatible install... " >&6; }
+if test -z "$INSTALL"; then
+if test "${ac_cv_path_install+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    # Account for people who put trailing slashes in PATH elements.
+case $as_dir/ in #((
+  ./ | .// | /[cC]/* | \
+  /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
+  ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \
+  /usr/ucb/* ) ;;
+  *)
+    # OSF1 and SCO ODT 3.0 have their own names for install.
+    # Don't use installbsd from OSF since it installs stuff as root
+    # by default.
+    for ac_prog in ginstall scoinst install; do
+      for ac_exec_ext in '' $ac_executable_extensions; do
+       if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then
+         if test $ac_prog = install &&
+           grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+           # AIX install.  It has an incompatible calling convention.
+           :
+         elif test $ac_prog = install &&
+           grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+           # program-specific install script used by HP pwplus--don't use.
+           :
+         else
+           rm -rf conftest.one conftest.two conftest.dir
+           echo one > conftest.one
+           echo two > conftest.two
+           mkdir conftest.dir
+           if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" &&
+             test -s conftest.one && test -s conftest.two &&
+             test -s conftest.dir/conftest.one &&
+             test -s conftest.dir/conftest.two
+           then
+             ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+             break 3
+           fi
+         fi
+       fi
+      done
+    done
+    ;;
+esac
+
+  done
+IFS=$as_save_IFS
+
+rm -rf conftest.one conftest.two conftest.dir
+
+fi
+  if test "${ac_cv_path_install+set}" = set; then
+    INSTALL=$ac_cv_path_install
+  else
+    # As a last resort, use the slow shell script.  Don't cache a
+    # value for INSTALL within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the value is a relative name.
+    INSTALL=$ac_install_sh
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5
+$as_echo "$INSTALL" >&6; }
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5
+$as_echo_n "checking whether build environment is sane... " >&6; }
+# Just in case
+sleep 1
+echo timestamp > conftest.file
+# Reject unsafe characters in $srcdir or the absolute working directory
+# name.  Accept space and tab only in the latter.
+am_lf='
+'
+case `pwd` in
+  *[\\\"\#\$\&\'\`$am_lf]*)
+    as_fn_error "unsafe absolute working directory name" "$LINENO" 5;;
+esac
+case $srcdir in
+  *[\\\"\#\$\&\'\`$am_lf\ \    ]*)
+    as_fn_error "unsafe srcdir value: \`$srcdir'" "$LINENO" 5;;
+esac
+
+# Do `set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
+   if test "$*" = "X"; then
+      # -L didn't work.
+      set X `ls -t "$srcdir/configure" conftest.file`
+   fi
+   rm -f conftest.file
+   if test "$*" != "X $srcdir/configure conftest.file" \
+      && test "$*" != "X conftest.file $srcdir/configure"; then
+
+      # If neither matched, then we have a broken ls.  This can happen
+      # if, for instance, CONFIG_SHELL is bash and it inherits a
+      # broken ls alias from the environment.  This has actually
+      # happened.  Such a system could not be considered "sane".
+      as_fn_error "ls -t appears to fail.  Make sure there is not a broken
+alias in your environment" "$LINENO" 5
+   fi
+
+   test "$2" = conftest.file
+   )
+then
+   # Ok.
+   :
+else
+   as_fn_error "newly created file is older than distributed files!
+Check your system clock" "$LINENO" 5
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+test "$program_prefix" != NONE &&
+  program_transform_name="s&^&$program_prefix&;$program_transform_name"
+# Use a double $ so make ignores it.
+test "$program_suffix" != NONE &&
+  program_transform_name="s&\$&$program_suffix&;$program_transform_name"
+# Double any \ or $.
+# By default was `s,x,x', remove it if useless.
+ac_script='s/[\\$]/&&/g;s/;s,x,x,$//'
+program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"`
+
+# expand $ac_aux_dir to an absolute path
+am_aux_dir=`cd $ac_aux_dir && pwd`
+
+if test x"${MISSING+set}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\    *)
+    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
+  *)
+    MISSING="\${SHELL} $am_aux_dir/missing" ;;
+  esac
+fi
+# Use eval to expand $SHELL
+if eval "$MISSING --run true"; then
+  am_missing_run="$MISSING --run "
+else
+  am_missing_run=
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`missing' script is too old or missing" >&5
+$as_echo "$as_me: WARNING: \`missing' script is too old or missing" >&2;}
+fi
+
+if test x"${install_sh}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\    *)
+    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
+  *)
+    install_sh="\${SHELL} $am_aux_dir/install-sh"
+  esac
+fi
+
+# Installed binaries are usually stripped using `strip' when the user
+# run `make install-strip'.  However `strip' might not be the right
+# tool to use in cross-compilation environments, therefore Automake
+# will honor the `STRIP' environment variable to overrule this program.
+if test "$cross_compiling" != no; then
+  if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
+set dummy ${ac_tool_prefix}strip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_STRIP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$STRIP"; then
+  ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_STRIP="${ac_tool_prefix}strip"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+STRIP=$ac_cv_prog_STRIP
+if test -n "$STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5
+$as_echo "$STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_STRIP"; then
+  ac_ct_STRIP=$STRIP
+  # Extract the first word of "strip", so it can be a program name with args.
+set dummy strip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_STRIP"; then
+  ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_STRIP="strip"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP
+if test -n "$ac_ct_STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5
+$as_echo "$ac_ct_STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_STRIP" = x; then
+    STRIP=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    STRIP=$ac_ct_STRIP
+  fi
+else
+  STRIP="$ac_cv_prog_STRIP"
+fi
+
+fi
+INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5
+$as_echo_n "checking for a thread-safe mkdir -p... " >&6; }
+if test -z "$MKDIR_P"; then
+  if test "${ac_cv_path_mkdir+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in mkdir gmkdir; do
+        for ac_exec_ext in '' $ac_executable_extensions; do
+          { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue
+          case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #(
+            'mkdir (GNU coreutils) '* | \
+            'mkdir (coreutils) '* | \
+            'mkdir (fileutils) '4.1*)
+              ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext
+              break 3;;
+          esac
+        done
+       done
+  done
+IFS=$as_save_IFS
+
+fi
+
+  if test "${ac_cv_path_mkdir+set}" = set; then
+    MKDIR_P="$ac_cv_path_mkdir -p"
+  else
+    # As a last resort, use the slow shell script.  Don't cache a
+    # value for MKDIR_P within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the value is a relative name.
+    test -d ./--version && rmdir ./--version
+    MKDIR_P="$ac_install_sh -d"
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5
+$as_echo "$MKDIR_P" >&6; }
+
+mkdir_p="$MKDIR_P"
+case $mkdir_p in
+  [\\/$]* | ?:[\\/]*) ;;
+  */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
+esac
+
+for ac_prog in gawk mawk nawk awk
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_AWK+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$AWK"; then
+  ac_cv_prog_AWK="$AWK" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_AWK="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+AWK=$ac_cv_prog_AWK
+if test -n "$AWK"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5
+$as_echo "$AWK" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$AWK" && break
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5
+$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
+set x ${MAKE-make}
+ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
+if { as_var=ac_cv_prog_make_${ac_make}_set; eval "test \"\${$as_var+set}\" = set"; }; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.make <<\_ACEOF
+SHELL = /bin/sh
+all:
+       @echo '@@@%%%=$(MAKE)=@@@%%%'
+_ACEOF
+# GNU make sometimes prints "make[1]: Entering...", which would confuse us.
+case `${MAKE-make} -f conftest.make 2>/dev/null` in
+  *@@@%%%=?*=@@@%%%*)
+    eval ac_cv_prog_make_${ac_make}_set=yes;;
+  *)
+    eval ac_cv_prog_make_${ac_make}_set=no;;
+esac
+rm -f conftest.make
+fi
+if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+  SET_MAKE=
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+  SET_MAKE="MAKE=${MAKE-make}"
+fi
+
+rm -rf .tst 2>/dev/null
+mkdir .tst 2>/dev/null
+if test -d .tst; then
+  am__leading_dot=.
+else
+  am__leading_dot=_
+fi
+rmdir .tst 2>/dev/null
+
+if test "`cd $srcdir && pwd`" != "`pwd`"; then
+  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
+  # is not polluted with repeated "-I."
+  am__isrc=' -I$(srcdir)'
+  # test to see if srcdir already configured
+  if test -f $srcdir/config.status; then
+    as_fn_error "source directory already configured; run \"make distclean\" there first" "$LINENO" 5
+  fi
+fi
+
+# test whether we have cygpath
+if test -z "$CYGPATH_W"; then
+  if (cygpath --version) >/dev/null 2>/dev/null; then
+    CYGPATH_W='cygpath -w'
+  else
+    CYGPATH_W=echo
+  fi
+fi
+
+
+# Define the identity of the package.
+ PACKAGE='m17n-lib'
+ VERSION='1.6.1'
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE "$PACKAGE"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define VERSION "$VERSION"
+_ACEOF
+
+# Some tools Automake needs.
+
+ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"}
+
+
+AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"}
+
+
+AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"}
+
+
+AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"}
+
+
+MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"}
+
+# We need awk for the "check" target.  The system "awk" is bad on
+# some platforms.
+# Always define AMTAR for backward compatibility.
+
+AMTAR=${AMTAR-"${am_missing_run}tar"}
+
+am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'
+
+
+
+
+
+case `pwd` in
+  *\ * | *\    *)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5
+$as_echo "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;;
+esac
+
+
+
+macro_version='2.2.6'
+macro_revision='1.3012'
+
+
+
+
+
+
+
+
+
+
+
+
+
+ltmain="$ac_aux_dir/ltmain.sh"
+
+# Make sure we can run config.sub.
+$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
+  as_fn_error "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5
+$as_echo_n "checking build system type... " >&6; }
+if test "${ac_cv_build+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_build_alias=$build_alias
+test "x$ac_build_alias" = x &&
+  ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"`
+test "x$ac_build_alias" = x &&
+  as_fn_error "cannot guess build type; you must specify one" "$LINENO" 5
+ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` ||
+  as_fn_error "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5
+$as_echo "$ac_cv_build" >&6; }
+case $ac_cv_build in
+*-*-*) ;;
+*) as_fn_error "invalid value of canonical build" "$LINENO" 5;;
+esac
+build=$ac_cv_build
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_build
+shift
+build_cpu=$1
+build_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+build_os=$*
+IFS=$ac_save_IFS
+case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5
+$as_echo_n "checking host system type... " >&6; }
+if test "${ac_cv_host+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "x$host_alias" = x; then
+  ac_cv_host=$ac_cv_build
+else
+  ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` ||
+    as_fn_error "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5
+$as_echo "$ac_cv_host" >&6; }
+case $ac_cv_host in
+*-*-*) ;;
+*) as_fn_error "invalid value of canonical host" "$LINENO" 5;;
+esac
+host=$ac_cv_host
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_host
+shift
+host_cpu=$1
+host_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+host_os=$*
+IFS=$ac_save_IFS
+case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
+
+
+DEPDIR="${am__leading_dot}deps"
+
+ac_config_commands="$ac_config_commands depfiles"
+
+
+am_make=${MAKE-make}
+cat > confinc << 'END'
+am__doit:
+       @echo this is the am__doit target
+.PHONY: am__doit
+END
+# If we don't find an include directive, just comment out the code.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for style of include used by $am_make" >&5
+$as_echo_n "checking for style of include used by $am_make... " >&6; }
+am__include="#"
+am__quote=
+_am_result=none
+# First try GNU make style include.
+echo "include confinc" > confmf
+# Ignore all kinds of additional output from `make'.
+case `$am_make -s -f confmf 2> /dev/null` in #(
+*the\ am__doit\ target*)
+  am__include=include
+  am__quote=
+  _am_result=GNU
+  ;;
+esac
+# Now try BSD make style include.
+if test "$am__include" = "#"; then
+   echo '.include "confinc"' > confmf
+   case `$am_make -s -f confmf 2> /dev/null` in #(
+   *the\ am__doit\ target*)
+     am__include=.include
+     am__quote="\""
+     _am_result=BSD
+     ;;
+   esac
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $_am_result" >&5
+$as_echo "$_am_result" >&6; }
+rm -f confinc confmf
+
+# Check whether --enable-dependency-tracking was given.
+if test "${enable_dependency_tracking+set}" = set; then :
+  enableval=$enable_dependency_tracking;
+fi
+
+if test "x$enable_dependency_tracking" != xno; then
+  am_depcomp="$ac_aux_dir/depcomp"
+  AMDEPBACKSLASH='\'
+fi
+ if test "x$enable_dependency_tracking" != xno; then
+  AMDEP_TRUE=
+  AMDEP_FALSE='#'
+else
+  AMDEP_TRUE='#'
+  AMDEP_FALSE=
+fi
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CC="${ac_tool_prefix}gcc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+  ac_ct_CC=$CC
+  # Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_CC="gcc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
+else
+  CC="$ac_cv_prog_CC"
+fi
+
+if test -z "$CC"; then
+          if test -n "$ac_tool_prefix"; then
+    # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CC="${ac_tool_prefix}cc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  fi
+fi
+if test -z "$CC"; then
+  # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+  ac_prog_rejected=no
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
+       ac_prog_rejected=yes
+       continue
+     fi
+    ac_cv_prog_CC="cc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+if test $ac_prog_rejected = yes; then
+  # We found a bogon in the path, so make sure we never use it.
+  set dummy $ac_cv_prog_CC
+  shift
+  if test $# != 0; then
+    # We chose a different compiler from the bogus one.
+    # However, it has the same basename, so the bogon will be chosen
+    # first if we set CC to just the basename; use the full file name.
+    shift
+    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
+  fi
+fi
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$CC"; then
+  if test -n "$ac_tool_prefix"; then
+  for ac_prog in cl.exe
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$CC" && break
+  done
+fi
+if test -z "$CC"; then
+  ac_ct_CC=$CC
+  for ac_prog in cl.exe
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_CC="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_CC" && break
+done
+
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
+fi
+
+fi
+
+
+test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "no acceptable C compiler found in \$PATH
+See \`config.log' for more details." "$LINENO" 5; }
+
+# Provide some information about the compiler.
+$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+for ac_option in --version -v -V -qversion; do
+  { { ac_try="$ac_compiler $ac_option >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    sed '10a\
+... rest of stderr output deleted ...
+         10q' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    rm -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+done
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdio.h>
+int
+main ()
+{
+FILE *f = fopen ("conftest.out", "w");
+ return ferror (f) || fclose (f) != 0;
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out conftest.out"
+# Try to create an executable without -o first, disregard a.out.
+# It will help us diagnose broken compilers, and finding out an intuition
+# of exeext.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
+$as_echo_n "checking for C compiler default output file name... " >&6; }
+ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
+
+# The possible output files:
+ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"
+
+ac_rmfiles=
+for ac_file in $ac_files
+do
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+    * ) ac_rmfiles="$ac_rmfiles $ac_file";;
+  esac
+done
+rm -f $ac_rmfiles
+
+if { { ac_try="$ac_link_default"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link_default") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
+# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
+# in a Makefile.  We should not override ac_cv_exeext if it was cached,
+# so that the user can short-circuit this test for compilers unknown to
+# Autoconf.
+for ac_file in $ac_files ''
+do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
+       ;;
+    [ab].out )
+       # We found the default executable, but exeext='' is most
+       # certainly right.
+       break;;
+    *.* )
+       if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
+       then :; else
+          ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+       fi
+       # We set ac_cv_exeext here because the later test for it is not
+       # safe: cross compilers may not add the suffix if given an `-o'
+       # argument, so we may need to know it at that point already.
+       # Even if this section looks crufty: it has the advantage of
+       # actually working.
+       break;;
+    * )
+       break;;
+  esac
+done
+test "$ac_cv_exeext" = no && ac_cv_exeext=
+
+else
+  ac_file=''
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
+$as_echo "$ac_file" >&6; }
+if test -z "$ac_file"; then :
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ as_fn_set_status 77
+as_fn_error "C compiler cannot create executables
+See \`config.log' for more details." "$LINENO" 5; }; }
+fi
+ac_exeext=$ac_cv_exeext
+
+# Check that the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
+$as_echo_n "checking whether the C compiler works... " >&6; }
+# If not cross compiling, check that we can run a simple program.
+if test "$cross_compiling" != yes; then
+  if { ac_try='./$ac_file'
+  { { case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then
+    cross_compiling=no
+  else
+    if test "$cross_compiling" = maybe; then
+       cross_compiling=yes
+    else
+       { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." "$LINENO" 5; }
+    fi
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out conftest.out
+ac_clean_files=$ac_clean_files_save
+# Check that the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
+$as_echo_n "checking whether we are cross compiling... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
+$as_echo "$cross_compiling" >&6; }
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
+$as_echo_n "checking for suffix of executables... " >&6; }
+if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  # If both `conftest.exe' and `conftest' are `present' (well, observable)
+# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
+# work properly (i.e., refer to `conftest.exe'), while it won't with
+# `rm'.
+for ac_file in conftest.exe conftest conftest.*; do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+    *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+         break;;
+    * ) break;;
+  esac
+done
+else
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." "$LINENO" 5; }
+fi
+rm -f conftest$ac_cv_exeext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
+$as_echo "$ac_cv_exeext" >&6; }
+
+rm -f conftest.$ac_ext
+EXEEXT=$ac_cv_exeext
+ac_exeext=$EXEEXT
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
+$as_echo_n "checking for suffix of object files... " >&6; }
+if test "${ac_cv_objext+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.o conftest.obj
+if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compile") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  for ac_file in conftest.o conftest.obj conftest.*; do
+  test -f "$ac_file" || continue;
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;
+    *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
+       break;;
+  esac
+done
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." "$LINENO" 5; }
+fi
+rm -f conftest.$ac_cv_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
+$as_echo "$ac_cv_objext" >&6; }
+OBJEXT=$ac_cv_objext
+ac_objext=$OBJEXT
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
+$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
+if test "${ac_cv_c_compiler_gnu+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_compiler_gnu=yes
+else
+  ac_compiler_gnu=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_c_compiler_gnu=$ac_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
+$as_echo "$ac_cv_c_compiler_gnu" >&6; }
+if test $ac_compiler_gnu = yes; then
+  GCC=yes
+else
+  GCC=
+fi
+ac_test_CFLAGS=${CFLAGS+set}
+ac_save_CFLAGS=$CFLAGS
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
+$as_echo_n "checking whether $CC accepts -g... " >&6; }
+if test "${ac_cv_prog_cc_g+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_save_c_werror_flag=$ac_c_werror_flag
+   ac_c_werror_flag=yes
+   ac_cv_prog_cc_g=no
+   CFLAGS="-g"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_g=yes
+else
+  CFLAGS=""
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+else
+  ac_c_werror_flag=$ac_save_c_werror_flag
+        CFLAGS="-g"
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_g=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   ac_c_werror_flag=$ac_save_c_werror_flag
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
+$as_echo "$ac_cv_prog_cc_g" >&6; }
+if test "$ac_test_CFLAGS" = set; then
+  CFLAGS=$ac_save_CFLAGS
+elif test $ac_cv_prog_cc_g = yes; then
+  if test "$GCC" = yes; then
+    CFLAGS="-g -O2"
+  else
+    CFLAGS="-g"
+  fi
+else
+  if test "$GCC" = yes; then
+    CFLAGS="-O2"
+  else
+    CFLAGS=
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
+$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
+if test "${ac_cv_prog_cc_c89+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_prog_cc_c89=no
+ac_save_CC=$CC
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+     char **p;
+     int i;
+{
+  return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+  char *s;
+  va_list v;
+  va_start (v,p);
+  s = g (p, va_arg (v,int));
+  va_end (v);
+  return s;
+}
+
+/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
+   function prototypes and stuff, but not '\xHH' hex character constants.
+   These don't provoke an error unfortunately, instead are silently treated
+   as 'x'.  The following induces an error, until -std is added to get
+   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
+   array size at least.  It's necessary to write '\x00'==0 to get something
+   that's true only with -std.  */
+int osf4_cc_array ['\x00' == 0 ? 1 : -1];
+
+/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
+   inside strings and character constants.  */
+#define FOO(x) 'x'
+int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
+
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+int
+main ()
+{
+return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
+  ;
+  return 0;
+}
+_ACEOF
+for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
+       -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+  CC="$ac_save_CC $ac_arg"
+  if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_c89=$ac_arg
+fi
+rm -f core conftest.err conftest.$ac_objext
+  test "x$ac_cv_prog_cc_c89" != "xno" && break
+done
+rm -f conftest.$ac_ext
+CC=$ac_save_CC
+
+fi
+# AC_CACHE_VAL
+case "x$ac_cv_prog_cc_c89" in
+  x)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
+$as_echo "none needed" >&6; } ;;
+  xno)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
+$as_echo "unsupported" >&6; } ;;
+  *)
+    CC="$CC $ac_cv_prog_cc_c89"
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
+$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
+esac
+if test "x$ac_cv_prog_cc_c89" != xno; then :
+
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+depcc="$CC"   am_compiler_list=
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5
+$as_echo_n "checking dependency style of $depcc... " >&6; }
+if test "${am_cv_CC_dependencies_compiler_type+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named `D' -- because `-MD' means `put the output
+  # in D'.
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_CC_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp`
+  fi
+  am__universal=false
+  case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac
+
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+      # Solaris 8's {/usr,}/bin/sh.
+      touch sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    # We check with `-c' and `-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle `-M -o', and we need to detect this.  Also, some Intel
+    # versions had trouble with output in subdirs
+    am__obj=sub/conftest.${OBJEXT-o}
+    am__minus_obj="-o $am__obj"
+    case $depmode in
+    gcc)
+      # This depmode causes a compiler race in universal mode.
+      test "$am__universal" = false || continue
+      ;;
+    nosideeffect)
+      # after this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested
+      if test "x$enable_dependency_tracking" = xyes; then
+       continue
+      else
+       break
+      fi
+      ;;
+    msvisualcpp | msvcmsys)
+      # This compiler won't grok `-c -o', but also, the minuso test has
+      # not run yet.  These depmodes are late enough in the game, and
+      # so weak that their functioning should not be impacted.
+      am__obj=conftest.${OBJEXT-o}
+      am__minus_obj=
+      ;;
+    none) break ;;
+    esac
+    if depmode=$depmode \
+       source=sub/conftest.c object=$am__obj \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_CC_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_CC_dependencies_compiler_type=none
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5
+$as_echo "$am_cv_CC_dependencies_compiler_type" >&6; }
+CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type
+
+ if
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then
+  am__fastdepCC_TRUE=
+  am__fastdepCC_FALSE='#'
+else
+  am__fastdepCC_TRUE='#'
+  am__fastdepCC_FALSE=
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5
+$as_echo_n "checking for a sed that does not truncate output... " >&6; }
+if test "${ac_cv_path_SED+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+            ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
+     for ac_i in 1 2 3 4 5 6 7; do
+       ac_script="$ac_script$as_nl$ac_script"
+     done
+     echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed
+     { ac_script=; unset ac_script;}
+     if test -z "$SED"; then
+  ac_path_SED_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in sed gsed; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_SED="$as_dir/$ac_prog$ac_exec_ext"
+      { test -f "$ac_path_SED" && $as_test_x "$ac_path_SED"; } || continue
+# Check for GNU ac_path_SED and select it if it is found.
+  # Check for GNU $ac_path_SED
+case `"$ac_path_SED" --version 2>&1` in
+*GNU*)
+  ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo '' >> "conftest.nl"
+    "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_SED_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_SED="$ac_path_SED"
+      ac_path_SED_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_SED_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_SED"; then
+    as_fn_error "no acceptable sed could be found in \$PATH" "$LINENO" 5
+  fi
+else
+  ac_cv_path_SED=$SED
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5
+$as_echo "$ac_cv_path_SED" >&6; }
+ SED="$ac_cv_path_SED"
+  rm -f conftest.sed
+
+test -z "$SED" && SED=sed
+Xsed="$SED -e 1s/^X//"
+
+
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
+$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
+if test "${ac_cv_path_GREP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$GREP"; then
+  ac_path_GREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in grep ggrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
+      { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue
+# Check for GNU ac_path_GREP and select it if it is found.
+  # Check for GNU $ac_path_GREP
+case `"$ac_path_GREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'GREP' >> "conftest.nl"
+    "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_GREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_GREP="$ac_path_GREP"
+      ac_path_GREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_GREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_GREP"; then
+    as_fn_error "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_GREP=$GREP
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
+$as_echo "$ac_cv_path_GREP" >&6; }
+ GREP="$ac_cv_path_GREP"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
+$as_echo_n "checking for egrep... " >&6; }
+if test "${ac_cv_path_EGREP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
+   then ac_cv_path_EGREP="$GREP -E"
+   else
+     if test -z "$EGREP"; then
+  ac_path_EGREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in egrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
+      { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue
+# Check for GNU ac_path_EGREP and select it if it is found.
+  # Check for GNU $ac_path_EGREP
+case `"$ac_path_EGREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'EGREP' >> "conftest.nl"
+    "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_EGREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_EGREP="$ac_path_EGREP"
+      ac_path_EGREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_EGREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_EGREP"; then
+    as_fn_error "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_EGREP=$EGREP
+fi
+
+   fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
+$as_echo "$ac_cv_path_EGREP" >&6; }
+ EGREP="$ac_cv_path_EGREP"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5
+$as_echo_n "checking for fgrep... " >&6; }
+if test "${ac_cv_path_FGREP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1
+   then ac_cv_path_FGREP="$GREP -F"
+   else
+     if test -z "$FGREP"; then
+  ac_path_FGREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in fgrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext"
+      { test -f "$ac_path_FGREP" && $as_test_x "$ac_path_FGREP"; } || continue
+# Check for GNU ac_path_FGREP and select it if it is found.
+  # Check for GNU $ac_path_FGREP
+case `"$ac_path_FGREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'FGREP' >> "conftest.nl"
+    "$ac_path_FGREP" FGREP < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_FGREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_FGREP="$ac_path_FGREP"
+      ac_path_FGREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_FGREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_FGREP"; then
+    as_fn_error "no acceptable fgrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_FGREP=$FGREP
+fi
+
+   fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5
+$as_echo "$ac_cv_path_FGREP" >&6; }
+ FGREP="$ac_cv_path_FGREP"
+
+
+test -z "$GREP" && GREP=grep
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# Check whether --with-gnu-ld was given.
+if test "${with_gnu_ld+set}" = set; then :
+  withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes
+else
+  with_gnu_ld=no
+fi
+
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5
+$as_echo_n "checking for ld used by $CC... " >&6; }
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [\\/]* | ?:[\\/]*)
+      re_direlt='/[^/][^/]*/\.\./'
+      # Canonicalize the pathname of ld
+      ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'`
+      while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do
+       ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5
+$as_echo_n "checking for GNU ld... " >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5
+$as_echo_n "checking for non-GNU ld... " >&6; }
+fi
+if test "${lt_cv_path_LD+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$LD"; then
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  for ac_dir in $PATH; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      lt_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some variants of GNU ld only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
+      *GNU* | *'with BFD'*)
+       test "$with_gnu_ld" != no && break
+       ;;
+      *)
+       test "$with_gnu_ld" != yes && break
+       ;;
+      esac
+    fi
+  done
+  IFS="$lt_save_ifs"
+else
+  lt_cv_path_LD="$LD" # Let the user override the test with a path.
+fi
+fi
+
+LD="$lt_cv_path_LD"
+if test -n "$LD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5
+$as_echo "$LD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+test -z "$LD" && as_fn_error "no acceptable ld found in \$PATH" "$LINENO" 5
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5
+$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; }
+if test "${lt_cv_prog_gnu_ld+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  # I'd rather use --version here, but apparently some GNU lds only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  lt_cv_prog_gnu_ld=yes
+  ;;
+*)
+  lt_cv_prog_gnu_ld=no
+  ;;
+esac
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_gnu_ld" >&5
+$as_echo "$lt_cv_prog_gnu_ld" >&6; }
+with_gnu_ld=$lt_cv_prog_gnu_ld
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5
+$as_echo_n "checking for BSD- or MS-compatible name lister (nm)... " >&6; }
+if test "${lt_cv_path_NM+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$NM"; then
+  # Let the user override the test.
+  lt_cv_path_NM="$NM"
+else
+  lt_nm_to_check="${ac_tool_prefix}nm"
+  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
+    lt_nm_to_check="$lt_nm_to_check nm"
+  fi
+  for lt_tmp_nm in $lt_nm_to_check; do
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
+      IFS="$lt_save_ifs"
+      test -z "$ac_dir" && ac_dir=.
+      tmp_nm="$ac_dir/$lt_tmp_nm"
+      if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
+       # Check to see if the nm accepts a BSD-compat flag.
+       # Adding the `sed 1q' prevents false positives on HP-UX, which says:
+       #   nm: unknown option "B" ignored
+       # Tru64's nm complains that /dev/null is an invalid object file
+       case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
+       */dev/null* | *'Invalid file or object type'*)
+         lt_cv_path_NM="$tmp_nm -B"
+         break
+         ;;
+       *)
+         case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
+         */dev/null*)
+           lt_cv_path_NM="$tmp_nm -p"
+           break
+           ;;
+         *)
+           lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
+           continue # so that we can try to find one that supports BSD flags
+           ;;
+         esac
+         ;;
+       esac
+      fi
+    done
+    IFS="$lt_save_ifs"
+  done
+  : ${lt_cv_path_NM=no}
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5
+$as_echo "$lt_cv_path_NM" >&6; }
+if test "$lt_cv_path_NM" != "no"; then
+  NM="$lt_cv_path_NM"
+else
+  # Didn't find any BSD compatible name lister, look for dumpbin.
+  if test -n "$ac_tool_prefix"; then
+  for ac_prog in "dumpbin -symbols" "link -dump -symbols"
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_DUMPBIN+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$DUMPBIN"; then
+  ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+DUMPBIN=$ac_cv_prog_DUMPBIN
+if test -n "$DUMPBIN"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5
+$as_echo "$DUMPBIN" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$DUMPBIN" && break
+  done
+fi
+if test -z "$DUMPBIN"; then
+  ac_ct_DUMPBIN=$DUMPBIN
+  for ac_prog in "dumpbin -symbols" "link -dump -symbols"
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_DUMPBIN+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_DUMPBIN"; then
+  ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_DUMPBIN="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_DUMPBIN=$ac_cv_prog_ac_ct_DUMPBIN
+if test -n "$ac_ct_DUMPBIN"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5
+$as_echo "$ac_ct_DUMPBIN" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_DUMPBIN" && break
+done
+
+  if test "x$ac_ct_DUMPBIN" = x; then
+    DUMPBIN=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DUMPBIN=$ac_ct_DUMPBIN
+  fi
+fi
+
+
+  if test "$DUMPBIN" != ":"; then
+    NM="$DUMPBIN"
+  fi
+fi
+test -z "$NM" && NM=nm
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5
+$as_echo_n "checking the name lister ($NM) interface... " >&6; }
+if test "${lt_cv_nm_interface+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_nm_interface="BSD nm"
+  echo "int some_variable = 0;" > conftest.$ac_ext
+  (eval echo "\"\$as_me:4799: $ac_compile\"" >&5)
+  (eval "$ac_compile" 2>conftest.err)
+  cat conftest.err >&5
+  (eval echo "\"\$as_me:4802: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
+  (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
+  cat conftest.err >&5
+  (eval echo "\"\$as_me:4805: output\"" >&5)
+  cat conftest.out >&5
+  if $GREP 'External.*some_variable' conftest.out > /dev/null; then
+    lt_cv_nm_interface="MS dumpbin"
+  fi
+  rm -f conftest*
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5
+$as_echo "$lt_cv_nm_interface" >&6; }
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5
+$as_echo_n "checking whether ln -s works... " >&6; }
+LN_S=$as_ln_s
+if test "$LN_S" = "ln -s"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5
+$as_echo "no, using $LN_S" >&6; }
+fi
+
+# find the maximum length of command line arguments
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5
+$as_echo_n "checking the maximum length of command line arguments... " >&6; }
+if test "${lt_cv_sys_max_cmd_len+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+    i=0
+  teststring="ABCD"
+
+  case $build_os in
+  msdosdjgpp*)
+    # On DJGPP, this test can blow up pretty badly due to problems in libc
+    # (any single argument exceeding 2000 bytes causes a buffer overrun
+    # during glob expansion).  Even if it were fixed, the result of this
+    # check would be larger than it should be.
+    lt_cv_sys_max_cmd_len=12288;    # 12K is about right
+    ;;
+
+  gnu*)
+    # Under GNU Hurd, this test is not required because there is
+    # no limit to the length of command line arguments.
+    # Libtool will interpret -1 as no limit whatsoever
+    lt_cv_sys_max_cmd_len=-1;
+    ;;
+
+  cygwin* | mingw* | cegcc*)
+    # On Win9x/ME, this test blows up -- it succeeds, but takes
+    # about 5 minutes as the teststring grows exponentially.
+    # Worse, since 9x/ME are not pre-emptively multitasking,
+    # you end up with a "frozen" computer, even though with patience
+    # the test eventually succeeds (with a max line length of 256k).
+    # Instead, let's just punt: use the minimum linelength reported by
+    # all of the supported platforms: 8192 (on NT/2K/XP).
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  amigaos*)
+    # On AmigaOS with pdksh, this test takes hours, literally.
+    # So we just punt and use a minimum line length of 8192.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
+    # This has been around since 386BSD, at least.  Likely further.
+    if test -x /sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
+    elif test -x /usr/sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
+    else
+      lt_cv_sys_max_cmd_len=65536      # usable default for all BSDs
+    fi
+    # And add a safety zone
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    ;;
+
+  interix*)
+    # We know the value 262144 and hardcode it with a safety zone (like BSD)
+    lt_cv_sys_max_cmd_len=196608
+    ;;
+
+  osf*)
+    # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
+    # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
+    # nice to cause kernel panics so lets avoid the loop below.
+    # First set a reasonable default.
+    lt_cv_sys_max_cmd_len=16384
+    #
+    if test -x /sbin/sysconfig; then
+      case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
+        *1*) lt_cv_sys_max_cmd_len=-1 ;;
+      esac
+    fi
+    ;;
+  sco3.2v5*)
+    lt_cv_sys_max_cmd_len=102400
+    ;;
+  sysv5* | sco5v6* | sysv4.2uw2*)
+    kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null`
+    if test -n "$kargmax"; then
+      lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[         ]//'`
+    else
+      lt_cv_sys_max_cmd_len=32768
+    fi
+    ;;
+  *)
+    lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
+    if test -n "$lt_cv_sys_max_cmd_len"; then
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    else
+      # Make teststring a little bigger before we do anything with it.
+      # a 1K string should be a reasonable start.
+      for i in 1 2 3 4 5 6 7 8 ; do
+        teststring=$teststring$teststring
+      done
+      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
+      # If test is not a shell built-in, we'll probably end up computing a
+      # maximum length that is only half of the actual maximum length, but
+      # we can't tell.
+      while { test "X"`$SHELL $0 --fallback-echo "X$teststring$teststring" 2>/dev/null` \
+                = "XX$teststring$teststring"; } >/dev/null 2>&1 &&
+             test $i != 17 # 1/2 MB should be enough
+      do
+        i=`expr $i + 1`
+        teststring=$teststring$teststring
+      done
+      # Only check the string length outside the loop.
+      lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1`
+      teststring=
+      # Add a significant safety factor because C++ compilers can tack on
+      # massive amounts of additional arguments before passing them to the
+      # linker.  It appears as though 1/2 is a usable value.
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
+    fi
+    ;;
+  esac
+
+fi
+
+if test -n $lt_cv_sys_max_cmd_len ; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5
+$as_echo "$lt_cv_sys_max_cmd_len" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5
+$as_echo "none" >&6; }
+fi
+max_cmd_len=$lt_cv_sys_max_cmd_len
+
+
+
+
+
+
+: ${CP="cp -f"}
+: ${MV="mv -f"}
+: ${RM="rm -f"}
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the shell understands some XSI constructs" >&5
+$as_echo_n "checking whether the shell understands some XSI constructs... " >&6; }
+# Try some XSI features
+xsi_shell=no
+( _lt_dummy="a/b/c"
+  test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \
+      = c,a/b,, \
+    && eval 'test $(( 1 + 1 )) -eq 2 \
+    && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \
+  && xsi_shell=yes
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xsi_shell" >&5
+$as_echo "$xsi_shell" >&6; }
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the shell understands \"+=\"" >&5
+$as_echo_n "checking whether the shell understands \"+=\"... " >&6; }
+lt_shell_append=no
+( foo=bar; set foo baz; eval "$1+=\$2" && test "$foo" = barbaz ) \
+    >/dev/null 2>&1 \
+  && lt_shell_append=yes
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_shell_append" >&5
+$as_echo "$lt_shell_append" >&6; }
+
+
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  lt_unset=unset
+else
+  lt_unset=false
+fi
+
+
+
+
+
+# test EBCDIC or ASCII
+case `echo X|tr X '\101'` in
+ A) # ASCII based system
+    # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr
+  lt_SP2NL='tr \040 \012'
+  lt_NL2SP='tr \015\012 \040\040'
+  ;;
+ *) # EBCDIC based system
+  lt_SP2NL='tr \100 \n'
+  lt_NL2SP='tr \r\n \100\100'
+  ;;
+esac
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5
+$as_echo_n "checking for $LD option to reload object files... " >&6; }
+if test "${lt_cv_ld_reload_flag+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_ld_reload_flag='-r'
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5
+$as_echo "$lt_cv_ld_reload_flag" >&6; }
+reload_flag=$lt_cv_ld_reload_flag
+case $reload_flag in
+"" | " "*) ;;
+*) reload_flag=" $reload_flag" ;;
+esac
+reload_cmds='$LD$reload_flag -o $output$reload_objs'
+case $host_os in
+  darwin*)
+    if test "$GCC" = yes; then
+      reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs'
+    else
+      reload_cmds='$LD$reload_flag -o $output$reload_objs'
+    fi
+    ;;
+esac
+
+
+
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args.
+set dummy ${ac_tool_prefix}objdump; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_OBJDUMP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$OBJDUMP"; then
+  ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+OBJDUMP=$ac_cv_prog_OBJDUMP
+if test -n "$OBJDUMP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5
+$as_echo "$OBJDUMP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_OBJDUMP"; then
+  ac_ct_OBJDUMP=$OBJDUMP
+  # Extract the first word of "objdump", so it can be a program name with args.
+set dummy objdump; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_OBJDUMP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_OBJDUMP"; then
+  ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_OBJDUMP="objdump"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP
+if test -n "$ac_ct_OBJDUMP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5
+$as_echo "$ac_ct_OBJDUMP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_OBJDUMP" = x; then
+    OBJDUMP="false"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    OBJDUMP=$ac_ct_OBJDUMP
+  fi
+else
+  OBJDUMP="$ac_cv_prog_OBJDUMP"
+fi
+
+test -z "$OBJDUMP" && OBJDUMP=objdump
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5
+$as_echo_n "checking how to recognize dependent libraries... " >&6; }
+if test "${lt_cv_deplibs_check_method+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_file_magic_cmd='$MAGIC_CMD'
+lt_cv_file_magic_test_file=
+lt_cv_deplibs_check_method='unknown'
+# Need to set the preceding variable on all platforms that support
+# interlibrary dependencies.
+# 'none' -- dependencies not supported.
+# `unknown' -- same as none, but documents that we really don't know.
+# 'pass_all' -- all dependencies passed with no checks.
+# 'test_compile' -- check by making test program.
+# 'file_magic [[regex]]' -- check by looking for files in library path
+# which responds to the $file_magic_cmd with a given extended regex.
+# If you have `file' or equivalent on your system and you're not sure
+# whether `pass_all' will *always* work, you probably want this one.
+
+case $host_os in
+aix[4-9]*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+beos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+bsdi[45]*)
+  lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)'
+  lt_cv_file_magic_cmd='/usr/bin/file -L'
+  lt_cv_file_magic_test_file=/shlib/libc.so
+  ;;
+
+cygwin*)
+  # func_win32_libid is a shell function defined in ltmain.sh
+  lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+  lt_cv_file_magic_cmd='func_win32_libid'
+  ;;
+
+mingw* | pw32*)
+  # Base MSYS/MinGW do not provide the 'file' command needed by
+  # func_win32_libid shell function, so use a weaker test based on 'objdump',
+  # unless we find 'file', for example because we are cross-compiling.
+  if ( file / ) >/dev/null 2>&1; then
+    lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+    lt_cv_file_magic_cmd='func_win32_libid'
+  else
+    lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?'
+    lt_cv_file_magic_cmd='$OBJDUMP -f'
+  fi
+  ;;
+
+cegcc)
+  # use the weaker test based on 'objdump'. See mingw*.
+  lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?'
+  lt_cv_file_magic_cmd='$OBJDUMP -f'
+  ;;
+
+darwin* | rhapsody*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+freebsd* | dragonfly*)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    case $host_cpu in
+    i*86 )
+      # Not sure whether the presence of OpenBSD here was a mistake.
+      # Let's accept both of them until this is cleared up.
+      lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library'
+      lt_cv_file_magic_cmd=/usr/bin/file
+      lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
+      ;;
+    esac
+  else
+    lt_cv_deplibs_check_method=pass_all
+  fi
+  ;;
+
+gnu*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+hpux10.20* | hpux11*)
+  lt_cv_file_magic_cmd=/usr/bin/file
+  case $host_cpu in
+  ia64*)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64'
+    lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
+    ;;
+  hppa*64*)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]'
+    lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
+    ;;
+  *)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|PA-RISC[0-9].[0-9]) shared library'
+    lt_cv_file_magic_test_file=/usr/lib/libc.sl
+    ;;
+  esac
+  ;;
+
+interix[3-9]*)
+  # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here
+  lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|\.a)$'
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $LD in
+  *-32|*"-32 ") libmagic=32-bit;;
+  *-n32|*"-n32 ") libmagic=N32;;
+  *-64|*"-64 ") libmagic=64-bit;;
+  *) libmagic=never-match;;
+  esac
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+netbsd* | netbsdelf*-gnu)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|_pic\.a)$'
+  fi
+  ;;
+
+newos6*)
+  lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)'
+  lt_cv_file_magic_cmd=/usr/bin/file
+  lt_cv_file_magic_test_file=/usr/lib/libnls.so
+  ;;
+
+*nto* | *qnx*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+openbsd*)
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
+  fi
+  ;;
+
+osf3* | osf4* | osf5*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+rdos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+solaris*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv4 | sysv4.3*)
+  case $host_vendor in
+  motorola)
+    lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]'
+    lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
+    ;;
+  ncr)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  sequent)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib )'
+    ;;
+  sni)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method="file_magic ELF [0-9][0-9]*-bit [LM]SB dynamic lib"
+    lt_cv_file_magic_test_file=/lib/libc.so
+    ;;
+  siemens)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  pc)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  esac
+  ;;
+
+tpf*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+esac
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5
+$as_echo "$lt_cv_deplibs_check_method" >&6; }
+file_magic_cmd=$lt_cv_file_magic_cmd
+deplibs_check_method=$lt_cv_deplibs_check_method
+test -z "$deplibs_check_method" && deplibs_check_method=unknown
+
+
+
+
+
+
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ar; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_AR+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$AR"; then
+  ac_cv_prog_AR="$AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_AR="${ac_tool_prefix}ar"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+AR=$ac_cv_prog_AR
+if test -n "$AR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
+$as_echo "$AR" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_AR"; then
+  ac_ct_AR=$AR
+  # Extract the first word of "ar", so it can be a program name with args.
+set dummy ar; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_AR+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_AR"; then
+  ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_AR="ar"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_AR=$ac_cv_prog_ac_ct_AR
+if test -n "$ac_ct_AR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5
+$as_echo "$ac_ct_AR" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_AR" = x; then
+    AR="false"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    AR=$ac_ct_AR
+  fi
+else
+  AR="$ac_cv_prog_AR"
+fi
+
+test -z "$AR" && AR=ar
+test -z "$AR_FLAGS" && AR_FLAGS=cru
+
+
+
+
+
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
+set dummy ${ac_tool_prefix}strip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_STRIP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$STRIP"; then
+  ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_STRIP="${ac_tool_prefix}strip"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+STRIP=$ac_cv_prog_STRIP
+if test -n "$STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5
+$as_echo "$STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_STRIP"; then
+  ac_ct_STRIP=$STRIP
+  # Extract the first word of "strip", so it can be a program name with args.
+set dummy strip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_STRIP"; then
+  ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_STRIP="strip"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP
+if test -n "$ac_ct_STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5
+$as_echo "$ac_ct_STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_STRIP" = x; then
+    STRIP=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    STRIP=$ac_ct_STRIP
+  fi
+else
+  STRIP="$ac_cv_prog_STRIP"
+fi
+
+test -z "$STRIP" && STRIP=:
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_RANLIB+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$RANLIB"; then
+  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
+$as_echo "$RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_RANLIB"; then
+  ac_ct_RANLIB=$RANLIB
+  # Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_RANLIB"; then
+  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_RANLIB="ranlib"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
+if test -n "$ac_ct_RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
+$as_echo "$ac_ct_RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_RANLIB" = x; then
+    RANLIB=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    RANLIB=$ac_ct_RANLIB
+  fi
+else
+  RANLIB="$ac_cv_prog_RANLIB"
+fi
+
+test -z "$RANLIB" && RANLIB=:
+
+
+
+
+
+
+# Determine commands to create old-style static archives.
+old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs'
+old_postinstall_cmds='chmod 644 $oldlib'
+old_postuninstall_cmds=
+
+if test -n "$RANLIB"; then
+  case $host_os in
+  openbsd*)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib"
+    ;;
+  *)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib"
+    ;;
+  esac
+  old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib"
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+
+
+# Check for command to grab the raw symbol name followed by C symbol from nm.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5
+$as_echo_n "checking command to parse $NM output from $compiler object... " >&6; }
+if test "${lt_cv_sys_global_symbol_pipe+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+
+# These are sane defaults that work on at least a few old systems.
+# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
+
+# Character class describing NM global symbol codes.
+symcode='[BCDEGRST]'
+
+# Regexp to match symbols that can be accessed directly from C.
+sympat='\([_A-Za-z][_A-Za-z0-9]*\)'
+
+# Define system-specific variables.
+case $host_os in
+aix*)
+  symcode='[BCDT]'
+  ;;
+cygwin* | mingw* | pw32* | cegcc*)
+  symcode='[ABCDGISTW]'
+  ;;
+hpux*)
+  if test "$host_cpu" = ia64; then
+    symcode='[ABCDEGRST]'
+  fi
+  ;;
+irix* | nonstopux*)
+  symcode='[BCDEGRST]'
+  ;;
+osf*)
+  symcode='[BCDEGQRST]'
+  ;;
+solaris*)
+  symcode='[BDRT]'
+  ;;
+sco3.2v5*)
+  symcode='[DT]'
+  ;;
+sysv4.2uw2*)
+  symcode='[DT]'
+  ;;
+sysv5* | sco5v6* | unixware* | OpenUNIX*)
+  symcode='[ABDT]'
+  ;;
+sysv4)
+  symcode='[DFNSTU]'
+  ;;
+esac
+
+# If we're using GNU nm, then use its standard symbol codes.
+case `$NM -V 2>&1` in
+*GNU* | *'with BFD'*)
+  symcode='[ABCDGIRSTW]' ;;
+esac
+
+# Transform an extracted symbol line into a proper C declaration.
+# Some systems (esp. on ia64) link data and code symbols differently,
+# so use this general approach.
+lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
+
+# Transform an extracted symbol line into symbol name and symbol address
+lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([^ ]*\) $/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/  {\"\2\", (void *) \&\2},/p'"
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([^ ]*\) $/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \(lib[^ ]*\)$/  {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/  {\"lib\2\", (void *) \&\2},/p'"
+
+# Handle CRLF in mingw tool chain
+opt_cr=
+case $build_os in
+mingw*)
+  opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp
+  ;;
+esac
+
+# Try without a prefix underscore, then with it.
+for ac_symprfx in "" "_"; do
+
+  # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
+  symxfrm="\\1 $ac_symprfx\\2 \\2"
+
+  # Write the raw and C identifiers.
+  if test "$lt_cv_nm_interface" = "MS dumpbin"; then
+    # Fake it for dumpbin and say T for any non-static function
+    # and D for any global variable.
+    # Also find C++ and __fastcall symbols from MSVC++,
+    # which start with @ or ?.
+    lt_cv_sys_global_symbol_pipe="$AWK '"\
+"     {last_section=section; section=\$ 3};"\
+"     /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\
+"     \$ 0!~/External *\|/{next};"\
+"     / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\
+"     {if(hide[section]) next};"\
+"     {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\
+"     {split(\$ 0, a, /\||\r/); split(a[2], s)};"\
+"     s[1]~/^[@?]/{print s[1], s[1]; next};"\
+"     s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\
+"     ' prfx=^$ac_symprfx"
+  else
+    lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[     ]\($symcode$symcode*\)[         ][      ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
+  fi
+
+  # Check to see that the pipe works correctly.
+  pipe_works=no
+
+  rm -f conftest*
+  cat > conftest.$ac_ext <<_LT_EOF
+#ifdef __cplusplus
+extern "C" {
+#endif
+char nm_test_var;
+void nm_test_func(void);
+void nm_test_func(void){}
+#ifdef __cplusplus
+}
+#endif
+int main(){nm_test_var='a';nm_test_func();return(0);}
+_LT_EOF
+
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    # Now try to grab the symbols.
+    nlist=conftest.nm
+    if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist\""; } >&5
+  (eval $NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && test -s "$nlist"; then
+      # Try sorting and uniquifying the output.
+      if sort "$nlist" | uniq > "$nlist"T; then
+       mv -f "$nlist"T "$nlist"
+      else
+       rm -f "$nlist"T
+      fi
+
+      # Make sure that we snagged all the symbols we need.
+      if $GREP ' nm_test_var$' "$nlist" >/dev/null; then
+       if $GREP ' nm_test_func$' "$nlist" >/dev/null; then
+         cat <<_LT_EOF > conftest.$ac_ext
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+_LT_EOF
+         # Now generate the symbol file.
+         eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext'
+
+         cat <<_LT_EOF >> conftest.$ac_ext
+
+/* The mapping between symbol names and symbols.  */
+const struct {
+  const char *name;
+  void       *address;
+}
+lt__PROGRAM__LTX_preloaded_symbols[] =
+{
+  { "@PROGRAM@", (void *) 0 },
+_LT_EOF
+         $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext
+         cat <<\_LT_EOF >> conftest.$ac_ext
+  {0, (void *) 0}
+};
+
+/* This works around a problem in FreeBSD linker */
+#ifdef FREEBSD_WORKAROUND
+static const void *lt_preloaded_setup() {
+  return lt__PROGRAM__LTX_preloaded_symbols;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+_LT_EOF
+         # Now try linking the two files.
+         mv conftest.$ac_objext conftstm.$ac_objext
+         lt_save_LIBS="$LIBS"
+         lt_save_CFLAGS="$CFLAGS"
+         LIBS="conftstm.$ac_objext"
+         CFLAGS="$CFLAGS$lt_prog_compiler_no_builtin_flag"
+         if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && test -s conftest${ac_exeext}; then
+           pipe_works=yes
+         fi
+         LIBS="$lt_save_LIBS"
+         CFLAGS="$lt_save_CFLAGS"
+       else
+         echo "cannot find nm_test_func in $nlist" >&5
+       fi
+      else
+       echo "cannot find nm_test_var in $nlist" >&5
+      fi
+    else
+      echo "cannot run $lt_cv_sys_global_symbol_pipe" >&5
+    fi
+  else
+    echo "$progname: failed program was:" >&5
+    cat conftest.$ac_ext >&5
+  fi
+  rm -rf conftest* conftst*
+
+  # Do not use the global_symbol_pipe unless it works.
+  if test "$pipe_works" = yes; then
+    break
+  else
+    lt_cv_sys_global_symbol_pipe=
+  fi
+done
+
+fi
+
+if test -z "$lt_cv_sys_global_symbol_pipe"; then
+  lt_cv_sys_global_symbol_to_cdecl=
+fi
+if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: failed" >&5
+$as_echo "failed" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5
+$as_echo "ok" >&6; }
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# Check whether --enable-libtool-lock was given.
+if test "${enable_libtool_lock+set}" = set; then :
+  enableval=$enable_libtool_lock;
+fi
+
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
+
+# Some flags need to be propagated to the compiler or linker for good
+# libtool support.
+case $host in
+ia64-*-hpux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    case `/usr/bin/file conftest.$ac_objext` in
+      *ELF-32*)
+       HPUX_IA64_MODE="32"
+       ;;
+      *ELF-64*)
+       HPUX_IA64_MODE="64"
+       ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+*-*-irix6*)
+  # Find out which ABI we are using.
+  echo '#line 6011 "configure"' > conftest.$ac_ext
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    if test "$lt_cv_prog_gnu_ld" = yes; then
+      case `/usr/bin/file conftest.$ac_objext` in
+       *32-bit*)
+         LD="${LD-ld} -melf32bsmip"
+         ;;
+       *N32*)
+         LD="${LD-ld} -melf32bmipn32"
+         ;;
+       *64-bit*)
+         LD="${LD-ld} -melf64bmip"
+       ;;
+      esac
+    else
+      case `/usr/bin/file conftest.$ac_objext` in
+       *32-bit*)
+         LD="${LD-ld} -32"
+         ;;
+       *N32*)
+         LD="${LD-ld} -n32"
+         ;;
+       *64-bit*)
+         LD="${LD-ld} -64"
+         ;;
+      esac
+    fi
+  fi
+  rm -rf conftest*
+  ;;
+
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
+s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    case `/usr/bin/file conftest.o` in
+      *32-bit*)
+       case $host in
+         x86_64-*kfreebsd*-gnu)
+           LD="${LD-ld} -m elf_i386_fbsd"
+           ;;
+         x86_64-*linux*)
+           LD="${LD-ld} -m elf_i386"
+           ;;
+         ppc64-*linux*|powerpc64-*linux*)
+           LD="${LD-ld} -m elf32ppclinux"
+           ;;
+         s390x-*linux*)
+           LD="${LD-ld} -m elf_s390"
+           ;;
+         sparc64-*linux*)
+           LD="${LD-ld} -m elf32_sparc"
+           ;;
+       esac
+       ;;
+      *64-bit*)
+       case $host in
+         x86_64-*kfreebsd*-gnu)
+           LD="${LD-ld} -m elf_x86_64_fbsd"
+           ;;
+         x86_64-*linux*)
+           LD="${LD-ld} -m elf_x86_64"
+           ;;
+         ppc*-*linux*|powerpc*-*linux*)
+           LD="${LD-ld} -m elf64ppc"
+           ;;
+         s390*-*linux*|s390*-*tpf*)
+           LD="${LD-ld} -m elf64_s390"
+           ;;
+         sparc*-*linux*)
+           LD="${LD-ld} -m elf64_sparc"
+           ;;
+       esac
+       ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+
+*-*-sco3.2v5*)
+  # On SCO OpenServer 5, we need -belf to get full-featured binaries.
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -belf"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5
+$as_echo_n "checking whether the C compiler needs -belf... " >&6; }
+if test "${lt_cv_cc_needs_belf+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  lt_cv_cc_needs_belf=yes
+else
+  lt_cv_cc_needs_belf=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+     ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5
+$as_echo "$lt_cv_cc_needs_belf" >&6; }
+  if test x"$lt_cv_cc_needs_belf" != x"yes"; then
+    # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
+    CFLAGS="$SAVE_CFLAGS"
+  fi
+  ;;
+sparc*-*solaris*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    case `/usr/bin/file conftest.o` in
+    *64-bit*)
+      case $lt_cv_prog_gnu_ld in
+      yes*) LD="${LD-ld} -m elf64_sparc" ;;
+      *)
+       if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then
+         LD="${LD-ld} -64"
+       fi
+       ;;
+      esac
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+esac
+
+need_locks="$enable_libtool_lock"
+
+
+  case $host_os in
+    rhapsody* | darwin*)
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args.
+set dummy ${ac_tool_prefix}dsymutil; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_DSYMUTIL+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$DSYMUTIL"; then
+  ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+DSYMUTIL=$ac_cv_prog_DSYMUTIL
+if test -n "$DSYMUTIL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5
+$as_echo "$DSYMUTIL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_DSYMUTIL"; then
+  ac_ct_DSYMUTIL=$DSYMUTIL
+  # Extract the first word of "dsymutil", so it can be a program name with args.
+set dummy dsymutil; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_DSYMUTIL+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_DSYMUTIL"; then
+  ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_DSYMUTIL="dsymutil"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_DSYMUTIL=$ac_cv_prog_ac_ct_DSYMUTIL
+if test -n "$ac_ct_DSYMUTIL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5
+$as_echo "$ac_ct_DSYMUTIL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_DSYMUTIL" = x; then
+    DSYMUTIL=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DSYMUTIL=$ac_ct_DSYMUTIL
+  fi
+else
+  DSYMUTIL="$ac_cv_prog_DSYMUTIL"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args.
+set dummy ${ac_tool_prefix}nmedit; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_NMEDIT+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$NMEDIT"; then
+  ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+NMEDIT=$ac_cv_prog_NMEDIT
+if test -n "$NMEDIT"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5
+$as_echo "$NMEDIT" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_NMEDIT"; then
+  ac_ct_NMEDIT=$NMEDIT
+  # Extract the first word of "nmedit", so it can be a program name with args.
+set dummy nmedit; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_NMEDIT+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_NMEDIT"; then
+  ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_NMEDIT="nmedit"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_NMEDIT=$ac_cv_prog_ac_ct_NMEDIT
+if test -n "$ac_ct_NMEDIT"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5
+$as_echo "$ac_ct_NMEDIT" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_NMEDIT" = x; then
+    NMEDIT=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    NMEDIT=$ac_ct_NMEDIT
+  fi
+else
+  NMEDIT="$ac_cv_prog_NMEDIT"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args.
+set dummy ${ac_tool_prefix}lipo; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_LIPO+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$LIPO"; then
+  ac_cv_prog_LIPO="$LIPO" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_LIPO="${ac_tool_prefix}lipo"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+LIPO=$ac_cv_prog_LIPO
+if test -n "$LIPO"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5
+$as_echo "$LIPO" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_LIPO"; then
+  ac_ct_LIPO=$LIPO
+  # Extract the first word of "lipo", so it can be a program name with args.
+set dummy lipo; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_LIPO+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_LIPO"; then
+  ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_LIPO="lipo"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_LIPO=$ac_cv_prog_ac_ct_LIPO
+if test -n "$ac_ct_LIPO"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5
+$as_echo "$ac_ct_LIPO" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_LIPO" = x; then
+    LIPO=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    LIPO=$ac_ct_LIPO
+  fi
+else
+  LIPO="$ac_cv_prog_LIPO"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args.
+set dummy ${ac_tool_prefix}otool; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_OTOOL+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$OTOOL"; then
+  ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_OTOOL="${ac_tool_prefix}otool"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+OTOOL=$ac_cv_prog_OTOOL
+if test -n "$OTOOL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5
+$as_echo "$OTOOL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_OTOOL"; then
+  ac_ct_OTOOL=$OTOOL
+  # Extract the first word of "otool", so it can be a program name with args.
+set dummy otool; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_OTOOL+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_OTOOL"; then
+  ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_OTOOL="otool"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_OTOOL=$ac_cv_prog_ac_ct_OTOOL
+if test -n "$ac_ct_OTOOL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5
+$as_echo "$ac_ct_OTOOL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_OTOOL" = x; then
+    OTOOL=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    OTOOL=$ac_ct_OTOOL
+  fi
+else
+  OTOOL="$ac_cv_prog_OTOOL"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args.
+set dummy ${ac_tool_prefix}otool64; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_OTOOL64+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$OTOOL64"; then
+  ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+OTOOL64=$ac_cv_prog_OTOOL64
+if test -n "$OTOOL64"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5
+$as_echo "$OTOOL64" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_OTOOL64"; then
+  ac_ct_OTOOL64=$OTOOL64
+  # Extract the first word of "otool64", so it can be a program name with args.
+set dummy otool64; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_OTOOL64+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_OTOOL64"; then
+  ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_OTOOL64="otool64"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_OTOOL64=$ac_cv_prog_ac_ct_OTOOL64
+if test -n "$ac_ct_OTOOL64"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5
+$as_echo "$ac_ct_OTOOL64" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_OTOOL64" = x; then
+    OTOOL64=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    OTOOL64=$ac_ct_OTOOL64
+  fi
+else
+  OTOOL64="$ac_cv_prog_OTOOL64"
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5
+$as_echo_n "checking for -single_module linker flag... " >&6; }
+if test "${lt_cv_apple_cc_single_mod+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_apple_cc_single_mod=no
+      if test -z "${LT_MULTI_MODULE}"; then
+       # By default we will add the -single_module flag. You can override
+       # by either setting the environment variable LT_MULTI_MODULE
+       # non-empty at configure time, or by adding -multi_module to the
+       # link flags.
+       rm -rf libconftest.dylib*
+       echo "int foo(void){return 1;}" > conftest.c
+       echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+-dynamiclib -Wl,-single_module conftest.c" >&5
+       $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+         -dynamiclib -Wl,-single_module conftest.c 2>conftest.err
+        _lt_result=$?
+       if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then
+         lt_cv_apple_cc_single_mod=yes
+       else
+         cat conftest.err >&5
+       fi
+       rm -rf libconftest.dylib*
+       rm -f conftest.*
+      fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5
+$as_echo "$lt_cv_apple_cc_single_mod" >&6; }
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5
+$as_echo_n "checking for -exported_symbols_list linker flag... " >&6; }
+if test "${lt_cv_ld_exported_symbols_list+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_ld_exported_symbols_list=no
+      save_LDFLAGS=$LDFLAGS
+      echo "_main" > conftest.sym
+      LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym"
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  lt_cv_ld_exported_symbols_list=yes
+else
+  lt_cv_ld_exported_symbols_list=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+       LDFLAGS="$save_LDFLAGS"
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5
+$as_echo "$lt_cv_ld_exported_symbols_list" >&6; }
+    case $host_os in
+    rhapsody* | darwin1.[012])
+      _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;;
+    darwin1.*)
+      _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+    darwin*) # darwin 5.x on
+      # if running on 10.5 or later, the deployment target defaults
+      # to the OS version, if on x86, and 10.4, the deployment
+      # target defaults to 10.4. Don't you love it?
+      case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
+       10.0,*86*-darwin8*|10.0,*-darwin[91]*)
+         _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+       10.[012]*)
+         _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+       10.*)
+         _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+      esac
+    ;;
+  esac
+    if test "$lt_cv_apple_cc_single_mod" = "yes"; then
+      _lt_dar_single_mod='$single_module'
+    fi
+    if test "$lt_cv_ld_exported_symbols_list" = "yes"; then
+      _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym'
+    else
+      _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}'
+    fi
+    if test "$DSYMUTIL" != ":"; then
+      _lt_dsymutil='~$DSYMUTIL $lib || :'
+    else
+      _lt_dsymutil=
+    fi
+    ;;
+  esac
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
+$as_echo_n "checking how to run the C preprocessor... " >&6; }
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+  CPP=
+fi
+if test -z "$CPP"; then
+  if test "${ac_cv_prog_CPP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+      # Double quotes because CPP needs to be expanded
+    for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
+    do
+      ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+                    Syntax error
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  # Broken: success on invalid input.
+continue
+else
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+  break
+fi
+
+    done
+    ac_cv_prog_CPP=$CPP
+
+fi
+  CPP=$ac_cv_prog_CPP
+else
+  ac_cv_prog_CPP=$CPP
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
+$as_echo "$CPP" >&6; }
+ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+                    Syntax error
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  # Broken: success on invalid input.
+continue
+else
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+
+else
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." "$LINENO" 5; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
+$as_echo_n "checking for ANSI C header files... " >&6; }
+if test "${ac_cv_header_stdc+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_header_stdc=yes
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then :
+  :
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ctype.h>
+#include <stdlib.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+                  (('a' <= (c) && (c) <= 'i') \
+                    || ('j' <= (c) && (c) <= 'r') \
+                    || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+       || toupper (i) != TOUPPER (i))
+      return 2;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
+$as_echo "$ac_cv_header_stdc" >&6; }
+if test $ac_cv_header_stdc = yes; then
+
+$as_echo "#define STDC_HEADERS 1" >>confdefs.h
+
+fi
+
+# On IRIX 5.3, sys/types and inttypes.h are conflicting.
+for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
+                 inttypes.h stdint.h unistd.h
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
+"
+eval as_val=\$$as_ac_Header
+   if test "x$as_val" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+for ac_header in dlfcn.h
+do :
+  ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default
+"
+if test "x$ac_cv_header_dlfcn_h" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_DLFCN_H 1
+_ACEOF
+
+fi
+
+done
+
+
+
+# Set options
+
+
+
+        enable_dlopen=no
+
+
+  enable_win32_dll=no
+
+
+            # Check whether --enable-shared was given.
+if test "${enable_shared+set}" = set; then :
+  enableval=$enable_shared; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_shared=yes ;;
+    no) enable_shared=no ;;
+    *)
+      enable_shared=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+       IFS="$lt_save_ifs"
+       if test "X$pkg" = "X$p"; then
+         enable_shared=yes
+       fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_shared=yes
+fi
+
+
+
+
+
+
+
+
+
+  # Check whether --enable-static was given.
+if test "${enable_static+set}" = set; then :
+  enableval=$enable_static; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_static=yes ;;
+    no) enable_static=no ;;
+    *)
+     enable_static=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+       IFS="$lt_save_ifs"
+       if test "X$pkg" = "X$p"; then
+         enable_static=yes
+       fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_static=yes
+fi
+
+
+
+
+
+
+
+
+
+
+# Check whether --with-pic was given.
+if test "${with_pic+set}" = set; then :
+  withval=$with_pic; pic_mode="$withval"
+else
+  pic_mode=default
+fi
+
+
+test -z "$pic_mode" && pic_mode=default
+
+
+
+
+
+
+
+  # Check whether --enable-fast-install was given.
+if test "${enable_fast_install+set}" = set; then :
+  enableval=$enable_fast_install; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_fast_install=yes ;;
+    no) enable_fast_install=no ;;
+    *)
+      enable_fast_install=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+       IFS="$lt_save_ifs"
+       if test "X$pkg" = "X$p"; then
+         enable_fast_install=yes
+       fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_fast_install=yes
+fi
+
+
+
+
+
+
+
+
+
+
+
+# This can be used to rebuild libtool when needed
+LIBTOOL_DEPS="$ltmain"
+
+# Always use our own libtool.
+LIBTOOL='$(SHELL) $(top_builddir)/libtool'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+test -z "$LN_S" && LN_S="ln -s"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+if test -n "${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5
+$as_echo_n "checking for objdir... " >&6; }
+if test "${lt_cv_objdir+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  rm -f .libs 2>/dev/null
+mkdir .libs 2>/dev/null
+if test -d .libs; then
+  lt_cv_objdir=.libs
+else
+  # MS-DOS does not allow filenames that begin with a dot.
+  lt_cv_objdir=_libs
+fi
+rmdir .libs 2>/dev/null
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5
+$as_echo "$lt_cv_objdir" >&6; }
+objdir=$lt_cv_objdir
+
+
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define LT_OBJDIR "$lt_cv_objdir/"
+_ACEOF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+case $host_os in
+aix3*)
+  # AIX sometimes has problems with the GCC collect2 program.  For some
+  # reason, if we set the COLLECT_NAMES environment variable, the problems
+  # vanish in a puff of smoke.
+  if test "X${COLLECT_NAMES+set}" != Xset; then
+    COLLECT_NAMES=
+    export COLLECT_NAMES
+  fi
+  ;;
+esac
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+sed_quote_subst='s/\(["`$\\]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\(["`\\]\)/\\\1/g'
+
+# Sed substitution to delay expansion of an escaped shell variable in a
+# double_quote_subst'ed string.
+delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
+
+# Sed substitution to delay expansion of an escaped single quote.
+delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g'
+
+# Sed substitution to avoid accidental globbing in evaled expressions
+no_glob_subst='s/\*/\\\*/g'
+
+# Global variables:
+ofile=libtool
+can_build_shared=yes
+
+# All known linkers require a `.a' archive for static linking (except MSVC,
+# which needs '.lib').
+libext=a
+
+with_gnu_ld="$lt_cv_prog_gnu_ld"
+
+old_CC="$CC"
+old_CFLAGS="$CFLAGS"
+
+# Set sane defaults for various variables
+test -z "$CC" && CC=cc
+test -z "$LTCC" && LTCC=$CC
+test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS
+test -z "$LD" && LD=ld
+test -z "$ac_objext" && ac_objext=o
+
+for cc_temp in $compiler""; do
+  case $cc_temp in
+    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+
+
+# Only perform the check for file, if the check method requires it
+test -z "$MAGIC_CMD" && MAGIC_CMD=file
+case $deplibs_check_method in
+file_magic*)
+  if test "$file_magic_cmd" = '$MAGIC_CMD'; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5
+$as_echo_n "checking for ${ac_tool_prefix}file... " >&6; }
+if test "${lt_cv_path_MAGIC_CMD+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $MAGIC_CMD in
+[\\/*] |  ?:[\\/]*)
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  ac_dummy="/usr/bin$PATH_SEPARATOR$PATH"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/${ac_tool_prefix}file; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/${ac_tool_prefix}file"
+      if test -n "$file_magic_test_file"; then
+       case $deplibs_check_method in
+       "file_magic "*)
+         file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+         MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+         if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+           $EGREP "$file_magic_regex" > /dev/null; then
+           :
+         else
+           cat <<_LT_EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool@gnu.org
+
+_LT_EOF
+         fi ;;
+       esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac
+fi
+
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5
+$as_echo "$MAGIC_CMD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
+
+
+if test -z "$lt_cv_path_MAGIC_CMD"; then
+  if test -n "$ac_tool_prefix"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for file" >&5
+$as_echo_n "checking for file... " >&6; }
+if test "${lt_cv_path_MAGIC_CMD+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $MAGIC_CMD in
+[\\/*] |  ?:[\\/]*)
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  ac_dummy="/usr/bin$PATH_SEPARATOR$PATH"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/file; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/file"
+      if test -n "$file_magic_test_file"; then
+       case $deplibs_check_method in
+       "file_magic "*)
+         file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+         MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+         if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+           $EGREP "$file_magic_regex" > /dev/null; then
+           :
+         else
+           cat <<_LT_EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool@gnu.org
+
+_LT_EOF
+         fi ;;
+       esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac
+fi
+
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5
+$as_echo "$MAGIC_CMD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  else
+    MAGIC_CMD=:
+  fi
+fi
+
+  fi
+  ;;
+esac
+
+# Use C for the default configuration in the libtool script
+
+lt_save_CC="$CC"
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+# Source file extension for C test sources.
+ac_ext=c
+
+# Object file extension for compiled C test sources.
+objext=o
+objext=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="int some_variable = 0;"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='int main(){return(0);}'
+
+
+
+
+
+
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+
+# Save the default compiler, since it gets overwritten when the other
+# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP.
+compiler_DEFAULT=$CC
+
+# save warnings/boilerplate of simple test code
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$RM conftest*
+
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$RM -r conftest*
+
+
+## CAVEAT EMPTOR:
+## There is no encapsulation within the following macros, do not change
+## the running order or otherwise move them around unless you know exactly
+## what you are doing...
+if test -n "$compiler"; then
+
+lt_prog_compiler_no_builtin_flag=
+
+if test "$GCC" = yes; then
+  lt_prog_compiler_no_builtin_flag=' -fno-builtin'
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5
+$as_echo_n "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; }
+if test "${lt_cv_prog_compiler_rtti_exceptions+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_rtti_exceptions=no
+   ac_outfile=conftest.$ac_objext
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="-fno-rtti -fno-exceptions"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:7541: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&5
+   echo "$as_me:7545: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_rtti_exceptions=yes
+     fi
+   fi
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5
+$as_echo "$lt_cv_prog_compiler_rtti_exceptions" >&6; }
+
+if test x"$lt_cv_prog_compiler_rtti_exceptions" = xyes; then
+    lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions"
+else
+    :
+fi
+
+fi
+
+
+
+
+
+
+  lt_prog_compiler_wl=
+lt_prog_compiler_pic=
+lt_prog_compiler_static=
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5
+$as_echo_n "checking for $compiler option to produce PIC... " >&6; }
+
+  if test "$GCC" = yes; then
+    lt_prog_compiler_wl='-Wl,'
+    lt_prog_compiler_static='-static'
+
+    case $host_os in
+      aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+       # AIX 5 now supports IA64 processor
+       lt_prog_compiler_static='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            lt_prog_compiler_pic='-fPIC'
+        ;;
+      m68k)
+            # FIXME: we need at least 68020 code to build shared libraries, but
+            # adding the `-m68020' flag to GCC prevents building anything better,
+            # like `-m68040'.
+            lt_prog_compiler_pic='-m68020 -resident32 -malways-restore-a4'
+        ;;
+      esac
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      lt_prog_compiler_pic='-DDLL_EXPORT'
+      ;;
+
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      lt_prog_compiler_pic='-fno-common'
+      ;;
+
+    hpux*)
+      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
+      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
+      # sets the default TLS model and affects inlining.
+      case $host_cpu in
+      hppa*64*)
+       # +Z the default
+       ;;
+      *)
+       lt_prog_compiler_pic='-fPIC'
+       ;;
+      esac
+      ;;
+
+    interix[3-9]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+
+    msdosdjgpp*)
+      # Just because we use GCC doesn't mean we suddenly get shared libraries
+      # on systems that don't support them.
+      lt_prog_compiler_can_build_shared=no
+      enable_shared=no
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      lt_prog_compiler_pic='-fPIC -shared'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+       lt_prog_compiler_pic=-Kconform_pic
+      fi
+      ;;
+
+    *)
+      lt_prog_compiler_pic='-fPIC'
+      ;;
+    esac
+  else
+    # PORTME Check for flag to pass linker flags through the system compiler.
+    case $host_os in
+    aix*)
+      lt_prog_compiler_wl='-Wl,'
+      if test "$host_cpu" = ia64; then
+       # AIX 5 now supports IA64 processor
+       lt_prog_compiler_static='-Bstatic'
+      else
+       lt_prog_compiler_static='-bnso -bI:/lib/syscalls.exp'
+      fi
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      lt_prog_compiler_pic='-DDLL_EXPORT'
+      ;;
+
+    hpux9* | hpux10* | hpux11*)
+      lt_prog_compiler_wl='-Wl,'
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+       # +Z the default
+       ;;
+      *)
+       lt_prog_compiler_pic='+Z'
+       ;;
+      esac
+      # Is there a better lt_prog_compiler_static that works with the bundled CC?
+      lt_prog_compiler_static='${wl}-a ${wl}archive'
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      lt_prog_compiler_wl='-Wl,'
+      # PIC (with -KPIC) is the default.
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    linux* | k*bsd*-gnu)
+      case $cc_basename in
+      # old Intel for x86_64 which still supported -KPIC.
+      ecc*)
+       lt_prog_compiler_wl='-Wl,'
+       lt_prog_compiler_pic='-KPIC'
+       lt_prog_compiler_static='-static'
+        ;;
+      # icc used to be incompatible with GCC.
+      # ICC 10 doesn't accept -KPIC any more.
+      icc* | ifort*)
+       lt_prog_compiler_wl='-Wl,'
+       lt_prog_compiler_pic='-fPIC'
+       lt_prog_compiler_static='-static'
+        ;;
+      # Lahey Fortran 8.1.
+      lf95*)
+       lt_prog_compiler_wl='-Wl,'
+       lt_prog_compiler_pic='--shared'
+       lt_prog_compiler_static='--static'
+       ;;
+      pgcc* | pgf77* | pgf90* | pgf95*)
+        # Portland Group compilers (*not* the Pentium gcc compiler,
+       # which looks to be a dead project)
+       lt_prog_compiler_wl='-Wl,'
+       lt_prog_compiler_pic='-fpic'
+       lt_prog_compiler_static='-Bstatic'
+        ;;
+      ccc*)
+        lt_prog_compiler_wl='-Wl,'
+        # All Alpha code is PIC.
+        lt_prog_compiler_static='-non_shared'
+        ;;
+      xl*)
+       # IBM XL C 8.0/Fortran 10.1 on PPC
+       lt_prog_compiler_wl='-Wl,'
+       lt_prog_compiler_pic='-qpic'
+       lt_prog_compiler_static='-qstaticlink'
+       ;;
+      *)
+       case `$CC -V 2>&1 | sed 5q` in
+       *Sun\ C*)
+         # Sun C 5.9
+         lt_prog_compiler_pic='-KPIC'
+         lt_prog_compiler_static='-Bstatic'
+         lt_prog_compiler_wl='-Wl,'
+         ;;
+       *Sun\ F*)
+         # Sun Fortran 8.3 passes all unrecognized flags to the linker
+         lt_prog_compiler_pic='-KPIC'
+         lt_prog_compiler_static='-Bstatic'
+         lt_prog_compiler_wl=''
+         ;;
+       esac
+       ;;
+      esac
+      ;;
+
+    newsos6)
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      lt_prog_compiler_pic='-fPIC -shared'
+      ;;
+
+    osf3* | osf4* | osf5*)
+      lt_prog_compiler_wl='-Wl,'
+      # All OSF/1 code is PIC.
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    rdos*)
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    solaris*)
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      case $cc_basename in
+      f77* | f90* | f95*)
+       lt_prog_compiler_wl='-Qoption ld ';;
+      *)
+       lt_prog_compiler_wl='-Wl,';;
+      esac
+      ;;
+
+    sunos4*)
+      lt_prog_compiler_wl='-Qoption ld '
+      lt_prog_compiler_pic='-PIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    sysv4 | sysv4.2uw2* | sysv4.3*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec ;then
+       lt_prog_compiler_pic='-Kconform_pic'
+       lt_prog_compiler_static='-Bstatic'
+      fi
+      ;;
+
+    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    unicos*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_can_build_shared=no
+      ;;
+
+    uts4*)
+      lt_prog_compiler_pic='-pic'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    *)
+      lt_prog_compiler_can_build_shared=no
+      ;;
+    esac
+  fi
+
+case $host_os in
+  # For platforms which do not support PIC, -DPIC is meaningless:
+  *djgpp*)
+    lt_prog_compiler_pic=
+    ;;
+  *)
+    lt_prog_compiler_pic="$lt_prog_compiler_pic -DPIC"
+    ;;
+esac
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_prog_compiler_pic" >&5
+$as_echo "$lt_prog_compiler_pic" >&6; }
+
+
+
+
+
+
+#
+# Check to make sure the PIC flag actually works.
+#
+if test -n "$lt_prog_compiler_pic"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5
+$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; }
+if test "${lt_cv_prog_compiler_pic_works+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_pic_works=no
+   ac_outfile=conftest.$ac_objext
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="$lt_prog_compiler_pic -DPIC"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:7880: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&5
+   echo "$as_me:7884: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_pic_works=yes
+     fi
+   fi
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5
+$as_echo "$lt_cv_prog_compiler_pic_works" >&6; }
+
+if test x"$lt_cv_prog_compiler_pic_works" = xyes; then
+    case $lt_prog_compiler_pic in
+     "" | " "*) ;;
+     *) lt_prog_compiler_pic=" $lt_prog_compiler_pic" ;;
+     esac
+else
+    lt_prog_compiler_pic=
+     lt_prog_compiler_can_build_shared=no
+fi
+
+fi
+
+
+
+
+
+
+#
+# Check to make sure the static flag actually works.
+#
+wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5
+$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; }
+if test "${lt_cv_prog_compiler_static_works+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_static_works=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $lt_tmp_static_flag"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&5
+       $ECHO "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         lt_cv_prog_compiler_static_works=yes
+       fi
+     else
+       lt_cv_prog_compiler_static_works=yes
+     fi
+   fi
+   $RM -r conftest*
+   LDFLAGS="$save_LDFLAGS"
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5
+$as_echo "$lt_cv_prog_compiler_static_works" >&6; }
+
+if test x"$lt_cv_prog_compiler_static_works" = xyes; then
+    :
+else
+    lt_prog_compiler_static=
+fi
+
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5
+$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; }
+if test "${lt_cv_prog_compiler_c_o+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_c_o=no
+   $RM -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:7985: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&5
+   echo "$as_me:7989: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_c_o=yes
+     fi
+   fi
+   chmod u+w . 2>&5
+   $RM conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
+   $RM out/* && rmdir out
+   cd ..
+   $RM -r conftest
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5
+$as_echo "$lt_cv_prog_compiler_c_o" >&6; }
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5
+$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; }
+if test "${lt_cv_prog_compiler_c_o+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_c_o=no
+   $RM -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:8040: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&5
+   echo "$as_me:8044: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_c_o=yes
+     fi
+   fi
+   chmod u+w . 2>&5
+   $RM conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
+   $RM out/* && rmdir out
+   cd ..
+   $RM -r conftest
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5
+$as_echo "$lt_cv_prog_compiler_c_o" >&6; }
+
+
+
+
+hard_links="nottested"
+if test "$lt_cv_prog_compiler_c_o" = no && test "$need_locks" != no; then
+  # do not overwrite the value of need_locks provided by the user
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5
+$as_echo_n "checking if we can lock with hard links... " >&6; }
+  hard_links=yes
+  $RM conftest*
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  touch conftest.a
+  ln conftest.a conftest.b 2>&5 || hard_links=no
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5
+$as_echo "$hard_links" >&6; }
+  if test "$hard_links" = no; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5
+$as_echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;}
+    need_locks=warn
+  fi
+else
+  need_locks=no
+fi
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5
+$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; }
+
+  runpath_var=
+  allow_undefined_flag=
+  always_export_symbols=no
+  archive_cmds=
+  archive_expsym_cmds=
+  compiler_needs_object=no
+  enable_shared_with_static_runtimes=no
+  export_dynamic_flag_spec=
+  export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  hardcode_automatic=no
+  hardcode_direct=no
+  hardcode_direct_absolute=no
+  hardcode_libdir_flag_spec=
+  hardcode_libdir_flag_spec_ld=
+  hardcode_libdir_separator=
+  hardcode_minus_L=no
+  hardcode_shlibpath_var=unsupported
+  inherit_rpath=no
+  link_all_deplibs=unknown
+  module_cmds=
+  module_expsym_cmds=
+  old_archive_from_new_cmds=
+  old_archive_from_expsyms_cmds=
+  thread_safe_flag_spec=
+  whole_archive_flag_spec=
+  # include_expsyms should be a list of space-separated symbols to be *always*
+  # included in the symbol list
+  include_expsyms=
+  # exclude_expsyms can be an extended regexp of symbols to exclude
+  # it will be wrapped by ` (' and `)$', so one must not match beginning or
+  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
+  # as well as any symbol that contains `d'.
+  exclude_expsyms='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'
+  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
+  # platforms (ab)use it in PIC code, but their linkers get confused if
+  # the symbol is explicitly referenced.  Since portable code cannot
+  # rely on this symbol name, it's probably fine to never include it in
+  # preloaded symbol tables.
+  # Exclude shared library initialization/finalization symbols.
+  extract_expsyms_cmds=
+
+  case $host_os in
+  cygwin* | mingw* | pw32* | cegcc*)
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
+    # When not using gcc, we currently assume that we are using
+    # Microsoft Visual C++.
+    if test "$GCC" != yes; then
+      with_gnu_ld=no
+    fi
+    ;;
+  interix*)
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
+    with_gnu_ld=yes
+    ;;
+  openbsd*)
+    with_gnu_ld=no
+    ;;
+  linux* | k*bsd*-gnu)
+    link_all_deplibs=no
+    ;;
+  esac
+
+  ld_shlibs=yes
+  if test "$with_gnu_ld" = yes; then
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    wlarc='${wl}'
+
+    # Set some defaults for GNU ld with shared library support. These
+    # are reset later if shared libraries are not supported. Putting them
+    # here allows them to be overridden if necessary.
+    runpath_var=LD_RUN_PATH
+    hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+    export_dynamic_flag_spec='${wl}--export-dynamic'
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then
+      whole_archive_flag_spec="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+    else
+      whole_archive_flag_spec=
+    fi
+    supports_anon_versioning=no
+    case `$LD -v 2>&1` in
+      *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11
+      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
+      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
+      *\ 2.11.*) ;; # other 2.11 versions
+      *) supports_anon_versioning=yes ;;
+    esac
+
+    # See if GNU ld supports shared libraries.
+    case $host_os in
+    aix[3-9]*)
+      # On AIX/PPC, the GNU linker is very broken
+      if test "$host_cpu" != ia64; then
+       ld_shlibs=no
+       cat <<_LT_EOF 1>&2
+
+*** Warning: the GNU linker, at least up to release 2.9.1, is reported
+*** to be unable to reliably create shared libraries on AIX.
+*** Therefore, libtool is disabling shared libraries support.  If you
+*** really care for shared libraries, you may want to modify your PATH
+*** so that a non-GNU linker is found, and then restart.
+
+_LT_EOF
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            archive_expsym_cmds=''
+        ;;
+      m68k)
+            archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            hardcode_libdir_flag_spec='-L$libdir'
+            hardcode_minus_L=yes
+        ;;
+      esac
+      ;;
+
+    beos*)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+       allow_undefined_flag=unsupported
+       # Joseph Beckenbach <jrb3@best.com> says some releases of gcc
+       # support --undefined.  This deserves some investigation.  FIXME
+       archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      else
+       ld_shlibs=no
+      fi
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless,
+      # as there is no search path for DLLs.
+      hardcode_libdir_flag_spec='-L$libdir'
+      allow_undefined_flag=unsupported
+      always_export_symbols=no
+      enable_shared_with_static_runtimes=yes
+      export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/'\'' | $SED -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols'
+
+      if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
+        archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+       # If the export-symbols file already is a .def file (1st line
+       # is EXPORTS), use it as is; otherwise, prepend...
+       archive_expsym_cmds='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+         cp $export_symbols $output_objdir/$soname.def;
+       else
+         echo EXPORTS > $output_objdir/$soname.def;
+         cat $export_symbols >> $output_objdir/$soname.def;
+       fi~
+       $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      else
+       ld_shlibs=no
+      fi
+      ;;
+
+    interix[3-9]*)
+      hardcode_direct=no
+      hardcode_shlibpath_var=no
+      hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+      export_dynamic_flag_spec='${wl}-E'
+      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+      # Instead, shared libraries are loaded at an image base (0x10000000 by
+      # default) and relocated if they conflict, which is a slow very memory
+      # consuming and fragmenting process.  To avoid this, we pick a random,
+      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+      archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      archive_expsym_cmds='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      ;;
+
+    gnu* | linux* | tpf* | k*bsd*-gnu)
+      tmp_diet=no
+      if test "$host_os" = linux-dietlibc; then
+       case $cc_basename in
+         diet\ *) tmp_diet=yes;;       # linux-dietlibc with static linking (!diet-dyn)
+       esac
+      fi
+      if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \
+        && test "$tmp_diet" = no
+      then
+       tmp_addflag=
+       tmp_sharedflag='-shared'
+       case $cc_basename,$host_cpu in
+        pgcc*)                         # Portland Group C compiler
+         whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+         tmp_addflag=' $pic_flag'
+         ;;
+       pgf77* | pgf90* | pgf95*)       # Portland Group f77 and f90 compilers
+         whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+         tmp_addflag=' $pic_flag -Mnomain' ;;
+       ecc*,ia64* | icc*,ia64*)        # Intel C compiler on ia64
+         tmp_addflag=' -i_dynamic' ;;
+       efc*,ia64* | ifort*,ia64*)      # Intel Fortran compiler on ia64
+         tmp_addflag=' -i_dynamic -nofor_main' ;;
+       ifc* | ifort*)                  # Intel Fortran compiler
+         tmp_addflag=' -nofor_main' ;;
+       lf95*)                          # Lahey Fortran 8.1
+         whole_archive_flag_spec=
+         tmp_sharedflag='--shared' ;;
+       xl[cC]*)                        # IBM XL C 8.0 on PPC (deal with xlf below)
+         tmp_sharedflag='-qmkshrobj'
+         tmp_addflag= ;;
+       esac
+       case `$CC -V 2>&1 | sed 5q` in
+       *Sun\ C*)                       # Sun C 5.9
+         whole_archive_flag_spec='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+         compiler_needs_object=yes
+         tmp_sharedflag='-G' ;;
+       *Sun\ F*)                       # Sun Fortran 8.3
+         tmp_sharedflag='-G' ;;
+       esac
+       archive_cmds='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+
+        if test "x$supports_anon_versioning" = xyes; then
+          archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~
+           cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+           echo "local: *; };" >> $output_objdir/$libname.ver~
+           $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+        fi
+
+       case $cc_basename in
+       xlf*)
+         # IBM XL Fortran 10.1 on PPC cannot create shared libs itself
+         whole_archive_flag_spec='--whole-archive$convenience --no-whole-archive'
+         hardcode_libdir_flag_spec=
+         hardcode_libdir_flag_spec_ld='-rpath $libdir'
+         archive_cmds='$LD -shared $libobjs $deplibs $compiler_flags -soname $soname -o $lib'
+         if test "x$supports_anon_versioning" = xyes; then
+           archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~
+             cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+             echo "local: *; };" >> $output_objdir/$libname.ver~
+             $LD -shared $libobjs $deplibs $compiler_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib'
+         fi
+         ;;
+       esac
+      else
+        ld_shlibs=no
+      fi
+      ;;
+
+    netbsd* | netbsdelf*-gnu)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+       archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
+       wlarc=
+      else
+       archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+       archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      fi
+      ;;
+
+    solaris*)
+      if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then
+       ld_shlibs=no
+       cat <<_LT_EOF 1>&2
+
+*** Warning: The releases 2.8.* of the GNU linker cannot reliably
+*** create shared libraries on Solaris systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.9.1 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+      elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+       archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+       archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+       ld_shlibs=no
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+      case `$LD -v 2>&1` in
+        *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*)
+       ld_shlibs=no
+       cat <<_LT_EOF 1>&2
+
+*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
+*** reliably create shared libraries on SCO systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+       ;;
+       *)
+         # For security reasons, it is highly recommended that you always
+         # use absolute paths for naming shared libraries, and exclude the
+         # DT_RUNPATH tag from executables and libraries.  But doing so
+         # requires that you compile everything twice, which is a pain.
+         if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+           hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+           archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+           archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+         else
+           ld_shlibs=no
+         fi
+       ;;
+      esac
+      ;;
+
+    sunos4*)
+      archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      wlarc=
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    *)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+       archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+       archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+       ld_shlibs=no
+      fi
+      ;;
+    esac
+
+    if test "$ld_shlibs" = no; then
+      runpath_var=
+      hardcode_libdir_flag_spec=
+      export_dynamic_flag_spec=
+      whole_archive_flag_spec=
+    fi
+  else
+    # PORTME fill in a description of your system's linker (not GNU ld)
+    case $host_os in
+    aix3*)
+      allow_undefined_flag=unsupported
+      always_export_symbols=yes
+      archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
+      # Note: this linker hardcodes the directories in LIBPATH if there
+      # are no directories specified by -L.
+      hardcode_minus_L=yes
+      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
+       # Neither direct hardcoding nor static linking is supported with a
+       # broken collect2.
+       hardcode_direct=unsupported
+      fi
+      ;;
+
+    aix[4-9]*)
+      if test "$host_cpu" = ia64; then
+       # On IA64, the linker does run time linking by default, so we don't
+       # have to do anything special.
+       aix_use_runtimelinking=no
+       exp_sym_flag='-Bexport'
+       no_entry_flag=""
+      else
+       # If we're using GNU nm, then we don't want the "-C" option.
+       # -C means demangle to AIX nm, but means don't demangle with GNU nm
+       if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
+         export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+       else
+         export_symbols_cmds='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+       fi
+       aix_use_runtimelinking=no
+
+       # Test if we are trying to use run time linking or normal
+       # AIX style linking. If -brtl is somewhere in LDFLAGS, we
+       # need to do runtime linking.
+       case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*)
+         for ld_flag in $LDFLAGS; do
+         if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
+           aix_use_runtimelinking=yes
+           break
+         fi
+         done
+         ;;
+       esac
+
+       exp_sym_flag='-bexport'
+       no_entry_flag='-bnoentry'
+      fi
+
+      # When large executables or shared objects are built, AIX ld can
+      # have problems creating the table of contents.  If linking a library
+      # or program results in "error TOC overflow" add -mminimal-toc to
+      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+      archive_cmds=''
+      hardcode_direct=yes
+      hardcode_direct_absolute=yes
+      hardcode_libdir_separator=':'
+      link_all_deplibs=yes
+      file_list_spec='${wl}-f,'
+
+      if test "$GCC" = yes; then
+       case $host_os in aix4.[012]|aix4.[012].*)
+       # We only want to do this on AIX 4.2 and lower, the check
+       # below for broken collect2 doesn't work under 4.3+
+         collect2name=`${CC} -print-prog-name=collect2`
+         if test -f "$collect2name" &&
+          strings "$collect2name" | $GREP resolve_lib_name >/dev/null
+         then
+         # We have reworked collect2
+         :
+         else
+         # We have old collect2
+         hardcode_direct=unsupported
+         # It fails to find uninstalled libraries when the uninstalled
+         # path is not listed in the libpath.  Setting hardcode_minus_L
+         # to unsupported forces relinking
+         hardcode_minus_L=yes
+         hardcode_libdir_flag_spec='-L$libdir'
+         hardcode_libdir_separator=
+         fi
+         ;;
+       esac
+       shared_flag='-shared'
+       if test "$aix_use_runtimelinking" = yes; then
+         shared_flag="$shared_flag "'${wl}-G'
+       fi
+       link_all_deplibs=no
+      else
+       # not using gcc
+       if test "$host_cpu" = ia64; then
+       # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+       # chokes on -Wl,-G. The following line is correct:
+         shared_flag='-G'
+       else
+         if test "$aix_use_runtimelinking" = yes; then
+           shared_flag='${wl}-G'
+         else
+           shared_flag='${wl}-bM:SRE'
+         fi
+       fi
+      fi
+
+      export_dynamic_flag_spec='${wl}-bexpall'
+      # It seems that -bexpall does not export symbols beginning with
+      # underscore (_), so it is better to generate a list of symbols to export.
+      always_export_symbols=yes
+      if test "$aix_use_runtimelinking" = yes; then
+       # Warning - without using the other runtime loading flags (-brtl),
+       # -berok will link without error, but may produce a broken library.
+       allow_undefined_flag='-berok'
+        # Determine the default libpath from the value encoded in an
+        # empty executable.
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+       /^0/ {
+           s/^0  *\(.*\)$/\1/
+           p
+       }
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+
+        hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
+        archive_expsym_cmds='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+      else
+       if test "$host_cpu" = ia64; then
+         hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib'
+         allow_undefined_flag="-z nodefs"
+         archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+       else
+        # Determine the default libpath from the value encoded in an
+        # empty executable.
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+       /^0/ {
+           s/^0  *\(.*\)$/\1/
+           p
+       }
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+
+        hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
+         # Warning - without using the other run time loading flags,
+         # -berok will link without error, but may produce a broken library.
+         no_undefined_flag=' ${wl}-bernotok'
+         allow_undefined_flag=' ${wl}-berok'
+         # Exported symbols can be pulled into shared objects from archives
+         whole_archive_flag_spec='$convenience'
+         archive_cmds_need_lc=yes
+         # This is similar to how AIX traditionally builds its shared libraries.
+         archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+       fi
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            archive_expsym_cmds=''
+        ;;
+      m68k)
+            archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            hardcode_libdir_flag_spec='-L$libdir'
+            hardcode_minus_L=yes
+        ;;
+      esac
+      ;;
+
+    bsdi[45]*)
+      export_dynamic_flag_spec=-rdynamic
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # When not using gcc, we currently assume that we are using
+      # Microsoft Visual C++.
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      hardcode_libdir_flag_spec=' '
+      allow_undefined_flag=unsupported
+      # Tell ltmain to make .lib files, not .a files.
+      libext=lib
+      # Tell ltmain to make .dll files, not .so files.
+      shrext_cmds=".dll"
+      # FIXME: Setting linknames here is a bad hack.
+      archive_cmds='$CC -o $lib $libobjs $compiler_flags `$ECHO "X$deplibs" | $Xsed -e '\''s/ -lc$//'\''` -link -dll~linknames='
+      # The linker will automatically build a .lib file if we build a DLL.
+      old_archive_from_new_cmds='true'
+      # FIXME: Should let the user specify the lib program.
+      old_archive_cmds='lib -OUT:$oldlib$oldobjs$old_deplibs'
+      fix_srcfile_path='`cygpath -w "$srcfile"`'
+      enable_shared_with_static_runtimes=yes
+      ;;
+
+    darwin* | rhapsody*)
+
+
+  archive_cmds_need_lc=no
+  hardcode_direct=no
+  hardcode_automatic=yes
+  hardcode_shlibpath_var=unsupported
+  whole_archive_flag_spec=''
+  link_all_deplibs=yes
+  allow_undefined_flag="$_lt_dar_allow_undefined"
+  case $cc_basename in
+     ifort*) _lt_dar_can_shared=yes ;;
+     *) _lt_dar_can_shared=$GCC ;;
+  esac
+  if test "$_lt_dar_can_shared" = "yes"; then
+    output_verbose_link_cmd=echo
+    archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}"
+    module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}"
+    archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}"
+    module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}"
+
+  else
+  ld_shlibs=no
+  fi
+
+      ;;
+
+    dgux*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_shlibpath_var=no
+      ;;
+
+    freebsd1*)
+      ld_shlibs=no
+      ;;
+
+    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
+    # support.  Future versions do this automatically, but an explicit c++rt0.o
+    # does not break anything, and helps significantly (at the cost of a little
+    # extra space).
+    freebsd2.2*)
+      archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
+    freebsd2*)
+      archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_direct=yes
+      hardcode_minus_L=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
+    freebsd* | dragonfly*)
+      archive_cmds='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    hpux9*)
+      if test "$GCC" = yes; then
+       archive_cmds='$RM $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+       archive_cmds='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      fi
+      hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+      hardcode_libdir_separator=:
+      hardcode_direct=yes
+
+      # hardcode_minus_L: Not really in the search PATH,
+      # but as the default location of the library.
+      hardcode_minus_L=yes
+      export_dynamic_flag_spec='${wl}-E'
+      ;;
+
+    hpux10*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+       archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      if test "$with_gnu_ld" = no; then
+       hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+       hardcode_libdir_flag_spec_ld='+b $libdir'
+       hardcode_libdir_separator=:
+       hardcode_direct=yes
+       hardcode_direct_absolute=yes
+       export_dynamic_flag_spec='${wl}-E'
+       # hardcode_minus_L: Not really in the search PATH,
+       # but as the default location of the library.
+       hardcode_minus_L=yes
+      fi
+      ;;
+
+    hpux11*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+       case $host_cpu in
+       hppa*64*)
+         archive_cmds='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       ia64*)
+         archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       *)
+         archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       esac
+      else
+       case $host_cpu in
+       hppa*64*)
+         archive_cmds='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       ia64*)
+         archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       *)
+         archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       esac
+      fi
+      if test "$with_gnu_ld" = no; then
+       hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+       hardcode_libdir_separator=:
+
+       case $host_cpu in
+       hppa*64*|ia64*)
+         hardcode_direct=no
+         hardcode_shlibpath_var=no
+         ;;
+       *)
+         hardcode_direct=yes
+         hardcode_direct_absolute=yes
+         export_dynamic_flag_spec='${wl}-E'
+
+         # hardcode_minus_L: Not really in the search PATH,
+         # but as the default location of the library.
+         hardcode_minus_L=yes
+         ;;
+       esac
+      fi
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      if test "$GCC" = yes; then
+       archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+       # Try to use the -exported_symbol ld option, if it does not
+       # work, assume that -exports_file does not work either and
+       # implicitly export all symbols.
+        save_LDFLAGS="$LDFLAGS"
+        LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null"
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int foo(void) {}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib'
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+        LDFLAGS="$save_LDFLAGS"
+      else
+       archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+       archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib'
+      fi
+      archive_cmds_need_lc='no'
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      inherit_rpath=yes
+      link_all_deplibs=yes
+      ;;
+
+    netbsd* | netbsdelf*-gnu)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+       archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
+      else
+       archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
+      fi
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    newsos6)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_direct=yes
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      hardcode_shlibpath_var=no
+      ;;
+
+    *nto* | *qnx*)
+      ;;
+
+    openbsd*)
+      if test -f /usr/libexec/ld.so; then
+       hardcode_direct=yes
+       hardcode_shlibpath_var=no
+       hardcode_direct_absolute=yes
+       if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+         archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+         archive_expsym_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
+         hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+         export_dynamic_flag_spec='${wl}-E'
+       else
+         case $host_os in
+          openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*)
+            archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+            hardcode_libdir_flag_spec='-R$libdir'
+            ;;
+          *)
+            archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+            hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+            ;;
+         esac
+       fi
+      else
+       ld_shlibs=no
+      fi
+      ;;
+
+    os2*)
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_minus_L=yes
+      allow_undefined_flag=unsupported
+      archive_cmds='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$ECHO DATA >> $output_objdir/$libname.def~$ECHO " SINGLE NONSHARED" >> $output_objdir/$libname.def~$ECHO EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
+      old_archive_from_new_cmds='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
+      ;;
+
+    osf3*)
+      if test "$GCC" = yes; then
+       allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
+       archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+       allow_undefined_flag=' -expect_unresolved \*'
+       archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+      fi
+      archive_cmds_need_lc='no'
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      ;;
+
+    osf4* | osf5*)     # as osf3* with the addition of -msym flag
+      if test "$GCC" = yes; then
+       allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
+       archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+       hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      else
+       allow_undefined_flag=' -expect_unresolved \*'
+       archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+       archive_expsym_cmds='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~
+       $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp'
+
+       # Both c and cxx compiler support -rpath directly
+       hardcode_libdir_flag_spec='-rpath $libdir'
+      fi
+      archive_cmds_need_lc='no'
+      hardcode_libdir_separator=:
+      ;;
+
+    solaris*)
+      no_undefined_flag=' -z defs'
+      if test "$GCC" = yes; then
+       wlarc='${wl}'
+       archive_cmds='$CC -shared ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+       archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+         $CC -shared ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+      else
+       case `$CC -V 2>&1` in
+       *"Compilers 5.0"*)
+         wlarc=''
+         archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
+         archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+         $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp'
+         ;;
+       *)
+         wlarc='${wl}'
+         archive_cmds='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags'
+         archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+         $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+         ;;
+       esac
+      fi
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_shlibpath_var=no
+      case $host_os in
+      solaris2.[0-5] | solaris2.[0-5].*) ;;
+      *)
+       # The compiler driver will combine and reorder linker options,
+       # but understands `-z linker_flag'.  GCC discards it without `$wl',
+       # but is careful enough not to reorder.
+       # Supported since Solaris 2.6 (maybe 2.5.1?)
+       if test "$GCC" = yes; then
+         whole_archive_flag_spec='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+       else
+         whole_archive_flag_spec='-z allextract$convenience -z defaultextract'
+       fi
+       ;;
+      esac
+      link_all_deplibs=yes
+      ;;
+
+    sunos4*)
+      if test "x$host_vendor" = xsequent; then
+       # Use $CC to link under sequent, because it throws in some extra .o
+       # files that make .init and .fini sections work.
+       archive_cmds='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_direct=yes
+      hardcode_minus_L=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    sysv4)
+      case $host_vendor in
+       sni)
+         archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+         hardcode_direct=yes # is this really true???
+       ;;
+       siemens)
+         ## LD is ld it makes a PLAMLIB
+         ## CC just makes a GrossModule.
+         archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags'
+         reload_cmds='$CC -r -o $output$reload_objs'
+         hardcode_direct=no
+        ;;
+       motorola)
+         archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+         hardcode_direct=no #Motorola manual says yes, but my tests say they lie
+       ;;
+      esac
+      runpath_var='LD_RUN_PATH'
+      hardcode_shlibpath_var=no
+      ;;
+
+    sysv4.3*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_shlibpath_var=no
+      export_dynamic_flag_spec='-Bexport'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+       archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+       hardcode_shlibpath_var=no
+       runpath_var=LD_RUN_PATH
+       hardcode_runpath_var=yes
+       ld_shlibs=yes
+      fi
+      ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*)
+      no_undefined_flag='${wl}-z,text'
+      archive_cmds_need_lc=no
+      hardcode_shlibpath_var=no
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+       archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6*)
+      # Note: We can NOT use -z defs as we might desire, because we do not
+      # link with -lc, and that would cause any symbols used from libc to
+      # always be unresolved, which means just about no library would
+      # ever link correctly.  If we're not using GNU ld we use -z text
+      # though, which does catch some bad symbols but isn't as heavy-handed
+      # as -z defs.
+      no_undefined_flag='${wl}-z,text'
+      allow_undefined_flag='${wl}-z,nodefs'
+      archive_cmds_need_lc=no
+      hardcode_shlibpath_var=no
+      hardcode_libdir_flag_spec='${wl}-R,$libdir'
+      hardcode_libdir_separator=':'
+      link_all_deplibs=yes
+      export_dynamic_flag_spec='${wl}-Bexport'
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+       archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    uts4*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_shlibpath_var=no
+      ;;
+
+    *)
+      ld_shlibs=no
+      ;;
+    esac
+
+    if test x$host_vendor = xsni; then
+      case $host in
+      sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
+       export_dynamic_flag_spec='${wl}-Blargedynsym'
+       ;;
+      esac
+    fi
+  fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5
+$as_echo "$ld_shlibs" >&6; }
+test "$ld_shlibs" = no && can_build_shared=no
+
+with_gnu_ld=$with_gnu_ld
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#
+# Do we need to explicitly link libc?
+#
+case "x$archive_cmds_need_lc" in
+x|xyes)
+  # Assume -lc should be added
+  archive_cmds_need_lc=yes
+
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
+    case $archive_cmds in
+    *'~'*)
+      # FIXME: we may have to deal with multi-command sequences.
+      ;;
+    '$CC '*)
+      # Test whether the compiler implicitly links with -lc since on some
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
+      # to ld, don't add -lc before -lgcc.
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5
+$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; }
+      $RM conftest*
+      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+      if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } 2>conftest.err; then
+        soname=conftest
+        lib=conftest
+        libobjs=conftest.$ac_objext
+        deplibs=
+        wl=$lt_prog_compiler_wl
+       pic_flag=$lt_prog_compiler_pic
+        compiler_flags=-v
+        linker_flags=-v
+        verstring=
+        output_objdir=.
+        libname=conftest
+        lt_save_allow_undefined_flag=$allow_undefined_flag
+        allow_undefined_flag=
+        if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5
+  (eval $archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+        then
+         archive_cmds_need_lc=no
+        else
+         archive_cmds_need_lc=yes
+        fi
+        allow_undefined_flag=$lt_save_allow_undefined_flag
+      else
+        cat conftest.err 1>&5
+      fi
+      $RM conftest*
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: $archive_cmds_need_lc" >&5
+$as_echo "$archive_cmds_need_lc" >&6; }
+      ;;
+    esac
+  fi
+  ;;
+esac
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5
+$as_echo_n "checking dynamic linker characteristics... " >&6; }
+
+if test "$GCC" = yes; then
+  case $host_os in
+    darwin*) lt_awk_arg="/^libraries:/,/LR/" ;;
+    *) lt_awk_arg="/^libraries:/" ;;
+  esac
+  lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+  if $ECHO "$lt_search_path_spec" | $GREP ';' >/dev/null ; then
+    # if the path contains ";" then we assume it to be the separator
+    # otherwise default to the standard path separator (i.e. ":") - it is
+    # assumed that no part of a normal pathname contains ";" but that should
+    # okay in the real world where ";" in dirpaths is itself problematic.
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e 's/;/ /g'`
+  else
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+  fi
+  # Ok, now we have the path, separated by spaces, we can step through it
+  # and add multilib dir if necessary.
+  lt_tmp_lt_search_path_spec=
+  lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null`
+  for lt_sys_path in $lt_search_path_spec; do
+    if test -d "$lt_sys_path/$lt_multi_os_dir"; then
+      lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir"
+    else
+      test -d "$lt_sys_path" && \
+       lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path"
+    fi
+  done
+  lt_search_path_spec=`$ECHO $lt_tmp_lt_search_path_spec | awk '
+BEGIN {RS=" "; FS="/|\n";} {
+  lt_foo="";
+  lt_count=0;
+  for (lt_i = NF; lt_i > 0; lt_i--) {
+    if ($lt_i != "" && $lt_i != ".") {
+      if ($lt_i == "..") {
+        lt_count++;
+      } else {
+        if (lt_count == 0) {
+          lt_foo="/" $lt_i lt_foo;
+        } else {
+          lt_count--;
+        }
+      }
+    }
+  }
+  if (lt_foo != "") { lt_freq[lt_foo]++; }
+  if (lt_freq[lt_foo] == 1) { print lt_foo; }
+}'`
+  sys_lib_search_path_spec=`$ECHO $lt_search_path_spec`
+else
+  sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
+fi
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+shrext_cmds=".so"
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+shlibpath_overrides_runpath=unknown
+version_type=none
+dynamic_linker="$host_os ld.so"
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
+need_lib_prefix=unknown
+hardcode_into_libs=no
+
+# when you set need_version to no, make sure it does not cause -set_version
+# flags to be left without arguments
+need_version=unknown
+
+case $host_os in
+aix3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
+  shlibpath_var=LIBPATH
+
+  # AIX 3 has no versioning support, so we append a major version to the name.
+  soname_spec='${libname}${release}${shared_ext}$major'
+  ;;
+
+aix[4-9]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  hardcode_into_libs=yes
+  if test "$host_cpu" = ia64; then
+    # AIX 5 supports IA64
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
+    shlibpath_var=LD_LIBRARY_PATH
+  else
+    # With GCC up to 2.95.x, collect2 would create an import file
+    # for dependence libraries.  The import file would start with
+    # the line `#! .'.  This would cause the generated library to
+    # depend on `.', always an invalid library.  This was fixed in
+    # development snapshots of GCC prior to 3.0.
+    case $host_os in
+      aix4 | aix4.[01] | aix4.[01].*)
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
+          echo ' yes '
+          echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then
+       :
+      else
+       can_build_shared=no
+      fi
+      ;;
+    esac
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
+    # soname into executable. Probably we can add versioning support to
+    # collect2, so additional links can be useful in future.
+    if test "$aix_use_runtimelinking" = yes; then
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
+      # instead of lib<name>.a to let people know that these are not
+      # typical AIX shared libraries.
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    else
+      # We preserve .a as extension for shared libraries through AIX4.2
+      # and later when we are not doing run time linking.
+      library_names_spec='${libname}${release}.a $libname.a'
+      soname_spec='${libname}${release}${shared_ext}$major'
+    fi
+    shlibpath_var=LIBPATH
+  fi
+  ;;
+
+amigaos*)
+  case $host_cpu in
+  powerpc)
+    # Since July 2007 AmigaOS4 officially supports .so libraries.
+    # When compiling the executable, add -use-dynld -Lsobjs: to the compileline.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    ;;
+  m68k)
+    library_names_spec='$libname.ixlibrary $libname.a'
+    # Create ${libname}_ixlibrary.a entries in /sys/libs.
+    finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$ECHO "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
+    ;;
+  esac
+  ;;
+
+beos*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  ;;
+
+bsdi[45]*)
+  version_type=linux
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
+  # the default ld.so.conf also contains /usr/contrib/lib and
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
+  # libtool to hard-code these into programs
+  ;;
+
+cygwin* | mingw* | pw32* | cegcc*)
+  version_type=windows
+  shrext_cmds=".dll"
+  need_version=no
+  need_lib_prefix=no
+
+  case $GCC,$host_os in
+  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
+    library_names_spec='$libname.dll.a'
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname~
+      chmod a+x \$dldir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
+      fi'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $RM \$dlpath'
+    shlibpath_overrides_runpath=yes
+
+    case $host_os in
+    cygwin*)
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib"
+      ;;
+    mingw* | cegcc*)
+      # MinGW DLLs use traditional 'lib' prefix
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec=`$CC -print-search-dirs | $GREP "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+      if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then
+        # It is most probably a Windows format PATH printed by
+        # mingw gcc, but we are running on Cygwin. Gcc prints its search
+        # path with ; separators, and with drive letters. We can handle the
+        # drive letters (cygwin fileutils understands them), so leave them,
+        # especially as we might pass files found there to a mingw objdump,
+        # which wouldn't understand a cygwinified path. Ahh.
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
+      else
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+      fi
+      ;;
+    pw32*)
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    esac
+    ;;
+
+  *)
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib'
+    ;;
+  esac
+  dynamic_linker='Win32 ld.exe'
+  # FIXME: first we should search . and the directory the executable is in
+  shlibpath_var=PATH
+  ;;
+
+darwin* | rhapsody*)
+  dynamic_linker="$host_os dyld"
+  version_type=darwin
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext'
+  soname_spec='${libname}${release}${major}$shared_ext'
+  shlibpath_overrides_runpath=yes
+  shlibpath_var=DYLD_LIBRARY_PATH
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
+
+  sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
+  ;;
+
+dgux*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+freebsd1*)
+  dynamic_linker=no
+  ;;
+
+freebsd* | dragonfly*)
+  # DragonFly does not have aout.  When/if they implement a new
+  # versioning mechanism, adjust this.
+  if test -x /usr/bin/objformat; then
+    objformat=`/usr/bin/objformat`
+  else
+    case $host_os in
+    freebsd[123]*) objformat=aout ;;
+    *) objformat=elf ;;
+    esac
+  fi
+  version_type=freebsd-$objformat
+  case $version_type in
+    freebsd-elf*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+      need_version=no
+      need_lib_prefix=no
+      ;;
+    freebsd-*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
+      need_version=yes
+      ;;
+  esac
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_os in
+  freebsd2*)
+    shlibpath_overrides_runpath=yes
+    ;;
+  freebsd3.[01]* | freebsdelf3.[01]*)
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  freebsd3.[2-9]* | freebsdelf3.[2-9]* | \
+  freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1)
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
+  *) # from 4.6 on, and DragonFly
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  esac
+  ;;
+
+gnu*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  ;;
+
+hpux9* | hpux10* | hpux11*)
+  # Give a soname corresponding to the major version so that dld.sl refuses to
+  # link against other versions.
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  case $host_cpu in
+  ia64*)
+    shrext_cmds='.so'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.so"
+    shlibpath_var=LD_LIBRARY_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    if test "X$HPUX_IA64_MODE" = X32; then
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
+    else
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
+    fi
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  hppa*64*)
+    shrext_cmds='.sl'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  *)
+    shrext_cmds='.sl'
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=SHLIB_PATH
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    ;;
+  esac
+  # HP-UX runs *really* slowly unless shared libraries are mode 555.
+  postinstall_cmds='chmod 555 $lib'
+  ;;
+
+interix[3-9]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $host_os in
+    nonstopux*) version_type=nonstopux ;;
+    *)
+       if test "$lt_cv_prog_gnu_ld" = yes; then
+               version_type=linux
+       else
+               version_type=irix
+       fi ;;
+  esac
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
+  case $host_os in
+  irix5* | nonstopux*)
+    libsuff= shlibsuff=
+    ;;
+  *)
+    case $LD in # libtool.m4 will add one of these switches to LD
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
+      libsuff= shlibsuff= libmagic=32-bit;;
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
+    *) libsuff= shlibsuff= libmagic=never-match;;
+    esac
+    ;;
+  esac
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
+  shlibpath_overrides_runpath=no
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+  hardcode_into_libs=yes
+  ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux*oldld* | linux*aout* | linux*coff*)
+  dynamic_linker=no
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  # Some binutils ld are patched to set DT_RUNPATH
+  save_LDFLAGS=$LDFLAGS
+  save_libdir=$libdir
+  eval "libdir=/foo; wl=\"$lt_prog_compiler_wl\"; \
+       LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec\""
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  if  ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then :
+  shlibpath_overrides_runpath=yes
+fi
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+  LDFLAGS=$save_LDFLAGS
+  libdir=$save_libdir
+
+  # This implies no fast_install, which is unacceptable.
+  # Some rework will be needed to allow for fast_install
+  # before this can be enabled.
+  hardcode_into_libs=yes
+
+  # Append ld.so.conf contents to the search path
+  if test -f /etc/ld.so.conf; then
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[      ]*hwcap[        ]/d;s/[:,      ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
+    sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra"
+  fi
+
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
+  # powerpc, because MkLinux only supported shared libraries with the
+  # GNU dynamic linker.  Since this was broken with cross compilers,
+  # most powerpc-linux boxes support dynamic linking these days and
+  # people can always --disable-shared, the test was removed, and we
+  # assume the GNU/Linux dynamic linker is in use.
+  dynamic_linker='GNU/Linux ld.so'
+  ;;
+
+netbsdelf*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='NetBSD ld.elf_so'
+  ;;
+
+netbsd*)
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+    dynamic_linker='NetBSD (a.out) ld.so'
+  else
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    dynamic_linker='NetBSD ld.elf_so'
+  fi
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  ;;
+
+newsos6)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+*nto* | *qnx*)
+  version_type=qnx
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='ldqnx.so'
+  ;;
+
+openbsd*)
+  version_type=sunos
+  sys_lib_dlsearch_path_spec="/usr/lib"
+  need_lib_prefix=no
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
+  case $host_os in
+    openbsd3.3 | openbsd3.3.*) need_version=yes ;;
+    *)                         need_version=no  ;;
+  esac
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    case $host_os in
+      openbsd2.[89] | openbsd2.[89].*)
+       shlibpath_overrides_runpath=no
+       ;;
+      *)
+       shlibpath_overrides_runpath=yes
+       ;;
+      esac
+  else
+    shlibpath_overrides_runpath=yes
+  fi
+  ;;
+
+os2*)
+  libname_spec='$name'
+  shrext_cmds=".dll"
+  need_lib_prefix=no
+  library_names_spec='$libname${shared_ext} $libname.a'
+  dynamic_linker='OS/2 ld.exe'
+  shlibpath_var=LIBPATH
+  ;;
+
+osf3* | osf4* | osf5*)
+  version_type=osf
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
+  ;;
+
+rdos*)
+  dynamic_linker=no
+  ;;
+
+solaris*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  # ldd complains unless libraries are executable
+  postinstall_cmds='chmod +x $lib'
+  ;;
+
+sunos4*)
+  version_type=sunos
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  if test "$with_gnu_ld" = yes; then
+    need_lib_prefix=no
+  fi
+  need_version=yes
+  ;;
+
+sysv4 | sysv4.3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_vendor in
+    sni)
+      shlibpath_overrides_runpath=no
+      need_lib_prefix=no
+      runpath_var=LD_RUN_PATH
+      ;;
+    siemens)
+      need_lib_prefix=no
+      ;;
+    motorola)
+      need_lib_prefix=no
+      need_version=no
+      shlibpath_overrides_runpath=no
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
+      ;;
+  esac
+  ;;
+
+sysv4*MP*)
+  if test -d /usr/nec ;then
+    version_type=linux
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
+    soname_spec='$libname${shared_ext}.$major'
+    shlibpath_var=LD_LIBRARY_PATH
+  fi
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  version_type=freebsd-elf
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  if test "$with_gnu_ld" = yes; then
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
+  else
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
+    case $host_os in
+      sco3.2v5*)
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
+       ;;
+    esac
+  fi
+  sys_lib_dlsearch_path_spec='/usr/lib'
+  ;;
+
+tpf*)
+  # TPF is a cross-target only.  Preferred cross-host = GNU/Linux.
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+uts4*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+*)
+  dynamic_linker=no
+  ;;
+esac
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5
+$as_echo "$dynamic_linker" >&6; }
+test "$dynamic_linker" = no && can_build_shared=no
+
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
+if test "$GCC" = yes; then
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+fi
+
+if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then
+  sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec"
+fi
+if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then
+  sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec"
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5
+$as_echo_n "checking how to hardcode library paths into programs... " >&6; }
+hardcode_action=
+if test -n "$hardcode_libdir_flag_spec" ||
+   test -n "$runpath_var" ||
+   test "X$hardcode_automatic" = "Xyes" ; then
+
+  # We can hardcode non-existent directories.
+  if test "$hardcode_direct" != no &&
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
+     # have to relink, otherwise we might link with an installed library
+     # when we should be linking with a yet-to-be-installed one
+     ## test "$_LT_TAGVAR(hardcode_shlibpath_var, )" != no &&
+     test "$hardcode_minus_L" != no; then
+    # Linking always hardcodes the temporary library directory.
+    hardcode_action=relink
+  else
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
+    hardcode_action=immediate
+  fi
+else
+  # We cannot hardcode anything, or else we can only hardcode existing
+  # directories.
+  hardcode_action=unsupported
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5
+$as_echo "$hardcode_action" >&6; }
+
+if test "$hardcode_action" = relink ||
+   test "$inherit_rpath" = yes; then
+  # Fast installation is not supported
+  enable_fast_install=no
+elif test "$shlibpath_overrides_runpath" = yes ||
+     test "$enable_shared" = no; then
+  # Fast installation is not necessary
+  enable_fast_install=needless
+fi
+
+
+
+
+
+
+  if test "x$enable_dlopen" != xyes; then
+  enable_dlopen=unknown
+  enable_dlopen_self=unknown
+  enable_dlopen_self_static=unknown
+else
+  lt_cv_dlopen=no
+  lt_cv_dlopen_libs=
+
+  case $host_os in
+  beos*)
+    lt_cv_dlopen="load_add_on"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ;;
+
+  mingw* | pw32* | cegcc*)
+    lt_cv_dlopen="LoadLibrary"
+    lt_cv_dlopen_libs=
+    ;;
+
+  cygwin*)
+    lt_cv_dlopen="dlopen"
+    lt_cv_dlopen_libs=
+    ;;
+
+  darwin*)
+  # if libdl is installed we need to link against it
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
+$as_echo_n "checking for dlopen in -ldl... " >&6; }
+if test "${ac_cv_lib_dl_dlopen+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dl_dlopen=yes
+else
+  ac_cv_lib_dl_dlopen=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
+$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
+if test "x$ac_cv_lib_dl_dlopen" = x""yes; then :
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
+else
+
+    lt_cv_dlopen="dyld"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+
+fi
+
+    ;;
+
+  *)
+    ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load"
+if test "x$ac_cv_func_shl_load" = x""yes; then :
+  lt_cv_dlopen="shl_load"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5
+$as_echo_n "checking for shl_load in -ldld... " >&6; }
+if test "${ac_cv_lib_dld_shl_load+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldld  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char shl_load ();
+int
+main ()
+{
+return shl_load ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dld_shl_load=yes
+else
+  ac_cv_lib_dld_shl_load=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5
+$as_echo "$ac_cv_lib_dld_shl_load" >&6; }
+if test "x$ac_cv_lib_dld_shl_load" = x""yes; then :
+  lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"
+else
+  ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen"
+if test "x$ac_cv_func_dlopen" = x""yes; then :
+  lt_cv_dlopen="dlopen"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
+$as_echo_n "checking for dlopen in -ldl... " >&6; }
+if test "${ac_cv_lib_dl_dlopen+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dl_dlopen=yes
+else
+  ac_cv_lib_dl_dlopen=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
+$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
+if test "x$ac_cv_lib_dl_dlopen" = x""yes; then :
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5
+$as_echo_n "checking for dlopen in -lsvld... " >&6; }
+if test "${ac_cv_lib_svld_dlopen+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lsvld  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_svld_dlopen=yes
+else
+  ac_cv_lib_svld_dlopen=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5
+$as_echo "$ac_cv_lib_svld_dlopen" >&6; }
+if test "x$ac_cv_lib_svld_dlopen" = x""yes; then :
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5
+$as_echo_n "checking for dld_link in -ldld... " >&6; }
+if test "${ac_cv_lib_dld_dld_link+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldld  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dld_link ();
+int
+main ()
+{
+return dld_link ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dld_dld_link=yes
+else
+  ac_cv_lib_dld_dld_link=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5
+$as_echo "$ac_cv_lib_dld_dld_link" >&6; }
+if test "x$ac_cv_lib_dld_dld_link" = x""yes; then :
+  lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"
+fi
+
+
+fi
+
+
+fi
+
+
+fi
+
+
+fi
+
+
+fi
+
+    ;;
+  esac
+
+  if test "x$lt_cv_dlopen" != xno; then
+    enable_dlopen=yes
+  else
+    enable_dlopen=no
+  fi
+
+  case $lt_cv_dlopen in
+  dlopen)
+    save_CPPFLAGS="$CPPFLAGS"
+    test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
+
+    save_LDFLAGS="$LDFLAGS"
+    wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
+
+    save_LIBS="$LIBS"
+    LIBS="$lt_cv_dlopen_libs $LIBS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5
+$as_echo_n "checking whether a program can dlopen itself... " >&6; }
+if test "${lt_cv_dlopen_self+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+         if test "$cross_compiling" = yes; then :
+  lt_cv_dlopen_self=cross
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<_LT_EOF
+#line 10423 "configure"
+#include "confdefs.h"
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL          RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL                DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL                0
+#  endif
+#endif
+
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW           RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW         DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW       RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW     DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW     0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+void fnord() { int i=42;}
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
+
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
+
+  return status;
+}
+_LT_EOF
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&5 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) lt_cv_dlopen_self=yes ;;
+      x$lt_dlneed_uscore) lt_cv_dlopen_self=yes ;;
+      x$lt_dlunknown|x*) lt_cv_dlopen_self=no ;;
+    esac
+  else :
+    # compilation failed
+    lt_cv_dlopen_self=no
+  fi
+fi
+rm -fr conftest*
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5
+$as_echo "$lt_cv_dlopen_self" >&6; }
+
+    if test "x$lt_cv_dlopen_self" = xyes; then
+      wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5
+$as_echo_n "checking whether a statically linked program can dlopen itself... " >&6; }
+if test "${lt_cv_dlopen_self_static+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+         if test "$cross_compiling" = yes; then :
+  lt_cv_dlopen_self_static=cross
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<_LT_EOF
+#line 10519 "configure"
+#include "confdefs.h"
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL          RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL                DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL                0
+#  endif
+#endif
+
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW           RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW         DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW       RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW     DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW     0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+void fnord() { int i=42;}
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
+
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
+
+  return status;
+}
+_LT_EOF
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&5 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) lt_cv_dlopen_self_static=yes ;;
+      x$lt_dlneed_uscore) lt_cv_dlopen_self_static=yes ;;
+      x$lt_dlunknown|x*) lt_cv_dlopen_self_static=no ;;
+    esac
+  else :
+    # compilation failed
+    lt_cv_dlopen_self_static=no
+  fi
+fi
+rm -fr conftest*
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5
+$as_echo "$lt_cv_dlopen_self_static" >&6; }
+    fi
+
+    CPPFLAGS="$save_CPPFLAGS"
+    LDFLAGS="$save_LDFLAGS"
+    LIBS="$save_LIBS"
+    ;;
+  esac
+
+  case $lt_cv_dlopen_self in
+  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
+  *) enable_dlopen_self=unknown ;;
+  esac
+
+  case $lt_cv_dlopen_self_static in
+  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
+  *) enable_dlopen_self_static=unknown ;;
+  esac
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+striplib=
+old_striplib=
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5
+$as_echo_n "checking whether stripping libraries is possible... " >&6; }
+if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then
+  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
+  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+# FIXME - insert some real tests, host_os isn't really good enough
+  case $host_os in
+  darwin*)
+    if test -n "$STRIP" ; then
+      striplib="$STRIP -x"
+      old_striplib="$STRIP -S"
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+    else
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+    fi
+    ;;
+  *)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+    ;;
+  esac
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+  # Report which library types will actually be built
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5
+$as_echo_n "checking if libtool supports shared libraries... " >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5
+$as_echo "$can_build_shared" >&6; }
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5
+$as_echo_n "checking whether to build shared libraries... " >&6; }
+  test "$can_build_shared" = "no" && enable_shared=no
+
+  # On AIX, shared libraries and static libraries use the same namespace, and
+  # are all built from PIC.
+  case $host_os in
+  aix3*)
+    test "$enable_shared" = yes && enable_static=no
+    if test -n "$RANLIB"; then
+      archive_cmds="$archive_cmds~\$RANLIB \$lib"
+      postinstall_cmds='$RANLIB $lib'
+    fi
+    ;;
+
+  aix[4-9]*)
+    if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+      test "$enable_shared" = yes && enable_static=no
+    fi
+    ;;
+  esac
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5
+$as_echo "$enable_shared" >&6; }
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5
+$as_echo_n "checking whether to build static libraries... " >&6; }
+  # Make sure either enable_shared or enable_static is yes.
+  test "$enable_shared" = yes || enable_static=yes
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5
+$as_echo "$enable_static" >&6; }
+
+
+
+
+fi
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+CC="$lt_save_CC"
+
+
+
+
+
+
+
+
+
+
+
+
+
+        ac_config_commands="$ac_config_commands libtool"
+
+
+
+
+# Only expand once:
+
+
+ac_config_headers="$ac_config_headers src/config.h"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5
+$as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; }
+    # Check whether --enable-maintainer-mode was given.
+if test "${enable_maintainer_mode+set}" = set; then :
+  enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval
+else
+  USE_MAINTAINER_MODE=no
+fi
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5
+$as_echo "$USE_MAINTAINER_MODE" >&6; }
+   if test $USE_MAINTAINER_MODE = yes; then
+  MAINTAINER_MODE_TRUE=
+  MAINTAINER_MODE_FALSE='#'
+else
+  MAINTAINER_MODE_TRUE='#'
+  MAINTAINER_MODE_FALSE=
+fi
+
+  MAINT=$MAINTAINER_MODE_TRUE
+
+
+
+API_VERSION=4:0:4
+
+
+# The earliest version that this release has binary compatibility
+# with.  This is used for module locations.
+M17N_BINARY_VERSION=1.0
+
+M17N_MODULE_DIR="m17n/$M17N_BINARY_VERSION"
+
+
+
+
+        MKINSTALLDIRS=
+  if test -n "$ac_aux_dir"; then
+    case "$ac_aux_dir" in
+      /*) MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs" ;;
+      *) MKINSTALLDIRS="\$(top_builddir)/$ac_aux_dir/mkinstalldirs" ;;
+    esac
+  fi
+  if test -z "$MKINSTALLDIRS"; then
+    MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
+  fi
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether NLS is requested" >&5
+$as_echo_n "checking whether NLS is requested... " >&6; }
+    # Check whether --enable-nls was given.
+if test "${enable_nls+set}" = set; then :
+  enableval=$enable_nls; USE_NLS=$enableval
+else
+  USE_NLS=yes
+fi
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_NLS" >&5
+$as_echo "$USE_NLS" >&6; }
+
+
+
+
+
+
+# Prepare PATH_SEPARATOR.
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+
+# Find out how to test for executable files. Don't use a zero-byte file,
+# as systems may use methods other than mode bits to determine executability.
+cat >conf$$.file <<_ASEOF
+#! /bin/sh
+exit 0
+_ASEOF
+chmod +x conf$$.file
+if test -x conf$$.file >/dev/null 2>&1; then
+  ac_executable_p="test -x"
+else
+  ac_executable_p="test -f"
+fi
+rm -f conf$$.file
+
+# Extract the first word of "msgfmt", so it can be a program name with args.
+set dummy msgfmt; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_MSGFMT+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case "$MSGFMT" in
+  [\\/]* | ?:[\\/]*)
+    ac_cv_path_MSGFMT="$MSGFMT" # Let the user override the test with a path.
+    ;;
+  *)
+    ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in $PATH; do
+      IFS="$ac_save_IFS"
+      test -z "$ac_dir" && ac_dir=.
+      for ac_exec_ext in '' $ac_executable_extensions; do
+        if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then
+          echo "$as_me: trying $ac_dir/$ac_word..." >&5
+          if $ac_dir/$ac_word --statistics /dev/null >&5 2>&1 &&
+     (if $ac_dir/$ac_word --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then
+            ac_cv_path_MSGFMT="$ac_dir/$ac_word$ac_exec_ext"
+            break 2
+          fi
+        fi
+      done
+    done
+    IFS="$ac_save_IFS"
+  test -z "$ac_cv_path_MSGFMT" && ac_cv_path_MSGFMT=":"
+    ;;
+esac
+fi
+MSGFMT="$ac_cv_path_MSGFMT"
+if test "$MSGFMT" != ":"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MSGFMT" >&5
+$as_echo "$MSGFMT" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  # Extract the first word of "gmsgfmt", so it can be a program name with args.
+set dummy gmsgfmt; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_GMSGFMT+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $GMSGFMT in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_GMSGFMT="$GMSGFMT" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_path_GMSGFMT="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_path_GMSGFMT" && ac_cv_path_GMSGFMT="$MSGFMT"
+  ;;
+esac
+fi
+GMSGFMT=$ac_cv_path_GMSGFMT
+if test -n "$GMSGFMT"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GMSGFMT" >&5
+$as_echo "$GMSGFMT" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
+
+# Prepare PATH_SEPARATOR.
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+
+# Find out how to test for executable files. Don't use a zero-byte file,
+# as systems may use methods other than mode bits to determine executability.
+cat >conf$$.file <<_ASEOF
+#! /bin/sh
+exit 0
+_ASEOF
+chmod +x conf$$.file
+if test -x conf$$.file >/dev/null 2>&1; then
+  ac_executable_p="test -x"
+else
+  ac_executable_p="test -f"
+fi
+rm -f conf$$.file
+
+# Extract the first word of "xgettext", so it can be a program name with args.
+set dummy xgettext; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_XGETTEXT+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case "$XGETTEXT" in
+  [\\/]* | ?:[\\/]*)
+    ac_cv_path_XGETTEXT="$XGETTEXT" # Let the user override the test with a path.
+    ;;
+  *)
+    ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in $PATH; do
+      IFS="$ac_save_IFS"
+      test -z "$ac_dir" && ac_dir=.
+      for ac_exec_ext in '' $ac_executable_extensions; do
+        if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then
+          echo "$as_me: trying $ac_dir/$ac_word..." >&5
+          if $ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >&5 2>&1 &&
+     (if $ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then
+            ac_cv_path_XGETTEXT="$ac_dir/$ac_word$ac_exec_ext"
+            break 2
+          fi
+        fi
+      done
+    done
+    IFS="$ac_save_IFS"
+  test -z "$ac_cv_path_XGETTEXT" && ac_cv_path_XGETTEXT=":"
+    ;;
+esac
+fi
+XGETTEXT="$ac_cv_path_XGETTEXT"
+if test "$XGETTEXT" != ":"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XGETTEXT" >&5
+$as_echo "$XGETTEXT" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+    rm -f messages.po
+
+
+# Prepare PATH_SEPARATOR.
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+
+# Find out how to test for executable files. Don't use a zero-byte file,
+# as systems may use methods other than mode bits to determine executability.
+cat >conf$$.file <<_ASEOF
+#! /bin/sh
+exit 0
+_ASEOF
+chmod +x conf$$.file
+if test -x conf$$.file >/dev/null 2>&1; then
+  ac_executable_p="test -x"
+else
+  ac_executable_p="test -f"
+fi
+rm -f conf$$.file
+
+# Extract the first word of "msgmerge", so it can be a program name with args.
+set dummy msgmerge; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_MSGMERGE+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case "$MSGMERGE" in
+  [\\/]* | ?:[\\/]*)
+    ac_cv_path_MSGMERGE="$MSGMERGE" # Let the user override the test with a path.
+    ;;
+  *)
+    ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in $PATH; do
+      IFS="$ac_save_IFS"
+      test -z "$ac_dir" && ac_dir=.
+      for ac_exec_ext in '' $ac_executable_extensions; do
+        if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then
+          echo "$as_me: trying $ac_dir/$ac_word..." >&5
+          if $ac_dir/$ac_word --update -q /dev/null /dev/null >&5 2>&1; then
+            ac_cv_path_MSGMERGE="$ac_dir/$ac_word$ac_exec_ext"
+            break 2
+          fi
+        fi
+      done
+    done
+    IFS="$ac_save_IFS"
+  test -z "$ac_cv_path_MSGMERGE" && ac_cv_path_MSGMERGE=":"
+    ;;
+esac
+fi
+MSGMERGE="$ac_cv_path_MSGMERGE"
+if test "$MSGMERGE" != ":"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MSGMERGE" >&5
+$as_echo "$MSGMERGE" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+      if test "$GMSGFMT" != ":"; then
+            if $GMSGFMT --statistics /dev/null >/dev/null 2>&1 &&
+       (if $GMSGFMT --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then
+      : ;
+    else
+      GMSGFMT=`echo "$GMSGFMT" | sed -e 's,^.*/,,'`
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: found $GMSGFMT program is not GNU msgfmt; ignore it" >&5
+$as_echo "found $GMSGFMT program is not GNU msgfmt; ignore it" >&6; }
+      GMSGFMT=":"
+    fi
+  fi
+
+      if test "$XGETTEXT" != ":"; then
+            if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >/dev/null 2>&1 &&
+       (if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then
+      : ;
+    else
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: found xgettext program is not GNU xgettext; ignore it" >&5
+$as_echo "found xgettext program is not GNU xgettext; ignore it" >&6; }
+      XGETTEXT=":"
+    fi
+        rm -f messages.po
+  fi
+
+  ac_config_commands="$ac_config_commands default-1"
+
+
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C Library 2 or newer" >&5
+$as_echo_n "checking whether we are using the GNU C Library 2 or newer... " >&6; }
+if test "${ac_cv_gnu_library_2+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <features.h>
+#ifdef __GNU_LIBRARY__
+ #if (__GLIBC__ >= 2)
+  Lucky GNU user
+ #endif
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "Lucky GNU user" >/dev/null 2>&1; then :
+  ac_cv_gnu_library_2=yes
+else
+  ac_cv_gnu_library_2=no
+fi
+rm -f conftest*
+
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_gnu_library_2" >&5
+$as_echo "$ac_cv_gnu_library_2" >&6; }
+
+    GLIBC2="$ac_cv_gnu_library_2"
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_RANLIB+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$RANLIB"; then
+  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
+$as_echo "$RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_RANLIB"; then
+  ac_ct_RANLIB=$RANLIB
+  # Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_RANLIB"; then
+  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_RANLIB="ranlib"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
+if test -n "$ac_ct_RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
+$as_echo "$ac_ct_RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_RANLIB" = x; then
+    RANLIB=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    RANLIB=$ac_ct_RANLIB
+  fi
+else
+  RANLIB="$ac_cv_prog_RANLIB"
+fi
+
+
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for strerror in -lcposix" >&5
+$as_echo_n "checking for strerror in -lcposix... " >&6; }
+if test "${ac_cv_lib_cposix_strerror+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lcposix  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char strerror ();
+int
+main ()
+{
+return strerror ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_cposix_strerror=yes
+else
+  ac_cv_lib_cposix_strerror=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_cposix_strerror" >&5
+$as_echo "$ac_cv_lib_cposix_strerror" >&6; }
+if test "x$ac_cv_lib_cposix_strerror" = x""yes; then :
+  LIBS="$LIBS -lcposix"
+fi
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5
+$as_echo_n "checking for an ANSI C-conforming const... " >&6; }
+if test "${ac_cv_c_const+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+/* FIXME: Include the comments suggested by Paul. */
+#ifndef __cplusplus
+  /* Ultrix mips cc rejects this.  */
+  typedef int charset[2];
+  const charset cs;
+  /* SunOS 4.1.1 cc rejects this.  */
+  char const *const *pcpcc;
+  char **ppc;
+  /* NEC SVR4.0.2 mips cc rejects this.  */
+  struct point {int x, y;};
+  static struct point const zero = {0,0};
+  /* AIX XL C 1.02.0.0 rejects this.
+     It does not let you subtract one const X* pointer from another in
+     an arm of an if-expression whose if-part is not a constant
+     expression */
+  const char *g = "string";
+  pcpcc = &g + (g ? g-g : 0);
+  /* HPUX 7.0 cc rejects these. */
+  ++pcpcc;
+  ppc = (char**) pcpcc;
+  pcpcc = (char const *const *) ppc;
+  { /* SCO 3.2v4 cc rejects this.  */
+    char *t;
+    char const *s = 0 ? (char *) 0 : (char const *) 0;
+
+    *t++ = 0;
+    if (s) return 0;
+  }
+  { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
+    int x[] = {25, 17};
+    const int *foo = &x[0];
+    ++foo;
+  }
+  { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
+    typedef const int *iptr;
+    iptr p = 0;
+    ++p;
+  }
+  { /* AIX XL C 1.02.0.0 rejects this saying
+       "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
+    struct s { int j; const int *ap[3]; };
+    struct s *b; b->j = 5;
+  }
+  { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
+    const int foo = 10;
+    if (!foo) return 0;
+  }
+  return !cs[0] && !zero.x;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_c_const=yes
+else
+  ac_cv_c_const=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5
+$as_echo "$ac_cv_c_const" >&6; }
+if test $ac_cv_c_const = no; then
+
+$as_echo "#define const /**/" >>confdefs.h
+
+fi
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for signed" >&5
+$as_echo_n "checking for signed... " >&6; }
+if test "${bh_cv_c_signed+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+signed char x;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  bh_cv_c_signed=yes
+else
+  bh_cv_c_signed=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $bh_cv_c_signed" >&5
+$as_echo "$bh_cv_c_signed" >&6; }
+  if test $bh_cv_c_signed = no; then
+
+$as_echo "#define signed /**/" >>confdefs.h
+
+  fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline" >&5
+$as_echo_n "checking for inline... " >&6; }
+if test "${ac_cv_c_inline+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_c_inline=no
+for ac_kw in inline __inline__ __inline; do
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifndef __cplusplus
+typedef int foo_t;
+static $ac_kw foo_t static_foo () {return 0; }
+$ac_kw foo_t foo () {return 0; }
+#endif
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_c_inline=$ac_kw
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  test "$ac_cv_c_inline" != no && break
+done
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5
+$as_echo "$ac_cv_c_inline" >&6; }
+
+case $ac_cv_c_inline in
+  inline | yes) ;;
+  *)
+    case $ac_cv_c_inline in
+      no) ac_val=;;
+      *) ac_val=$ac_cv_c_inline;;
+    esac
+    cat >>confdefs.h <<_ACEOF
+#ifndef __cplusplus
+#define inline $ac_val
+#endif
+_ACEOF
+    ;;
+esac
+
+ac_fn_c_check_type "$LINENO" "off_t" "ac_cv_type_off_t" "$ac_includes_default"
+if test "x$ac_cv_type_off_t" = x""yes; then :
+
+else
+
+cat >>confdefs.h <<_ACEOF
+#define off_t long int
+_ACEOF
+
+fi
+
+ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default"
+if test "x$ac_cv_type_size_t" = x""yes; then :
+
+else
+
+cat >>confdefs.h <<_ACEOF
+#define size_t unsigned int
+_ACEOF
+
+fi
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for long long" >&5
+$as_echo_n "checking for long long... " >&6; }
+if test "${ac_cv_type_long_long+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+long long ll = 1LL; int i = 63;
+int
+main ()
+{
+long long llmax = (long long) -1;
+     return ll << i | ll >> i | llmax / ll | llmax % ll;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_type_long_long=yes
+else
+  ac_cv_type_long_long=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_long_long" >&5
+$as_echo "$ac_cv_type_long_long" >&6; }
+  if test $ac_cv_type_long_long = yes; then
+
+$as_echo "#define HAVE_LONG_LONG 1" >>confdefs.h
+
+  fi
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for long double" >&5
+$as_echo_n "checking for long double... " >&6; }
+if test "${gt_cv_c_long_double+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "$GCC" = yes; then
+       gt_cv_c_long_double=yes
+     else
+       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+         /* The Stardent Vistra knows sizeof(long double), but does not support it.  */
+         long double foo = 0.0;
+         /* On Ultrix 4.3 cc, long double is 4 and double is 8.  */
+         int array [2*(sizeof(long double) >= sizeof(double)) - 1];
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gt_cv_c_long_double=yes
+else
+  gt_cv_c_long_double=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+     fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_c_long_double" >&5
+$as_echo "$gt_cv_c_long_double" >&6; }
+  if test $gt_cv_c_long_double = yes; then
+
+$as_echo "#define HAVE_LONG_DOUBLE 1" >>confdefs.h
+
+  fi
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for wchar_t" >&5
+$as_echo_n "checking for wchar_t... " >&6; }
+if test "${gt_cv_c_wchar_t+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stddef.h>
+       wchar_t foo = (wchar_t)'\0';
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gt_cv_c_wchar_t=yes
+else
+  gt_cv_c_wchar_t=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_c_wchar_t" >&5
+$as_echo "$gt_cv_c_wchar_t" >&6; }
+  if test $gt_cv_c_wchar_t = yes; then
+
+$as_echo "#define HAVE_WCHAR_T 1" >>confdefs.h
+
+  fi
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for wint_t" >&5
+$as_echo_n "checking for wint_t... " >&6; }
+if test "${gt_cv_c_wint_t+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <wchar.h>
+       wint_t foo = (wchar_t)'\0';
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gt_cv_c_wint_t=yes
+else
+  gt_cv_c_wint_t=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_c_wint_t" >&5
+$as_echo "$gt_cv_c_wint_t" >&6; }
+  if test $gt_cv_c_wint_t = yes; then
+
+$as_echo "#define HAVE_WINT_T 1" >>confdefs.h
+
+  fi
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inttypes.h" >&5
+$as_echo_n "checking for inttypes.h... " >&6; }
+if test "${gl_cv_header_inttypes_h+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <inttypes.h>
+int
+main ()
+{
+uintmax_t i = (uintmax_t) -1;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gl_cv_header_inttypes_h=yes
+else
+  gl_cv_header_inttypes_h=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_header_inttypes_h" >&5
+$as_echo "$gl_cv_header_inttypes_h" >&6; }
+  if test $gl_cv_header_inttypes_h = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_INTTYPES_H_WITH_UINTMAX 1
+_ACEOF
+
+  fi
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdint.h" >&5
+$as_echo_n "checking for stdint.h... " >&6; }
+if test "${gl_cv_header_stdint_h+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <stdint.h>
+int
+main ()
+{
+uintmax_t i = (uintmax_t) -1;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gl_cv_header_stdint_h=yes
+else
+  gl_cv_header_stdint_h=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_header_stdint_h" >&5
+$as_echo "$gl_cv_header_stdint_h" >&6; }
+  if test $gl_cv_header_stdint_h = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STDINT_H_WITH_UINTMAX 1
+_ACEOF
+
+  fi
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for intmax_t" >&5
+$as_echo_n "checking for intmax_t... " >&6; }
+if test "${gt_cv_c_intmax_t+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <stddef.h>
+#include <stdlib.h>
+#if HAVE_STDINT_H_WITH_UINTMAX
+#include <stdint.h>
+#endif
+#if HAVE_INTTYPES_H_WITH_UINTMAX
+#include <inttypes.h>
+#endif
+
+int
+main ()
+{
+intmax_t x = -1;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gt_cv_c_intmax_t=yes
+else
+  gt_cv_c_intmax_t=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_c_intmax_t" >&5
+$as_echo "$gt_cv_c_intmax_t" >&6; }
+  if test $gt_cv_c_intmax_t = yes; then
+
+$as_echo "#define HAVE_INTMAX_T 1" >>confdefs.h
+
+  fi
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether printf() supports POSIX/XSI format strings" >&5
+$as_echo_n "checking whether printf() supports POSIX/XSI format strings... " >&6; }
+if test "${gt_cv_func_printf_posix+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+
+      if test "$cross_compiling" = yes; then :
+
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#if defined __NetBSD__ || defined _MSC_VER || defined __MINGW32__ || defined __CYGWIN__
+  notposix
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "notposix" >/dev/null 2>&1; then :
+  gt_cv_func_printf_posix="guessing no"
+else
+  gt_cv_func_printf_posix="guessing yes"
+fi
+rm -f conftest*
+
+
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <stdio.h>
+#include <string.h>
+/* The string "%2$d %1$d", with dollar characters protected from the shell's
+   dollar expansion (possibly an autoconf bug).  */
+static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
+static char buf[100];
+int main ()
+{
+  sprintf (buf, format, 33, 55);
+  return (strcmp (buf, "55 33") != 0);
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  gt_cv_func_printf_posix=yes
+else
+  gt_cv_func_printf_posix=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_printf_posix" >&5
+$as_echo "$gt_cv_func_printf_posix" >&6; }
+  case $gt_cv_func_printf_posix in
+    *yes)
+
+$as_echo "#define HAVE_POSIX_PRINTF 1" >>confdefs.h
+
+      ;;
+  esac
+
+# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
+# for constant arguments.  Useless!
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working alloca.h" >&5
+$as_echo_n "checking for working alloca.h... " >&6; }
+if test "${ac_cv_working_alloca_h+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <alloca.h>
+int
+main ()
+{
+char *p = (char *) alloca (2 * sizeof (int));
+                         if (p) return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_working_alloca_h=yes
+else
+  ac_cv_working_alloca_h=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_working_alloca_h" >&5
+$as_echo "$ac_cv_working_alloca_h" >&6; }
+if test $ac_cv_working_alloca_h = yes; then
+
+$as_echo "#define HAVE_ALLOCA_H 1" >>confdefs.h
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for alloca" >&5
+$as_echo_n "checking for alloca... " >&6; }
+if test "${ac_cv_func_alloca_works+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __GNUC__
+# define alloca __builtin_alloca
+#else
+# ifdef _MSC_VER
+#  include <malloc.h>
+#  define alloca _alloca
+# else
+#  ifdef HAVE_ALLOCA_H
+#   include <alloca.h>
+#  else
+#   ifdef _AIX
+ #pragma alloca
+#   else
+#    ifndef alloca /* predefined by HP cc +Olibcalls */
+char *alloca ();
+#    endif
+#   endif
+#  endif
+# endif
+#endif
+
+int
+main ()
+{
+char *p = (char *) alloca (1);
+                                   if (p) return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_func_alloca_works=yes
+else
+  ac_cv_func_alloca_works=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_alloca_works" >&5
+$as_echo "$ac_cv_func_alloca_works" >&6; }
+
+if test $ac_cv_func_alloca_works = yes; then
+
+$as_echo "#define HAVE_ALLOCA 1" >>confdefs.h
+
+else
+  # The SVR3 libPW and SVR4 libucb both contain incompatible functions
+# that cause trouble.  Some versions do not even contain alloca or
+# contain a buggy version.  If you still want to use their alloca,
+# use ar to extract alloca.o from them instead of compiling alloca.c.
+
+ALLOCA=\${LIBOBJDIR}alloca.$ac_objext
+
+$as_echo "#define C_ALLOCA 1" >>confdefs.h
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether \`alloca.c' needs Cray hooks" >&5
+$as_echo_n "checking whether \`alloca.c' needs Cray hooks... " >&6; }
+if test "${ac_cv_os_cray+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#if defined CRAY && ! defined CRAY2
+webecray
+#else
+wenotbecray
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "webecray" >/dev/null 2>&1; then :
+  ac_cv_os_cray=yes
+else
+  ac_cv_os_cray=no
+fi
+rm -f conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_os_cray" >&5
+$as_echo "$ac_cv_os_cray" >&6; }
+if test $ac_cv_os_cray = yes; then
+  for ac_func in _getb67 GETB67 getb67; do
+    as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+eval as_val=\$$as_ac_var
+   if test "x$as_val" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define CRAY_STACKSEG_END $ac_func
+_ACEOF
+
+    break
+fi
+
+  done
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking stack direction for C alloca" >&5
+$as_echo_n "checking stack direction for C alloca... " >&6; }
+if test "${ac_cv_c_stack_direction+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "$cross_compiling" = yes; then :
+  ac_cv_c_stack_direction=0
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$ac_includes_default
+int
+find_stack_direction ()
+{
+  static char *addr = 0;
+  auto char dummy;
+  if (addr == 0)
+    {
+      addr = &dummy;
+      return find_stack_direction ();
+    }
+  else
+    return (&dummy > addr) ? 1 : -1;
+}
+
+int
+main ()
+{
+  return find_stack_direction () < 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  ac_cv_c_stack_direction=1
+else
+  ac_cv_c_stack_direction=-1
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_stack_direction" >&5
+$as_echo "$ac_cv_c_stack_direction" >&6; }
+cat >>confdefs.h <<_ACEOF
+#define STACK_DIRECTION $ac_cv_c_stack_direction
+_ACEOF
+
+
+fi
+
+for ac_header in stdlib.h unistd.h
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
+eval as_val=\$$as_ac_Header
+   if test "x$as_val" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+for ac_func in getpagesize
+do :
+  ac_fn_c_check_func "$LINENO" "getpagesize" "ac_cv_func_getpagesize"
+if test "x$ac_cv_func_getpagesize" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_GETPAGESIZE 1
+_ACEOF
+
+fi
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working mmap" >&5
+$as_echo_n "checking for working mmap... " >&6; }
+if test "${ac_cv_func_mmap_fixed_mapped+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "$cross_compiling" = yes; then :
+  ac_cv_func_mmap_fixed_mapped=no
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$ac_includes_default
+/* malloc might have been renamed as rpl_malloc. */
+#undef malloc
+
+/* Thanks to Mike Haertel and Jim Avera for this test.
+   Here is a matrix of mmap possibilities:
+       mmap private not fixed
+       mmap private fixed at somewhere currently unmapped
+       mmap private fixed at somewhere already mapped
+       mmap shared not fixed
+       mmap shared fixed at somewhere currently unmapped
+       mmap shared fixed at somewhere already mapped
+   For private mappings, we should verify that changes cannot be read()
+   back from the file, nor mmap's back from the file at a different
+   address.  (There have been systems where private was not correctly
+   implemented like the infamous i386 svr4.0, and systems where the
+   VM page cache was not coherent with the file system buffer cache
+   like early versions of FreeBSD and possibly contemporary NetBSD.)
+   For shared mappings, we should conversely verify that changes get
+   propagated back to all the places they're supposed to be.
+
+   Grep wants private fixed already mapped.
+   The main things grep needs to know about mmap are:
+   * does it exist and is it safe to write into the mmap'd area
+   * how to use it (BSD variants)  */
+
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#if !defined STDC_HEADERS && !defined HAVE_STDLIB_H
+char *malloc ();
+#endif
+
+/* This mess was copied from the GNU getpagesize.h.  */
+#ifndef HAVE_GETPAGESIZE
+/* Assume that all systems that can run configure have sys/param.h.  */
+# ifndef HAVE_SYS_PARAM_H
+#  define HAVE_SYS_PARAM_H 1
+# endif
+
+# ifdef _SC_PAGESIZE
+#  define getpagesize() sysconf(_SC_PAGESIZE)
+# else /* no _SC_PAGESIZE */
+#  ifdef HAVE_SYS_PARAM_H
+#   include <sys/param.h>
+#   ifdef EXEC_PAGESIZE
+#    define getpagesize() EXEC_PAGESIZE
+#   else /* no EXEC_PAGESIZE */
+#    ifdef NBPG
+#     define getpagesize() NBPG * CLSIZE
+#     ifndef CLSIZE
+#      define CLSIZE 1
+#     endif /* no CLSIZE */
+#    else /* no NBPG */
+#     ifdef NBPC
+#      define getpagesize() NBPC
+#     else /* no NBPC */
+#      ifdef PAGESIZE
+#       define getpagesize() PAGESIZE
+#      endif /* PAGESIZE */
+#     endif /* no NBPC */
+#    endif /* no NBPG */
+#   endif /* no EXEC_PAGESIZE */
+#  else /* no HAVE_SYS_PARAM_H */
+#   define getpagesize() 8192  /* punt totally */
+#  endif /* no HAVE_SYS_PARAM_H */
+# endif /* no _SC_PAGESIZE */
+
+#endif /* no HAVE_GETPAGESIZE */
+
+int
+main ()
+{
+  char *data, *data2, *data3;
+  int i, pagesize;
+  int fd;
+
+  pagesize = getpagesize ();
+
+  /* First, make a file with some known garbage in it. */
+  data = (char *) malloc (pagesize);
+  if (!data)
+    return 1;
+  for (i = 0; i < pagesize; ++i)
+    *(data + i) = rand ();
+  umask (0);
+  fd = creat ("conftest.mmap", 0600);
+  if (fd < 0)
+    return 1;
+  if (write (fd, data, pagesize) != pagesize)
+    return 1;
+  close (fd);
+
+  /* Next, try to mmap the file at a fixed address which already has
+     something else allocated at it.  If we can, also make sure that
+     we see the same garbage.  */
+  fd = open ("conftest.mmap", O_RDWR);
+  if (fd < 0)
+    return 1;
+  data2 = (char *) malloc (2 * pagesize);
+  if (!data2)
+    return 1;
+  data2 += (pagesize - ((long int) data2 & (pagesize - 1))) & (pagesize - 1);
+  if (data2 != mmap (data2, pagesize, PROT_READ | PROT_WRITE,
+                    MAP_PRIVATE | MAP_FIXED, fd, 0L))
+    return 1;
+  for (i = 0; i < pagesize; ++i)
+    if (*(data + i) != *(data2 + i))
+      return 1;
+
+  /* Finally, make sure that changes to the mapped area do not
+     percolate back to the file as seen by read().  (This is a bug on
+     some variants of i386 svr4.0.)  */
+  for (i = 0; i < pagesize; ++i)
+    *(data2 + i) = *(data2 + i) + 1;
+  data3 = (char *) malloc (pagesize);
+  if (!data3)
+    return 1;
+  if (read (fd, data3, pagesize) != pagesize)
+    return 1;
+  for (i = 0; i < pagesize; ++i)
+    if (*(data + i) != *(data3 + i))
+      return 1;
+  close (fd);
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  ac_cv_func_mmap_fixed_mapped=yes
+else
+  ac_cv_func_mmap_fixed_mapped=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_mmap_fixed_mapped" >&5
+$as_echo "$ac_cv_func_mmap_fixed_mapped" >&6; }
+if test $ac_cv_func_mmap_fixed_mapped = yes; then
+
+$as_echo "#define HAVE_MMAP 1" >>confdefs.h
+
+fi
+rm -f conftest.mmap
+
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C Library 2.1 or newer" >&5
+$as_echo_n "checking whether we are using the GNU C Library 2.1 or newer... " >&6; }
+if test "${ac_cv_gnu_library_2_1+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <features.h>
+#ifdef __GNU_LIBRARY__
+ #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2)
+  Lucky GNU user
+ #endif
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "Lucky GNU user" >/dev/null 2>&1; then :
+  ac_cv_gnu_library_2_1=yes
+else
+  ac_cv_gnu_library_2_1=no
+fi
+rm -f conftest*
+
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_gnu_library_2_1" >&5
+$as_echo "$ac_cv_gnu_library_2_1" >&6; }
+
+    GLIBC21="$ac_cv_gnu_library_2_1"
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether integer division by zero raises SIGFPE" >&5
+$as_echo_n "checking whether integer division by zero raises SIGFPE... " >&6; }
+if test "${gt_cv_int_divbyzero_sigfpe+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+
+      if test "$cross_compiling" = yes; then :
+
+          # Guess based on the CPU.
+          case "$host_cpu" in
+            alpha* | i3456786 | m68k | s390*)
+              gt_cv_int_divbyzero_sigfpe="guessing yes";;
+            *)
+              gt_cv_int_divbyzero_sigfpe="guessing no";;
+          esac
+
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <stdlib.h>
+#include <signal.h>
+
+static void
+#ifdef __cplusplus
+sigfpe_handler (int sig)
+#else
+sigfpe_handler (sig) int sig;
+#endif
+{
+  /* Exit with code 0 if SIGFPE, with code 1 if any other signal.  */
+  exit (sig != SIGFPE);
+}
+
+int x = 1;
+int y = 0;
+int z;
+int nan;
+
+int main ()
+{
+  signal (SIGFPE, sigfpe_handler);
+/* IRIX and AIX (when "xlc -qcheck" is used) yield signal SIGTRAP.  */
+#if (defined (__sgi) || defined (_AIX)) && defined (SIGTRAP)
+  signal (SIGTRAP, sigfpe_handler);
+#endif
+/* Linux/SPARC yields signal SIGILL.  */
+#if defined (__sparc__) && defined (__linux__)
+  signal (SIGILL, sigfpe_handler);
+#endif
+
+  z = x / y;
+  nan = y / y;
+  exit (1);
+}
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  gt_cv_int_divbyzero_sigfpe=yes
+else
+  gt_cv_int_divbyzero_sigfpe=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_int_divbyzero_sigfpe" >&5
+$as_echo "$gt_cv_int_divbyzero_sigfpe" >&6; }
+  case "$gt_cv_int_divbyzero_sigfpe" in
+    *yes) value=1;;
+    *) value=0;;
+  esac
+
+cat >>confdefs.h <<_ACEOF
+#define INTDIV0_RAISES_SIGFPE $value
+_ACEOF
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for unsigned long long" >&5
+$as_echo_n "checking for unsigned long long... " >&6; }
+if test "${ac_cv_type_unsigned_long_long+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+unsigned long long ull = 1ULL; int i = 63;
+int
+main ()
+{
+unsigned long long ullmax = (unsigned long long) -1;
+     return ull << i | ull >> i | ullmax / ull | ullmax % ull;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_type_unsigned_long_long=yes
+else
+  ac_cv_type_unsigned_long_long=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_unsigned_long_long" >&5
+$as_echo "$ac_cv_type_unsigned_long_long" >&6; }
+  if test $ac_cv_type_unsigned_long_long = yes; then
+
+$as_echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>confdefs.h
+
+  fi
+
+
+
+
+  if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then
+
+    test $ac_cv_type_unsigned_long_long = yes \
+      && ac_type='unsigned long long' \
+      || ac_type='unsigned long'
+
+cat >>confdefs.h <<_ACEOF
+#define uintmax_t $ac_type
+_ACEOF
+
+  else
+
+$as_echo "#define HAVE_UINTMAX_T 1" >>confdefs.h
+
+  fi
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inttypes.h" >&5
+$as_echo_n "checking for inttypes.h... " >&6; }
+if test "${gt_cv_header_inttypes_h+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <inttypes.h>
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gt_cv_header_inttypes_h=yes
+else
+  gt_cv_header_inttypes_h=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_header_inttypes_h" >&5
+$as_echo "$gt_cv_header_inttypes_h" >&6; }
+  if test $gt_cv_header_inttypes_h = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_INTTYPES_H 1
+_ACEOF
+
+  fi
+
+
+
+  if test $gt_cv_header_inttypes_h = yes; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the inttypes.h PRIxNN macros are broken" >&5
+$as_echo_n "checking whether the inttypes.h PRIxNN macros are broken... " >&6; }
+if test "${gt_cv_inttypes_pri_broken+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <inttypes.h>
+#ifdef PRId32
+char *p = PRId32;
+#endif
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gt_cv_inttypes_pri_broken=no
+else
+  gt_cv_inttypes_pri_broken=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_inttypes_pri_broken" >&5
+$as_echo "$gt_cv_inttypes_pri_broken" >&6; }
+  fi
+  if test "$gt_cv_inttypes_pri_broken" = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define PRI_MACROS_BROKEN 1
+_ACEOF
+
+  fi
+
+
+  for ac_header in stdint.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "stdint.h" "ac_cv_header_stdint_h" "$ac_includes_default"
+if test "x$ac_cv_header_stdint_h" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_STDINT_H 1
+_ACEOF
+
+fi
+
+done
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SIZE_MAX" >&5
+$as_echo_n "checking for SIZE_MAX... " >&6; }
+  result=
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <limits.h>
+#if HAVE_STDINT_H
+#include <stdint.h>
+#endif
+#ifdef SIZE_MAX
+Found it
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "Found it" >/dev/null 2>&1; then :
+  result=yes
+fi
+rm -f conftest*
+
+  if test -z "$result"; then
+                    if ac_fn_c_compute_int "$LINENO" "~(size_t)0 / 10" "res_hi"        "#include <stddef.h>"; then :
+
+else
+  result=?
+fi
+
+
+    if ac_fn_c_compute_int "$LINENO" "~(size_t)0 % 10" "res_lo"        "#include <stddef.h>"; then :
+
+else
+  result=?
+fi
+
+
+    if ac_fn_c_compute_int "$LINENO" "sizeof (size_t) <= sizeof (unsigned int)" "fits_in_uint"        "#include <stddef.h>"; then :
+
+else
+  result=?
+fi
+
+
+    if test "$fits_in_uint" = 1; then
+                  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stddef.h>
+        extern size_t foo;
+        extern unsigned long foo;
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  fits_in_uint=0
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    fi
+    if test -z "$result"; then
+      if test "$fits_in_uint" = 1; then
+        result="$res_hi$res_lo"U
+      else
+        result="$res_hi$res_lo"UL
+      fi
+    else
+            result='~(size_t)0'
+    fi
+  fi
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $result" >&5
+$as_echo "$result" >&6; }
+  if test "$result" != yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define SIZE_MAX $result
+_ACEOF
+
+  fi
+
+
+
+
+  for ac_header in stdint.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "stdint.h" "ac_cv_header_stdint_h" "$ac_includes_default"
+if test "x$ac_cv_header_stdint_h" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_STDINT_H 1
+_ACEOF
+
+fi
+
+done
+
+
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFPreferencesCopyAppValue" >&5
+$as_echo_n "checking for CFPreferencesCopyAppValue... " >&6; }
+if test "${gt_cv_func_CFPreferencesCopyAppValue+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  gt_save_CPPFLAGS="$CPPFLAGS"
+     CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers"
+     gt_save_LIBS="$LIBS"
+     LIBS="$LIBS -framework CoreFoundation"
+     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <CFPreferences.h>
+int
+main ()
+{
+CFPreferencesCopyAppValue(NULL, NULL)
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gt_cv_func_CFPreferencesCopyAppValue=yes
+else
+  gt_cv_func_CFPreferencesCopyAppValue=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+     CPPFLAGS="$gt_save_CPPFLAGS"
+     LIBS="$gt_save_LIBS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_CFPreferencesCopyAppValue" >&5
+$as_echo "$gt_cv_func_CFPreferencesCopyAppValue" >&6; }
+  if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then
+
+$as_echo "#define HAVE_CFPREFERENCESCOPYAPPVALUE 1" >>confdefs.h
+
+  fi
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFLocaleCopyCurrent" >&5
+$as_echo_n "checking for CFLocaleCopyCurrent... " >&6; }
+if test "${gt_cv_func_CFLocaleCopyCurrent+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  gt_save_CPPFLAGS="$CPPFLAGS"
+     CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers"
+     gt_save_LIBS="$LIBS"
+     LIBS="$LIBS -framework CoreFoundation"
+     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <CFLocale.h>
+int
+main ()
+{
+CFLocaleCopyCurrent();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gt_cv_func_CFLocaleCopyCurrent=yes
+else
+  gt_cv_func_CFLocaleCopyCurrent=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+     CPPFLAGS="$gt_save_CPPFLAGS"
+     LIBS="$gt_save_LIBS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_CFLocaleCopyCurrent" >&5
+$as_echo "$gt_cv_func_CFLocaleCopyCurrent" >&6; }
+  if test $gt_cv_func_CFLocaleCopyCurrent = yes; then
+
+$as_echo "#define HAVE_CFLOCALECOPYCURRENT 1" >>confdefs.h
+
+  fi
+  INTL_MACOSX_LIBS=
+  if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then
+    INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation"
+  fi
+
+
+
+      if test "X$prefix" = "XNONE"; then
+    acl_final_prefix="$ac_default_prefix"
+  else
+    acl_final_prefix="$prefix"
+  fi
+  if test "X$exec_prefix" = "XNONE"; then
+    acl_final_exec_prefix='${prefix}'
+  else
+    acl_final_exec_prefix="$exec_prefix"
+  fi
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  eval acl_final_exec_prefix=\"$acl_final_exec_prefix\"
+  prefix="$acl_save_prefix"
+
+
+# Check whether --with-gnu-ld was given.
+if test "${with_gnu_ld+set}" = set; then :
+  withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes
+else
+  with_gnu_ld=no
+fi
+
+# Prepare PATH_SEPARATOR.
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by GCC" >&5
+$as_echo_n "checking for ld used by GCC... " >&6; }
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [\\/]* | [A-Za-z]:[\\/]*)
+      re_direlt='/[^/][^/]*/\.\./'
+      # Canonicalize the path of ld
+      ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'`
+      while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
+       ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5
+$as_echo_n "checking for GNU ld... " >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5
+$as_echo_n "checking for non-GNU ld... " >&6; }
+fi
+if test "${acl_cv_path_LD+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$LD"; then
+  IFS="${IFS=  }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}"
+  for ac_dir in $PATH; do
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      acl_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some GNU ld's only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$acl_cv_path_LD" -v 2>&1 < /dev/null` in
+      *GNU* | *'with BFD'*)
+       test "$with_gnu_ld" != no && break ;;
+      *)
+       test "$with_gnu_ld" != yes && break ;;
+      esac
+    fi
+  done
+  IFS="$ac_save_ifs"
+else
+  acl_cv_path_LD="$LD" # Let the user override the test with a path.
+fi
+fi
+
+LD="$acl_cv_path_LD"
+if test -n "$LD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5
+$as_echo "$LD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+test -z "$LD" && as_fn_error "no acceptable ld found in \$PATH" "$LINENO" 5
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5
+$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; }
+if test "${acl_cv_prog_gnu_ld+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  # I'd rather use --version here, but apparently some GNU ld's only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  acl_cv_prog_gnu_ld=yes ;;
+*)
+  acl_cv_prog_gnu_ld=no ;;
+esac
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $acl_cv_prog_gnu_ld" >&5
+$as_echo "$acl_cv_prog_gnu_ld" >&6; }
+with_gnu_ld=$acl_cv_prog_gnu_ld
+
+
+
+
+                                                { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shared library run path origin" >&5
+$as_echo_n "checking for shared library run path origin... " >&6; }
+if test "${acl_cv_rpath+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+
+    CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \
+    ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh
+    . ./conftest.sh
+    rm -f ./conftest.sh
+    acl_cv_rpath=done
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $acl_cv_rpath" >&5
+$as_echo "$acl_cv_rpath" >&6; }
+  wl="$acl_cv_wl"
+  libext="$acl_cv_libext"
+  shlibext="$acl_cv_shlibext"
+  hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
+  hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
+  hardcode_direct="$acl_cv_hardcode_direct"
+  hardcode_minus_L="$acl_cv_hardcode_minus_L"
+    # Check whether --enable-rpath was given.
+if test "${enable_rpath+set}" = set; then :
+  enableval=$enable_rpath; :
+else
+  enable_rpath=yes
+fi
+
+
+
+
+
+
+
+
+    use_additional=yes
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+
+    eval additional_includedir=\"$includedir\"
+    eval additional_libdir=\"$libdir\"
+
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+
+# Check whether --with-libiconv-prefix was given.
+if test "${with_libiconv_prefix+set}" = set; then :
+  withval=$with_libiconv_prefix;
+    if test "X$withval" = "Xno"; then
+      use_additional=no
+    else
+      if test "X$withval" = "X"; then
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+
+          eval additional_includedir=\"$includedir\"
+          eval additional_libdir=\"$libdir\"
+
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+      else
+        additional_includedir="$withval/include"
+        additional_libdir="$withval/lib"
+      fi
+    fi
+
+fi
+
+      LIBICONV=
+  LTLIBICONV=
+  INCICONV=
+  rpathdirs=
+  ltrpathdirs=
+  names_already_handled=
+  names_next_round='iconv '
+  while test -n "$names_next_round"; do
+    names_this_round="$names_next_round"
+    names_next_round=
+    for name in $names_this_round; do
+      already_handled=
+      for n in $names_already_handled; do
+        if test "$n" = "$name"; then
+          already_handled=yes
+          break
+        fi
+      done
+      if test -z "$already_handled"; then
+        names_already_handled="$names_already_handled $name"
+                        uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
+        eval value=\"\$HAVE_LIB$uppername\"
+        if test -n "$value"; then
+          if test "$value" = yes; then
+            eval value=\"\$LIB$uppername\"
+            test -z "$value" || LIBICONV="${LIBICONV}${LIBICONV:+ }$value"
+            eval value=\"\$LTLIB$uppername\"
+            test -z "$value" || LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }$value"
+          else
+                                    :
+          fi
+        else
+                              found_dir=
+          found_la=
+          found_so=
+          found_a=
+          if test $use_additional = yes; then
+            if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then
+              found_dir="$additional_libdir"
+              found_so="$additional_libdir/lib$name.$shlibext"
+              if test -f "$additional_libdir/lib$name.la"; then
+                found_la="$additional_libdir/lib$name.la"
+              fi
+            else
+              if test -f "$additional_libdir/lib$name.$libext"; then
+                found_dir="$additional_libdir"
+                found_a="$additional_libdir/lib$name.$libext"
+                if test -f "$additional_libdir/lib$name.la"; then
+                  found_la="$additional_libdir/lib$name.la"
+                fi
+              fi
+            fi
+          fi
+          if test "X$found_dir" = "X"; then
+            for x in $LDFLAGS $LTLIBICONV; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+              case "$x" in
+                -L*)
+                  dir=`echo "X$x" | sed -e 's/^X-L//'`
+                  if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then
+                    found_dir="$dir"
+                    found_so="$dir/lib$name.$shlibext"
+                    if test -f "$dir/lib$name.la"; then
+                      found_la="$dir/lib$name.la"
+                    fi
+                  else
+                    if test -f "$dir/lib$name.$libext"; then
+                      found_dir="$dir"
+                      found_a="$dir/lib$name.$libext"
+                      if test -f "$dir/lib$name.la"; then
+                        found_la="$dir/lib$name.la"
+                      fi
+                    fi
+                  fi
+                  ;;
+              esac
+              if test "X$found_dir" != "X"; then
+                break
+              fi
+            done
+          fi
+          if test "X$found_dir" != "X"; then
+                        LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-L$found_dir -l$name"
+            if test "X$found_so" != "X"; then
+                                                        if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; then
+                                LIBICONV="${LIBICONV}${LIBICONV:+ }$found_so"
+              else
+                                                                                haveit=
+                for x in $ltrpathdirs; do
+                  if test "X$x" = "X$found_dir"; then
+                    haveit=yes
+                    break
+                  fi
+                done
+                if test -z "$haveit"; then
+                  ltrpathdirs="$ltrpathdirs $found_dir"
+                fi
+                                if test "$hardcode_direct" = yes; then
+                                                      LIBICONV="${LIBICONV}${LIBICONV:+ }$found_so"
+                else
+                  if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
+                                                            LIBICONV="${LIBICONV}${LIBICONV:+ }$found_so"
+                                                            haveit=
+                    for x in $rpathdirs; do
+                      if test "X$x" = "X$found_dir"; then
+                        haveit=yes
+                        break
+                      fi
+                    done
+                    if test -z "$haveit"; then
+                      rpathdirs="$rpathdirs $found_dir"
+                    fi
+                  else
+                                                                                haveit=
+                    for x in $LDFLAGS $LIBICONV; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+                      if test "X$x" = "X-L$found_dir"; then
+                        haveit=yes
+                        break
+                      fi
+                    done
+                    if test -z "$haveit"; then
+                      LIBICONV="${LIBICONV}${LIBICONV:+ }-L$found_dir"
+                    fi
+                    if test "$hardcode_minus_L" != no; then
+                                                                                        LIBICONV="${LIBICONV}${LIBICONV:+ }$found_so"
+                    else
+                                                                                                                                                                                LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name"
+                    fi
+                  fi
+                fi
+              fi
+            else
+              if test "X$found_a" != "X"; then
+                                LIBICONV="${LIBICONV}${LIBICONV:+ }$found_a"
+              else
+                                                LIBICONV="${LIBICONV}${LIBICONV:+ }-L$found_dir -l$name"
+              fi
+            fi
+                        additional_includedir=
+            case "$found_dir" in
+              */lib | */lib/)
+                basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'`
+                additional_includedir="$basedir/include"
+                ;;
+            esac
+            if test "X$additional_includedir" != "X"; then
+                                                                                                                if test "X$additional_includedir" != "X/usr/include"; then
+                haveit=
+                if test "X$additional_includedir" = "X/usr/local/include"; then
+                  if test -n "$GCC"; then
+                    case $host_os in
+                      linux* | gnu* | k*bsd*-gnu) haveit=yes;;
+                    esac
+                  fi
+                fi
+                if test -z "$haveit"; then
+                  for x in $CPPFLAGS $INCICONV; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+                    if test "X$x" = "X-I$additional_includedir"; then
+                      haveit=yes
+                      break
+                    fi
+                  done
+                  if test -z "$haveit"; then
+                    if test -d "$additional_includedir"; then
+                                            INCICONV="${INCICONV}${INCICONV:+ }-I$additional_includedir"
+                    fi
+                  fi
+                fi
+              fi
+            fi
+                        if test -n "$found_la"; then
+                                                        save_libdir="$libdir"
+              case "$found_la" in
+                */* | *\\*) . "$found_la" ;;
+                *) . "./$found_la" ;;
+              esac
+              libdir="$save_libdir"
+                            for dep in $dependency_libs; do
+                case "$dep" in
+                  -L*)
+                    additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
+                                                                                                                                                                if test "X$additional_libdir" != "X/usr/lib"; then
+                      haveit=
+                      if test "X$additional_libdir" = "X/usr/local/lib"; then
+                        if test -n "$GCC"; then
+                          case $host_os in
+                            linux* | gnu* | k*bsd*-gnu) haveit=yes;;
+                          esac
+                        fi
+                      fi
+                      if test -z "$haveit"; then
+                        haveit=
+                        for x in $LDFLAGS $LIBICONV; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+                          if test "X$x" = "X-L$additional_libdir"; then
+                            haveit=yes
+                            break
+                          fi
+                        done
+                        if test -z "$haveit"; then
+                          if test -d "$additional_libdir"; then
+                                                        LIBICONV="${LIBICONV}${LIBICONV:+ }-L$additional_libdir"
+                          fi
+                        fi
+                        haveit=
+                        for x in $LDFLAGS $LTLIBICONV; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+                          if test "X$x" = "X-L$additional_libdir"; then
+                            haveit=yes
+                            break
+                          fi
+                        done
+                        if test -z "$haveit"; then
+                          if test -d "$additional_libdir"; then
+                                                        LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-L$additional_libdir"
+                          fi
+                        fi
+                      fi
+                    fi
+                    ;;
+                  -R*)
+                    dir=`echo "X$dep" | sed -e 's/^X-R//'`
+                    if test "$enable_rpath" != no; then
+                                                                  haveit=
+                      for x in $rpathdirs; do
+                        if test "X$x" = "X$dir"; then
+                          haveit=yes
+                          break
+                        fi
+                      done
+                      if test -z "$haveit"; then
+                        rpathdirs="$rpathdirs $dir"
+                      fi
+                                                                  haveit=
+                      for x in $ltrpathdirs; do
+                        if test "X$x" = "X$dir"; then
+                          haveit=yes
+                          break
+                        fi
+                      done
+                      if test -z "$haveit"; then
+                        ltrpathdirs="$ltrpathdirs $dir"
+                      fi
+                    fi
+                    ;;
+                  -l*)
+                                        names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
+                    ;;
+                  *.la)
+                                                                                names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
+                    ;;
+                  *)
+                                        LIBICONV="${LIBICONV}${LIBICONV:+ }$dep"
+                    LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }$dep"
+                    ;;
+                esac
+              done
+            fi
+          else
+                                                            LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name"
+            LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l$name"
+          fi
+        fi
+      fi
+    done
+  done
+  if test "X$rpathdirs" != "X"; then
+    if test -n "$hardcode_libdir_separator"; then
+                        alldirs=
+      for found_dir in $rpathdirs; do
+        alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"
+      done
+            acl_save_libdir="$libdir"
+      libdir="$alldirs"
+      eval flag=\"$hardcode_libdir_flag_spec\"
+      libdir="$acl_save_libdir"
+      LIBICONV="${LIBICONV}${LIBICONV:+ }$flag"
+    else
+            for found_dir in $rpathdirs; do
+        acl_save_libdir="$libdir"
+        libdir="$found_dir"
+        eval flag=\"$hardcode_libdir_flag_spec\"
+        libdir="$acl_save_libdir"
+        LIBICONV="${LIBICONV}${LIBICONV:+ }$flag"
+      done
+    fi
+  fi
+  if test "X$ltrpathdirs" != "X"; then
+            for found_dir in $ltrpathdirs; do
+      LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-R$found_dir"
+    done
+  fi
+
+
+
+
+
+
+
+
+  ac_fn_c_check_type "$LINENO" "ptrdiff_t" "ac_cv_type_ptrdiff_t" "$ac_includes_default"
+if test "x$ac_cv_type_ptrdiff_t" = x""yes; then :
+
+else
+
+$as_echo "#define ptrdiff_t long" >>confdefs.h
+
+
+fi
+
+  for ac_header in argz.h limits.h locale.h nl_types.h malloc.h stddef.h \
+stdlib.h string.h unistd.h sys/param.h
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
+eval as_val=\$$as_ac_Header
+   if test "x$as_val" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+  for ac_func in asprintf fwprintf getcwd getegid geteuid getgid getuid \
+mempcpy munmap putenv setenv setlocale snprintf stpcpy strcasecmp strdup \
+strtoul tsearch wcslen __argz_count __argz_stringify __argz_next \
+__fsetlocking
+do :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+eval as_val=\$$as_ac_var
+   if test "x$as_val" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether _snprintf is declared" >&5
+$as_echo_n "checking whether _snprintf is declared... " >&6; }
+if test "${ac_cv_have_decl__snprintf+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdio.h>
+int
+main ()
+{
+
+#ifndef _snprintf
+  char *p = (char *) _snprintf;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_have_decl__snprintf=yes
+else
+  ac_cv_have_decl__snprintf=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_decl__snprintf" >&5
+$as_echo "$ac_cv_have_decl__snprintf" >&6; }
+  if test $ac_cv_have_decl__snprintf = yes; then
+    gt_value=1
+  else
+    gt_value=0
+  fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL__SNPRINTF $gt_value
+_ACEOF
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether _snwprintf is declared" >&5
+$as_echo_n "checking whether _snwprintf is declared... " >&6; }
+if test "${ac_cv_have_decl__snwprintf+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdio.h>
+int
+main ()
+{
+
+#ifndef _snwprintf
+  char *p = (char *) _snwprintf;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_have_decl__snwprintf=yes
+else
+  ac_cv_have_decl__snwprintf=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_decl__snwprintf" >&5
+$as_echo "$ac_cv_have_decl__snwprintf" >&6; }
+  if test $ac_cv_have_decl__snwprintf = yes; then
+    gt_value=1
+  else
+    gt_value=0
+  fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL__SNWPRINTF $gt_value
+_ACEOF
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether feof_unlocked is declared" >&5
+$as_echo_n "checking whether feof_unlocked is declared... " >&6; }
+if test "${ac_cv_have_decl_feof_unlocked+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdio.h>
+int
+main ()
+{
+
+#ifndef feof_unlocked
+  char *p = (char *) feof_unlocked;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_have_decl_feof_unlocked=yes
+else
+  ac_cv_have_decl_feof_unlocked=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_decl_feof_unlocked" >&5
+$as_echo "$ac_cv_have_decl_feof_unlocked" >&6; }
+  if test $ac_cv_have_decl_feof_unlocked = yes; then
+    gt_value=1
+  else
+    gt_value=0
+  fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_FEOF_UNLOCKED $gt_value
+_ACEOF
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether fgets_unlocked is declared" >&5
+$as_echo_n "checking whether fgets_unlocked is declared... " >&6; }
+if test "${ac_cv_have_decl_fgets_unlocked+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdio.h>
+int
+main ()
+{
+
+#ifndef fgets_unlocked
+  char *p = (char *) fgets_unlocked;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_have_decl_fgets_unlocked=yes
+else
+  ac_cv_have_decl_fgets_unlocked=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_decl_fgets_unlocked" >&5
+$as_echo "$ac_cv_have_decl_fgets_unlocked" >&6; }
+  if test $ac_cv_have_decl_fgets_unlocked = yes; then
+    gt_value=1
+  else
+    gt_value=0
+  fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_FGETS_UNLOCKED $gt_value
+_ACEOF
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether getc_unlocked is declared" >&5
+$as_echo_n "checking whether getc_unlocked is declared... " >&6; }
+if test "${ac_cv_have_decl_getc_unlocked+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdio.h>
+int
+main ()
+{
+
+#ifndef getc_unlocked
+  char *p = (char *) getc_unlocked;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_have_decl_getc_unlocked=yes
+else
+  ac_cv_have_decl_getc_unlocked=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_decl_getc_unlocked" >&5
+$as_echo "$ac_cv_have_decl_getc_unlocked" >&6; }
+  if test $ac_cv_have_decl_getc_unlocked = yes; then
+    gt_value=1
+  else
+    gt_value=0
+  fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_GETC_UNLOCKED $gt_value
+_ACEOF
+
+
+
+  case $gt_cv_func_printf_posix in
+    *yes) HAVE_POSIX_PRINTF=1 ;;
+    *) HAVE_POSIX_PRINTF=0 ;;
+  esac
+
+  if test "$ac_cv_func_asprintf" = yes; then
+    HAVE_ASPRINTF=1
+  else
+    HAVE_ASPRINTF=0
+  fi
+
+  if test "$ac_cv_func_snprintf" = yes; then
+    HAVE_SNPRINTF=1
+  else
+    HAVE_SNPRINTF=0
+  fi
+
+  if test "$ac_cv_func_wprintf" = yes; then
+    HAVE_WPRINTF=1
+  else
+    HAVE_WPRINTF=0
+  fi
+
+
+
+
+
+
+
+          am_save_CPPFLAGS="$CPPFLAGS"
+
+  for element in $INCICONV; do
+    haveit=
+    for x in $CPPFLAGS; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+      if test "X$x" = "X$element"; then
+        haveit=yes
+        break
+      fi
+    done
+    if test -z "$haveit"; then
+      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
+    fi
+  done
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5
+$as_echo_n "checking for iconv... " >&6; }
+if test "${am_cv_func_iconv+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+
+    am_cv_func_iconv="no, consider installing GNU libiconv"
+    am_cv_lib_iconv=no
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <iconv.h>
+int
+main ()
+{
+iconv_t cd = iconv_open("","");
+       iconv(cd,NULL,NULL,NULL,NULL);
+       iconv_close(cd);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  am_cv_func_iconv=yes
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+    if test "$am_cv_func_iconv" != yes; then
+      am_save_LIBS="$LIBS"
+      LIBS="$LIBS $LIBICONV"
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <iconv.h>
+int
+main ()
+{
+iconv_t cd = iconv_open("","");
+         iconv(cd,NULL,NULL,NULL,NULL);
+         iconv_close(cd);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  am_cv_lib_iconv=yes
+        am_cv_func_iconv=yes
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+      LIBS="$am_save_LIBS"
+    fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv" >&5
+$as_echo "$am_cv_func_iconv" >&6; }
+  if test "$am_cv_func_iconv" = yes; then
+
+$as_echo "#define HAVE_ICONV 1" >>confdefs.h
+
+  fi
+  if test "$am_cv_lib_iconv" = yes; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libiconv" >&5
+$as_echo_n "checking how to link with libiconv... " >&6; }
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBICONV" >&5
+$as_echo "$LIBICONV" >&6; }
+  else
+            CPPFLAGS="$am_save_CPPFLAGS"
+    LIBICONV=
+    LTLIBICONV=
+  fi
+
+
+
+  if test "$am_cv_func_iconv" = yes; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv declaration" >&5
+$as_echo_n "checking for iconv declaration... " >&6; }
+    if test "${am_cv_proto_iconv+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <stdlib.h>
+#include <iconv.h>
+extern
+#ifdef __cplusplus
+"C"
+#endif
+#if defined(__STDC__) || defined(__cplusplus)
+size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
+#else
+size_t iconv();
+#endif
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  am_cv_proto_iconv_arg1=""
+else
+  am_cv_proto_iconv_arg1="const"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+      am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"
+fi
+
+    am_cv_proto_iconv=`echo "$am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${ac_t:-
+         }$am_cv_proto_iconv" >&5
+$as_echo "${ac_t:-
+         }$am_cv_proto_iconv" >&6; }
+
+cat >>confdefs.h <<_ACEOF
+#define ICONV_CONST $am_cv_proto_iconv_arg1
+_ACEOF
+
+  fi
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for nl_langinfo and CODESET" >&5
+$as_echo_n "checking for nl_langinfo and CODESET... " >&6; }
+if test "${am_cv_langinfo_codeset+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <langinfo.h>
+int
+main ()
+{
+char* cs = nl_langinfo(CODESET);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  am_cv_langinfo_codeset=yes
+else
+  am_cv_langinfo_codeset=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_langinfo_codeset" >&5
+$as_echo "$am_cv_langinfo_codeset" >&6; }
+  if test $am_cv_langinfo_codeset = yes; then
+
+$as_echo "#define HAVE_LANGINFO_CODESET 1" >>confdefs.h
+
+  fi
+
+  if test $ac_cv_header_locale_h = yes; then
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for LC_MESSAGES" >&5
+$as_echo_n "checking for LC_MESSAGES... " >&6; }
+if test "${gt_cv_val_LC_MESSAGES+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <locale.h>
+int
+main ()
+{
+return LC_MESSAGES
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gt_cv_val_LC_MESSAGES=yes
+else
+  gt_cv_val_LC_MESSAGES=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_val_LC_MESSAGES" >&5
+$as_echo "$gt_cv_val_LC_MESSAGES" >&6; }
+  if test $gt_cv_val_LC_MESSAGES = yes; then
+
+$as_echo "#define HAVE_LC_MESSAGES 1" >>confdefs.h
+
+  fi
+
+  fi
+
+  if test -n "$INTL_MACOSX_LIBS"; then
+    CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers"
+  fi
+
+                      for ac_prog in bison
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_INTLBISON+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$INTLBISON"; then
+  ac_cv_prog_INTLBISON="$INTLBISON" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_INTLBISON="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+INTLBISON=$ac_cv_prog_INTLBISON
+if test -n "$INTLBISON"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $INTLBISON" >&5
+$as_echo "$INTLBISON" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$INTLBISON" && break
+done
+
+  if test -z "$INTLBISON"; then
+    ac_verc_fail=yes
+  else
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking version of bison" >&5
+$as_echo_n "checking version of bison... " >&6; }
+    ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'`
+    case $ac_prog_version in
+      '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
+      1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*)
+         ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
+      *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
+    esac
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_prog_version" >&5
+$as_echo "$ac_prog_version" >&6; }
+  fi
+  if test $ac_verc_fail = yes; then
+    INTLBISON=:
+  fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFPreferencesCopyAppValue" >&5
+$as_echo_n "checking for CFPreferencesCopyAppValue... " >&6; }
+if test "${gt_cv_func_CFPreferencesCopyAppValue+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  gt_save_CPPFLAGS="$CPPFLAGS"
+     CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers"
+     gt_save_LIBS="$LIBS"
+     LIBS="$LIBS -framework CoreFoundation"
+     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <CFPreferences.h>
+int
+main ()
+{
+CFPreferencesCopyAppValue(NULL, NULL)
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gt_cv_func_CFPreferencesCopyAppValue=yes
+else
+  gt_cv_func_CFPreferencesCopyAppValue=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+     CPPFLAGS="$gt_save_CPPFLAGS"
+     LIBS="$gt_save_LIBS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_CFPreferencesCopyAppValue" >&5
+$as_echo "$gt_cv_func_CFPreferencesCopyAppValue" >&6; }
+  if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then
+
+$as_echo "#define HAVE_CFPREFERENCESCOPYAPPVALUE 1" >>confdefs.h
+
+  fi
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFLocaleCopyCurrent" >&5
+$as_echo_n "checking for CFLocaleCopyCurrent... " >&6; }
+if test "${gt_cv_func_CFLocaleCopyCurrent+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  gt_save_CPPFLAGS="$CPPFLAGS"
+     CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers"
+     gt_save_LIBS="$LIBS"
+     LIBS="$LIBS -framework CoreFoundation"
+     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <CFLocale.h>
+int
+main ()
+{
+CFLocaleCopyCurrent();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gt_cv_func_CFLocaleCopyCurrent=yes
+else
+  gt_cv_func_CFLocaleCopyCurrent=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+     CPPFLAGS="$gt_save_CPPFLAGS"
+     LIBS="$gt_save_LIBS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_CFLocaleCopyCurrent" >&5
+$as_echo "$gt_cv_func_CFLocaleCopyCurrent" >&6; }
+  if test $gt_cv_func_CFLocaleCopyCurrent = yes; then
+
+$as_echo "#define HAVE_CFLOCALECOPYCURRENT 1" >>confdefs.h
+
+  fi
+  INTL_MACOSX_LIBS=
+  if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then
+    INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation"
+  fi
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether NLS is requested" >&5
+$as_echo_n "checking whether NLS is requested... " >&6; }
+    # Check whether --enable-nls was given.
+if test "${enable_nls+set}" = set; then :
+  enableval=$enable_nls; USE_NLS=$enableval
+else
+  USE_NLS=yes
+fi
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_NLS" >&5
+$as_echo "$USE_NLS" >&6; }
+
+
+
+
+    BUILD_INCLUDED_LIBINTL=no
+    USE_INCLUDED_LIBINTL=no
+
+  LIBINTL=
+  LTLIBINTL=
+  POSUB=
+
+    if test "$USE_NLS" = "yes"; then
+    gt_use_preinstalled_gnugettext=no
+
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether included gettext is requested" >&5
+$as_echo_n "checking whether included gettext is requested... " >&6; }
+
+# Check whether --with-included-gettext was given.
+if test "${with_included_gettext+set}" = set; then :
+  withval=$with_included_gettext; nls_cv_force_use_gnu_gettext=$withval
+else
+  nls_cv_force_use_gnu_gettext=no
+fi
+
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: $nls_cv_force_use_gnu_gettext" >&5
+$as_echo "$nls_cv_force_use_gnu_gettext" >&6; }
+
+      nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
+      if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
+
+
+
+
+
+
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU gettext in libc" >&5
+$as_echo_n "checking for GNU gettext in libc... " >&6; }
+if test "${gt_cv_func_gnugettext1_libc+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <libintl.h>
+extern int _nl_msg_cat_cntr;
+extern int *_nl_domain_bindings;
+int
+main ()
+{
+bindtextdomain ("", "");
+return * gettext ("") + _nl_msg_cat_cntr + *_nl_domain_bindings
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gt_cv_func_gnugettext1_libc=yes
+else
+  gt_cv_func_gnugettext1_libc=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_gnugettext1_libc" >&5
+$as_echo "$gt_cv_func_gnugettext1_libc" >&6; }
+
+        if test "$gt_cv_func_gnugettext1_libc" != "yes"; then
+
+
+
+    use_additional=yes
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+
+    eval additional_includedir=\"$includedir\"
+    eval additional_libdir=\"$libdir\"
+
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+
+# Check whether --with-libintl-prefix was given.
+if test "${with_libintl_prefix+set}" = set; then :
+  withval=$with_libintl_prefix;
+    if test "X$withval" = "Xno"; then
+      use_additional=no
+    else
+      if test "X$withval" = "X"; then
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+
+          eval additional_includedir=\"$includedir\"
+          eval additional_libdir=\"$libdir\"
+
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+      else
+        additional_includedir="$withval/include"
+        additional_libdir="$withval/lib"
+      fi
+    fi
+
+fi
+
+      LIBINTL=
+  LTLIBINTL=
+  INCINTL=
+  rpathdirs=
+  ltrpathdirs=
+  names_already_handled=
+  names_next_round='intl '
+  while test -n "$names_next_round"; do
+    names_this_round="$names_next_round"
+    names_next_round=
+    for name in $names_this_round; do
+      already_handled=
+      for n in $names_already_handled; do
+        if test "$n" = "$name"; then
+          already_handled=yes
+          break
+        fi
+      done
+      if test -z "$already_handled"; then
+        names_already_handled="$names_already_handled $name"
+                        uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
+        eval value=\"\$HAVE_LIB$uppername\"
+        if test -n "$value"; then
+          if test "$value" = yes; then
+            eval value=\"\$LIB$uppername\"
+            test -z "$value" || LIBINTL="${LIBINTL}${LIBINTL:+ }$value"
+            eval value=\"\$LTLIB$uppername\"
+            test -z "$value" || LTLIBINTL="${LTLIBINTL}${LTLIBINTL:+ }$value"
+          else
+                                    :
+          fi
+        else
+                              found_dir=
+          found_la=
+          found_so=
+          found_a=
+          if test $use_additional = yes; then
+            if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then
+              found_dir="$additional_libdir"
+              found_so="$additional_libdir/lib$name.$shlibext"
+              if test -f "$additional_libdir/lib$name.la"; then
+                found_la="$additional_libdir/lib$name.la"
+              fi
+            else
+              if test -f "$additional_libdir/lib$name.$libext"; then
+                found_dir="$additional_libdir"
+                found_a="$additional_libdir/lib$name.$libext"
+                if test -f "$additional_libdir/lib$name.la"; then
+                  found_la="$additional_libdir/lib$name.la"
+                fi
+              fi
+            fi
+          fi
+          if test "X$found_dir" = "X"; then
+            for x in $LDFLAGS $LTLIBINTL; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+              case "$x" in
+                -L*)
+                  dir=`echo "X$x" | sed -e 's/^X-L//'`
+                  if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then
+                    found_dir="$dir"
+                    found_so="$dir/lib$name.$shlibext"
+                    if test -f "$dir/lib$name.la"; then
+                      found_la="$dir/lib$name.la"
+                    fi
+                  else
+                    if test -f "$dir/lib$name.$libext"; then
+                      found_dir="$dir"
+                      found_a="$dir/lib$name.$libext"
+                      if test -f "$dir/lib$name.la"; then
+                        found_la="$dir/lib$name.la"
+                      fi
+                    fi
+                  fi
+                  ;;
+              esac
+              if test "X$found_dir" != "X"; then
+                break
+              fi
+            done
+          fi
+          if test "X$found_dir" != "X"; then
+                        LTLIBINTL="${LTLIBINTL}${LTLIBINTL:+ }-L$found_dir -l$name"
+            if test "X$found_so" != "X"; then
+                                                        if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; then
+                                LIBINTL="${LIBINTL}${LIBINTL:+ }$found_so"
+              else
+                                                                                haveit=
+                for x in $ltrpathdirs; do
+                  if test "X$x" = "X$found_dir"; then
+                    haveit=yes
+                    break
+                  fi
+                done
+                if test -z "$haveit"; then
+                  ltrpathdirs="$ltrpathdirs $found_dir"
+                fi
+                                if test "$hardcode_direct" = yes; then
+                                                      LIBINTL="${LIBINTL}${LIBINTL:+ }$found_so"
+                else
+                  if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
+                                                            LIBINTL="${LIBINTL}${LIBINTL:+ }$found_so"
+                                                            haveit=
+                    for x in $rpathdirs; do
+                      if test "X$x" = "X$found_dir"; then
+                        haveit=yes
+                        break
+                      fi
+                    done
+                    if test -z "$haveit"; then
+                      rpathdirs="$rpathdirs $found_dir"
+                    fi
+                  else
+                                                                                haveit=
+                    for x in $LDFLAGS $LIBINTL; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+                      if test "X$x" = "X-L$found_dir"; then
+                        haveit=yes
+                        break
+                      fi
+                    done
+                    if test -z "$haveit"; then
+                      LIBINTL="${LIBINTL}${LIBINTL:+ }-L$found_dir"
+                    fi
+                    if test "$hardcode_minus_L" != no; then
+                                                                                        LIBINTL="${LIBINTL}${LIBINTL:+ }$found_so"
+                    else
+                                                                                                                                                                                LIBINTL="${LIBINTL}${LIBINTL:+ }-l$name"
+                    fi
+                  fi
+                fi
+              fi
+            else
+              if test "X$found_a" != "X"; then
+                                LIBINTL="${LIBINTL}${LIBINTL:+ }$found_a"
+              else
+                                                LIBINTL="${LIBINTL}${LIBINTL:+ }-L$found_dir -l$name"
+              fi
+            fi
+                        additional_includedir=
+            case "$found_dir" in
+              */lib | */lib/)
+                basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'`
+                additional_includedir="$basedir/include"
+                ;;
+            esac
+            if test "X$additional_includedir" != "X"; then
+                                                                                                                if test "X$additional_includedir" != "X/usr/include"; then
+                haveit=
+                if test "X$additional_includedir" = "X/usr/local/include"; then
+                  if test -n "$GCC"; then
+                    case $host_os in
+                      linux* | gnu* | k*bsd*-gnu) haveit=yes;;
+                    esac
+                  fi
+                fi
+                if test -z "$haveit"; then
+                  for x in $CPPFLAGS $INCINTL; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+                    if test "X$x" = "X-I$additional_includedir"; then
+                      haveit=yes
+                      break
+                    fi
+                  done
+                  if test -z "$haveit"; then
+                    if test -d "$additional_includedir"; then
+                                            INCINTL="${INCINTL}${INCINTL:+ }-I$additional_includedir"
+                    fi
+                  fi
+                fi
+              fi
+            fi
+                        if test -n "$found_la"; then
+                                                        save_libdir="$libdir"
+              case "$found_la" in
+                */* | *\\*) . "$found_la" ;;
+                *) . "./$found_la" ;;
+              esac
+              libdir="$save_libdir"
+                            for dep in $dependency_libs; do
+                case "$dep" in
+                  -L*)
+                    additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
+                                                                                                                                                                if test "X$additional_libdir" != "X/usr/lib"; then
+                      haveit=
+                      if test "X$additional_libdir" = "X/usr/local/lib"; then
+                        if test -n "$GCC"; then
+                          case $host_os in
+                            linux* | gnu* | k*bsd*-gnu) haveit=yes;;
+                          esac
+                        fi
+                      fi
+                      if test -z "$haveit"; then
+                        haveit=
+                        for x in $LDFLAGS $LIBINTL; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+                          if test "X$x" = "X-L$additional_libdir"; then
+                            haveit=yes
+                            break
+                          fi
+                        done
+                        if test -z "$haveit"; then
+                          if test -d "$additional_libdir"; then
+                                                        LIBINTL="${LIBINTL}${LIBINTL:+ }-L$additional_libdir"
+                          fi
+                        fi
+                        haveit=
+                        for x in $LDFLAGS $LTLIBINTL; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+                          if test "X$x" = "X-L$additional_libdir"; then
+                            haveit=yes
+                            break
+                          fi
+                        done
+                        if test -z "$haveit"; then
+                          if test -d "$additional_libdir"; then
+                                                        LTLIBINTL="${LTLIBINTL}${LTLIBINTL:+ }-L$additional_libdir"
+                          fi
+                        fi
+                      fi
+                    fi
+                    ;;
+                  -R*)
+                    dir=`echo "X$dep" | sed -e 's/^X-R//'`
+                    if test "$enable_rpath" != no; then
+                                                                  haveit=
+                      for x in $rpathdirs; do
+                        if test "X$x" = "X$dir"; then
+                          haveit=yes
+                          break
+                        fi
+                      done
+                      if test -z "$haveit"; then
+                        rpathdirs="$rpathdirs $dir"
+                      fi
+                                                                  haveit=
+                      for x in $ltrpathdirs; do
+                        if test "X$x" = "X$dir"; then
+                          haveit=yes
+                          break
+                        fi
+                      done
+                      if test -z "$haveit"; then
+                        ltrpathdirs="$ltrpathdirs $dir"
+                      fi
+                    fi
+                    ;;
+                  -l*)
+                                        names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
+                    ;;
+                  *.la)
+                                                                                names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
+                    ;;
+                  *)
+                                        LIBINTL="${LIBINTL}${LIBINTL:+ }$dep"
+                    LTLIBINTL="${LTLIBINTL}${LTLIBINTL:+ }$dep"
+                    ;;
+                esac
+              done
+            fi
+          else
+                                                            LIBINTL="${LIBINTL}${LIBINTL:+ }-l$name"
+            LTLIBINTL="${LTLIBINTL}${LTLIBINTL:+ }-l$name"
+          fi
+        fi
+      fi
+    done
+  done
+  if test "X$rpathdirs" != "X"; then
+    if test -n "$hardcode_libdir_separator"; then
+                        alldirs=
+      for found_dir in $rpathdirs; do
+        alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"
+      done
+            acl_save_libdir="$libdir"
+      libdir="$alldirs"
+      eval flag=\"$hardcode_libdir_flag_spec\"
+      libdir="$acl_save_libdir"
+      LIBINTL="${LIBINTL}${LIBINTL:+ }$flag"
+    else
+            for found_dir in $rpathdirs; do
+        acl_save_libdir="$libdir"
+        libdir="$found_dir"
+        eval flag=\"$hardcode_libdir_flag_spec\"
+        libdir="$acl_save_libdir"
+        LIBINTL="${LIBINTL}${LIBINTL:+ }$flag"
+      done
+    fi
+  fi
+  if test "X$ltrpathdirs" != "X"; then
+            for found_dir in $ltrpathdirs; do
+      LTLIBINTL="${LTLIBINTL}${LTLIBINTL:+ }-R$found_dir"
+    done
+  fi
+
+          { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU gettext in libintl" >&5
+$as_echo_n "checking for GNU gettext in libintl... " >&6; }
+if test "${gt_cv_func_gnugettext1_libintl+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  gt_save_CPPFLAGS="$CPPFLAGS"
+            CPPFLAGS="$CPPFLAGS $INCINTL"
+            gt_save_LIBS="$LIBS"
+            LIBS="$LIBS $LIBINTL"
+                        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <libintl.h>
+extern int _nl_msg_cat_cntr;
+extern
+#ifdef __cplusplus
+"C"
+#endif
+const char *_nl_expand_alias (const char *);
+int
+main ()
+{
+bindtextdomain ("", "");
+return * gettext ("") + _nl_msg_cat_cntr + *_nl_expand_alias ("")
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gt_cv_func_gnugettext1_libintl=yes
+else
+  gt_cv_func_gnugettext1_libintl=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+                        if test "$gt_cv_func_gnugettext1_libintl" != yes && test -n "$LIBICONV"; then
+              LIBS="$LIBS $LIBICONV"
+              cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <libintl.h>
+extern int _nl_msg_cat_cntr;
+extern
+#ifdef __cplusplus
+"C"
+#endif
+const char *_nl_expand_alias (const char *);
+int
+main ()
+{
+bindtextdomain ("", "");
+return * gettext ("") + _nl_msg_cat_cntr + *_nl_expand_alias ("")
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  LIBINTL="$LIBINTL $LIBICONV"
+                LTLIBINTL="$LTLIBINTL $LTLIBICONV"
+                gt_cv_func_gnugettext1_libintl=yes
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+            fi
+            CPPFLAGS="$gt_save_CPPFLAGS"
+            LIBS="$gt_save_LIBS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_gnugettext1_libintl" >&5
+$as_echo "$gt_cv_func_gnugettext1_libintl" >&6; }
+        fi
+
+                                        if test "$gt_cv_func_gnugettext1_libc" = "yes" \
+           || { test "$gt_cv_func_gnugettext1_libintl" = "yes" \
+                && test "$PACKAGE" != gettext-runtime \
+                && test "$PACKAGE" != gettext-tools; }; then
+          gt_use_preinstalled_gnugettext=yes
+        else
+                    LIBINTL=
+          LTLIBINTL=
+          INCINTL=
+        fi
+
+
+        if test "$gt_use_preinstalled_gnugettext" != "yes"; then
+                              nls_cv_use_gnu_gettext=yes
+        fi
+      fi
+
+      if test "$nls_cv_use_gnu_gettext" = "yes"; then
+                BUILD_INCLUDED_LIBINTL=yes
+        USE_INCLUDED_LIBINTL=yes
+        LIBINTL="\${top_builddir}/intl/libintl.a $LIBICONV"
+        LTLIBINTL="\${top_builddir}/intl/libintl.a $LTLIBICONV"
+        LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
+      fi
+
+      CATOBJEXT=
+      if test "$gt_use_preinstalled_gnugettext" = "yes" \
+         || test "$nls_cv_use_gnu_gettext" = "yes"; then
+                CATOBJEXT=.gmo
+      fi
+
+
+    if test -n "$INTL_MACOSX_LIBS"; then
+      if test "$gt_use_preinstalled_gnugettext" = "yes" \
+         || test "$nls_cv_use_gnu_gettext" = "yes"; then
+                LIBINTL="$LIBINTL $INTL_MACOSX_LIBS"
+        LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS"
+      fi
+    fi
+
+    if test "$gt_use_preinstalled_gnugettext" = "yes" \
+       || test "$nls_cv_use_gnu_gettext" = "yes"; then
+
+$as_echo "#define ENABLE_NLS 1" >>confdefs.h
+
+    else
+      USE_NLS=no
+    fi
+  fi
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use NLS" >&5
+$as_echo_n "checking whether to use NLS... " >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_NLS" >&5
+$as_echo "$USE_NLS" >&6; }
+  if test "$USE_NLS" = "yes"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking where the gettext function comes from" >&5
+$as_echo_n "checking where the gettext function comes from... " >&6; }
+    if test "$gt_use_preinstalled_gnugettext" = "yes"; then
+      if test "$gt_cv_func_gnugettext1_libintl" = "yes"; then
+        gt_source="external libintl"
+      else
+        gt_source="libc"
+      fi
+    else
+      gt_source="included intl directory"
+    fi
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_source" >&5
+$as_echo "$gt_source" >&6; }
+  fi
+
+  if test "$USE_NLS" = "yes"; then
+
+    if test "$gt_use_preinstalled_gnugettext" = "yes"; then
+      if test "$gt_cv_func_gnugettext1_libintl" = "yes"; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libintl" >&5
+$as_echo_n "checking how to link with libintl... " >&6; }
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBINTL" >&5
+$as_echo "$LIBINTL" >&6; }
+
+  for element in $INCINTL; do
+    haveit=
+    for x in $CPPFLAGS; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+      if test "X$x" = "X$element"; then
+        haveit=yes
+        break
+      fi
+    done
+    if test -z "$haveit"; then
+      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
+    fi
+  done
+
+      fi
+
+
+$as_echo "#define HAVE_GETTEXT 1" >>confdefs.h
+
+
+$as_echo "#define HAVE_DCGETTEXT 1" >>confdefs.h
+
+    fi
+
+        POSUB=po
+  fi
+
+
+            if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then
+      BUILD_INCLUDED_LIBINTL=yes
+    fi
+
+
+
+
+
+        nls_cv_header_intl=
+    nls_cv_header_libgt=
+
+        DATADIRNAME=share
+
+
+        INSTOBJEXT=.mo
+
+
+        GENCAT=gencat
+
+
+        INTLOBJS=
+    if test "$USE_INCLUDED_LIBINTL" = yes; then
+      INTLOBJS="\$(GETTOBJS)"
+    fi
+
+
+        INTL_LIBTOOL_SUFFIX_PREFIX=
+
+
+
+    INTLLIBS="$LIBINTL"
+
+
+
+
+
+
+GETTEXTDIR="$datadir/locale"
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CC="${ac_tool_prefix}gcc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+  ac_ct_CC=$CC
+  # Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_CC="gcc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
+else
+  CC="$ac_cv_prog_CC"
+fi
+
+if test -z "$CC"; then
+          if test -n "$ac_tool_prefix"; then
+    # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CC="${ac_tool_prefix}cc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  fi
+fi
+if test -z "$CC"; then
+  # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+  ac_prog_rejected=no
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
+       ac_prog_rejected=yes
+       continue
+     fi
+    ac_cv_prog_CC="cc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+if test $ac_prog_rejected = yes; then
+  # We found a bogon in the path, so make sure we never use it.
+  set dummy $ac_cv_prog_CC
+  shift
+  if test $# != 0; then
+    # We chose a different compiler from the bogus one.
+    # However, it has the same basename, so the bogon will be chosen
+    # first if we set CC to just the basename; use the full file name.
+    shift
+    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
+  fi
+fi
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$CC"; then
+  if test -n "$ac_tool_prefix"; then
+  for ac_prog in cl.exe
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$CC" && break
+  done
+fi
+if test -z "$CC"; then
+  ac_ct_CC=$CC
+  for ac_prog in cl.exe
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_CC="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_CC" && break
+done
+
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
+fi
+
+fi
+
+
+test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "no acceptable C compiler found in \$PATH
+See \`config.log' for more details." "$LINENO" 5; }
+
+# Provide some information about the compiler.
+$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+for ac_option in --version -v -V -qversion; do
+  { { ac_try="$ac_compiler $ac_option >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    sed '10a\
+... rest of stderr output deleted ...
+         10q' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    rm -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
+$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
+if test "${ac_cv_c_compiler_gnu+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_compiler_gnu=yes
+else
+  ac_compiler_gnu=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_c_compiler_gnu=$ac_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
+$as_echo "$ac_cv_c_compiler_gnu" >&6; }
+if test $ac_compiler_gnu = yes; then
+  GCC=yes
+else
+  GCC=
+fi
+ac_test_CFLAGS=${CFLAGS+set}
+ac_save_CFLAGS=$CFLAGS
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
+$as_echo_n "checking whether $CC accepts -g... " >&6; }
+if test "${ac_cv_prog_cc_g+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_save_c_werror_flag=$ac_c_werror_flag
+   ac_c_werror_flag=yes
+   ac_cv_prog_cc_g=no
+   CFLAGS="-g"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_g=yes
+else
+  CFLAGS=""
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+else
+  ac_c_werror_flag=$ac_save_c_werror_flag
+        CFLAGS="-g"
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_g=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   ac_c_werror_flag=$ac_save_c_werror_flag
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
+$as_echo "$ac_cv_prog_cc_g" >&6; }
+if test "$ac_test_CFLAGS" = set; then
+  CFLAGS=$ac_save_CFLAGS
+elif test $ac_cv_prog_cc_g = yes; then
+  if test "$GCC" = yes; then
+    CFLAGS="-g -O2"
+  else
+    CFLAGS="-g"
+  fi
+else
+  if test "$GCC" = yes; then
+    CFLAGS="-O2"
+  else
+    CFLAGS=
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
+$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
+if test "${ac_cv_prog_cc_c89+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_prog_cc_c89=no
+ac_save_CC=$CC
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+     char **p;
+     int i;
+{
+  return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+  char *s;
+  va_list v;
+  va_start (v,p);
+  s = g (p, va_arg (v,int));
+  va_end (v);
+  return s;
+}
+
+/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
+   function prototypes and stuff, but not '\xHH' hex character constants.
+   These don't provoke an error unfortunately, instead are silently treated
+   as 'x'.  The following induces an error, until -std is added to get
+   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
+   array size at least.  It's necessary to write '\x00'==0 to get something
+   that's true only with -std.  */
+int osf4_cc_array ['\x00' == 0 ? 1 : -1];
+
+/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
+   inside strings and character constants.  */
+#define FOO(x) 'x'
+int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
+
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+int
+main ()
+{
+return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
+  ;
+  return 0;
+}
+_ACEOF
+for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
+       -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+  CC="$ac_save_CC $ac_arg"
+  if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_c89=$ac_arg
+fi
+rm -f core conftest.err conftest.$ac_objext
+  test "x$ac_cv_prog_cc_c89" != "xno" && break
+done
+rm -f conftest.$ac_ext
+CC=$ac_save_CC
+
+fi
+# AC_CACHE_VAL
+case "x$ac_cv_prog_cc_c89" in
+  x)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
+$as_echo "none needed" >&6; } ;;
+  xno)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
+$as_echo "unsupported" >&6; } ;;
+  *)
+    CC="$CC $ac_cv_prog_cc_c89"
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
+$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
+esac
+if test "x$ac_cv_prog_cc_c89" != xno; then :
+
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+depcc="$CC"   am_compiler_list=
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5
+$as_echo_n "checking dependency style of $depcc... " >&6; }
+if test "${am_cv_CC_dependencies_compiler_type+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named `D' -- because `-MD' means `put the output
+  # in D'.
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_CC_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp`
+  fi
+  am__universal=false
+  case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac
+
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+      # Solaris 8's {/usr,}/bin/sh.
+      touch sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    # We check with `-c' and `-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle `-M -o', and we need to detect this.  Also, some Intel
+    # versions had trouble with output in subdirs
+    am__obj=sub/conftest.${OBJEXT-o}
+    am__minus_obj="-o $am__obj"
+    case $depmode in
+    gcc)
+      # This depmode causes a compiler race in universal mode.
+      test "$am__universal" = false || continue
+      ;;
+    nosideeffect)
+      # after this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested
+      if test "x$enable_dependency_tracking" = xyes; then
+       continue
+      else
+       break
+      fi
+      ;;
+    msvisualcpp | msvcmsys)
+      # This compiler won't grok `-c -o', but also, the minuso test has
+      # not run yet.  These depmodes are late enough in the game, and
+      # so weak that their functioning should not be impacted.
+      am__obj=conftest.${OBJEXT-o}
+      am__minus_obj=
+      ;;
+    none) break ;;
+    esac
+    if depmode=$depmode \
+       source=sub/conftest.c object=$am__obj \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_CC_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_CC_dependencies_compiler_type=none
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5
+$as_echo "$am_cv_CC_dependencies_compiler_type" >&6; }
+CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type
+
+ if
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then
+  am__fastdepCC_TRUE=
+  am__fastdepCC_FALSE='#'
+else
+  am__fastdepCC_TRUE='#'
+  am__fastdepCC_FALSE=
+fi
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for X" >&5
+$as_echo_n "checking for X... " >&6; }
+
+
+# Check whether --with-x was given.
+if test "${with_x+set}" = set; then :
+  withval=$with_x;
+fi
+
+# $have_x is `yes', `no', `disabled', or empty when we do not yet know.
+if test "x$with_x" = xno; then
+  # The user explicitly disabled X.
+  have_x=disabled
+else
+  case $x_includes,$x_libraries in #(
+    *\'*) as_fn_error "cannot use X directory names containing '" "$LINENO" 5;; #(
+    *,NONE | NONE,*) if test "${ac_cv_have_x+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  # One or both of the vars are not set, and there is no cached value.
+ac_x_includes=no ac_x_libraries=no
+rm -f -r conftest.dir
+if mkdir conftest.dir; then
+  cd conftest.dir
+  cat >Imakefile <<'_ACEOF'
+incroot:
+       @echo incroot='${INCROOT}'
+usrlibdir:
+       @echo usrlibdir='${USRLIBDIR}'
+libdir:
+       @echo libdir='${LIBDIR}'
+_ACEOF
+  if (export CC; ${XMKMF-xmkmf}) >/dev/null 2>/dev/null && test -f Makefile; then
+    # GNU make sometimes prints "make[1]: Entering...", which would confuse us.
+    for ac_var in incroot usrlibdir libdir; do
+      eval "ac_im_$ac_var=\`\${MAKE-make} $ac_var 2>/dev/null | sed -n 's/^$ac_var=//p'\`"
+    done
+    # Open Windows xmkmf reportedly sets LIBDIR instead of USRLIBDIR.
+    for ac_extension in a so sl dylib la dll; do
+      if test ! -f "$ac_im_usrlibdir/libX11.$ac_extension" &&
+        test -f "$ac_im_libdir/libX11.$ac_extension"; then
+       ac_im_usrlibdir=$ac_im_libdir; break
+      fi
+    done
+    # Screen out bogus values from the imake configuration.  They are
+    # bogus both because they are the default anyway, and because
+    # using them would break gcc on systems where it needs fixed includes.
+    case $ac_im_incroot in
+       /usr/include) ac_x_includes= ;;
+       *) test -f "$ac_im_incroot/X11/Xos.h" && ac_x_includes=$ac_im_incroot;;
+    esac
+    case $ac_im_usrlibdir in
+       /usr/lib | /usr/lib64 | /lib | /lib64) ;;
+       *) test -d "$ac_im_usrlibdir" && ac_x_libraries=$ac_im_usrlibdir ;;
+    esac
+  fi
+  cd ..
+  rm -f -r conftest.dir
+fi
+
+# Standard set of common directories for X headers.
+# Check X11 before X11Rn because it is often a symlink to the current release.
+ac_x_header_dirs='
+/usr/X11/include
+/usr/X11R7/include
+/usr/X11R6/include
+/usr/X11R5/include
+/usr/X11R4/include
+
+/usr/include/X11
+/usr/include/X11R7
+/usr/include/X11R6
+/usr/include/X11R5
+/usr/include/X11R4
+
+/usr/local/X11/include
+/usr/local/X11R7/include
+/usr/local/X11R6/include
+/usr/local/X11R5/include
+/usr/local/X11R4/include
+
+/usr/local/include/X11
+/usr/local/include/X11R7
+/usr/local/include/X11R6
+/usr/local/include/X11R5
+/usr/local/include/X11R4
+
+/usr/X386/include
+/usr/x386/include
+/usr/XFree86/include/X11
+
+/usr/include
+/usr/local/include
+/usr/unsupported/include
+/usr/athena/include
+/usr/local/x11r5/include
+/usr/lpp/Xamples/include
+
+/usr/openwin/include
+/usr/openwin/share/include'
+
+if test "$ac_x_includes" = no; then
+  # Guess where to find include files, by looking for Xlib.h.
+  # First, try using that file with no special directory specified.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <X11/Xlib.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  # We can compile using X headers with no special include directory.
+ac_x_includes=
+else
+  for ac_dir in $ac_x_header_dirs; do
+  if test -r "$ac_dir/X11/Xlib.h"; then
+    ac_x_includes=$ac_dir
+    break
+  fi
+done
+fi
+rm -f conftest.err conftest.$ac_ext
+fi # $ac_x_includes = no
+
+if test "$ac_x_libraries" = no; then
+  # Check for the libraries.
+  # See if we find them without any special options.
+  # Don't add to $LIBS permanently.
+  ac_save_LIBS=$LIBS
+  LIBS="-lX11 $LIBS"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <X11/Xlib.h>
+int
+main ()
+{
+XrmInitialize ()
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  LIBS=$ac_save_LIBS
+# We can link X programs with no special library path.
+ac_x_libraries=
+else
+  LIBS=$ac_save_LIBS
+for ac_dir in `$as_echo "$ac_x_includes $ac_x_header_dirs" | sed s/include/lib/g`
+do
+  # Don't even attempt the hair of trying to link an X program!
+  for ac_extension in a so sl dylib la dll; do
+    if test -r "$ac_dir/libX11.$ac_extension"; then
+      ac_x_libraries=$ac_dir
+      break 2
+    fi
+  done
+done
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi # $ac_x_libraries = no
+
+case $ac_x_includes,$ac_x_libraries in #(
+  no,* | *,no | *\'*)
+    # Didn't find X, or a directory has "'" in its name.
+    ac_cv_have_x="have_x=no";; #(
+  *)
+    # Record where we found X for the cache.
+    ac_cv_have_x="have_x=yes\
+       ac_x_includes='$ac_x_includes'\
+       ac_x_libraries='$ac_x_libraries'"
+esac
+fi
+;; #(
+    *) have_x=yes;;
+  esac
+  eval "$ac_cv_have_x"
+fi # $with_x != no
+
+if test "$have_x" != yes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_x" >&5
+$as_echo "$have_x" >&6; }
+  no_x=yes
+else
+  # If each of the values was on the command line, it overrides each guess.
+  test "x$x_includes" = xNONE && x_includes=$ac_x_includes
+  test "x$x_libraries" = xNONE && x_libraries=$ac_x_libraries
+  # Update the cache value to reflect the command line values.
+  ac_cv_have_x="have_x=yes\
+       ac_x_includes='$x_includes'\
+       ac_x_libraries='$x_libraries'"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: libraries $x_libraries, headers $x_includes" >&5
+$as_echo "libraries $x_libraries, headers $x_includes" >&6; }
+fi
+
+if test "$no_x" = yes; then
+  # Not all programs may use this symbol, but it does not hurt to define it.
+
+$as_echo "#define X_DISPLAY_MISSING 1" >>confdefs.h
+
+  X_CFLAGS= X_PRE_LIBS= X_LIBS= X_EXTRA_LIBS=
+else
+  if test -n "$x_includes"; then
+    X_CFLAGS="$X_CFLAGS -I$x_includes"
+  fi
+
+  # It would also be nice to do this for all -L options, not just this one.
+  if test -n "$x_libraries"; then
+    X_LIBS="$X_LIBS -L$x_libraries"
+    # For Solaris; some versions of Sun CC require a space after -R and
+    # others require no space.  Words are not sufficient . . . .
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -R must be followed by a space" >&5
+$as_echo_n "checking whether -R must be followed by a space... " >&6; }
+    ac_xsave_LIBS=$LIBS; LIBS="$LIBS -R$x_libraries"
+    ac_xsave_c_werror_flag=$ac_c_werror_flag
+    ac_c_werror_flag=yes
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+       X_LIBS="$X_LIBS -R$x_libraries"
+else
+  LIBS="$ac_xsave_LIBS -R $x_libraries"
+       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+         X_LIBS="$X_LIBS -R $x_libraries"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: neither works" >&5
+$as_echo "neither works" >&6; }
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+    ac_c_werror_flag=$ac_xsave_c_werror_flag
+    LIBS=$ac_xsave_LIBS
+  fi
+
+  # Check for system-dependent libraries X programs must link with.
+  # Do this before checking for the system-independent R6 libraries
+  # (-lICE), since we may need -lsocket or whatever for X linking.
+
+  if test "$ISC" = yes; then
+    X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl_s -linet"
+  else
+    # Martyn Johnson says this is needed for Ultrix, if the X
+    # libraries were built with DECnet support.  And Karl Berry says
+    # the Alpha needs dnet_stub (dnet does not exist).
+    ac_xsave_LIBS="$LIBS"; LIBS="$LIBS $X_LIBS -lX11"
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char XOpenDisplay ();
+int
+main ()
+{
+return XOpenDisplay ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dnet_ntoa in -ldnet" >&5
+$as_echo_n "checking for dnet_ntoa in -ldnet... " >&6; }
+if test "${ac_cv_lib_dnet_dnet_ntoa+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldnet  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dnet_ntoa ();
+int
+main ()
+{
+return dnet_ntoa ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dnet_dnet_ntoa=yes
+else
+  ac_cv_lib_dnet_dnet_ntoa=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dnet_dnet_ntoa" >&5
+$as_echo "$ac_cv_lib_dnet_dnet_ntoa" >&6; }
+if test "x$ac_cv_lib_dnet_dnet_ntoa" = x""yes; then :
+  X_EXTRA_LIBS="$X_EXTRA_LIBS -ldnet"
+fi
+
+    if test $ac_cv_lib_dnet_dnet_ntoa = no; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dnet_ntoa in -ldnet_stub" >&5
+$as_echo_n "checking for dnet_ntoa in -ldnet_stub... " >&6; }
+if test "${ac_cv_lib_dnet_stub_dnet_ntoa+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldnet_stub  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dnet_ntoa ();
+int
+main ()
+{
+return dnet_ntoa ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dnet_stub_dnet_ntoa=yes
+else
+  ac_cv_lib_dnet_stub_dnet_ntoa=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dnet_stub_dnet_ntoa" >&5
+$as_echo "$ac_cv_lib_dnet_stub_dnet_ntoa" >&6; }
+if test "x$ac_cv_lib_dnet_stub_dnet_ntoa" = x""yes; then :
+  X_EXTRA_LIBS="$X_EXTRA_LIBS -ldnet_stub"
+fi
+
+    fi
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+    LIBS="$ac_xsave_LIBS"
+
+    # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
+    # to get the SysV transport functions.
+    # Chad R. Larson says the Pyramis MIS-ES running DC/OSx (SVR4)
+    # needs -lnsl.
+    # The nsl library prevents programs from opening the X display
+    # on Irix 5.2, according to T.E. Dickey.
+    # The functions gethostbyname, getservbyname, and inet_addr are
+    # in -lbsd on LynxOS 3.0.1/i386, according to Lars Hecking.
+    ac_fn_c_check_func "$LINENO" "gethostbyname" "ac_cv_func_gethostbyname"
+if test "x$ac_cv_func_gethostbyname" = x""yes; then :
+
+fi
+
+    if test $ac_cv_func_gethostbyname = no; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyname in -lnsl" >&5
+$as_echo_n "checking for gethostbyname in -lnsl... " >&6; }
+if test "${ac_cv_lib_nsl_gethostbyname+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lnsl  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char gethostbyname ();
+int
+main ()
+{
+return gethostbyname ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_nsl_gethostbyname=yes
+else
+  ac_cv_lib_nsl_gethostbyname=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_nsl_gethostbyname" >&5
+$as_echo "$ac_cv_lib_nsl_gethostbyname" >&6; }
+if test "x$ac_cv_lib_nsl_gethostbyname" = x""yes; then :
+  X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl"
+fi
+
+      if test $ac_cv_lib_nsl_gethostbyname = no; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyname in -lbsd" >&5
+$as_echo_n "checking for gethostbyname in -lbsd... " >&6; }
+if test "${ac_cv_lib_bsd_gethostbyname+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lbsd  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char gethostbyname ();
+int
+main ()
+{
+return gethostbyname ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_bsd_gethostbyname=yes
+else
+  ac_cv_lib_bsd_gethostbyname=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bsd_gethostbyname" >&5
+$as_echo "$ac_cv_lib_bsd_gethostbyname" >&6; }
+if test "x$ac_cv_lib_bsd_gethostbyname" = x""yes; then :
+  X_EXTRA_LIBS="$X_EXTRA_LIBS -lbsd"
+fi
+
+      fi
+    fi
+
+    # lieder@skyler.mavd.honeywell.com says without -lsocket,
+    # socket/setsockopt and other routines are undefined under SCO ODT
+    # 2.0.  But -lsocket is broken on IRIX 5.2 (and is not necessary
+    # on later versions), says Simon Leinen: it contains gethostby*
+    # variants that don't use the name server (or something).  -lsocket
+    # must be given before -lnsl if both are needed.  We assume that
+    # if connect needs -lnsl, so does gethostbyname.
+    ac_fn_c_check_func "$LINENO" "connect" "ac_cv_func_connect"
+if test "x$ac_cv_func_connect" = x""yes; then :
+
+fi
+
+    if test $ac_cv_func_connect = no; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for connect in -lsocket" >&5
+$as_echo_n "checking for connect in -lsocket... " >&6; }
+if test "${ac_cv_lib_socket_connect+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lsocket $X_EXTRA_LIBS $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char connect ();
+int
+main ()
+{
+return connect ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_socket_connect=yes
+else
+  ac_cv_lib_socket_connect=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_socket_connect" >&5
+$as_echo "$ac_cv_lib_socket_connect" >&6; }
+if test "x$ac_cv_lib_socket_connect" = x""yes; then :
+  X_EXTRA_LIBS="-lsocket $X_EXTRA_LIBS"
+fi
+
+    fi
+
+    # Guillermo Gomez says -lposix is necessary on A/UX.
+    ac_fn_c_check_func "$LINENO" "remove" "ac_cv_func_remove"
+if test "x$ac_cv_func_remove" = x""yes; then :
+
+fi
+
+    if test $ac_cv_func_remove = no; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for remove in -lposix" >&5
+$as_echo_n "checking for remove in -lposix... " >&6; }
+if test "${ac_cv_lib_posix_remove+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lposix  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char remove ();
+int
+main ()
+{
+return remove ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_posix_remove=yes
+else
+  ac_cv_lib_posix_remove=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_posix_remove" >&5
+$as_echo "$ac_cv_lib_posix_remove" >&6; }
+if test "x$ac_cv_lib_posix_remove" = x""yes; then :
+  X_EXTRA_LIBS="$X_EXTRA_LIBS -lposix"
+fi
+
+    fi
+
+    # BSDI BSD/OS 2.1 needs -lipc for XOpenDisplay.
+    ac_fn_c_check_func "$LINENO" "shmat" "ac_cv_func_shmat"
+if test "x$ac_cv_func_shmat" = x""yes; then :
+
+fi
+
+    if test $ac_cv_func_shmat = no; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shmat in -lipc" >&5
+$as_echo_n "checking for shmat in -lipc... " >&6; }
+if test "${ac_cv_lib_ipc_shmat+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lipc  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char shmat ();
+int
+main ()
+{
+return shmat ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_ipc_shmat=yes
+else
+  ac_cv_lib_ipc_shmat=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ipc_shmat" >&5
+$as_echo "$ac_cv_lib_ipc_shmat" >&6; }
+if test "x$ac_cv_lib_ipc_shmat" = x""yes; then :
+  X_EXTRA_LIBS="$X_EXTRA_LIBS -lipc"
+fi
+
+    fi
+  fi
+
+  # Check for libraries that X11R6 Xt/Xaw programs need.
+  ac_save_LDFLAGS=$LDFLAGS
+  test -n "$x_libraries" && LDFLAGS="$LDFLAGS -L$x_libraries"
+  # SM needs ICE to (dynamically) link under SunOS 4.x (so we have to
+  # check for ICE first), but we must link in the order -lSM -lICE or
+  # we get undefined symbols.  So assume we have SM if we have ICE.
+  # These have to be linked with before -lX11, unlike the other
+  # libraries we check for below, so use a different variable.
+  # John Interrante, Karl Berry
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for IceConnectionNumber in -lICE" >&5
+$as_echo_n "checking for IceConnectionNumber in -lICE... " >&6; }
+if test "${ac_cv_lib_ICE_IceConnectionNumber+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lICE $X_EXTRA_LIBS $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char IceConnectionNumber ();
+int
+main ()
+{
+return IceConnectionNumber ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_ICE_IceConnectionNumber=yes
+else
+  ac_cv_lib_ICE_IceConnectionNumber=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ICE_IceConnectionNumber" >&5
+$as_echo "$ac_cv_lib_ICE_IceConnectionNumber" >&6; }
+if test "x$ac_cv_lib_ICE_IceConnectionNumber" = x""yes; then :
+  X_PRE_LIBS="$X_PRE_LIBS -lSM -lICE"
+fi
+
+  LDFLAGS=$ac_save_LDFLAGS
+
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
+$as_echo_n "checking for ANSI C header files... " >&6; }
+if test "${ac_cv_header_stdc+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_header_stdc=yes
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then :
+  :
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ctype.h>
+#include <stdlib.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+                  (('a' <= (c) && (c) <= 'i') \
+                    || ('j' <= (c) && (c) <= 'r') \
+                    || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+       || toupper (i) != TOUPPER (i))
+      return 2;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
+$as_echo "$ac_cv_header_stdc" >&6; }
+if test $ac_cv_header_stdc = yes; then
+
+$as_echo "#define STDC_HEADERS 1" >>confdefs.h
+
+fi
+
+ac_header_dirent=no
+for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do
+  as_ac_Header=`$as_echo "ac_cv_header_dirent_$ac_hdr" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_hdr that defines DIR" >&5
+$as_echo_n "checking for $ac_hdr that defines DIR... " >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <$ac_hdr>
+
+int
+main ()
+{
+if ((DIR *) 0)
+return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$as_ac_Header=yes"
+else
+  eval "$as_ac_Header=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$as_ac_Header
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+eval as_val=\$$as_ac_Header
+   if test "x$as_val" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_hdr" | $as_tr_cpp` 1
+_ACEOF
+
+ac_header_dirent=$ac_hdr; break
+fi
+
+done
+# Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
+if test $ac_header_dirent = dirent.h; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing opendir" >&5
+$as_echo_n "checking for library containing opendir... " >&6; }
+if test "${ac_cv_search_opendir+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char opendir ();
+int
+main ()
+{
+return opendir ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' dir; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_opendir=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if test "${ac_cv_search_opendir+set}" = set; then :
+  break
+fi
+done
+if test "${ac_cv_search_opendir+set}" = set; then :
+
+else
+  ac_cv_search_opendir=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_opendir" >&5
+$as_echo "$ac_cv_search_opendir" >&6; }
+ac_res=$ac_cv_search_opendir
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing opendir" >&5
+$as_echo_n "checking for library containing opendir... " >&6; }
+if test "${ac_cv_search_opendir+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char opendir ();
+int
+main ()
+{
+return opendir ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' x; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_opendir=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if test "${ac_cv_search_opendir+set}" = set; then :
+  break
+fi
+done
+if test "${ac_cv_search_opendir+set}" = set; then :
+
+else
+  ac_cv_search_opendir=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_opendir" >&5
+$as_echo "$ac_cv_search_opendir" >&6; }
+ac_res=$ac_cv_search_opendir
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether time.h and sys/time.h may both be included" >&5
+$as_echo_n "checking whether time.h and sys/time.h may both be included... " >&6; }
+if test "${ac_cv_header_time+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <sys/time.h>
+#include <time.h>
+
+int
+main ()
+{
+if ((struct tm *) 0)
+return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_header_time=yes
+else
+  ac_cv_header_time=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_time" >&5
+$as_echo "$ac_cv_header_time" >&6; }
+if test $ac_cv_header_time = yes; then
+
+$as_echo "#define TIME_WITH_SYS_TIME 1" >>confdefs.h
+
+fi
+
+for ac_header in fcntl.h langinfo.h limits.h locale.h stdlib.h \
+                         string.h strings.h sys/time.h unistd.h
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
+eval as_val=\$$as_ac_Header
+   if test "x$as_val" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+ac_fn_c_check_header_mongrel "$LINENO" "X11/Xaw/Command.h" "ac_cv_header_X11_Xaw_Command_h" "$ac_includes_default"
+if test "x$ac_cv_header_X11_Xaw_Command_h" = x""yes; then :
+  HAVE_XAW=yes
+fi
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5
+$as_echo_n "checking for an ANSI C-conforming const... " >&6; }
+if test "${ac_cv_c_const+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+/* FIXME: Include the comments suggested by Paul. */
+#ifndef __cplusplus
+  /* Ultrix mips cc rejects this.  */
+  typedef int charset[2];
+  const charset cs;
+  /* SunOS 4.1.1 cc rejects this.  */
+  char const *const *pcpcc;
+  char **ppc;
+  /* NEC SVR4.0.2 mips cc rejects this.  */
+  struct point {int x, y;};
+  static struct point const zero = {0,0};
+  /* AIX XL C 1.02.0.0 rejects this.
+     It does not let you subtract one const X* pointer from another in
+     an arm of an if-expression whose if-part is not a constant
+     expression */
+  const char *g = "string";
+  pcpcc = &g + (g ? g-g : 0);
+  /* HPUX 7.0 cc rejects these. */
+  ++pcpcc;
+  ppc = (char**) pcpcc;
+  pcpcc = (char const *const *) ppc;
+  { /* SCO 3.2v4 cc rejects this.  */
+    char *t;
+    char const *s = 0 ? (char *) 0 : (char const *) 0;
+
+    *t++ = 0;
+    if (s) return 0;
+  }
+  { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
+    int x[] = {25, 17};
+    const int *foo = &x[0];
+    ++foo;
+  }
+  { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
+    typedef const int *iptr;
+    iptr p = 0;
+    ++p;
+  }
+  { /* AIX XL C 1.02.0.0 rejects this saying
+       "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
+    struct s { int j; const int *ap[3]; };
+    struct s *b; b->j = 5;
+  }
+  { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
+    const int foo = 10;
+    if (!foo) return 0;
+  }
+  return !cs[0] && !zero.x;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_c_const=yes
+else
+  ac_cv_c_const=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5
+$as_echo "$ac_cv_c_const" >&6; }
+if test $ac_cv_c_const = no; then
+
+$as_echo "#define const /**/" >>confdefs.h
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline" >&5
+$as_echo_n "checking for inline... " >&6; }
+if test "${ac_cv_c_inline+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_c_inline=no
+for ac_kw in inline __inline__ __inline; do
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifndef __cplusplus
+typedef int foo_t;
+static $ac_kw foo_t static_foo () {return 0; }
+$ac_kw foo_t foo () {return 0; }
+#endif
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_c_inline=$ac_kw
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  test "$ac_cv_c_inline" != no && break
+done
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5
+$as_echo "$ac_cv_c_inline" >&6; }
+
+case $ac_cv_c_inline in
+  inline | yes) ;;
+  *)
+    case $ac_cv_c_inline in
+      no) ac_val=;;
+      *) ac_val=$ac_cv_c_inline;;
+    esac
+    cat >>confdefs.h <<_ACEOF
+#ifndef __cplusplus
+#define inline $ac_val
+#endif
+_ACEOF
+    ;;
+esac
+
+ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default"
+if test "x$ac_cv_type_size_t" = x""yes; then :
+
+else
+
+cat >>confdefs.h <<_ACEOF
+#define size_t unsigned int
+_ACEOF
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether struct tm is in sys/time.h or time.h" >&5
+$as_echo_n "checking whether struct tm is in sys/time.h or time.h... " >&6; }
+if test "${ac_cv_struct_tm+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <time.h>
+
+int
+main ()
+{
+struct tm tm;
+                                    int *p = &tm.tm_sec;
+                                    return !p;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_struct_tm=time.h
+else
+  ac_cv_struct_tm=sys/time.h
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_struct_tm" >&5
+$as_echo "$ac_cv_struct_tm" >&6; }
+if test $ac_cv_struct_tm = sys/time.h; then
+
+$as_echo "#define TM_IN_SYS_TIME 1" >>confdefs.h
+
+fi
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5
+$as_echo_n "checking whether byte ordering is bigendian... " >&6; }
+if test "${ac_cv_c_bigendian+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_c_bigendian=unknown
+    # See if we're dealing with a universal compiler.
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifndef __APPLE_CC__
+              not a universal capable compiler
+            #endif
+            typedef int dummy;
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+       # Check for potential -arch flags.  It is not universal unless
+       # there are at least two -arch flags with different values.
+       ac_arch=
+       ac_prev=
+       for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
+        if test -n "$ac_prev"; then
+          case $ac_word in
+            i?86 | x86_64 | ppc | ppc64)
+              if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then
+                ac_arch=$ac_word
+              else
+                ac_cv_c_bigendian=universal
+                break
+              fi
+              ;;
+          esac
+          ac_prev=
+        elif test "x$ac_word" = "x-arch"; then
+          ac_prev=arch
+        fi
+       done
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    if test $ac_cv_c_bigendian = unknown; then
+      # See if sys/param.h defines the BYTE_ORDER macro.
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+            #include <sys/param.h>
+
+int
+main ()
+{
+#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
+                    && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
+                    && LITTLE_ENDIAN)
+             bogus endian macros
+            #endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  # It does; now see whether it defined to BIG_ENDIAN or not.
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+               #include <sys/param.h>
+
+int
+main ()
+{
+#if BYTE_ORDER != BIG_ENDIAN
+                not big endian
+               #endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_c_bigendian=yes
+else
+  ac_cv_c_bigendian=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    fi
+    if test $ac_cv_c_bigendian = unknown; then
+      # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <limits.h>
+
+int
+main ()
+{
+#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
+             bogus endian macros
+            #endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  # It does; now see whether it defined to _BIG_ENDIAN or not.
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <limits.h>
+
+int
+main ()
+{
+#ifndef _BIG_ENDIAN
+                not big endian
+               #endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_c_bigendian=yes
+else
+  ac_cv_c_bigendian=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    fi
+    if test $ac_cv_c_bigendian = unknown; then
+      # Compile a test program.
+      if test "$cross_compiling" = yes; then :
+  # Try to guess by grepping values from an object file.
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+short int ascii_mm[] =
+                 { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
+               short int ascii_ii[] =
+                 { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
+               int use_ascii (int i) {
+                 return ascii_mm[i] + ascii_ii[i];
+               }
+               short int ebcdic_ii[] =
+                 { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
+               short int ebcdic_mm[] =
+                 { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
+               int use_ebcdic (int i) {
+                 return ebcdic_mm[i] + ebcdic_ii[i];
+               }
+               extern int foo;
+
+int
+main ()
+{
+return use_ascii (foo) == use_ebcdic (foo);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
+             ac_cv_c_bigendian=yes
+           fi
+           if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
+             if test "$ac_cv_c_bigendian" = unknown; then
+               ac_cv_c_bigendian=no
+             else
+               # finding both strings is unlikely to happen, but who knows?
+               ac_cv_c_bigendian=unknown
+             fi
+           fi
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+
+            /* Are we little or big endian?  From Harbison&Steele.  */
+            union
+            {
+              long int l;
+              char c[sizeof (long int)];
+            } u;
+            u.l = 1;
+            return u.c[sizeof (long int) - 1] == 1;
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  ac_cv_c_bigendian=no
+else
+  ac_cv_c_bigendian=yes
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+    fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5
+$as_echo "$ac_cv_c_bigendian" >&6; }
+ case $ac_cv_c_bigendian in #(
+   yes)
+     $as_echo "#define WORDS_BIGENDIAN 1" >>confdefs.h
+;; #(
+   no)
+      ;; #(
+   universal)
+
+$as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h
+
+     ;; #(
+   *)
+     as_fn_error "unknown endianness
+ presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;;
+ esac
+
+
+# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
+# for constant arguments.  Useless!
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working alloca.h" >&5
+$as_echo_n "checking for working alloca.h... " >&6; }
+if test "${ac_cv_working_alloca_h+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <alloca.h>
+int
+main ()
+{
+char *p = (char *) alloca (2 * sizeof (int));
+                         if (p) return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_working_alloca_h=yes
+else
+  ac_cv_working_alloca_h=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_working_alloca_h" >&5
+$as_echo "$ac_cv_working_alloca_h" >&6; }
+if test $ac_cv_working_alloca_h = yes; then
+
+$as_echo "#define HAVE_ALLOCA_H 1" >>confdefs.h
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for alloca" >&5
+$as_echo_n "checking for alloca... " >&6; }
+if test "${ac_cv_func_alloca_works+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __GNUC__
+# define alloca __builtin_alloca
+#else
+# ifdef _MSC_VER
+#  include <malloc.h>
+#  define alloca _alloca
+# else
+#  ifdef HAVE_ALLOCA_H
+#   include <alloca.h>
+#  else
+#   ifdef _AIX
+ #pragma alloca
+#   else
+#    ifndef alloca /* predefined by HP cc +Olibcalls */
+char *alloca ();
+#    endif
+#   endif
+#  endif
+# endif
+#endif
+
+int
+main ()
+{
+char *p = (char *) alloca (1);
+                                   if (p) return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_func_alloca_works=yes
+else
+  ac_cv_func_alloca_works=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_alloca_works" >&5
+$as_echo "$ac_cv_func_alloca_works" >&6; }
+
+if test $ac_cv_func_alloca_works = yes; then
+
+$as_echo "#define HAVE_ALLOCA 1" >>confdefs.h
+
+else
+  # The SVR3 libPW and SVR4 libucb both contain incompatible functions
+# that cause trouble.  Some versions do not even contain alloca or
+# contain a buggy version.  If you still want to use their alloca,
+# use ar to extract alloca.o from them instead of compiling alloca.c.
+
+ALLOCA=\${LIBOBJDIR}alloca.$ac_objext
+
+$as_echo "#define C_ALLOCA 1" >>confdefs.h
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether \`alloca.c' needs Cray hooks" >&5
+$as_echo_n "checking whether \`alloca.c' needs Cray hooks... " >&6; }
+if test "${ac_cv_os_cray+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#if defined CRAY && ! defined CRAY2
+webecray
+#else
+wenotbecray
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "webecray" >/dev/null 2>&1; then :
+  ac_cv_os_cray=yes
+else
+  ac_cv_os_cray=no
+fi
+rm -f conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_os_cray" >&5
+$as_echo "$ac_cv_os_cray" >&6; }
+if test $ac_cv_os_cray = yes; then
+  for ac_func in _getb67 GETB67 getb67; do
+    as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+eval as_val=\$$as_ac_var
+   if test "x$as_val" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define CRAY_STACKSEG_END $ac_func
+_ACEOF
+
+    break
+fi
+
+  done
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking stack direction for C alloca" >&5
+$as_echo_n "checking stack direction for C alloca... " >&6; }
+if test "${ac_cv_c_stack_direction+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "$cross_compiling" = yes; then :
+  ac_cv_c_stack_direction=0
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$ac_includes_default
+int
+find_stack_direction ()
+{
+  static char *addr = 0;
+  auto char dummy;
+  if (addr == 0)
+    {
+      addr = &dummy;
+      return find_stack_direction ();
+    }
+  else
+    return (&dummy > addr) ? 1 : -1;
+}
+
+int
+main ()
+{
+  return find_stack_direction () < 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  ac_cv_c_stack_direction=1
+else
+  ac_cv_c_stack_direction=-1
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_stack_direction" >&5
+$as_echo "$ac_cv_c_stack_direction" >&6; }
+cat >>confdefs.h <<_ACEOF
+#define STACK_DIRECTION $ac_cv_c_stack_direction
+_ACEOF
+
+
+fi
+
+for ac_header in stdlib.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "stdlib.h" "ac_cv_header_stdlib_h" "$ac_includes_default"
+if test "x$ac_cv_header_stdlib_h" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_STDLIB_H 1
+_ACEOF
+
+fi
+
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU libc compatible malloc" >&5
+$as_echo_n "checking for GNU libc compatible malloc... " >&6; }
+if test "${ac_cv_func_malloc_0_nonnull+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "$cross_compiling" = yes; then :
+  ac_cv_func_malloc_0_nonnull=no
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#if defined STDC_HEADERS || defined HAVE_STDLIB_H
+# include <stdlib.h>
+#else
+char *malloc ();
+#endif
+
+int
+main ()
+{
+return ! malloc (0);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  ac_cv_func_malloc_0_nonnull=yes
+else
+  ac_cv_func_malloc_0_nonnull=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_malloc_0_nonnull" >&5
+$as_echo "$ac_cv_func_malloc_0_nonnull" >&6; }
+if test $ac_cv_func_malloc_0_nonnull = yes; then :
+
+$as_echo "#define HAVE_MALLOC 1" >>confdefs.h
+
+else
+  $as_echo "#define HAVE_MALLOC 0" >>confdefs.h
+
+   case " $LIBOBJS " in
+  *" malloc.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS malloc.$ac_objext"
+ ;;
+esac
+
+
+$as_echo "#define malloc rpl_malloc" >>confdefs.h
+
+fi
+
+
+for ac_header in stdlib.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "stdlib.h" "ac_cv_header_stdlib_h" "$ac_includes_default"
+if test "x$ac_cv_header_stdlib_h" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_STDLIB_H 1
+_ACEOF
+
+fi
+
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU libc compatible realloc" >&5
+$as_echo_n "checking for GNU libc compatible realloc... " >&6; }
+if test "${ac_cv_func_realloc_0_nonnull+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "$cross_compiling" = yes; then :
+  ac_cv_func_realloc_0_nonnull=no
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#if defined STDC_HEADERS || defined HAVE_STDLIB_H
+# include <stdlib.h>
+#else
+char *realloc ();
+#endif
+
+int
+main ()
+{
+return ! realloc (0, 0);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  ac_cv_func_realloc_0_nonnull=yes
+else
+  ac_cv_func_realloc_0_nonnull=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_realloc_0_nonnull" >&5
+$as_echo "$ac_cv_func_realloc_0_nonnull" >&6; }
+if test $ac_cv_func_realloc_0_nonnull = yes; then :
+
+$as_echo "#define HAVE_REALLOC 1" >>confdefs.h
+
+else
+  $as_echo "#define HAVE_REALLOC 0" >>confdefs.h
+
+   case " $LIBOBJS " in
+  *" realloc.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS realloc.$ac_objext"
+ ;;
+esac
+
+
+$as_echo "#define realloc rpl_realloc" >>confdefs.h
+
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working memcmp" >&5
+$as_echo_n "checking for working memcmp... " >&6; }
+if test "${ac_cv_func_memcmp_working+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "$cross_compiling" = yes; then :
+  ac_cv_func_memcmp_working=no
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+
+  /* Some versions of memcmp are not 8-bit clean.  */
+  char c0 = '\100', c1 = '\200', c2 = '\201';
+  if (memcmp(&c0, &c2, 1) >= 0 || memcmp(&c1, &c2, 1) >= 0)
+    return 1;
+
+  /* The Next x86 OpenStep bug shows up only when comparing 16 bytes
+     or more and with at least one buffer not starting on a 4-byte boundary.
+     William Lewis provided this test program.   */
+  {
+    char foo[21];
+    char bar[21];
+    int i;
+    for (i = 0; i < 4; i++)
+      {
+       char *a = foo + i;
+       char *b = bar + i;
+       strcpy (a, "--------01111111");
+       strcpy (b, "--------10000000");
+       if (memcmp (a, b, 16) >= 0)
+         return 1;
+      }
+    return 0;
+  }
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  ac_cv_func_memcmp_working=yes
+else
+  ac_cv_func_memcmp_working=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_memcmp_working" >&5
+$as_echo "$ac_cv_func_memcmp_working" >&6; }
+test $ac_cv_func_memcmp_working = no && case " $LIBOBJS " in
+  *" memcmp.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS memcmp.$ac_objext"
+ ;;
+esac
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether lstat dereferences a symlink specified with a trailing slash" >&5
+$as_echo_n "checking whether lstat dereferences a symlink specified with a trailing slash... " >&6; }
+if test "${ac_cv_func_lstat_dereferences_slashed_symlink+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  rm -f conftest.sym conftest.file
+echo >conftest.file
+if test "$as_ln_s" = "ln -s" && ln -s conftest.file conftest.sym; then
+  if test "$cross_compiling" = yes; then :
+  ac_cv_func_lstat_dereferences_slashed_symlink=no
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+struct stat sbuf;
+     /* Linux will dereference the symlink and fail.
+       That is better in the sense that it means we will not
+       have to compile and use the lstat wrapper.  */
+     return lstat ("conftest.sym/", &sbuf) == 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  ac_cv_func_lstat_dereferences_slashed_symlink=yes
+else
+  ac_cv_func_lstat_dereferences_slashed_symlink=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+else
+  # If the `ln -s' command failed, then we probably don't even
+  # have an lstat function.
+  ac_cv_func_lstat_dereferences_slashed_symlink=no
+fi
+rm -f conftest.sym conftest.file
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_lstat_dereferences_slashed_symlink" >&5
+$as_echo "$ac_cv_func_lstat_dereferences_slashed_symlink" >&6; }
+
+test $ac_cv_func_lstat_dereferences_slashed_symlink = yes &&
+
+cat >>confdefs.h <<_ACEOF
+#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1
+_ACEOF
+
+
+if test $ac_cv_func_lstat_dereferences_slashed_symlink = no; then
+  case " $LIBOBJS " in
+  *" lstat.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS lstat.$ac_objext"
+ ;;
+esac
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stat accepts an empty string" >&5
+$as_echo_n "checking whether stat accepts an empty string... " >&6; }
+if test "${ac_cv_func_stat_empty_string_bug+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "$cross_compiling" = yes; then :
+  ac_cv_func_stat_empty_string_bug=yes
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+struct stat sbuf;
+  return stat ("", &sbuf) == 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  ac_cv_func_stat_empty_string_bug=no
+else
+  ac_cv_func_stat_empty_string_bug=yes
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_stat_empty_string_bug" >&5
+$as_echo "$ac_cv_func_stat_empty_string_bug" >&6; }
+if test $ac_cv_func_stat_empty_string_bug = yes; then
+  case " $LIBOBJS " in
+  *" stat.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS stat.$ac_objext"
+ ;;
+esac
+
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STAT_EMPTY_STRING_BUG 1
+_ACEOF
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working strcoll" >&5
+$as_echo_n "checking for working strcoll... " >&6; }
+if test "${ac_cv_func_strcoll_works+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "$cross_compiling" = yes; then :
+  ac_cv_func_strcoll_works=no
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+return (strcoll ("abc", "def") >= 0 ||
+        strcoll ("ABC", "DEF") >= 0 ||
+        strcoll ("123", "456") >= 0)
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  ac_cv_func_strcoll_works=yes
+else
+  ac_cv_func_strcoll_works=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_strcoll_works" >&5
+$as_echo "$ac_cv_func_strcoll_works" >&6; }
+if test $ac_cv_func_strcoll_works = yes; then
+
+$as_echo "#define HAVE_STRCOLL 1" >>confdefs.h
+
+fi
+
+for ac_func in strftime
+do :
+  ac_fn_c_check_func "$LINENO" "strftime" "ac_cv_func_strftime"
+if test "x$ac_cv_func_strftime" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_STRFTIME 1
+_ACEOF
+
+else
+  # strftime is in -lintl on SCO UNIX.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for strftime in -lintl" >&5
+$as_echo_n "checking for strftime in -lintl... " >&6; }
+if test "${ac_cv_lib_intl_strftime+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lintl  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char strftime ();
+int
+main ()
+{
+return strftime ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_intl_strftime=yes
+else
+  ac_cv_lib_intl_strftime=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_intl_strftime" >&5
+$as_echo "$ac_cv_lib_intl_strftime" >&6; }
+if test "x$ac_cv_lib_intl_strftime" = x""yes; then :
+  $as_echo "#define HAVE_STRFTIME 1" >>confdefs.h
+
+LIBS="-lintl $LIBS"
+fi
+
+fi
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working strtod" >&5
+$as_echo_n "checking for working strtod... " >&6; }
+if test "${ac_cv_func_strtod+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "$cross_compiling" = yes; then :
+  ac_cv_func_strtod=no
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+$ac_includes_default
+#ifndef strtod
+double strtod ();
+#endif
+int
+main()
+{
+  {
+    /* Some versions of Linux strtod mis-parse strings with leading '+'.  */
+    char *string = " +69";
+    char *term;
+    double value;
+    value = strtod (string, &term);
+    if (value != 69 || term != (string + 4))
+      return 1;
+  }
+
+  {
+    /* Under Solaris 2.4, strtod returns the wrong value for the
+       terminating character under some conditions.  */
+    char *string = "NaN";
+    char *term;
+    strtod (string, &term);
+    if (term != string && *(term - 1) == 0)
+      return 1;
+  }
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  ac_cv_func_strtod=yes
+else
+  ac_cv_func_strtod=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_strtod" >&5
+$as_echo "$ac_cv_func_strtod" >&6; }
+if test $ac_cv_func_strtod = no; then
+  case " $LIBOBJS " in
+  *" strtod.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS strtod.$ac_objext"
+ ;;
+esac
+
+ac_fn_c_check_func "$LINENO" "pow" "ac_cv_func_pow"
+if test "x$ac_cv_func_pow" = x""yes; then :
+
+fi
+
+if test $ac_cv_func_pow = no; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pow in -lm" >&5
+$as_echo_n "checking for pow in -lm... " >&6; }
+if test "${ac_cv_lib_m_pow+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lm  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char pow ();
+int
+main ()
+{
+return pow ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_m_pow=yes
+else
+  ac_cv_lib_m_pow=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_pow" >&5
+$as_echo "$ac_cv_lib_m_pow" >&6; }
+if test "x$ac_cv_lib_m_pow" = x""yes; then :
+  POW_LIB=-lm
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cannot find library containing definition of pow" >&5
+$as_echo "$as_me: WARNING: cannot find library containing definition of pow" >&2;}
+fi
+
+fi
+
+fi
+
+for ac_func in memmove memset nl_langinfo putenv regcomp setlocale
+do :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+eval as_val=\$$as_ac_var
+   if test "x$as_val" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+for ac_func in strchr strdup gettimeofday
+do :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+eval as_val=\$$as_ac_var
+   if test "x$as_val" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
+
+# Extract the first word of "m17n-db", so it can be a program name with args.
+set dummy m17n-db; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_HAVE_M17N_DB+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$HAVE_M17N_DB"; then
+  ac_cv_prog_HAVE_M17N_DB="$HAVE_M17N_DB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_HAVE_M17N_DB="yes"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+HAVE_M17N_DB=$ac_cv_prog_HAVE_M17N_DB
+if test -n "$HAVE_M17N_DB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAVE_M17N_DB" >&5
+$as_echo "$HAVE_M17N_DB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+if test "x$HAVE_M17N_DB" = "xyes"; then
+  M17NDIR=`m17n-db`
+else
+  M17NDIR="${datadir}/m17n"
+fi
+
+
+
+# Check whether --enable-gui was given.
+if test "${enable_gui+set}" = set; then :
+  enableval=$enable_gui;
+fi
+
+
+ if test x$with_gui != xno; then
+  WITH_GUI_TRUE=
+  WITH_GUI_FALSE='#'
+else
+  WITH_GUI_TRUE='#'
+  WITH_GUI_FALSE=
+fi
+
+
+if test x$with_gui != xno; then
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing dlopen" >&5
+$as_echo_n "checking for library containing dlopen... " >&6; }
+if test "${ac_cv_search_dlopen+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' dl; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_dlopen=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if test "${ac_cv_search_dlopen+set}" = set; then :
+  break
+fi
+done
+if test "${ac_cv_search_dlopen+set}" = set; then :
+
+else
+  ac_cv_search_dlopen=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_dlopen" >&5
+$as_echo "$ac_cv_search_dlopen" >&6; }
+ac_res=$ac_cv_search_dlopen
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+$as_echo "#define HAVE_DLOPEN 1" >>confdefs.h
+
+fi
+
+
+
+M17N_EXT_LIBS=
+
+# Extract the first word of "pkg-config", so it can be a program name with args.
+set dummy pkg-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_HAVE_PKG_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$HAVE_PKG_CONFIG"; then
+  ac_cv_prog_HAVE_PKG_CONFIG="$HAVE_PKG_CONFIG" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_HAVE_PKG_CONFIG="yes"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+HAVE_PKG_CONFIG=$ac_cv_prog_HAVE_PKG_CONFIG
+if test -n "$HAVE_PKG_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAVE_PKG_CONFIG" >&5
+$as_echo "$HAVE_PKG_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
+if test "x$no_x" != "xyes"; then
+
+$as_echo "#define HAVE_X11 1" >>confdefs.h
+
+  X11_LD_FLAGS="-lXt -lX11"
+  M17N_EXT_LIBS="$M17N_EXT_LIBS X11"
+
+  if test "x$HAVE_XAW" = "xyes"; then
+
+$as_echo "#define HAVE_X11_XAW_COMMAND_H 1" >>confdefs.h
+
+    XAW_LD_FLAGS="-lXaw -lXmu"
+    CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_X11_XAW_COMMAND_H"
+    M17N_EXT_LIBS="$M17N_EXT_LIBS Xaw"
+  fi
+fi
+
+
+
+save_CPPFLAGS="$CPPFLAGS"
+save_LIBS="$LIBS"
+# Extract the first word of "fribidi-config", so it can be a program name with args.
+set dummy fribidi-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_HAVE_FRIBIDI_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$HAVE_FRIBIDI_CONFIG"; then
+  ac_cv_prog_HAVE_FRIBIDI_CONFIG="$HAVE_FRIBIDI_CONFIG" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_HAVE_FRIBIDI_CONFIG="yes"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+HAVE_FRIBIDI_CONFIG=$ac_cv_prog_HAVE_FRIBIDI_CONFIG
+if test -n "$HAVE_FRIBIDI_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAVE_FRIBIDI_CONFIG" >&5
+$as_echo "$HAVE_FRIBIDI_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+if test "x$HAVE_FRIBIDI_CONFIG" = "xyes"; then
+  CPPFLAGS="$CPPFLAGS `fribidi-config --cflags`"
+  FRIBIDI_LD_FLAGS="`fribidi-config --libs`"
+  LIBS="$LIBS $FRIBIDI_LD_FLAGS"
+else
+  FRIBIDI_LD_FLAGS=-lfribidi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fribidi_set_mirroring in -lfribidi" >&5
+$as_echo_n "checking for fribidi_set_mirroring in -lfribidi... " >&6; }
+if test "${ac_cv_lib_fribidi_fribidi_set_mirroring+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lfribidi  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char fribidi_set_mirroring ();
+int
+main ()
+{
+return fribidi_set_mirroring ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_fribidi_fribidi_set_mirroring=yes
+else
+  ac_cv_lib_fribidi_fribidi_set_mirroring=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_fribidi_fribidi_set_mirroring" >&5
+$as_echo "$ac_cv_lib_fribidi_fribidi_set_mirroring" >&6; }
+if test "x$ac_cv_lib_fribidi_fribidi_set_mirroring" = x""yes; then :
+  HAVE_FRIBIDI=yes
+else
+  HAVE_FRIBIDI=no
+fi
+
+ac_fn_c_check_header_mongrel "$LINENO" "fribidi/fribidi.h" "ac_cv_header_fribidi_fribidi_h" "$ac_includes_default"
+if test "x$ac_cv_header_fribidi_fribidi_h" = x""yes; then :
+
+else
+  HAVE_FRIBIDI=no
+fi
+
+
+if test "x$HAVE_FRIBIDI" = "xyes"; then
+
+$as_echo "#define HAVE_FRIBIDI 1" >>confdefs.h
+
+  M17N_EXT_LIBS="$M17N_EXT_LIBS fribidi"
+else
+  CPPFLAGS="$save_CPPFLAGS"
+  FRIBIDI_LD_FLAGS=
+fi
+LIBS="$save_LIBS"
+
+
+
+# Check whether --with-libotf was given.
+if test "${with_libotf+set}" = set; then :
+  withval=$with_libotf;
+fi
+
+
+if test "x$with_libotf" != "xno"; then
+  save_CPPFLAGS="$CPPFLAGS"
+  save_LIBS="$LIBS"
+  # Extract the first word of "libotf-config", so it can be a program name with args.
+set dummy libotf-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_HAVE_OTFLIB_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$HAVE_OTFLIB_CONFIG"; then
+  ac_cv_prog_HAVE_OTFLIB_CONFIG="$HAVE_OTFLIB_CONFIG" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_HAVE_OTFLIB_CONFIG="yes"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+HAVE_OTFLIB_CONFIG=$ac_cv_prog_HAVE_OTFLIB_CONFIG
+if test -n "$HAVE_OTFLIB_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAVE_OTFLIB_CONFIG" >&5
+$as_echo "$HAVE_OTFLIB_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  if test "x$HAVE_OTFLIB_CONFIG" = "xyes"; then
+    CPPFLAGS="$CPPFLAGS `libotf-config --cflags`"
+    OTF_LD_FLAGS="`libotf-config --libs`"
+    LIBS="$LIBS $OTF_LD_FLAGS"
+  else
+    OTF_LD_FLAGS=-lotf
+  fi
+  ## We check the availability of OTF_check_features
+  ## because we need libotf-0.9.4 or the later.
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for OTF_check_features in -lotf" >&5
+$as_echo_n "checking for OTF_check_features in -lotf... " >&6; }
+if test "${ac_cv_lib_otf_OTF_check_features+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lotf  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char OTF_check_features ();
+int
+main ()
+{
+return OTF_check_features ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_otf_OTF_check_features=yes
+else
+  ac_cv_lib_otf_OTF_check_features=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_otf_OTF_check_features" >&5
+$as_echo "$ac_cv_lib_otf_OTF_check_features" >&6; }
+if test "x$ac_cv_lib_otf_OTF_check_features" = x""yes; then :
+  HAVE_OTF=yes
+else
+  HAVE_OTF=no
+fi
+
+  ac_fn_c_check_header_mongrel "$LINENO" "otf.h" "ac_cv_header_otf_h" "$ac_includes_default"
+if test "x$ac_cv_header_otf_h" = x""yes; then :
+
+else
+  HAVE_OTF=no
+fi
+
+
+  if test "x$HAVE_OTF" = "xyes"; then
+
+$as_echo "#define HAVE_OTF 1" >>confdefs.h
+
+    M17N_EXT_LIBS="$M17N_EXT_LIBS libotf"
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for OTF_drive_gpos2 in -lotf" >&5
+$as_echo_n "checking for OTF_drive_gpos2 in -lotf... " >&6; }
+if test "${ac_cv_lib_otf_OTF_drive_gpos2+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lotf  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char OTF_drive_gpos2 ();
+int
+main ()
+{
+return OTF_drive_gpos2 ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_otf_OTF_drive_gpos2=yes
+else
+  ac_cv_lib_otf_OTF_drive_gpos2=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_otf_OTF_drive_gpos2" >&5
+$as_echo "$ac_cv_lib_otf_OTF_drive_gpos2" >&6; }
+if test "x$ac_cv_lib_otf_OTF_drive_gpos2" = x""yes; then :
+  HAVE_OTF_DRIVE_GPOS2=yes
+else
+  HAVE_OTF_DRIVE_GPOS2=no
+fi
+
+    if test "x$HAVE_OTF_DRIVE_GPOS2" = "xyes"; then
+
+$as_echo "#define HAVE_OTF_DRIVE_GPOS2 1" >>confdefs.h
+
+    fi
+  else
+    CPPFLAGS="$save_CPPFLAGS"
+    OTF_LD_FLAGS=
+  fi
+  LIBS="$save_LIBS"
+fi
+
+
+# Extract the first word of "freetype-config", so it can be a program name with args.
+set dummy freetype-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_HAVE_FREETYPE_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$HAVE_FREETYPE_CONFIG"; then
+  ac_cv_prog_HAVE_FREETYPE_CONFIG="$HAVE_FREETYPE_CONFIG" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_HAVE_FREETYPE_CONFIG="yes"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+HAVE_FREETYPE_CONFIG=$ac_cv_prog_HAVE_FREETYPE_CONFIG
+if test -n "$HAVE_FREETYPE_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAVE_FREETYPE_CONFIG" >&5
+$as_echo "$HAVE_FREETYPE_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+if test "x$HAVE_FREETYPE_CONFIG" = "xyes"; then
+  FREETYPE_INC=`freetype-config --cflags`
+  save_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $FREETYPE_INC"
+  ac_fn_c_check_header_mongrel "$LINENO" "ft2build.h" "ac_cv_header_ft2build_h" "$ac_includes_default"
+if test "x$ac_cv_header_ft2build_h" = x""yes; then :
+  HAVE_FREETYPE=yes
+else
+  HAVE_FREETYPE=no CPPFLAGS="$save_CPPFLAGS"
+fi
+
+
+  if test "x$HAVE_FREETYPE" = "xyes" ; then
+    save_LIBS="$LIBS"
+    LIBS="$LIBS `freetype-config --libs`"
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for FT_Init_FreeType in -lfreetype" >&5
+$as_echo_n "checking for FT_Init_FreeType in -lfreetype... " >&6; }
+if test "${ac_cv_lib_freetype_FT_Init_FreeType+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lfreetype  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char FT_Init_FreeType ();
+int
+main ()
+{
+return FT_Init_FreeType ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_freetype_FT_Init_FreeType=yes
+else
+  ac_cv_lib_freetype_FT_Init_FreeType=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_freetype_FT_Init_FreeType" >&5
+$as_echo "$ac_cv_lib_freetype_FT_Init_FreeType" >&6; }
+if test "x$ac_cv_lib_freetype_FT_Init_FreeType" = x""yes; then :
+  HAVE_FREETYPE=yes
+else
+  HAVE_FREETYPE=no
+fi
+
+    LIBS="$save_LIBS"
+    if test "x$HAVE_FREETYPE" = "xyes"; then
+      FREETYPE_LD_FLAGS=`freetype-config --libs`
+
+$as_echo "#define HAVE_FREETYPE 1" >>confdefs.h
+
+      M17N_EXT_LIBS="$M17N_EXT_LIBS freetype"
+      ac_fn_c_check_header_compile "$LINENO" "freetype/ftbdf.h" "ac_cv_header_freetype_ftbdf_h" "#include <ft2build.h>
+#include FT_FREETYPE_H
+"
+if test "x$ac_cv_header_freetype_ftbdf_h" = x""yes; then :
+  HAVE_FTBDF_H=yes
+else
+  HAVE_FTBDF_H=no
+fi
+
+
+      if test "x$HAVE_FTBDF_H" = "xyes"; then
+
+$as_echo "#define HAVE_FTBDF_H 1" >>confdefs.h
+
+      fi
+      CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_FREETYPE"
+    fi
+  fi
+fi
+
+
+save_CPPFLAGS="$CPPFLAGS"
+save_LIBS="$LIBS"
+XFT2_LD_FLAGS="-lXft -lfreetype -lfontconfig -lXrender -lX11"
+# Extract the first word of "xft-config", so it can be a program name with args.
+set dummy xft-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_HAVE_XFT_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$HAVE_XFT_CONFIG"; then
+  ac_cv_prog_HAVE_XFT_CONFIG="$HAVE_XFT_CONFIG" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_HAVE_XFT_CONFIG="yes"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+HAVE_XFT_CONFIG=$ac_cv_prog_HAVE_XFT_CONFIG
+if test -n "$HAVE_XFT_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAVE_XFT_CONFIG" >&5
+$as_echo "$HAVE_XFT_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+if test "x$HAVE_XFT_CONFIG" = "xyes"; then
+  CPPFLAGS="$CPPFLAGS `xft-config --cflags`"
+  XFT2_LD_FLAGS="`xft-config --libs`"
+elif test "x$HAVE_PKG_CONFIG" = "xyes" ; then
+  if pkg-config xft ; then
+    CPPFLAGS="$CPPFLAGS `pkg-config --cflags xft`"
+    XFT2_LD_FLAGS="`pkg-config --libs xft`"
+  fi
+fi
+LIBS="$LIBS $XFT2_LD_FLAGS"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XftDrawCreate in -lXft" >&5
+$as_echo_n "checking for XftDrawCreate in -lXft... " >&6; }
+if test "${ac_cv_lib_Xft_XftDrawCreate+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lXft  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char XftDrawCreate ();
+int
+main ()
+{
+return XftDrawCreate ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_Xft_XftDrawCreate=yes
+else
+  ac_cv_lib_Xft_XftDrawCreate=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_Xft_XftDrawCreate" >&5
+$as_echo "$ac_cv_lib_Xft_XftDrawCreate" >&6; }
+if test "x$ac_cv_lib_Xft_XftDrawCreate" = x""yes; then :
+  HAVE_XFT2=yes
+else
+  HAVE_XFT2=no
+fi
+
+ac_fn_c_check_header_compile "$LINENO" "X11/Xft/Xft.h" "ac_cv_header_X11_Xft_Xft_h" "#include <X11/Xft/Xft.h>
+#if XftVersion >= 20000
+#else
+Version too old.  Compiling this line should fail.
+#endif
+"
+if test "x$ac_cv_header_X11_Xft_Xft_h" = x""yes; then :
+
+else
+  HAVE_XFT2=no
+fi
+
+
+if test "x$HAVE_XFT2" = "xyes"; then
+
+$as_echo "#define HAVE_XFT2 1" >>confdefs.h
+
+  M17N_EXT_LIBS="$M17N_EXT_LIBS xft2"
+else
+  XFT2_LD_FLAGS=
+  CPPFLAGS="$save_CPPFLAGS"
+fi
+LIBS="$save_LIBS"
+
+
+
+# Check whether --with-fontconfig was given.
+if test "${with_fontconfig+set}" = set; then :
+  withval=$with_fontconfig;
+fi
+
+if test "x$with_fontconfig" != "xno"; then
+  save_CPPFLAGS="$CPPFLAGS"
+  save_LIBS="$LIBS"
+  FONTCONFIG_LD_FLAGS=-lfontconfig
+  if test "x$HAVE_PKG_CONFIG" = "xyes"; then
+    if pkg-config --exists fontconfig; then
+      CPPFLAGS="$CPPFLAGS `pkg-config --cflags fontconfig`"
+      FONTCONFIG_LD_FLAGS="`pkg-config --libs fontconfig`"
+      LIBS="$LIBS $FONTCONFIG_LD_FLAGS"
+    fi
+  fi
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for FcInit in -lfontconfig" >&5
+$as_echo_n "checking for FcInit in -lfontconfig... " >&6; }
+if test "${ac_cv_lib_fontconfig_FcInit+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lfontconfig  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char FcInit ();
+int
+main ()
+{
+return FcInit ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_fontconfig_FcInit=yes
+else
+  ac_cv_lib_fontconfig_FcInit=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_fontconfig_FcInit" >&5
+$as_echo "$ac_cv_lib_fontconfig_FcInit" >&6; }
+if test "x$ac_cv_lib_fontconfig_FcInit" = x""yes; then :
+  HAVE_FONTCONFIG=yes
+else
+  HAVE_FONTCONFIG=no
+fi
+
+  ac_fn_c_check_header_mongrel "$LINENO" "fontconfig/fontconfig.h" "ac_cv_header_fontconfig_fontconfig_h" "$ac_includes_default"
+if test "x$ac_cv_header_fontconfig_fontconfig_h" = x""yes; then :
+
+else
+  HAVE_FONTCONFIG=no
+fi
+
+
+  if test "x$HAVE_FONTCONFIG" = "xyes"; then
+
+$as_echo "#define HAVE_FONTCONFIG 1" >>confdefs.h
+
+    M17N_EXT_LIBS="$M17N_EXT_LIBS fontconfig"
+  else
+    FONTCONFIG_LD_FLAGS=
+    CPPFLAGS="$save_CPPFLAGS"
+  fi
+  LIBS="$save_LIBS"
+fi
+
+
+
+# Check whether --with-gd was given.
+if test "${with_gd+set}" = set; then :
+  withval=$with_gd;
+fi
+
+
+if test "x$with_gd" != "xno"; then
+  save_LIBS="$LIBS"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gdImageCreate in -lgd" >&5
+$as_echo_n "checking for gdImageCreate in -lgd... " >&6; }
+if test "${ac_cv_lib_gd_gdImageCreate+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lgd  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char gdImageCreate ();
+int
+main ()
+{
+return gdImageCreate ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_gd_gdImageCreate=yes
+else
+  ac_cv_lib_gd_gdImageCreate=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gd_gdImageCreate" >&5
+$as_echo "$ac_cv_lib_gd_gdImageCreate" >&6; }
+if test "x$ac_cv_lib_gd_gdImageCreate" = x""yes; then :
+  HAVE_GD=yes
+else
+  HAVE_GD=no
+fi
+
+  ac_fn_c_check_header_mongrel "$LINENO" "gd.h" "ac_cv_header_gd_h" "$ac_includes_default"
+if test "x$ac_cv_header_gd_h" = x""yes; then :
+
+else
+  HAVE_GD=no
+fi
+
+
+  if test "x$HAVE_GD" = "xyes"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gdImageCreateTrueColor in -lgd" >&5
+$as_echo_n "checking for gdImageCreateTrueColor in -lgd... " >&6; }
+if test "${ac_cv_lib_gd_gdImageCreateTrueColor+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lgd  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char gdImageCreateTrueColor ();
+int
+main ()
+{
+return gdImageCreateTrueColor ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_gd_gdImageCreateTrueColor=yes
+else
+  ac_cv_lib_gd_gdImageCreateTrueColor=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gd_gdImageCreateTrueColor" >&5
+$as_echo "$ac_cv_lib_gd_gdImageCreateTrueColor" >&6; }
+if test "x$ac_cv_lib_gd_gdImageCreateTrueColor" = x""yes; then :
+  HAVE_GD=2
+else
+  HAVE_GD=1
+fi
+
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_GD $HAVE_GD
+_ACEOF
+
+    M17N_EXT_LIBS="$M17N_EXT_LIBS gdlib"
+    GD_LD_FLAGS=-lgd
+    CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_GD=$HAVE_GD"
+  fi
+  LIBS="$save_LIBS"
+fi
+
+
+fi
+
+save_CPPFLAGS="$CPPFLAGS"
+save_LIBS="$LIBS"
+# Extract the first word of "xml2-config", so it can be a program name with args.
+set dummy xml2-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_HAVE_XML2_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$HAVE_XML2_CONFIG"; then
+  ac_cv_prog_HAVE_XML2_CONFIG="$HAVE_XML2_CONFIG" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_HAVE_XML2_CONFIG="yes"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+HAVE_XML2_CONFIG=$ac_cv_prog_HAVE_XML2_CONFIG
+if test -n "$HAVE_XML2_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAVE_XML2_CONFIG" >&5
+$as_echo "$HAVE_XML2_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+if test "x$HAVE_XML2_CONFIG" = "xyes"; then
+  CPPFLAGS="$CPPFLAGS `xml2-config --cflags`"
+  XML2_LD_FLAGS="`xml2-config --libs`"
+  LIBS="$LIBS $XML2_LD_FLAGS"
+else
+  CPPFLAGS="$CPPFLAGS -I/usr/include/libxml2"
+  XML2_LD_FLAGS="-lxml2 -lz -lpthread -lm"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for xmlParseMemory in -lxml2" >&5
+$as_echo_n "checking for xmlParseMemory in -lxml2... " >&6; }
+if test "${ac_cv_lib_xml2_xmlParseMemory+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lxml2  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char xmlParseMemory ();
+int
+main ()
+{
+return xmlParseMemory ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_xml2_xmlParseMemory=yes
+else
+  ac_cv_lib_xml2_xmlParseMemory=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_xml2_xmlParseMemory" >&5
+$as_echo "$ac_cv_lib_xml2_xmlParseMemory" >&6; }
+if test "x$ac_cv_lib_xml2_xmlParseMemory" = x""yes; then :
+  HAVE_XML2=yes
+else
+  HAVE_XML2=no
+fi
+
+ac_fn_c_check_header_compile "$LINENO" "libxml/tree.h" "ac_cv_header_libxml_tree_h" "/**/
+"
+if test "x$ac_cv_header_libxml_tree_h" = x""yes; then :
+
+else
+  HAVE_XML2=no
+fi
+
+
+if test "x$HAVE_XML2" = "xyes"; then
+
+$as_echo "#define HAVE_XML2 1" >>confdefs.h
+
+  M17N_EXT_LIBS="$M17N_EXT_LIBS xml2"
+else
+  XML2_LD_FLAGS=
+  CPPFLAGS="$save_CPPFLAGS"
+fi
+LIBS="$save_LIBS"
+
+
+
+
+
+if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
+       if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args.
+set dummy ${ac_tool_prefix}pkg-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_PKG_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+PKG_CONFIG=$ac_cv_path_PKG_CONFIG
+if test -n "$PKG_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5
+$as_echo "$PKG_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_PKG_CONFIG"; then
+  ac_pt_PKG_CONFIG=$PKG_CONFIG
+  # Extract the first word of "pkg-config", so it can be a program name with args.
+set dummy pkg-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_ac_pt_PKG_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG
+if test -n "$ac_pt_PKG_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5
+$as_echo "$ac_pt_PKG_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_PKG_CONFIG" = x; then
+    PKG_CONFIG=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    PKG_CONFIG=$ac_pt_PKG_CONFIG
+  fi
+else
+  PKG_CONFIG="$ac_cv_path_PKG_CONFIG"
+fi
+
+fi
+if test -n "$PKG_CONFIG"; then
+       _pkg_min_version=0.9.0
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking pkg-config is at least version $_pkg_min_version" >&5
+$as_echo_n "checking pkg-config is at least version $_pkg_min_version... " >&6; }
+       if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+       else
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+               PKG_CONFIG=""
+       fi
+
+fi
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANTHY" >&5
+$as_echo_n "checking for ANTHY... " >&6; }
+
+if test -n "$PKG_CONFIG"; then
+    if test -n "$ANTHY_CFLAGS"; then
+        pkg_cv_ANTHY_CFLAGS="$ANTHY_CFLAGS"
+    else
+        if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"anthy\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "anthy") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_ANTHY_CFLAGS=`$PKG_CONFIG --cflags "anthy" 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+    fi
+else
+       pkg_failed=untried
+fi
+if test -n "$PKG_CONFIG"; then
+    if test -n "$ANTHY_LIBS"; then
+        pkg_cv_ANTHY_LIBS="$ANTHY_LIBS"
+    else
+        if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"anthy\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "anthy") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_ANTHY_LIBS=`$PKG_CONFIG --libs "anthy" 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+    fi
+else
+       pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+               ANTHY_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "anthy"`
+        else
+               ANTHY_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "anthy"`
+        fi
+       # Put the nasty error message in config.log where it belongs
+       echo "$ANTHY_PKG_ERRORS" >&5
+
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+                HAVE_ANTHY=no
+elif test $pkg_failed = untried; then
+       HAVE_ANTHY=no
+else
+       ANTHY_CFLAGS=$pkg_cv_ANTHY_CFLAGS
+       ANTHY_LIBS=$pkg_cv_ANTHY_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+       HAVE_ANTHY=yes
+fi
+if test "x$HAVE_ANTHY" = "xyes"; then
+
+$as_echo "#define HAVE_ANTHY 1" >>confdefs.h
+
+  M17N_EXT_LIBS="$M17N_EXT_LIBS anthy"
+  ANTHY_LD_FLAGS="$ANTHY_LIBS"
+  CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_ANTHY"
+fi
+
+
+# Extract the first word of "ispell", so it can be a program name with args.
+set dummy ispell; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_HAVE_ISPELL+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$HAVE_ISPELL"; then
+  ac_cv_prog_HAVE_ISPELL="$HAVE_ISPELL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_HAVE_ISPELL="yes"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+HAVE_ISPELL=$ac_cv_prog_HAVE_ISPELL
+if test -n "$HAVE_ISPELL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAVE_ISPELL" >&5
+$as_echo "$HAVE_ISPELL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+if test "x$HAVE_ISPELL" = "xyes"; then
+
+$as_echo "#define HAVE_ISPELL 1" >>confdefs.h
+
+  M17N_EXT_LIBS="$M17N_EXT_LIBS ispell"
+  CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_ISPELL"
+fi
+
+
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBTHAI" >&5
+$as_echo_n "checking for LIBTHAI... " >&6; }
+
+if test -n "$PKG_CONFIG"; then
+    if test -n "$LIBTHAI_CFLAGS"; then
+        pkg_cv_LIBTHAI_CFLAGS="$LIBTHAI_CFLAGS"
+    else
+        if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libthai\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libthai") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LIBTHAI_CFLAGS=`$PKG_CONFIG --cflags "libthai" 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+    fi
+else
+       pkg_failed=untried
+fi
+if test -n "$PKG_CONFIG"; then
+    if test -n "$LIBTHAI_LIBS"; then
+        pkg_cv_LIBTHAI_LIBS="$LIBTHAI_LIBS"
+    else
+        if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libthai\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libthai") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LIBTHAI_LIBS=`$PKG_CONFIG --libs "libthai" 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+    fi
+else
+       pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+               LIBTHAI_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "libthai"`
+        else
+               LIBTHAI_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "libthai"`
+        fi
+       # Put the nasty error message in config.log where it belongs
+       echo "$LIBTHAI_PKG_ERRORS" >&5
+
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+                HAVE_LIBTHAI=no
+elif test $pkg_failed = untried; then
+       HAVE_LIBTHAI=no
+else
+       LIBTHAI_CFLAGS=$pkg_cv_LIBTHAI_CFLAGS
+       LIBTHAI_LIBS=$pkg_cv_LIBTHAI_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+       HAVE_LIBTHAI=yes
+fi
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for WORDCUT" >&5
+$as_echo_n "checking for WORDCUT... " >&6; }
+
+if test -n "$PKG_CONFIG"; then
+    if test -n "$WORDCUT_CFLAGS"; then
+        pkg_cv_WORDCUT_CFLAGS="$WORDCUT_CFLAGS"
+    else
+        if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"wordcut\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "wordcut") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_WORDCUT_CFLAGS=`$PKG_CONFIG --cflags "wordcut" 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+    fi
+else
+       pkg_failed=untried
+fi
+if test -n "$PKG_CONFIG"; then
+    if test -n "$WORDCUT_LIBS"; then
+        pkg_cv_WORDCUT_LIBS="$WORDCUT_LIBS"
+    else
+        if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"wordcut\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "wordcut") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_WORDCUT_LIBS=`$PKG_CONFIG --libs "wordcut" 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+    fi
+else
+       pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+               WORDCUT_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "wordcut"`
+        else
+               WORDCUT_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "wordcut"`
+        fi
+       # Put the nasty error message in config.log where it belongs
+       echo "$WORDCUT_PKG_ERRORS" >&5
+
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+                HAVE_WORDCUT=no
+elif test $pkg_failed = untried; then
+       HAVE_WORDCUT=no
+else
+       WORDCUT_CFLAGS=$pkg_cv_WORDCUT_CFLAGS
+       WORDCUT_LIBS=$pkg_cv_WORDCUT_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+       HAVE_WORDCUT=yes
+fi
+
+if test "x$HAVE_LIBTHAI" == "xyes"; then
+
+
+$as_echo "#define HAVE_LIBTHAI 1" >>confdefs.h
+
+  THAI_WORDSEG_LD_FLAGS="$LIBTHAI_LIBS"
+  M17N_EXT_LIBS="$M17N_EXT_LIBS libthai"
+  HAVE_THAI_WORDSEG=yes
+
+elif test "x$HAVE_WORDCUT" = "xyes"; then
+
+  save_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $WORDCUT_CFLAGS"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <wordcut/wcwordcut.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+  HAVE_WORDCUT=no
+fi
+rm -f conftest.err conftest.$ac_ext
+  if test "x$HAVE_WORDCUT" = "xno"; then
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GLIB_2_0" >&5
+$as_echo_n "checking for GLIB_2_0... " >&6; }
+
+if test -n "$PKG_CONFIG"; then
+    if test -n "$GLIB_2_0_CFLAGS"; then
+        pkg_cv_GLIB_2_0_CFLAGS="$GLIB_2_0_CFLAGS"
+    else
+        if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"glib-2.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "glib-2.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GLIB_2_0_CFLAGS=`$PKG_CONFIG --cflags "glib-2.0" 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+    fi
+else
+       pkg_failed=untried
+fi
+if test -n "$PKG_CONFIG"; then
+    if test -n "$GLIB_2_0_LIBS"; then
+        pkg_cv_GLIB_2_0_LIBS="$GLIB_2_0_LIBS"
+    else
+        if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"glib-2.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "glib-2.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GLIB_2_0_LIBS=`$PKG_CONFIG --libs "glib-2.0" 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+    fi
+else
+       pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+               GLIB_2_0_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "glib-2.0"`
+        else
+               GLIB_2_0_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "glib-2.0"`
+        fi
+       # Put the nasty error message in config.log where it belongs
+       echo "$GLIB_2_0_PKG_ERRORS" >&5
+
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+                HAVE_GLIB_2_0=no
+elif test $pkg_failed = untried; then
+       HAVE_GLIB_2_0=no
+else
+       GLIB_2_0_CFLAGS=$pkg_cv_GLIB_2_0_CFLAGS
+       GLIB_2_0_LIBS=$pkg_cv_GLIB_2_0_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+       HAVE_GLIB_2_0=yes
+fi
+    if test "x$HAVE_GLIB_2_0" = "xyes"; then
+      CPPFLAGS="$CPPFLAGS $GLIB_2_0_CFLAGS"
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <wordcut/wcwordcut.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  HAVE_WORDCUT=yes
+fi
+rm -f conftest.err conftest.$ac_ext
+    fi
+  fi
+  if test "x$HAVE_WORDCUT" = "xyes"; then
+    THAI_WORDSEG_LD_FLAGS="$WORDCUT_LIBS"
+
+$as_echo "#define HAVE_WORDCUT 1" >>confdefs.h
+
+    M17N_EXT_LIBS="$M17N_EXT_LIBS wordcut"
+    HAVE_THAI_WORDSEG=yes
+  else
+    CPPFLAGS="$save_CPPFLAGS"
+  fi
+
+else
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for wordcut_init in -lwordcut" >&5
+$as_echo_n "checking for wordcut_init in -lwordcut... " >&6; }
+if test "${ac_cv_lib_wordcut_wordcut_init+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lwordcut  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char wordcut_init ();
+int
+main ()
+{
+return wordcut_init ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_wordcut_wordcut_init=yes
+else
+  ac_cv_lib_wordcut_wordcut_init=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_wordcut_wordcut_init" >&5
+$as_echo "$ac_cv_lib_wordcut_wordcut_init" >&6; }
+if test "x$ac_cv_lib_wordcut_wordcut_init" = x""yes; then :
+  HAVE_WORDCUT_OLD=yes
+fi
+
+  if test "x$HAVE_WORDCUT_OLD" = "xyes"; then
+    if test -f "/usr/share/wordcut/tdict.wcd"; then
+      tdict="/usr/share/wordcut/tdict.wcd"
+    elif test -f "/usr/local/share/wordcut/tdict.wcd"; then
+      tdict="/usr/local/share/wordcut/tdict.wcd"
+    fi
+    echo "TDICT=$tdict"
+    if test "x$tdict" != "x"; then
+
+$as_echo "#define HAVE_WORDCUT_OLD 1" >>confdefs.h
+
+
+cat >>confdefs.h <<_ACEOF
+#define WORDCUT_TDICT "$tdict"
+_ACEOF
+
+      THAI_WORDSEG_LD_FLAGS=-lwordcut
+      M17N_EXT_LIBS="$M17N_EXT_LIBS wordcut-old"
+      HAVE_THAI_WORDSEG=yes
+    else
+      HAVE_WORDCUT=no
+    fi
+  fi
+fi
+
+if test "x$HAVE_THAI_WORDSEG" = "xyes"; then
+
+$as_echo "#define HAVE_THAI_WORDSEG 1" >>confdefs.h
+
+fi
+
+
+
+
+
+CPPFLAGS="$CPPFLAGS $X_CFLAGS"
+
+
+SHLIB_EXT=".so"
+case $host_os in
+darwin* | rhapsody*)
+  SHLIB_EXT=".dylib";;
+esac
+
+cat >>confdefs.h <<_ACEOF
+#define DLOPEN_SHLIB_EXT "$SHLIB_EXT"
+_ACEOF
+
+
+ac_config_files="$ac_config_files Makefile po/Makefile.in intl/Makefile src/Makefile example/Makefile m17n-config m17n-core.pc m17n-shell.pc m17n-flt.pc m17n-gui.pc"
+
+
+
+cat >confcache <<\_ACEOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+_ACEOF
+
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, we kill variables containing newlines.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+(
+  for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) { eval $ac_var=; unset $ac_var;} ;;
+      esac ;;
+    esac
+  done
+
+  (set) 2>&1 |
+    case $as_nl`(ac_space=' '; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
+      # `set' does not quote correctly, so add quotes: double-quote
+      # substitution turns \\\\ into \\, and sed turns \\ into \.
+      sed -n \
+       "s/'/'\\\\''/g;
+         s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+      ;; #(
+    *)
+      # `set' quotes correctly as required by POSIX, so do not add quotes.
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+      ;;
+    esac |
+    sort
+) |
+  sed '
+     /^ac_cv_env_/b end
+     t clear
+     :clear
+     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+     t end
+     s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+     :end' >>confcache
+if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
+  if test -w "$cache_file"; then
+    test "x$cache_file" != "x/dev/null" &&
+      { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
+$as_echo "$as_me: updating cache $cache_file" >&6;}
+    cat confcache >$cache_file
+  else
+    { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
+$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
+  fi
+fi
+rm -f confcache
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+DEFS=-DHAVE_CONFIG_H
+
+ac_libobjs=
+ac_ltlibobjs=
+for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
+  # 1. Remove the extension, and $U if already installed.
+  ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
+  ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
+  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
+  #    will be set to the directory where LIBOBJS objects are built.
+  as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
+  as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
+done
+LIBOBJS=$ac_libobjs
+
+LTLIBOBJS=$ac_ltlibobjs
+
+
+ if test -n "$EXEEXT"; then
+  am__EXEEXT_TRUE=
+  am__EXEEXT_FALSE='#'
+else
+  am__EXEEXT_TRUE='#'
+  am__EXEEXT_FALSE=
+fi
+
+if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then
+  as_fn_error "conditional \"AMDEP\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then
+  as_fn_error "conditional \"am__fastdepCC\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then
+  as_fn_error "conditional \"MAINTAINER_MODE\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then
+  as_fn_error "conditional \"am__fastdepCC\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+
+if test -z "${WITH_GUI_TRUE}" && test -z "${WITH_GUI_FALSE}"; then
+  as_fn_error "conditional \"WITH_GUI\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+
+: ${CONFIG_STATUS=./config.status}
+ac_write_fail=0
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files $CONFIG_STATUS"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
+$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
+as_write_fail=0
+cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate the current configuration.
+# Compiler output produced by configure, useful for debugging
+# configure, is in config.log if it exists.
+
+debug=false
+ac_cs_recheck=false
+ac_cs_silent=false
+
+SHELL=\${CONFIG_SHELL-$SHELL}
+export SHELL
+_ASEOF
+cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in #(
+      *"$as_nl"*)
+       expr "X$arg" : "X\\(.*\\)$as_nl";
+       arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" ""       $as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+case $0 in #((
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+  done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there.  '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+
+# as_fn_error ERROR [LINENO LOG_FD]
+# ---------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with status $?, using 1 if that was 0.
+as_fn_error ()
+{
+  as_status=$?; test $as_status -eq 0 && as_status=1
+  if test "$3"; then
+    as_lineno=${as_lineno-"$2"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $1" >&$3
+  fi
+  $as_echo "$as_me: error: $1" >&2
+  as_fn_exit $as_status
+} # as_fn_error
+
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+  return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+  set +e
+  as_fn_set_status $1
+  exit $1
+} # as_fn_exit
+
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+  { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+  eval 'as_fn_append ()
+  {
+    eval $1+=\$2
+  }'
+else
+  as_fn_append ()
+  {
+    eval $1=\$$1\$2
+  }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+  eval 'as_fn_arith ()
+  {
+    as_val=$(( $* ))
+  }'
+else
+  as_fn_arith ()
+  {
+    as_val=`expr "$@" || test $? -eq 1`
+  }
+fi # as_fn_arith
+
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+        X"$0" : 'X\(//\)$' \| \
+        X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+           s//\1/
+           q
+         }
+         /^X\/\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\/\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+  case `echo 'xy\c'` in
+  *c*) ECHO_T='        ';;     # ECHO_T is single tab character.
+  xy)  ECHO_C='\c';;
+  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
+       ECHO_T='        ';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -p'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -p'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
+    as_ln_s='cp -p'
+  fi
+else
+  as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || eval $as_mkdir_p || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+        X"$as_dir" : 'X\(//\)[^/]' \| \
+        X"$as_dir" : 'X\(//\)$' \| \
+        X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)[^/].*/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || as_fn_error "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p='mkdir -p "$as_dir"'
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+       test -d "$1/.";
+      else
+       case $1 in #(
+       -*)set "./$1";;
+       esac;
+       case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
+       ???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+exec 6>&1
+## ----------------------------------- ##
+## Main body of $CONFIG_STATUS script. ##
+## ----------------------------------- ##
+_ASEOF
+test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# Save the log message, to keep $0 and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling.
+ac_log="
+This file was extended by m17n-lib $as_me 1.6.1, which was
+generated by GNU Autoconf 2.64.  Invocation command line was
+
+  CONFIG_FILES    = $CONFIG_FILES
+  CONFIG_HEADERS  = $CONFIG_HEADERS
+  CONFIG_LINKS    = $CONFIG_LINKS
+  CONFIG_COMMANDS = $CONFIG_COMMANDS
+  $ $0 $@
+
+on `(hostname || uname -n) 2>/dev/null | sed 1q`
+"
+
+_ACEOF
+
+case $ac_config_files in *"
+"*) set x $ac_config_files; shift; ac_config_files=$*;;
+esac
+
+case $ac_config_headers in *"
+"*) set x $ac_config_headers; shift; ac_config_headers=$*;;
+esac
+
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+# Files that config.status was made for.
+config_files="$ac_config_files"
+config_headers="$ac_config_headers"
+config_commands="$ac_config_commands"
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+ac_cs_usage="\
+\`$as_me' instantiates files and other configuration actions
+from templates according to the current configuration.  Unless the files
+and actions are specified as TAGs, all are instantiated by default.
+
+Usage: $0 [OPTION]... [TAG]...
+
+  -h, --help       print this help, then exit
+  -V, --version    print version number and configuration settings, then exit
+  -q, --quiet, --silent
+                   do not print progress messages
+  -d, --debug      don't remove temporary files
+      --recheck    update $as_me by reconfiguring in the same conditions
+      --file=FILE[:TEMPLATE]
+                   instantiate the configuration file FILE
+      --header=FILE[:TEMPLATE]
+                   instantiate the configuration header FILE
+
+Configuration files:
+$config_files
+
+Configuration headers:
+$config_headers
+
+Configuration commands:
+$config_commands
+
+Report bugs to <m17n-lib-bug@m17n.org>."
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_cs_version="\\
+m17n-lib config.status 1.6.1
+configured by $0, generated by GNU Autoconf 2.64,
+  with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
+
+Copyright (C) 2009 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+
+ac_pwd='$ac_pwd'
+srcdir='$srcdir'
+INSTALL='$INSTALL'
+MKDIR_P='$MKDIR_P'
+AWK='$AWK'
+test -n "\$AWK" || AWK=awk
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# The default lists apply if the user does not specify any file.
+ac_need_defaults=:
+while test $# != 0
+do
+  case $1 in
+  --*=*)
+    ac_option=`expr "X$1" : 'X\([^=]*\)='`
+    ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
+    ac_shift=:
+    ;;
+  *)
+    ac_option=$1
+    ac_optarg=$2
+    ac_shift=shift
+    ;;
+  esac
+
+  case $ac_option in
+  # Handling of the options.
+  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+    ac_cs_recheck=: ;;
+  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
+    $as_echo "$ac_cs_version"; exit ;;
+  --debug | --debu | --deb | --de | --d | -d )
+    debug=: ;;
+  --file | --fil | --fi | --f )
+    $ac_shift
+    case $ac_optarg in
+    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    as_fn_append CONFIG_FILES " '$ac_optarg'"
+    ac_need_defaults=false;;
+  --header | --heade | --head | --hea )
+    $ac_shift
+    case $ac_optarg in
+    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    as_fn_append CONFIG_HEADERS " '$ac_optarg'"
+    ac_need_defaults=false;;
+  --he | --h)
+    # Conflict between --help and --header
+    as_fn_error "ambiguous option: \`$1'
+Try \`$0 --help' for more information.";;
+  --help | --hel | -h )
+    $as_echo "$ac_cs_usage"; exit ;;
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil | --si | --s)
+    ac_cs_silent=: ;;
+
+  # This is an error.
+  -*) as_fn_error "unrecognized option: \`$1'
+Try \`$0 --help' for more information." ;;
+
+  *) as_fn_append ac_config_targets " $1"
+     ac_need_defaults=false ;;
+
+  esac
+  shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+  exec 6>/dev/null
+  ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+if \$ac_cs_recheck; then
+  set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  shift
+  \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
+  CONFIG_SHELL='$SHELL'
+  export CONFIG_SHELL
+  exec "\$@"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+exec 5>>config.log
+{
+  echo
+  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+  $as_echo "$ac_log"
+} >&5
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+#
+# INIT-COMMANDS
+#
+AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"
+
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+sed_quote_subst='$sed_quote_subst'
+double_quote_subst='$double_quote_subst'
+delay_variable_subst='$delay_variable_subst'
+macro_version='`$ECHO "X$macro_version" | $Xsed -e "$delay_single_quote_subst"`'
+macro_revision='`$ECHO "X$macro_revision" | $Xsed -e "$delay_single_quote_subst"`'
+enable_shared='`$ECHO "X$enable_shared" | $Xsed -e "$delay_single_quote_subst"`'
+enable_static='`$ECHO "X$enable_static" | $Xsed -e "$delay_single_quote_subst"`'
+pic_mode='`$ECHO "X$pic_mode" | $Xsed -e "$delay_single_quote_subst"`'
+enable_fast_install='`$ECHO "X$enable_fast_install" | $Xsed -e "$delay_single_quote_subst"`'
+host_alias='`$ECHO "X$host_alias" | $Xsed -e "$delay_single_quote_subst"`'
+host='`$ECHO "X$host" | $Xsed -e "$delay_single_quote_subst"`'
+host_os='`$ECHO "X$host_os" | $Xsed -e "$delay_single_quote_subst"`'
+build_alias='`$ECHO "X$build_alias" | $Xsed -e "$delay_single_quote_subst"`'
+build='`$ECHO "X$build" | $Xsed -e "$delay_single_quote_subst"`'
+build_os='`$ECHO "X$build_os" | $Xsed -e "$delay_single_quote_subst"`'
+SED='`$ECHO "X$SED" | $Xsed -e "$delay_single_quote_subst"`'
+Xsed='`$ECHO "X$Xsed" | $Xsed -e "$delay_single_quote_subst"`'
+GREP='`$ECHO "X$GREP" | $Xsed -e "$delay_single_quote_subst"`'
+EGREP='`$ECHO "X$EGREP" | $Xsed -e "$delay_single_quote_subst"`'
+FGREP='`$ECHO "X$FGREP" | $Xsed -e "$delay_single_quote_subst"`'
+LD='`$ECHO "X$LD" | $Xsed -e "$delay_single_quote_subst"`'
+NM='`$ECHO "X$NM" | $Xsed -e "$delay_single_quote_subst"`'
+LN_S='`$ECHO "X$LN_S" | $Xsed -e "$delay_single_quote_subst"`'
+max_cmd_len='`$ECHO "X$max_cmd_len" | $Xsed -e "$delay_single_quote_subst"`'
+ac_objext='`$ECHO "X$ac_objext" | $Xsed -e "$delay_single_quote_subst"`'
+exeext='`$ECHO "X$exeext" | $Xsed -e "$delay_single_quote_subst"`'
+lt_unset='`$ECHO "X$lt_unset" | $Xsed -e "$delay_single_quote_subst"`'
+lt_SP2NL='`$ECHO "X$lt_SP2NL" | $Xsed -e "$delay_single_quote_subst"`'
+lt_NL2SP='`$ECHO "X$lt_NL2SP" | $Xsed -e "$delay_single_quote_subst"`'
+reload_flag='`$ECHO "X$reload_flag" | $Xsed -e "$delay_single_quote_subst"`'
+reload_cmds='`$ECHO "X$reload_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+OBJDUMP='`$ECHO "X$OBJDUMP" | $Xsed -e "$delay_single_quote_subst"`'
+deplibs_check_method='`$ECHO "X$deplibs_check_method" | $Xsed -e "$delay_single_quote_subst"`'
+file_magic_cmd='`$ECHO "X$file_magic_cmd" | $Xsed -e "$delay_single_quote_subst"`'
+AR='`$ECHO "X$AR" | $Xsed -e "$delay_single_quote_subst"`'
+AR_FLAGS='`$ECHO "X$AR_FLAGS" | $Xsed -e "$delay_single_quote_subst"`'
+STRIP='`$ECHO "X$STRIP" | $Xsed -e "$delay_single_quote_subst"`'
+RANLIB='`$ECHO "X$RANLIB" | $Xsed -e "$delay_single_quote_subst"`'
+old_postinstall_cmds='`$ECHO "X$old_postinstall_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+old_postuninstall_cmds='`$ECHO "X$old_postuninstall_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+old_archive_cmds='`$ECHO "X$old_archive_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+CC='`$ECHO "X$CC" | $Xsed -e "$delay_single_quote_subst"`'
+CFLAGS='`$ECHO "X$CFLAGS" | $Xsed -e "$delay_single_quote_subst"`'
+compiler='`$ECHO "X$compiler" | $Xsed -e "$delay_single_quote_subst"`'
+GCC='`$ECHO "X$GCC" | $Xsed -e "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_pipe='`$ECHO "X$lt_cv_sys_global_symbol_pipe" | $Xsed -e "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_to_cdecl='`$ECHO "X$lt_cv_sys_global_symbol_to_cdecl" | $Xsed -e "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_to_c_name_address='`$ECHO "X$lt_cv_sys_global_symbol_to_c_name_address" | $Xsed -e "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix='`$ECHO "X$lt_cv_sys_global_symbol_to_c_name_address_lib_prefix" | $Xsed -e "$delay_single_quote_subst"`'
+objdir='`$ECHO "X$objdir" | $Xsed -e "$delay_single_quote_subst"`'
+SHELL='`$ECHO "X$SHELL" | $Xsed -e "$delay_single_quote_subst"`'
+ECHO='`$ECHO "X$ECHO" | $Xsed -e "$delay_single_quote_subst"`'
+MAGIC_CMD='`$ECHO "X$MAGIC_CMD" | $Xsed -e "$delay_single_quote_subst"`'
+lt_prog_compiler_no_builtin_flag='`$ECHO "X$lt_prog_compiler_no_builtin_flag" | $Xsed -e "$delay_single_quote_subst"`'
+lt_prog_compiler_wl='`$ECHO "X$lt_prog_compiler_wl" | $Xsed -e "$delay_single_quote_subst"`'
+lt_prog_compiler_pic='`$ECHO "X$lt_prog_compiler_pic" | $Xsed -e "$delay_single_quote_subst"`'
+lt_prog_compiler_static='`$ECHO "X$lt_prog_compiler_static" | $Xsed -e "$delay_single_quote_subst"`'
+lt_cv_prog_compiler_c_o='`$ECHO "X$lt_cv_prog_compiler_c_o" | $Xsed -e "$delay_single_quote_subst"`'
+need_locks='`$ECHO "X$need_locks" | $Xsed -e "$delay_single_quote_subst"`'
+DSYMUTIL='`$ECHO "X$DSYMUTIL" | $Xsed -e "$delay_single_quote_subst"`'
+NMEDIT='`$ECHO "X$NMEDIT" | $Xsed -e "$delay_single_quote_subst"`'
+LIPO='`$ECHO "X$LIPO" | $Xsed -e "$delay_single_quote_subst"`'
+OTOOL='`$ECHO "X$OTOOL" | $Xsed -e "$delay_single_quote_subst"`'
+OTOOL64='`$ECHO "X$OTOOL64" | $Xsed -e "$delay_single_quote_subst"`'
+libext='`$ECHO "X$libext" | $Xsed -e "$delay_single_quote_subst"`'
+shrext_cmds='`$ECHO "X$shrext_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+extract_expsyms_cmds='`$ECHO "X$extract_expsyms_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+archive_cmds_need_lc='`$ECHO "X$archive_cmds_need_lc" | $Xsed -e "$delay_single_quote_subst"`'
+enable_shared_with_static_runtimes='`$ECHO "X$enable_shared_with_static_runtimes" | $Xsed -e "$delay_single_quote_subst"`'
+export_dynamic_flag_spec='`$ECHO "X$export_dynamic_flag_spec" | $Xsed -e "$delay_single_quote_subst"`'
+whole_archive_flag_spec='`$ECHO "X$whole_archive_flag_spec" | $Xsed -e "$delay_single_quote_subst"`'
+compiler_needs_object='`$ECHO "X$compiler_needs_object" | $Xsed -e "$delay_single_quote_subst"`'
+old_archive_from_new_cmds='`$ECHO "X$old_archive_from_new_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+old_archive_from_expsyms_cmds='`$ECHO "X$old_archive_from_expsyms_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+archive_cmds='`$ECHO "X$archive_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+archive_expsym_cmds='`$ECHO "X$archive_expsym_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+module_cmds='`$ECHO "X$module_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+module_expsym_cmds='`$ECHO "X$module_expsym_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+with_gnu_ld='`$ECHO "X$with_gnu_ld" | $Xsed -e "$delay_single_quote_subst"`'
+allow_undefined_flag='`$ECHO "X$allow_undefined_flag" | $Xsed -e "$delay_single_quote_subst"`'
+no_undefined_flag='`$ECHO "X$no_undefined_flag" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_libdir_flag_spec='`$ECHO "X$hardcode_libdir_flag_spec" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_libdir_flag_spec_ld='`$ECHO "X$hardcode_libdir_flag_spec_ld" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_libdir_separator='`$ECHO "X$hardcode_libdir_separator" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_direct='`$ECHO "X$hardcode_direct" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_direct_absolute='`$ECHO "X$hardcode_direct_absolute" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_minus_L='`$ECHO "X$hardcode_minus_L" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_shlibpath_var='`$ECHO "X$hardcode_shlibpath_var" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_automatic='`$ECHO "X$hardcode_automatic" | $Xsed -e "$delay_single_quote_subst"`'
+inherit_rpath='`$ECHO "X$inherit_rpath" | $Xsed -e "$delay_single_quote_subst"`'
+link_all_deplibs='`$ECHO "X$link_all_deplibs" | $Xsed -e "$delay_single_quote_subst"`'
+fix_srcfile_path='`$ECHO "X$fix_srcfile_path" | $Xsed -e "$delay_single_quote_subst"`'
+always_export_symbols='`$ECHO "X$always_export_symbols" | $Xsed -e "$delay_single_quote_subst"`'
+export_symbols_cmds='`$ECHO "X$export_symbols_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+exclude_expsyms='`$ECHO "X$exclude_expsyms" | $Xsed -e "$delay_single_quote_subst"`'
+include_expsyms='`$ECHO "X$include_expsyms" | $Xsed -e "$delay_single_quote_subst"`'
+prelink_cmds='`$ECHO "X$prelink_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+file_list_spec='`$ECHO "X$file_list_spec" | $Xsed -e "$delay_single_quote_subst"`'
+variables_saved_for_relink='`$ECHO "X$variables_saved_for_relink" | $Xsed -e "$delay_single_quote_subst"`'
+need_lib_prefix='`$ECHO "X$need_lib_prefix" | $Xsed -e "$delay_single_quote_subst"`'
+need_version='`$ECHO "X$need_version" | $Xsed -e "$delay_single_quote_subst"`'
+version_type='`$ECHO "X$version_type" | $Xsed -e "$delay_single_quote_subst"`'
+runpath_var='`$ECHO "X$runpath_var" | $Xsed -e "$delay_single_quote_subst"`'
+shlibpath_var='`$ECHO "X$shlibpath_var" | $Xsed -e "$delay_single_quote_subst"`'
+shlibpath_overrides_runpath='`$ECHO "X$shlibpath_overrides_runpath" | $Xsed -e "$delay_single_quote_subst"`'
+libname_spec='`$ECHO "X$libname_spec" | $Xsed -e "$delay_single_quote_subst"`'
+library_names_spec='`$ECHO "X$library_names_spec" | $Xsed -e "$delay_single_quote_subst"`'
+soname_spec='`$ECHO "X$soname_spec" | $Xsed -e "$delay_single_quote_subst"`'
+postinstall_cmds='`$ECHO "X$postinstall_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+postuninstall_cmds='`$ECHO "X$postuninstall_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+finish_cmds='`$ECHO "X$finish_cmds" | $Xsed -e "$delay_single_quote_subst"`'
+finish_eval='`$ECHO "X$finish_eval" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_into_libs='`$ECHO "X$hardcode_into_libs" | $Xsed -e "$delay_single_quote_subst"`'
+sys_lib_search_path_spec='`$ECHO "X$sys_lib_search_path_spec" | $Xsed -e "$delay_single_quote_subst"`'
+sys_lib_dlsearch_path_spec='`$ECHO "X$sys_lib_dlsearch_path_spec" | $Xsed -e "$delay_single_quote_subst"`'
+hardcode_action='`$ECHO "X$hardcode_action" | $Xsed -e "$delay_single_quote_subst"`'
+enable_dlopen='`$ECHO "X$enable_dlopen" | $Xsed -e "$delay_single_quote_subst"`'
+enable_dlopen_self='`$ECHO "X$enable_dlopen_self" | $Xsed -e "$delay_single_quote_subst"`'
+enable_dlopen_self_static='`$ECHO "X$enable_dlopen_self_static" | $Xsed -e "$delay_single_quote_subst"`'
+old_striplib='`$ECHO "X$old_striplib" | $Xsed -e "$delay_single_quote_subst"`'
+striplib='`$ECHO "X$striplib" | $Xsed -e "$delay_single_quote_subst"`'
+
+LTCC='$LTCC'
+LTCFLAGS='$LTCFLAGS'
+compiler='$compiler_DEFAULT'
+
+# Quote evaled strings.
+for var in SED \
+GREP \
+EGREP \
+FGREP \
+LD \
+NM \
+LN_S \
+lt_SP2NL \
+lt_NL2SP \
+reload_flag \
+OBJDUMP \
+deplibs_check_method \
+file_magic_cmd \
+AR \
+AR_FLAGS \
+STRIP \
+RANLIB \
+CC \
+CFLAGS \
+compiler \
+lt_cv_sys_global_symbol_pipe \
+lt_cv_sys_global_symbol_to_cdecl \
+lt_cv_sys_global_symbol_to_c_name_address \
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix \
+SHELL \
+ECHO \
+lt_prog_compiler_no_builtin_flag \
+lt_prog_compiler_wl \
+lt_prog_compiler_pic \
+lt_prog_compiler_static \
+lt_cv_prog_compiler_c_o \
+need_locks \
+DSYMUTIL \
+NMEDIT \
+LIPO \
+OTOOL \
+OTOOL64 \
+shrext_cmds \
+export_dynamic_flag_spec \
+whole_archive_flag_spec \
+compiler_needs_object \
+with_gnu_ld \
+allow_undefined_flag \
+no_undefined_flag \
+hardcode_libdir_flag_spec \
+hardcode_libdir_flag_spec_ld \
+hardcode_libdir_separator \
+fix_srcfile_path \
+exclude_expsyms \
+include_expsyms \
+file_list_spec \
+variables_saved_for_relink \
+libname_spec \
+library_names_spec \
+soname_spec \
+finish_eval \
+old_striplib \
+striplib; do
+    case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in
+    *[\\\\\\\`\\"\\\$]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$sed_quote_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+# Double-quote double-evaled strings.
+for var in reload_cmds \
+old_postinstall_cmds \
+old_postuninstall_cmds \
+old_archive_cmds \
+extract_expsyms_cmds \
+old_archive_from_new_cmds \
+old_archive_from_expsyms_cmds \
+archive_cmds \
+archive_expsym_cmds \
+module_cmds \
+module_expsym_cmds \
+export_symbols_cmds \
+prelink_cmds \
+postinstall_cmds \
+postuninstall_cmds \
+finish_cmds \
+sys_lib_search_path_spec \
+sys_lib_dlsearch_path_spec; do
+    case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in
+    *[\\\\\\\`\\"\\\$]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+# Fix-up fallback echo if it was mangled by the above quoting rules.
+case \$lt_ECHO in
+*'\\\$0 --fallback-echo"')  lt_ECHO=\`\$ECHO "X\$lt_ECHO" | \$Xsed -e 's/\\\\\\\\\\\\\\\$0 --fallback-echo"\$/\$0 --fallback-echo"/'\`
+  ;;
+esac
+
+ac_aux_dir='$ac_aux_dir'
+xsi_shell='$xsi_shell'
+lt_shell_append='$lt_shell_append'
+
+# See if we are running on zsh, and set the options which allow our
+# commands through without removal of \ escapes INIT.
+if test -n "\${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+
+
+    PACKAGE='$PACKAGE'
+    VERSION='$VERSION'
+    TIMESTAMP='$TIMESTAMP'
+    RM='$RM'
+    ofile='$ofile'
+
+
+
+# Capture the value of obsolete ALL_LINGUAS because we need it to compute
+    # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it
+    # from automake.
+    eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"'
+    # Capture the value of LINGUAS because we need it to compute CATALOGS.
+    LINGUAS="${LINGUAS-%UNSET%}"
+
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+
+# Handling of arguments.
+for ac_config_target in $ac_config_targets
+do
+  case $ac_config_target in
+    "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
+    "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
+    "src/config.h") CONFIG_HEADERS="$CONFIG_HEADERS src/config.h" ;;
+    "default-1") CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;;
+    "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
+    "po/Makefile.in") CONFIG_FILES="$CONFIG_FILES po/Makefile.in" ;;
+    "intl/Makefile") CONFIG_FILES="$CONFIG_FILES intl/Makefile" ;;
+    "src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;;
+    "example/Makefile") CONFIG_FILES="$CONFIG_FILES example/Makefile" ;;
+    "m17n-config") CONFIG_FILES="$CONFIG_FILES m17n-config" ;;
+    "m17n-core.pc") CONFIG_FILES="$CONFIG_FILES m17n-core.pc" ;;
+    "m17n-shell.pc") CONFIG_FILES="$CONFIG_FILES m17n-shell.pc" ;;
+    "m17n-flt.pc") CONFIG_FILES="$CONFIG_FILES m17n-flt.pc" ;;
+    "m17n-gui.pc") CONFIG_FILES="$CONFIG_FILES m17n-gui.pc" ;;
+
+  *) as_fn_error "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
+  esac
+done
+
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used.  Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+  test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
+  test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands
+fi
+
+# Have a temporary directory for convenience.  Make it in the build tree
+# simply because there is no reason against having it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Hook for its removal unless debugging.
+# Note that there is a small window in which the directory will not be cleaned:
+# after its creation but before its name has been assigned to `$tmp'.
+$debug ||
+{
+  tmp=
+  trap 'exit_status=$?
+  { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status
+' 0
+  trap 'as_fn_exit 1' 1 2 13 15
+}
+# Create a (secure) tmp directory for tmp files.
+
+{
+  tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
+  test -n "$tmp" && test -d "$tmp"
+}  ||
+{
+  tmp=./conf$$-$RANDOM
+  (umask 077 && mkdir "$tmp")
+} || as_fn_error "cannot create a temporary directory in ." "$LINENO" 5
+
+# Set up the scripts for CONFIG_FILES section.
+# No need to generate them if there are no CONFIG_FILES.
+# This happens for instance with `./config.status config.h'.
+if test -n "$CONFIG_FILES"; then
+
+
+ac_cr=`echo X | tr X '\015'`
+# On cygwin, bash can eat \r inside `` if the user requested igncr.
+# But we know of no other shell where ac_cr would be empty at this
+# point, so we can use a bashism as a fallback.
+if test "x$ac_cr" = x; then
+  eval ac_cr=\$\'\\r\'
+fi
+ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' </dev/null 2>/dev/null`
+if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
+  ac_cs_awk_cr='\r'
+else
+  ac_cs_awk_cr=$ac_cr
+fi
+
+echo 'BEGIN {' >"$tmp/subs1.awk" &&
+_ACEOF
+
+
+{
+  echo "cat >conf$$subs.awk <<_ACEOF" &&
+  echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
+  echo "_ACEOF"
+} >conf$$subs.sh ||
+  as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5
+ac_delim_num=`echo "$ac_subst_vars" | grep -c '$'`
+ac_delim='%!_!# '
+for ac_last_try in false false false false false :; do
+  . ./conf$$subs.sh ||
+    as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5
+
+  ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X`
+  if test $ac_delim_n = $ac_delim_num; then
+    break
+  elif $ac_last_try; then
+    as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+rm -f conf$$subs.sh
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+cat >>"\$tmp/subs1.awk" <<\\_ACAWK &&
+_ACEOF
+sed -n '
+h
+s/^/S["/; s/!.*/"]=/
+p
+g
+s/^[^!]*!//
+:repl
+t repl
+s/'"$ac_delim"'$//
+t delim
+:nl
+h
+s/\(.\{148\}\).*/\1/
+t more1
+s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/
+p
+n
+b repl
+:more1
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t nl
+:delim
+h
+s/\(.\{148\}\).*/\1/
+t more2
+s/["\\]/\\&/g; s/^/"/; s/$/"/
+p
+b
+:more2
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t delim
+' <conf$$subs.awk | sed '
+/^[^""]/{
+  N
+  s/\n//
+}
+' >>$CONFIG_STATUS || ac_write_fail=1
+rm -f conf$$subs.awk
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACAWK
+cat >>"\$tmp/subs1.awk" <<_ACAWK &&
+  for (key in S) S_is_set[key] = 1
+  FS = "\a"
+
+}
+{
+  line = $ 0
+  nfields = split(line, field, "@")
+  substed = 0
+  len = length(field[1])
+  for (i = 2; i < nfields; i++) {
+    key = field[i]
+    keylen = length(key)
+    if (S_is_set[key]) {
+      value = S[key]
+      line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3)
+      len += length(value) + length(field[++i])
+      substed = 1
+    } else
+      len += 1 + keylen
+  }
+
+  print line
+}
+
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then
+  sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
+else
+  cat
+fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \
+  || as_fn_error "could not setup config files machinery" "$LINENO" 5
+_ACEOF
+
+# VPATH may cause trouble with some makes, so we remove $(srcdir),
+# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+  ac_vpsub='/^[         ]*VPATH[        ]*=/{
+s/:*\$(srcdir):*/:/
+s/:*\${srcdir}:*/:/
+s/:*@srcdir@:*/:/
+s/^\([^=]*=[    ]*\):*/\1/
+s/:*$//
+s/^[^=]*=[      ]*$//
+}'
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+fi # test -n "$CONFIG_FILES"
+
+# Set up the scripts for CONFIG_HEADERS section.
+# No need to generate them if there are no CONFIG_HEADERS.
+# This happens for instance with `./config.status Makefile'.
+if test -n "$CONFIG_HEADERS"; then
+cat >"$tmp/defines.awk" <<\_ACAWK ||
+BEGIN {
+_ACEOF
+
+# Transform confdefs.h into an awk script `defines.awk', embedded as
+# here-document in config.status, that substitutes the proper values into
+# config.h.in to produce config.h.
+
+# Create a delimiter string that does not exist in confdefs.h, to ease
+# handling of long lines.
+ac_delim='%!_!# '
+for ac_last_try in false false :; do
+  ac_t=`sed -n "/$ac_delim/p" confdefs.h`
+  if test -z "$ac_t"; then
+    break
+  elif $ac_last_try; then
+    as_fn_error "could not make $CONFIG_HEADERS" "$LINENO" 5
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+
+# For the awk script, D is an array of macro values keyed by name,
+# likewise P contains macro parameters if any.  Preserve backslash
+# newline sequences.
+
+ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]*
+sed -n '
+s/.\{148\}/&'"$ac_delim"'/g
+t rset
+:rset
+s/^[    ]*#[    ]*define[       ][      ]*/ /
+t def
+d
+:def
+s/\\$//
+t bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[    ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3"/p
+s/^ \('"$ac_word_re"'\)[        ]*\(.*\)/D["\1"]=" \2"/p
+d
+:bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[    ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3\\\\\\n"\\/p
+t cont
+s/^ \('"$ac_word_re"'\)[        ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p
+t cont
+d
+:cont
+n
+s/.\{148\}/&'"$ac_delim"'/g
+t clear
+:clear
+s/\\$//
+t bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/"/p
+d
+:bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p
+b cont
+' <confdefs.h | sed '
+s/'"$ac_delim"'/"\\\
+"/g' >>$CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+  for (key in D) D_is_set[key] = 1
+  FS = "\a"
+}
+/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ {
+  line = \$ 0
+  split(line, arg, " ")
+  if (arg[1] == "#") {
+    defundef = arg[2]
+    mac1 = arg[3]
+  } else {
+    defundef = substr(arg[1], 2)
+    mac1 = arg[2]
+  }
+  split(mac1, mac2, "(") #)
+  macro = mac2[1]
+  prefix = substr(line, 1, index(line, defundef) - 1)
+  if (D_is_set[macro]) {
+    # Preserve the white space surrounding the "#".
+    print prefix "define", macro P[macro] D[macro]
+    next
+  } else {
+    # Replace #undef with comments.  This is necessary, for example,
+    # in the case of _POSIX_SOURCE, which is predefined and required
+    # on some systems where configure will not decide to define it.
+    if (defundef == "undef") {
+      print "/*", prefix defundef, macro, "*/"
+      next
+    }
+  }
+}
+{ print }
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+  as_fn_error "could not setup config headers machinery" "$LINENO" 5
+fi # test -n "$CONFIG_HEADERS"
+
+
+eval set X "  :F $CONFIG_FILES  :H $CONFIG_HEADERS    :C $CONFIG_COMMANDS"
+shift
+for ac_tag
+do
+  case $ac_tag in
+  :[FHLC]) ac_mode=$ac_tag; continue;;
+  esac
+  case $ac_mode$ac_tag in
+  :[FHL]*:*);;
+  :L* | :C*:*) as_fn_error "invalid tag \`$ac_tag'" "$LINENO" 5;;
+  :[FH]-) ac_tag=-:-;;
+  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
+  esac
+  ac_save_IFS=$IFS
+  IFS=:
+  set x $ac_tag
+  IFS=$ac_save_IFS
+  shift
+  ac_file=$1
+  shift
+
+  case $ac_mode in
+  :L) ac_source=$1;;
+  :[FH])
+    ac_file_inputs=
+    for ac_f
+    do
+      case $ac_f in
+      -) ac_f="$tmp/stdin";;
+      *) # Look for the file first in the build tree, then in the source tree
+        # (if the path is not absolute).  The absolute path cannot be DOS-style,
+        # because $ac_f cannot contain `:'.
+        test -f "$ac_f" ||
+          case $ac_f in
+          [\\/$]*) false;;
+          *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
+          esac ||
+          as_fn_error "cannot find input file: \`$ac_f'" "$LINENO" 5;;
+      esac
+      case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
+      as_fn_append ac_file_inputs " '$ac_f'"
+    done
+
+    # Let's still pretend it is `configure' which instantiates (i.e., don't
+    # use $as_me), people would be surprised to read:
+    #    /* config.h.  Generated by config.status.  */
+    configure_input='Generated from '`
+         $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
+       `' by configure.'
+    if test x"$ac_file" != x-; then
+      configure_input="$ac_file.  $configure_input"
+      { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
+$as_echo "$as_me: creating $ac_file" >&6;}
+    fi
+    # Neutralize special characters interpreted by sed in replacement strings.
+    case $configure_input in #(
+    *\&* | *\|* | *\\* )
+       ac_sed_conf_input=`$as_echo "$configure_input" |
+       sed 's/[\\\\&|]/\\\\&/g'`;; #(
+    *) ac_sed_conf_input=$configure_input;;
+    esac
+
+    case $ac_tag in
+    *:-:* | *:-) cat >"$tmp/stdin" \
+      || as_fn_error "could not create $ac_file" "$LINENO" 5 ;;
+    esac
+    ;;
+  esac
+
+  ac_dir=`$as_dirname -- "$ac_file" ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+        X"$ac_file" : 'X\(//\)[^/]' \| \
+        X"$ac_file" : 'X\(//\)$' \| \
+        X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)[^/].*/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`
+  as_dir="$ac_dir"; as_fn_mkdir_p
+  ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+  .)  # We are building in place.
+    ac_srcdir=.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+
+  case $ac_mode in
+  :F)
+  #
+  # CONFIG_FILE
+  #
+
+  case $INSTALL in
+  [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
+  *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;;
+  esac
+  ac_MKDIR_P=$MKDIR_P
+  case $MKDIR_P in
+  [\\/$]* | ?:[\\/]* ) ;;
+  */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;;
+  esac
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# If the template does not know about datarootdir, expand it.
+# FIXME: This hack should be removed a few years after 2.60.
+ac_datarootdir_hack=; ac_datarootdir_seen=
+ac_sed_dataroot='
+/datarootdir/ {
+  p
+  q
+}
+/@datadir@/p
+/@docdir@/p
+/@infodir@/p
+/@localedir@/p
+/@mandir@/p'
+case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
+*datarootdir*) ac_datarootdir_seen=yes;;
+*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
+$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+  ac_datarootdir_hack='
+  s&@datadir@&$datadir&g
+  s&@docdir@&$docdir&g
+  s&@infodir@&$infodir&g
+  s&@localedir@&$localedir&g
+  s&@mandir@&$mandir&g
+  s&\\\${datarootdir}&$datarootdir&g' ;;
+esac
+_ACEOF
+
+# Neutralize VPATH when `$srcdir' = `.'.
+# Shell code in configure.ac might set extrasub.
+# FIXME: do we really want to maintain this feature?
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_sed_extra="$ac_vpsub
+$extrasub
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+:t
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+s|@configure_input@|$ac_sed_conf_input|;t t
+s&@top_builddir@&$ac_top_builddir_sub&;t t
+s&@top_build_prefix@&$ac_top_build_prefix&;t t
+s&@srcdir@&$ac_srcdir&;t t
+s&@abs_srcdir@&$ac_abs_srcdir&;t t
+s&@top_srcdir@&$ac_top_srcdir&;t t
+s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t
+s&@builddir@&$ac_builddir&;t t
+s&@abs_builddir@&$ac_abs_builddir&;t t
+s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
+s&@INSTALL@&$ac_INSTALL&;t t
+s&@MKDIR_P@&$ac_MKDIR_P&;t t
+$ac_datarootdir_hack
+"
+eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \
+  || as_fn_error "could not create $ac_file" "$LINENO" 5
+
+test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
+  { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } &&
+  { ac_out=`sed -n '/^[         ]*datarootdir[  ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } &&
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined." >&5
+$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined." >&2;}
+
+  rm -f "$tmp/stdin"
+  case $ac_file in
+  -) cat "$tmp/out" && rm -f "$tmp/out";;
+  *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";;
+  esac \
+  || as_fn_error "could not create $ac_file" "$LINENO" 5
+ ;;
+  :H)
+  #
+  # CONFIG_HEADER
+  #
+  if test x"$ac_file" != x-; then
+    {
+      $as_echo "/* $configure_input  */" \
+      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs"
+    } >"$tmp/config.h" \
+      || as_fn_error "could not create $ac_file" "$LINENO" 5
+    if diff "$ac_file" "$tmp/config.h" >/dev/null 2>&1; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5
+$as_echo "$as_me: $ac_file is unchanged" >&6;}
+    else
+      rm -f "$ac_file"
+      mv "$tmp/config.h" "$ac_file" \
+       || as_fn_error "could not create $ac_file" "$LINENO" 5
+    fi
+  else
+    $as_echo "/* $configure_input  */" \
+      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \
+      || as_fn_error "could not create -" "$LINENO" 5
+  fi
+# Compute "$ac_file"'s index in $config_headers.
+_am_arg="$ac_file"
+_am_stamp_count=1
+for _am_header in $config_headers :; do
+  case $_am_header in
+    $_am_arg | $_am_arg:* )
+      break ;;
+    * )
+      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
+  esac
+done
+echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" ||
+$as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+        X"$_am_arg" : 'X\(//\)[^/]' \| \
+        X"$_am_arg" : 'X\(//\)$' \| \
+        X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$_am_arg" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)[^/].*/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`/stamp-h$_am_stamp_count
+ ;;
+
+  :C)  { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5
+$as_echo "$as_me: executing $ac_file commands" >&6;}
+ ;;
+  esac
+
+
+  case $ac_file$ac_mode in
+    "depfiles":C) test x"$AMDEP_TRUE" != x"" || {
+  # Autoconf 2.62 quotes --file arguments for eval, but not when files
+  # are listed without --file.  Let's play safe and only enable the eval
+  # if we detect the quoting.
+  case $CONFIG_FILES in
+  *\'*) eval set x "$CONFIG_FILES" ;;
+  *)   set x $CONFIG_FILES ;;
+  esac
+  shift
+  for mf
+  do
+    # Strip MF so we end up with the name of the file.
+    mf=`echo "$mf" | sed -e 's/:.*$//'`
+    # Check whether this is an Automake generated Makefile or not.
+    # We used to match only the files named `Makefile.in', but
+    # some people rename them; so instead we look at the file content.
+    # Grep'ing the first line is not enough: some people post-process
+    # each Makefile.in and add a new line on top of each file to say so.
+    # Grep'ing the whole file is not good either: AIX grep has a line
+    # limit of 2048, but all sed's we know have understand at least 4000.
+    if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
+      dirpart=`$as_dirname -- "$mf" ||
+$as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+        X"$mf" : 'X\(//\)[^/]' \| \
+        X"$mf" : 'X\(//\)$' \| \
+        X"$mf" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$mf" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)[^/].*/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`
+    else
+      continue
+    fi
+    # Extract the definition of DEPDIR, am__include, and am__quote
+    # from the Makefile without running `make'.
+    DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
+    test -z "$DEPDIR" && continue
+    am__include=`sed -n 's/^am__include = //p' < "$mf"`
+    test -z "am__include" && continue
+    am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
+    # When using ansi2knr, U may be empty or an underscore; expand it
+    U=`sed -n 's/^U = //p' < "$mf"`
+    # Find all dependency output files, they are included files with
+    # $(DEPDIR) in their names.  We invoke sed twice because it is the
+    # simplest approach to changing $(DEPDIR) to its actual value in the
+    # expansion.
+    for file in `sed -n "
+      s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
+        sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
+      # Make sure the directory exists.
+      test -f "$dirpart/$file" && continue
+      fdir=`$as_dirname -- "$file" ||
+$as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+        X"$file" : 'X\(//\)[^/]' \| \
+        X"$file" : 'X\(//\)$' \| \
+        X"$file" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)[^/].*/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`
+      as_dir=$dirpart/$fdir; as_fn_mkdir_p
+      # echo "creating $dirpart/$file"
+      echo '# dummy' > "$dirpart/$file"
+    done
+  done
+}
+ ;;
+    "libtool":C)
+
+    # See if we are running on zsh, and set the options which allow our
+    # commands through without removal of \ escapes.
+    if test -n "${ZSH_VERSION+set}" ; then
+      setopt NO_GLOB_SUBST
+    fi
+
+    cfgfile="${ofile}T"
+    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
+    $RM "$cfgfile"
+
+    cat <<_LT_EOF >> "$cfgfile"
+#! $SHELL
+
+# `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services.
+# Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+# NOTE: Changes made to this file will be lost: look at ltmain.sh.
+#
+#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+#                 2006, 2007, 2008 Free Software Foundation, Inc.
+#   Written by Gordon Matzigkeit, 1996
+#
+#   This file is part of GNU Libtool.
+#
+# GNU Libtool is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# As a special exception to the GNU General Public License,
+# if you distribute this file as part of a program or library that
+# is built using GNU Libtool, you may include this file under the
+# same distribution terms that you use for the rest of that program.
+#
+# GNU Libtool 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Libtool; see the file COPYING.  If not, a copy
+# can be downloaded from http://www.gnu.org/licenses/gpl.html, or
+# obtained by writing to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+
+# The names of the tagged configurations supported by this script.
+available_tags=""
+
+# ### BEGIN LIBTOOL CONFIG
+
+# Which release of libtool.m4 was used?
+macro_version=$macro_version
+macro_revision=$macro_revision
+
+# Whether or not to build shared libraries.
+build_libtool_libs=$enable_shared
+
+# Whether or not to build static libraries.
+build_old_libs=$enable_static
+
+# What type of objects to build.
+pic_mode=$pic_mode
+
+# Whether or not to optimize for fast installation.
+fast_install=$enable_fast_install
+
+# The host system.
+host_alias=$host_alias
+host=$host
+host_os=$host_os
+
+# The build system.
+build_alias=$build_alias
+build=$build
+build_os=$build_os
+
+# A sed program that does not truncate output.
+SED=$lt_SED
+
+# Sed that helps us avoid accidentally triggering echo(1) options like -n.
+Xsed="\$SED -e 1s/^X//"
+
+# A grep program that handles long lines.
+GREP=$lt_GREP
+
+# An ERE matcher.
+EGREP=$lt_EGREP
+
+# A literal string matcher.
+FGREP=$lt_FGREP
+
+# A BSD- or MS-compatible name lister.
+NM=$lt_NM
+
+# Whether we need soft or hard links.
+LN_S=$lt_LN_S
+
+# What is the maximum length of a command?
+max_cmd_len=$max_cmd_len
+
+# Object file suffix (normally "o").
+objext=$ac_objext
+
+# Executable file suffix (normally "").
+exeext=$exeext
+
+# whether the shell understands "unset".
+lt_unset=$lt_unset
+
+# turn spaces into newlines.
+SP2NL=$lt_lt_SP2NL
+
+# turn newlines into spaces.
+NL2SP=$lt_lt_NL2SP
+
+# How to create reloadable object files.
+reload_flag=$lt_reload_flag
+reload_cmds=$lt_reload_cmds
+
+# An object symbol dumper.
+OBJDUMP=$lt_OBJDUMP
+
+# Method to check whether dependent libraries are shared objects.
+deplibs_check_method=$lt_deplibs_check_method
+
+# Command to use when deplibs_check_method == "file_magic".
+file_magic_cmd=$lt_file_magic_cmd
+
+# The archiver.
+AR=$lt_AR
+AR_FLAGS=$lt_AR_FLAGS
+
+# A symbol stripping program.
+STRIP=$lt_STRIP
+
+# Commands used to install an old-style archive.
+RANLIB=$lt_RANLIB
+old_postinstall_cmds=$lt_old_postinstall_cmds
+old_postuninstall_cmds=$lt_old_postuninstall_cmds
+
+# A C compiler.
+LTCC=$lt_CC
+
+# LTCC compiler flags.
+LTCFLAGS=$lt_CFLAGS
+
+# Take the output of nm and produce a listing of raw symbols and C names.
+global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe
+
+# Transform the output of nm in a proper C declaration.
+global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl
+
+# Transform the output of nm in a C name address pair.
+global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address
+
+# Transform the output of nm in a C name address pair when lib prefix is needed.
+global_symbol_to_c_name_address_lib_prefix=$lt_lt_cv_sys_global_symbol_to_c_name_address_lib_prefix
+
+# The name of the directory that contains temporary libtool files.
+objdir=$objdir
+
+# Shell to use when invoking shell scripts.
+SHELL=$lt_SHELL
+
+# An echo program that does not interpret backslashes.
+ECHO=$lt_ECHO
+
+# Used to examine libraries when file_magic_cmd begins with "file".
+MAGIC_CMD=$MAGIC_CMD
+
+# Must we lock files when doing compilation?
+need_locks=$lt_need_locks
+
+# Tool to manipulate archived DWARF debug symbol files on Mac OS X.
+DSYMUTIL=$lt_DSYMUTIL
+
+# Tool to change global to local symbols on Mac OS X.
+NMEDIT=$lt_NMEDIT
+
+# Tool to manipulate fat objects and archives on Mac OS X.
+LIPO=$lt_LIPO
+
+# ldd/readelf like tool for Mach-O binaries on Mac OS X.
+OTOOL=$lt_OTOOL
+
+# ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4.
+OTOOL64=$lt_OTOOL64
+
+# Old archive suffix (normally "a").
+libext=$libext
+
+# Shared library suffix (normally ".so").
+shrext_cmds=$lt_shrext_cmds
+
+# The commands to extract the exported symbol list from a shared archive.
+extract_expsyms_cmds=$lt_extract_expsyms_cmds
+
+# Variables whose values should be saved in libtool wrapper scripts and
+# restored at link time.
+variables_saved_for_relink=$lt_variables_saved_for_relink
+
+# Do we need the "lib" prefix for modules?
+need_lib_prefix=$need_lib_prefix
+
+# Do we need a version for libraries?
+need_version=$need_version
+
+# Library versioning type.
+version_type=$version_type
+
+# Shared library runtime path variable.
+runpath_var=$runpath_var
+
+# Shared library path variable.
+shlibpath_var=$shlibpath_var
+
+# Is shlibpath searched before the hard-coded library search path?
+shlibpath_overrides_runpath=$shlibpath_overrides_runpath
+
+# Format of library name prefix.
+libname_spec=$lt_libname_spec
+
+# List of archive names.  First name is the real one, the rest are links.
+# The last name is the one that the linker finds with -lNAME
+library_names_spec=$lt_library_names_spec
+
+# The coded name of the library, if different from the real name.
+soname_spec=$lt_soname_spec
+
+# Command to use after installation of a shared archive.
+postinstall_cmds=$lt_postinstall_cmds
+
+# Command to use after uninstallation of a shared archive.
+postuninstall_cmds=$lt_postuninstall_cmds
+
+# Commands used to finish a libtool library installation in a directory.
+finish_cmds=$lt_finish_cmds
+
+# As "finish_cmds", except a single script fragment to be evaled but
+# not shown.
+finish_eval=$lt_finish_eval
+
+# Whether we should hardcode library paths into libraries.
+hardcode_into_libs=$hardcode_into_libs
+
+# Compile-time system search path for libraries.
+sys_lib_search_path_spec=$lt_sys_lib_search_path_spec
+
+# Run-time system search path for libraries.
+sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec
+
+# Whether dlopen is supported.
+dlopen_support=$enable_dlopen
+
+# Whether dlopen of programs is supported.
+dlopen_self=$enable_dlopen_self
+
+# Whether dlopen of statically linked programs is supported.
+dlopen_self_static=$enable_dlopen_self_static
+
+# Commands to strip libraries.
+old_striplib=$lt_old_striplib
+striplib=$lt_striplib
+
+
+# The linker used to build libraries.
+LD=$lt_LD
+
+# Commands used to build an old-style archive.
+old_archive_cmds=$lt_old_archive_cmds
+
+# A language specific compiler.
+CC=$lt_compiler
+
+# Is the compiler the GNU compiler?
+with_gcc=$GCC
+
+# Compiler flag to turn off builtin functions.
+no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag
+
+# How to pass a linker flag through the compiler.
+wl=$lt_lt_prog_compiler_wl
+
+# Additional compiler flags for building library objects.
+pic_flag=$lt_lt_prog_compiler_pic
+
+# Compiler flag to prevent dynamic linking.
+link_static_flag=$lt_lt_prog_compiler_static
+
+# Does compiler simultaneously support -c and -o options?
+compiler_c_o=$lt_lt_cv_prog_compiler_c_o
+
+# Whether or not to add -lc for building shared libraries.
+build_libtool_need_lc=$archive_cmds_need_lc
+
+# Whether or not to disallow shared libs when runtime libs are static.
+allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes
+
+# Compiler flag to allow reflexive dlopens.
+export_dynamic_flag_spec=$lt_export_dynamic_flag_spec
+
+# Compiler flag to generate shared objects directly from archives.
+whole_archive_flag_spec=$lt_whole_archive_flag_spec
+
+# Whether the compiler copes with passing no objects directly.
+compiler_needs_object=$lt_compiler_needs_object
+
+# Create an old-style archive from a shared archive.
+old_archive_from_new_cmds=$lt_old_archive_from_new_cmds
+
+# Create a temporary old-style archive to link instead of a shared archive.
+old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds
+
+# Commands used to build a shared archive.
+archive_cmds=$lt_archive_cmds
+archive_expsym_cmds=$lt_archive_expsym_cmds
+
+# Commands used to build a loadable module if different from building
+# a shared archive.
+module_cmds=$lt_module_cmds
+module_expsym_cmds=$lt_module_expsym_cmds
+
+# Whether we are building with GNU ld or not.
+with_gnu_ld=$lt_with_gnu_ld
+
+# Flag that allows shared libraries with undefined symbols to be built.
+allow_undefined_flag=$lt_allow_undefined_flag
+
+# Flag that enforces no undefined symbols.
+no_undefined_flag=$lt_no_undefined_flag
+
+# Flag to hardcode \$libdir into a binary during linking.
+# This must work even if \$libdir does not exist
+hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec
+
+# If ld is used when linking, flag to hardcode \$libdir into a binary
+# during linking.  This must work even if \$libdir does not exist.
+hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld
+
+# Whether we need a single "-rpath" flag with a separated argument.
+hardcode_libdir_separator=$lt_hardcode_libdir_separator
+
+# Set to "yes" if using DIR/libNAME\${shared_ext} during linking hardcodes
+# DIR into the resulting binary.
+hardcode_direct=$hardcode_direct
+
+# Set to "yes" if using DIR/libNAME\${shared_ext} during linking hardcodes
+# DIR into the resulting binary and the resulting library dependency is
+# "absolute",i.e impossible to change by setting \${shlibpath_var} if the
+# library is relocated.
+hardcode_direct_absolute=$hardcode_direct_absolute
+
+# Set to "yes" if using the -LDIR flag during linking hardcodes DIR
+# into the resulting binary.
+hardcode_minus_L=$hardcode_minus_L
+
+# Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR
+# into the resulting binary.
+hardcode_shlibpath_var=$hardcode_shlibpath_var
+
+# Set to "yes" if building a shared library automatically hardcodes DIR
+# into the library and all subsequent libraries and executables linked
+# against it.
+hardcode_automatic=$hardcode_automatic
+
+# Set to yes if linker adds runtime paths of dependent libraries
+# to runtime path list.
+inherit_rpath=$inherit_rpath
+
+# Whether libtool must link a program against all its dependency libraries.
+link_all_deplibs=$link_all_deplibs
+
+# Fix the shell variable \$srcfile for the compiler.
+fix_srcfile_path=$lt_fix_srcfile_path
+
+# Set to "yes" if exported symbols are required.
+always_export_symbols=$always_export_symbols
+
+# The commands to list exported symbols.
+export_symbols_cmds=$lt_export_symbols_cmds
+
+# Symbols that should not be listed in the preloaded symbols.
+exclude_expsyms=$lt_exclude_expsyms
+
+# Symbols that must always be exported.
+include_expsyms=$lt_include_expsyms
+
+# Commands necessary for linking programs (against libraries) with templates.
+prelink_cmds=$lt_prelink_cmds
+
+# Specify filename containing input files.
+file_list_spec=$lt_file_list_spec
+
+# How to hardcode a shared library path into an executable.
+hardcode_action=$hardcode_action
+
+# ### END LIBTOOL CONFIG
+
+_LT_EOF
+
+  case $host_os in
+  aix3*)
+    cat <<\_LT_EOF >> "$cfgfile"
+# AIX sometimes has problems with the GCC collect2 program.  For some
+# reason, if we set the COLLECT_NAMES environment variable, the problems
+# vanish in a puff of smoke.
+if test "X${COLLECT_NAMES+set}" != Xset; then
+  COLLECT_NAMES=
+  export COLLECT_NAMES
+fi
+_LT_EOF
+    ;;
+  esac
+
+
+ltmain="$ac_aux_dir/ltmain.sh"
+
+
+  # We use sed instead of cat because bash on DJGPP gets confused if
+  # if finds mixed CR/LF and LF-only lines.  Since sed operates in
+  # text mode, it properly converts lines to CR/LF.  This bash problem
+  # is reportedly fixed, but why not run on old versions too?
+  sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \
+    || (rm -f "$cfgfile"; exit 1)
+
+  case $xsi_shell in
+  yes)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_dirname file append nondir_replacement
+# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
+# otherwise set result to NONDIR_REPLACEMENT.
+func_dirname ()
+{
+  case ${1} in
+    */*) func_dirname_result="${1%/*}${2}" ;;
+    *  ) func_dirname_result="${3}" ;;
+  esac
+}
+
+# func_basename file
+func_basename ()
+{
+  func_basename_result="${1##*/}"
+}
+
+# func_dirname_and_basename file append nondir_replacement
+# perform func_basename and func_dirname in a single function
+# call:
+#   dirname:  Compute the dirname of FILE.  If nonempty,
+#             add APPEND to the result, otherwise set result
+#             to NONDIR_REPLACEMENT.
+#             value returned in "$func_dirname_result"
+#   basename: Compute filename of FILE.
+#             value retuned in "$func_basename_result"
+# Implementation must be kept synchronized with func_dirname
+# and func_basename. For efficiency, we do not delegate to
+# those functions but instead duplicate the functionality here.
+func_dirname_and_basename ()
+{
+  case ${1} in
+    */*) func_dirname_result="${1%/*}${2}" ;;
+    *  ) func_dirname_result="${3}" ;;
+  esac
+  func_basename_result="${1##*/}"
+}
+
+# func_stripname prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+func_stripname ()
+{
+  # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
+  # positional parameters, so assign one to ordinary parameter first.
+  func_stripname_result=${3}
+  func_stripname_result=${func_stripname_result#"${1}"}
+  func_stripname_result=${func_stripname_result%"${2}"}
+}
+
+# func_opt_split
+func_opt_split ()
+{
+  func_opt_split_opt=${1%%=*}
+  func_opt_split_arg=${1#*=}
+}
+
+# func_lo2o object
+func_lo2o ()
+{
+  case ${1} in
+    *.lo) func_lo2o_result=${1%.lo}.${objext} ;;
+    *)    func_lo2o_result=${1} ;;
+  esac
+}
+
+# func_xform libobj-or-source
+func_xform ()
+{
+  func_xform_result=${1%.*}.lo
+}
+
+# func_arith arithmetic-term...
+func_arith ()
+{
+  func_arith_result=$(( $* ))
+}
+
+# func_len string
+# STRING may not start with a hyphen.
+func_len ()
+{
+  func_len_result=${#1}
+}
+
+_LT_EOF
+    ;;
+  *) # Bourne compatible functions.
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_dirname file append nondir_replacement
+# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
+# otherwise set result to NONDIR_REPLACEMENT.
+func_dirname ()
+{
+  # Extract subdirectory from the argument.
+  func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"`
+  if test "X$func_dirname_result" = "X${1}"; then
+    func_dirname_result="${3}"
+  else
+    func_dirname_result="$func_dirname_result${2}"
+  fi
+}
+
+# func_basename file
+func_basename ()
+{
+  func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
+}
+
+
+# func_stripname prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+# func_strip_suffix prefix name
+func_stripname ()
+{
+  case ${2} in
+    .*) func_stripname_result=`$ECHO "X${3}" \
+           | $Xsed -e "s%^${1}%%" -e "s%\\\\${2}\$%%"`;;
+    *)  func_stripname_result=`$ECHO "X${3}" \
+           | $Xsed -e "s%^${1}%%" -e "s%${2}\$%%"`;;
+  esac
+}
+
+# sed scripts:
+my_sed_long_opt='1s/^\(-[^=]*\)=.*/\1/;q'
+my_sed_long_arg='1s/^-[^=]*=//'
+
+# func_opt_split
+func_opt_split ()
+{
+  func_opt_split_opt=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_opt"`
+  func_opt_split_arg=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_arg"`
+}
+
+# func_lo2o object
+func_lo2o ()
+{
+  func_lo2o_result=`$ECHO "X${1}" | $Xsed -e "$lo2o"`
+}
+
+# func_xform libobj-or-source
+func_xform ()
+{
+  func_xform_result=`$ECHO "X${1}" | $Xsed -e 's/\.[^.]*$/.lo/'`
+}
+
+# func_arith arithmetic-term...
+func_arith ()
+{
+  func_arith_result=`expr "$@"`
+}
+
+# func_len string
+# STRING may not start with a hyphen.
+func_len ()
+{
+  func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
+}
+
+_LT_EOF
+esac
+
+case $lt_shell_append in
+  yes)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_append var value
+# Append VALUE to the end of shell variable VAR.
+func_append ()
+{
+  eval "$1+=\$2"
+}
+_LT_EOF
+    ;;
+  *)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_append var value
+# Append VALUE to the end of shell variable VAR.
+func_append ()
+{
+  eval "$1=\$$1\$2"
+}
+
+_LT_EOF
+    ;;
+  esac
+
+
+  sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> "$cfgfile" \
+    || (rm -f "$cfgfile"; exit 1)
+
+  mv -f "$cfgfile" "$ofile" ||
+    (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
+  chmod +x "$ofile"
+
+ ;;
+    "default-1":C)
+    for ac_file in $CONFIG_FILES; do
+      # Support "outfile[:infile[:infile...]]"
+      case "$ac_file" in
+        *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
+      esac
+      # PO directories have a Makefile.in generated from Makefile.in.in.
+      case "$ac_file" in */Makefile.in)
+        # Adjust a relative srcdir.
+        ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
+        ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
+        ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
+        # In autoconf-2.13 it is called $ac_given_srcdir.
+        # In autoconf-2.50 it is called $srcdir.
+        test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
+        case "$ac_given_srcdir" in
+          .)  top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
+          /*) top_srcdir="$ac_given_srcdir" ;;
+          *)  top_srcdir="$ac_dots$ac_given_srcdir" ;;
+        esac
+        # Treat a directory as a PO directory if and only if it has a
+        # POTFILES.in file. This allows packages to have multiple PO
+        # directories under different names or in different locations.
+        if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then
+          rm -f "$ac_dir/POTFILES"
+          test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES"
+          cat "$ac_given_srcdir/$ac_dir/POTFILES.in" | sed -e "/^#/d" -e "/^[  ]*\$/d" -e "s,.*,     $top_srcdir/& \\\\," | sed -e "\$s/\(.*\) \\\\/\1/" > "$ac_dir/POTFILES"
+          POMAKEFILEDEPS="POTFILES.in"
+          # ALL_LINGUAS, POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES depend
+          # on $ac_dir but don't depend on user-specified configuration
+          # parameters.
+          if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then
+            # The LINGUAS file contains the set of available languages.
+            if test -n "$OBSOLETE_ALL_LINGUAS"; then
+              test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete"
+            fi
+            ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"`
+            # Hide the ALL_LINGUAS assigment from automake.
+            eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
+            POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
+          else
+            # The set of available languages was given in configure.in.
+            eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS'
+          fi
+          # Compute POFILES
+          # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
+          # Compute UPDATEPOFILES
+          # as      $(foreach lang, $(ALL_LINGUAS), $(lang).po-update)
+          # Compute DUMMYPOFILES
+          # as      $(foreach lang, $(ALL_LINGUAS), $(lang).nop)
+          # Compute GMOFILES
+          # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo)
+          case "$ac_given_srcdir" in
+            .) srcdirpre= ;;
+            *) srcdirpre='$(srcdir)/' ;;
+          esac
+          POFILES=
+          UPDATEPOFILES=
+          DUMMYPOFILES=
+          GMOFILES=
+          for lang in $ALL_LINGUAS; do
+            POFILES="$POFILES $srcdirpre$lang.po"
+            UPDATEPOFILES="$UPDATEPOFILES $lang.po-update"
+            DUMMYPOFILES="$DUMMYPOFILES $lang.nop"
+            GMOFILES="$GMOFILES $srcdirpre$lang.gmo"
+          done
+          # CATALOGS depends on both $ac_dir and the user's LINGUAS
+          # environment variable.
+          INST_LINGUAS=
+          if test -n "$ALL_LINGUAS"; then
+            for presentlang in $ALL_LINGUAS; do
+              useit=no
+              if test "%UNSET%" != "$LINGUAS"; then
+                desiredlanguages="$LINGUAS"
+              else
+                desiredlanguages="$ALL_LINGUAS"
+              fi
+              for desiredlang in $desiredlanguages; do
+                # Use the presentlang catalog if desiredlang is
+                #   a. equal to presentlang, or
+                #   b. a variant of presentlang (because in this case,
+                #      presentlang can be used as a fallback for messages
+                #      which are not translated in the desiredlang catalog).
+                case "$desiredlang" in
+                  "$presentlang"*) useit=yes;;
+                esac
+              done
+              if test $useit = yes; then
+                INST_LINGUAS="$INST_LINGUAS $presentlang"
+              fi
+            done
+          fi
+          CATALOGS=
+          if test -n "$INST_LINGUAS"; then
+            for lang in $INST_LINGUAS; do
+              CATALOGS="$CATALOGS $lang.gmo"
+            done
+          fi
+          test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile"
+          sed -e "/^POTFILES =/r $ac_dir/POTFILES" -e "/^# Makevars/r $ac_given_srcdir/$ac_dir/Makevars" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@POMAKEFILEDEPS@|$POMAKEFILEDEPS|g" "$ac_dir/Makefile.in" > "$ac_dir/Makefile"
+          for f in "$ac_given_srcdir/$ac_dir"/Rules-*; do
+            if test -f "$f"; then
+              case "$f" in
+                *.orig | *.bak | *~) ;;
+                *) cat "$f" >> "$ac_dir/Makefile" ;;
+              esac
+            fi
+          done
+        fi
+        ;;
+      esac
+    done ;;
+
+  esac
+done # for ac_tag
+
+
+as_fn_exit 0
+_ACEOF
+ac_clean_files=$ac_clean_files_save
+
+test $ac_write_fail = 0 ||
+  as_fn_error "write failure creating $CONFIG_STATUS" "$LINENO" 5
+
+
+# configure is writing to config.log, and then calls config.status.
+# config.status does its own redirection, appending to config.log.
+# Unfortunately, on DOS this fails, as config.log is still kept open
+# by configure, so config.status won't be able to write to it; its
+# output is simply discarded.  So we exec the FD to /dev/null,
+# effectively closing config.log, so it can be properly (re)opened and
+# appended to by config.status.  When coming back to configure, we
+# need to make the FD available again.
+if test "$no_create" != yes; then
+  ac_cs_success=:
+  ac_config_status_args=
+  test "$silent" = yes &&
+    ac_config_status_args="$ac_config_status_args --quiet"
+  exec 5>/dev/null
+  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
+  exec 5>>config.log
+  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
+  # would make configure fail if this is the last instruction.
+  $ac_cs_success || as_fn_exit $?
+fi
+if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
+$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
+fi
+
+
+echo "The m17n library is configured with these external libraries."
+echo " $M17N_EXT_LIBS"
+
diff --git a/configure.ac b/configure.ac
new file mode 100644 (file)
index 0000000..bda8981
--- /dev/null
@@ -0,0 +1,466 @@
+dnl configure.ac -- autoconf script for the m17n library.
+
+dnl Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+dnl   National Institute of Advanced Industrial Science and Technology (AIST)
+dnl   Registration Number H15PRO112
+
+dnl This file is part of the m17n library.
+
+dnl The m17n library is free software; you can redistribute it and/or
+dnl modify it under the terms of the GNU Lesser General Public License
+dnl as published by the Free Software Foundation; either version 2.1 of
+dnl the License, or (at your option) any later version.
+
+dnl The m17n library is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+dnl Lesser General Public License for more details.
+
+dnl You should have received a copy of the GNU Lesser General Public
+dnl License along with the m17n library; if not, write to the Free
+dnl Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+dnl Boston, MA 02110-1301, USA.
+
+dnl Process this file with autoconf to produce a configure script.
+
+AC_INIT([m17n-lib],[1.6.1],[m17n-lib-bug@m17n.org])
+AC_CONFIG_MACRO_DIR([m4])
+AM_INIT_AUTOMAKE
+AC_PROG_LIBTOOL
+AC_CONFIG_HEADERS([src/config.h])
+AM_MAINTAINER_MODE
+
+API_VERSION=4:0:4
+AC_SUBST(API_VERSION)
+
+# The earliest version that this release has binary compatibility
+# with.  This is used for module locations.
+M17N_BINARY_VERSION=1.0
+
+M17N_MODULE_DIR="m17n/$M17N_BINARY_VERSION"
+AC_SUBST(M17N_MODULE_DIR)
+
+AM_GNU_GETTEXT
+GETTEXTDIR="$datadir/locale"
+AC_SUBST(GETTEXTDIR)
+
+dnl Checks for programs for compiling.
+AC_PROG_CC
+dnl LT_PREREQ([2.2.4])
+dnl LT_INIT
+
+dnl Checks for X libraries.
+AC_PATH_XTRA
+
+dnl Checks for standard header files.
+AC_HEADER_STDC
+AC_HEADER_DIRENT
+AC_HEADER_TIME
+AC_CHECK_HEADERS([fcntl.h langinfo.h limits.h locale.h stdlib.h \
+                         string.h strings.h sys/time.h unistd.h])
+AC_CHECK_HEADER(X11/Xaw/Command.h, HAVE_XAW=yes)
+
+dnl Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+AC_C_INLINE
+AC_TYPE_SIZE_T
+AC_STRUCT_TM
+
+dnl Checks for endian.  This influence the default UTF-16 definition.
+AC_C_BIGENDIAN
+
+dnl Checks for library functions.
+AC_FUNC_ALLOCA
+AC_FUNC_MALLOC
+AC_FUNC_REALLOC
+AC_FUNC_MEMCMP
+AC_FUNC_STAT
+AC_FUNC_STRCOLL
+AC_FUNC_STRFTIME
+AC_FUNC_STRTOD
+AC_CHECK_FUNCS(memmove memset nl_langinfo putenv regcomp setlocale)
+AC_CHECK_FUNCS(strchr strdup gettimeofday)
+
+dnl Checks where the m17n database is installed.
+
+AC_CHECK_PROG(HAVE_M17N_DB, m17n-db, yes)
+if test "x$HAVE_M17N_DB" = "xyes"; then
+  M17NDIR=`m17n-db`
+else
+  M17NDIR="${datadir}/m17n"
+fi
+AC_SUBST(M17NDIR)
+
+dnl Checks which levels of APIs should be compiled.
+
+AC_ARG_ENABLE(gui,
+             AS_HELP_STRING([--with-gui],[with GUI level APIs (default is YES)]))
+
+AM_CONDITIONAL(WITH_GUI, test x$with_gui != xno)
+
+if test x$with_gui != xno; then
+
+dnl Checks if dlopen exists, and if it's in libc or libdl.
+
+AC_SEARCH_LIBS(dlopen, dl,
+              AC_DEFINE(HAVE_DLOPEN, 1,
+              [Define to 1 if you have the function dlopen.]))
+
+dnl Check several libraries without adding -lxxx to LIBS, without
+dnl defining HAVE_LIBXXX nor HAVE_XXX_H because they are used only by
+dnl some libraries (e.g. libm17n-X.so).  Instead, define XXX_LD_FLAGS
+dnl and HAVE_XXX if library XXX is available.  CPPFLAGS will be
+dnl augmented.
+
+M17N_EXT_LIBS=
+
+AC_CHECK_PROG(HAVE_PKG_CONFIG, pkg-config, yes)
+
+if test "x$no_x" != "xyes"; then
+  AC_DEFINE(HAVE_X11, 1, [Define to 1 if you have X11.])
+  X11_LD_FLAGS="-lXt -lX11"
+  M17N_EXT_LIBS="$M17N_EXT_LIBS X11"
+
+  if test "x$HAVE_XAW" = "xyes"; then
+    AC_DEFINE(HAVE_X11_XAW_COMMAND_H, 1,
+             [Define to 1 if you have the Xaw header files.])
+    XAW_LD_FLAGS="-lXaw -lXmu"
+    CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_X11_XAW_COMMAND_H"
+    M17N_EXT_LIBS="$M17N_EXT_LIBS Xaw"
+  fi
+fi
+AC_SUBST(X11_LD_FLAGS)
+AC_SUBST(XAW_LD_FLAGS)
+
+dnl Check for fribidi library.
+save_CPPFLAGS="$CPPFLAGS"
+save_LIBS="$LIBS"
+AC_CHECK_PROG(HAVE_FRIBIDI_CONFIG, fribidi-config, yes)
+if test "x$HAVE_FRIBIDI_CONFIG" = "xyes"; then
+  CPPFLAGS="$CPPFLAGS `fribidi-config --cflags`"
+  FRIBIDI_LD_FLAGS="`fribidi-config --libs`"
+  LIBS="$LIBS $FRIBIDI_LD_FLAGS"
+else
+  FRIBIDI_LD_FLAGS=-lfribidi
+fi
+AC_CHECK_LIB(fribidi, fribidi_set_mirroring, HAVE_FRIBIDI=yes, HAVE_FRIBIDI=no)
+AC_CHECK_HEADER(fribidi/fribidi.h,, HAVE_FRIBIDI=no)
+if test "x$HAVE_FRIBIDI" = "xyes"; then
+  AC_DEFINE(HAVE_FRIBIDI, 1, 
+           [Define to 1 if you have Fribidi library and header file.])
+  M17N_EXT_LIBS="$M17N_EXT_LIBS fribidi"
+else
+  CPPFLAGS="$save_CPPFLAGS"
+  FRIBIDI_LD_FLAGS=
+fi
+LIBS="$save_LIBS"
+AC_SUBST(FRIBIDI_LD_FLAGS)
+
+dnl Check for otflib usability.
+AC_ARG_WITH(libotf, 
+           AS_HELP_STRING([--with-libotf],[with OpenType font suport (default is YES)]))
+
+if test "x$with_libotf" != "xno"; then
+  save_CPPFLAGS="$CPPFLAGS"
+  save_LIBS="$LIBS"
+  AC_CHECK_PROG(HAVE_OTFLIB_CONFIG, libotf-config, yes)
+  if test "x$HAVE_OTFLIB_CONFIG" = "xyes"; then
+    CPPFLAGS="$CPPFLAGS `libotf-config --cflags`"
+    OTF_LD_FLAGS="`libotf-config --libs`"
+    LIBS="$LIBS $OTF_LD_FLAGS"
+  else
+    OTF_LD_FLAGS=-lotf
+  fi
+  ## We check the availability of OTF_check_features
+  ## because we need libotf-0.9.4 or the later.
+  AC_CHECK_LIB(otf, OTF_check_features, HAVE_OTF=yes, HAVE_OTF=no)
+  AC_CHECK_HEADER(otf.h,, HAVE_OTF=no)
+  if test "x$HAVE_OTF" = "xyes"; then
+    AC_DEFINE(HAVE_OTF, 1, 
+             [Define to 1 if you have OTF library and header file.])
+    M17N_EXT_LIBS="$M17N_EXT_LIBS libotf"
+    AC_CHECK_LIB(otf, OTF_drive_gpos2, HAVE_OTF_DRIVE_GPOS2=yes,
+                HAVE_OTF_DRIVE_GPOS2=no)
+    if test "x$HAVE_OTF_DRIVE_GPOS2" = "xyes"; then
+      AC_DEFINE(HAVE_OTF_DRIVE_GPOS2, 1,
+                [Define to 1 if the OTF library has OTF_drive_gpos2().])
+    fi
+  else
+    CPPFLAGS="$save_CPPFLAGS"
+    OTF_LD_FLAGS=
+  fi
+  LIBS="$save_LIBS"
+fi
+AC_SUBST(OTF_LD_FLAGS)
+
+dnl Check for Freetype2 usability.
+AC_CHECK_PROG(HAVE_FREETYPE_CONFIG, freetype-config, yes)
+if test "x$HAVE_FREETYPE_CONFIG" = "xyes"; then
+  FREETYPE_INC=`freetype-config --cflags`
+  save_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $FREETYPE_INC"
+  AC_CHECK_HEADER(ft2build.h, HAVE_FREETYPE=yes,
+                             HAVE_FREETYPE=no CPPFLAGS="$save_CPPFLAGS")
+  if test "x$HAVE_FREETYPE" = "xyes" ; then
+    save_LIBS="$LIBS"
+    LIBS="$LIBS `freetype-config --libs`"
+    AC_CHECK_LIB(freetype, FT_Init_FreeType, HAVE_FREETYPE=yes,
+                                            HAVE_FREETYPE=no)
+    LIBS="$save_LIBS"
+    if test "x$HAVE_FREETYPE" = "xyes"; then
+      FREETYPE_LD_FLAGS=`freetype-config --libs`
+      AC_DEFINE(HAVE_FREETYPE, 1, 
+               [Define to 1 if you have FreeType library and header file.])
+      M17N_EXT_LIBS="$M17N_EXT_LIBS freetype"
+      AC_CHECK_HEADER(freetype/ftbdf.h, HAVE_FTBDF_H=yes, HAVE_FTBDF_H=no,
+                     [#include <ft2build.h>
+#include FT_FREETYPE_H])
+      if test "x$HAVE_FTBDF_H" = "xyes"; then
+        AC_DEFINE(HAVE_FTBDF_H, 1,
+                 [Define to 1 if you have freetype/ftbdf.h.])
+      fi
+      CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_FREETYPE"
+    fi
+  fi
+fi
+AC_SUBST(FREETYPE_LD_FLAGS)
+
+dnl Check for Xft2 usability.
+save_CPPFLAGS="$CPPFLAGS"
+save_LIBS="$LIBS"
+XFT2_LD_FLAGS="-lXft -lfreetype -lfontconfig -lXrender -lX11"
+AC_CHECK_PROG(HAVE_XFT_CONFIG, xft-config, yes)
+if test "x$HAVE_XFT_CONFIG" = "xyes"; then
+  CPPFLAGS="$CPPFLAGS `xft-config --cflags`"
+  XFT2_LD_FLAGS="`xft-config --libs`"
+elif test "x$HAVE_PKG_CONFIG" = "xyes" ; then
+  if pkg-config xft ; then
+    CPPFLAGS="$CPPFLAGS `pkg-config --cflags xft`"
+    XFT2_LD_FLAGS="`pkg-config --libs xft`"
+  fi
+fi
+LIBS="$LIBS $XFT2_LD_FLAGS"
+AC_CHECK_LIB(Xft, XftDrawCreate, HAVE_XFT2=yes, HAVE_XFT2=no)
+AC_CHECK_HEADER(X11/Xft/Xft.h,, HAVE_XFT2=no, 
+               [#include <X11/Xft/Xft.h>
+#if XftVersion >= 20000
+#else
+Version too old.  Compiling this line should fail.
+#endif])
+if test "x$HAVE_XFT2" = "xyes"; then
+  AC_DEFINE(HAVE_XFT2, 1,
+           [Define to 1 if you have Xft2 library and header file.])
+  M17N_EXT_LIBS="$M17N_EXT_LIBS xft2"
+else
+  XFT2_LD_FLAGS=
+  CPPFLAGS="$save_CPPFLAGS"
+fi
+LIBS="$save_LIBS"
+AC_SUBST(XFT2_LD_FLAGS)
+
+dnl Check for fontconfig usability.
+AC_ARG_WITH(fontconfig,
+           AS_HELP_STRING([--with-fontconfig],[with FontConfig library (default is YES)]))
+if test "x$with_fontconfig" != "xno"; then
+  save_CPPFLAGS="$CPPFLAGS"
+  save_LIBS="$LIBS"
+  FONTCONFIG_LD_FLAGS=-lfontconfig
+  if test "x$HAVE_PKG_CONFIG" = "xyes"; then
+    if pkg-config --exists fontconfig; then
+      CPPFLAGS="$CPPFLAGS `pkg-config --cflags fontconfig`"
+      FONTCONFIG_LD_FLAGS="`pkg-config --libs fontconfig`"
+      LIBS="$LIBS $FONTCONFIG_LD_FLAGS"
+    fi
+  fi
+  AC_CHECK_LIB(fontconfig, FcInit, HAVE_FONTCONFIG=yes, HAVE_FONTCONFIG=no)
+  AC_CHECK_HEADER(fontconfig/fontconfig.h, , HAVE_FONTCONFIG=no)
+  if test "x$HAVE_FONTCONFIG" = "xyes"; then
+    AC_DEFINE(HAVE_FONTCONFIG, 1,
+             [Define to 1 if you have fontconfig library and header file.])
+    M17N_EXT_LIBS="$M17N_EXT_LIBS fontconfig"
+  else
+    FONTCONFIG_LD_FLAGS=
+    CPPFLAGS="$save_CPPFLAGS"
+  fi
+  LIBS="$save_LIBS"
+fi
+AC_SUBST(FONTCONFIG_LD_FLAGS)
+
+dnl Check for gdlib usability.
+AC_ARG_WITH(gd, 
+           AS_HELP_STRING([--with-gd],[suport graphic device by GD library (default is YES)]))
+
+if test "x$with_gd" != "xno"; then
+  save_LIBS="$LIBS"
+  AC_CHECK_LIB(gd, gdImageCreate, HAVE_GD=yes, HAVE_GD=no)
+  AC_CHECK_HEADER(gd.h, , HAVE_GD=no)
+  if test "x$HAVE_GD" = "xyes"; then
+    AC_CHECK_LIB(gd, gdImageCreateTrueColor, HAVE_GD=2, HAVE_GD=1)
+    AC_DEFINE_UNQUOTED(HAVE_GD, $HAVE_GD,
+             [Define to 1 or 2 if you have gd library and header file.])
+    M17N_EXT_LIBS="$M17N_EXT_LIBS gdlib"
+    GD_LD_FLAGS=-lgd
+    CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_GD=$HAVE_GD"
+  fi
+  LIBS="$save_LIBS"
+fi
+AC_SUBST(GD_LD_FLAGS)
+
+fi
+
+dnl Check for libxml2 usability.
+save_CPPFLAGS="$CPPFLAGS"
+save_LIBS="$LIBS"
+AC_CHECK_PROG(HAVE_XML2_CONFIG, xml2-config, yes)
+if test "x$HAVE_XML2_CONFIG" = "xyes"; then
+  CPPFLAGS="$CPPFLAGS `xml2-config --cflags`"
+  XML2_LD_FLAGS="`xml2-config --libs`"
+  LIBS="$LIBS $XML2_LD_FLAGS"
+else
+  CPPFLAGS="$CPPFLAGS -I/usr/include/libxml2"
+  XML2_LD_FLAGS="-lxml2 -lz -lpthread -lm"
+fi
+AC_CHECK_LIB(xml2, xmlParseMemory, HAVE_XML2=yes, HAVE_XML2=no)
+AC_CHECK_HEADER(libxml/tree.h,, HAVE_XML2=no, /**/)
+if test "x$HAVE_XML2" = "xyes"; then
+  AC_DEFINE(HAVE_XML2, 1,
+           [Define to 1 if you have libxml2 library and header file])
+  M17N_EXT_LIBS="$M17N_EXT_LIBS xml2"
+else
+  XML2_LD_FLAGS=
+  CPPFLAGS="$save_CPPFLAGS"
+fi
+LIBS="$save_LIBS"
+AC_SUBST(XML2_LD_FLAGS)
+
+dnl Check for Anthy usability.
+
+PKG_CHECK_MODULES(ANTHY, anthy, HAVE_ANTHY=yes, HAVE_ANTHY=no)
+if test "x$HAVE_ANTHY" = "xyes"; then
+  AC_DEFINE(HAVE_ANTHY, 1,
+          [Define to 1 if you have Anthy library and header file])
+  M17N_EXT_LIBS="$M17N_EXT_LIBS anthy"
+  ANTHY_LD_FLAGS="$ANTHY_LIBS"
+  CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_ANTHY"
+fi
+AC_SUBST(ANTHY_LD_FLAGS)
+
+dnl Check for Ispell usability.
+AC_CHECK_PROG(HAVE_ISPELL, ispell, yes)
+if test "x$HAVE_ISPELL" = "xyes"; then
+  AC_DEFINE(HAVE_ISPELL, 1, [Define if ispell is available.])
+  M17N_EXT_LIBS="$M17N_EXT_LIBS ispell"
+  CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_ISPELL"
+fi
+
+dnl Check for Thai word-segmentation library.
+dnl If we have one, define HAVE_THAI_WORDSEG and one of these:
+dnl   HAVE_LIBTHAI, HAVE_WORDCUT, or HAVE_WORDCUT_OLD
+dnl In addition, set THAI_WORDSEG_LD_FLAGS to a proper value.
+
+PKG_CHECK_MODULES(LIBTHAI, libthai, HAVE_LIBTHAI=yes, HAVE_LIBTHAI=no)
+PKG_CHECK_MODULES(WORDCUT, wordcut, HAVE_WORDCUT=yes, HAVE_WORDCUT=no)
+
+if test "x$HAVE_LIBTHAI" == "xyes"; then
+
+  AC_DEFINE(HAVE_LIBTHAI, 1, [Define if you have libthai])
+  THAI_WORDSEG_LD_FLAGS="$LIBTHAI_LIBS"
+  M17N_EXT_LIBS="$M17N_EXT_LIBS libthai"
+  HAVE_THAI_WORDSEG=yes
+
+elif test "x$HAVE_WORDCUT" = "xyes"; then
+
+  save_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $WORDCUT_CFLAGS"
+  AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <wordcut/wcwordcut.h>]])],[],[HAVE_WORDCUT=no])
+  if test "x$HAVE_WORDCUT" = "xno"; then
+    PKG_CHECK_MODULES(GLIB_2_0, glib-2.0, HAVE_GLIB_2_0=yes, HAVE_GLIB_2_0=no)
+    if test "x$HAVE_GLIB_2_0" = "xyes"; then
+      CPPFLAGS="$CPPFLAGS $GLIB_2_0_CFLAGS"
+      AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <wordcut/wcwordcut.h>]])],[HAVE_WORDCUT=yes],[])
+    fi
+  fi
+  if test "x$HAVE_WORDCUT" = "xyes"; then
+    THAI_WORDSEG_LD_FLAGS="$WORDCUT_LIBS"
+    AC_DEFINE(HAVE_WORDCUT, 1,
+             [Define if you have the wordcut library and header file])
+    M17N_EXT_LIBS="$M17N_EXT_LIBS wordcut"
+    HAVE_THAI_WORDSEG=yes
+  else
+    CPPFLAGS="$save_CPPFLAGS"
+  fi
+
+else
+
+  AC_CHECK_LIB(wordcut, wordcut_init, HAVE_WORDCUT_OLD=yes)
+  if test "x$HAVE_WORDCUT_OLD" = "xyes"; then
+    if test -f "/usr/share/wordcut/tdict.wcd"; then
+      tdict="/usr/share/wordcut/tdict.wcd"
+    elif test -f "/usr/local/share/wordcut/tdict.wcd"; then
+      tdict="/usr/local/share/wordcut/tdict.wcd"
+    fi
+    echo "TDICT=$tdict"
+    if test "x$tdict" != "x"; then
+      AC_DEFINE(HAVE_WORDCUT_OLD, 1,
+               [Define if you have the old version of wordcut library])
+      AC_DEFINE_UNQUOTED(WORDCUT_TDICT, "$tdict", [Define tdict file name])
+      THAI_WORDSEG_LD_FLAGS=-lwordcut
+      M17N_EXT_LIBS="$M17N_EXT_LIBS wordcut-old"
+      HAVE_THAI_WORDSEG=yes
+    else
+      HAVE_WORDCUT=no
+    fi
+  fi
+fi  
+
+if test "x$HAVE_THAI_WORDSEG" = "xyes"; then
+  AC_DEFINE(HAVE_THAI_WORDSEG, 1,
+            [Define if you have some Thai word-segmentation library])
+fi
+AC_SUBST(THAI_WORDSEG_LD_FLAGS)
+
+AC_SUBST(CONFIG_FLAGS)
+
+dnl We can't include X_CFLAGS in AM_CPPFLAGS because the generated
+dnl Makefile put ${AM_CPPFLAGS} before ${CPPFLAGS} and that leads to
+dnl inclusion of an incorrect header file.  So, append X_CFLAGS to
+dnl CPPFLAGS here directly.
+
+CPPFLAGS="$CPPFLAGS $X_CFLAGS"
+
+dnl AC_ARG_ENABLE(xom, 
+dnl          [  --enable-xom            build and install XOM library.],
+dnl          XOM="$enableval")
+
+SHLIB_EXT=".so"
+case $host_os in
+darwin* | rhapsody*)
+  SHLIB_EXT=".dylib";;
+esac
+AC_DEFINE_UNQUOTED(DLOPEN_SHLIB_EXT, "$SHLIB_EXT",
+                  [Define to loadable module extention])
+
+AC_CONFIG_FILES([Makefile po/Makefile.in intl/Makefile
+                 src/Makefile
+                 example/Makefile
+                m17n-config
+                m17n-core.pc
+                m17n-shell.pc
+                m17n-flt.pc
+                m17n-gui.pc
+                ])
+
+dnl if test "x$XOM" = "xyes"; then
+dnl  AC_CONFIG_FILES(omM17N/Makefile)
+dnl fi
+
+AC_OUTPUT
+
+echo "The m17n library is configured with these external libraries."
+echo " $M17N_EXT_LIBS"
+
+dnl Local Variables:
+dnl comment-start: "dnl "
+dnl comment-end: ""
+dnl comment-start-skip: "\\bdnl\\b\\s *"
+dnl End:
diff --git a/depcomp b/depcomp
new file mode 100755 (executable)
index 0000000..df8eea7
--- /dev/null
+++ b/depcomp
@@ -0,0 +1,630 @@
+#! /bin/sh
+# depcomp - compile a program generating dependencies as side-effects
+
+scriptversion=2009-04-28.21; # UTC
+
+# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
+# Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program 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 General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
+
+case $1 in
+  '')
+     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
+     exit 1;
+     ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: depcomp [--help] [--version] PROGRAM [ARGS]
+
+Run PROGRAMS ARGS to compile a file, generating dependencies
+as side-effects.
+
+Environment variables:
+  depmode     Dependency tracking mode.
+  source      Source file read by `PROGRAMS ARGS'.
+  object      Object file output by `PROGRAMS ARGS'.
+  DEPDIR      directory where to store dependencies.
+  depfile     Dependency file to output.
+  tmpdepfile  Temporary file to use when outputing dependencies.
+  libtool     Whether libtool is used (yes/no).
+
+Report bugs to <bug-automake@gnu.org>.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "depcomp $scriptversion"
+    exit $?
+    ;;
+esac
+
+if test -z "$depmode" || test -z "$source" || test -z "$object"; then
+  echo "depcomp: Variables source, object and depmode must be set" 1>&2
+  exit 1
+fi
+
+# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
+depfile=${depfile-`echo "$object" |
+  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
+tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
+
+rm -f "$tmpdepfile"
+
+# Some modes work just like other modes, but use different flags.  We
+# parameterize here, but still list the modes in the big case below,
+# to make depend.m4 easier to write.  Note that we *cannot* use a case
+# here, because this file can only contain one case statement.
+if test "$depmode" = hp; then
+  # HP compiler uses -M and no extra arg.
+  gccflag=-M
+  depmode=gcc
+fi
+
+if test "$depmode" = dashXmstdout; then
+   # This is just like dashmstdout with a different argument.
+   dashmflag=-xM
+   depmode=dashmstdout
+fi
+
+cygpath_u="cygpath -u -f -"
+if test "$depmode" = msvcmsys; then
+   # This is just like msvisualcpp but w/o cygpath translation.
+   # Just convert the backslash-escaped backslashes to single forward
+   # slashes to satisfy depend.m4
+   cygpath_u="sed s,\\\\\\\\,/,g"
+   depmode=msvisualcpp
+fi
+
+case "$depmode" in
+gcc3)
+## gcc 3 implements dependency tracking that does exactly what
+## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
+## it if -MD -MP comes after the -MF stuff.  Hmm.
+## Unfortunately, FreeBSD c89 acceptance of flags depends upon
+## the command line argument order; so add the flags where they
+## appear in depend2.am.  Note that the slowdown incurred here
+## affects only configure: in makefiles, %FASTDEP% shortcuts this.
+  for arg
+  do
+    case $arg in
+    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
+    *)  set fnord "$@" "$arg" ;;
+    esac
+    shift # fnord
+    shift # $arg
+  done
+  "$@"
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  mv "$tmpdepfile" "$depfile"
+  ;;
+
+gcc)
+## There are various ways to get dependency output from gcc.  Here's
+## why we pick this rather obscure method:
+## - Don't want to use -MD because we'd like the dependencies to end
+##   up in a subdir.  Having to rename by hand is ugly.
+##   (We might end up doing this anyway to support other compilers.)
+## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
+##   -MM, not -M (despite what the docs say).
+## - Using -M directly means running the compiler twice (even worse
+##   than renaming).
+  if test -z "$gccflag"; then
+    gccflag=-MD,
+  fi
+  "$@" -Wp,"$gccflag$tmpdepfile"
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
+## The second -e expression handles DOS-style file names with drive letters.
+  sed -e 's/^[^:]*: / /' \
+      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
+## This next piece of magic avoids the `deleted header file' problem.
+## The problem is that when a header file which appears in a .P file
+## is deleted, the dependency causes make to die (because there is
+## typically no way to rebuild the header).  We avoid this by adding
+## dummy dependencies for each header file.  Too bad gcc doesn't do
+## this for us directly.
+  tr ' ' '
+' < "$tmpdepfile" |
+## Some versions of gcc put a space before the `:'.  On the theory
+## that the space means something, we add a space to the output as
+## well.
+## Some versions of the HPUX 10.20 sed can't process this invocation
+## correctly.  Breaking it into two sed invocations is a workaround.
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+hp)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+sgi)
+  if test "$libtool" = yes; then
+    "$@" "-Wp,-MDupdate,$tmpdepfile"
+  else
+    "$@" -MDupdate "$tmpdepfile"
+  fi
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+
+  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
+    echo "$object : \\" > "$depfile"
+
+    # Clip off the initial element (the dependent).  Don't try to be
+    # clever and replace this with sed code, as IRIX sed won't handle
+    # lines with more than a fixed number of characters (4096 in
+    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
+    # the IRIX cc adds comments like `#:fec' to the end of the
+    # dependency line.
+    tr ' ' '
+' < "$tmpdepfile" \
+    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
+    tr '
+' ' ' >> "$depfile"
+    echo >> "$depfile"
+
+    # The second pass generates a dummy entry for each header file.
+    tr ' ' '
+' < "$tmpdepfile" \
+   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
+   >> "$depfile"
+  else
+    # The sourcefile does not contain any dependencies, so just
+    # store a dummy comment line, to avoid errors with the Makefile
+    # "include basename.Plo" scheme.
+    echo "#dummy" > "$depfile"
+  fi
+  rm -f "$tmpdepfile"
+  ;;
+
+aix)
+  # The C for AIX Compiler uses -M and outputs the dependencies
+  # in a .u file.  In older versions, this file always lives in the
+  # current directory.  Also, the AIX compiler puts `$object:' at the
+  # start of each line; $object doesn't have directory information.
+  # Version 6 uses the directory in both cases.
+  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+  test "x$dir" = "x$object" && dir=
+  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$base.u
+    tmpdepfile3=$dir.libs/$base.u
+    "$@" -Wc,-M
+  else
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$dir$base.u
+    tmpdepfile3=$dir$base.u
+    "$@" -M
+  fi
+  stat=$?
+
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+    exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  if test -f "$tmpdepfile"; then
+    # Each line is of the form `foo.o: dependent.h'.
+    # Do two passes, one to just change these to
+    # `$object: dependent.h' and one to simply `dependent.h:'.
+    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
+    # That's a tab and a space in the [].
+    sed -e 's,^.*\.[a-z]*:[     ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
+  else
+    # The sourcefile does not contain any dependencies, so just
+    # store a dummy comment line, to avoid errors with the Makefile
+    # "include basename.Plo" scheme.
+    echo "#dummy" > "$depfile"
+  fi
+  rm -f "$tmpdepfile"
+  ;;
+
+icc)
+  # Intel's C compiler understands `-MD -MF file'.  However on
+  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
+  # ICC 7.0 will fill foo.d with something like
+  #    foo.o: sub/foo.c
+  #    foo.o: sub/foo.h
+  # which is wrong.  We want:
+  #    sub/foo.o: sub/foo.c
+  #    sub/foo.o: sub/foo.h
+  #    sub/foo.c:
+  #    sub/foo.h:
+  # ICC 7.1 will output
+  #    foo.o: sub/foo.c sub/foo.h
+  # and will wrap long lines using \ :
+  #    foo.o: sub/foo.c ... \
+  #     sub/foo.h ... \
+  #     ...
+
+  "$@" -MD -MF "$tmpdepfile"
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  # Each line is of the form `foo.o: dependent.h',
+  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
+  # Do two passes, one to just change these to
+  # `$object: dependent.h' and one to simply `dependent.h:'.
+  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
+  # Some versions of the HPUX 10.20 sed can't process this invocation
+  # correctly.  Breaking it into two sed invocations is a workaround.
+  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
+    sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+hp2)
+  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
+  # compilers, which have integrated preprocessors.  The correct option
+  # to use with these is +Maked; it writes dependencies to a file named
+  # 'foo.d', which lands next to the object file, wherever that
+  # happens to be.
+  # Much of this is similar to the tru64 case; see comments there.
+  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+  test "x$dir" = "x$object" && dir=
+  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir.libs/$base.d
+    "$@" -Wc,+Maked
+  else
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir$base.d
+    "$@" +Maked
+  fi
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+     rm -f "$tmpdepfile1" "$tmpdepfile2"
+     exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  if test -f "$tmpdepfile"; then
+    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
+    # Add `dependent.h:' lines.
+    sed -ne '2,${
+              s/^ *//
+              s/ \\*$//
+              s/$/:/
+              p
+            }' "$tmpdepfile" >> "$depfile"
+  else
+    echo "#dummy" > "$depfile"
+  fi
+  rm -f "$tmpdepfile" "$tmpdepfile2"
+  ;;
+
+tru64)
+   # The Tru64 compiler uses -MD to generate dependencies as a side
+   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
+   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
+   # dependencies in `foo.d' instead, so we check for that too.
+   # Subdirectories are respected.
+   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+   test "x$dir" = "x$object" && dir=
+   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+
+   if test "$libtool" = yes; then
+      # With Tru64 cc, shared objects can also be used to make a
+      # static library.  This mechanism is used in libtool 1.4 series to
+      # handle both shared and static libraries in a single compilation.
+      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
+      #
+      # With libtool 1.5 this exception was removed, and libtool now
+      # generates 2 separate objects for the 2 libraries.  These two
+      # compilations output dependencies in $dir.libs/$base.o.d and
+      # in $dir$base.o.d.  We have to check for both files, because
+      # one of the two compilations can be disabled.  We should prefer
+      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
+      # automatically cleaned when .libs/ is deleted, while ignoring
+      # the former would cause a distcleancheck panic.
+      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
+      tmpdepfile2=$dir$base.o.d          # libtool 1.5
+      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
+      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
+      "$@" -Wc,-MD
+   else
+      tmpdepfile1=$dir$base.o.d
+      tmpdepfile2=$dir$base.d
+      tmpdepfile3=$dir$base.d
+      tmpdepfile4=$dir$base.d
+      "$@" -MD
+   fi
+
+   stat=$?
+   if test $stat -eq 0; then :
+   else
+      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
+      exit $stat
+   fi
+
+   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
+   do
+     test -f "$tmpdepfile" && break
+   done
+   if test -f "$tmpdepfile"; then
+      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
+      # That's a tab and a space in the [].
+      sed -e 's,^.*\.[a-z]*:[   ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
+   else
+      echo "#dummy" > "$depfile"
+   fi
+   rm -f "$tmpdepfile"
+   ;;
+
+#nosideeffect)
+  # This comment above is used by automake to tell side-effect
+  # dependency tracking mechanisms from slower ones.
+
+dashmstdout)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout, regardless of -o.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  # Remove `-o $object'.
+  IFS=" "
+  for arg
+  do
+    case $arg in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    *)
+      set fnord "$@" "$arg"
+      shift # fnord
+      shift # $arg
+      ;;
+    esac
+  done
+
+  test -z "$dashmflag" && dashmflag=-M
+  # Require at least two characters before searching for `:'
+  # in the target name.  This is to cope with DOS-style filenames:
+  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
+  "$@" $dashmflag |
+    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
+  rm -f "$depfile"
+  cat < "$tmpdepfile" > "$depfile"
+  tr ' ' '
+' < "$tmpdepfile" | \
+## Some versions of the HPUX 10.20 sed can't process this invocation
+## correctly.  Breaking it into two sed invocations is a workaround.
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+dashXmstdout)
+  # This case only exists to satisfy depend.m4.  It is never actually
+  # run, as this mode is specially recognized in the preamble.
+  exit 1
+  ;;
+
+makedepend)
+  "$@" || exit $?
+  # Remove any Libtool call
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+  # X makedepend
+  shift
+  cleared=no eat=no
+  for arg
+  do
+    case $cleared in
+    no)
+      set ""; shift
+      cleared=yes ;;
+    esac
+    if test $eat = yes; then
+      eat=no
+      continue
+    fi
+    case "$arg" in
+    -D*|-I*)
+      set fnord "$@" "$arg"; shift ;;
+    # Strip any option that makedepend may not understand.  Remove
+    # the object too, otherwise makedepend will parse it as a source file.
+    -arch)
+      eat=yes ;;
+    -*|$object)
+      ;;
+    *)
+      set fnord "$@" "$arg"; shift ;;
+    esac
+  done
+  obj_suffix=`echo "$object" | sed 's/^.*\././'`
+  touch "$tmpdepfile"
+  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
+  rm -f "$depfile"
+  cat < "$tmpdepfile" > "$depfile"
+  sed '1,2d' "$tmpdepfile" | tr ' ' '
+' | \
+## Some versions of the HPUX 10.20 sed can't process this invocation
+## correctly.  Breaking it into two sed invocations is a workaround.
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile" "$tmpdepfile".bak
+  ;;
+
+cpp)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  # Remove `-o $object'.
+  IFS=" "
+  for arg
+  do
+    case $arg in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    *)
+      set fnord "$@" "$arg"
+      shift # fnord
+      shift # $arg
+      ;;
+    esac
+  done
+
+  "$@" -E |
+    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
+    sed '$ s: \\$::' > "$tmpdepfile"
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  cat < "$tmpdepfile" >> "$depfile"
+  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+msvisualcpp)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  IFS=" "
+  for arg
+  do
+    case "$arg" in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
+       set fnord "$@"
+       shift
+       shift
+       ;;
+    *)
+       set fnord "$@" "$arg"
+       shift
+       shift
+       ;;
+    esac
+  done
+  "$@" -E 2>/dev/null |
+  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::     \1 \\:p' >> "$depfile"
+  echo "       " >> "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+msvcmsys)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+none)
+  exec "$@"
+  ;;
+
+*)
+  echo "Unknown depmode $depmode" 1>&2
+  exit 1
+  ;;
+esac
+
+exit 0
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/example/.gdb.util b/example/.gdb.util
new file mode 100644 (file)
index 0000000..efc3b4b
--- /dev/null
@@ -0,0 +1,62 @@
+define xchartab
+set mdebug_dump_chartab ($, 0)
+echo \n
+end
+
+define xsymbol
+set mdebug_dump_symbol ($, 0)
+echo \n
+end
+
+define xmtext
+set mdebug_dump_mtext ($, 1, 0)
+echo \n
+end
+
+define xplist
+set mdebug_dump_plist ($, 0)
+echo \n
+end
+
+define xinterval
+set dump_interval ($arg0, 0)
+echo \n
+end
+
+define xfont
+set mdebug_dump_font ($)
+echo \n
+end
+
+define xfontset
+set mdebug_dump_fontset ($, 0)
+echo \n
+end
+
+define xface
+set mdebug_dump_face ($, 0)
+echo \n
+end
+
+define xgstring
+set dump_gstring (gstring, 0, 0)
+echo \n
+end
+
+define xgstr
+set dump_gstring ($arg0, 0, 1)
+echo \n
+end
+
+define xim
+set mdebug_dump_im ($, 0)
+echo \n
+end
+
+define xflush
+call XFlush (display)
+end
+
+define xsynch
+call XSynchronize (display, 1)
+end
diff --git a/example/.gdbinit b/example/.gdbinit
new file mode 100644 (file)
index 0000000..db736ae
--- /dev/null
@@ -0,0 +1,23 @@
+set main
+
+# br mdebug_hook
+
+source .gdb.util
+
+set env LD_LIBRARY_PATH=../src/.libs:./.libs:/usr/local/lib
+
+set env EF_ALLOW_MALLOC_0=1
+set env EF_PROTECT_FREE=1
+set env EF_OVERRUN_DETECTION=1
+set env EF_FREE_WIPES=1
+
+set env MDEBUG_INIT=1
+set env MDEBUG_FINI=1
+set env MDEBUG_CHARSET=1
+set env MDEBUG_CODING=1
+set env MDEBUG_DATABASE=1
+set env MDEBUG_FONT=1
+set env MDEBUG_FONT_FLT=0
+set env MDEBUG_FONT_OTF=1
+
+set env PURIFYOPTIONS=-chain-length="20"
diff --git a/example/ChangeLog b/example/ChangeLog
new file mode 100644 (file)
index 0000000..7d828ce
--- /dev/null
@@ -0,0 +1,777 @@
+2010-04-23  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.6.1 released.
+
+2010-04-23  Kenichi Handa  <handa@m17n.org>
+
+       * HELLO.utf8: Add Unicode 5.1 based Myanmar.
+
+2010-03-30  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.6.0 released.
+
+2010-02-18  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am: Build modules dynamically loaded with
+       -avoid-version and no -version-info.
+
+2010-02-09  Kenichi Handa  <handa@m17n.org>
+
+       * HELLO.utf8 (Greek, Hindi): Fixed.
+
+2009-08-13  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.5.5 released.
+
+2009-03-02  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.5.4 released.
+
+2009-01-15  Kenichi Handa  <handa@m17n.org>
+
+       * mconv.c (suppress_warning, continue_on_error): Make them global
+       variables.
+       (check_invalid_bytes, check_unencoded_chars): Check
+       suppress_warning and continue_on_error.
+       (unknown_encoding): New function.
+       (FATAL_ERROR): Check suppress_warning.
+       (main): Use unknown_encoding.  Call check_invalid_bytes and
+       check_unencoded_chars unconditionally.
+
+2008-12-26  Kenichi Handa  <handa@m17n.org>
+
+       * mconv.c (main): Print a proper error message if the specified
+       encoding requires m17n-db.
+
+2008-10-30  Andreas Schwab <schwab@suse.de>  (tiny change)
+
+       * medit.c (FilterProc): Fix strict aliasing bug.
+
+2008-10-30  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (update_scroll_bar): Use XawScrollbarSetThumb.
+
+2008-10-20  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.5.3 released.
+
+2008-06-23  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.5.2 released.
+
+       * mview.c: (main): Copyright years updated.
+
+       * mdump.c (main): Copyright years updated.
+
+       * mdate.c: (main): Copyright years updated.
+
+       * medit.c: (main): Copyright years updated.
+
+       * mconv.c (main): Copyright years updated.
+
+2008-06-13  Kenichi Handa  <handa@m17n.org>
+
+       * M17NEdit.ja: Shinalese -> Shinhala.
+
+2008-04-04  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (unicode_input_method, saved_input_method): New
+       variables.
+       (KeyProc): Make `C-=' activate the unicode input method
+       temporarily.
+       (setup_input_methods): Set unicode_input_method if any.
+
+2008-04-03  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (update_cursor): Update control.cursor_pos at first.
+
+2008-01-31  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * Version 1.5.1 released.
+
+2008-01-31  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * mview.c: Include <stdlib.h>.
+
+2007-12-28  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * Version 1.5.0 released.
+
+2007-10-29  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (common_ldflags_gui): Add
+       ${top_builddir}/src/libm17n-flt.la.
+
+       * .gdb.util (xgstring): Adjusted for the change of dump_gstring.
+       (xgtr): New command.
+
+2007-09-18  Kenichi Handa  <handa@m17n.org>
+
+       * mdump.c (main): Use "generic" fontset by default.
+
+2007-07-13  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.4.0 released.
+
+2007-05-21  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (show_cursor): Use msymbol_name (not mlangauge_name).
+
+2007-05-16  Kenichi Handa  <handa@m17n.org>
+
+       * mdate.c (VERSION): Delete it.
+       (main): Use M17NLIB_VERSION_NAME to print the version number.
+
+       * mconv.c (VERSION): Delete it.
+       (main): Use M17NLIB_VERSION_NAME to print the version number.
+
+       * mdump.c (PROGRAM_VERSION): Delete it.
+       (main): Use M17NLIB_VERSION_NAME to print the version number.
+
+       * medit.c (VERSION): Delete it.
+       (main): Use M17NLIB_VERSION_NAME to print the version number.
+
+       * mview.c (VERSION): Delete it.
+       (main): Use M17NLIB_VERSION_NAME to print the version number.
+
+2007-03-29  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (setup_input_methods): Use mplist_put_func.
+
+2006-12-06  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.4 released.
+
+       * mview.c (VERSION): Changed to 1.3.4.
+
+       * mdump.c (PROGRAM_VERSION): Changed to 1.3.4.
+
+       * mdate.c (VERSION): Changed to 1.3.4.
+
+       * medit.c (VERSION): Changed to 1.3.4.
+
+       * mconv.c (VERSION): Changed to 1.3.4.
+
+2006-10-27  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (surrounding_text_handler): Be sure to set surround text
+       even if LEN is zero.
+
+2006-10-16  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (create_menu_button): Set XtNinternational to True.
+
+2006-08-02  Theppitak Karoonboonyanan  <thep@linux.thai.net>  (tiny change)
+
+       * Makefile.am (common_ldflags, common_ldflags_gui): Use
+       ${top_builddir}.
+
+2006-07-19  TAKAHASHI Naoto  <ntakahas@m17n.org>
+
+       * HELLO.utf8, HELLO.html, HELLO.xml: Add final sukun to Arabic.
+
+2006-06-23  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (BUILD_LIBS): Don't increment it conditionally.
+
+       * medit.c (show_cursor): Call mlanguage_name to get English name
+       of language.
+       (compare_input_method): Likewise.
+       (main): Likewise.
+
+2006-02-22  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.3 released.
+
+2006-02-22  Kenichi Handa  <handa@m17n.org>
+
+       * mview.c: Fix some typo in documention.
+
+       * medit.c: Fix some typo in documention.
+
+       * mdump.c: Fix some typo in documention.
+
+2006-02-06  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.2 released.
+
+2006-02-03  Kenichi Handa  <handa@m17n.org>
+
+       * mdump.c: Describe the supported color names.
+
+2006-01-19  Kenichi Handa  <handa@m17n.org>
+
+       * HELLO.utf8: Fix greek.
+
+       * HELLO.xml: Fix greek.
+
+2006-01-17  Kenichi Handa  <handa@m17n.org>
+
+       * mdump.c (main): Use gdImageCreateTrueColor and
+       gdImageAlphaBlending only if HAVE_GD is 2 or the greater.
+
+2006-01-16  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.1 released.
+
+2006-01-16  Kenichi Handa  <handa@m17n.org>
+
+       * mdump.c (help_exit): Describe -fg, -bg, -r args.
+       (main): Handle -fg, -bg args.  Use gdImageCreateTrueColor instead
+       of gdImageCreate.
+
+2006-01-05  Kenichi Handa  <handa@m17n.org>
+
+       * HELLO.utf8: Fix Hindi and Oriya.
+
+       * HELLO.xml: Adjusted for the latest HELLO.utf8.
+
+       * HELLO.html: Adjusted for the latest HELLO.utf8.
+
+       * mdate.c (main): Call m17n-view; not mview.
+
+2005-12-22  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.0 released.
+
+2005-12-06  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (mt_modified): New variable.
+       (KeyProc): Update screen if input method modified a text.
+       (surrounding_text_handler): Set mt_modified to 1 if a text is
+       deleted.
+       (main): Fix handling of --font arg.
+
+2005-12-02  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (main): Handle --font arg.
+
+2005-11-21  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (bin_PROGRAMS, lib_LTLIBRARIES): Define them
+       conditionally on WITH_GUI.
+
+2005-11-11  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (surrounding_text_handler): Directly delete characters
+       instead of calling delete_char.
+
+2005-11-08  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (delete_char): Fix the case of deleting the previous
+       multiple characters.
+       (surrounding_text_handler): Check number of characters to delete.
+
+2005-11-07  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (surrounding_text_handler): New function.
+       (setup_input_methods): Add callback functions for surrounding text
+       handling.
+
+2005-10-20  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (setup_input_methods): Ignore an input method of name
+       nil.
+
+2005-10-14  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (main): Don't leave a fontset unfreed.
+
+2005-10-03  Kenichi Handa  <handa@m17n.org>
+
+       * mdump.c (main): Make the image tranparent.
+
+2005-09-27  Kenichi Handa  <handa@m17n.org>
+
+       * mdump.c (dump_image): If FILTER is "-", print the image to
+       stdout.
+
+2005-09-22  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (select_input_method): Open an input method if
+       necessary.  Handle left bitmap of input method menus here.
+       (show_cursor): Don't open an input method here.
+       (ExposeProc): Likewise.
+       (FocusInProc): Fix typo (Minput_focus_out -> Minput_focus_in).
+       (InputMethodProc): Don't handle left bitmap of input method menus
+       here.
+       (setup_input_methods): Don't open an input method here.
+
+2005-09-16  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (ButtonProc): Don't reset ic, instead send
+       Minput_focus_move event to the current input method.
+       (FocusInProc, FocusOutProc): New functions.
+       (actions): Add elements for FocusIn and FocusOut.
+       (main): Add  elements for FocusIn and FocusOut to trans2.
+
+2005-09-12  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (redraw): Don't redraw an area where not text is
+       displayed.
+
+2005-09-05  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c: Check HAVE_X11_XAW_COMMAND_H before including X11/*.h.
+
+       * mview.c: Check HAVE_X11_XAW_COMMAND_H before including X11/*.h.
+
+       * Makefile.am (X_LD_FLAGS): Use @X11_LD_FLAGS@ instead of
+       directory listing libraries.
+       (PURIFY, purify_medit, purify_mdate): Define them in maintainer
+       mode.
+
+2005-08-22  Kenichi Handa  <handa@m17n.org>
+
+       * mdump.c: Don't include config.h.
+
+       * medit.c: Likewise.
+
+       * mview.c: Likewise.
+
+       * mimx-anthy.c: Likewise.
+
+       * mimx-ispell.c: Likewise.
+
+       * Makefile.am (AM_CPPFLAGS): Set it to @CONFIG_FLAGS@.
+
+2005-08-18  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (main): Adjusted for the change of symbol's language
+       property (now in lowercase).
+
+       * mdump.c (main): Handle --fontset arg.
+
+2005-05-19  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (main): Explicitly set minput_driver.
+
+2005-04-28  Kenichi Handa  <handa@m17n.org>
+
+       * .cvsignore: Change mXXXX to m17n-XXXX.
+
+       * Makefile.am (X_LD_FLAGS): Include @XAW_LD_FLAGS@, not -lXaw.
+
+       * medit.c: Check HAVE_X11_XAW_COMMAND_H, and if it not defined,
+       add dummy code.
+
+       * mview.c: Check HAVE_X11_XAW_COMMAND_H, and if it not defined,
+       add dummy code.
+
+2005-04-15  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c: Include dlfcn.h.
+       (Mword): New variable.
+       (show_cursor): Check Mlanguage text property of the cursor
+       position only.
+       (delete_char): Pay attention to the change of line beginning
+       position because of filling.
+       (insert_chars): Likewise.
+       (word_constituent_p, forward_word, backward_word): New functions.
+       (KeyProc): Assign XK_b and XK_f for back/foreward word.
+       (line_break): Delete extern.
+       (LineBreakProc): Use mdraw_default_line_break.
+       (FilterProc): New function.
+       (main): Handle --filter arg.  Initialize Mword.  
+
+       * mdump.c (main): Set control.line_break to
+       mdraw_default_line_break.
+
+       * Makefile.am (m17n_edit_SOURCES): Don't include linebreak.c.
+       (m17n_dump_SOURCES): Likewise.
+       (m17n_edit_LDADD): Don't include @WORDCUT_LD_FLAGS@.
+       (m17n_dump_LDADD): Likewise.
+
+2005-03-09  Kenichi Handa  <handa@m17n.org>
+
+       * HELLO.utf8, HELLO.xml, HELLO.html: Fix Telugu line.
+
+2005-02-17  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (setup_input_methods): Fix for the case that no input
+       method is available.
+
+2005-01-12  Kenichi Handa  <handa@m17n.org>
+
+       * HELLO.utf8, HELLO.xml, HELLO.html: Adjust the encoding of
+       Myanmar kinzi to the new proposal by Myanmar NLP.
+
+2004-12-27  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.2.0 released.
+
+2004-12-27  Kenichi Handa  <handa@m17n.org>
+
+       * M17NEdit.ja: Renamed from MEdit.ja.
+
+       * Makefile.am: Put prefix "m17n-" instead of single "m" to
+       executables.
+       (EXTRA_DIST): Include HELLO.html and M17NEdit.ja.
+
+       * mconv.c, mdate.c, mdump.c, medit.c, mview.c: Documentations
+       changed ("mXXXX" -> "m17n-XXXX").
+
+2004-12-21  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (ButtonProc): Reset the current input method (if
+       activated) and insert the produced text.
+       (KeyProc): Cancel the previous change.
+
+2004-12-21  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (KeyProc): Handle C-\ as resetting input context.
+
+2004-12-17  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (main): Allocagte filename by strdup if not specified.
+
+2004-12-10  Kenichi Handa  <handa@m17n.org>
+
+       * mview.c (VERSION): Update to 1.2.0.
+
+       * medit.c (VERSION): Update to 1.2.0.
+       (main): If filename is not specified, open /dev/null.
+
+       * mdate.c (VERSION): Update to 1.2.0.
+
+       * mconv.c (VERSION): Update to 1.2.0.
+
+2004-12-09  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (SaveProc, DumpImageProc, FileDialogProc, read_file):
+       Decode by Mcoding_utf_8_full, not Mcoding_utf_8.
+
+2004-12-09  handa  <handa@m17n.org>
+
+       * Makefile.am (common_ldflags): Include libm17n-core.la.
+       (common_ldflags_gui): Include ${common_ldflags}
+       
+2004-12-03  Kenichi Handa  <handa@m17n.org>
+
+       * mimx-anthy.c (AnthyContext): New member ic.
+       (new_context): When something goes wrong, return NULL without
+       creating a context.
+       (get_context): New function.
+       (init): Pay attention to the case of multiple calls.
+       (fini): Likewise.
+       (convert, change, resize, commit): Use get_context.
+
+       * mimx-ispell.c (face_available): New variable.
+       (init): Check if GUI APIs are available or not.  If not, set
+       face_available to 0.
+       (fini): Free a face only if face_available is not zero.
+       (ispell_word): Put face property only if available.
+
+2004-10-29  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (main): Fix handling of "-s" arg.
+
+2004-10-12  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (KeyProc): Cast buf to `unsigned char *'.
+       (FaceProc): Call hide_cursor () at first.
+
+2004-09-27  Kenichi Handa  <handa@m17n.org>
+
+       * HELLO.html: Add Sinhala.
+
+2004-09-23  Kenichi Handa  <handa@m17n.org>
+
+       * HELLO.utf8, HELLO.xml: Add Sinhala.
+
+2004-09-14  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (update_selection): Fix for the case that the selection
+       is just one line.
+
+2004-08-27  Kenichi Handa  <handa@m17n.org>
+
+       * mdump.c (help_exit): Describe about the arg "-r".
+       (reverse_bit_order, init_reverse_bit_order): Delete them.
+       (main): Handle the arg "-r".
+
+2004-08-25  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c: Adjusted for the member name change
+       (MDrawGlyphInfo->this -> MDrawGlyphInfo->metics).
+
+       * mdump.c: Adjusted for the member name change
+       (MDrawGlyphInfo->this -> MDrawGlyphInfo->metics).
+
+2004-08-16  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.1.0 released.
+
+2004-08-15  Kenichi Handa  <handa@m17n.org>
+
+       * MEdit.ja: Add Dhivehi.
+
+       * HELLO.utf8, HELLO.xml: Add Oriya and Dhivehi.
+
+       * medit.c (covert_selection): Handle explicit request of
+       UTF8_STRING.
+       (ExposeProc): If an initial input method is specifed, activate it.
+       (setup_input_methods): New arg initial_input_method.  If it's not
+       NULL, set current_input_method to the corresponding index.
+       (help_exit): Fix help message.
+       (main): Handle --im and -s command args.
+
+       * mdump.c (help_exit): Fix help message.
+
+2004-08-09  Kenichi Handa  <handa@m17n.org>
+
+       * mconv.c (VERSION): Updated to 1.1.
+
+       * mdate.c (VERSION): Likewise.
+
+       * medit.c (VERSION): Likewise.
+
+       * mview.c (VERSION): Likewise.
+
+2004-07-28  Kenichi Handa  <handa@m17n.org>
+
+       * HELLO.utf8: Add language names for Telugu and Gujarati.
+
+       * HELLO.xml: Add language names for Telugu and Gujarati.
+
+2004-07-26  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (redraw_cursor): Fix checking of redrawing area.
+       (set_input_method_spot): Don't check face if the buffer is empty.
+       (show_cursor): Likewise.
+       (delete_char): Fix adjustment of nchars.
+       (CursorProc): Call update_cursor.
+
+2004-07-23  Kenichi Handa  <handa@m17n.org>
+
+       * HELLO.xml: Add Myanmar.
+
+       * HELLO.utf8: Add Myanmar.
+
+2004-07-22  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (get_selection): If decoding fails and *type is not
+       XA_UTF8_STRING, try to get selection value of type XA_UTF8_STRING.
+
+2004-07-20  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (main): If frame creation is falied, exit by error.
+       Call M17N_FINI after destroying the application context.
+
+2004-07-18  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (common_ldflags): Don't include
+       ${top_srcdir}/src/libm17n-core.la.
+
+2004-07-07  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (Mcoding_compound_text): New variable.
+       (covert_selection): Fix previous change.
+       (main): Set Mcoding_compound_text.
+
+2004-07-06  Kenichi Handa  <handa@m17n.org>
+
+       * mdump.c: Cancel previous change.
+
+       * Makefile.am (X_LD_FLAGS): Fix the order of linking.
+       (medit_LDADD, mview_LDADD, mdump_LDADD): Cancel previous change.
+
+       * HELLO.xml: Add Punjabi, Kannada, Telugu, and Gujarati.
+
+       * medit.c (covert_selection): If X_HAVE_UTF8_STRING is defined and
+       target is XA_UTF8_STRING, encode by utf-8.
+       (get_selection): If X_HAVE_UTF8_STRING is defined and *type is
+       XA_UTF8_STRING, decode by utf-8.
+
+2004-07-05  Kenichi Handa  <handa@m17n.org>
+
+       * HELLO.utf8: Add Kannada.
+
+2004-06-30  Kenichi Handa  <handa@m17n.org>
+
+       * mdump.c: Include <m17n-gd.h> instead of <m17n-gui.h>.
+
+       * Makefile.am (X_LD_FLAGS): New variable.
+       (medit_LDADD, mview_LDADD, mdump_LDADD): Add all depending
+       libraries.
+       (medit_LDFLAGS, mview_LDFLAGS, mdump_LDFLAGS): Delete them.
+       (libmimx_anthy_la_LIBADD): Add @ANTHY_LD_FLAGS@.
+       (libmimx_anthy_la_LDFLAGS): Delete @ANTHY_LD_FLAGS@.
+
+2004-06-25  TAKAHASHI Naoto  <ntakahas@m17n.org>
+
+       * HELLO.utf8: Add Punjabi.
+
+2004-06-24  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am: (libmimx_ispell_la_LDFLAGS)
+       (libmimx_anthy_la_LDFLAGS): Add -module.
+
+2004-06-23  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (medit_LDFLAGS, mview_LDFLAGS): Cancel the previous
+       change.
+
+       * medit.c (redraw_cursor): Refer to cursor.logical_width instead
+       of cursor.this.width.
+
+2004-06-21  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (medit_LDFLAGS, mview_LDFLAGS): Include -lX11 and
+       -lXt.
+
+2004-06-17  Kenichi Handa  <handa@m17n.org>
+
+       * mdump.c (main): Don't set control.as_image to 1.
+
+2004-06-16  Kenichi Handa  <handa@m17n.org>
+
+       * mdump.c (main): Fix typo of error message.
+
+       * medit.c (face_freeserif): New variable.
+       (face_table): Add an entry for freeserif.
+       (main): Initialized and free face_freeserif.
+
+2004-06-15  Kenichi Handa  <handa@m17n.org>
+
+       * mdump.c: Add command line arguments --family and --language.
+       (help_exit): Print info about those arguemnts.
+       (main): Make family name to lowercase.
+
+2004-06-04  Kenichi Handa  <handa@m17n.org>
+
+       * mconv.c (compare_coding_name): New function.
+       (list_coding): Sort the list of codings by their names.
+
+2004-06-03  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (InputMethodInfo): New type.
+       (input_method_table): Type changed to `InputMethodInfo *'.
+       (select_input_method): Adjusted for the change of
+       input_method_table.
+       (show_cursor): Open an input method here if necessary.
+       (compare_input_method): Adjusted for the change of
+       input_method_table.
+       (setup_input_methods): Likewise.  Don't open input methods here
+       except for XIM.
+       (main): Adjusted for the change of input_method_table.
+
+       * mconv.c (main): Close `in' and `out'.
+
+       * HELLO.utf8: Fix Greek line.
+
+       * HELLO.xml: Fix Greek line.
+
+2004-05-28  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (VINFO): New variable.
+       (libmimx_ispell_la_LDFLAGS, libmimx_anthy_la_LDFLAGS): Include
+       ${VINFO}.
+
+       * mdump.c (PROGRAM_VERSION): Renamed from VERSION.
+       (main): Use PROGRAM_VERSION.
+
+       * medit.c (main): Make face_input_status copy of face_default.
+
+2004-05-27  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (show_cursor): Check hline->width and box->width.
+       (main): Set reverse videomode in a face for selection.
+
+       * mdump.c: Include config.h.  Include <gd.h> instead of
+       <X11/Xlib.h>.  If not HAVE_FREETYPE nor HAVE_GD, define a pseudo
+       function main that just print an error message.
+       (help_exit): Adjusted for the change of spec.
+       (dump_image): Argument changed.  Dump PNG image instead of PBM.
+       (main): Adjusted for the change of spec.
+
+       * Makefile.am (common_ldflags_gui): Renamed from
+       common_ldflags_X.  Set to .../libm17n-gui.la.  Referrer changed.
+       (mdump_LDFLAGS): Include @GD_LD_FLAGS@
+
+       * HELLO.xml:  Add Bengali.
+
+2004-05-21  Kenichi Handa  <handa@m17n.org>
+
+       * HELLO.utf8: Add Bengali.
+
+2004-05-20  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (redraw): If contro.anti_alias is nonzero, always clear.
+       (ButtonMoveProc): Don't give control.anti_alias to redraw.
+       (default_face_list): New variable.
+       (FaceProc): If no selection, change the default face.
+       (main): Initialize and finalize default_face_list.
+
+2004-04-27  Kenichi Handa  <handa@m17n.org>
+
+       * mimx-ispell.c: Add coding tag euc-jp.
+
+       * mimx-anthy.c: Add coding tag euc-jp.
+
+       * medit.c: Add coding tag euc-jp.
+       (ButtonMoveProc): Full redraw if we are using anti-aliased text.
+       (main): Set control.anti_alias to 1. 
+
+       * mdump.c: Add coding tag euc-jp.
+
+       * mdate.c: Add coding tag euc-jp.
+
+       * mconv.c: Add coding tag euc-jp.
+
+2004-04-20  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (medit_LDFLAGS): Include X_PRE_LIBS, XLIBS,
+       X_EXTRA_LIBS.
+       (mview_LDFLAGS): Likewise.
+
+       * linebreak.c: Don't include wordcut/xmalloc.h, wordcut/path.h.
+
+2004-03-29  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.0 Patch Level 2 released.
+
+2004-03-19  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.0 Patch Level 1 released.
+
+2004-03-19  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (VERSION): Changed to 1.0.1.
+       (update_selection): Fix for the case that the selected region is
+       expanded to the opposite direction.
+       (ButtonMoveProc): Likewise.
+       (main): Use alloca instead of malloc for allocating menu names.
+       Free several memory areas and GCs.
+
+2004-03-12  Kenichi Handa  <handa@m17n.org>
+
+       * medit.c (input_status_control): New variable.
+       (input_status): Use input_status_control.
+       (main): Initialize input_status_control.
+
+2004-03-01  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.0 released.
+
+\f
+Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+  National Institute of Advanced Industrial Science and Technology (AIST)
+  Registration Number H15PRO112
+
+This file is part of the m17n library.
+
+The m17n 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.1 of
+the License, or (at your option) any later version.
+
+The m17n 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 the m17n library; if not, write to the Free
+Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
diff --git a/example/HELLO-ja.utf8 b/example/HELLO-ja.utf8
new file mode 100644 (file)
index 0000000..102fcbc
--- /dev/null
@@ -0,0 +1,30 @@
+ヨーロッパ
+  英語 (English)                             Hello
+  フランス語 (français)          Bonjour, Salut
+  ドイツ語 (Deutsch)                       Guten Tag, Grüß Gott
+  スロバキア語 (slovensky)       Dobrý deň
+  ロシア語 (русский)                        Здравствуйте!
+  ギリシャ語 (ελληνικά)           Γειάσας
+
+中近東・アフリカ
+  トルコ語 (Türkçe)                      Merhaba
+  グルジア語 (ქართული)              გამარჯობათ!
+  アラビア語 (اَلْعَرَبِيَّةُ)‎                  اَلسَّلَامُ عَلَيْكُم
+  ペルシャ語 (فارسی)‎                      سلام عليکم
+  ヘブライ語 (עִבְרִית)‎                        שָׁלוֹם
+  アムハラ語 (አማርኛ)               ሠላም
+
+南・東南アジア
+  ヒンディー語 (हिंदी)         नमस्ते, नमस्कार ।
+  マラヤラム語(മലയാളം)               നമസ്കാരം
+  タミール語 (தமிழ்)            வணக்கம்
+  チベット語  (བོད་སྐད་)          བཀྲ་ཤིས་བདེ་ལེགས༎ (ex: བསྒྲུབས, ཧཱུཾ)
+  クメール語 (ខ្មៃរ)                    ជំរាបសួរ (ex: ក្ក្រឿ៌)
+  ベトナム語  (Tiếng Việt)            Chào bạn
+  タイ語 (ภาษาไทย)                    สวัสดีครับ, สวัสดีค่ะ
+  ラオ語 (ພາສາລາວ)                    ສະບາຍດີ, ຂໍໃຫ້ໂຊກດີ
+
+東アジア
+  日本語                                    こんにちは
+  中国語 (汉语,普通话)         你好
+  韓国語 (한글)                           안녕하세요
diff --git a/example/HELLO-ja.xml b/example/HELLO-ja.xml
new file mode 100644 (file)
index 0000000..9a1eeaf
--- /dev/null
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mtext [
+<!ELEMENT mtext (property* , body+)>
+<!ELEMENT property EMPTY>
+<!ELEMENT body (#PCDATA)>
+<!ATTLIST property key CDATA #REQUIRED>
+<!ATTLIST property value CDATA #REQUIRED>
+<!ATTLIST property from CDATA #REQUIRED>
+<!ATTLIST property to CDATA #REQUIRED>
+<!ATTLIST property control CDATA #REQUIRED>
+]>
+<mtext>
+<property key="language" value="en" from="11" to="29" control="0"/>
+<property key="language" value="fr" from="37" to="64" control="0"/>
+<property key="language" value="de" from="72" to="104" control="0"/>
+<property key="language" value="sk" from="114" to="135" control="0"/>
+<property key="language" value="ru" from="143" to="168" control="0"/>
+<property key="language" value="el" from="177" to="196" control="0"/>
+<property key="language" value="tr" from="214" to="232" control="0"/>
+<property key="language" value="ka" from="241" to="263" control="0"/>
+<property key="language" value="ar" from="272" to="314" control="0"/>
+<property key="language" value="fa" from="323" to="344" control="0"/>
+<property key="language" value="he" from="353" to="374" control="0"/>
+<property key="language" value="am" from="383" to="394" control="0"/>
+<property key="language" value="hi" from="413" to="439" control="0"/>
+<property key="language" value="ml" from="448" to="466" control="0"/>
+<property key="language" value="ta" from="475" to="491" control="0"/>
+<property key="language" value="bo" from="501" to="550" control="0"/>
+<property key="language" value="km" from="559" to="591" control="0"/>
+<property key="language" value="vi" from="601" to="623" control="0"/>
+<property key="language" value="th" from="630" to="663" control="0"/>
+<property key="language" value="lo" from="670" to="701" control="0"/>
+<property key="language" value="ja" from="708" to="724" control="0"/>
+<property key="language" value="zh" from="730" to="742" control="0"/>
+<property key="language" value="ko" from="749" to="762" control="0"/>
+<body>ヨーロッパ
+  英語 (English)                             Hello
+  フランス語 (français)          Bonjour, Salut
+  ドイツ語 (Deutsch)                       Guten Tag, Grüß Gott
+  スロバキア語 (slovensky)       Dobrý deň
+  ロシア語 (русский)                        Здравствуйте!
+  ギリシャ語 (ελληνικά)           Γειάσας
+
+中近東・アフリカ
+  トルコ語 (Türkçe)                      Merhaba
+  グルジア語 (ქართული)              გამარჯობათ!
+  アラビア語 (اَلْعَرَبِيَّةُ)‎                  اَلسَّلَامُ عَلَيْكُم
+  ペルシャ語 (فارسی)‎                      سلام عليکم
+  ヘブライ語 (עִבְרִית)‎                        שָׁלוֹם
+  アムハラ語 (አማርኛ)               ሠላም
+
+南・東南アジア
+  ヒンディー語 (हिंदी)         नमस्ते, नमस्कार ।
+  マラヤラム語(മലയാളം)               നമസ്കാരം
+  タミール語 (தமிழ்)            வணக்கம்
+  チベット語  (བོད་སྐད་)          བཀྲ་ཤིས་བདེ་ལེགས༎ (ex: བསྒྲུབས, ཧཱུཾ)
+  クメール語 (ខ្មៃរ)                    ជំរាបសួរ (ex: ក្ក្រឿ៌)
+  ベトナム語  (Tiếng Việt)            Chào bạn
+  タイ語 (ภาษาไทย)                    สวัสดีครับ, สวัสดีค่ะ
+  ラオ語 (ພາສາລາວ)                    ສະບາຍດີ, ຂໍໃຫ້ໂຊກດີ
+
+東アジア
+  日本語                                    こんにちは
+  中国語 (汉语,普通话)         你好
+  韓国語 (한글)                           안녕하세요
+</body></mtext>
diff --git a/example/HELLO.html b/example/HELLO.html
new file mode 100644 (file)
index 0000000..d5921f3
--- /dev/null
@@ -0,0 +1,190 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+   "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+
+<head>
+  <meta http-equiv="content-type" content="text/html; charset=utf-8">
+  <title>Hello World!</title>
+</head>
+
+<body>
+<table border="3" cellpadding="4">
+
+<tr><th colspan="2">Europe</th></tr>
+<tr>
+  <td>English</td>
+  <td></td>
+  <td lang="en">hello</td>
+</tr>
+<tr>
+  <td>French</td>
+  <td lang="fr">français</td>
+  <td lang="fr">Bonjour, Salut</td>
+</tr>
+<tr>
+  <td>German</td>
+  <td lang="de">Deutsch</td>
+  <td lang="de">Guten Tag, Grüß Gott</td>
+</tr>
+<tr>
+  <td>Slovak</td>
+  <td lang="sk">slovensky</td>
+  <td lang="sk">Dobrý deň</td>
+</tr>
+<tr>
+  <td>Russian</td>
+  <td lang="ru">русский</td>
+  <td lang="ru">Здравствуйте!</td>
+</tr>
+<tr>
+  <td>Greek</td>
+  <td lang="el">ελληνικά</td>
+  <td lang="el">Γειά σας</td>
+</tr>
+<tr>
+  <td>Armenian</td>
+  <td lang="hy">հայերեն</td>
+  <td lang="hy">Բարեւ։</td>
+</tr>
+<tr>
+  <td>Georgian</td>
+  <td lang="ka">ქართული</td>
+  <td lang="ka">გამარჯობათ!</td>
+</tr>
+
+<tr><th colspan="2">Middle Near East/Africa</th></tr>
+<tr>
+  <td>Turkish</td>
+  <td lang="tr">Türkçe</td>
+  <td lang="tr">Merhaba</td>
+</tr>
+<tr>
+  <td>Hebrew</td>
+  <td lang="he">עִבְרִית</td>
+  <td lang="he">שָׁלוֹם</td>
+</tr>
+<tr>
+  <td>Arabic</td>
+  <td lang="ar">اَلْعَرَبِيَّةُ</td>
+  <td lang="ar">اَلسَّلَامُ عَلَيْكُمْ</td>
+</tr>
+<tr>
+  <td>Persian</td>
+  <td lang="fa">فارسی</td>
+  <td lang="fa">سلام عليکم</td>
+</tr>
+<tr>
+  <td>Dhivehi</td>
+  <td lang="dv">ދިވެހިބަސް</td>
+  <td lang="dv">އައްސަލާމު އަލައިކުމް</td>
+</tr>
+<tr>
+  <td>Amharic</td>
+  <td lang="am">አማርኛ</td>
+  <td lang="am">ሠላም</td>
+</tr>
+
+<tr><th colspan="2">South Asia</th></tr>
+<tr>
+  <td>Hindi</td>
+  <td lang="hi">हिन्दी</td>
+  <td lang="hi">नमस्ते, नमस्कार ।</td>
+</tr>
+<tr>
+  <td>Bengali</td>
+  <td lang="bn">বাংলা</td>
+  <td lang="bn">নমস্কার</td>
+</tr>
+<tr>
+  <td>Punjabi</td>
+  <td lang="pa">ਪੰਜਾਬੀ</td>
+  <td lang="pa">ਸਤਿ ਸ਼੍ਰੀ ਅਕਾਲ</td>
+</tr>
+<tr>
+  <td>Gujarati</td>
+  <td lang="gu">ગુજરાતી</td>
+  <td lang="gu">નમસ્તે</td>
+</tr>
+<tr>
+  <td>Oriya</td>
+  <td lang="or">ଓଡ଼ିଆ</td>
+  <td lang="or">ଶୁଣିବେ</td>
+</tr>
+<tr>
+  <td>Tamil</td>
+  <td lang="ta">தமிழ்</td>
+  <td lang="ta">வணக்கம்</td>
+</tr>
+<tr>
+  <td>Telugu</td>
+  <td lang="te">తెలుగు</td>
+  <td lang="te">నమస్కారం</td>
+</tr>
+<tr>
+  <td>Kannada</td>
+  <td lang="kn">ಕನ್ನಡ</td>
+  <td lang="kn">ನಮಸ್ಕಾರ</td>
+</tr>
+<tr>
+  <td>Malayalam</td>
+  <td lang="ml">മലയാളം</td>
+  <td lang="ml">നമസ്കാരം</td>
+</tr>
+<tr>
+  <td>Sinhala</td>
+  <td>සිංහල</td>
+  <td>ආයුබෝවන්</td>
+</tr>
+<tr>
+  <td>Tibetan</td>
+  <td lang="bo">བོད་སྐད་</td>
+  <td lang="bo">བཀྲ་ཤིས་བདེ་ལེགས༎</td>
+</tr>
+
+<tr><th colspan="2">South-East Asia</th></tr>
+<tr>
+  <td>Thai</td>
+  <td lang="th">ภาษาไทย</td>
+  <td lang="th">สวัสดีครับ, สวัสดีค่ะ</td>
+</tr>
+<tr>
+  <td>Lao</td>
+  <td lang="lo">ພາສາລາວ</td>
+  <td lang="lo">ສະບາຍດີ, ຂໍໃຫ້ໂຊກດີ</td>
+</tr>
+<tr>
+  <td>Myanmar</td>
+  <td lang="my">မ္ရန္‌မာ</td>
+  <td lang="my">မင္‍ဂလာပာ</td>
+</tr>
+<tr>
+  <td>Khmer</td>
+  <td lang="km">ខ្មៃរ</td>
+  <td lang="km">ជំរាបសួរ</td>
+</tr>
+<tr>
+  <td>Vietnamese</td>
+  <td lang="vi">Tiếng Việt</td>
+  <td lang="vi">Chào bạn</td>
+</tr>
+
+<tr><th colspan="2">East Asia</th></tr>
+<tr>
+  <td>Japanese</td>
+  <td lang="ja">日本語</td>
+  <td lang="ja">こんにちは</td>
+</tr>
+<tr>
+  <td>Chinese</td>
+  <td lang="zh">汉语,普通话</td>
+  <td lang="zh">你好</td>
+</tr>
+<tr>
+  <td>Korean</td>
+  <td lang="ko">한글</td>
+  <td lang="ko">안녕하세요</td>
+</tr>
+
+</table>
+</body>
+</html>
diff --git a/example/HELLO.utf8 b/example/HELLO.utf8
new file mode 100644 (file)
index 0000000..9934932
--- /dev/null
@@ -0,0 +1,41 @@
+Europe
+  English                                      Hello
+  French (français)                   Bonjour, Salut
+  German (Deutsch)                     Guten Tag, Grüß Gott
+  Slovak (slovensky)           Dobrý deň
+  Russian (русский)                     Здравствуйте!
+  Greek (ελληνικά)                     Γειά σας
+  Armenian (հայերեն)            Բարեւ։
+  Georgian (ქართული)             გამარჯობათ!
+
+Middle Near East/Africa
+  Turkish (Türkçe)                   Merhaba
+  Hebrew (עִבְרִית)‎                 שָׁלוֹם
+  Arabic (اَلْعَرَبِيَّةُ)‎                   اَلسَّلَامُ عَلَيْكُمْ
+  Persian (فارسی)‎                      سلام عليکم
+  Dhivehi (ދިވެހިބަސް)‎                    އައްސަލާމު އަލައިކުމް
+  Amharic (አማርኛ)                       ሠላም
+
+South/South-East Asia
+  Hindi (हिंदी)                              नमस्ते, नमस्कार ।
+  Bengali (বাংলা)                    নমস্কার
+  Punjabi (ਪੰਜਾਬੀ)                 ਸਤਿ ਸ਼੍ਰੀ ਅਕਾਲ
+  Gujarati (ગુજરાતી)                     નમસ્તે
+  Oriya (ଓଡ଼ିଆ)                         ଶୁଣିବେ
+  Tamil (தமிழ்)                              வணக்கம்
+  Telugu (తెలుగు)                  నమస్కారం
+  Kannada (ಕನ್ನಡ)                    ನಮಸ್ಕಾರ
+  Malayalam (മലയാളം)               നമസ്കാരം (ex: ന+്+ര=ന്ര)
+  Sinhala (සිංහල)                    ආයුබෝවන්
+  Tibetan (བོད་སྐད་)                   བཀྲ་ཤིས་བདེ་ལེགས༎ (ex: བསྒྲུབས, ཧཱུཾ)
+  Thai (ภาษาไทย)                 สวัสดีครับ, สวัสดีค่ะ
+  Lao (ພາສາລາວ)                  ສະບາຍດີ, ຂໍໃຫ້ໂຊກດີ
+  Myanmar (မ္ရန္‌မာ)                   မင္‍ဂလာပာ (before Unicode 5.1)
+  Myanmar (မြန်မာ)                 မင်္ဂလာပါ (after Unicode 5.1)
+  Khmer (ភាសាខ្មែរ)                  ជំរាបសួរ (ex: ក៊្ក្រឿ)
+  Vietnamese (Tiếng Việt)  Chào bạn
+
+East Asia
+  Chinese (汉语,普通话)           你好
+  Japanese (日本語)                 こんにちは
+  Korean (한글)                      안녕하세요
diff --git a/example/HELLO.xml b/example/HELLO.xml
new file mode 100644 (file)
index 0000000..3a9d852
--- /dev/null
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mtext [
+<!ELEMENT mtext (property* , body+)>
+<!ELEMENT property EMPTY>
+<!ELEMENT body (#PCDATA)>
+<!ATTLIST property key CDATA #REQUIRED>
+<!ATTLIST property value CDATA #REQUIRED>
+<!ATTLIST property from CDATA #REQUIRED>
+<!ATTLIST property to CDATA #REQUIRED>
+<!ATTLIST property control CDATA #REQUIRED>
+]>
+<mtext>
+<property key="language" value="el" from="174" to="183" control="0"/>
+<property key="language" value="ru" from="138" to="174" control="0"/>
+<property key="language" value="sk" from="106" to="138" control="0"/>
+<property key="language" value="de" from="64" to="106" control="0"/>
+<property key="language" value="fr" from="27" to="64" control="0"/>
+<property key="language" value="en" from="7" to="27" control="0"/>
+<property key="language" value="ka" from="233" to="267" control="0"/>
+<property key="language" value="hy" from="204" to="233" control="0"/>
+<property key="language" value="el" from="184" to="204" control="0"/>
+<property key="language" value="am" from="484" to="507" control="0"/>
+<property key="language" value="dv" from="436" to="484" control="0"/>
+<property key="language" value="fa" from="404" to="436" control="0"/>
+<property key="language" value="ar" from="352" to="404" control="0"/>
+<property key="language" value="he" from="321" to="352" control="0"/>
+<property key="language" value="tr" from="292" to="321" control="0"/>
+<property key="language" value="hi" from="530" to="567" control="0"/>
+<property key="language" value="gu" from="631" to="643" control="0"/>
+<property key="language" value="pa" from="596" to="631" control="0"/>
+<property key="language" value="bn" from="568" to="596" control="0"/>
+<property key="language" value="or" from="661" to="685" control="0"/>
+<property key="language" value="gu" from="650" to="661" control="0"/>
+<property key="language" value="km" from="1019" to="1061" control="0"/>
+<property key="language" value="my" from="986" to="1019" control="0"/>
+<property key="language" value="lo" from="948" to="986" control="0"/>
+<property key="language" value="th" from="907" to="948" control="0"/>
+<property key="language" value="bo" from="846" to="907" control="0"/>
+<property key="language" value="si" from="817" to="846" control="0"/>
+<property key="language" value="ml" from="770" to="817" control="0"/>
+<property key="language" value="kn" from="742" to="770" control="0"/>
+<property key="language" value="te" from="713" to="742" control="0"/>
+<property key="language" value="ta" from="686" to="713" control="0"/>
+<property key="language" value="vi" from="1074" to="1096" control="0"/>
+<property key="language" value="ko" from="1155" to="1177" control="0"/>
+<property key="language" value="ja" from="1130" to="1155" control="0"/>
+<property key="language" value="zh" from="1107" to="1130" control="0"/>
+<body>Europe
+  English                                      Hello
+  French (français)                   Bonjour, Salut
+  German (Deutsch)                     Guten Tag, Grüß Gott
+  Slovak (slovensky)           Dobrý deň
+  Russian (русский)                     Здравствуйте!
+  Greek (ἑλληνικά)                    Γειά σας
+  Armenian (հայերեն)            Բարեւ։
+  Georgian (ქართული)             გამარჯობათ!
+
+Middle Near East/Africa
+  Turkish (Türkçe)                   Merhaba
+  Hebrew (עִבְרִית)‎                 שָׁלוֹם
+  Arabic (اَلْعَرَبِيَّةُ)‎                   اَلسَّلَامُ عَلَيْكُمْ
+  Persian (فارسی)‎                      سلام عليکم
+  Dhivehi (ދިވެހިބަސް)‎                    އައްސަލާމު އަލައިކުމް
+  Amharic (አማርኛ)                       ሠላም
+
+South/South-East Asia
+  Hindi (हिन्दी)                           नमस्ते, नमस्कार ।
+  Bengali (বাংলা)                    নমস্কার
+  Punjabi (ਪੰਜਾਬੀ)                 ਸਤਿ ਸ਼੍ਰੀ ਅਕਾਲ
+  Gujarati (ગુજરાતી)                     નમસ્તે
+  Oriya (ଓଡ଼ିଆ)                         ଶୁଣିବେ
+  Tamil (தமிழ்)                              வணக்கம்
+  Telugu (తెలుగు)                  నమస్కారం
+  Kannada (ಕನ್ನಡ)                    ನಮಸ್ಕಾರ
+  Malayalam (മലയാളം)               നമസ്കാരം (ex: ന+്+ര=ന്ര)
+  Sinhala (සිංහල)                    ආයුබෝවන්
+  Tibetan (བོད་སྐད་)                   བཀྲ་ཤིས་བདེ་ལེགས༎ (ex: བསྒྲུབས, ཧཱུཾ)
+  Thai (ภาษาไทย)                 สวัสดีครับ, สวัสดีค่ะ
+  Lao (ພາສາລາວ)                  ສະບາຍດີ, ຂໍໃຫ້ໂຊກດີ
+  Myanmar (မ္ရန္‌မာ)                   မင္‍ဂလာပာ
+  Khmer (ខ្មៃរ)                              ជំរាបសួរ (ex: ក្ក្រឿ៌)
+  Vietnamese (Tiếng Việt)  Chào bạn
+
+East Asia
+  Chinese (汉语,普通话)           你好
+  Japanese (日本語)                 こんにちは
+  Korean (한글)                      안녕하세요
+</body></mtext>
diff --git a/example/M17NEdit.ja b/example/M17NEdit.ja
new file mode 100644 (file)
index 0000000..fbc08b9
--- /dev/null
@@ -0,0 +1,154 @@
+! -*- coding: euc-jp; -*-
+*.fontSet: -etl-fixed-medium-r-normal--24-*-*-*-*,-*-*-medium-r-normal--24-*-*-*-*
+*.international: True
+*.File.label: ¥Õ¥¡¥¤¥ë
+*.Cursor.label: ¥«¡¼¥½¥ë
+*.Bidi.label: ½ñ»úÊý¸þ
+*.LineBreak.label: ¹Ôʬ³ä
+*.InputMethod.label: ÆþÎϥ᥽¥Ã¥É
+*.Face.label: ¥Õ¥§¡¼¥¹
+*.Lang.label: ¸À¸ì
+*.Size.label: ¥µ¥¤¥º
+*.Family.label: ¥Õ¥¡¥ß¥ê¡¼
+*.Style.label: ¥¹¥¿¥¤¥ë
+*.Color.label: ¿§
+*.Misc.label: ¤½¤Î¾
+*.Pop Face.label: ¥Ý¥Ã¥×
+*Abkhazian.label:¥¢¥Ö¥Ï¥º¸ì
+*Afar.label:¥¢¥Õ¥¡¥ë¸ì
+*Afrikaans.label:¥¢¥Õ¥ê¥«¡¼¥ó¥¹¸ì
+*Albanian.label:¥¢¥ë¥Ð¥Ë¥¢¸ì
+*Amharic.label:¥¢¥à¥Ï¥é¸ì
+*Arabic.label:¥¢¥é¥Ó¥¢¸ì
+*Armenian.label:¥¢¥ë¥á¥Ë¥¢¸ì
+*Assamese.label:¥¢¥Ã¥µ¥à¸ì
+*Aymara.label:¥¢¥¤¥Þ¥é¸ì
+*Azerbaijani.label:¥¢¥¼¥ë¥Ð¥¤¥¸¥ã¥ó¸ì
+*Bashkir.label:¥Ð¥·¥å¥­¡¼¥ë¸ì
+*Basque.label:¥Ð¥¹¥¯¸ì
+*Bengali.label:¥Ù¥ó¥¬¥ë¸ì
+*Bhutani.label:¥Ö¡¼¥¿¥ó¸ì
+*Bihari.label:¥Ó¥Ï¡¼¥ë¸ì
+*Bislama.label:¥Ó¥¹¥é¥Þ¸ì
+*Breton.label:¥Ö¥ë¥È¥ó¸ì
+*Bulgarian.label:¥Ö¥ë¥¬¥ê¥¢¸ì
+*Burmese.label:¥Ó¥ë¥Þ¸ì
+*Byelorussian.label:Çò¥í¥·¥¢¸ì
+*Cambodian.label:¥«¥ó¥Ü¥¸¥¢¸ì
+*Catalan.label:¥«¥¿¥í¥Ë¥¢¸ì
+*Chinese.label:Ãæ¹ñ¸ì
+*Corsican.label:¥³¥ë¥·¥«¸ì
+*Croatian.label:¥¯¥í¥¢¥Á¥¢¸ì
+*Czech.label:¥Á¥§¥³¸ì
+*Dhivehi.label:¥Ç¥£¥Ù¥Ò¸ì
+*Danish.label:¥Ç¥ó¥Þ¡¼¥¯¸ì
+*Dutch.label:¥ª¥é¥ó¥À¸ì
+*English.label:±Ñ¸ì
+*Esperanto.label:¥¨¥¹¥Ú¥é¥ó¥È
+*Estonian.label:¥¨¥¹¥È¥Ë¥¢¸ì
+*Faeroese.label:¥Õ¥§¡¼¥í¡¼¸ì
+*Farsi.label:¥Ú¥ë¥·¥¢¸ì
+*Fiji.label:¥Õ¥£¥¸¡¼¸ì
+*Finnish.label:¥Õ¥£¥ó¥é¥ó¥É¸ì
+*French.label:¥Õ¥é¥ó¥¹¸ì
+*Frisian.label:¥Õ¥ê¥¸¥¢¸ì
+*Galician.label:¥¬¥ê¥·¥¢¸ì
+*Gaelic(Scottish).label:¥²¡¼¥ë¸ì¡Ê¥¹¥³¥Ã¥È¥é¥ó¥É¡Ë
+*Gaelic(Manx).label:¥²¡¼¥ë¸ì¡Ê¥Þ¥óÅç¡Ë
+*Georgian.label:¥°¥ë¥¸¥¢¸ì
+*German.label:¥É¥¤¥Ä¸ì
+*Greek.label:¥®¥ê¥·¥¢¸ì
+*Greenlandic.label:¥°¥ê¡¼¥ó¥é¥ó¥É¸ì
+*Guarani.label:¥ï¥é¥Ë¡¼¸ì
+*Gujarati.label:¥°¥¸¥ã¥é¡¼¥È¸ì
+*Hausa.label:¥Ï¥¦¥µ¸ì
+*Hebrew.label:¥Ø¥Ö¥é¥¤¸ì
+*Hindi.label:¥Ò¥ó¥Ç¥£¡¼¸ì
+*Hungarian.label:¥Ï¥ó¥¬¥ê¡¼¸ì
+*Icelandic.label:¥¢¥¤¥¹¥é¥ó¥É¸ì
+*Indonesian.label:¥¤¥ó¥É¥Í¥·¥¢¸ì
+*Inuktitut.label:¥¤¥Ì¥¯¥Æ¥£¥È¥Ã¥È¸ì
+*Inupiak.label:¥¤¥Ì¥Ô¥¢¥Ã¥¯¸ì
+*Irish.label:¥¢¥¤¥ë¥é¥ó¥É¸ì
+*Italian.label:¥¤¥¿¥ê¥¢¸ì
+*Japanese.label:ÆüËܸì
+*Javanese.label:¥¸¥ã¥ï¸ì
+*Kannada.label:¥«¥ó¥Ê¥À¸ì
+*Kashmiri.label:¥«¥·¥å¥ß¡¼¥ë¸ì
+*Kazakh.label:¥«¥¶¥Õ¸ì
+*Kinyarwanda.label:¥ë¥ï¥ó¥À¸ì
+*Kirghiz.label:¥­¥ë¥®¥¹¸ì
+*Kirundi.label:¥ë¥ó¥Ç¥£¸ì
+*Korean.label:Ä«Á¯¸ì
+*Kurdish.label:¥¯¥ë¥É¸ì
+*Laothian.label:¥é¥ª¸ì
+*Latin.label:¥é¥Æ¥ó¸ì
+*Latvian.label:¥é¥È¥ô¥£¥¢¸ì
+*Lingala.label:¥ê¥ó¥¬¥é¸ì
+*Lithuanian.label:¥ê¥È¥¢¥Ë¥¢¸ì
+*Macedonian.label:¥Þ¥±¥É¥Ë¥¢¸ì
+*Malagasy.label:¥Þ¥é¥¬¥·¸ì
+*Malay.label:¥à¥é¥æ¸ì
+*Malayalam.label:¥Þ¥é¥ä¡¼¥é¥à¸ì
+*Maltese.label:¥Þ¥ë¥¿¸ì
+*Maori.label:¥Þ¥ª¥ê¸ì
+*Marathi.label:¥Þ¥é¡¼¥Æ¥£¡¼¸ì
+*Moldavian.label:¥â¥ë¥À¥Ó¥¢¸ì
+*Mongolian.label:¥â¥ó¥´¥ë¸ì
+*Nauru.label:¥Ê¥¦¥ë¸ì
+*Nepali.label:¥Í¥Ñ¡¼¥ë¸ì
+*Norwegian.label:¥Î¥ë¥¦¥§¡¼¸ì
+*Occitan.label:¥×¥í¥ô¥¡¥ó¥¹¸ì
+*Oriya.label:¥ª¥ê¥ä¡¼¸ì
+*Oromo.label:¥¬¥Ã¥é¸ì
+*Pashto.label:¥Ñ¥·¥å¥È¡¼¸ì
+*Polish.label:¥Ý¡¼¥é¥ó¥É¸ì
+*Portuguese.label:¥Ý¥ë¥È¥¬¥ë¸ì
+*Punjabi.label:¥Ñ¥ó¥¸¥ã¡¼¥Ö¸ì
+*Quechua.label:¥±¥Á¥å¥¢¸ì
+*Rhaeto-Romance.label:¥ì¥È¡¦¥í¥Þ¥ó¥¹¸ì
+*Romanian.label:¥ë¡¼¥Þ¥Ë¥¢¸ì
+*Russian.label:¥í¥·¥¢¸ì
+*Samoan.label:¥µ¥â¥¢¸ì
+*Sangro.label:¥µ¥ó¥´¸ì
+*Sanskrit.label:¥µ¥ó¥¹¥¯¥ê¥Ã¥È
+*Serbian.label:¥»¥ë¥Ó¥¢¸ì
+*Serbo-Croatian.label:¥»¥ë¥Ó¥¢¡¦¥¯¥í¥¢¥Á¥¢¸ì
+*Sesotho.label:¥½¥È¸ì
+*Setswana.label:¥Ä¥ï¥Ê¸ì
+*Shona.label:¥·¥ç¥Ê¸ì
+*Sindhi.label:¥·¥ó¥É¸ì
+*Sinhala.label:¥·¥ó¥Ï¥é¸ì
+*Siswati.label:¥¹¥ï¥Æ¥£¸ì
+*Slovak.label:¥¹¥í¥Ð¥­¥¢¸ì
+*Slovenian.label:¥¹¥í¥Ù¥Ë¥¢¸ì
+*Somali.label:¥½¥Þ¥ê¸ì
+*Spanish.label:¥¹¥Ú¥¤¥ó¸ì
+*Sundanese.label:¥¹¥ó¥À¸ì
+*Swahili.label:¥¹¥ï¥Ò¥ê¸ì
+*Swedish.label:¥¹¥¦¥§¡¼¥Ç¥ó¸ì
+*Tagalog.label:¥¿¥¬¥í¥°¸ì
+*Tajik.label:¥¿¥¸¥¯¸ì
+*Tamil.label:¥¿¥ß¡¼¥ë¸ì
+*Tatar.label:¥¿¥¿¡¼¥ë¸ì
+*Telugu.label:¥Æ¥ë¥°¸ì
+*Thai.label:¥¿¥¤¸ì
+*Tibetan.label:¥Á¥Ù¥Ã¥È¸ì
+*Tigrinya.label:¥Æ¥£¥°¥ê¥Ë¥¢¸ì
+*Tonga.label:¥È¥ó¥¬¸ì
+*Tsonga.label:¥Ä¥©¥ó¥¬¸ì
+*Turkish.label:¥È¥ë¥³¸ì
+*Turkmen.label:¥È¥ë¥¯¥á¥ó¸ì
+*Twi.label:¥Á¥å¥¤¸ì
+*Uighur.label:¥¦¥¤¥°¥ë¸ì
+*Ukrainian.label:¥¦¥¯¥é¥¤¥Ê¸ì
+*Urdu.label:¥¦¥ë¥É¥¥¡¼¸ì
+*Uzbek.label:¥¦¥º¥Ù¥¯¸ì
+*Vietnamese.label:¥Ù¥È¥Ê¥à¸ì
+*Volapuk.label:¥ô¥©¥é¥Ô¥å¥¯
+*Welsh.label:¥¦¥§¡¼¥ë¥º¸ì
+*Wolof.label:¥¦¥©¥í¥Õ¸ì
+*Xhosa.label:¥³¥µ¸ì
+*Yiddish.label:¥¤¥Ç¥£¥Ã¥·¥å¸ì
+*Yoruba.label:¥è¥ë¥Ð¸ì
+*Zulu.label:¥º¡¼¥ë¡¼¸ì
diff --git a/example/Makefile.am b/example/Makefile.am
new file mode 100644 (file)
index 0000000..1fd9b4d
--- /dev/null
@@ -0,0 +1,95 @@
+# Makefile.am -- example level Makefile for the m17n library.
+# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010
+#   National Institute of Advanced Industrial Science and Technology (AIST)
+#   Registration Number H15PRO112
+
+# This file is part of the m17n library.
+
+# The m17n 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.1 of
+# the License, or (at your option) any later version.
+
+# The m17n 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 the m17n library; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+## Process this file with Automake to create Makefile.in
+
+## Note: Source files have preifx "m" but executables have prefix
+## "m17n-" to avoid confliction of program names.
+
+BASICPROGS = m17n-conv
+if WITH_GUI
+bin_PROGRAMS = $(BASICPROGS) m17n-view m17n-date m17n-dump m17n-edit
+else
+bin_PROGRAMS = $(BASICPROGS)
+endif
+
+common_ldflags = ${top_builddir}/src/libm17n-core.la ${top_builddir}/src/libm17n.la
+common_ldflags_gui = ${common_ldflags} ${top_builddir}/src/libm17n-flt.la ${top_builddir}/src/libm17n-gui.la
+AM_CPPFLAGS=@CONFIG_FLAGS@
+
+m17n_date_SOURCES = mdate.c
+m17n_date_LDADD = ${common_ldflags}
+
+m17n_conv_SOURCES = mconv.c
+m17n_conv_LDADD = ${common_ldflags}
+
+X_LD_FLAGS = ${X_PRE_LIBS} ${X_LIBS} @XAW_LD_FLAGS@ @X11_LD_FLAGS@ ${X_EXTRA_LIBS}
+
+m17n_edit_SOURCES = medit.c
+m17n_edit_LDADD = ${X_LD_FLAGS} ${common_ldflags_gui} -ldl
+
+m17n_view_SOURCES = mview.c
+m17n_view_LDADD = ${X_LD_FLAGS} ${common_ldflags_gui}
+
+m17n_dump_SOURCES = mdump.c
+m17n_dump_LDADD = @GD_LD_FLAGS@ ${common_ldflags_gui}
+
+# Input method data files.
+
+pkgdatadir=$(datadir)/m17n
+
+EXTRA_DIST = \
+       .gdbinit .gdb.util \
+       HELLO.utf8 HELLO.xml HELLO-ja.utf8 HELLO-ja.xml HELLO.html M17NEdit.ja
+
+# External modules used by the above input methods.
+
+moduledir = ${libdir}/@M17N_MODULE_DIR@
+
+BASICBUILDS = libmimx-anthy.la
+if WITH_GUI
+BUILD_LIBS = $(BASICBUILDS) libmimx-ispell.la 
+else
+BUILD_LIBS = $(BASICBUILDS)
+endif
+module_LTLIBRARIES = $(BUILD_LIBS)
+
+libmimx_ispell_la_SOURCES = mimx-ispell.c
+libmimx_ispell_la_LIBADD = ${common_ldflags_gui}
+libmimx_ispell_la_LDFLAGS = -avoid-version -module
+libmimx_anthy_la_SOURCES = mimx-anthy.c
+libmimx_anthy_la_LIBADD = ${common_ldflags} @ANTHY_LD_FLAGS@ 
+libmimx_anthy_la_LDFLAGS = -avoid-version -module
+
+if MAINTAINER_MODE
+
+# Special targets to test the m17n library with Purify.
+
+PURIFY=/usr/local/rational/releases/purify.sol.2002.05.00/purify
+
+purify_medit: medit ../src/.libs/libm17n-core.so ../src/.libs/libm17n.so ../src/.libs/libm17n-X.so linebreak.c
+       ${PURIFY} gcc -g medit.o linebreak.o -lXaw -lXmu -L/usr/X11R6/lib -R/usr/X11R6/lib -lSM -lICE -lX11 -lXt -L../src/.libs -lm17n-core -lm17n -lm17n-X -ldl
+
+purify_mdate: mdate.o ../src/.libs/libm17n.so ../src/.libs/libm17n-X.so
+       ${PURIFY} gcc -g mdate.o -lXaw -lXmu -L/usr/X11R6/lib -R/usr/X11R6/lib -lSM -lICE -lX11 -lXt -L../src/.libs -lm17n -lm17n-X -ldl
+
+endif
diff --git a/example/Makefile.in b/example/Makefile.in
new file mode 100644 (file)
index 0000000..f5af380
--- /dev/null
@@ -0,0 +1,773 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  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@
+
+# Makefile.am -- example level Makefile for the m17n library.
+# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010
+#   National Institute of Advanced Industrial Science and Technology (AIST)
+#   Registration Number H15PRO112
+
+# This file is part of the m17n library.
+
+# The m17n 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.1 of
+# the License, or (at your option) any later version.
+
+# The m17n 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 the m17n library; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+
+VPATH = @srcdir@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+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@
+@WITH_GUI_FALSE@bin_PROGRAMS = $(am__EXEEXT_1)
+@WITH_GUI_TRUE@bin_PROGRAMS = $(am__EXEEXT_1) m17n-view$(EXEEXT) \
+@WITH_GUI_TRUE@        m17n-date$(EXEEXT) m17n-dump$(EXEEXT) \
+@WITH_GUI_TRUE@        m17n-edit$(EXEEXT)
+subdir = example
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ChangeLog
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/codeset.m4 \
+       $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/glibc2.m4 \
+       $(top_srcdir)/m4/glibc21.m4 $(top_srcdir)/m4/iconv.m4 \
+       $(top_srcdir)/m4/intdiv0.m4 $(top_srcdir)/m4/intmax.m4 \
+       $(top_srcdir)/m4/inttypes-pri.m4 $(top_srcdir)/m4/inttypes.m4 \
+       $(top_srcdir)/m4/inttypes_h.m4 $(top_srcdir)/m4/isc-posix.m4 \
+       $(top_srcdir)/m4/lcmessage.m4 $(top_srcdir)/m4/lib-ld.m4 \
+       $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
+       $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/longdouble.m4 \
+       $(top_srcdir)/m4/longlong.m4 $(top_srcdir)/m4/ltoptions.m4 \
+       $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+       $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \
+       $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/printf-posix.m4 \
+       $(top_srcdir)/m4/progtest.m4 $(top_srcdir)/m4/signed.m4 \
+       $(top_srcdir)/m4/size_max.m4 $(top_srcdir)/m4/stdint_h.m4 \
+       $(top_srcdir)/m4/uintmax_t.m4 $(top_srcdir)/m4/ulonglong.m4 \
+       $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/m4/wint_t.m4 \
+       $(top_srcdir)/m4/xsize.m4 $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+       $(ACLOCAL_M4)
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/src/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_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 = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(moduledir)" "$(DESTDIR)$(bindir)"
+LTLIBRARIES = $(module_LTLIBRARIES)
+libmimx_anthy_la_DEPENDENCIES = $(common_ldflags)
+am_libmimx_anthy_la_OBJECTS = mimx-anthy.lo
+libmimx_anthy_la_OBJECTS = $(am_libmimx_anthy_la_OBJECTS)
+libmimx_anthy_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(libmimx_anthy_la_LDFLAGS) $(LDFLAGS) -o $@
+@WITH_GUI_FALSE@am_libmimx_anthy_la_rpath = -rpath $(moduledir)
+@WITH_GUI_TRUE@am_libmimx_anthy_la_rpath = -rpath $(moduledir)
+am__DEPENDENCIES_1 = $(common_ldflags) \
+       ${top_builddir}/src/libm17n-flt.la \
+       ${top_builddir}/src/libm17n-gui.la
+libmimx_ispell_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_libmimx_ispell_la_OBJECTS = mimx-ispell.lo
+libmimx_ispell_la_OBJECTS = $(am_libmimx_ispell_la_OBJECTS)
+libmimx_ispell_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(libmimx_ispell_la_LDFLAGS) $(LDFLAGS) -o $@
+@WITH_GUI_TRUE@am_libmimx_ispell_la_rpath = -rpath $(moduledir)
+am__EXEEXT_1 = m17n-conv$(EXEEXT)
+PROGRAMS = $(bin_PROGRAMS)
+am_m17n_conv_OBJECTS = mconv.$(OBJEXT)
+m17n_conv_OBJECTS = $(am_m17n_conv_OBJECTS)
+m17n_conv_DEPENDENCIES = $(common_ldflags)
+am_m17n_date_OBJECTS = mdate.$(OBJEXT)
+m17n_date_OBJECTS = $(am_m17n_date_OBJECTS)
+m17n_date_DEPENDENCIES = $(common_ldflags)
+am_m17n_dump_OBJECTS = mdump.$(OBJEXT)
+m17n_dump_OBJECTS = $(am_m17n_dump_OBJECTS)
+m17n_dump_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_m17n_edit_OBJECTS = medit.$(OBJEXT)
+m17n_edit_OBJECTS = $(am_m17n_edit_OBJECTS)
+am__DEPENDENCIES_2 =
+am__DEPENDENCIES_3 = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_2) \
+       $(am__DEPENDENCIES_2)
+m17n_edit_DEPENDENCIES = $(am__DEPENDENCIES_3) $(am__DEPENDENCIES_1)
+am_m17n_view_OBJECTS = mview.$(OBJEXT)
+m17n_view_OBJECTS = $(am_m17n_view_OBJECTS)
+m17n_view_DEPENDENCIES = $(am__DEPENDENCIES_3) $(am__DEPENDENCIES_1)
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+       $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+       --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+       $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+       --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+       $(LDFLAGS) -o $@
+SOURCES = $(libmimx_anthy_la_SOURCES) $(libmimx_ispell_la_SOURCES) \
+       $(m17n_conv_SOURCES) $(m17n_date_SOURCES) $(m17n_dump_SOURCES) \
+       $(m17n_edit_SOURCES) $(m17n_view_SOURCES)
+DIST_SOURCES = $(libmimx_anthy_la_SOURCES) \
+       $(libmimx_ispell_la_SOURCES) $(m17n_conv_SOURCES) \
+       $(m17n_date_SOURCES) $(m17n_dump_SOURCES) $(m17n_edit_SOURCES) \
+       $(m17n_view_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+
+# Input method data files.
+pkgdatadir = $(datadir)/m17n
+ACLOCAL = @ACLOCAL@
+ALLOCA = @ALLOCA@
+AMTAR = @AMTAR@
+ANTHY_CFLAGS = @ANTHY_CFLAGS@
+ANTHY_LD_FLAGS = @ANTHY_LD_FLAGS@
+ANTHY_LIBS = @ANTHY_LIBS@
+API_VERSION = @API_VERSION@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@
+CATOBJEXT = @CATOBJEXT@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CONFIG_FLAGS = @CONFIG_FLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DATADIRNAME = @DATADIRNAME@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+FONTCONFIG_LD_FLAGS = @FONTCONFIG_LD_FLAGS@
+FREETYPE_LD_FLAGS = @FREETYPE_LD_FLAGS@
+FRIBIDI_LD_FLAGS = @FRIBIDI_LD_FLAGS@
+GD_LD_FLAGS = @GD_LD_FLAGS@
+GENCAT = @GENCAT@
+GETTEXTDIR = @GETTEXTDIR@
+GLIBC2 = @GLIBC2@
+GLIBC21 = @GLIBC21@
+GLIB_2_0_CFLAGS = @GLIB_2_0_CFLAGS@
+GLIB_2_0_LIBS = @GLIB_2_0_LIBS@
+GMSGFMT = @GMSGFMT@
+GREP = @GREP@
+HAVE_ASPRINTF = @HAVE_ASPRINTF@
+HAVE_FREETYPE_CONFIG = @HAVE_FREETYPE_CONFIG@
+HAVE_FRIBIDI_CONFIG = @HAVE_FRIBIDI_CONFIG@
+HAVE_ISPELL = @HAVE_ISPELL@
+HAVE_M17N_DB = @HAVE_M17N_DB@
+HAVE_OTFLIB_CONFIG = @HAVE_OTFLIB_CONFIG@
+HAVE_PKG_CONFIG = @HAVE_PKG_CONFIG@
+HAVE_POSIX_PRINTF = @HAVE_POSIX_PRINTF@
+HAVE_SNPRINTF = @HAVE_SNPRINTF@
+HAVE_WPRINTF = @HAVE_WPRINTF@
+HAVE_XFT_CONFIG = @HAVE_XFT_CONFIG@
+HAVE_XML2_CONFIG = @HAVE_XML2_CONFIG@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+INSTOBJEXT = @INSTOBJEXT@
+INTLBISON = @INTLBISON@
+INTLLIBS = @INTLLIBS@
+INTLOBJS = @INTLOBJS@
+INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@
+INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBICONV = @LIBICONV@
+LIBINTL = @LIBINTL@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTHAI_CFLAGS = @LIBTHAI_CFLAGS@
+LIBTHAI_LIBS = @LIBTHAI_LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBICONV = @LTLIBICONV@
+LTLIBINTL = @LTLIBINTL@
+LTLIBOBJS = @LTLIBOBJS@
+M17NDIR = @M17NDIR@
+M17N_MODULE_DIR = @M17N_MODULE_DIR@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+MKINSTALLDIRS = @MKINSTALLDIRS@
+MSGFMT = @MSGFMT@
+MSGMERGE = @MSGMERGE@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTF_LD_FLAGS = @OTF_LD_FLAGS@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+POSUB = @POSUB@
+POW_LIB = @POW_LIB@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+THAI_WORDSEG_LD_FLAGS = @THAI_WORDSEG_LD_FLAGS@
+USE_INCLUDED_LIBINTL = @USE_INCLUDED_LIBINTL@
+USE_NLS = @USE_NLS@
+VERSION = @VERSION@
+WORDCUT_CFLAGS = @WORDCUT_CFLAGS@
+WORDCUT_LIBS = @WORDCUT_LIBS@
+X11_LD_FLAGS = @X11_LD_FLAGS@
+XAW_LD_FLAGS = @XAW_LD_FLAGS@
+XFT2_LD_FLAGS = @XFT2_LD_FLAGS@
+XGETTEXT = @XGETTEXT@
+XMKMF = @XMKMF@
+XML2_LD_FLAGS = @XML2_LD_FLAGS@
+X_CFLAGS = @X_CFLAGS@
+X_EXTRA_LIBS = @X_EXTRA_LIBS@
+X_LIBS = @X_LIBS@
+X_PRE_LIBS = @X_PRE_LIBS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+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@
+builddir = @builddir@
+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@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+BASICPROGS = m17n-conv
+common_ldflags = ${top_builddir}/src/libm17n-core.la ${top_builddir}/src/libm17n.la
+common_ldflags_gui = ${common_ldflags} ${top_builddir}/src/libm17n-flt.la ${top_builddir}/src/libm17n-gui.la
+AM_CPPFLAGS = @CONFIG_FLAGS@
+m17n_date_SOURCES = mdate.c
+m17n_date_LDADD = ${common_ldflags}
+m17n_conv_SOURCES = mconv.c
+m17n_conv_LDADD = ${common_ldflags}
+X_LD_FLAGS = ${X_PRE_LIBS} ${X_LIBS} @XAW_LD_FLAGS@ @X11_LD_FLAGS@ ${X_EXTRA_LIBS}
+m17n_edit_SOURCES = medit.c
+m17n_edit_LDADD = ${X_LD_FLAGS} ${common_ldflags_gui} -ldl
+m17n_view_SOURCES = mview.c
+m17n_view_LDADD = ${X_LD_FLAGS} ${common_ldflags_gui}
+m17n_dump_SOURCES = mdump.c
+m17n_dump_LDADD = @GD_LD_FLAGS@ ${common_ldflags_gui}
+EXTRA_DIST = \
+       .gdbinit .gdb.util \
+       HELLO.utf8 HELLO.xml HELLO-ja.utf8 HELLO-ja.xml HELLO.html M17NEdit.ja
+
+
+# External modules used by the above input methods.
+moduledir = ${libdir}/@M17N_MODULE_DIR@
+BASICBUILDS = libmimx-anthy.la
+@WITH_GUI_FALSE@BUILD_LIBS = $(BASICBUILDS)
+@WITH_GUI_TRUE@BUILD_LIBS = $(BASICBUILDS) libmimx-ispell.la 
+module_LTLIBRARIES = $(BUILD_LIBS)
+libmimx_ispell_la_SOURCES = mimx-ispell.c
+libmimx_ispell_la_LIBADD = ${common_ldflags_gui}
+libmimx_ispell_la_LDFLAGS = -avoid-version -module
+libmimx_anthy_la_SOURCES = mimx-anthy.c
+libmimx_anthy_la_LIBADD = ${common_ldflags} @ANTHY_LD_FLAGS@ 
+libmimx_anthy_la_LDFLAGS = -avoid-version -module
+
+# Special targets to test the m17n library with Purify.
+@MAINTAINER_MODE_TRUE@PURIFY = /usr/local/rational/releases/purify.sol.2002.05.00/purify
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+       @for dep in $?; do \
+         case '$(am__configure_deps)' in \
+           *$$dep*) \
+             ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+               && { if test -f $@; then exit 0; else break; fi; }; \
+             exit 1;; \
+         esac; \
+       done; \
+       echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu example/Makefile'; \
+       $(am__cd) $(top_srcdir) && \
+         $(AUTOMAKE) --gnu example/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: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-moduleLTLIBRARIES: $(module_LTLIBRARIES)
+       @$(NORMAL_INSTALL)
+       test -z "$(moduledir)" || $(MKDIR_P) "$(DESTDIR)$(moduledir)"
+       @list='$(module_LTLIBRARIES)'; test -n "$(moduledir)" || list=; \
+       list2=; for p in $$list; do \
+         if test -f $$p; then \
+           list2="$$list2 $$p"; \
+         else :; fi; \
+       done; \
+       test -z "$$list2" || { \
+         echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(moduledir)'"; \
+         $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(moduledir)"; \
+       }
+
+uninstall-moduleLTLIBRARIES:
+       @$(NORMAL_UNINSTALL)
+       @list='$(module_LTLIBRARIES)'; test -n "$(moduledir)" || list=; \
+       for p in $$list; do \
+         $(am__strip_dir) \
+         echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(moduledir)/$$f'"; \
+         $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(moduledir)/$$f"; \
+       done
+
+clean-moduleLTLIBRARIES:
+       -test -z "$(module_LTLIBRARIES)" || rm -f $(module_LTLIBRARIES)
+       @list='$(module_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
+libmimx-anthy.la: $(libmimx_anthy_la_OBJECTS) $(libmimx_anthy_la_DEPENDENCIES) 
+       $(libmimx_anthy_la_LINK) $(am_libmimx_anthy_la_rpath) $(libmimx_anthy_la_OBJECTS) $(libmimx_anthy_la_LIBADD) $(LIBS)
+libmimx-ispell.la: $(libmimx_ispell_la_OBJECTS) $(libmimx_ispell_la_DEPENDENCIES) 
+       $(libmimx_ispell_la_LINK) $(am_libmimx_ispell_la_rpath) $(libmimx_ispell_la_OBJECTS) $(libmimx_ispell_la_LIBADD) $(LIBS)
+install-binPROGRAMS: $(bin_PROGRAMS)
+       @$(NORMAL_INSTALL)
+       test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
+       @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+       for p in $$list; do echo "$$p $$p"; done | \
+       sed 's/$(EXEEXT)$$//' | \
+       while read p p1; do if test -f $$p || test -f $$p1; \
+         then echo "$$p"; echo "$$p"; else :; fi; \
+       done | \
+       sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \
+           -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+       sed 'N;N;N;s,\n, ,g' | \
+       $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+         { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+           if ($$2 == $$4) files[d] = files[d] " " $$1; \
+           else { print "f", $$3 "/" $$4, $$1; } } \
+         END { for (d in files) print "f", d, files[d] }' | \
+       while read type dir files; do \
+           if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+           test -z "$$files" || { \
+           echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \
+           $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
+           } \
+       ; done
+
+uninstall-binPROGRAMS:
+       @$(NORMAL_UNINSTALL)
+       @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+       files=`for p in $$list; do echo "$$p"; done | \
+         sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+             -e 's/$$/$(EXEEXT)/' `; \
+       test -n "$$list" || exit 0; \
+       echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
+       cd "$(DESTDIR)$(bindir)" && rm -f $$files
+
+clean-binPROGRAMS:
+       @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \
+       echo " rm -f" $$list; \
+       rm -f $$list || exit $$?; \
+       test -n "$(EXEEXT)" || exit 0; \
+       list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+       echo " rm -f" $$list; \
+       rm -f $$list
+m17n-conv$(EXEEXT): $(m17n_conv_OBJECTS) $(m17n_conv_DEPENDENCIES) 
+       @rm -f m17n-conv$(EXEEXT)
+       $(LINK) $(m17n_conv_OBJECTS) $(m17n_conv_LDADD) $(LIBS)
+m17n-date$(EXEEXT): $(m17n_date_OBJECTS) $(m17n_date_DEPENDENCIES) 
+       @rm -f m17n-date$(EXEEXT)
+       $(LINK) $(m17n_date_OBJECTS) $(m17n_date_LDADD) $(LIBS)
+m17n-dump$(EXEEXT): $(m17n_dump_OBJECTS) $(m17n_dump_DEPENDENCIES) 
+       @rm -f m17n-dump$(EXEEXT)
+       $(LINK) $(m17n_dump_OBJECTS) $(m17n_dump_LDADD) $(LIBS)
+m17n-edit$(EXEEXT): $(m17n_edit_OBJECTS) $(m17n_edit_DEPENDENCIES) 
+       @rm -f m17n-edit$(EXEEXT)
+       $(LINK) $(m17n_edit_OBJECTS) $(m17n_edit_LDADD) $(LIBS)
+m17n-view$(EXEEXT): $(m17n_view_OBJECTS) $(m17n_view_DEPENDENCIES) 
+       @rm -f m17n-view$(EXEEXT)
+       $(LINK) $(m17n_view_OBJECTS) $(m17n_view_LDADD) $(LIBS)
+
+mostlyclean-compile:
+       -rm -f *.$(OBJEXT)
+
+distclean-compile:
+       -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mconv.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mdate.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mdump.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/medit.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mimx-anthy.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mimx-ispell.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mview.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@   $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@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@   $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@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@   $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@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
+
+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; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+               $(TAGS_FILES) $(LISP)
+       set x; \
+       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; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       shift; \
+       if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+         test -n "$$unique" || unique=$$empty_fix; \
+         if test $$# -gt 0; then \
+           $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+             "$$@" $$unique; \
+         else \
+           $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+             $$unique; \
+         fi; \
+       fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+               $(TAGS_FILES) $(LISP)
+       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; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       test -z "$(CTAGS_ARGS)$$unique" \
+         || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+            $$unique
+
+GTAGS:
+       here=`$(am__cd) $(top_builddir) && pwd` \
+         && $(am__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)'; \
+         dist_files=`for file in $$list; do echo $$file; done | \
+         sed -e "s|^$$srcdirstrip/||;t" \
+             -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+       case $$dist_files in \
+         */*) $(MKDIR_P) `echo "$$dist_files" | \
+                          sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+                          sort -u` ;; \
+       esac; \
+       for file in $$dist_files; do \
+         if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+         if test -d $$d/$$file; then \
+           dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+           if test -d "$(distdir)/$$file"; then \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+             cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+         else \
+           test -f "$(distdir)/$$file" \
+           || cp -p $$d/$$file "$(distdir)/$$file" \
+           || exit 1; \
+         fi; \
+       done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES) $(PROGRAMS)
+installdirs:
+       for dir in "$(DESTDIR)$(moduledir)" "$(DESTDIR)$(bindir)"; do \
+         test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+       done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+       @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+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)
+       -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_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-am
+
+clean-am: clean-binPROGRAMS clean-generic clean-libtool \
+       clean-moduleLTLIBRARIES mostlyclean-am
+
+distclean: distclean-am
+       -rm -rf ./$(DEPDIR)
+       -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+       distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-moduleLTLIBRARIES
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-binPROGRAMS
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+       -rm -rf ./$(DEPDIR)
+       -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+       mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-binPROGRAMS uninstall-moduleLTLIBRARIES
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
+       clean-generic clean-libtool clean-moduleLTLIBRARIES ctags \
+       distclean distclean-compile distclean-generic \
+       distclean-libtool distclean-tags distdir dvi dvi-am html \
+       html-am info info-am install install-am install-binPROGRAMS \
+       install-data install-data-am install-dvi install-dvi-am \
+       install-exec install-exec-am install-html install-html-am \
+       install-info install-info-am install-man \
+       install-moduleLTLIBRARIES install-pdf install-pdf-am \
+       install-ps install-ps-am install-strip installcheck \
+       installcheck-am installdirs maintainer-clean \
+       maintainer-clean-generic mostlyclean mostlyclean-compile \
+       mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+       tags uninstall uninstall-am uninstall-binPROGRAMS \
+       uninstall-moduleLTLIBRARIES
+
+
+@MAINTAINER_MODE_TRUE@purify_medit: medit ../src/.libs/libm17n-core.so ../src/.libs/libm17n.so ../src/.libs/libm17n-X.so linebreak.c
+@MAINTAINER_MODE_TRUE@ ${PURIFY} gcc -g medit.o linebreak.o -lXaw -lXmu -L/usr/X11R6/lib -R/usr/X11R6/lib -lSM -lICE -lX11 -lXt -L../src/.libs -lm17n-core -lm17n -lm17n-X -ldl
+
+@MAINTAINER_MODE_TRUE@purify_mdate: mdate.o ../src/.libs/libm17n.so ../src/.libs/libm17n-X.so
+@MAINTAINER_MODE_TRUE@ ${PURIFY} gcc -g mdate.o -lXaw -lXmu -L/usr/X11R6/lib -R/usr/X11R6/lib -lSM -lICE -lX11 -lXt -L../src/.libs -lm17n -lm17n-X -ldl
+
+# 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/example/mconv.c b/example/mconv.c
new file mode 100644 (file)
index 0000000..09a4969
--- /dev/null
@@ -0,0 +1,450 @@
+/* mconv.c -- Code converter.                          -*- coding: euc-jp; -*-
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @enpage m17n-conv convert file code
+
+    @section m17n-conv-synopsis SYNOPSIS
+
+    m17n-conv [ OPTION ... ] [ INFILE [ OUTFILE ] ]
+
+    @section m17n-conv-description DESCRIPTION
+
+    Convert encoding of given files from one to another.
+
+    If INFILE is omitted, the input is taken from standard input.  If
+    OUTFILE is omitted, the output written to standard output.
+
+    The following OPTIONs are available.
+
+    <ul>
+
+    <li> -f FROMCODE
+
+    FROMCODE is the encoding of INFILE (defaults to UTF-8).
+
+    <li> -t TOCODE
+
+    TOCODE is the encoding of OUTFILE (defaults to UTF-8).
+
+    <li> -k
+
+    Do not stop conversion on error.
+
+    <li> -s
+
+    Suppress warnings.
+
+    <li> -v
+
+    Print progress information.
+
+    <li> -l
+
+    List available encodings.
+
+    <li> --version
+
+    Print version number.
+
+    <li> -h, --help
+
+    Print this message.
+
+    </ul>
+*/
+/***ja
+    @japage m17n-conv ¥Õ¥¡¥¤¥ë¤Î¥³¡¼¥É¤òÊÑ´¹¤¹¤ë
+
+    @section m17n-conv-synopsis SYNOPSIS
+
+    m17n-conv [ OPTION ... ] [ INFILE [ OUTFILE ] ]
+
+    @section m17n-conv-description ÀâÌÀ
+
+    Í¿¤¨¤é¤ì¤¿¥Õ¥¡¥¤¥ë¤Î¥³¡¼¥É¤òÊ̤Τâ¤Î¤ËÊÑ´¹¤¹¤ë¡£ 
+
+    INFILE ¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Ï¡¢É¸½àÆþÎϤ«¤é¤È¤ë¡£OUTFILE ¤¬¾Êά¤µ¤ì¤¿ 
+    ¾ì¹ç¤Ï¡¢É¸½à½ÐÎϤؽñ¤­½Ð¤¹¡£
+
+    °Ê²¼¤Î¥ª¥×¥·¥ç¥ó¤¬ÍøÍѤǤ­¤ë¡£
+
+    <ul>
+
+    <li> -f FROMCODE
+
+    FROMCODE ¤Ï INFILE ¤Î¥³¡¼¥É·Ï¤Ç¤¢¤ë¡£(¥Ç¥Õ¥©¥ë¥È¤Ï UTF-8) 
+
+    <li> -t TOCODE
+
+    TOCODE ¤Ï OUTFILE ¤Î¥³¡¼¥É·Ï¤Ç¤¢¤ë¡£(¥Ç¥Õ¥©¥ë¥È¤Ï UTF-8) 
+
+    <li> -k
+
+    ¥¨¥é¡¼¤ÇÊÑ´¹¤òÄä»ß¤·¤Ê¤¤¡£
+
+    <li> -s
+
+    ·Ù¹ð¤òɽ¼¨¤·¤Ê¤¤¡£ 
+
+    <li> -v
+
+    ¿Ê¹Ô¾õ¶·¤òɽ¼¨¤¹¤ë¡£ 
+
+    <li> -l
+
+    ÍøÍѲÄǽ¤Ê¥³¡¼¥É·Ï¤òÎóµó¤¹¤ë¡£ 
+
+    <li> --version
+
+    ¥Ð¡¼¥¸¥ç¥óÈÖ¹æ¤òɽ¼¨¤¹¤ë¡£ 
+
+    <li> -h, --help
+
+    ¤³¤Î¥á¥Ã¥»¡¼¥¸¤òɽ¼¨¤¹¤ë¡£ 
+
+    </ul>
+*/
+
+#ifndef FOR_DOXYGEN
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <m17n.h>
+#include <m17n-misc.h>
+
+/* Print all coding system names.  */
+
+int
+compare_coding_name (const void *elt1, const void *elt2)
+{
+  const MSymbol *n1 = elt1;
+  const MSymbol *n2 = elt2;
+
+  return strcmp (msymbol_name (*n1), msymbol_name (*n2));
+}
+
+void
+list_coding ()
+{
+  MSymbol *codings;
+  int i, n;
+  char *name;
+  int len, clm;
+
+  n = mconv_list_codings (&codings);
+  qsort (codings, n, sizeof (MSymbol), compare_coding_name);
+  clm = 0;
+  for (i = 0; i < n; i++)
+    {
+      name = msymbol_name (codings[i]);
+      len = strlen (name) + 1;
+      if (clm + len >= 80)
+       {
+         printf ("\n");
+         clm = 0;
+       }
+      printf (" %s", name);
+      clm += len;
+    }
+  printf ("\n");
+  free (codings);
+}
+
+
+/* Print the usage of this program (the name is PROG), and exit with
+   EXIT_CODE.  */
+
+void
+help_exit (char *prog, int exit_code)
+{
+  char *p = prog;
+
+  while (*p)
+    if (*p++ == '/')
+      prog = p;
+
+  printf ("Usage: %s [ OPTION ... ] [ INFILE [ OUTFILE ] ]\n", prog);
+  printf ("Convert encoding of given files from one to another.\n");
+  printf ("  If INFILE is omitted, the input is taken from standard input.\n");
+  printf ("  If OUTFILE is omitted, the output is written to standard output.\n");
+  printf ("The following OPTIONs are available.\n");
+  printf ("  %-13s %s", "-f FROMCODE",
+         "FROMCODE is the encoding of INFILE (defaults to UTF-8).\n");
+  printf ("  %-13s %s", "-t TOCODE",
+         "TOCODE is the encoding of OUTFILE (defaults to UTF-8).\n");
+  printf ("  %-13s %s", "-k", "Do not stop conversion on error.\n");
+  printf ("  %-13s %s", "-s", "Suppress warnings.\n");
+  printf ("  %-13s %s", "-v", "Print progress information.\n");
+  printf ("  %-13s %s", "-l", "List available encodings.\n");
+  printf ("  %-13s %s", "--version", "Print version number.\n");
+  printf ("  %-13s %s", "-h, --help", "Print this message.\n");
+  exit (exit_code);
+}
+
+/* Global flags to control the behaviour.  */
+int suppress_warning;
+int continue_on_error;
+
+/* Check invalid bytes found in the last decoding.  Text property
+   Mcharset of such a byte is Mcharset_binary.  */
+
+void
+check_invalid_bytes (MText *mt)
+{
+  int from = 0, to = 0;
+  int len = mtext_len (mt);
+  int first = 1;
+
+  while (to < len)
+    {
+      int n = mtext_prop_range (mt, Mcharset, from, NULL, &to, 1);
+      MSymbol charset
+       = n > 0 ? (MSymbol) mtext_get_prop (mt, from, Mcharset) : Mnil;
+
+      if (charset == Mcharset_binary)
+       {
+         if (! suppress_warning)
+           {
+             if (first)
+               {
+                 fprintf (stderr,
+                          "Invalid bytes (at each character position);\n");
+                 first = 0;
+               }
+             for (; from < to; from++)
+               fprintf (stderr, " 0x%02X(%d)",
+                        mtext_ref_char (mt, from), from);
+           }
+         if (! continue_on_error)
+           {
+             if (! first)
+               fprintf (stderr, "\n");
+             exit (1);
+           }
+       }
+      else
+       from = to;
+    }
+  if (! first)
+    fprintf (stderr, "\n");
+}
+
+
+/* Check unencoded characters in the last encoding.  Text property
+   Mcoding of such a character is Mnil.  */
+
+void
+check_unencoded_chars (MText *mt, int len)
+{
+  int from = 0, to = 0;
+  int first = 1;
+
+  while (to < len)
+    {
+      int n = mtext_prop_range (mt, Mcoding, from, NULL, &to, 1);
+      MSymbol coding
+       = n > 0 ? (MSymbol) mtext_get_prop (mt, from, Mcoding) : Mnil;
+
+      if (coding == Mnil)
+       {
+         if (! suppress_warning)
+           {
+             if (first)
+               {
+                 fprintf (stderr,
+                          "Unencoded chars (at each character position):\n");
+                 first = 0;
+               }
+             for (; from < to; from++)
+               fprintf (stderr, " 0x%02X(%d)",
+                        mtext_ref_char (mt, from), from);
+           }
+         if (! continue_on_error)
+           {
+             if (! first)
+               fprintf (stderr, "\n");
+             exit (1);
+           }
+       }
+      else
+       from = to;
+    }
+  if (! first)
+    fprintf (stderr, "\n");
+}
+
+
+void
+unknown_encoding (char *name)
+{
+  if (! suppress_warning)
+    {
+      fprintf (stderr, "Unknown encoding: \"%s\"\n", name);
+      if (mconv_resolve_coding (msymbol ("iso-2022-jp")) == Mnil)
+       fprintf (stderr, "Perhaps the library \"m17n-db\" is missing.\n");
+    }
+  exit (1);
+}
+
+/* Format MSG by FMT and print the result to the stderr, and exit.  */
+
+#define FATAL_ERROR(fmt, arg)          \
+  do {                                 \
+    if (! suppress_warning)            \
+      fprintf (stderr, fmt, arg);      \
+    exit (1);                          \
+  } while (0)
+
+
+int
+main (int argc, char **argv)
+{
+  int verbose;
+  MSymbol incode, outcode;
+  FILE *in, *out;
+  MText *mt;
+  MConverter *converter;
+  int i;
+
+  /* Initialize the m17n library.  */
+  M17N_INIT ();
+  if (merror_code != MERROR_NONE)
+    FATAL_ERROR ("%s\n", "Fail to initialize the m17n library.");
+
+  /* Default encodings are both UTF-8.  */
+  incode = outcode = Mcoding_utf_8;
+  /* By default, read from standard input and write to standard output. */
+  in = stdin, out = stdout;
+  /* By default, all these flags are 0.  */
+  suppress_warning = verbose = continue_on_error = 0;
+  /* Parse the command line arguments.  */
+  for (i = 1; i < argc; i++)
+    {
+      if (! strcmp (argv[i], "--help")
+              || ! strcmp (argv[i], "-h")
+              || ! strcmp (argv[i], "-?"))
+       help_exit (argv[0], 0);
+      else if (! strcmp (argv[i], "--version"))
+       {
+         printf ("m17n-conv (m17n library) %s\n", M17NLIB_VERSION_NAME);
+         printf ("Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 AIST, JAPAN\n");
+         exit (0);
+       }
+      else if (! strcmp (argv[i], "-l"))
+       {
+         list_coding ();
+         M17N_FINI ();
+         exit (0);
+       }
+      else if (! strcmp (argv[i], "-f"))
+       {
+         incode = mconv_resolve_coding (msymbol (argv[++i]));
+         if (incode == Mnil)
+           unknown_encoding (argv[i]);
+       }
+      else if (! strcmp (argv[i], "-t"))
+       {
+         outcode = mconv_resolve_coding (msymbol (argv[++i]));
+         if (outcode == Mnil)
+           unknown_encoding (argv[i]);
+       }
+      else if (! strcmp (argv[i], "-k"))
+       continue_on_error = 1;
+      else if (! strcmp (argv[i], "-s"))
+       suppress_warning = 1;
+      else if (! strcmp (argv[i], "-v"))
+       verbose = 1;
+      else if (argv[i][0] != '-')
+       {
+         if (in == stdin)
+           {
+             in = fopen (argv[i], "r");
+             if (! in)
+               FATAL_ERROR ("Can't read the file %s\n", argv[i]);
+           }
+         else if (out == stdout)
+           {
+             out = fopen (argv[i], "w");
+             if (! out)
+               FATAL_ERROR ("Can't write the file %s\n", argv[i]);
+           }
+         else
+           help_exit (argv[0], 1);
+       }
+      else
+       help_exit (argv[0], 1);
+    }
+  if (verbose)
+    suppress_warning = 0;
+
+  /* Create an M-text to store the decoded characters.  */
+  mt = mtext ();
+
+  /* Create a converter for decoding.  */
+  converter = mconv_stream_converter (incode, in);
+  if (! converter)
+    FATAL_ERROR ("Encoding \"%s\" requires the missing library \"m17n-db\".\n",
+                msymbol_name (incode));
+  /* Instead of doing strict decoding, we decode all input bytes at
+     once, and check invalid bytes later by the fuction
+     check_invalid_bytes.  */
+  converter->lenient = 1;
+
+  mconv_decode (converter, mt);
+
+  check_invalid_bytes (mt);
+  if (verbose)
+    fprintf (stderr, "%d bytes (%s) decoded into %d characters,\n",
+            converter->nbytes, msymbol_name (incode), mtext_len (mt));
+
+  mconv_free_converter (converter);
+
+  /* Create a converter for encoding.  */
+  converter = mconv_stream_converter (outcode, out);
+  if (! converter)
+    FATAL_ERROR ("Encoding \"%s\" requires the missing library \"m17n-db\".\n",
+                msymbol_name (outcode));
+  /* Instead of doing strict encoding, we encode all characters at
+     once, and check unencoded characters later by the fuction
+     check_unencoded_chars.  */
+  converter->lenient = 1;
+  converter->last_block = 1;
+  if (mconv_encode (converter, mt) < 0
+      && ! suppress_warning)
+    fprintf (stderr, "I/O error on writing\n");
+  check_unencoded_chars (mt, converter->nchars);
+  if (verbose)
+    fprintf (stderr, "%d characters encoded into %d bytes (%s).\n",
+            converter->nchars, converter->nbytes, msymbol_name (outcode));
+
+  /* Clear away.  */
+  mconv_free_converter (converter);
+  fclose (in);
+  fclose (out);
+  m17n_object_unref (mt);
+  M17N_FINI ();
+  exit (0);
+}
+#endif /* not FOR_DOXYGEN */
diff --git a/example/mdate.c b/example/mdate.c
new file mode 100644 (file)
index 0000000..9f8103f
--- /dev/null
@@ -0,0 +1,238 @@
+/* mdate.c -- Show system date/time in all locales.    -*- coding: euc-jp; -*-
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @enpage m17n-date display date and time
+
+    @section m17n-date-synopsis SYNOPSIS
+
+    m17n-date [ OPTION ... ]
+
+    @section m17n-date-description DESCRIPTION
+
+    Display the system date and time in many locales on a window.
+
+    The following OPTIONs are available.
+
+    <ul>
+
+    <li> --version
+
+    Print version number.
+
+    <li> -h, --help
+
+    Print this message.
+    </ul>
+*/
+/***ja
+    @japage m17n-date Æü»þ¤òɽ¼¨¤¹¤ë
+
+    @section m17n-date-synopsis ¥·¥Î¥×¥·¥¹
+
+    m17n-date [ OPTION ... ]
+
+    @section m17n-date-description ÀâÌÀ
+
+    ¥·¥¹¥Æ¥à¤ÎÆü»þ¤ò¤µ¤Þ¤¶¤Þ¤Ê¥í¥±¡¼¥ë¤Ç¥¦¥£¥ó¥É¥¦¤Ëɽ¼¨¤¹¤ë¡£ 
+
+    °Ê²¼¤Î¥ª¥×¥·¥ç¥ó¤¬ÍøÍѤǤ­¤ë¡£ 
+
+    <ul>
+
+    <li> --version
+
+    ¥Ð¡¼¥¸¥ç¥óÈÖ¹æ¤òɽ¼¨¤¹¤ë¡£ 
+
+    <li> -h, --help
+
+    ¤³¤Î¥á¥Ã¥»¡¼¥¸¤òɽ¼¨¤¹¤ë¡£
+
+    </ul>
+*/
+
+#ifndef FOR_DOXYGEN
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <sys/time.h>
+#include <locale.h>
+
+#include <m17n.h>
+#include <m17n-misc.h>
+
+/* Return a plist of all locales currently avairable on the system.
+   The keys and values of the plist are locale name symbols and
+   pointers to MLocale respectively.  */
+
+MPlist *
+list_system_locales ()
+{
+  FILE *p;
+  char buf[1024];
+  MPlist *plist;
+
+  /* Run the command "locale -a" to get a list of locales.  */
+  if (! (p = popen ("locale -a", "r")))
+    {
+      fprintf (stderr, "Can't run `locale -a'.\n");
+      exit (1);
+    }
+
+  plist = mplist ();
+  /* Read from the pipe one line by one.  */
+  while (fgets (buf, 1024, p))
+    {
+      MLocale *locale;
+      int len = strlen (buf);
+
+      if (buf[len - 1] == '\n')
+       buf[len - 1] = '\0';
+      locale = mlocale_set (LC_TIME, buf);
+
+      /* If the locale is surely usable, it is not duplicated, and we
+        know the corresponding coding system, add it to the list.  */
+      if (locale
+         && ! mplist_get (plist, mlocale_get_prop (locale, Mname))
+         && mlocale_get_prop (locale, Mcoding) != Mnil)
+       mplist_add (plist, mlocale_get_prop (locale, Mname), locale);
+    }
+  pclose (p);
+  return plist;
+}
+
+
+/* Print the usage of this program (the name is PROG), and exit with
+   EXIT_CODE.  */
+
+void
+help_exit (char *prog, int exit_code)
+{
+  char *p = prog;
+
+  while (*p)
+    if (*p++ == '/')
+      prog = p;
+
+  printf ("Usage: %s [ OPTION ...]\n", prog);
+  printf ("Display the system date and time in many locales on a window.\n");
+  printf ("The following OPTIONs are available.\n");
+  printf ("  %-13s %s", "--version", "Print version number.\n");
+  printf ("  %-13s %s", "-h, --help", "Print this message.\n");
+  exit (exit_code);
+}
+
+
+/* Format MSG by FMT and print the result to the stderr, and exit.  */
+
+#define FATAL_ERROR(fmt, arg)  \
+  do {                         \
+    fprintf (stderr, fmt, arg);        \
+    exit (1);                  \
+  } while (0)
+
+
+int
+main (int argc, char **argv)
+{
+  time_t current_time_t = time (NULL);
+  struct tm *current_time_tm = localtime (&current_time_t);
+  /* List of all locales.  */
+  MPlist *locale_list, *plist;
+  /* Text to be shown.  */
+  MText *mt;
+  int i;
+
+  for (i = 1; i < argc; i++)
+    {
+      if (! strcmp (argv[i], "--help")
+              || ! strcmp (argv[i], "-h")
+              || ! strcmp (argv[i], "-?"))
+       help_exit (argv[0], 0);
+      else if (! strcmp (argv[i], "--version"))
+       {
+         printf ("m17n-date (m17n library) %s\n", M17NLIB_VERSION_NAME);
+         printf ("Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 AIST, JAPAN\n");
+         exit (0);
+       }
+      else
+       help_exit (argv[0], 1);
+    }
+
+
+  /* Initialize the m17n library.  */
+  M17N_INIT ();
+  if (merror_code != MERROR_NONE)
+    FATAL_ERROR ("%s\n", "Fail to initialize the m17n library.");
+
+  /* Get a locale list in LOCALE_LIST, and generate an M-text that
+     contains date string in each locale.  */
+  locale_list = list_system_locales ();
+  mt = mtext ();
+  plist = locale_list;
+  while (mplist_key (plist) != Mnil)
+    {
+      char *name = msymbol_name (mplist_key (plist));
+      char fmtbuf[256];
+      int len;
+      MLocale *locale = mplist_value (plist);
+      MSymbol coding = mlocale_get_prop (locale, Mcoding);
+      /* One line text for this locale.  The format is:
+        "LOCALE-NAME:  DATE-AND-TIME-STRING".  */
+      MText *thisline;
+
+      sprintf (fmtbuf, "%16s: ", name);
+      len = strlen (fmtbuf);
+      thisline = mconv_decode_buffer (coding, (unsigned char *) fmtbuf, len);
+      if (thisline)
+       {
+         mlocale_set (LC_TIME, name);
+         if (mtext_ftime (thisline, "%c", current_time_tm, NULL) > 0)
+           {
+             mtext_cat_char (thisline, '\n');
+             mtext_cat (mt, thisline);
+           }
+         m17n_object_unref (thisline);
+       }
+      plist = mplist_next (plist);
+    }
+
+  /* Show the generated M-text by another example program "mview".  */
+  {
+    FILE *p = popen ("m17n-view", "w");
+
+    if (!p)
+      FATAL_ERROR ("%s\n", "Can't run the program mview!");
+    mconv_encode_stream (Mcoding_utf_8, mt, p);
+    fclose (p);
+  }
+
+  /* Clear away.  */
+  m17n_object_unref (locale_list);
+  m17n_object_unref (mt);
+  M17N_FINI ();
+
+  exit (0);
+}
+#endif /* not FOR_DOXYGEN */
diff --git a/example/mdump.c b/example/mdump.c
new file mode 100644 (file)
index 0000000..2159f90
--- /dev/null
@@ -0,0 +1,810 @@
+/* mdump.c -- Dump text image                          -*- coding: euc-jp; -*-
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @enpage m17n-dump dump text image
+
+    @section m17n-dump-synopsis SYNOPSIS
+
+    m17n-dump [ OPTION ... ] [ FILE ]
+
+    @section m17n-dump-description DESCRIPTION
+
+    Dump a text as PNG image file.
+
+    The PNG file is written to a file created in the current directory
+    with the name "BASE.png" where BASE is the basename of FILE.  If
+    FILE is omitted, text is read from standard input, and the image
+    is dumped into the file "output.png".
+
+    The following OPTIONs are available.
+
+    <ul>
+
+    <li> -s SIZE
+
+    SIZE is the font size in point.  The default font size is 12 point.
+
+    <li> -d DPI
+
+    DPI is the resolution in dots per inch.  The default resolution is
+    300 dpi.
+
+    <li> -p PAPER
+
+    PAPER is the paper size: a4, a4r, a5, a5r, b5, b5r, letter, WxH,
+    or W.  In the case of WxH, W and H are the width and height in
+    millimeter.  In the case of W, W is the width in millimeter.  If
+    this option is specified, PAPER limits the image size.  If FILE is
+    too large for a single page, multiple files with the names
+    "BASE.01.png", "BASE.02.png", etc. are created.
+
+    <li> -m MARGIN
+
+    MARGIN is the horizontal and vertical margin in millimeter.  The
+    default margin is 20 mm.  It is ignored when PAPER is not
+    specified.
+
+    <li> -c POS
+
+    POS is the character position of cursor to draw.  By default,
+    cursor is not drawn.
+
+    <li> -x
+
+    FILE is assumed to be an XML file generated by the serialize
+    facility of the m17n library, and FILE is deserialized before an
+    image is created.
+
+    <li> -w
+
+    Each line is broken at word boundary.
+
+    <li> -f FILTER
+
+    FILTER is a string containing a shell command line.  If this
+    option is specified, the PNG image is not written info a
+    file but is given to FILTER as standard input.  If FILTER
+    contains "%s", that part is replaced by a basename of FILE.
+    So, the default behaviour is the same as specifying "cat >
+    %s.png" as FILTER.
+
+    If FILTER is just "-", the PNG image is written to stdout.
+
+    <li> -a
+
+    Enable anti-alias drawing.
+
+    <li> --family FAMILY
+
+    Prefer a font whose family name is FAMILY.
+
+    <li> --language LANG
+
+    Prefer a font specified for the language LANG.  LANG must be a
+    2-letter code of ISO 630 (e.g. "en" for English).
+
+    <li> -fg FOREGROUND
+
+    Specify the text color.  The supported color names are those of
+    HTML 4.0 and "#RRGGBB" notation.
+
+    <li> -bg BACKGROUND
+
+    Specify the background color.  The supported color names are the
+    same as FOREGROUND, except that if "transparent" is specified,
+    make the background transparent.
+
+    <li> -r
+
+    Specify that the orientation of the text is right-to-left.
+
+    <li> -q
+
+    Quiet mode.  Don't print any messages.
+
+    <li> --version
+
+    Print the version number.
+
+    <li> -h, --help
+
+    Print this message.
+
+    </ul>
+*/
+/***ja
+    @japage m17n-dump ¥Æ¥­¥¹¥È²èÁü¤Î¥À¥ó¥×
+
+    @section m17n-dump-synopsis SYNOPSIS
+
+    m17n-dump [ OPTION ... ] [ FILE ]
+
+    @section m17n-dump-description DESCRIPTION
+
+    ¥Æ¥­¥¹¥È¤ò PNG ²èÁü¤È¤·¤Æ¥À¥ó¥×¤¹¤ë¡£ 
+
+    PNG ²èÁü¤Ï¸½ºß¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ëºî¤é¤ì¤¿ "BASE.png" ¤È¤¤¤¦Ì¾Á°¤Î 
+    ¥Õ¥¡¥¤¥ë¤Ë½ñ¤­¹þ¤Þ¤ì¤ë¡£¤³¤³¤Ç BASE ¤ÏFILE ¤Î basename ¤Ç¤¢¤ë¡£ 
+    FILE ¤¬¾Êά¤µ¤ì¤ì¤Ð¡¢¥Æ¥­¥¹¥È¤Ïɸ½àÆþÎϤ«¤éÆɤޤ졢²èÁü¤Ï 
+    "output.png" ¤Ë¥À¥ó¥×¤µ¤ì¤ë¡£
+
+    °Ê²¼¤Î¥ª¥×¥·¥ç¥ó¤¬ÍøÍѤǤ­¤ë¡£
+
+    <ul>
+
+    <li> -s SIZE
+
+    SIZE ¤Ï¥Õ¥©¥ó¥È¤ÎÂ礭¤µ¤ò¥Ý¥¤¥ó¥Èñ°Ì¤Ç¼¨¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£¥Ç¥Õ¥©¥ë
+    ¥È¤ÎÂ礭¤µ¤Ï 12 ¥Ý¥¤¥ó¥È¡£
+
+    <li> -d DPI
+
+    DPI ¤Ï²òÁüÅÙ¤ò£±¥¤¥ó¥Á¤¢¤¿¤ê¤Î¥É¥Ã¥Èñ°Ì¤Ç¼¨¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£¥Ç¥Õ¥© 
+    ¥ë¥È¤Î²òÁüÅ٤Ϡ300 dpi¡£
+
+    <li> -p PAPER
+
+    PAPER ¤Ï¤Ú¡¼¥Ñ¥µ¥¤¥º : a4, a4r, a5, a5r, b5, b5r, letter, WxH ¤Þ¤¿
+    ¤Ï W¡£ WxH ¤Î¾ì¹ç¡¢ W ¤È H ¤ÏÉý¤È¹â¤µ¤ò¥ß¥ê¥á¡¼¥¿Ã±°Ì¤Ç¼¨¤·¤¿¤â¤Î¡£
+    W ¤Î¾ì¹ç¡¢ W ¤ÏÉý¤ò¥ß¥ê¥á¡¼¥¿Ã±°Ì¤Ç¼¨¤·¤¿¤â¤Î¡£¤³¤Î¥ª¥×¥·¥ç¥ó¤¬»ØÄê
+    ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢ PAPER ¤¬²èÁü¥µ¥¤¥º¤òÀ©¸Â¤¹ ¤ë¡£FILE ¤¬ 1 ¥Ú¡¼¥¸
+    ¤ËǼ¤Þ¤é¤Ê¤¤¤Û¤ÉÂ礭¤¤¾ì¹ç¤Ï¡¢"BASE.01.png", "BASE.02.png" Åù¤Î̾Á°
+    ¤Î¤Ä¤¤¤¿Ê£¿ô¤Î¥Õ¥¡¥¤¥ë¤¬ºî¤é¤ì¤ë¡£
+
+    <li> -m MARGIN
+
+    MARGIN ¤Ï¿åÊ¿¡¢¿âľ¥Þ¡¼¥¸¥ó¤ò¥ß¥ê¥á¡¼¥¿Ã±°Ì¤Ç¼¨¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£¥Ç 
+    ¥Õ¥©¥ë¥È¤Î¥Þ¡¼¥¸¥ó¤Ï 20 mm¡£PAPER ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð̵»ë¤µ¤ì¤ë¡£
+
+    <li> -c POS
+
+    POS ¤Ï¥«¡¼¥½¥ë¤Îʸ»ú°ÌÃÖ¡£¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢¥«¡¼¥½¥ë¤ÏÉÁ¤«¤ì¤Ê¤¤¡£
+
+    <li> -x
+
+    FILE ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤Î¥·¥ê¥¢¥é¥¤¥ºµ¡Ç½¤Ë¤è¤Ã¤Æºî¤é¤ì¤¿ XML ¥Õ¥¡ 
+    ¥¤¥ë¤Ç¤¢¤ê¡¢²èÁü¤òÀ¸À®¤¹¤ëÁ°¤Ë¥Ç¥·¥ê¥¢¥é¥¤¥º¤µ¤ì¤ë¡£
+
+    <li> -w
+
+    ¸ì¤Î¶­³¦¤Ç²þ¹Ô¤¹¤ë¡£ 
+
+    <li> -f FILTER
+
+    FILTER ¤Ï¥·¥§¥ë¥³¥Þ¥ó¥É¹Ô¤ò´Þ¤àʸ»úÎó¤Ç¤¢¤ë¡£¤³¤Î¥ª¥×¥·¥ç¥ó¤¬»ØÄê
+    ¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢PNG ²èÁü¤Ï¥Õ¥¡¥¤¥ë¤Ë½ñ¤«¤ì¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢FILTER ¤Ë 
+    É¸½àÆþÎϤȤ·¤ÆÅϤµ¤ì¤ë¡£ FILTER ¤¬ "%s" ¤ò´Þ¤ó¤Ç¤¤¤ì¤Ð¡¢¤½¤ì¤Ï FILE 
+    ¤Î¥Ù¡¼¥¹¥Í¡¼¥à¤ËÃÖ¤­´¹¤¨¤é¤ì¤ë¡£¤³¤Î¥×¥í¥°¥é¥à¤Î¥Ç¥Õ¥©¥ë¥È¤Î¿¶Éñ¤¤
+    ¤È¡¢FILTER ¤Ë "cat > %s.png" ¤ò»ØÄꤷ¤¿¾ì¹ç¤Î¿¶Éñ¤ÏƱ°ì¤Ç¤¢¤ë¡£
+
+    ¤â¤· FILTER ¤¬Ã±¤Ë "-" ¤Ç¤¢¤ì¤Ð¡¢ PNG ²èÁü¤Ï stdout ¤Ë½ÐÎϤµ¤ì¤ë¡£
+
+    <li> -a
+
+    ¥¢¥ó¥Á¥¨¥¤¥ê¥¢¥¹½èÍý¤ò¹Ô¤¦¡£
+
+    <li> --family FAMILY
+
+    ¥Õ¥¡¥ß¥ê¥£Ì¾¤¬ FAMILY ¤Î¥Õ¥©¥ó¥È¤òÍ¥ÀèŪ¤Ë»È¤¦¡£
+
+    <li> --language LANG
+
+    ¸À¸ì LANG ÍѤ˻ØÄꤵ¤ì¤¿¥Õ¥©¥ó¥È¤òÍ¥ÀèŪ¤Ë»È¤¦¡£LANG ¤Ï ISO 630 ¤Î
+    £²Ê¸»ú¥³¡¼¥É¡ÊÎ㡧±Ñ¸ì¤Ï "en" ¡Ë¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
+
+    <li> -fg FOREGROUND
+
+    ¥Æ¥­¥¹¥È¤Î¿§¤ò»ØÄꤹ¤ë¡£HTML 4.0 ¤Î¿§¤Î̾Á°¤ª¤è¤Ó "#RRGGBB" µ­Ë¡¤ò
+    ¥µ¥Ý¡¼¥È¡£
+
+    <li> -bg BACKGROUND
+
+    Çطʤ理ò»ØÄꤹ¤ë¡£¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¿§¤Î̾Á°¤Ï FOREGROUND Æ±¤¸¡£
+    ¤¿¤À¤·¡¢¤â¤· "transparent" ¤¬»ØÄꤵ¤ì¤¿¤éÇطʤòÆ©ÌÀ¤Ë¤¹¤ë¡£
+
+    <li> -r
+
+    Specify that the orientation of the text is right-to-left.
+
+    <li> -q
+
+    °ìÀڤΥá¥Ã¥»¡¼¥¸¤òɽ¼¨¤·¤Ê¤¤¡£ 
+
+    <li> --version
+
+    ¥Ð¡¼¥¸¥ç¥óÈÖ¹æ¤òɽ¼¨¤¹¤ë¡£
+
+    <li> -h, --help
+
+    ¤³¤Î¥á¥Ã¥»¡¼¥¸¤òɽ¼¨¤¹¤ë¡£ 
+
+    </ul>
+*/
+
+#ifndef FOR_DOXYGEN
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <libgen.h>
+
+#if defined (HAVE_FREETYPE) && defined (HAVE_GD)
+#include <gd.h>
+
+#include <m17n-gui.h>
+#include <m17n-misc.h>
+
+/* Enumuration of the supported paper types.  */
+enum paper_type
+  {
+    PAPER_A4,
+    PAPER_A4R,
+    PAPER_A5,
+    PAPER_A5R,
+    PAPER_B5,
+    PAPER_B5R,
+    PAPER_LETTER,
+    PAPER_USER,
+    PAPER_NOLIMIT
+  };
+
+/* Array of paper sizes for the supported paper types.  */
+struct
+{
+  int width, height;           /* in millimeter */
+} paper_size[PAPER_NOLIMIT] = {
+  { 210, 297 },                        /* a4 */
+  { 297, 210 },                        /* a4r */
+  { 148, 210 },                        /* a5 */
+  { 210, 148 },                        /* a5r */
+  { 250, 176 },                        /* b5 */
+  { 176, 250 },                        /* b5r */
+  { 216, 279 },                        /* letter */
+};
+
+
+/* Print the usage of this program (the name is PROG), and exit with
+   EXIT_CODE.  */
+
+void
+help_exit (char *prog, int exit_code)
+{
+  char *p = prog;
+
+  while (*p)
+    if (*p++ == '/')
+      prog = p;
+
+  printf ("Usage: %s [ OPTION ...] [ FILE ]\n", prog);
+  printf ("Dump a text as a PNG image into a file.\n");
+  printf ("  The PNG file is created in the current directory\n");
+  printf ("    with the name \"BASE.png\" where BASE is the basename of FILE.\n");
+  printf ("  If FILE is omitted, text is read from standard input, and\n");
+  printf ("    dumped into the file \"output.png\".\n");
+  printf ("The following OPTIONs are available.\n");
+  printf ("  %-13s %s", "-s SIZE",
+         "Font size in 1/10 point (default 120).\n");
+  printf ("  %-13s %s", "-d DPI",
+         "Resolution in dots per inch (defualt 300).\n");
+  printf ("  %-13s %s", "-p PAPER",
+         "Paper size; a4, a4r, a5, a5r, b5, b5r, letter, W, or WxH.\n");
+  printf ("  %-13s %s", "-m MARGIN",
+         "Marginal space in millimeter (default 20).\n");
+  printf ("  %-13s %s", "-c POS",
+         "Character position of cursor to draw (default no cursor)\n");
+  printf ("  %-13s %s", "-x",
+         "FILE is assumed to be an XML file.\n");
+  printf ("  %-13s %s", "-f FILTER",
+         "String containing a shell command line to be used as a filter.\n");
+  printf ("  %-13s %s", "-w", "Each line is broken at word boundary.\n");
+  printf ("  %-13s %s", "-a", "Enable anti-alias drawing.\n");
+  printf ("  %-13s %s", "--family FAMILY", 
+         "Prefer a font whose family is FAMILY.\n");
+  printf ("  %-13s %s", "--language LANG", 
+         "Prefer a font specified for the langauge LANG.\n");
+  printf ("  %-13s %s", "-r", 
+         "Specify that the orientation of the text is right-to-left.\n");
+  printf ("  %-13s %s", "-fg FOREGROUND",
+         "Specify the text color (HTML 4.0 color names or \"#RRGGBB\").\n");
+  printf ("  %-13s %s", "-bg BACKGROUND",
+         "Specify the background color (\"transparent\" for transparent)\n");
+  printf ("  %-13s %s", "-q", "Quiet mode.  Don't print any messages.\n");
+  printf ("  %-13s %s", "--version", "Print the version number.\n");
+  printf ("  %-13s %s", "-h, --help", "Print this message.\n");
+  exit (exit_code);
+}
+
+
+/* Format MSG by FMT and print the result to the stderr, and exit.  */
+
+#define FATAL_ERROR(fmt, arg)  \
+  do {                         \
+    fprintf (stderr, fmt, arg);        \
+    exit (1);                  \
+  } while (0)
+
+
+/* Move POS to the next line head in M-text MT whose length is LEN.
+   If POS is already on the last line, set POS to LEN.  */
+
+#define NEXTLINE(pos, len)                     \
+  do {                                         \
+    pos = mtext_character (mt, pos, len, '\n');        \
+    if (pos < 0)                               \
+      pos = len;                               \
+    else                                       \
+      pos++;                                   \
+  } while (0)
+
+
+/* Find the range of M-text MT that fits in one page of height HEIGHT
+   when drawn from the character position POS.  Set RECT->y to the
+   Y-offset of the first baseline.  */
+
+int
+find_page_end (MFrame *frame, int height, MText *mt, int pos,
+              MDrawControl *control, MDrawMetric *rect)
+{
+  int len = mtext_len (mt);
+  int to = pos;
+  int y = 0, yoff;
+
+  while (to < len)
+    {
+      int next = to;
+
+      NEXTLINE (next, len);
+      mdraw_text_extents (frame, mt, to, next, control, NULL, NULL, rect);
+      if (to == pos)
+       yoff = rect->y;
+      if (y + rect->height > height)
+       {
+         MDrawGlyphInfo info;
+
+         while (to < next)
+           {
+             mdraw_glyph_info (frame, mt, to, to, control, &info);
+             if (y + info.metrics.height > height)
+               break;
+             y += info.metrics.height;
+             to = info.line_to;
+           }
+         break;
+       }
+      y += rect->height;
+      to = next;
+    }
+
+  rect->y = yoff;
+  return to;
+}
+
+/* Dump the image in IMAGE into a file whose name is generated from
+   FILENAME and PAGE_INDEX (if it is not zero).  */
+
+void
+dump_image (gdImagePtr image, char *filename, char *filter,
+           int page_index, int quiet_mode)
+{
+  FILE *fp;
+
+  if (page_index)
+    {
+      char *name = alloca (strlen (filename) + 8);
+
+      sprintf (name, "%s.%02d", filename, page_index);
+      filename = name;
+    }
+
+  if (filter)
+    {
+      if (filter[0] == '-' && filter[1] == '\0')
+       fp = stdout;
+      else
+       {
+         char *command = alloca (strlen (filename) + strlen (filter) + 1);
+
+         sprintf (command, filter, filename);
+         fp = popen (command, "w");
+         if (! fp)
+           FATAL_ERROR ("Can't run the command \"%s\"\n", command);
+         if (! quiet_mode)
+           printf ("Running \"%s\" ... ", command);
+       }
+    }
+  else
+    {
+      char *fullname = alloca (strlen (filename) + 5);
+
+      sprintf (fullname, "%s.png", filename);
+      fp = fopen (fullname, "w");
+      if (! fp)
+       FATAL_ERROR ("Can't write to \"%s\"\n", fullname);
+      if (! quiet_mode)
+       printf ("Writing %s ... ", fullname);
+    }
+
+  /* Generate PNG.  */
+  gdImagePng (image, fp);
+  if (fp != stderr)
+    fclose (fp);
+  if (! quiet_mode)
+    printf (" done (%dx%d)\n", image->sx, image->sy);
+}
+
+extern int line_break (MText *mt, int pos, int from, int to, int line, int y);
+
+int
+main (int argc, char **argv)
+{
+  int fontsize = 120;
+  int paper = PAPER_NOLIMIT;
+  int dpi = 300;
+  int margin = 20;
+  int xml = 0;
+  FILE *fp = stdin;
+  int cursor_pos = -1;
+  int quiet_mode = 0;
+  int break_by_word = 0;
+  char *filter = NULL;
+  int paper_width, paper_height;
+  int anti_alias = 0;
+  char *family_name = NULL;
+  char *lang_name = NULL;
+  char *fg_color = NULL, *bg_color = NULL;
+  int transparent = 0;
+  int r2l = 0;
+  int i;
+  int page_index;
+  gdImagePtr image;
+  int bg_rgb;
+
+  MFrame *frame;
+  MText *mt;
+  MDrawControl control;
+  MDrawMetric rect;
+  char *filename = "output";
+  int len, from;
+  char *fontset_name = "generic";
+
+
+  /* Parse the command line arguments.  */
+  for (i = 1; i < argc; i++)
+    {
+      if (! strcmp (argv[i], "--help")
+              || ! strcmp (argv[i], "-h")
+              || ! strcmp (argv[i], "-?"))
+       help_exit (argv[0], 0);
+      else if (! strcmp (argv[i], "--version"))
+       {
+         printf ("m17n-dump (m17n library) %s\n", M17NLIB_VERSION_NAME);
+         printf ("Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 AIST, JAPAN\n");
+         exit (0);
+       }
+      else if (! strcmp (argv[i], "-s") && i + 1< argc)
+       {
+         fontsize = atoi (argv[++i]);
+         if (! fontsize)
+           FATAL_ERROR ("Invalid font size: %s\n", argv[i]);
+       }
+      else if (! strcmp (argv[i], "-p") && i + 1< argc)
+       {
+         int w, h;
+
+         i++;
+         if (! strcmp (argv[i], "a4"))
+           paper = PAPER_A4;
+         else if (! strcmp (argv[i], "a4r"))
+           paper = PAPER_A4R;
+         else if (! strcmp (argv[i], "a5"))
+           paper = PAPER_A5;
+         else if (! strcmp (argv[i], "a5r"))
+           paper = PAPER_A5R;
+         else if (! strcmp (argv[i], "b5"))
+           paper = PAPER_B5;
+         else if (! strcmp (argv[i], "b5r"))
+           paper = PAPER_B5R;
+         else if (! strcmp (argv[i], "letter"))
+           paper = PAPER_LETTER;
+         else if (sscanf (argv[i], "%dx%d", &w, &h) == 2
+                  && w > 0 && h > 0)
+           {
+             paper = PAPER_USER;
+             paper_size[paper].width = w;
+             paper_size[paper].height = h;
+           }
+         else if (sscanf (argv[i], "%d", &w) == 1
+                  && w > 0)
+           {
+             paper = PAPER_USER;
+             paper_size[paper].width = w;
+             paper_size[paper].height = 0;
+           }
+         else
+           FATAL_ERROR ("Invalid paper type: %s\n", argv[i]);
+       }
+      else if (! strcmp (argv[i], "-d") && i + 1< argc)
+       {
+         dpi = atoi (argv[++i]);
+         if (! dpi)
+           FATAL_ERROR ("Invalid resolution: %s\n", argv[i]);
+       }
+      else if (! strcmp (argv[i], "-m") && i + 1< argc)
+       {
+         margin = atoi (argv[++i]);
+         if (margin < 0)
+           FATAL_ERROR ("Invalid margin: %s\n", argv[i]);
+       }
+      else if (! strcmp (argv[i], "-c") && i + 1< argc)
+       {
+         cursor_pos = atoi (argv[++i]);
+         if (cursor_pos < 0)
+           FATAL_ERROR ("Invalid cursor position: %s\n", argv[i]);
+       }
+      else if (! strcmp (argv[i], "-f") && i + 1< argc)
+       {
+         filter = argv[++i];
+       }
+      else if (! strcmp (argv[i], "-x"))
+       {
+         xml = 1;
+       }
+      else if (! strcmp (argv[i], "-w"))
+       {
+         break_by_word = 1;
+       }
+      else if (! strcmp (argv[i], "-q"))
+       {
+         quiet_mode = 1;
+       }
+      else if (! strcmp (argv[i], "-a"))
+       {
+         anti_alias = 1;
+       }
+      else if (! strcmp (argv[i], "--family"))
+       {
+         family_name = argv[++i];
+       }
+      else if (! strcmp (argv[i], "--language"))
+       {
+         lang_name = argv[++i];
+       }
+      else if (! strcmp (argv[i], "-r"))
+       {
+         r2l = 1;
+       }
+      else if (argv[i][0] != '-')
+       {
+         fp = fopen (argv[i], "r");
+         if (! fp)
+           FATAL_ERROR ("Fail to open the file %s!\n", argv[i]);
+         filename = basename (argv[i]);
+       }
+      else if (! strcmp (argv[i], "--fontset"))
+       {
+         fontset_name = argv[++i];
+       }
+      else if (! strcmp (argv[i], "-fg"))
+       {
+         if (i + 1 == argc)
+           {
+             fprintf (stderr, "Foreground color not specified\n");
+             help_exit (argv[0], 1);
+           }
+         fg_color = argv[++i];
+       }
+      else if (! strcmp (argv[i], "-bg"))
+       {
+         if (i + 1 == argc)
+           {
+             fprintf (stderr, "Background color not specified\n");
+             help_exit (argv[0], 1);
+           }
+         i++;
+         if (! strcmp (argv[i], "transparent"))
+           transparent = 1;
+         else
+           bg_color = argv[i];
+       }
+      else
+       {
+         fprintf (stderr, "Unknown or invalid option: %s\n", argv[i]);
+         help_exit (argv[0], 1);
+       }
+    }
+
+  /* Initialize the m17n library.  */
+  M17N_INIT ();
+  if (merror_code != MERROR_NONE)
+    FATAL_ERROR ("%s\n", "Fail to initialize the m17n library.");
+
+  mt = mconv_decode_stream (Mcoding_utf_8, fp);
+  fclose (fp);
+  if (xml)
+    mt = mtext_deserialize (mt);
+  if (! mt)
+    FATAL_ERROR ("%s\n", "Fail to decode the input file or stream!");
+
+  len = mtext_len (mt);
+  if (lang_name)
+    mtext_put_prop (mt, 0, len, Mlanguage, msymbol (lang_name));
+
+  if (paper == PAPER_NOLIMIT)
+    paper_width = paper_height = margin = 0;
+  else
+    {
+      paper_width = paper_size[paper].width * dpi / 25.4;
+      paper_height = paper_size[paper].height * dpi / 25.4;
+      margin = margin * dpi / 25.4;
+    }
+
+  {
+    MPlist *plist = mplist (), *p;
+    MFontset *fontset = mfontset (fontset_name);
+    MFace *face = mface ();
+
+    mface_put_prop (face, Mfontset, fontset);
+    mface_put_prop (face, Msize, (void *) (fontsize * dpi / 100));
+    if (family_name)
+      {
+       char *p;
+
+       for (p = family_name; *p; p++)
+         if (isupper (*p)) *p = tolower (*p);
+       mface_put_prop (face, Mfamily, msymbol (family_name));
+      }
+    if (fg_color)
+      mface_put_prop (face, Mforeground, msymbol (fg_color));
+    if (bg_color)
+      mface_put_prop (face, Mbackground, msymbol (bg_color));
+    p = mplist_add (plist, Mdevice, msymbol ("gd"));
+    p = mplist_add (p, Mface, face);
+    m17n_object_unref (face);
+    frame = mframe (plist);
+    m17n_object_unref (plist);
+    if (! frame)
+      FATAL_ERROR ("%s\n", "Can't open a frame (perhaps no font available)!");
+  }
+
+  memset (&control, 0, sizeof control);
+  control.two_dimensional = 1;
+  control.enable_bidi = 1;
+  control.anti_alias = anti_alias;
+  control.orientation_reversed = r2l;
+  if (cursor_pos >= 0)
+    {
+      control.with_cursor = 1;
+      if (cursor_pos > len)
+       cursor_pos = len;
+      control.cursor_pos = cursor_pos;
+      control.cursor_width = -1;
+    }
+  else
+    control.ignore_formatting_char = 1;
+  if (break_by_word)
+    control.line_break = mdraw_default_line_break;
+
+  if (paper == PAPER_NOLIMIT)
+    {
+      control.max_line_width = 0;
+      mdraw_text_extents (frame, mt, 0, len, &control, NULL, NULL, &rect);
+      paper_width = rect.width;
+      paper_height = rect.height;
+    }
+  else
+    {
+      control.max_line_width = paper_width - margin * 2;
+      if (paper_height == 0)
+       {
+         mdraw_text_extents (frame, mt, 0, len, &control, NULL, NULL, &rect);
+         paper_height = rect.height + margin * 2;
+       }
+    }
+
+#if HAVE_GD > 1
+  image = gdImageCreateTrueColor (paper_width, paper_height);
+#else
+  image = gdImageCreate (paper_width, paper_height);
+#endif
+  from = 0;
+  page_index = 1;
+
+  if (transparent)
+    {
+      MFace *face = mframe_get_prop (frame, Mface);
+      MSymbol fg = mface_get_prop (face, Mforeground);
+      int rgb_value = 0;
+
+      if (fg)
+       rgb_value = (int) msymbol_get (fg, msymbol ("  rgb"));
+      if (rgb_value == 0xFFFFFF)
+       bg_rgb = gdImageColorAllocate (image, 0, 0, 0);
+      else
+       bg_rgb = gdImageColorAllocate (image, 255, 255, 255);
+      gdImageColorTransparent (image, bg_rgb);
+#if HAVE_GD > 1
+      gdImageAlphaBlending (image, 0);
+#endif
+    }
+  else
+    {
+      MFace *face = mframe_get_prop (frame, Mface);
+      MSymbol bg = mface_get_prop (face, Mbackground);
+      if (bg)
+       {
+         int rgb_value = (int) msymbol_get (bg, msymbol ("  rgb"));
+         bg_rgb = gdImageColorAllocate (image, rgb_value >> 16, 
+                                        (rgb_value >> 8) & 255, 
+                                        rgb_value & 255);
+       }
+      else
+       bg_rgb = gdImageColorAllocate (image, 255, 255, 255);
+    }
+
+  while (from < len)
+    {
+      int to;
+
+      if (paper == PAPER_NOLIMIT || paper_size[paper].height == 0)
+       to = len;
+      else
+       to = find_page_end (frame, paper_height - margin * 2, mt, from,
+                           &control, &rect);
+
+      gdImageFilledRectangle (image, 0, 0, paper_width - 1, paper_height - 1,
+                             bg_rgb);
+      if (! r2l)
+       mdraw_text_with_control (frame, image,
+                                margin, margin - rect.y,
+                                mt, from, to, &control);
+      else
+       mdraw_text_with_control (frame, image,
+                                paper_width - margin, margin - rect.y,
+                                mt, from, to, &control);
+      dump_image (image, filename, filter,
+                 ((from > 0 || to < len) ? page_index : 0),
+                 quiet_mode);
+
+      from = to;
+      page_index++;
+    }
+
+  m17n_object_unref (frame);
+  m17n_object_unref (mt);
+  M17N_FINI ();
+  gdImageDestroy (image);
+  exit (0);
+}
+
+#else  /* not HAVE_FREETYPE nor HAVE_GD */
+
+int
+main (int argc, char **argv)
+{
+  fprintf (stderr, "Can't run without Freetype and GD library!\n");
+  exit (1);
+}
+
+#endif  /* not HAVE_FREETYPE nor HAVE_GD */
+#endif /* not FOR_DOXYGEN */
diff --git a/example/medit.c b/example/medit.c
new file mode 100644 (file)
index 0000000..fe6fad2
--- /dev/null
@@ -0,0 +1,3278 @@
+/* medit.c -- simple multilingual editor.              -*- coding: euc-jp; -*-
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @enpage m17n-edit edit multilingual text
+
+    @section m17n-edit-synopsis SYNOPSIS
+
+    m17n-edit [ XT-OPTION ...] [ OPTION ... ] FILE
+
+    @section m17n-edit-description DESCRIPTION
+
+    Display FILE on a window and allow users to edit it.
+
+    XT-OPTIONs are standard Xt arguments (e.g. -fn, -fg).
+
+    The following OPTIONs are available.
+
+    <ul>
+
+    <li> --version
+
+    Print version number.
+
+    <li> -h, --help
+
+    Print this message.
+
+    </ul>
+
+    This program is to demonstrate how to use the m17n GUI API.
+    Although m17n-edit directly uses the GUI API, the API is mainly
+    for toolkit libraries or to implement XOM (X Output Method), not
+    for direct use from application programs.
+*/
+/***ja
+    @japage m17n-edit Â¿¸À¸ì¥Æ¥­¥¹¥È¤ÎÊÔ½¸
+
+    @section m17n-edit-synopsis SYNOPSIS
+
+    m17n-edit [ XT-OPTION ...] [ OPTION ... ] FILE
+
+    @section m17n-edit-description DESCRIPTION
+
+    FILE ¤ò¥¦¥£¥ó¥É¥¦¤Ëɽ¼¨¤·¡¢¥æ¡¼¥¶¤¬ÊÔ½¸¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë¡£
+
+    XT-OPTIONs ¤Ï Xt ¤Îɸ½à¤Î°ú¿ô¤Ç¤¢¤ë¡£ (e.g. -fn, -fg). 
+
+    °Ê²¼¤Î¥ª¥×¥·¥ç¥ó¤¬ÍøÍѤǤ­¤ë¡£ 
+
+    <ul>
+
+    <li> --version
+
+    ¥Ð¡¼¥¸¥ç¥óÈÖ¹æ¤òɽ¼¨¤¹¤ë¡£ 
+
+    <li> -h, --help
+
+    ¤³¤Î¥á¥Ã¥»¡¼¥¸¤òɽ¼¨¤¹¤ë¡£ 
+
+    </ul>
+
+    ¤³¤Î¥×¥í¥°¥é¥à¤Ï m17n GUI API ¤Î»È¤¤Êý¤ò¼¨¤¹¤â¤Î¤Ç¤¢¤ë¡£m17n-edit
+    ¤ÏľÀÜ GUI API ¤ò»È¤Ã¤Æ¤¤¤ë¤¬¡¢¤³¤Î API ¤Ï¼ç¤Ë¥Ä¡¼¥ë¥­¥Ã¥È¥é¥¤¥Ö¥é
+    ¥ê¤äXOM (X Output Method) ¤Î¼ÂÁõÍѤǤ¢¤ê¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é
+    ¥à¤«¤é¤ÎľÀܤÎÍøÍѤò°Õ¿Þ¤·¤Æ¤¤¤Ê¤¤¡£
+*/
+
+#ifndef FOR_DOXYGEN
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <libgen.h>
+#include <locale.h>
+#include <dlfcn.h>
+
+#ifdef HAVE_X11_XAW_COMMAND_H
+
+#include <X11/keysym.h>
+#include <X11/Xatom.h>
+#include <X11/Intrinsic.h>
+#include <X11/StringDefs.h>
+#include <X11/Shell.h>
+
+#include <m17n-gui.h>
+#include <m17n-misc.h>
+#include <m17n-X.h>
+
+#include <X11/Xaw/Command.h>
+#include <X11/Xaw/Box.h>
+#include <X11/Xaw/Form.h>
+#include <X11/Xaw/Dialog.h>
+#include <X11/Xaw/Scrollbar.h>
+#include <X11/Xaw/Toggle.h>
+#include <X11/Xaw/SimpleMenu.h>
+#include <X11/Xaw/SmeBSB.h>
+#include <X11/Xaw/SmeLine.h>
+#include <X11/Xaw/MenuButton.h>
+
+/* Global variables.  */
+
+char *filename;
+int serialized;
+
+/* For the X Window System.  */
+Display *display;
+int screen;
+/* GCs for normal drawing, filling by background color, normal drawing
+   on bitmap (i.e. pixmap of depth 1), filling bitmap by background
+   color. */
+GC gc, gc_inv, mono_gc, mono_gc_inv;
+Window win;
+Atom XA_TEXT, XA_COMPOUND_TEXT, XA_UTF8_STRING;        /* X Selection types.  */
+XtAppContext context;
+int default_font_size;
+
+/* Widget hierarchy
+
+Shell - Form -+- Head -- File, Cursor, Bidi, LineBreak, InputMethod, CurIM;
+             +- Face -- Size, Family, Style, Color, Misc, Pop, CurFace
+             +- Lang -- A-B, C-D, ..., U-Z, Pop, CurLang
+             +- Body -- Sbar, Text
+             +- Tail -- Message
+*/
+
+Widget ShellWidget, HeadWidget, TailWidget, MessageWidget;
+Widget CursorMenus[5], BidiMenus[3], LineBreakMenus[3], *InputMethodMenus;
+Widget SbarWidget, TextWidget;
+Widget FileShellWidget, FileDialogWidget;
+Widget FaceWidget, CurFaceWidget, LangWidget, CurLangWidget;
+Widget CurIMLang, CurIMStatus;
+
+int win_width, win_height;     /* Size of TextWidget.  */
+Arg arg[10];
+
+Pixmap input_status_pixmap;
+int input_status_width, input_status_height;
+
+/* Bitmap for "check" glyph.  */
+#define check_width 9
+#define check_height 8
+static unsigned char check_bits[] = {
+   0x00, 0x01, 0x80, 0x01, 0xc0, 0x00, 0x60, 0x00,
+   0x31, 0x00, 0x1b, 0x00, 0x0e, 0x00, 0x04, 0x00 };
+Pixmap CheckPixmap;
+
+/* For the m17n library.  */
+MFrame *frame;
+MText *mt;
+int nchars;                    /* == mtext_len (mt) */
+int mt_modified;
+MDrawControl control, input_status_control;
+MTextProperty *selection;
+
+MSymbol Mword;
+
+MFace *face_default;
+MFace *face_xxx_large;
+MFace *face_box;
+MFace *face_courier, *face_helvetica, *face_times;
+MFace *face_dv_ttyogesh, *face_freesans, *face_freeserif, *face_freemono;
+MFace *face_default_fontset, *face_no_ctl_fontset;
+MFace *face_input_status;
+
+MSymbol Mcoding_compound_text;
+
+int logical_move = 1;          /* If 0, move cursor visually.  */
+
+typedef struct {
+  int available;
+  MSymbol language, name;
+  MInputMethod *im;
+} InputMethodInfo;
+
+InputMethodInfo *input_method_table;
+
+int num_input_methods;
+int current_input_method = -1; /* i.e. none */
+int unicode_input_method = -1;
+int auto_input_method = 0;
+int saved_input_method = -3;
+MInputContext *current_input_context;
+
+struct FaceRec
+{
+  char *name;
+  MFace **face;
+} face_table[] =
+  { {"Menu Size", NULL},
+    {"xx-small", &mface_xx_small},
+    {"x-small", &mface_x_small},
+    {"small", &mface_small},
+    {"normalsize", &mface_normalsize},
+    {"large", &mface_large},
+    {"x-large", &mface_x_large},
+    {"xx-large", &mface_xx_large},
+    {"xxx-large", &face_xxx_large},
+
+    {"Menu Family", NULL},
+    {"courier", &face_courier},
+    {"helvetica", &face_helvetica},
+    {"times", &face_times},
+    {"dv-ttyogesh", &face_dv_ttyogesh},
+    {"freesans", &face_freesans},
+    {"freeserif", &face_freeserif},
+    {"freemono", &face_freemono},
+
+    {"Menu Style", NULL},
+    {"medium", &mface_medium},
+    {"bold", &mface_bold},
+    {"italic", &mface_italic},
+
+    {"Menu Color", NULL},
+    {"black", &mface_black},
+    {"white", &mface_white},
+    {"red", &mface_red},
+    {"green", &mface_green},
+    {"blue", &mface_blue},
+    {"cyan", &mface_cyan},
+    {"yello", &mface_yellow},
+    {"magenta", &mface_magenta},
+
+    {"Menu Misc", NULL},
+    {"normal", &mface_normal_video},
+    {"reverse", &mface_reverse_video},
+    {"underline", &mface_underline},
+    {"box", &face_box},
+    {"No CTL", &face_no_ctl_fontset} };
+
+
+int num_faces = sizeof (face_table) / sizeof (struct FaceRec);
+
+/* Information about a physical line metric.  */
+struct LineInfo
+{
+  int from;                    /* BOL position of the line.  */
+  int to;                      /* BOL position of the next line.  */
+  int y0, y1;                  /* Top and bottom Y position of the line.  */
+  int ascent;                  /* Height of the top Y position.  */
+};
+
+struct LineInfo top;           /* Topmost line.  */
+struct LineInfo cur;           /* Line containing cursor.  */
+struct LineInfo sel_start;     /* Line containing selection start.  */
+struct LineInfo sel_end;       /* Line containing selection end.  */
+
+MDrawGlyphInfo cursor;     /* Information about the cursor glyph.  */
+
+/* X position to keep on vertical (up and down) cursor motion. */
+int target_x_position;
+
+/* Interface macros for m17n-lib drawing routines. */
+
+/* Draw a text in the range $FROM to $TO of the M-text #MT at the
+   coordinate ($X, $Y)  */
+#define DRAW_TEXT(x, y, from, to)                              \
+    mdraw_text_with_control                                    \
+      (frame, (MDrawWindow) win,                               \
+       control.orientation_reversed ? x + win_width : x, y,    \
+       mt, from, to, &control)
+
+/* Store the extents of a text in the range $FROM to $TO in the
+   structure $RECT (type MDrawMetric).  */
+#define TEXT_EXTENTS(from, to, rect)   \
+  mdraw_text_extents (frame, mt, from, (to), &control, NULL, NULL, &(rect))
+
+/* Store the glyph information of a character at the position $POS in
+   the struct $INFO (type MDrawGlyphInfo) assuming that the text from
+   $FROM is written at the coordinate (0, 0).  */
+#define GLYPH_INFO(from, pos, info)    \
+  mdraw_glyph_info (frame, mt, from, (pos), &control, &(info))
+
+/* Set $X and $Y to the coordinate of character at position $POS
+   assuming that the text from $FROM is written at the coordinate (0,
+   0).  */
+#define COORDINATES_POSITION(from, pos, x, y)  \
+  mdraw_coordinates_position (frame, mt, (from), (pos), (x), (y), &control)
+
+/* Interface macros for X library.  */
+#define COPY_AREA(y0, y1, to)  \
+  XCopyArea (display, win, win, gc, 0, (y0), win_width, (y1) - (y0), 0, (to))
+
+#define CLEAR_AREA(x, y, w, h) \
+  XClearArea (display, win, (x), (y), (w), (h), False)
+
+#define SELECTEDP() \
+  mtext_property_mtext (selection)
+
+/* Format MSG by FMT and print the result to the stderr, and exit.  */
+#define FATAL_ERROR(fmt, arg)  \
+  do {                         \
+    fprintf (stderr, fmt, arg);        \
+    exit (1);                  \
+  } while (0)
+
+
+/* If POS is greater than zero, move POS back to the beginning of line
+   (BOL) position.  If FORWARD is nonzero, move POS forward instead.
+   Return the new position.  */
+int
+bol (int pos, int forward)
+{
+  int limit = forward ? nchars : 0;
+
+  pos = mtext_character (mt, pos, limit, '\n');
+  return (pos < 0 ? limit : pos + 1);
+}
+
+/* Update the structure #TOP (struct LineInfo) to make $POS the first
+   character position of the screen.  */
+void
+update_top (int pos)
+{
+  int from = bol (pos, 0);
+  MDrawGlyphInfo info;
+
+  GLYPH_INFO (from, pos, info);
+  top.from = info.line_from;
+  top.to = info.line_to;
+  top.y0 = 0;
+  top.y1 = info.metrics.height;
+  top.ascent = - info.metrics.y;
+}
+
+
+/* Update the scroll bar so that the text of the range $FROM to $TO
+   are shown on the window.  */
+void
+update_scroll_bar (int from, int to)
+{
+  float top = (float) from / nchars;
+  float shown = (float) (to - from) / nchars;
+
+  XawScrollbarSetThumb (SbarWidget, top, shown);
+}
+
+
+/* Redraw the window area between $Y0 and $Y1 (both Y-codinates).  If
+   $CLEAR is nonzero, clear the area before drawing.  If $SCROLL_BAR
+   is nonzero, update the scoll bar.  */
+void
+redraw (int y0, int y1, int clear, int scroll_bar)
+{
+  int from, to;
+  int y;
+  MDrawGlyphInfo info;
+  int sel_y0 = SELECTEDP () ? sel_start.y0 : 0;
+  struct LineInfo *line;
+  
+  if (clear || control.anti_alias)
+    CLEAR_AREA (0, y0, win_width, y1 - y0);
+
+  /* Find a line closest to y0.  It is a cursor line if the cursor is
+     Y0, otherwise the top line.  */
+  if (y0 >= cur.y0)
+    line = &cur;
+  else
+    line = &top;
+  /* If there exists a selected region, check it too.  */
+  if (sel_y0 > line->y0 && y0 >= sel_y0)
+    line = &sel_start;
+
+  from = line->from;
+  y = line->y0;
+  info.metrics.height = line->y1 - y;
+  info.metrics.y = - line->ascent;
+  info.line_to = line->to;
+  while (y + info.metrics.height <= y0)
+    {
+      y += info.metrics.height;
+      from = info.line_to;
+      if (from >= nchars)
+       break;
+      GLYPH_INFO (from, from, info);
+    }
+  if (y + info.metrics.height <= y0)
+    return;
+
+  y0 = y - info.metrics.y;
+  to = from;
+  while (to < nchars && y < y1)
+    {
+      GLYPH_INFO (to, to, info);
+      y += info.metrics.height;
+      to = info.line_to;
+    }
+  if (to == nchars)
+    to++;
+  if (from < to)
+    DRAW_TEXT (0, y0, from, to);
+  if (scroll_bar)
+    {
+      while (to < nchars)
+       {
+         GLYPH_INFO (to, to, info);
+         if (y + info.metrics.height >= win_height)
+           break;
+         to = info.line_to;
+         y += info.metrics.height;
+       }
+      update_scroll_bar (top.from, to);
+    }
+}
+     
+
+/* Set the current input method spot to the correct position.  */
+void
+set_input_method_spot ()
+{
+  int x = cursor.x + (control.orientation_reversed ? win_width : 0);
+  int pos = cursor.from > 0 ? cursor.from - 1 : 0;
+  MFace *faces[256];
+  int n = 0;
+  int size = 0, ratio = 0, i;
+
+  if (nchars > 0)
+    n = mtext_get_prop_values (mt, pos, Mface, (void **) faces, 256);
+  if (n > 0)
+    for (i = n - 1; i >= 0; i--)
+      {
+       if (! size)
+         size = (int) mface_get_prop (faces[i], Msize);
+       if (! ratio)
+         ratio = (int) mface_get_prop (faces[i], Mratio);
+      }
+  if (! size)
+    size = default_font_size;
+  if (ratio)
+    size = size * ratio / 100;
+  minput_set_spot (current_input_context, x, cur.y0 + cur.ascent,
+                  cur.ascent, cur.y1 - (cur.y0 + cur.ascent), size,
+                  mt, cursor.from);
+}
+
+
+/* Redraw the cursor.  If $CLEAR is nonzero, clear the cursor area
+   before drawing.  */
+void
+redraw_cursor (int clear)
+{
+  if (control.cursor_bidi)
+    {
+      /* We must update the whole line of the cursor.  */
+      int beg = bol (cur.from, 0);
+      int end = bol (cur.to - 1, 1);
+      MDrawMetric rect;
+      int y0 = cur.y0, y1 = cur.y1;
+
+      if (beg < cur.from)
+       {
+         TEXT_EXTENTS (beg, cur.from, rect);
+         y0 -= rect.height;
+       }
+      if (end > cur.to)
+       {
+         TEXT_EXTENTS (cur.to, end, rect);
+         y1 += rect.height; 
+       }
+      redraw (y0, y1, clear, 0);
+    }
+  else
+    {
+      if (clear)
+       {
+         int x = cursor.x;
+
+         if (control.orientation_reversed)
+           x += win_width - cursor.logical_width;
+         CLEAR_AREA (x, cur.y0, cursor.logical_width, cursor.metrics.height);
+       }
+      DRAW_TEXT (cursor.x, cur.y0 + cur.ascent, cursor.from, cursor.to);
+    }
+}
+
+
+/* Update the information about the location of cursor to the position
+   $POS.  If $FULL is nonzero, update the information fully only from
+   the information about the top line.  Otherwise, trust the current
+   information in the structure $CUR.  */
+void
+update_cursor (int pos, int full)
+{
+  MDrawMetric rect;
+
+  control.cursor_pos = pos;
+  if (full)
+    {
+      /* CUR is inaccurate.  We can trust only TOP.  */
+      GLYPH_INFO (top.from, pos, cursor);
+      cur.y0 = top.ascent + cursor.y + cursor.metrics.y;
+    }
+  else if (pos < cur.from)
+    {
+      int from = bol (pos, 0);
+
+      TEXT_EXTENTS (from, cur.from, rect);
+      GLYPH_INFO (from, pos, cursor);
+      cur.y0 -= (rect.height + rect.y) - (cursor.y + cursor.metrics.y);
+    }
+  else if (pos < cur.to)
+    {
+      GLYPH_INFO (cur.from, pos, cursor);
+    }
+  else
+    {
+      GLYPH_INFO (cur.from, pos, cursor);
+      cur.y0 += cur.ascent + cursor.y + cursor.metrics.y;
+    }
+
+  cur.from = cursor.line_from;
+  cur.to = cursor.line_to;
+  cur.y1 = cur.y0 + cursor.metrics.height;
+  cur.ascent = - cursor.metrics.y;
+}
+
+
+/* Update the information about the selected region.  */
+void
+update_selection ()
+{
+  int from, to;
+  MDrawMetric rect;
+  MDrawGlyphInfo info;
+
+  if (! SELECTEDP ())
+    return;
+  from = mtext_property_start (selection);
+  to = mtext_property_end (selection);
+
+  if (from < top.from)
+    {
+      int pos = bol (from, 0);
+
+      TEXT_EXTENTS (pos, top.from, rect);
+      sel_start.y0 = top.y0 - rect.height;
+      sel_start.ascent = - rect.y;
+      GLYPH_INFO (pos, from, info);
+      if (pos < info.line_from)
+       sel_start.y0 += - rect.y + info.y + info.metrics.y;
+    }
+  else
+    {
+      GLYPH_INFO (top.from, from, info);
+      sel_start.y0 = top.ascent + info.y + info.metrics.y;
+    }
+  sel_start.ascent = -info.metrics.y;
+  sel_start.y1 = sel_start.y0 + info.metrics.height;
+  sel_start.from = info.line_from;
+  sel_start.to = info.line_to;
+
+  if (to <= sel_start.to)
+    {
+      sel_end = sel_start;
+    }
+  else
+    {
+      GLYPH_INFO (sel_start.from, to, info);
+      sel_end.y0 = sel_start.y0 + sel_start.ascent + info.y + info.metrics.y;
+      sel_end.y1 = sel_end.y0 + info.metrics.height;
+      sel_end.ascent = - info.metrics.y;
+      sel_end.from = info.line_from;
+      sel_end.to = info.line_to;
+    }
+}
+
+
+/* Select the text in the region from $FROM to $TO.  */
+void
+select_region (int from, int to)
+{
+  int pos;
+
+  if (from > to)
+    pos = from, from = to, to = pos;
+  mtext_push_property (mt, from, to, selection);
+  update_selection ();
+}
+
+
+/* Setup the window to display the character of $POS at the top left
+   of the window.  */
+void
+reseat (int pos)
+{
+  MDrawMetric rect;
+  /* Top and bottom Y positions to redraw.  */
+  int y0, y1;
+
+  if (pos + 1000 < top.from)
+    y0 = 0, y1 = win_height;
+  else if (pos < top.from)
+    {
+      y0 = 0;
+      TEXT_EXTENTS (pos, top.from, rect);
+      if (rect.height >= win_height * 0.9)
+       y1 = win_height;
+      else
+       {
+         y1 = rect.height;
+         COPY_AREA (0, win_height - y1, y1);
+       }
+    }
+  else if (pos < top.to)
+    {
+      /* No need of redrawing.  */
+      y0 = y1 = 0;
+    }
+  else if (pos < top.from + 1000)
+    {
+      TEXT_EXTENTS (top.from, pos, rect);
+      if (rect.height >= win_height * 0.9)
+       y0 = 0;
+      else
+       {
+         y0 = win_height - rect.height;
+         COPY_AREA (rect.height, win_height, 0);
+       }
+      y1 = win_height;
+    }
+  else
+    y0 = 0, y1 = win_height;
+
+  if (y0 < y1)
+    {
+      update_top (pos);
+      if (cur.to <= pos)
+       update_cursor (pos, 1);
+      else
+       update_cursor (cursor.from, 1);
+      update_selection ();
+      redraw (y0, y1, 1, 1);
+    }
+}
+
+static void MenuHelpProc (Widget, XEvent *, String *, Cardinal *);
+
+
+/* Select an input method accoding to $IDX.  If $IDX is negative, turn
+   off the current input method, otherwide turn on the input method
+   input_method_table[$IDX].  */
+void
+select_input_method (idx)
+{
+  int previous_input_method = current_input_method;
+
+  if (idx == current_input_method)
+    return;
+  if (current_input_method >= 0)
+    {
+      minput_destroy_ic (current_input_context);
+      current_input_context = NULL;
+      current_input_method = -1;
+    }
+
+  if (idx >= 0
+      && input_method_table[idx].available >= 0)
+    {
+      InputMethodInfo *im = input_method_table + idx;
+
+      if (im->available == 0)
+       {
+         if (im->language)
+           im->im = minput_open_im (im->language, im->name, NULL);
+         else
+           {
+             MInputXIMArgIM arg_xim;
+
+             arg_xim.display = display;
+             arg_xim.db = NULL;  
+             arg_xim.res_name = arg_xim.res_class = NULL;
+             arg_xim.locale = NULL;
+             arg_xim.modifier_list = NULL;
+             im->im = minput_open_im (Mnil, im->name, &arg_xim);
+           }
+         im->available = im->im ? 1 : -1;
+       }
+      if (im->im)
+       {
+         if (im->language == Mnil)
+           {
+             MInputXIMArgIC arg_xic;
+             Window win = XtWindow (TextWidget);
+
+             arg_xic.input_style = 0;
+             arg_xic.client_win = arg_xic.focus_win = win;
+             arg_xic.preedit_attrs =  arg_xic.status_attrs = NULL;
+             current_input_context = minput_create_ic (im->im, &arg_xic);
+           }
+         else
+           {
+             MInputGUIArgIC arg_ic;
+
+             arg_ic.frame = frame;
+             arg_ic.client = (MDrawWindow) XtWindow (ShellWidget);
+             arg_ic.focus = (MDrawWindow) XtWindow (TextWidget);
+             current_input_context = minput_create_ic (im->im, &arg_ic);
+           }
+
+         if (current_input_context)
+           {
+             current_input_method = idx;
+             set_input_method_spot ();
+           }
+         else
+           {
+             minput_close_im (im->im);
+             im->im = NULL;
+             im->available = -1;
+             current_input_method = -1;
+           }
+       }
+    }
+  if (! auto_input_method)
+    {
+      XtSetArg (arg[0], XtNleftBitmap, None);
+      if (previous_input_method >= 0)
+       XtSetValues (InputMethodMenus[previous_input_method + 2], arg, 1);
+      else
+       XtSetValues (InputMethodMenus[0], arg, 1);
+      XtSetArg (arg[0], XtNleftBitmap, CheckPixmap);
+      if (current_input_method >= 0)
+       XtSetValues (InputMethodMenus[current_input_method + 2], arg, 1);
+      else
+       XtSetValues (InputMethodMenus[0], arg, 1);
+    }
+
+  if (current_input_method >= 0)
+    {
+      char *label;
+
+      XtSetArg (arg[0], XtNlabel, &label);
+      XtGetValues (InputMethodMenus[current_input_method + 2], arg, 1);
+      XtSetArg (arg[0], XtNlabel, label);
+    }
+  else
+    {
+      XtSetArg (arg[0], XtNlabel, "");
+    }
+  XtSetValues (CurIMLang, arg, 1);
+}
+
+static void MenuHelpProc (Widget w, XEvent *event, String *str, Cardinal *num);
+
+
+/* Display cursor according to the current information of #CUR.
+   $CLIENT_DATA is ignore.  Most callback functions add this function
+   as a background processing procedure the current application (by
+   XtAppAddWorkProc) via the function hide_cursor.  */
+Boolean
+show_cursor (XtPointer client_data)
+{
+  MFaceHLineProp *hline;
+  MFaceBoxProp *box;
+
+  if (cur.y0 < 0)
+    {
+      reseat (cur.from);
+      update_cursor (cursor.from, 1);
+    }
+  while (cur.y1 > win_height)
+    {
+      reseat (top.to);
+      update_cursor (cursor.from, 1);
+    }
+
+  control.cursor_pos = cursor.from;
+  if (! SELECTEDP ())
+    {
+      control.with_cursor = 1;
+      redraw_cursor (0);
+    }
+  if (current_input_context)
+    set_input_method_spot ();
+
+  if (nchars > 0)
+    {
+      int pos = (SELECTEDP () ? mtext_property_start (selection)
+                : cursor.from > 0 ? cursor.from - 1
+                : cursor.from);
+      MFace *face = mface ();
+      MTextProperty *props[256];
+      int n = mtext_get_properties (mt, pos, Mface, props, 256);
+      int i;
+      char buf[256], *p = buf;
+      MSymbol sym;
+
+      buf[0] = '\0';
+      if (cursor.font)
+       {
+         int size = (int) mfont_get_prop (cursor.font, Msize);
+         MSymbol family = mfont_get_prop (cursor.font, Mfamily);
+         MSymbol weight = mfont_get_prop (cursor.font, Mweight);
+         MSymbol style = mfont_get_prop (cursor.font, Mstyle);
+         MSymbol registry = mfont_get_prop (cursor.font, Mregistry);
+
+         sprintf (p, "%dpt", size / 10), p += strlen (p);
+         if (family)
+           strcat (p, ","), strcat (p, msymbol_name (family)), p += strlen (p);
+         if (weight)
+           strcat (p, ","), strcat (p, msymbol_name (weight)), p += strlen (p);
+         if (style)
+           strcat (p, ","), strcat (p, msymbol_name (style)), p += strlen (p);
+         if (registry)
+           strcat (p, ","), strcat (p, msymbol_name (registry)), p += strlen (p);
+         p += strlen (p);
+       }
+
+      mface_merge (face, face_default);
+      for (i = 0; i < n; i++)
+       if (props[i] != selection)
+         mface_merge (face, (MFace *) mtext_property_value (props[i]));
+      sym = (MSymbol) mface_get_prop (face, Mforeground);
+      if (sym != Mnil)
+       strcat (p, ","), strcat (p, msymbol_name (sym)), p += strlen (p);
+      if ((MSymbol) mface_get_prop (face, Mvideomode) == Mreverse)
+       strcat (p, ",rev"), p += strlen (p);
+      hline = mface_get_prop (face, Mhline);
+      if (hline && hline->width > 0)
+       strcat (p, ",ul"), p += strlen (p);
+      box = mface_get_prop (face, Mbox);
+      if (box && box->width > 0)
+       strcat (p, ",box"), p += strlen (p);
+      m17n_object_unref (face);
+
+      XtSetArg (arg[0], XtNborderWidth, 1);
+      XtSetArg (arg[1], XtNlabel, buf);
+      XtSetValues (CurFaceWidget, arg, 2);
+    }
+
+  if (control.cursor_pos < nchars)
+    {
+      MSymbol sym = mtext_get_prop (mt, control.cursor_pos, Mlanguage);
+
+      if (sym == Mnil)
+       {
+         XtSetArg (arg[0], XtNborderWidth, 0);
+         XtSetArg (arg[1], XtNlabel, "");
+       }
+      else
+       {
+         XtSetArg (arg[0], XtNborderWidth, 1);
+         sym = mlanguage_name (sym);
+         XtSetArg (arg[1], XtNlabel, msymbol_name (sym));
+         XtSetValues (CurLangWidget, arg, 2);
+       }
+      XtSetValues (CurLangWidget, arg, 2);
+
+      if (auto_input_method)
+       {
+         if (sym == Mnil)
+           select_input_method (-1);
+         else
+           {
+             int i;
+
+             for (i = 0; i < num_input_methods; i++)
+               if (input_method_table[i].language == sym
+                   && input_method_table[i].available >= 0)
+                 break;
+             if (i < num_input_methods)
+               select_input_method (i);
+             else
+               select_input_method (-1);
+           }
+       }
+    }
+
+  MenuHelpProc (MessageWidget, NULL, NULL, NULL);
+
+  return True;
+}
+
+
+/* Hide the cursor.  */
+void
+hide_cursor ()
+{
+  control.with_cursor = 0;
+  redraw_cursor (1);
+  XtAppAddWorkProc (context, show_cursor, NULL);
+}
+
+
+/* Update the window area between the Y-positions $Y0 and $OLD_Y1 to
+   $Y1 and $NEW_Y1 assuming that the text in the other area is not
+   changed.  */
+void
+update_region (int y0, int old_y1, int new_y1)
+{
+  if (y0 < 0)
+    y0 = 0;
+  if (new_y1 < old_y1)
+    {
+      if (old_y1 < win_height)
+       {
+         COPY_AREA (old_y1, win_height, new_y1);
+         redraw (win_height - (old_y1 - new_y1), win_height, 1, 0);
+       }
+      else
+       redraw (new_y1, win_height, 1, 0);
+    }
+  else if (new_y1 > old_y1)
+    {
+      if (new_y1 < win_height)
+       COPY_AREA (old_y1, win_height, new_y1);
+    }
+  if (new_y1 > win_height)
+    new_y1 = win_height;
+  redraw (y0, new_y1, 1, 1);
+}
+
+
+/* Delete the next $N characters.  If $N is negative delete the
+   precious (- $N) characters.  */
+void
+delete_char (int n)
+{
+  MDrawMetric rect;
+  MDrawGlyphInfo info;
+  int y0, old_y1, new_y1;
+  int from, to;
+  int line_from = cursor.line_from;
+
+  if (n > 0)
+    from = cursor.from, to = from + n;
+  else
+    {
+      from = cursor.from + n;
+      to = cursor.from;
+      if (cursor.from == cur.from)
+       {
+         /* We are at the beginning of line.  */
+         int pos = cursor.prev_from;
+         
+         if (cursor.from == top.from)
+           {
+             /* We are at the beginning of screen.  We must scroll
+                down.  */
+             GLYPH_INFO (bol (top.from - 1, 0), top.from - 1, info);
+             reseat (info.line_from);
+           }
+         update_cursor (pos, 1);
+       }
+    }
+
+  TEXT_EXTENTS (cur.from, bol (to + 1, 1), rect);
+  old_y1 = cur.y0 + rect.height;
+
+  /* Now delete a character.  */
+  mtext_del (mt, from, to);
+  nchars -= to - from;
+  if (from >= top.from && from < top.to)
+    update_top (top.from);
+  update_cursor (from, 1);
+
+  y0 = cur.y0;
+  if (line_from != cursor.line_from)
+    y0 -= 1;
+
+  TEXT_EXTENTS (cur.from, bol (to, 1), rect);
+  new_y1 = cur.y0 + rect.height;
+
+  update_region (cur.y0, old_y1, new_y1);
+}
+
+
+/* Insert M-text $NEWTEXT at the current cursor position.  */
+void
+insert_chars (MText *newtext)
+{
+  int n = mtext_len (newtext);
+  MDrawMetric rect;
+  int y0, old_y1, new_y1;
+  int line_from;
+
+  if (SELECTEDP ())
+    {
+      int n = (mtext_property_end (selection)
+              - mtext_property_start (selection));
+      mtext_detach_property (selection);
+      delete_char (n);
+    }
+
+  y0 = cur.y0;
+  if (cursor.line_from > 0
+      && mtext_ref_char (mt, cursor.line_from - 1) != '\n')
+    y0 -= control.min_line_descent;
+
+  TEXT_EXTENTS (cur.from, bol (cur.to - 1, 1), rect);
+  old_y1 = y0 + rect.height;
+
+  line_from = cursor.line_from;
+
+  /* Now insert chars.  */
+  mtext_ins (mt, cursor.from, newtext);
+  nchars += n;
+  if (cur.from == top.from)
+    update_top (top.from);
+  update_cursor (cursor.from + n, 1);
+
+  TEXT_EXTENTS (cur.from, bol (cur.to - 1, 1), rect);
+  new_y1 = cur.y0 + rect.height;
+
+  update_region (y0, old_y1, new_y1);
+  update_selection ();
+}
+
+
+int
+word_constituent_p (int c)
+{
+  MSymbol category = (MSymbol) mchar_get_prop (c, Mcategory);
+  char *name = category != Mnil ? msymbol_name (category) : NULL;
+
+  return (name && (name[0] == 'L' || name[0] == 'M'));
+}
+
+
+void
+forward_word ()
+{
+  int pos = cursor.from;
+
+  while (pos < nchars && ! word_constituent_p (mtext_ref_char (mt, pos)))
+    pos++;
+  if (pos < nchars)
+    {
+      MTextProperty *prop = mtext_get_property (mt, pos, Mword);
+
+      if (prop)
+       pos = mtext_property_end (prop);
+      else
+       while (pos < nchars && word_constituent_p (mtext_ref_char (mt, pos)))
+         pos++;
+    }
+  update_cursor (pos, 0);
+}
+
+void
+backward_word ()
+{
+  int pos = cursor.from;
+
+  while (pos > 0 && ! word_constituent_p (mtext_ref_char (mt, pos - 1)))
+    pos--;
+  if (pos > 0)
+    {
+      MTextProperty *prop = mtext_get_property (mt, pos - 1, Mword);
+
+      if (prop)
+       pos = mtext_property_start (prop);
+      else
+       while (pos > 0 && word_constituent_p (mtext_ref_char (mt, pos - 1)))
+         pos--;
+    }
+  update_cursor (pos, 0);
+}
+
+
+/* Convert the currently selected text to UTF8-STRING or
+   COMPOUND-TEXT.  It is called when someone requests the current
+   value of the selection.  */
+Boolean
+covert_selection (Widget w, Atom *selection_atom,
+                 Atom *target, Atom *return_type,
+                 XtPointer *value, unsigned long *length, int *format)
+{
+  unsigned char *buf = (unsigned char *) XtMalloc (4096);
+  MText *this_mt = mtext ();
+  int from = mtext_property_start (selection);
+  int to = mtext_property_end (selection);
+  MSymbol coding;
+  int len;
+
+  mtext_copy (this_mt, 0, mt, from, to);
+  if (*target == XA_TEXT)
+    {
+#ifdef X_HAVE_UTF8_STRING
+      coding = Mcoding_utf_8;
+      *return_type = XA_UTF8_STRING;
+#else
+      coding = Mcoding_compound_text;
+      *return_type = XA_COMPOUND_TEXT;
+#endif
+    }
+  else if (*target == XA_UTF8_STRING)
+    {
+      coding = Mcoding_utf_8;
+      *return_type = XA_UTF8_STRING;
+    }
+  else if (*target == XA_STRING)
+    {
+      int i;
+
+      len = to - from;
+      for (i = 0; i < len; i++)
+       if (mtext_ref_char (this_mt, i) >= 0x100)
+         /* Can't encode in XA_STRING */
+         return False;
+      coding = Mcoding_iso_8859_1;
+      *return_type = XA_STRING;
+    }
+  else if (*target == XA_COMPOUND_TEXT)
+    {
+      coding = Mcoding_compound_text;
+      *return_type = XA_COMPOUND_TEXT;
+    }
+  else
+    return False;
+
+  len = mconv_encode_buffer (coding, this_mt, buf, 4096);
+  m17n_object_unref (this_mt);
+  if (len < 0)
+    return False;
+  *length = len;
+  *value = (XtPointer) buf;
+  *format = 8;
+  return True;
+}
+
+
+/* Unselect the text.  It is called when we loose the selection.  */
+void
+lose_selection (Widget w, Atom *selection_atom)
+{
+  if (SELECTEDP ())
+    {
+      mtext_detach_property (selection);
+      redraw (sel_start.y0, sel_end.y1, 1, 0);
+    }
+}
+
+void
+get_selection (Widget w, XtPointer cliend_data, Atom *selection,  Atom *type,
+              XtPointer value, unsigned long *length, int *format)
+{
+  MText *this_mt;
+  MSymbol coding;
+
+  if (*type == XT_CONVERT_FAIL || ! value)
+    goto err;
+  if (*type == XA_STRING)
+    coding = Mnil;
+  else if (*type == XA_COMPOUND_TEXT)
+    coding = msymbol ("compound-text");
+#ifdef X_HAVE_UTF8_STRING
+  else if (*type == XA_UTF8_STRING)
+    coding = msymbol ("utf-8");
+#endif
+  else
+    goto err;
+
+  this_mt = mconv_decode_buffer (coding, (unsigned char *) value, *length);
+  if (! this_mt && *type != XA_UTF8_STRING)
+    {
+      XtGetSelectionValue (w, XA_PRIMARY, XA_UTF8_STRING, get_selection, NULL,
+                          CurrentTime);
+      goto err;
+    }
+  if (this_mt)
+    {
+      hide_cursor ();
+      insert_chars (this_mt);
+      m17n_object_unref (this_mt);
+    }
+
+ err:
+  if (value)
+    XtFree (value);
+}
+
+static void
+ExposeProc (Widget w, XEvent *event, String *str, Cardinal *num)
+{
+  XExposeEvent *expose = (XExposeEvent *) event;
+
+  if (top.from < 0)
+    {
+      Dimension width_max, width;
+
+      XtSetArg (arg[0], XtNwidth, &width);
+      XtGetValues (XtParent (w), arg, 1);
+      width_max = width;
+      XtGetValues (HeadWidget, arg, 1);
+      if (width_max < width)
+       width_max = width;
+      XtGetValues (FaceWidget, arg, 1);
+      if (width_max < width)
+       width_max = width;
+      XtGetValues (LangWidget, arg, 1);
+      if (width_max < width)
+       width_max = width;
+      XtSetArg (arg[0], XtNwidth, width_max);
+      XtSetValues (HeadWidget, arg, 1);
+      XtSetValues (FaceWidget, arg, 1);
+      XtSetValues (LangWidget, arg, 1);
+      XtSetValues (XtParent (w), arg, 1);
+      XtSetValues (TailWidget, arg, 1);
+
+      update_top (0);
+      update_cursor (0, 1);
+      redraw (0, win_height, 0, 1);
+      if (current_input_method >= 0)
+       {
+         int idx = current_input_method;
+
+         current_input_method = -1;
+         select_input_method (idx);
+       }
+      show_cursor (NULL);
+    }
+  else
+    {
+      redraw (expose->y, expose->y + expose->height, 0, 0);
+      if (current_input_context
+         && expose->y < cur.y0 && expose->y + expose->height < cur.y1)
+       set_input_method_spot ();
+    }
+}
+
+static void
+ConfigureProc (Widget w, XEvent *event, String *str, Cardinal *num)
+{
+  XConfigureEvent *configure = (XConfigureEvent *) event;
+  
+  hide_cursor ();
+  control.max_line_width = win_width = configure->width;
+  win_height = configure->height;
+  mdraw_clear_cache (mt);
+  update_top (0);
+  update_cursor (0, 1);
+  redraw (0, win_height, 1, 1);
+  if (current_input_context)
+    set_input_method_spot ();
+}
+
+static void
+ButtonProc (Widget w, XEvent *event, String *str, Cardinal *num)
+{
+  int pos;
+  int x = event->xbutton.x;
+  int y = event->xbutton.y - top.ascent;
+
+  if (control.orientation_reversed)
+    x -= win_width;
+  pos = COORDINATES_POSITION (top.from, nchars + 1, x, y);
+  if (SELECTEDP ())
+    {
+      XtDisownSelection (w, XA_PRIMARY, CurrentTime);
+      mtext_detach_property (selection);
+      redraw (sel_start.y0, sel_end.y1, 1, 0);
+    }
+  hide_cursor ();
+  if (current_input_context
+      && minput_filter (current_input_context, Minput_focus_move, NULL) == 0)
+    {
+      MText *produced = mtext ();
+
+      minput_lookup (current_input_context, Mnil, NULL, produced);
+      if (mtext_len (produced) > 0)
+       {
+         insert_chars (produced);
+         if (pos >= cursor.from)
+           pos += mtext_len (produced);
+       }
+      m17n_object_unref (produced);
+    }
+  update_cursor (pos, 0);
+}
+
+
+static void
+ButtonReleaseProc (Widget w, XEvent *event, String *str, Cardinal *num)
+{
+  if (! SELECTEDP ())
+    return;
+
+  XtOwnSelection (w, XA_PRIMARY, CurrentTime,
+                 covert_selection, lose_selection, NULL);
+  update_cursor (mtext_property_start (selection), 0);
+}
+
+static
+void
+Button2Proc (Widget w, XEvent *event, String *str, Cardinal *num)
+{
+  if (! SELECTEDP ())
+    {
+      /* We don't have a local selection.  */
+      XtGetSelectionValue (w, XA_PRIMARY, XA_TEXT, get_selection, NULL,
+                          CurrentTime);
+    }
+  else
+    {
+      int from = mtext_property_start (selection);
+      int to = mtext_property_end (selection);
+      MText *this_mt;
+      int pos;
+      int x = event->xbutton.x;
+      int y = event->xbutton.y - top.ascent;
+
+      if (control.orientation_reversed)
+       x -= win_width;
+      pos = COORDINATES_POSITION (top.from, nchars + 1, x, y);
+      
+      XtDisownSelection (w, XA_PRIMARY, CurrentTime);
+      mtext_detach_property (selection);
+      hide_cursor ();
+      this_mt = mtext_copy (mtext (), 0, mt, from, to);
+      update_cursor (pos, 0);
+      insert_chars (this_mt);
+      m17n_object_unref (this_mt);
+    }
+}
+
+static void
+ButtonMoveProc (Widget w, XEvent *event, String *str, Cardinal *num)
+{
+  int pos;
+  int x = event->xbutton.x;
+  int y = event->xbutton.y;
+
+  if (control.orientation_reversed)
+    x -= win_width;
+  if (y < cur.y0)
+    pos = top.from, y -= top.ascent;
+  else
+    pos = cur.from, y -= cur.y0 + cur.ascent;
+  pos = COORDINATES_POSITION (pos, nchars + 1, x, y);
+
+  if (pos == cursor.from)
+    return;
+
+  hide_cursor ();
+  if (SELECTEDP ())
+    {
+      /* Selection range changed.  */
+      int from = mtext_property_start (selection);
+      int to = mtext_property_end (selection);
+      int start_y0 = sel_start.y0, start_y1 = sel_start.y1;
+      int end_y0 = sel_end.y0, end_y1 = sel_end.y1;
+
+      if (cursor.from == from)
+       {
+         /* Starting position changed.  */
+         if (pos <= from)
+           {
+             /* Enlarged.  We can simply overdraw.  */
+             select_region (pos, to);
+             redraw (sel_start.y0, start_y1, 0, 0);
+           }
+         else if (pos < to)
+           {
+             /* Shrunken.  Previous selection face must be cleared.  */
+             select_region (pos, to);
+             redraw (start_y0, sel_start.y1, 1, 0);
+           }
+         else if (pos == to)
+           {
+             /* Shrunken to zero.  */
+             XtDisownSelection (w, XA_PRIMARY, CurrentTime);
+             mtext_detach_property (selection);
+             redraw (start_y0, end_y1, 1, 0);
+           }
+         else
+           {
+             /* Full update is necessary.  */
+             select_region (to, pos);
+             redraw (start_y0, sel_end.y1, 1, 0);
+           }
+       }
+      else
+       {
+         /* Ending position changed.  */
+         if (pos < from)
+           {
+             /* Full update is necessary.  */
+             select_region (pos, from);
+             redraw (sel_start.y0, end_y1, 1, 0);
+           }
+         else if (pos == from)
+           {
+             /* Shrunken to zero.  */
+             XtDisownSelection (w, XA_PRIMARY, CurrentTime);
+             mtext_detach_property (selection);
+             redraw (start_y0, end_y1, 1, 0);
+           }
+         else if (pos < to)
+           {
+             /* Shrunken.  Previous selection face must be cleared.  */
+             select_region (from, pos);
+             redraw (sel_end.y0, end_y1, 1, 0);
+           }
+         else
+           {
+             /* Enlarged.  We can simply overdraw.  */
+             select_region (from, pos);
+             redraw (end_y0, sel_end.y1, 0, 0);
+           }
+       }
+    }
+  else
+    {
+      /* Newly selected.  */
+      select_region (pos, cursor.from);
+      redraw (sel_start.y0, sel_end.y1, 0, 0);
+    }
+  update_cursor (pos, 1);
+}
+
+void
+FocusInProc (Widget w, XEvent *event, String *str, Cardinal *num)
+{
+  if (current_input_context
+      && minput_filter (current_input_context, Minput_focus_in, NULL) == 0)
+    {
+      MText *produced = mtext ();
+
+      minput_lookup (current_input_context, Mnil, NULL, produced);
+      if (mtext_len (produced) > 0)
+       {
+         hide_cursor ();
+         insert_chars (produced);
+       }
+      m17n_object_unref (produced);
+    }
+}
+
+void
+FocusOutProc (Widget w, XEvent *event, String *str, Cardinal *num)
+{
+  if (current_input_context
+      && minput_filter (current_input_context, Minput_focus_out, NULL) == 0)
+    {
+      MText *produced = mtext ();
+
+      minput_lookup (current_input_context, Mnil, NULL, produced);
+      if (mtext_len (produced) > 0)
+       {
+         hide_cursor ();
+         insert_chars (produced);
+       }
+      m17n_object_unref (produced);
+    }
+}
+
+void
+ScrollProc (Widget w, XtPointer client_data, XtPointer position)
+{
+  int from;
+  MDrawGlyphInfo info;
+  int height;
+  int cursor_pos = cursor.from;
+
+  if (((int) position) < 0)
+    {
+      /* Scroll down.  */
+      int pos;
+
+      from = top.from;
+      height = top.y1 - top.y0;
+      while (from > 0)
+       {
+         pos = bol (from - 1, 0);
+         GLYPH_INFO (pos, from - 1, info);
+         if (height + info.metrics.height > win_height)
+           break;
+         height += info.metrics.height;
+         from = info.line_from;
+       }
+      if (cursor_pos >= top.to)
+       {
+         cursor_pos = top.from;
+         pos = top.to;
+         while (cursor_pos < nchars)
+           {
+             GLYPH_INFO (pos, pos, info);
+             if (height + info.metrics.height > win_height)
+               break;
+             height += info.metrics.height;
+             cursor_pos = pos;
+             pos = info.line_to;
+           }
+       }
+    }
+  else if (cur.to < nchars)
+    {
+      /* Scroll up, but leave at least one line.  */
+      from = cur.to;
+      height = cur.y1;
+      while (from < nchars)
+       {
+         GLYPH_INFO (from, from, info);
+         if (height + info.metrics.height > win_height
+             || info.line_to >= nchars)
+           break;
+         height += info.metrics.height;
+         from = info.line_to;
+       }
+      if (from == nchars)
+       from = info.line_from;
+      if (cursor_pos < from)
+       cursor_pos = from;
+    }
+  else
+    /* Scroll up to make the cursor line top.  */
+    from = cur.from;
+  hide_cursor ();
+  reseat (from);
+  update_cursor (cursor_pos, 1);
+}
+
+void
+JumpProc (Widget w, XtPointer client_data, XtPointer persent_ptr)
+{
+  float persent = *(float *) persent_ptr;
+  int pos1, pos2 = nchars * persent;
+  MDrawGlyphInfo info;
+
+  hide_cursor ();
+  pos1 = bol (pos2, 0);
+  GLYPH_INFO (pos1, pos2, info);
+  pos1 = info.line_from;
+  reseat (pos1);
+  update_cursor (pos1, 1);
+}
+
+static void InputMethodProc (Widget, XtPointer, XtPointer);
+
+static void
+KeyProc (Widget w, XEvent *event, String *str, Cardinal *num)
+{
+  XKeyEvent *key_event = (XKeyEvent *) event;
+  char buf[512];
+  KeySym keysym = NoSymbol;
+  int ret;
+  /* If set to 1, do not update target_x_position.  */
+  int keep_target_x_position = 0;
+  MText *produced;
+  int y0, old_y1, new_y1;
+
+  hide_cursor ();
+
+  mt_modified = 0;
+  y0 = cur.y0;
+  old_y1 = cur.y1;
+  if (current_input_context
+      && minput_filter (current_input_context, Mnil, event))
+    {
+      if (mt_modified)
+       {
+         new_y1 = cur.y1;
+         update_region (y0, old_y1, new_y1);
+       }
+      return;
+    }
+  if (event->type == KeyRelease)
+    return;
+
+  produced = mtext ();
+  ret = minput_lookup (current_input_context, Mnil, event, produced);
+  if (mtext_len (produced) > 0)
+    insert_chars (produced);
+  if (ret)
+    ret = XLookupString (key_event, buf, sizeof (buf), &keysym, NULL);
+  m17n_object_unref (produced);
+
+  if (saved_input_method > -3)
+    {
+      InputMethodProc (w, (XtPointer) saved_input_method, NULL);
+      saved_input_method = -3;
+    }
+
+  switch (keysym)
+    {
+    case XK_Delete:
+      {
+       int n = 0;
+
+       if (SELECTEDP ())
+         {
+           n = (mtext_property_end (selection)
+                - mtext_property_start (selection));
+           mtext_detach_property (selection);
+         }
+       else if (cursor.from < nchars)
+         {
+           /* Delete the following grapheme cluster.  */
+           n = cursor.to - cursor.from;
+         }
+       if (n != 0)
+         delete_char (n);
+      }
+      break;
+
+    case XK_BackSpace:
+      {
+       int n = 0;
+
+       if (SELECTEDP ())
+         {
+           /* Delete selected region.  */
+           n = (mtext_property_end (selection)
+                - mtext_property_start (selection));
+           mtext_detach_property (selection);
+         }
+       else if (cursor.from > 0)
+         {
+           /* Delete the preceding character.  */
+           n = -1;
+         }
+       if (n != 0)
+         delete_char (n);
+      }
+      break;
+
+    case XK_Left:
+      if (SELECTEDP ())
+       {
+         mtext_detach_property (selection);
+         redraw (sel_start.y0, sel_end.y1, 1, 0);;
+       }
+      if (logical_move)
+       {
+         if (cursor.prev_from >= 0)
+           update_cursor (cursor.prev_from, 0);
+       }
+      else
+       {
+         if (cursor.left_from >= 0)
+           update_cursor (cursor.left_from, 0);
+       }
+      break;
+
+    case XK_Right:
+      if (SELECTEDP ())
+       {
+         mtext_detach_property (selection);
+         redraw (sel_start.y0, sel_end.y1, 1, 0);;
+       }
+      if (logical_move)
+       {
+         if (cursor.next_to >= 0)
+           update_cursor (cursor.to, 0);
+       }
+      else
+       {
+         if (cursor.right_from >= 0)
+           update_cursor (cursor.right_from, 0);
+       }
+      break;
+
+    case XK_Down:
+      if (SELECTEDP ())
+       {
+         mtext_detach_property (selection);
+         redraw (sel_start.y0, sel_end.y1, 1, 0);;
+       }
+      if (cur.to <= nchars)
+       {
+         MDrawGlyphInfo info;
+         int pos;
+
+         GLYPH_INFO (cur.from, cur.to, info);
+         pos = COORDINATES_POSITION (cur.from, nchars + 1,
+                                     target_x_position, info.y);
+         keep_target_x_position = 1;
+         update_cursor (pos, 0);
+       }
+      break;
+
+    case XK_Up:
+      if (SELECTEDP ())
+       {
+         mtext_detach_property (selection);
+         redraw (sel_start.y0, sel_end.y1, 1, 0);;
+       }
+      if (cur.from > 0)
+       {
+         MDrawMetric rect;
+         int y;
+         int pos = bol (cur.from - 1, 0);
+
+         TEXT_EXTENTS (pos, cur.from - 1, rect);
+         y = rect.height + rect.y - 1;
+         pos = COORDINATES_POSITION (pos, nchars,
+                                     target_x_position, y);
+         keep_target_x_position = 1;
+         update_cursor (pos, 0);
+       }
+      break;
+
+    case XK_Page_Down:
+      if (SELECTEDP ())
+       {
+         mtext_detach_property (selection);
+         redraw (sel_start.y0, sel_end.y1, 1, 0);;
+       }
+      if (top.from < nchars)
+       ScrollProc (w, NULL, (XtPointer) 1);
+      break;
+
+    case XK_Page_Up:
+      if (SELECTEDP ())
+       {
+         mtext_detach_property (selection);
+         redraw (sel_start.y0, sel_end.y1, 1, 0);;
+       }
+      if (top.from > 0)
+       ScrollProc (w, NULL, (XtPointer) -1);
+      break;
+
+    case XK_b:
+      if (key_event->state >= Mod1Mask)
+       {
+         lose_selection (NULL, NULL);
+         backward_word ();
+         break;
+       }
+
+    case XK_f:
+      if (key_event->state >= Mod1Mask)
+       {
+         lose_selection (NULL, NULL);
+         forward_word ();
+         break;
+       }
+
+    default:
+      if (ret > 0)
+       {
+         if (buf[0] == 17) /* C-q */
+           {
+             XtAppSetExitFlag (context);
+             return;
+           }
+         else if (buf[0] == 12) /* C-l */
+           {
+             redraw (0, win_height, 1, 1);
+             return;
+           }
+         else if (buf[0] == '='
+                  && (event->xkey.state & ControlMask)
+                  && unicode_input_method >= 0)
+           {
+             saved_input_method = current_input_method;
+             InputMethodProc (w, (XtPointer) unicode_input_method, NULL);
+             minput_filter (current_input_context, msymbol ("C-u"), NULL);
+           }
+         else
+           {
+             MText *temp = mtext ();
+
+             mtext_cat_char (temp, buf[0] == '\r' ? '\n'
+                             : ((unsigned char *) buf)[0]);
+             if (current_input_context)
+               mtext_put_prop (temp, 0, 1, Mlanguage,
+                               current_input_context->im->language);
+             insert_chars (temp);
+             m17n_object_unref (temp);
+           }
+       }
+    }
+
+  if (! keep_target_x_position)
+    target_x_position = cursor.x;
+}
+
+void
+SaveProc (Widget w, XtPointer client_data, XtPointer call_data)
+{
+  char *name = (char *) client_data;
+  FILE *fp;
+  int from = -1, to = 0;
+  
+  if (name)
+    {
+      free (filename);
+      filename = strdup (name);
+    }
+
+  fp = fopen (filename, "w");
+  if (! fp)
+    {
+      fprintf (stderr, "Open for write fail: %s", filename);
+      return;
+    }
+
+  if (SELECTEDP ())
+    {
+      from = mtext_property_start (selection);
+      to = mtext_property_end (selection);
+      mtext_detach_property (selection);
+    }
+
+  mconv_encode_stream (Mcoding_utf_8_full, mt, fp);
+  fclose (fp);
+  if (from >= 0)
+    select_region (from, to);
+}
+
+void
+SerializeProc (Widget w, XtPointer client_data, XtPointer call_data)
+{
+  MText *new;
+
+  hide_cursor ();
+  if (SELECTEDP ())
+    mtext_detach_property (selection);
+  serialized = (int) client_data;
+  if (! serialized)
+    new = mtext_deserialize (mt);
+  else
+    {
+      MPlist *plist = mplist ();
+
+      mplist_push (plist, Mt, Mface);
+      mplist_push (plist, Mt, Mlanguage);
+      new = mtext_serialize (mt, 0, mtext_len (mt), plist);
+      m17n_object_unref (plist);
+    }
+  if (new)
+    {
+      m17n_object_unref (mt);
+      mt = new;
+      serialized = ! serialized;
+      nchars = mtext_len (mt);
+      update_top (0);
+    }
+  update_cursor (0, 1);
+  redraw (0, win_height, 1, 1);
+}
+
+void
+QuitProc (Widget w, XtPointer client_data, XtPointer call_data)
+{
+  XtAppSetExitFlag (context);
+}
+
+MText *
+read_file ()
+{
+  FILE *fp = fopen (filename, "r");
+
+  if (! fp)
+    FATAL_ERROR ("Can't read \"%s\"!\n", filename);
+  mt = mconv_decode_stream (Mcoding_utf_8_full, fp);
+  fclose (fp);
+  if (! mt)
+    FATAL_ERROR ("Can't decode \"%s\" by UTF-8!\n", filename);
+  return mt;
+}
+
+void
+BidiProc (Widget w, XtPointer client_data, XtPointer call_data)
+{
+  int data = (int) client_data;
+  int i;
+
+  if (data == 0)
+    {
+      control.enable_bidi = 0;
+      control.orientation_reversed = 0;
+    }
+  else
+    {
+      control.enable_bidi = 1;
+      control.orientation_reversed = data == 2;
+    }
+  for (i = 0; i < 3; i++)
+    {
+      if (i == data)
+       XtSetArg (arg[0], XtNleftBitmap, CheckPixmap);
+      else
+       XtSetArg (arg[0], XtNleftBitmap, None);
+      XtSetValues (BidiMenus[i], arg, 1);
+    }
+
+  update_cursor (cursor.from, 1);
+  redraw (0, win_height, 1, 0);
+}
+
+void
+LineBreakProc (Widget w, XtPointer client_data, XtPointer call_data)
+{
+  int data = (int) client_data;
+  int i;
+
+  if (data == 0)
+    control.max_line_width = 0;
+  else
+    {
+      control.max_line_width = win_width;
+      control.line_break = (data == 1 ? NULL : mdraw_default_line_break);
+    }
+  for (i = 0; i < 3; i++)
+    {
+      if (i == data)
+       XtSetArg (arg[0], XtNleftBitmap, CheckPixmap);
+      else
+       XtSetArg (arg[0], XtNleftBitmap, None);
+      XtSetValues (LineBreakMenus[i], arg, 1);
+    }
+
+  update_cursor (cursor.from, 1);
+  redraw (0, win_height, 1, 0);
+}
+
+void
+FilterProc (Widget w, XtPointer client_data, XtPointer call_data)
+{
+  char *filter_module = (char *) client_data;
+  void *handle;
+  void (*func) (MText *, int, int);
+
+  if (! SELECTEDP ())
+    return;
+  handle = dlopen (filter_module, RTLD_NOW);
+  if (! handle)
+    return;
+  func = (void (*) (MText *, int, int)) dlsym (handle, "filter");
+  if (func)
+    (*func) (mt, mtext_property_start (selection),
+            mtext_property_end (selection));
+  dlclose (handle);
+}
+
+void
+CursorProc (Widget w, XtPointer client_data, XtPointer call_data)
+{
+  int data = (int) client_data;
+  int i, from, to;
+
+  switch (data)
+    {
+    case 0:
+      logical_move = 1;
+      from = 0, to = 2;
+      break;
+    case 1:
+      logical_move = 0;
+      from = 0, to = 2;
+      break;
+    case 2:
+      control.cursor_bidi = 0, control.cursor_width = -1;
+      from = 2, to = 5;
+      break;
+    case 3:
+      control.cursor_bidi = 0, control.cursor_width = 2;
+      from = 2, to = 5;
+      break;
+    default:
+      control.cursor_bidi = 1;
+      from = 2, to = 5;
+      break;
+    }
+
+  for (i = from; i < to; i++)
+    {
+      if (i == data)
+       XtSetArg (arg[0], XtNleftBitmap, CheckPixmap);
+      else
+       XtSetArg (arg[0], XtNleftBitmap, None);
+      XtSetValues (CursorMenus[i], arg, 1);
+    }
+
+  update_cursor (cursor.from, 0);
+  redraw (0, win_height, 1, 0);
+}
+
+static void
+InputMethodProc (Widget w, XtPointer client_data, XtPointer call_data)
+{
+  int idx = (int) client_data;
+
+  if (idx == -2 ? (! auto_input_method && current_input_method < 0)
+      : idx == -1 ? auto_input_method
+      : idx == current_input_method)
+    return;
+
+  if (auto_input_method)
+    {
+      select_input_method (-1);
+      XtSetArg (arg[0], XtNleftBitmap, None);
+      XtSetValues (InputMethodMenus[1], arg, 1);
+      auto_input_method = 0;
+    }
+
+  if (idx == -1)
+    {
+      select_input_method (-1);
+      XtSetArg (arg[0], XtNleftBitmap, None);
+      XtSetValues (InputMethodMenus[0], arg, 1);
+      XtSetArg (arg[0], XtNleftBitmap, CheckPixmap);
+      XtSetValues (InputMethodMenus[1], arg, 1);
+      auto_input_method = 1;
+      hide_cursor ();
+    }
+  else
+    {
+      select_input_method (idx);
+    }
+}
+
+MPlist *default_face_list;
+
+void
+FaceProc (Widget w, XtPointer client_data, XtPointer call_data)
+{
+  int idx = (int) client_data;
+  int from, to;
+  int old_y1;
+
+  hide_cursor ();
+  if (! SELECTEDP ())
+    {
+      MPlist *plist;
+
+      if (idx >= 0)
+       {
+         MFace *face = mframe_get_prop (frame, Mface);
+
+         for (plist = default_face_list; mplist_key (plist) != Mnil;
+              plist = mplist_next (plist)) 
+           mface_merge (face, mplist_value (plist));
+         mplist_add (plist, Mt, *face_table[idx].face);
+         mface_merge (face, *face_table[idx].face);
+       }
+      else if (mplist_key (mplist_next (default_face_list)) != Mnil)
+       {
+         MFace *face = mframe_get_prop (frame, Mface);
+
+         for (plist = default_face_list;
+              mplist_key (mplist_next (plist)) != Mnil;
+              plist = mplist_next (plist)) 
+           mface_merge (face, mplist_value (plist));
+         mplist_pop (plist);
+       }
+      update_top (0);
+      update_cursor (0, 1);
+      redraw (0, win_height, 1, 1);
+      show_cursor (NULL);
+      return;
+    }
+
+  XtAppAddWorkProc (context, show_cursor, NULL);
+  from = mtext_property_start (selection);
+  to = mtext_property_end (selection);
+  old_y1 = sel_end.y1;
+
+  mtext_detach_property (selection);
+  if (idx >= 0)
+    {
+      MTextProperty *prop = mtext_property (Mface, *face_table[idx].face,
+                                           MTEXTPROP_REAR_STICKY);
+      mtext_push_property (mt, from, to, prop);
+      m17n_object_unref (prop);
+    }
+  else
+    mtext_pop_prop (mt, from, to, Mface);
+  if (from < top.to)
+    update_top (top.from);
+  update_cursor (cursor.from, 1);
+  select_region (from, to);
+  update_region (sel_start.y0, old_y1, sel_end.y1);
+  if (cur.y1 > win_height)
+    {
+      while (cur.y1 > win_height)
+       {
+         reseat (top.to);
+         update_cursor (cursor.from, 1);
+       }
+    }
+}
+
+void
+LangProc (Widget w, XtPointer client_data, XtPointer call_data)
+{
+  MSymbol sym = (MSymbol) client_data;
+  int from, to;
+  int old_y1;
+
+  if (! SELECTEDP ())
+    return;
+
+  XtAppAddWorkProc (context, show_cursor, NULL);
+  from = mtext_property_start (selection);
+  to = mtext_property_end (selection);
+  old_y1 = sel_end.y1;
+
+  mtext_detach_property (selection);
+  if (sym != Mnil)
+    mtext_put_prop (mt, from, to, Mlanguage, sym);
+  else
+    mtext_pop_prop (mt, from, to, Mlanguage);
+
+  if (from < top.to)
+    update_top (top.from);
+  update_cursor (cursor.from, 1);
+  select_region (from, to);
+  update_region (sel_start.y0, old_y1, sel_end.y1);
+  if (cur.y1 > win_height)
+    {
+      while (cur.y1 > win_height)
+       {
+         reseat (top.to);
+         update_cursor (cursor.from, 1);
+       }
+    }
+}
+
+void
+DumpImageProc (Widget w, XtPointer client_data, XtPointer call_data)
+{
+  int narrowed = (int) client_data;
+  FILE *mdump;
+  int from, to;
+  MConverter *converter;
+
+  if (narrowed)
+    {
+      if (! SELECTEDP ())
+       return;
+      from = mtext_property_start (selection);
+      to = mtext_property_end (selection);
+    }
+  else
+    {
+      from = 0;
+      to = nchars;
+    }
+
+  if (! narrowed)
+    mdump = popen ("mdump -q -p a4", "w");
+  else
+    mdump = popen ("mdump -q", "w");
+  if (! mdump)
+    return;
+  converter = mconv_stream_converter (Mcoding_utf_8_full, mdump);
+  mconv_encode_range (converter, mt, from, to);
+  mconv_free_converter (converter);
+  fclose (mdump);
+}
+
+void
+input_status (MInputContext *ic, MSymbol command)
+{
+  XFillRectangle (display, input_status_pixmap, gc_inv,
+                 0, 0, input_status_width, input_status_height);
+  if (command == Minput_status_draw)
+    {
+      MDrawMetric rect;
+
+      mtext_put_prop (ic->status, 0, mtext_len (ic->status),
+                     Mface, face_input_status);
+      if (ic->im->language != Mnil)
+       mtext_put_prop (ic->status, 0, mtext_len (ic->status),
+                       Mlanguage, ic->im->language);
+      mdraw_text_extents (frame, ic->status, 0, mtext_len (ic->status),
+                         &input_status_control, NULL, NULL, &rect);
+      mdraw_text_with_control (frame, (MDrawWindow) input_status_pixmap,
+                              input_status_width - rect.width - 2, - rect.y,
+                              ic->status, 0, mtext_len (ic->status),
+                              &input_status_control);
+    }
+  XtSetArg (arg[0], XtNbitmap, input_status_pixmap);
+  XtSetValues (CurIMStatus, arg, 1);
+}
+
+void
+surrounding_text_handler (MInputContext *ic, MSymbol command)
+{
+  if (command == Minput_get_surrounding_text)
+    {
+      int len = (int) mplist_value (ic->plist);
+      int pos;
+      MText *surround;
+
+      if (len < 0)
+       {
+         pos = cursor.from + len;
+         if (pos < 0)
+           pos = 0;
+         surround = mtext_duplicate (mt, pos, cursor.from);
+       }
+      else if (len > 0)
+       {
+         pos = cursor.from + len;
+         if (pos > nchars)
+           pos = nchars;
+         surround = mtext_duplicate (mt, cursor.from, pos);
+       }
+      else
+       surround = mtext ();
+      mplist_set (ic->plist, Mtext, surround);
+      m17n_object_unref (surround);
+    }
+  else if (command == Minput_delete_surrounding_text)
+    {
+      int len = (int) mplist_value (ic->plist);      
+
+      if (len < 0)
+       {
+         if (cursor.from + len < 0)
+           len = - cursor.from;
+         mtext_del (mt, cursor.from + len, cursor.from);
+         nchars += len;
+         update_cursor (cursor.from + len, 1);
+       }
+      else if (len > 0)
+       {
+         if (cursor.from + len > nchars)
+           len = nchars - cursor.from;
+         mtext_del (mt, cursor.from, cursor.from + len);
+         nchars -= len;
+         update_cursor (cursor.from, 1);
+       }
+      if (len)
+       mt_modified = 1;
+    }
+}
+
+int
+compare_input_method (const void *elt1, const void *elt2)
+{
+  const InputMethodInfo *im1 = elt1;
+  const InputMethodInfo *im2 = elt2;
+  MSymbol lang1, lang2;
+
+  if (im1->language == Mnil)
+    return 1;
+  if (im1->language == im2->language)
+    return strcmp (msymbol_name (im1->name), msymbol_name (im2->name));
+  if (im1->language == Mt)
+    return 1;
+  if (im2->language == Mt)
+    return -1;
+  lang1 = mlanguage_name (im1->language);
+  lang2 = mlanguage_name (im2->language);
+  return strcmp (msymbol_name (lang1), msymbol_name (lang2));
+}
+
+void
+setup_input_methods (int with_xim, char *initial_input_method)
+{
+  MPlist *plist = mdatabase_list (msymbol ("input-method"), Mnil, Mnil, Mnil);
+  MPlist *pl;
+  int i;
+  MSymbol Municode = msymbol ("unicode");
+
+  num_input_methods = plist ? mplist_length (plist) : 0;
+  if (with_xim)
+    num_input_methods++;
+  input_method_table = calloc (num_input_methods, sizeof (InputMethodInfo));
+
+  i = 0;
+  if (plist)
+    {
+      for (pl = plist; mplist_key (pl) != Mnil; pl = mplist_next (pl), i++)
+       {
+         MDatabase *mdb = mplist_value (pl);
+         MSymbol *tag = mdatabase_tag (mdb);
+
+         if (tag[2] == Mnil)
+           i--, num_input_methods--;
+         else
+           {
+             input_method_table[i].language = tag[1];
+             input_method_table[i].name = tag[2];
+           }
+       }
+      m17n_object_unref (plist);
+    }
+  if (with_xim)
+    {
+      input_method_table[i].language = Mnil;
+      input_method_table[i].name = msymbol ("xim");
+      i++;
+    }
+
+  qsort (input_method_table, num_input_methods, sizeof input_method_table[0],
+        compare_input_method);
+  for (i = 0; i < num_input_methods; i++)
+    if (input_method_table[i].language == Mt
+       && input_method_table[i].name == Municode)
+      {
+       unicode_input_method = i;
+       break;
+      }
+  mplist_put_func (minput_driver->callback_list, Minput_status_start,
+                  M17N_FUNC (input_status));
+  mplist_put_func (minput_driver->callback_list, Minput_status_draw,
+                  M17N_FUNC (input_status));
+  mplist_put_func (minput_driver->callback_list, Minput_status_done,
+                  M17N_FUNC (input_status));
+  mplist_put_func (minput_driver->callback_list, Minput_get_surrounding_text,
+                  M17N_FUNC (surrounding_text_handler));
+  mplist_put_func (minput_driver->callback_list, Minput_delete_surrounding_text,
+                  M17N_FUNC (surrounding_text_handler));
+
+  current_input_context = NULL;
+  current_input_method = -1;
+
+  if (initial_input_method)
+    {
+      char *lang_name, *method_name;
+      char *p = strchr (initial_input_method, '-');
+
+      if (p && p[1])
+       lang_name = initial_input_method, *p = '\0', method_name = p + 1;
+      else
+       lang_name = "t", method_name = initial_input_method;
+
+      for (i = 0; i < num_input_methods; i++)
+       if ((strcmp (method_name, msymbol_name (input_method_table[i].name))
+            == 0)
+           && (strcmp (lang_name, msymbol_name (input_method_table[i].language)) == 0))
+         {
+           current_input_method = i;
+           break;
+         }
+    }
+}
+
+
+static void
+MenuHelpProc (Widget w, XEvent *event, String *str, Cardinal *num)
+{
+  char *msg;
+
+  if (num && *num > 0)
+    {
+      int bytes = 0, i;
+
+      for (i = 0; i < *num; i++)
+       bytes += strlen (str[i]) + 1;
+      msg = alloca (bytes);
+      strcpy (msg, str[0]);
+      for (i = 1; i < *num; i++)
+       strcat (msg, " "), strcat (msg, str[i]);
+    }
+  else if (cursor.from < nchars)
+    {
+      int c = mtext_ref_char (mt, cursor.from);
+      char *name = mchar_get_prop (c, Mname);
+
+      if (! name)
+       name = "";
+      msg = alloca (10 + strlen (name));
+      sprintf (msg, "U+%04X %s", c, name);
+    }
+  else
+    {
+      msg = "";
+    }
+  XtSetArg (arg[0], XtNlabel, msg);
+  XtSetValues (MessageWidget, arg, 1);
+}
+
+typedef struct
+{
+  int type;
+  char *name1, *name2;
+  XtCallbackProc proc;
+  XtPointer client_data;
+  int status;
+  Widget w;
+} MenuRec;
+
+void PopupProc (Widget w, XtPointer client_data, XtPointer call_data);
+
+void SaveProc (Widget w, XtPointer client_data, XtPointer call_data);
+
+MenuRec FileMenu[] =
+  { { 0, "Open", NULL, PopupProc, FileMenu + 0, -1 },
+    { 0, "Save", NULL, SaveProc, NULL, -1 },
+    { 0, "Save as", NULL, PopupProc, FileMenu + 2, -1 },
+    { 1 },
+    { 0, "Serialize", NULL, SerializeProc, (void *) 1, -1 },
+    { 0, "Deserialize", NULL, SerializeProc, (void *) 0, -1 },
+    { 1 },
+    { 0, "Dump Image Buffer", NULL, DumpImageProc, (void *) 0, -1 },
+    { 0, "Dump Image Region", NULL, DumpImageProc, (void *) 1, -1 },
+    { 1 },
+    { 0, "Quit", NULL, QuitProc, NULL, -1 } };
+
+void
+PopupProc (Widget w, XtPointer client_data, XtPointer call_data)
+{
+  MenuRec *rec = (MenuRec *) client_data;
+  Position x, y;
+
+  XtSetArg (arg[0], XtNvalue, "");
+  XtSetArg (arg[1], XtNlabel, rec->name1);
+  XtSetValues (FileDialogWidget, arg, 2);
+  XtTranslateCoords (w, (Position) 0, (Position) 0, &x, &y);
+  XtSetArg (arg[0], XtNx, x + 20);
+  XtSetArg (arg[1], XtNy, y + 10);
+  XtSetValues (FileShellWidget, arg, 2);
+  XtPopup (FileShellWidget, XtGrabExclusive);
+}
+
+void
+FileDialogProc (Widget w, XtPointer client_data, XtPointer call_data)
+{
+  FILE *fp;
+  char *label;
+
+  XtPopdown (FileShellWidget);
+  if ((int) client_data == 1)
+    return;
+  XtSetArg (arg[0], XtNlabel, &label);
+  XtGetValues (FileDialogWidget, arg, 1);
+  if (strcmp (label, FileMenu[0].name1) == 0)
+    {
+      /* Open a file */
+      free (filename);
+      filename = strdup ((char *) XawDialogGetValueString (FileDialogWidget));
+      fp = fopen (filename, "r");
+      hide_cursor ();
+      m17n_object_unref (mt);
+      if (fp)
+       {
+         mt = mconv_decode_stream (Mcoding_utf_8_full, fp);
+         fclose (fp);
+         if (! mt)
+           mt = mtext ();
+       }
+      else
+       mt = mtext ();
+      serialized = 0;
+      nchars = mtext_len (mt);
+      update_top (0);
+      update_cursor (0, 1);
+      redraw (0, win_height, 1, 1);
+    }
+  else if (strcmp (label, FileMenu[2].name1) == 0)
+    SaveProc (w, (XtPointer) XawDialogGetValueString (FileDialogWidget), NULL);
+  else
+    fprintf (stderr, "Invalid calling sequence: FileDialogProc\n");
+}
+
+#define SetMenu(MENU, TYPE, NAME1, NAME2, PROC, DATA, STATUS)           \
+  ((MENU).type = (TYPE), (MENU).name1 = (NAME1), (MENU).name2 = (NAME2), \
+   (MENU).proc = (PROC), (MENU).client_data = (XtPointer) (DATA),       \
+   (MENU).status = (STATUS))
+
+
+Widget
+create_menu_button (Widget top, Widget parent, Widget left, char *button_name,
+                   char *menu_name, MenuRec *menus, int num_menus, char *help)
+{
+  Widget button, menu;
+  char *fmt = "<EnterWindow>: highlight() MenuHelp(%s)\n\
+              <LeaveWindow>: reset() MenuHelp()\n\
+              <BtnDown>: reset() PopupMenu()\n\
+              <BtnUp>: highlight()"; 
+  int i;
+  MenuRec *m;
+  char *trans;
+  int max_width = 0;
+
+  menu = XtCreatePopupShell (menu_name, simpleMenuWidgetClass, top, NULL, 0);
+  for (i = 0; i < num_menus; i++)
+    {
+      m = menus + i;
+      if (m->type == 0)
+       {
+         if (m->proc)
+           {
+             int n = 0;
+
+             if (m->status >= 0)
+               {
+                 XtSetArg (arg[n], XtNleftMargin, 20), n++;
+                 if (m->status > 0)
+                   XtSetArg (arg[n], XtNleftBitmap, CheckPixmap), n++;
+               }
+             m->w = XtCreateManagedWidget (m->name1, smeBSBObjectClass,
+                                           menu, arg, n);
+             XtAddCallback (m->w, XtNcallback, m->proc, m->client_data);
+           }
+         else
+           {
+             XtSetArg (arg[0], XtNsensitive, False);
+             m->w = XtCreateManagedWidget (m->name1, smeBSBObjectClass,
+                                           menu, arg, 2);
+           }
+       }
+      else
+       {
+         XtCreateManagedWidget (m->name1, smeLineObjectClass, menu, NULL, 0);
+       }
+      if (m->name2)
+       max_width = 1;
+    }
+  trans = alloca (strlen (fmt) + strlen (help));
+  sprintf (trans, fmt, help);
+  XtSetArg (arg[0], XtNmenuName, menu_name);
+  XtSetArg (arg[1], XtNtranslations, XtParseTranslationTable ((String) trans));
+  XtSetArg (arg[2], XtNinternalWidth, 2);
+  XtSetArg (arg[3], XtNhighlightThickness, 1);
+  XtSetArg (arg[4], XtNleft, XawChainLeft);
+  XtSetArg (arg[5], XtNright, XawChainLeft);
+  XtSetArg (arg[6], XtNinternational, True);
+  i = 7;
+  if (left)
+    XtSetArg (arg[i], XtNfromHoriz, left), i++;
+  button = XtCreateManagedWidget (button_name, menuButtonWidgetClass, parent,
+                                 arg, i);
+
+  if (max_width)
+    {
+      int height, ascent, *width = alloca (sizeof (int) * num_menus);
+      int *len = alloca (sizeof (int) * num_menus);
+
+      XFontSet font_set;
+      XFontSetExtents *fontset_extents;
+
+      XtSetArg (arg[0], XtNfontSet, &font_set);
+      XtGetValues (button, arg, 1);
+
+      fontset_extents = XExtentsOfFontSet (font_set);
+      height = fontset_extents->max_logical_extent.height;
+      ascent = - fontset_extents->max_logical_extent.y;
+
+      for (i = 0; i < num_menus; i++)
+       if (menus[i].name2)
+         {
+           len[i] = strlen (menus[i].name2);
+           width[i] = XmbTextEscapement (font_set, menus[i].name2, len[i]);
+           if (max_width < width[i])
+             max_width = width[i];
+         }
+      for (i = 0; i < num_menus; i++)
+       if (menus[i].name2)
+         {
+           Pixmap pixmap = XCreatePixmap (display,
+                                          RootWindow (display, screen),
+                                          max_width, height, 1);
+           XFillRectangle (display, pixmap, mono_gc_inv,
+                           0, 0, max_width, height);
+           XmbDrawString (display, pixmap, font_set, mono_gc,
+                          max_width - width[i], ascent,
+                          menus[i].name2, len[i]);
+           XtSetArg (arg[0], XtNrightBitmap, pixmap);
+           XtSetArg (arg[1], XtNrightMargin, max_width + 20);
+           XtSetValues (menus[i].w, arg, 2);
+         }
+    }
+
+  return button;
+}
+
+
+XtActionsRec actions[] = {
+  {"Expose", ExposeProc},
+  {"Configure", ConfigureProc},
+  {"Key", KeyProc},
+  {"ButtonPress", ButtonProc},
+  {"ButtonRelease", ButtonReleaseProc},
+  {"ButtonMotion", ButtonMoveProc},
+  {"Button2Press", Button2Proc},
+  {"MenuHelp", MenuHelpProc},
+  {"FocusIn", FocusInProc},
+  {"FocusOut", FocusOutProc}
+};
+
+
+/* Print the usage of this program (the name is PROG), and exit with
+   EXIT_CODE.  */
+
+void
+help_exit (char *prog, int exit_code)
+{
+  char *p = prog;
+
+  while (*p)
+    if (*p++ == '/')
+      prog = p;
+
+  printf ("Usage: %s [ XT-OPTION ...] [ OPTION ...] FILE\n", prog);
+  printf ("Display FILE on a window and allow users to edit it.\n");
+  printf ("XT-OPTIONs are standard Xt arguments (e.g. -fn, -fg).\n");
+  printf ("The following OPTIONs are available.\n");
+  printf ("  %-13s\n\t\t%s", "--fontset FONTSET",
+         "Use the specified fontset\n");
+  printf ("  %-13s %s", "-s SIZE", "Font size in 1/10 point (default 120).\n");
+  printf ("  %-13s\n\t\t%s", "--im INPUT-METHOD",
+         "Input method activated initially.\n");
+  printf ("  %-13s %s", "--version", "print version number\n");
+  printf ("  %-13s %s", "-h, --help", "print this message\n");
+         
+  exit (exit_code);
+}
+
+int
+main (int argc, char **argv)
+{
+  Widget form, BodyWidget, w;
+  char *fontset_name = NULL;
+  char *font_name = NULL;
+  int fontsize = 0;
+  char *initial_input_method = NULL;
+  int col = 80, row = 32;
+  /* Translation table for TextWidget.  */
+  String trans = "<Expose>: Expose()\n\
+                 <Configure>: Configure()\n\
+                 <Key>: Key()\n\
+                 <KeyUp>: Key()\n\
+                 <Btn1Down>: ButtonPress()\n\
+                 <Btn1Up>: ButtonRelease()\n\
+                 <Btn1Motion>: ButtonMotion()\n\
+                 <Btn2Down>: Button2Press()";
+  /* Translation table for the top form widget.  */
+  String trans2 = "<Key>: Key()\n\
+                  <KeyUp>: Key()\n\
+                  <FocusIn>: FocusIn()\n\
+                  <FocusOut>: FocusOut()";
+  String pop_face_trans
+    = "<EnterWindow>: MenuHelp(Pop face property) highlight()\n\
+       <LeaveWindow>: MenuHelp() reset()\n\
+       <Btn1Down>: set()\n\
+       <Btn1Up>: notify() unset()"; 
+  String pop_lang_trans
+    = "<EnterWindow>: MenuHelp(Pop language property) highlight()\n\
+       <LeaveWindow>: MenuHelp() reset()\n\
+       <Btn1Down>: set()\n\
+       <Btn1Up>: notify() unset()"; 
+  int font_width, font_ascent, font_descent;
+  int with_xim = 0;
+  int i, j;
+  char *filter = NULL;
+  MFont *font = NULL;
+
+  setlocale (LC_ALL, "");
+  /* Create the top shell.  */
+  XtSetLanguageProc (NULL, NULL, NULL);
+  ShellWidget = XtOpenApplication (&context, "M17NEdit", NULL, 0, &argc, argv,
+                                  NULL, sessionShellWidgetClass, NULL, 0);
+  display = XtDisplay (ShellWidget);
+  screen = XScreenNumberOfScreen (XtScreen (ShellWidget));
+
+  /* Parse the remaining command line arguments.  */
+  for (i = 1; i < argc; i++)
+    {
+      if (! strcmp (argv[i], "--help")
+         || ! strcmp (argv[i], "-h"))
+       help_exit (argv[0], 0);
+      else if (! strcmp (argv[i], "--version"))
+       {
+         printf ("m17n-edit (m17n library) %s\n", M17NLIB_VERSION_NAME);
+         printf ("Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 AIST, JAPAN\n");
+         exit (0);
+       }
+      else if (! strcmp (argv[i], "--geometry"))
+       {
+         i++;
+         if (sscanf (argv[i], "%dx%d", &col, &row) != 2)
+           help_exit (argv[0], 1);
+       }
+      else if (! strcmp (argv[i], "-s"))
+       {
+         i++;
+         fontsize = atoi (argv[i]);
+         if (fontsize < 0)
+           fontsize = 120;
+       }
+      else if (! strcmp (argv[i], "--fontset"))
+       {
+         i++;
+         fontset_name = strdup (argv[i]);
+       }
+      else if (! strcmp (argv[i], "--font"))
+       {
+         i++;
+         font_name = strdup (argv[i]);
+       }
+      else if (! strcmp (argv[i], "--im"))
+       {
+         i++;
+         initial_input_method = strdup (argv[i]);
+       }
+      else if (! strcmp (argv[i], "--with-xim"))
+       {
+         with_xim = 1;
+       }
+      else if (! strcmp (argv[i], "--filter"))
+       {
+         i++;
+         filter = argv[i];
+       }
+      else if (argv[i][0] != '-')
+       {
+         filename = strdup (argv[i]);
+       }
+      else
+       {
+         fprintf (stderr, "Unknown option: %s\n", argv[i]);
+         help_exit (argv[0], 1);
+       }
+    }
+  if (! filename)
+    filename = strdup ("/dev/null");
+
+  mdatabase_dir = ".";
+  /* Initialize the m17n library.  */
+  M17N_INIT ();
+  if (merror_code != MERROR_NONE)
+    FATAL_ERROR ("%s\n", "Fail to initialize the m17n library!");
+  minput_driver = &minput_gui_driver;
+
+  mt = read_file (filename);
+  serialized = 0;
+
+  nchars = mtext_len (mt);
+
+  Mword = msymbol ("word");
+
+  {
+    MFace *face = mface ();
+
+    mface_put_prop (face, Mforeground, msymbol ("blue"));
+    mface_put_prop (face, Mbackground, msymbol ("yellow"));
+    mface_put_prop (face, Mvideomode, Mreverse);
+    selection = mtext_property (Mface, face, MTEXTPROP_NO_MERGE);
+    m17n_object_unref (face);
+  }
+
+  /* This tells ExposeProc to initialize everything.  */
+  top.from = -1;
+  
+  XA_TEXT = XInternAtom (display, "TEXT", False);
+  XA_COMPOUND_TEXT = XInternAtom (display, "COMPOUND_TEXT", False);
+  XA_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
+  Mcoding_compound_text = mconv_resolve_coding (msymbol ("compound-text"));
+  if (Mcoding_compound_text == Mnil)
+    FATAL_ERROR ("%s\n", "Don't know about COMPOUND-TEXT encoding!");
+
+  {
+    MPlist *plist = mplist ();
+    MFont *font;
+
+    mplist_put (plist, msymbol ("widget"), ShellWidget);
+    if (fontset_name || font_name || fontsize > 0)
+      {
+       MFace *face;
+
+       if (font_name)
+         {
+           font = mfont_parse_name (font_name, Mnil);
+           if (font)
+             face = mface_from_font (font);
+           else
+             face = mface ();
+         }
+       else
+         face = mface ();
+       if (fontset_name)
+         {
+           MFontset *fontset = mfontset (fontset_name);
+
+           mface_put_prop (face, Mfontset, fontset);
+           m17n_object_unref (fontset);
+         }
+       if (fontsize > 0)
+         mface_put_prop (face, Msize, (void *) fontsize);
+       mplist_add (plist, Mface, face);
+       m17n_object_unref (face);
+      }
+    frame = mframe (plist);
+    if (! frame)
+      FATAL_ERROR ("%s\n", "Fail to create a frame!");
+    m17n_object_unref (plist);
+    face_default = mface_copy ((MFace *) mframe_get_prop (frame, Mface));
+    default_face_list = mplist ();
+    mplist_add (default_face_list, Mt, face_default);
+    face_default_fontset = mface ();
+    mface_put_prop (face_default_fontset, Mfontset,
+                   mface_get_prop (face_default, Mfontset));
+
+    font = (MFont *) mframe_get_prop (frame, Mfont);
+    default_font_size = (int) mfont_get_prop (font, Msize);
+  }
+
+  font_width = (int) mframe_get_prop (frame, Mfont_width);
+  font_ascent = (int) mframe_get_prop (frame, Mfont_ascent);
+  font_descent = (int) mframe_get_prop (frame, Mfont_descent);
+  win_width = font_width * col;
+  win_height = (font_ascent + font_descent) * row;
+
+  {
+    MFaceBoxProp prop;
+
+    prop.width = 4;
+    prop.color_top = prop.color_left = msymbol ("magenta");
+    prop.color_bottom = prop.color_right = msymbol ("red");
+    prop.inner_hmargin = prop.inner_vmargin = 1;
+    prop.outer_hmargin = prop.outer_vmargin = 2;
+
+    face_box = mface ();
+    mface_put_prop (face_box, Mbox, &prop);
+  }
+
+  face_courier = mface ();
+  mface_put_prop (face_courier, Mfamily, msymbol ("courier"));
+  face_helvetica = mface ();
+  mface_put_prop (face_helvetica, Mfamily, msymbol ("helvetica"));
+  face_times = mface ();
+  mface_put_prop (face_times, Mfamily, msymbol ("times"));
+  face_dv_ttyogesh = mface ();
+  mface_put_prop (face_dv_ttyogesh, Mfamily, msymbol ("dv-ttyogesh"));
+  face_freesans = mface ();
+  mface_put_prop (face_freesans, Mfamily, msymbol ("freesans"));
+  face_freeserif = mface ();
+  mface_put_prop (face_freeserif, Mfamily, msymbol ("freeserif"));
+  face_freemono = mface ();
+  mface_put_prop (face_freemono, Mfamily, msymbol ("freemono"));
+
+  face_xxx_large = mface ();
+  mface_put_prop (face_xxx_large, Mratio, (void *) 300);
+  {
+    MFont *latin_font = mframe_get_prop (frame, Mfont);
+    MFont *dev_font = mfont ();
+    MFont *thai_font = mfont ();
+    MFont *tib_font = mfont ();
+    MFontset *fontset, *fontset_no_ctl;
+    MSymbol unicode_bmp = msymbol ("unicode-bmp");
+    MSymbol no_ctl = msymbol ("no-ctl");
+
+    mfont_put_prop (dev_font, Mfamily, msymbol ("raghindi"));
+    mfont_put_prop (dev_font, Mregistry, unicode_bmp);
+    mfont_put_prop (thai_font, Mfamily, msymbol ("norasi"));
+    mfont_put_prop (thai_font, Mregistry, unicode_bmp);
+    mfont_put_prop (tib_font, Mfamily, msymbol ("mtib"));
+    mfont_put_prop (tib_font, Mregistry, unicode_bmp);
+
+    fontset = mfontset (fontset_name);
+    fontset_no_ctl = mfontset_copy (fontset, "no-ctl");
+    m17n_object_unref (fontset);
+    mfontset_modify_entry (fontset_no_ctl, msymbol ("latin"), Mnil, Mnil,
+                          latin_font, Mnil, 0);
+    mfontset_modify_entry (fontset_no_ctl, msymbol ("devanagari"), Mnil, Mnil,
+                          dev_font, no_ctl, 0);
+    mfontset_modify_entry (fontset_no_ctl, msymbol ("thai"), Mnil, Mnil,
+                          thai_font, no_ctl, 0);
+    mfontset_modify_entry (fontset_no_ctl, msymbol ("tibetan"), Mnil, Mnil,
+                          tib_font, no_ctl, 0);
+    face_no_ctl_fontset = mface ();
+    mface_put_prop (face_no_ctl_fontset, Mfontset, fontset_no_ctl);
+    m17n_object_unref (fontset_no_ctl);
+
+    free (dev_font);
+    free (thai_font);
+    free (tib_font);
+  }
+
+  setup_input_methods (with_xim, initial_input_method);
+
+  gc = DefaultGC (display, screen);
+
+  XtSetArg (arg[0], XtNtranslations, XtParseTranslationTable (trans2));
+  XtSetArg (arg[1], XtNdefaultDistance, 2);
+  form = XtCreateManagedWidget ("form", formWidgetClass, ShellWidget, arg, 2);
+
+  XtSetArg (arg[0], XtNborderWidth, 0);
+  XtSetArg (arg[1], XtNdefaultDistance, 2);
+  XtSetArg (arg[2], XtNtop, XawChainTop);
+  XtSetArg (arg[3], XtNbottom, XawChainTop);
+  XtSetArg (arg[4], XtNleft, XawChainLeft);
+  XtSetArg (arg[5], XtNright, XawChainRight);
+  XtSetArg (arg[6], XtNresizable, True);
+  HeadWidget = XtCreateManagedWidget ("head", formWidgetClass, form, arg, 7);
+  XtSetArg (arg[7], XtNfromVert, HeadWidget);
+  FaceWidget = XtCreateManagedWidget ("face", formWidgetClass, form, arg, 8);
+  XtSetArg (arg[7], XtNfromVert, FaceWidget);
+  LangWidget = XtCreateManagedWidget ("lang", formWidgetClass, form, arg, 8);
+  XtSetArg (arg[3], XtNbottom, XawChainBottom);
+  XtSetArg (arg[7], XtNfromVert, LangWidget);
+  BodyWidget = XtCreateManagedWidget ("body", formWidgetClass, form, arg, 8);
+  XtSetArg (arg[2], XtNtop, XawChainBottom);
+  XtSetArg (arg[7], XtNfromVert, BodyWidget);
+  TailWidget = XtCreateManagedWidget ("tail", formWidgetClass, form, arg, 8);
+
+  FileShellWidget = XtCreatePopupShell ("FileShell", transientShellWidgetClass,
+                                       HeadWidget, NULL, 0);
+  XtSetArg (arg[0], XtNvalue, "");
+  FileDialogWidget = XtCreateManagedWidget ("File", dialogWidgetClass,
+                                           FileShellWidget, arg, 1);
+  XawDialogAddButton (FileDialogWidget, "OK",
+                     FileDialogProc, (XtPointer) 0);
+  XawDialogAddButton (FileDialogWidget, "CANCEL",
+                     FileDialogProc, (XtPointer) 1);
+
+  CheckPixmap = XCreateBitmapFromData (display, RootWindow (display, screen),
+                                      (char *) check_bits,
+                                      check_width, check_height);
+  {
+    unsigned long valuemask = GCForeground;
+    XGCValues values;
+
+    values.foreground = 1;
+    mono_gc = XCreateGC (display, CheckPixmap, valuemask, &values);
+    values.foreground = 0;
+    mono_gc_inv = XCreateGC (display, CheckPixmap, valuemask, &values);
+  }
+
+  {
+    MenuRec *menus;
+    int num_menus = 10;
+
+    if (num_menus < num_input_methods + 2)
+      num_menus = num_input_methods + 2;
+    if (num_menus < num_faces + 1)
+      num_menus = num_faces + 1;
+    menus = alloca (sizeof (MenuRec) * num_menus);
+
+    w = create_menu_button (ShellWidget, HeadWidget, NULL, "File", "File Menu",
+                           FileMenu, sizeof FileMenu / sizeof (MenuRec),
+                           "File I/O, Serialization, Image, Quit");
+
+    SetMenu (menus[0], 0, "Logical Move", NULL, CursorProc, 0, 1);
+    SetMenu (menus[1], 0, "Visual Move", NULL, CursorProc, 1, 0);
+    SetMenu (menus[2], 1, "", NULL, NULL, NULL, 0);
+    SetMenu (menus[3], 0, "Box type", NULL, CursorProc, 2, 0);
+    SetMenu (menus[4], 0, "Bar type", NULL, CursorProc, 3, 1);
+    SetMenu (menus[5], 0, "Bidi type", NULL, CursorProc, 4, 0);
+    w = create_menu_button (ShellWidget, HeadWidget, w,
+                           "Cursor", "Cursor Menu",
+                           menus, 6, "Cursor Movement Mode, Cursor Shape");
+    CursorMenus[0] = menus[0].w;
+    CursorMenus[1] = menus[1].w;
+    CursorMenus[2] = menus[3].w;
+    CursorMenus[3] = menus[4].w;
+    CursorMenus[4] = menus[5].w;
+
+    SetMenu (menus[0], 0, "disable", NULL, BidiProc, 0, 0);
+    SetMenu (menus[1], 0, "Left  (|--> |)", NULL, BidiProc, 1, 1);
+    SetMenu (menus[2], 0, "Right (| <--|)", NULL, BidiProc, 2, 0);
+    w = create_menu_button (ShellWidget, HeadWidget, w, "Bidi", "Bidi Menu",
+                           menus, 3, "BIDI Processing Mode");
+    for (i = 0; i < 3; i++)
+      BidiMenus[i] = menus[i].w;
+
+    SetMenu (menus[0], 0, "truncate", NULL, LineBreakProc, 0, 0);
+    SetMenu (menus[1], 0, "break at edge", NULL, LineBreakProc, 1, 1);
+    SetMenu (menus[2], 0, "break at word boundary", NULL, LineBreakProc, 2, 0);
+    w = create_menu_button (ShellWidget, HeadWidget, w, "LineBreak",
+                           "LineBreak Menu",
+                           menus, 3, "How to break lines");
+    for (i = 0; i < 3; i++)
+      LineBreakMenus[i] = menus[i].w;
+
+    SetMenu (menus[0], 0, "none", NULL, InputMethodProc, -2, 1);
+    SetMenu (menus[1], 0, "auto", NULL, InputMethodProc, -1, 0);
+    for (i = 0; i < num_input_methods; i++)
+      {
+       InputMethodInfo *im = input_method_table + i;
+       char *name1, *name2;
+
+       if (im->language != Mnil && im->language != Mt)
+         {
+           MSymbol sym = mlanguage_name (im->language);
+           if (sym == Mnil)
+             name1 = msymbol_name (im->language);
+           else
+             name1 = msymbol_name (sym);
+           name2 = msymbol_name (im->name);
+         }
+       else
+         name1 = msymbol_name (im->name), name2 = NULL;
+
+       SetMenu (menus[i + 2], 0, name1, name2, InputMethodProc, i, 0);
+      }
+    w = create_menu_button (ShellWidget, HeadWidget, w, "InputMethod",
+                           "Input Method Menu", menus, i + 2,
+                           "Select input method");
+
+    {
+      unsigned long valuemask = GCForeground;
+      XGCValues values;
+
+      XtSetArg (arg[0], XtNbackground, &values.foreground);
+      XtGetValues (w, arg, 1);
+      gc_inv = XCreateGC (display, RootWindow (display, screen),
+                         valuemask, &values);
+    }
+
+    InputMethodMenus = malloc (sizeof (Widget) * (num_input_methods + 2));
+    for (i = 0; i < num_input_methods + 2; i++)
+      InputMethodMenus[i] = menus[i].w;
+
+    if (filter)
+      {
+       SetMenu (menus[0], 0, filter, NULL, FilterProc, filter, 0);
+       w = create_menu_button (ShellWidget, HeadWidget, w, "Filter",
+                               "Filter Menu", menus, 1,
+                               "Select filter to run");
+      }
+
+    input_status_width = font_width * 8;
+    input_status_height = (font_ascent + font_descent) * 2.4;
+    input_status_pixmap = XCreatePixmap (display, RootWindow (display, screen),
+                                        input_status_width,
+                                        input_status_height,
+                                        DefaultDepth (display, screen));
+    {
+      MFaceBoxProp prop;
+
+      prop.width = 1;
+      prop.color_top = prop.color_bottom
+       = prop.color_left = prop.color_right = Mnil;
+      prop.inner_hmargin = prop.inner_vmargin = 1;
+      prop.outer_hmargin = prop.outer_vmargin = 0;
+      face_input_status = mface_copy (face_default);
+      mface_put_prop (face_input_status, Mbox, &prop);
+    }
+
+    XFillRectangle (display, input_status_pixmap, gc_inv,
+                   0, 0, input_status_width, input_status_height);
+    XtSetArg (arg[0], XtNfromHoriz, w);
+    XtSetArg (arg[1], XtNleft, XawRubber);
+    XtSetArg (arg[2], XtNright, XawChainRight);
+    XtSetArg (arg[3], XtNborderWidth, 0);
+    XtSetArg (arg[4], XtNlabel, "          ");
+    XtSetArg (arg[5], XtNjustify, XtJustifyRight);
+    CurIMLang = XtCreateManagedWidget ("CurIMLang", labelWidgetClass,
+                                      HeadWidget, arg, 6);
+    XtSetArg (arg[0], XtNfromHoriz, CurIMLang);
+    XtSetArg (arg[1], XtNleft, XawChainRight);
+    XtSetArg (arg[4], XtNbitmap, input_status_pixmap);
+    CurIMStatus = XtCreateManagedWidget ("CurIMStatus", labelWidgetClass,
+                                        HeadWidget, arg, 5);
+
+    XtSetArg (arg[0], XtNborderWidth, 0);
+    XtSetArg (arg[1], XtNleft, XawChainLeft);
+    XtSetArg (arg[2], XtNright, XawChainLeft);
+    w = XtCreateManagedWidget ("Face", labelWidgetClass, FaceWidget, arg, 3);
+    for (i = 0; i < num_faces;)
+      {
+       char *label_menu = face_table[i++].name; /* "Menu Xxxx" */
+       char *label = label_menu + 5;            /* "Xxxx" */
+
+       for (j = i; j < num_faces && face_table[j].face; j++)
+         SetMenu (menus[j - i], 0, face_table[j].name, NULL,
+                  FaceProc, j, -1);
+       w = create_menu_button (ShellWidget, FaceWidget, w,
+                               label, label_menu,
+                               menus, j - i, "Push face property");
+       i = j;
+      }
+
+    XtSetArg (arg[0], XtNfromHoriz, w);
+    XtSetArg (arg[1], XtNleft, XawChainLeft);
+    XtSetArg (arg[2], XtNright, XawChainLeft);
+    XtSetArg (arg[3], XtNhorizDistance, 10);
+    XtSetArg (arg[4], XtNlabel, "Pop");
+    XtSetArg (arg[5], XtNtranslations,
+             XtParseTranslationTable (pop_face_trans));
+    w = XtCreateManagedWidget ("Pop Face", commandWidgetClass,
+                              FaceWidget, arg, 6);
+    XtAddCallback (w, XtNcallback, FaceProc, (void *) -1);
+
+    XtSetArg (arg[0], XtNfromHoriz, w);
+    XtSetArg (arg[1], XtNleft, XawChainLeft);
+    XtSetArg (arg[2], XtNright, XawChainRight);
+    XtSetArg (arg[3], XtNlabel, "");
+    XtSetArg (arg[4], XtNborderWidth, 0);
+    XtSetArg (arg[5], XtNjustify, XtJustifyRight);
+    CurFaceWidget = XtCreateManagedWidget ("Current Face", labelWidgetClass,
+                                          FaceWidget, arg, 6);
+
+    XtSetArg (arg[0], XtNborderWidth, 0);
+    XtSetArg (arg[1], XtNleft, XawChainLeft);
+    XtSetArg (arg[2], XtNright, XawChainLeft);
+    w = XtCreateManagedWidget ("Lang", labelWidgetClass, LangWidget, arg, 3);
+    {
+      MPlist *plist[11], *pl;
+      char langname[3];
+
+      for (i = 0; i < 11; i++) plist[i] = NULL;
+      langname[2] = '\0';
+      for (langname[0] = 'a'; langname[0] <= 'z'; langname[0]++)
+       for (langname[1] = 'a'; langname[1] <= 'z'; langname[1]++)
+         {
+           MSymbol sym = msymbol_exist (langname);
+           MSymbol fullname;
+
+           if (sym != Mnil
+               && ((fullname = mlanguage_name (sym)) != Mnil))
+             {
+               char *name = msymbol_name (fullname);
+               char c = name[0];
+
+               if (c >= 'a' && c <= 'z')
+                 {
+                   int idx = (c < 'u') ? (c - 'a') / 2 : 10;
+
+                   pl = plist[idx];
+                   if (! pl)
+                     pl = plist[idx] = mplist ();
+                   for (; mplist_next (pl); pl = mplist_next (pl))
+                     if (strcmp (name, (char *) mplist_value (pl)) < 0)
+                       break;
+                   mplist_push (pl, sym, fullname);
+                 }
+             }
+         }
+
+      for (i = 0; i < 11; i++)
+       if (plist[i])
+         {
+           char *name = alloca (9);
+
+           sprintf (name, "Menu %c-%c", 'A' + i * 2, 'A' + i * 2 + 1);
+           if (i == 10)
+             name[7] = 'Z';
+           for (j = 0, pl = plist[i]; mplist_next (pl);
+                j++, pl = mplist_next (pl))
+             SetMenu (menus[j], 0, msymbol_name ((MSymbol) mplist_value (pl)),
+                      msymbol_name (mplist_key (pl)),
+                      LangProc, mplist_key (pl), -1);
+           w = create_menu_button (ShellWidget, LangWidget, w, name + 5, name,
+                                   menus, j, "Push language property");
+         }
+      for (i = 0; i < 11; i++)
+       if (plist[i])
+         m17n_object_unref (plist[i]);
+    }
+    XtSetArg (arg[0], XtNfromHoriz, w);
+    XtSetArg (arg[1], XtNleft, XawChainLeft);
+    XtSetArg (arg[2], XtNright, XawChainLeft);
+    XtSetArg (arg[3], XtNhorizDistance, 10);
+    XtSetArg (arg[4], XtNlabel, "Pop");
+    XtSetArg (arg[5], XtNtranslations,
+             XtParseTranslationTable (pop_lang_trans));
+    w = XtCreateManagedWidget ("Pop Lang", commandWidgetClass,
+                              LangWidget, arg, 6);
+    XtAddCallback (w, XtNcallback, LangProc, Mnil);
+
+    XtSetArg (arg[0], XtNfromHoriz, w);
+    XtSetArg (arg[1], XtNleft, XawChainLeft);
+    XtSetArg (arg[2], XtNright, XawChainRight);
+    XtSetArg (arg[3], XtNlabel, "");
+    XtSetArg (arg[4], XtNborderWidth, 0);
+    XtSetArg (arg[5], XtNjustify, XtJustifyRight);
+    CurLangWidget = XtCreateManagedWidget ("Current Lang", labelWidgetClass,
+                                          LangWidget, arg, 6);
+  }
+
+  XtSetArg (arg[0], XtNheight, win_height);
+  XtSetArg (arg[1], XtNwidth, 10);
+  XtSetArg (arg[2], XtNleft, XawChainLeft);
+  XtSetArg (arg[3], XtNright, XawChainLeft);
+  SbarWidget = XtCreateManagedWidget ("sbar", scrollbarWidgetClass, BodyWidget,
+                                     arg, 4);
+  XtAddCallback (SbarWidget, XtNscrollProc, ScrollProc, NULL);
+  XtAddCallback (SbarWidget, XtNjumpProc, JumpProc, NULL);
+
+  XtSetArg (arg[0], XtNheight, win_height);
+  XtSetArg (arg[1], XtNwidth, win_width);
+  XtSetArg (arg[2], XtNtranslations, XtParseTranslationTable (trans));
+  XtSetArg (arg[3], XtNfromHoriz, SbarWidget);
+  XtSetArg (arg[4], XtNleft, XawChainLeft);
+  XtSetArg (arg[5], XtNright, XawChainRight);
+  TextWidget = XtCreateManagedWidget ("text", simpleWidgetClass, BodyWidget,
+                                     arg, 5);
+
+  XtSetArg (arg[0], XtNborderWidth, 0);
+  XtSetArg (arg[1], XtNleft, XawChainLeft);
+  XtSetArg (arg[2], XtNright, XawChainRight);
+  XtSetArg (arg[3], XtNresizable, True);
+  XtSetArg (arg[4], XtNjustify, XtJustifyLeft);
+  MessageWidget = XtCreateManagedWidget ("message", labelWidgetClass,
+                                        TailWidget, arg, 5);
+
+  memset (&control, 0, sizeof control);
+  control.two_dimensional = 1;
+  control.enable_bidi = 1;
+  control.anti_alias = 1;
+  control.min_line_ascent = font_ascent;
+  control.min_line_descent = font_descent;
+  control.max_line_width = win_width;
+  control.with_cursor = 1;
+  control.cursor_width = 2;
+  control.partial_update = 1;
+  control.ignore_formatting_char = 1;
+
+  memset (&input_status_control, 0, sizeof input_status_control);
+  input_status_control.enable_bidi = 1;
+
+  XtAppAddActions (context, actions, XtNumber (actions));
+  XtRealizeWidget (ShellWidget);
+
+  win = XtWindow (TextWidget);
+
+  XtAppMainLoop (context);
+
+  if (current_input_context)
+    minput_destroy_ic (current_input_context);
+  for (i = 0; i < num_input_methods; i++)
+    if (input_method_table[i].im)
+      minput_close_im (input_method_table[i].im);
+  m17n_object_unref (frame);
+  m17n_object_unref (mt);
+  m17n_object_unref (face_xxx_large);
+  m17n_object_unref (face_box);
+  m17n_object_unref (face_courier);
+  m17n_object_unref (face_helvetica);
+  m17n_object_unref (face_times);
+  m17n_object_unref (face_dv_ttyogesh);
+  m17n_object_unref (face_freesans);
+  m17n_object_unref (face_freeserif);
+  m17n_object_unref (face_freemono);
+  m17n_object_unref (face_default_fontset);
+  m17n_object_unref (face_no_ctl_fontset);
+  m17n_object_unref (face_input_status);
+  m17n_object_unref (face_default);
+  m17n_object_unref (default_face_list);
+  m17n_object_unref (selection);
+  if (font)
+    free (font);
+
+  XFreeGC (display, mono_gc);
+  XFreeGC (display, mono_gc_inv);
+  XFreeGC (display, gc_inv);
+  XtUninstallTranslations (form);
+  XtUninstallTranslations (TextWidget);
+  XtDestroyWidget (ShellWidget);
+  XtDestroyApplicationContext (context);
+
+  M17N_FINI ();
+
+  free (font_name);
+  free (fontset_name);
+  free (filename);
+  free (input_method_table);
+  free (InputMethodMenus);
+
+  exit (0);
+}
+
+#else  /* not HAVE_X11_XAW_COMMAND_H */
+
+int
+main (int argc, char **argv)
+{
+  fprintf (stderr,
+          "Building of this program failed (lack of some header files)\n");
+  exit (1);
+}
+
+#endif /* not HAVE_X11_XAW_COMMAND_H */
+
+#endif /* not FOR_DOXYGEN */
diff --git a/example/mimx-anthy.c b/example/mimx-anthy.c
new file mode 100644 (file)
index 0000000..997a726
--- /dev/null
@@ -0,0 +1,394 @@
+/* mimx-anthy.c -- Anthy input method external module. -*- coding: euc-jp; -*-
+   Copyright (C) 2003, 2004
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @enpage mimx-anthy external module for the input method <ja, anthy>
+
+    @section mimx-anthy-description DESCRIPTION
+
+    The shared library mimx-anthy.so is an external module used by the
+    input method <ja, anthy>.  It exports these functions.
+
+    <ul>
+    <li> init
+
+    Initialize this module.
+
+    <li> fini
+
+    Finalize this module.
+
+    <li> convert
+
+    Convert the current preedit text (Hiragana sequence) into
+    Kana-Kanji mixed text.
+
+    <li> change
+
+    Record the change of candidate of the current segment.
+
+    <li> resize
+
+    Enlarge or shorten the length of the current segment.
+
+    <li> commit
+
+    Commit the lastly selected candidates of all the segments.
+
+    </ul>
+
+    @section mimx-anthy-seealso See also
+    @ref mdbIM
+*/
+/***ja
+    @japage mimx-anthy ÆþÎϥ᥽¥Ã¥É <ja, anthy> Íѳ°Éô¥â¥¸¥å¡¼¥ë.
+
+    @section mimx-anthy-description DESCRIPTION
+
+    ¶¦Í­¥é¥¤¥Ö¥é¥ê mimx-anthy.so ¤ÏÆþÎϥ᥽¥Ã¥É<ja, anthy> ¤ËÍѤ¤¤é¤ì 
+    ¤ë³°Éô¥â¥¸¥å¡¼¥ë¤Ç¤¢¤ê¡¢°Ê²¼¤Î´Ø¿ô¤ò export ¤·¤Æ¤¤¤ë¡£
+
+    <ul>
+    <li> init
+
+    ¥â¥¸¥å¡¼¥ë¤Î½é´ü²½¡£ 
+
+    <li> fini
+
+    ¥â¥¸¥å¡¼¥ë¤Î½ªÎ»¡£ 
+
+    <li> convert
+
+    ¸½ºß¤Î preedit ¥Æ¥­¥¹¥È (¤Ò¤é¤¬¤ÊÎó) ¤ò¤«¤Ê´Á»ú¥Æ¥­¥¹¥È¤ËÊÑ´¹¤¹¤ë¡£ 
+
+    <li> change
+
+    ¸½ºß¤Î¥»¥°¥á¥ó¥È¤Î¸õÊä¤ÎÊÑÁ«¤òµ­Ï¿¤¹¤ë¡£ 
+
+    <li> resize
+
+    ¸½ºß¤Î¥»¥°¥á¥ó¥È¤ÎŤµ¤òÊѹ¹¤¹¤ë¡£ 
+
+    <li> commit
+
+    Á´¥»¥°¥á¥ó¥È¤ÎºÇ¿·¤Î¸õÊä¤ò¥³¥ß¥Ã¥È¤¹¤ë¡£
+
+    </ul>
+
+    @section mimx-anthy-seealso »²¾È
+    @ref mdbIM
+*/
+
+#ifndef FOR_DOXYGEN
+
+#include <stdio.h>
+#include <string.h>
+#include <m17n.h>
+
+#ifdef HAVE_ANTHY
+
+#include <anthy/anthy.h>
+
+static int initialized;
+static MSymbol Manthy, Msegment;
+
+/* A structure to record in MInputContext->plist with key Manthy.  */
+
+typedef struct {
+  MInputContext *ic;
+  anthy_context_t ac;
+  /* Which candidate is selected in each segment.  */
+  int *candidate_numbers;
+  /* Size of the above array.  */
+  int num_segments;
+  /* Converter for this context.  */
+  MConverter *converter;
+} AnthyContext;
+
+static AnthyContext *
+new_context (MInputContext *ic)
+{
+  AnthyContext *context;
+  anthy_context_t ac;
+  MSymbol euc_jp = msymbol ("euc-jp");
+  /* Rebound to an actual buffer just before being used.  */
+  MConverter *converter = mconv_buffer_converter (euc_jp, NULL, 0);
+
+  if (! converter)
+    return NULL;
+  ac = anthy_create_context ();
+  if (! ac)
+    return NULL;
+  context = calloc (1, sizeof (AnthyContext));
+  context->ic = ic;
+  context->ac = ac;
+  context->num_segments = 0;
+  context->candidate_numbers = NULL;
+  context->converter = converter;
+  return context;
+}
+
+static AnthyContext *
+get_context (MInputContext *ic)
+{
+  MPlist *plist = ic->plist;
+  AnthyContext *context;
+
+  for (; plist && mplist_key (plist) != Mnil; plist = mplist_next (plist))
+    {
+      if (mplist_key (plist) != Manthy)
+       continue;
+      context = mplist_value (plist);
+      if (context->ic == ic)
+       return context;
+    }
+  return NULL;
+}
+
+
+static void
+free_context (AnthyContext *context)
+{
+  anthy_release_context (context->ac);
+  if (context->candidate_numbers)
+    free (context->candidate_numbers);
+  mconv_free_converter (context->converter);
+  free (context);
+}
+
+static void
+allocate_candidate_numbers (AnthyContext *context, int num)
+{
+  if (context->num_segments < num)
+    {
+      if (context->num_segments == 0)
+       context->candidate_numbers = malloc (sizeof (int) * num);
+      else
+       context->candidate_numbers = realloc (context->candidate_numbers,
+                                             sizeof (int) * num);
+      context->num_segments = num;
+    }
+}
+
+static void
+add_action (MPlist *actions, MSymbol name, MSymbol key, void *val)
+{
+  MPlist *action = mplist ();
+
+  mplist_add (action, Msymbol, name);
+  mplist_add (action, key, val);
+  mplist_add (actions, Mplist, action);
+  m17n_object_unref (action);
+}
+
+/* Return a list of all candidates of the Nth segment.  The return
+   value is a plist whose elements are plists who contains at most 5
+   candidates.  */
+
+static MPlist *
+make_candidate_list (AnthyContext *context, int n)
+{
+  MPlist *plist = mplist (), *pl;
+  int i;
+  char buf[1024];
+  struct anthy_segment_stat ss;
+  MText *mt;
+  
+  anthy_get_segment_stat (context->ac, n, &ss);
+  for (i = 0, pl = mplist (); i < ss.nr_candidate; i++)
+    {
+      anthy_get_segment (context->ac, n, i, buf, sizeof (buf));
+      mconv_rebind_buffer (context->converter,
+                          (unsigned char *) buf, strlen (buf));
+      mt = mconv_decode (context->converter, mtext ());
+      mtext_put_prop (mt, 0, mtext_len (mt), Msegment, (void *) (n + 1));
+      mplist_add (pl, Mtext, mt);
+      m17n_object_unref (mt);
+      if (i % 5 == 4)
+       {
+         mplist_add (plist, Mplist, pl);
+         m17n_object_unref (pl);
+         pl = mplist ();
+       }
+    }
+  if (mplist_key (pl) != Mnil)
+    mplist_add (plist, Mplist, pl);
+  m17n_object_unref (pl);
+  return plist;
+}
+
+MPlist *
+init (MPlist *args)
+{
+  MInputContext *ic = mplist_value (args);
+  AnthyContext *context;
+
+  if (! initialized++)
+    {
+      anthy_init ();
+      Manthy = msymbol (" anthy");
+      Msegment = msymbol (" segment");
+    }
+  context = new_context (ic);
+  if (context)
+    mplist_push (ic->plist, Manthy, context);
+  return NULL;
+}
+
+MPlist *
+fini (MPlist *args)
+{
+  MInputContext *ic = mplist_value (args);
+  AnthyContext *context = get_context (ic);
+
+  if (context)
+    free_context (context);
+  return NULL;
+}
+
+MPlist *
+convert (MPlist *args)
+{
+  MInputContext *ic = mplist_value (args);
+  AnthyContext *context = get_context (ic);
+  struct anthy_conv_stat cs;
+  MPlist *action, *actions;
+  int i;
+  unsigned char buf[1024];
+
+  if (! context)
+    return NULL;
+
+  mconv_rebind_buffer (context->converter, buf, sizeof (buf));
+  mconv_encode (context->converter, ic->preedit);
+  buf[context->converter->nbytes] = '\0';
+  anthy_set_string (context->ac, (char *) buf);
+  anthy_get_stat (context->ac, &cs);
+  allocate_candidate_numbers (context, cs.nr_segment);
+
+  actions = mplist ();
+  add_action (actions, msymbol ("move"), Msymbol, msymbol ("@<"));
+  add_action (actions, msymbol ("delete"), Msymbol, msymbol ("@>"));
+  for (i = 0; i < cs.nr_segment; i++)
+    {
+      context->candidate_numbers[i] = 0;
+      if (i == 1)
+       add_action (actions, msymbol ("mark"), Msymbol, msymbol ("@anthy"));
+      action = make_candidate_list (context, i);
+      mplist_add (actions, Mplist, action);
+      m17n_object_unref (action);
+    }
+  if (cs.nr_segment > 1)
+    add_action (actions, msymbol ("move"), Msymbol, msymbol ("@anthy"));
+
+  return actions;
+}
+
+MPlist *
+change (MPlist *args)
+{
+  MInputContext *ic = mplist_value (args);
+  AnthyContext *context = get_context (ic);
+  int segment;
+
+  if (! context)
+    return NULL;
+  if (! ic->candidate_list || ic->cursor_pos == 0)
+    return NULL;
+  segment = (int) mtext_get_prop (ic->preedit, ic->cursor_pos - 1, Msegment);
+  if (segment == 0)
+    return NULL;
+  segment--;
+  context->candidate_numbers[segment] = ic->candidate_index;
+  return NULL;
+}
+
+MPlist *
+resize (MPlist *args)
+{
+  MInputContext *ic = mplist_value (args);
+  AnthyContext *context = get_context (ic);
+  struct anthy_conv_stat cs;
+  MSymbol shorten;
+  int segment;
+  MPlist *actions, *action;
+  int i;
+
+  if (! context)
+    return NULL;
+  if (! ic->candidate_list || ic->cursor_pos == 0)
+    return NULL;
+  segment = (int) mtext_get_prop (ic->preedit, ic->cursor_pos - 1, Msegment);
+  if (segment == 0)
+    return NULL;
+  segment--;
+  args = mplist_next (args);
+  shorten = mplist_value (args);
+  anthy_resize_segment (context->ac, segment, shorten == Mt ? -1 : 1);
+  anthy_get_stat (context->ac, &cs);
+  allocate_candidate_numbers (context, cs.nr_segment);
+
+  actions = mplist ();
+  if (segment == 0)
+    add_action (actions, msymbol ("move"), Msymbol, msymbol ("@<"));
+  else
+    add_action (actions, msymbol ("move"), Msymbol, msymbol ("@["));
+  add_action (actions, msymbol ("delete"), Msymbol, msymbol ("@>"));
+  for (i = segment; i < cs.nr_segment; i++)
+    {
+      context->candidate_numbers[i] = 0;
+      if (i == segment + 1)
+       add_action (actions, msymbol ("mark"), Msymbol, msymbol ("@anthy"));
+      action = make_candidate_list (context, i);
+      mplist_add (actions, Mplist, action);
+      m17n_object_unref (action);
+    }
+  if (segment + 1 < cs.nr_segment)
+    add_action (actions, msymbol ("move"), Msymbol, msymbol ("@anthy"));
+  return actions;
+}
+
+MPlist *
+commit (MPlist *args)
+{
+  MInputContext *ic = mplist_value (args);
+  AnthyContext *context = get_context (ic);
+  struct anthy_conv_stat cs;
+  int i;
+
+  if (! context)
+    return NULL;
+  anthy_get_stat (context->ac, &cs);
+  for (i = 0; i < cs.nr_segment; i++)
+    anthy_commit_segment (context->ac, i, context->candidate_numbers[i]);
+  return NULL;
+}
+
+#else  /* not HAVE_ANTHY */
+
+MPlist *convert (MPlist *args) { return NULL; }
+MPlist *change (MPlist *args) { return NULL; }
+MPlist *resize (MPlist *args) { return NULL; }
+MPlist *commit (MPlist *args) { return NULL; }
+
+#endif /* not HAVE_ANTHY */
+#endif /* not FOR_DOXYGEN */
diff --git a/example/mimx-ispell.c b/example/mimx-ispell.c
new file mode 100644 (file)
index 0000000..daa244f
--- /dev/null
@@ -0,0 +1,241 @@
+/* imx-ispell.c -- Ispell input method external module.        -*- coding: euc-jp; -*-
+   Copyright (C) 2003, 2004
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @enpage mimx-ispell external module for the input method <en, ispell>
+
+    @section mimx-ispell-description DESCRIPTION
+
+    The shared library mimx-ispell.so is an external module used by the
+    input method <en, ispell>.  It exports these functions.
+
+    <ul>
+    <li> init
+
+    Initialize this library.
+
+    <li> fini
+
+    Finalize this library.
+
+    <li> ispell_word
+
+    Check the spell of the current preedit text (English) and, if the
+    spell is incorrect,  return a list of candidates.
+
+    </ul>
+
+    This program is just for demonstrating how to write an external
+    module for an m17n input method, not for an actual use.
+
+    @section mimx-ispell-seealso See also
+    @ref mdbIM
+*/
+/***ja
+    @japage mimx-ispell ÆþÎϥ᥽¥Ã¥É <en, ispell> Íѳ°Éô¥â¥¸¥å¡¼¥ë
+
+    @section mimx-ispell-description DESCRIPTION
+
+    ¶¦Í­¥é¥¤¥Ö¥é¥ê mimx-ispell.so ¤ÏÆþÎϥ᥽¥Ã¥É <en, ispell> ¤ËÍѤ¤¤é 
+    ¤ì¤ë³°Éô¥â¥¸¥å¡¼¥ë¤Ç¤¢¤ê¡¢°Ê²¼¤Î´Ø¿ô¤ò export ¤·¤Æ¤¤¤ë¡£
+
+    <ul>
+    <li> init
+
+    ¥é¥¤¥Ö¥é¥ê¤Î½é´ü²½¡£
+
+    <li> fini
+
+    ¥é¥¤¥Ö¥é¥ê¤Î½ªÎ»¡£ 
+
+    <li> ispell_word
+
+    ¸½ºß¤Î preedit ¥Æ¥­¥¹¥È (±Ñʸ) ¤ÎÄÖ¤òÄ´¤Ù¡¢´Ö°ã¤Ã¤Æ¤¤¤ì¤Ð¸õÊä¤Î¥ê 
+    ¥¹¥È¤òÊÖ¤¹¡£
+
+    </ul>
+
+    ¤³¤Î¥×¥í¥°¥é¥à¤Ïm17n ÆþÎϥ᥽¥Ã¥ÉÍѳ°Éô¥â¥¸¥å¡¼¥ë¤Î½ñ¤­Êý¤ò¼¨¤¹¤¿ 
+    ¤á¤Î¤â¤Î¤Ç¤¢¤ê¡¢¼ÂºÝ¤ÎÍøÍѤò°Õ¿Þ¤·¤¿¤â¤Î¤Ç¤Ï¤Ê¤¤¡£
+
+    @section mimx-ispell-seealso »²¾È
+    @ref mdbIM
+*/
+
+#ifndef FOR_DOXYGEN
+
+#include <stdio.h>
+#include <string.h>
+#include <m17n-gui.h>
+
+#ifdef HAVE_ISPELL
+
+static int initialized = 0;
+static int face_available;
+static MFace *mface_overstrike = NULL;
+
+static MPlist *
+add_action (MPlist *actions, MSymbol name, MSymbol key, void *val)
+{
+  MPlist *action = mplist ();
+
+  mplist_add (action, Msymbol, name);
+  if (key != Mnil)
+    mplist_add (action, key, val);
+  mplist_add (actions, Mplist, action);
+  m17n_object_unref (action);
+  return actions;
+}
+
+MPlist *
+init (MPlist *args)
+{
+  if (! initialized++)
+    {
+      MFaceHLineProp hline;
+
+      face_available = 0;
+      if (m17n_status () == M17N_GUI_INITIALIZED)
+       {
+         face_available = 1;
+         hline.type = MFACE_HLINE_STRIKE_THROUGH;
+         hline.width = 1;
+         hline.color = msymbol ("black");
+         mface_overstrike = mface ();
+         mface_put_prop (mface_overstrike, Mhline, &hline);
+       }
+    }
+  return NULL;
+}
+
+MPlist *
+fini (MPlist *args)
+{
+  if (initialized != 0
+      && --initialized == 0
+      && face_available)
+    m17n_object_unref (mface_overstrike);
+  return NULL;
+}
+
+MPlist *
+ispell_word (MPlist *args)
+{
+  MInputContext *ic;
+  unsigned char buf[256];
+  int nbytes;
+  MPlist *actions, *candidates, *plist;
+  char command[256];
+  char **words;
+  FILE *ispell;
+  char *p = (char *) buf;
+  int i, n;
+  MSymbol init_state;
+  MSymbol select_state;
+  MText *mt;
+
+  ic = mplist_value (args);
+  args = mplist_next (args);
+  init_state = (MSymbol) mplist_value (args);
+  args = mplist_next (args);
+  select_state = (MSymbol) mplist_value (args);
+  nbytes = mconv_encode_buffer (Mcoding_us_ascii, ic->preedit, buf, 256);
+
+  actions = mplist ();
+
+  if (nbytes < 3)
+    return add_action (actions, msymbol ("shift"), Msymbol, init_state);
+
+  buf[nbytes] = '\0';
+  sprintf (command, "echo %s | ispell -a -m", (char *) buf);
+  ispell = popen (command, "r");
+  if (! ispell)
+    return add_action (actions, msymbol ("shift"), Msymbol, init_state);
+
+  /* Skip the heading line.  */
+  fgets (p, 256, ispell);
+  /* Read just 256 bytes, thus candidates listed after the first 256
+     bytes are just ignored.  */
+  fgets (p, 256, ispell);
+  pclose (ispell);
+  p[strlen (p) - 1] = '\0';
+  if (*p != '&' && *p != '#')
+    return add_action (actions, msymbol ("shift"), Msymbol, init_state);
+
+  add_action (actions, msymbol ("delete"), Msymbol,  msymbol ("@<"));
+  if (*p == '#')
+    {
+      mt = mtext_dup (ic->preedit);
+      if (face_available)
+       mtext_push_prop (mt, 0, mtext_len (mt), Mface, mface_overstrike);
+      mplist_add (actions, Mtext, mt);
+      add_action (actions, msymbol ("shift"), Msymbol, init_state);
+      m17n_object_unref (mt);
+      return actions;
+    }
+
+  p = strchr (p + 2, ' ');
+  if (sscanf (p, "%d", &n) != 1)
+    return add_action (actions, msymbol ("shift"), Msymbol, init_state);
+  words = alloca (sizeof (char *) * n);
+  p = strchr (p + 1, ' ');
+  p = strchr (p + 1, ' ');
+  for (i = 0; i < n - 1; i++)
+    {
+      words[i] = ++p;
+      p = strchr (p, ',');
+      if (! p)
+       {
+         n = i - 1;
+         break;
+       }
+      *p++ = '\0';
+    }
+  words[i] = ++p;
+  candidates = mplist ();
+  for (i = 0; i < n; i++)
+    {
+      mt = mconv_decode_buffer (Mcoding_us_ascii, (unsigned char *) words[i],
+                               strlen (words[i]));
+      mplist_add (candidates, Mtext, mt);
+      m17n_object_unref (mt);
+    }
+  mt = mtext_dup (ic->preedit);
+  if (face_available)
+    mtext_push_prop (mt, 0, mtext_len (mt), Mface, mface_overstrike);
+  mplist_add (candidates, Mtext, mt);
+  m17n_object_unref (mt);
+  plist = mplist_add (mplist (), Mplist, candidates);
+  m17n_object_unref (candidates);
+  mplist_add (actions, Mplist, plist);
+  m17n_object_unref (plist);
+  add_action (actions, msymbol ("show"), Mnil, NULL);
+  add_action (actions, msymbol ("shift"), Msymbol, select_state);
+  return actions;
+}
+
+#else  /* not HAVE_ISPELL */
+
+MPlist *ispell_word (MPlist *args) { return NULL; }
+
+#endif /* not HAVE_ISPELL */
+#endif /* not FOR_DOXYGEN */
diff --git a/example/mview.c b/example/mview.c
new file mode 100644 (file)
index 0000000..421ea04
--- /dev/null
@@ -0,0 +1,438 @@
+/* mview.c -- File viewer                              -*- coding: euc-jp; -*-
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @enpage m17n-view view file
+
+    @section m17n-view-synopsis SYNOPSIS
+
+    m17n-view [ XT-OPTION ...] [ OPTION ... ] [ FILE ]
+
+    @section m17n-view-description DESCRIPTION
+
+    Display FILE on a window.
+
+    If FILE is omitted, the input is taken from standard input.
+
+    XT-OPTIONs are standard Xt arguments (e.g. -fn, -fg).
+
+    The following OPTIONs are available.
+
+    <ul>
+
+    <li> -e ENCODING
+
+    ENCODING is the encoding of FILE (defaults to UTF-8).
+
+    <li> -s FONTSIZE
+
+    FONTSIZE is the fontsize in point.  If omitted, it defaults to the
+    size of the default font defined in X resource.
+
+    <li> --version
+
+    Print version number.
+
+    <li> -h, --help
+
+    Print this message.
+
+    </ul>
+*/
+/***ja
+    @japage m17n-view ¥Õ¥¡¥¤¥ë¤ò¸«¤ë
+
+    @section m17n-view-synopsis SYNOPSIS
+
+    m17n-view [ XT-OPTION ...] [ OPTION ... ] [ FILE ]
+
+    @section m17n-view-description DESCRIPTION
+
+    FILE ¤ò¥¦¥£¥ó¥É¥¦¤Ëɽ¼¨¤¹¤ë¡£ 
+
+    FILE ¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Ï¡¢É¸½àÆþÎϤ«¤é¤È¤ë¡£ 
+
+    XT-OPTIONs ¤Ï Xt ¤Îɸ½à¤Î°ú¿ô¤Ç¤¢¤ë¡£ (e.g. -fn, -fg). 
+
+    °Ê²¼¤Î¥ª¥×¥·¥ç¥ó¤¬ÍøÍѤǤ­¤ë¡£ 
+
+    <ul>
+
+    <li> -e ENCODING
+
+    ENCODING ¤Ï FILE ¤Î¥³¡¼¥É·Ï¤Ç¤¢¤ë¡£(¥Ç¥Õ¥©¥ë¥È¤Ï UTF-8) 
+
+    <li> -s FONTSIZE
+
+    FONTSIZE ¤Ï¥Õ¥©¥ó¥È¤ÎÂ礭¤µ¤ò¥Ý¥¤¥ó¥Èñ°Ì¤Ç¼¨¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£¾Êά 
+    ¤µ¤ì¤¿¾ì¹ç¤Ï¡¢X ¤Î¥ê¥½¡¼¥¹¤ÇÄêµÁ¤µ¤ì¤¿¥Ç¥Õ¥©¥ë¥È¥Õ¥©¥ó¥È¤ÎÂ礭¤µ¤È 
+    ¤Ê¤ë¡£
+
+    <li> --version
+
+    ¥Ð¡¼¥¸¥ç¥óÈÖ¹æ¤òɽ¼¨¤¹¤ë¡£
+
+    <li> -h, --help
+
+   ¤³¤Î¥á¥Ã¥»¡¼¥¸¤òɽ¼¨¤¹¤ë¡£ 
+
+    </ul>
+*/
+#ifndef FOR_DOXYGEN
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef HAVE_X11_XAW_COMMAND_H
+
+#include <X11/Intrinsic.h>
+#include <X11/StringDefs.h>
+#include <X11/Shell.h>
+
+#include <m17n-gui.h>
+#include <m17n-misc.h>
+#include <m17n-X.h>
+
+#include <X11/Xaw/Form.h>
+#include <X11/Xaw/Command.h>
+#include <X11/Xaw/Viewport.h>
+
+/* Global m17n variables.  */
+MFrame *frame;
+MText *mt;
+MDrawMetric metric;
+MDrawControl control;
+
+
+/* Callback procedure for "quit".  */
+
+void
+QuitProc (Widget w, XtPointer client_data, XtPointer call_data)
+{
+  XtAppSetExitFlag (XtWidgetToApplicationContext (w));
+}
+
+
+/* Move POS to the next line head in M-text MT whose length is LEN.
+   If POS is already on the last line, set POS to LEN.  */
+
+#define NEXTLINE(pos, len)                     \
+  do {                                         \
+    pos = mtext_character (mt, pos, len, '\n');        \
+    if (pos < 0)                               \
+      pos = len;                               \
+    else                                       \
+      pos++;                                   \
+  } while (0)
+
+
+/* Action procedure for expose event.  Redraw partial area of the
+   widget W.  The area is specified in EVENT.  */
+
+static void
+ExposeProc (Widget w, XEvent *event, String *str, Cardinal *num)
+{
+  XExposeEvent *expose = (XExposeEvent *) event;
+  int len = mtext_len (mt);
+  int pos, from, to;
+  int y = 0, yoff = 0;
+  MDrawMetric rect;
+
+  /* We must update the area between the Y-positions expose->y and
+     (expose->y + expose->height).  We ignore X-positions.  */
+
+  /* At first, find the line that occupies the Y-position expose->y.
+     That is the first line to draw.  */
+  to = 0;
+  while (1)
+    {
+      from = to;
+      NEXTLINE (to, len);
+      mdraw_text_extents (frame, mt, from, to, &control, NULL, NULL, &rect);
+      if (to == len || y + rect.height > expose->y)
+       break;
+      y += rect.height;
+    }
+  /* The first character to draw is at position FROM.  Remeber the
+     Y-position to start drawing.  */
+  yoff = y - rect.y;
+
+  /* Next, find the line that occupies the Y-position (expose->y +
+     expose->height).  That is the last line to draw.  This time, we
+     enable caching to utilize it in the later drawing.  */
+  y += rect.height;
+  control.disable_caching = 0;
+  while (to < len && y < expose->y + expose->height)
+    {
+      pos = to;
+      NEXTLINE (to, len);
+      mdraw_text_extents (frame, mt, pos, to, &control, NULL, NULL, &rect);
+      y += rect.height;
+    }
+
+  /* It is decided that we must draw from FROM to the previous
+     character of TO.  */
+  mdraw_text_with_control (frame, (MDrawWindow) XtWindow (w),
+                          0, yoff, mt, from, to, &control);
+
+  /* Disable caching again.  */
+  control.disable_caching = 1;
+
+  /* If the widget was vertically enlarged too much, shrink it.  */
+  if (metric.height < expose->y + expose->height)
+    {
+      Arg arg;
+
+      XtSetArg (arg, XtNheight, metric.height);
+      XtSetValues (w, &arg, 0);
+    }
+}
+
+
+/* Print the usage of this program (the name is PROG), and exit with
+   EXIT_CODE.  */
+
+void
+help_exit (char *prog, int exit_code)
+{
+  char *p = prog;
+
+  while (*p)
+    if (*p++ == '/')
+      prog = p;
+
+  printf ("Usage: %s [ XT-OPTION ...] [ OPTION ...] [ FILE ]\n", prog);
+  printf ("Display FILE on a window.\n");
+  printf ("  If FILE is omitted, the input is taken from standard input.\n");
+  printf ("  XT-OPTIONs are standard Xt arguments (e.g. -fn, -fg).\n");
+  printf ("The following OPTIONs are available.\n");
+  printf ("  %-13s %s", "-e ENCODING",
+         "ENCODING is the encoding of FILE (defaults to UTF-8).\n");
+  printf ("  %-13s %s", "-s FONTSIZE",
+         "FONTSIZE is the fontsize in point.\n");
+  printf ("\t\tIf omitted, it defaults to the size\n");
+  printf ("\t\tof the default font defined in X resource.\n");
+  printf ("  %-13s %s", "--version", "print version number\n");
+  printf ("  %-13s %s", "-h, --help", "print this message\n");
+  exit (exit_code);
+}
+
+
+/* Format MSG by FMT and print the result to the stderr, and exit.  */
+
+#define FATAL_ERROR(fmt, arg)  \
+  do {                         \
+    fprintf (stderr, fmt, arg);        \
+    exit (1);                  \
+  } while (0)
+
+
+/* Adjust FONTSIZE for the resolution of the screen of widget W.  */
+
+int
+adjust_fontsize (Widget w, int fontsize)
+{
+  Display *display = XtDisplay (w);
+  int screen_number = XScreenNumberOfScreen (XtScreen (w));
+  double pixels = DisplayHeight (display, screen_number);
+  double mm = DisplayHeightMM (display, screen_number);
+
+  return (fontsize * pixels * 25.4 / mm / 100);
+}
+
+
+int
+main (int argc, char **argv)
+{
+  XtAppContext context;
+  Widget shell, form, quit, viewport, text;
+  String quit_action = "<KeyPress>q: set() notify() unset()";
+  XtActionsRec actions[] = { {"Expose", ExposeProc} };
+  Arg arg[10];
+  int i;
+  int viewport_width, viewport_height;
+  char *coding_name = NULL;
+  FILE *fp = stdin;
+  MSymbol coding;
+  int fontsize = 0;
+
+  /* Open an application context.  */
+  XtSetLanguageProc (NULL, NULL, NULL);
+  shell = XtOpenApplication (&context, "M17NView", NULL, 0, &argc, argv, NULL,
+                            sessionShellWidgetClass, NULL, 0);
+  XtAppAddActions (context, actions, XtNumber (actions));
+
+  /* Parse the remaining command line arguments.  */
+  for (i = 1; i < argc; i++)
+    {
+      if (! strcmp (argv[i], "--help")
+         || ! strcmp (argv[i], "-h"))
+       help_exit (argv[0], 0);
+      else if (! strcmp (argv[i], "--version"))
+       {
+         printf ("m17n-view (m17n library) %s\n", M17NLIB_VERSION_NAME);
+         printf ("Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 AIST, JAPAN\n");
+         exit (0);
+       }
+      else if (! strcmp (argv[i], "-e"))
+       {
+         i++;
+         coding_name = argv[i];
+       }
+      else if (! strcmp (argv[i], "-s"))
+       {
+         double n;
+         i++;
+         n = atof (argv[i]);
+         if (n <= 0)
+           FATAL_ERROR ("Invalid fontsize %s!\n", argv[i]);
+         fontsize = adjust_fontsize (shell, (int) (n * 10));
+       }
+      else if (argv[i][0] != '-')
+       {
+         fp = fopen (argv[i], "r");
+         if (! fp)
+           FATAL_ERROR ("Fail to open the file %s!\n", argv[i]);
+       }
+      else
+       {
+         printf ("Unknown option: %s", argv[i]);
+         help_exit (argv[0], 1);
+       }
+    }
+
+  /* Initialize the m17n library.  */
+  M17N_INIT ();
+  if (merror_code != MERROR_NONE)
+    FATAL_ERROR ("%s\n", "Fail to initialize the m17n library.");
+
+  /* Decide how to decode the input stream.  */
+  if (coding_name)
+    {
+      coding = mconv_resolve_coding (msymbol (coding_name));
+      if (coding == Mnil)
+       FATAL_ERROR ("Invalid coding: %s\n", coding_name);
+    }
+  else
+    coding = Mcoding_utf_8;
+
+  mt = mconv_decode_stream (coding, fp);
+  fclose (fp);
+  if (! mt)
+    FATAL_ERROR ("%s\n", "Fail to decode the input file or stream!");
+
+  {
+    MPlist *param = mplist ();
+    MFace *face = mface ();
+
+    if (fontsize)
+      mface_put_prop (face, Msize, (void *) fontsize);
+    mplist_put (param, Mwidget, shell);
+    mplist_put (param, Mface, face);
+    frame = mframe (param);
+    m17n_object_unref (param);
+    m17n_object_unref (face);
+  }
+
+  /* Create this widget hierarchy.
+     Shell - form -+- quit
+                  |
+                  +- viewport - text  */
+
+  form = XtCreateManagedWidget ("form", formWidgetClass, shell, NULL, 0);
+  XtSetArg (arg[0], XtNleft, XawChainLeft);
+  XtSetArg (arg[1], XtNright, XawChainLeft);
+  XtSetArg (arg[2], XtNtop, XawChainTop);
+  XtSetArg (arg[3], XtNbottom, XawChainTop);
+  XtSetArg (arg[4], XtNaccelerators, XtParseAcceleratorTable (quit_action));
+  quit = XtCreateManagedWidget ("quit", commandWidgetClass, form, arg, 5);
+  XtAddCallback (quit, XtNcallback, QuitProc, NULL);
+
+  viewport_width = (int) mframe_get_prop (frame, Mfont_width) * 80;
+  viewport_height
+    = ((int) mframe_get_prop (frame, Mfont_ascent)
+       + (int) mframe_get_prop (frame, Mfont_descent)) * 24;
+  XtSetArg (arg[0], XtNallowVert, True);
+  XtSetArg (arg[1], XtNforceBars, False);
+  XtSetArg (arg[2], XtNfromVert, quit);
+  XtSetArg (arg[3], XtNtop, XawChainTop);
+  XtSetArg (arg[4], XtNbottom, XawChainBottom);
+  XtSetArg (arg[5], XtNright, XawChainRight);
+  XtSetArg (arg[6], XtNwidth, viewport_width);
+  XtSetArg (arg[7], XtNheight, viewport_height);
+  viewport = XtCreateManagedWidget ("viewport", viewportWidgetClass, form,
+                                   arg, 8);
+
+  /* Before creating the text widget, we must calculate the height of
+     the M-text to draw.  */
+  control.two_dimensional = 1;
+  control.enable_bidi = 1;
+  control.disable_caching = 1;
+  control.max_line_width = viewport_width;
+  mdraw_text_extents (frame, mt, 0, mtext_len (mt), &control,
+                     NULL, NULL, &metric);
+
+  {
+    /* Decide the size of the text widget.  */
+    XtSetArg (arg[0], XtNwidth, viewport_width);
+    if (viewport_height > metric.height)
+      /* The outer viewport is tall enough.  */
+      XtSetArg (arg[1], XtNheight, viewport_height);
+    else if (metric.height < 0x8000)
+      /* The M-text height is within the limit of X.  */
+      XtSetArg (arg[1], XtNheight, metric.height);
+    else
+      /* We can't make such a tall widget.  Truncate it.  */
+      XtSetArg (arg[1], XtNheight, 0x7FFF);
+
+    /* We must provide our own expose event handler.  */
+    XtSetArg (arg[2], XtNtranslations,
+             XtParseTranslationTable ((String) "<Expose>: Expose()"));
+    text = XtCreateManagedWidget ("text", simpleWidgetClass, viewport, arg, 3);
+  }
+
+  /* Realize the top widget, and dive into an even loop.  */
+  XtInstallAllAccelerators (form, form);
+  XtRealizeWidget (shell);
+  XtAppMainLoop (context);
+
+  /* Clear away.  */
+  m17n_object_unref (mt);
+  m17n_object_unref (frame);
+  M17N_FINI ();
+
+  exit (0);
+}
+
+#else  /* not HAVE_X11_XAW_COMMAND_H */
+
+int
+main (int argc, char **argv)
+{
+  fprintf (stderr,
+          "Building of this program failed (lack of some header files)\n");
+  exit (1);
+}
+
+#endif /* not HAVE_X11_XAW_COMMAND_H */
+
+#endif /* not FOR_DOXYGEN */
diff --git a/install-sh b/install-sh
new file mode 100755 (executable)
index 0000000..6781b98
--- /dev/null
@@ -0,0 +1,520 @@
+#!/bin/sh
+# install - install a program, script, or datafile
+
+scriptversion=2009-04-28.21; # UTC
+
+# This originates from X11R5 (mit/util/scripts/install.sh), which was
+# later released in X11R6 (xc/config/util/install.sh) with the
+# following copyright and license.
+#
+# Copyright (C) 1994 X Consortium
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
+# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# Except as contained in this notice, the name of the X Consortium shall not
+# be used in advertising or otherwise to promote the sale, use or other deal-
+# ings in this Software without prior written authorization from the X Consor-
+# tium.
+#
+#
+# FSF changes to this file are in the public domain.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# `make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.
+
+nl='
+'
+IFS=" ""       $nl"
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit=${DOITPROG-}
+if test -z "$doit"; then
+  doit_exec=exec
+else
+  doit_exec=$doit
+fi
+
+# Put in absolute file names if you don't have them in your path;
+# or use environment vars.
+
+chgrpprog=${CHGRPPROG-chgrp}
+chmodprog=${CHMODPROG-chmod}
+chownprog=${CHOWNPROG-chown}
+cmpprog=${CMPPROG-cmp}
+cpprog=${CPPROG-cp}
+mkdirprog=${MKDIRPROG-mkdir}
+mvprog=${MVPROG-mv}
+rmprog=${RMPROG-rm}
+stripprog=${STRIPPROG-strip}
+
+posix_glob='?'
+initialize_posix_glob='
+  test "$posix_glob" != "?" || {
+    if (set -f) 2>/dev/null; then
+      posix_glob=
+    else
+      posix_glob=:
+    fi
+  }
+'
+
+posix_mkdir=
+
+# Desired mode of installed file.
+mode=0755
+
+chgrpcmd=
+chmodcmd=$chmodprog
+chowncmd=
+mvcmd=$mvprog
+rmcmd="$rmprog -f"
+stripcmd=
+
+src=
+dst=
+dir_arg=
+dst_arg=
+
+copy_on_change=false
+no_target_directory=
+
+usage="\
+Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
+   or: $0 [OPTION]... SRCFILES... DIRECTORY
+   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
+   or: $0 [OPTION]... -d DIRECTORIES...
+
+In the 1st form, copy SRCFILE to DSTFILE.
+In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
+In the 4th, create DIRECTORIES.
+
+Options:
+     --help     display this help and exit.
+     --version  display version info and exit.
+
+  -c            (ignored)
+  -C            install only if different (preserve the last data modification time)
+  -d            create directories instead of installing files.
+  -g GROUP      $chgrpprog installed files to GROUP.
+  -m MODE       $chmodprog installed files to MODE.
+  -o USER       $chownprog installed files to USER.
+  -s            $stripprog installed files.
+  -t DIRECTORY  install into DIRECTORY.
+  -T            report an error if DSTFILE is a directory.
+
+Environment variables override the default commands:
+  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
+  RMPROG STRIPPROG
+"
+
+while test $# -ne 0; do
+  case $1 in
+    -c) ;;
+
+    -C) copy_on_change=true;;
+
+    -d) dir_arg=true;;
+
+    -g) chgrpcmd="$chgrpprog $2"
+       shift;;
+
+    --help) echo "$usage"; exit $?;;
+
+    -m) mode=$2
+       case $mode in
+         *' '* | *'    '* | *'
+'*       | *'*'* | *'?'* | *'['*)
+           echo "$0: invalid mode: $mode" >&2
+           exit 1;;
+       esac
+       shift;;
+
+    -o) chowncmd="$chownprog $2"
+       shift;;
+
+    -s) stripcmd=$stripprog;;
+
+    -t) dst_arg=$2
+       shift;;
+
+    -T) no_target_directory=true;;
+
+    --version) echo "$0 $scriptversion"; exit $?;;
+
+    --)        shift
+       break;;
+
+    -*)        echo "$0: invalid option: $1" >&2
+       exit 1;;
+
+    *)  break;;
+  esac
+  shift
+done
+
+if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
+  # When -d is used, all remaining arguments are directories to create.
+  # When -t is used, the destination is already specified.
+  # Otherwise, the last argument is the destination.  Remove it from $@.
+  for arg
+  do
+    if test -n "$dst_arg"; then
+      # $@ is not empty: it contains at least $arg.
+      set fnord "$@" "$dst_arg"
+      shift # fnord
+    fi
+    shift # arg
+    dst_arg=$arg
+  done
+fi
+
+if test $# -eq 0; then
+  if test -z "$dir_arg"; then
+    echo "$0: no input file specified." >&2
+    exit 1
+  fi
+  # It's OK to call `install-sh -d' without argument.
+  # This can happen when creating conditional directories.
+  exit 0
+fi
+
+if test -z "$dir_arg"; then
+  trap '(exit $?); exit' 1 2 13 15
+
+  # Set umask so as not to create temps with too-generous modes.
+  # However, 'strip' requires both read and write access to temps.
+  case $mode in
+    # Optimize common cases.
+    *644) cp_umask=133;;
+    *755) cp_umask=22;;
+
+    *[0-7])
+      if test -z "$stripcmd"; then
+       u_plus_rw=
+      else
+       u_plus_rw='% 200'
+      fi
+      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
+    *)
+      if test -z "$stripcmd"; then
+       u_plus_rw=
+      else
+       u_plus_rw=,u+rw
+      fi
+      cp_umask=$mode$u_plus_rw;;
+  esac
+fi
+
+for src
+do
+  # Protect names starting with `-'.
+  case $src in
+    -*) src=./$src;;
+  esac
+
+  if test -n "$dir_arg"; then
+    dst=$src
+    dstdir=$dst
+    test -d "$dstdir"
+    dstdir_status=$?
+  else
+
+    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
+    # might cause directories to be created, which would be especially bad
+    # if $src (and thus $dsttmp) contains '*'.
+    if test ! -f "$src" && test ! -d "$src"; then
+      echo "$0: $src does not exist." >&2
+      exit 1
+    fi
+
+    if test -z "$dst_arg"; then
+      echo "$0: no destination specified." >&2
+      exit 1
+    fi
+
+    dst=$dst_arg
+    # Protect names starting with `-'.
+    case $dst in
+      -*) dst=./$dst;;
+    esac
+
+    # If destination is a directory, append the input filename; won't work
+    # if double slashes aren't ignored.
+    if test -d "$dst"; then
+      if test -n "$no_target_directory"; then
+       echo "$0: $dst_arg: Is a directory" >&2
+       exit 1
+      fi
+      dstdir=$dst
+      dst=$dstdir/`basename "$src"`
+      dstdir_status=0
+    else
+      # Prefer dirname, but fall back on a substitute if dirname fails.
+      dstdir=`
+       (dirname "$dst") 2>/dev/null ||
+       expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+            X"$dst" : 'X\(//\)[^/]' \| \
+            X"$dst" : 'X\(//\)$' \| \
+            X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
+       echo X"$dst" |
+           sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+                  s//\1/
+                  q
+                }
+                /^X\(\/\/\)[^/].*/{
+                  s//\1/
+                  q
+                }
+                /^X\(\/\/\)$/{
+                  s//\1/
+                  q
+                }
+                /^X\(\/\).*/{
+                  s//\1/
+                  q
+                }
+                s/.*/./; q'
+      `
+
+      test -d "$dstdir"
+      dstdir_status=$?
+    fi
+  fi
+
+  obsolete_mkdir_used=false
+
+  if test $dstdir_status != 0; then
+    case $posix_mkdir in
+      '')
+       # Create intermediate dirs using mode 755 as modified by the umask.
+       # This is like FreeBSD 'install' as of 1997-10-28.
+       umask=`umask`
+       case $stripcmd.$umask in
+         # Optimize common cases.
+         *[2367][2367]) mkdir_umask=$umask;;
+         .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
+
+         *[0-7])
+           mkdir_umask=`expr $umask + 22 \
+             - $umask % 100 % 40 + $umask % 20 \
+             - $umask % 10 % 4 + $umask % 2
+           `;;
+         *) mkdir_umask=$umask,go-w;;
+       esac
+
+       # With -d, create the new directory with the user-specified mode.
+       # Otherwise, rely on $mkdir_umask.
+       if test -n "$dir_arg"; then
+         mkdir_mode=-m$mode
+       else
+         mkdir_mode=
+       fi
+
+       posix_mkdir=false
+       case $umask in
+         *[123567][0-7][0-7])
+           # POSIX mkdir -p sets u+wx bits regardless of umask, which
+           # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
+           ;;
+         *)
+           tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
+           trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
+
+           if (umask $mkdir_umask &&
+               exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
+           then
+             if test -z "$dir_arg" || {
+                  # Check for POSIX incompatibilities with -m.
+                  # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
+                  # other-writeable bit of parent directory when it shouldn't.
+                  # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
+                  ls_ld_tmpdir=`ls -ld "$tmpdir"`
+                  case $ls_ld_tmpdir in
+                    d????-?r-*) different_mode=700;;
+                    d????-?--*) different_mode=755;;
+                    *) false;;
+                  esac &&
+                  $mkdirprog -m$different_mode -p -- "$tmpdir" && {
+                    ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
+                    test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
+                  }
+                }
+             then posix_mkdir=:
+             fi
+             rmdir "$tmpdir/d" "$tmpdir"
+           else
+             # Remove any dirs left behind by ancient mkdir implementations.
+             rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
+           fi
+           trap '' 0;;
+       esac;;
+    esac
+
+    if
+      $posix_mkdir && (
+       umask $mkdir_umask &&
+       $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
+      )
+    then :
+    else
+
+      # The umask is ridiculous, or mkdir does not conform to POSIX,
+      # or it failed possibly due to a race condition.  Create the
+      # directory the slow way, step by step, checking for races as we go.
+
+      case $dstdir in
+       /*) prefix='/';;
+       -*) prefix='./';;
+       *)  prefix='';;
+      esac
+
+      eval "$initialize_posix_glob"
+
+      oIFS=$IFS
+      IFS=/
+      $posix_glob set -f
+      set fnord $dstdir
+      shift
+      $posix_glob set +f
+      IFS=$oIFS
+
+      prefixes=
+
+      for d
+      do
+       test -z "$d" && continue
+
+       prefix=$prefix$d
+       if test -d "$prefix"; then
+         prefixes=
+       else
+         if $posix_mkdir; then
+           (umask=$mkdir_umask &&
+            $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
+           # Don't fail if two instances are running concurrently.
+           test -d "$prefix" || exit 1
+         else
+           case $prefix in
+             *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
+             *) qprefix=$prefix;;
+           esac
+           prefixes="$prefixes '$qprefix'"
+         fi
+       fi
+       prefix=$prefix/
+      done
+
+      if test -n "$prefixes"; then
+       # Don't fail if two instances are running concurrently.
+       (umask $mkdir_umask &&
+        eval "\$doit_exec \$mkdirprog $prefixes") ||
+         test -d "$dstdir" || exit 1
+       obsolete_mkdir_used=true
+      fi
+    fi
+  fi
+
+  if test -n "$dir_arg"; then
+    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
+    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
+      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
+  else
+
+    # Make a couple of temp file names in the proper directory.
+    dsttmp=$dstdir/_inst.$$_
+    rmtmp=$dstdir/_rm.$$_
+
+    # Trap to clean up those temp files at exit.
+    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
+
+    # Copy the file name to the temp name.
+    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
+
+    # and set any options; do chmod last to preserve setuid bits.
+    #
+    # If any of these fail, we abort the whole thing.  If we want to
+    # ignore errors from any of these, just make sure not to ignore
+    # errors from the above "$doit $cpprog $src $dsttmp" command.
+    #
+    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
+    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
+    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
+
+    # If -C, don't bother to copy if it wouldn't change the file.
+    if $copy_on_change &&
+       old=`LC_ALL=C ls -dlL "$dst"    2>/dev/null` &&
+       new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
+
+       eval "$initialize_posix_glob" &&
+       $posix_glob set -f &&
+       set X $old && old=:$2:$4:$5:$6 &&
+       set X $new && new=:$2:$4:$5:$6 &&
+       $posix_glob set +f &&
+
+       test "$old" = "$new" &&
+       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
+    then
+      rm -f "$dsttmp"
+    else
+      # Rename the file to the real destination.
+      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
+
+      # The rename failed, perhaps because mv can't rename something else
+      # to itself, or perhaps because mv is so ancient that it does not
+      # support -f.
+      {
+       # Now remove or move aside any old file at destination location.
+       # We try this two ways since rm can't unlink itself on some
+       # systems and the destination file might be busy for other
+       # reasons.  In this case, the final cleanup might fail but the new
+       # file should still install successfully.
+       {
+         test ! -f "$dst" ||
+         $doit $rmcmd -f "$dst" 2>/dev/null ||
+         { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
+           { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
+         } ||
+         { echo "$0: cannot unlink or rename $dst" >&2
+           (exit 1); exit 1
+         }
+       } &&
+
+       # Now rename the file to the real destination.
+       $doit $mvcmd "$dsttmp" "$dst"
+      }
+    fi || exit 1
+
+    trap '' 0
+  fi
+done
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/intl/ChangeLog b/intl/ChangeLog
new file mode 100644 (file)
index 0000000..acc4005
--- /dev/null
@@ -0,0 +1,4 @@
+2005-04-11  GNU  <bug-gnu-gettext@gnu.org>
+
+       * Version 0.14.4 released.
+
diff --git a/intl/Makefile.in b/intl/Makefile.in
new file mode 100644 (file)
index 0000000..25499c0
--- /dev/null
@@ -0,0 +1,500 @@
+# Makefile for directory with message catalog handling library of GNU gettext
+# Copyright (C) 1995-1998, 2000-2005 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Library General Public License as published
+# by the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program 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
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+# USA.
+
+PACKAGE = @PACKAGE@
+VERSION = @VERSION@
+
+SHELL = /bin/sh
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+top_builddir = ..
+VPATH = $(srcdir)
+
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+transform = @program_transform_name@
+libdir = @libdir@
+includedir = @includedir@
+datadir = @datadir@
+localedir = $(datadir)/locale
+gettextsrcdir = $(datadir)/gettext/intl
+aliaspath = $(localedir)
+subdir = intl
+
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+MKINSTALLDIRS = @MKINSTALLDIRS@
+mkinstalldirs = $(SHELL) $(MKINSTALLDIRS)
+
+l = @INTL_LIBTOOL_SUFFIX_PREFIX@
+
+AR = ar
+CC = @CC@
+LIBTOOL = @LIBTOOL@
+RANLIB = @RANLIB@
+YACC = @INTLBISON@ -y -d
+YFLAGS = --name-prefix=__gettext
+
+DEFS = -DLOCALEDIR=\"$(localedir)\" -DLOCALE_ALIAS_PATH=\"$(aliaspath)\" \
+-DLIBDIR=\"$(libdir)\" -DIN_LIBINTL \
+-DENABLE_RELOCATABLE=1 -DIN_LIBRARY -DINSTALLDIR=\"$(libdir)\" -DNO_XMALLOC \
+-Dset_relocation_prefix=libintl_set_relocation_prefix \
+-Drelocate=libintl_relocate \
+-DDEPENDS_ON_LIBICONV=1 @DEFS@
+CPPFLAGS = @CPPFLAGS@
+CFLAGS = @CFLAGS@
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@
+
+COMPILE = $(CC) -c $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $(XCFLAGS)
+
+HEADERS = \
+  gmo.h \
+  gettextP.h \
+  hash-string.h \
+  loadinfo.h \
+  plural-exp.h \
+  eval-plural.h \
+  localcharset.h \
+  relocatable.h \
+  xsize.h \
+  printf-args.h printf-args.c \
+  printf-parse.h wprintf-parse.h printf-parse.c \
+  vasnprintf.h vasnwprintf.h vasnprintf.c \
+  os2compat.h \
+  libgnuintl.h.in
+SOURCES = \
+  bindtextdom.c \
+  dcgettext.c \
+  dgettext.c \
+  gettext.c \
+  finddomain.c \
+  loadmsgcat.c \
+  localealias.c \
+  textdomain.c \
+  l10nflist.c \
+  explodename.c \
+  dcigettext.c \
+  dcngettext.c \
+  dngettext.c \
+  ngettext.c \
+  plural.y \
+  plural-exp.c \
+  localcharset.c \
+  relocatable.c \
+  langprefs.c \
+  localename.c \
+  log.c \
+  printf.c \
+  osdep.c \
+  os2compat.c \
+  intl-compat.c
+OBJECTS = \
+  bindtextdom.$lo \
+  dcgettext.$lo \
+  dgettext.$lo \
+  gettext.$lo \
+  finddomain.$lo \
+  loadmsgcat.$lo \
+  localealias.$lo \
+  textdomain.$lo \
+  l10nflist.$lo \
+  explodename.$lo \
+  dcigettext.$lo \
+  dcngettext.$lo \
+  dngettext.$lo \
+  ngettext.$lo \
+  plural.$lo \
+  plural-exp.$lo \
+  localcharset.$lo \
+  relocatable.$lo \
+  langprefs.$lo \
+  localename.$lo \
+  log.$lo \
+  printf.$lo \
+  osdep.$lo \
+  intl-compat.$lo
+DISTFILES.common = Makefile.in \
+config.charset locale.alias ref-add.sin ref-del.sin $(HEADERS) $(SOURCES)
+DISTFILES.generated = plural.c
+DISTFILES.normal = VERSION
+DISTFILES.gettext = COPYING.LIB-2.0 COPYING.LIB-2.1 libintl.glibc \
+libgnuintl.h_vms Makefile.vms \
+libgnuintl.h.msvc-static libgnuintl.h.msvc-shared README.woe32 Makefile.msvc
+DISTFILES.obsolete = xopen-msg.sed linux-msg.sed po2tbl.sed.in cat-compat.c \
+COPYING.LIB-2 gettext.h libgettext.h plural-eval.c libgnuintl.h
+
+all: all-@USE_INCLUDED_LIBINTL@
+all-yes: libintl.$la libintl.h charset.alias ref-add.sed ref-del.sed
+all-no: all-no-@BUILD_INCLUDED_LIBINTL@
+all-no-yes: libgnuintl.$la
+all-no-no:
+
+libintl.a libgnuintl.a: $(OBJECTS)
+       rm -f $@
+       $(AR) cru $@ $(OBJECTS)
+       $(RANLIB) $@
+
+libintl.la libgnuintl.la: $(OBJECTS)
+       $(LIBTOOL) --mode=link \
+         $(CC) $(CPPFLAGS) $(CFLAGS) $(XCFLAGS) $(LDFLAGS) -o $@ \
+         $(OBJECTS) @LTLIBICONV@ @INTL_MACOSX_LIBS@ $(LIBS) -lc \
+         -version-info $(LTV_CURRENT):$(LTV_REVISION):$(LTV_AGE) \
+         -rpath $(libdir) \
+         -no-undefined
+
+# Libtool's library version information for libintl.
+# Before making a gettext release, the gettext maintainer must change this
+# according to the libtool documentation, section "Library interface versions".
+# Maintainers of other packages that include the intl directory must *not*
+# change these values.
+LTV_CURRENT=7
+LTV_REVISION=3
+LTV_AGE=4
+
+.SUFFIXES:
+.SUFFIXES: .c .y .o .lo .sin .sed
+
+.c.o:
+       $(COMPILE) $<
+
+.y.c:
+       $(YACC) $(YFLAGS) --output $@ $<
+       rm -f $*.h
+
+bindtextdom.lo: $(srcdir)/bindtextdom.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/bindtextdom.c
+dcgettext.lo: $(srcdir)/dcgettext.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dcgettext.c
+dgettext.lo: $(srcdir)/dgettext.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dgettext.c
+gettext.lo: $(srcdir)/gettext.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/gettext.c
+finddomain.lo: $(srcdir)/finddomain.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/finddomain.c
+loadmsgcat.lo: $(srcdir)/loadmsgcat.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/loadmsgcat.c
+localealias.lo: $(srcdir)/localealias.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/localealias.c
+textdomain.lo: $(srcdir)/textdomain.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/textdomain.c
+l10nflist.lo: $(srcdir)/l10nflist.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/l10nflist.c
+explodename.lo: $(srcdir)/explodename.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/explodename.c
+dcigettext.lo: $(srcdir)/dcigettext.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dcigettext.c
+dcngettext.lo: $(srcdir)/dcngettext.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dcngettext.c
+dngettext.lo: $(srcdir)/dngettext.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dngettext.c
+ngettext.lo: $(srcdir)/ngettext.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/ngettext.c
+plural.lo: $(srcdir)/plural.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/plural.c
+plural-exp.lo: $(srcdir)/plural-exp.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/plural-exp.c
+localcharset.lo: $(srcdir)/localcharset.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/localcharset.c
+relocatable.lo: $(srcdir)/relocatable.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/relocatable.c
+langprefs.lo: $(srcdir)/langprefs.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/langprefs.c
+localename.lo: $(srcdir)/localename.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/localename.c
+log.lo: $(srcdir)/log.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/log.c
+printf.lo: $(srcdir)/printf.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/printf.c
+osdep.lo: $(srcdir)/osdep.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/osdep.c
+intl-compat.lo: $(srcdir)/intl-compat.c
+       $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/intl-compat.c
+
+ref-add.sed: $(srcdir)/ref-add.sin
+       sed -e '/^#/d' -e 's/@''PACKAGE''@/@PACKAGE@/g' $(srcdir)/ref-add.sin > t-ref-add.sed
+       mv t-ref-add.sed ref-add.sed
+ref-del.sed: $(srcdir)/ref-del.sin
+       sed -e '/^#/d' -e 's/@''PACKAGE''@/@PACKAGE@/g' $(srcdir)/ref-del.sin > t-ref-del.sed
+       mv t-ref-del.sed ref-del.sed
+
+INCLUDES = -I. -I$(srcdir) -I..
+
+libgnuintl.h: $(srcdir)/libgnuintl.h.in
+       sed -e 's,@''HAVE_POSIX_PRINTF''@,@HAVE_POSIX_PRINTF@,g' \
+           -e 's,@''HAVE_ASPRINTF''@,@HAVE_ASPRINTF@,g' \
+           -e 's,@''HAVE_SNPRINTF''@,@HAVE_SNPRINTF@,g' \
+           -e 's,@''HAVE_WPRINTF''@,@HAVE_WPRINTF@,g' \
+         < $(srcdir)/libgnuintl.h.in > libgnuintl.h
+
+libintl.h: libgnuintl.h
+       cp libgnuintl.h libintl.h
+
+charset.alias: $(srcdir)/config.charset
+       $(SHELL) $(srcdir)/config.charset '@host@' > t-$@
+       mv t-$@ $@
+
+check: all
+
+# We must not install the libintl.h/libintl.a files if we are on a
+# system which has the GNU gettext() function in its C library or in a
+# separate library.
+# If you want to use the one which comes with this version of the
+# package, you have to use `configure --with-included-gettext'.
+install: install-exec install-data
+install-exec: all
+       if { test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; } \
+          && test '@USE_INCLUDED_LIBINTL@' = yes; then \
+         $(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir); \
+         $(INSTALL_DATA) libintl.h $(DESTDIR)$(includedir)/libintl.h; \
+         $(LIBTOOL) --mode=install \
+           $(INSTALL_DATA) libintl.$la $(DESTDIR)$(libdir)/libintl.$la; \
+         if test "@RELOCATABLE@" = yes; then \
+           dependencies=`sed -n -e 's,^dependency_libs=\(.*\),\1,p' < $(DESTDIR)$(libdir)/libintl.la | sed -e "s,^',," -e "s,'\$$,,"`; \
+           if test -n "$$dependencies"; then \
+             rm -f $(DESTDIR)$(libdir)/libintl.la; \
+           fi; \
+         fi; \
+       else \
+         : ; \
+       fi
+       if test "$(PACKAGE)" = "gettext-tools" \
+          && test '@USE_INCLUDED_LIBINTL@' = no \
+          && test @GLIBC2@ != no; then \
+         $(mkinstalldirs) $(DESTDIR)$(libdir); \
+         $(LIBTOOL) --mode=install \
+           $(INSTALL_DATA) libgnuintl.$la $(DESTDIR)$(libdir)/libgnuintl.$la; \
+         rm -f $(DESTDIR)$(libdir)/preloadable_libintl.so; \
+         $(INSTALL_DATA) $(DESTDIR)$(libdir)/libgnuintl.so $(DESTDIR)$(libdir)/preloadable_libintl.so; \
+         $(LIBTOOL) --mode=uninstall \
+           rm -f $(DESTDIR)$(libdir)/libgnuintl.$la; \
+       else \
+         : ; \
+       fi
+       if test '@USE_INCLUDED_LIBINTL@' = yes; then \
+         test @GLIBC21@ != no || $(mkinstalldirs) $(DESTDIR)$(libdir); \
+         temp=$(DESTDIR)$(libdir)/t-charset.alias; \
+         dest=$(DESTDIR)$(libdir)/charset.alias; \
+         if test -f $(DESTDIR)$(libdir)/charset.alias; then \
+           orig=$(DESTDIR)$(libdir)/charset.alias; \
+           sed -f ref-add.sed $$orig > $$temp; \
+           $(INSTALL_DATA) $$temp $$dest; \
+           rm -f $$temp; \
+         else \
+           if test @GLIBC21@ = no; then \
+             orig=charset.alias; \
+             sed -f ref-add.sed $$orig > $$temp; \
+             $(INSTALL_DATA) $$temp $$dest; \
+             rm -f $$temp; \
+           fi; \
+         fi; \
+         $(mkinstalldirs) $(DESTDIR)$(localedir); \
+         test -f $(DESTDIR)$(localedir)/locale.alias \
+           && orig=$(DESTDIR)$(localedir)/locale.alias \
+           || orig=$(srcdir)/locale.alias; \
+         temp=$(DESTDIR)$(localedir)/t-locale.alias; \
+         dest=$(DESTDIR)$(localedir)/locale.alias; \
+         sed -f ref-add.sed $$orig > $$temp; \
+         $(INSTALL_DATA) $$temp $$dest; \
+         rm -f $$temp; \
+       else \
+         : ; \
+       fi
+install-data: all
+       if test "$(PACKAGE)" = "gettext-tools"; then \
+         $(mkinstalldirs) $(DESTDIR)$(gettextsrcdir); \
+         $(INSTALL_DATA) VERSION $(DESTDIR)$(gettextsrcdir)/VERSION; \
+         $(INSTALL_DATA) ChangeLog.inst $(DESTDIR)$(gettextsrcdir)/ChangeLog; \
+         dists="COPYING.LIB-2.0 COPYING.LIB-2.1 $(DISTFILES.common)"; \
+         for file in $$dists; do \
+           $(INSTALL_DATA) $(srcdir)/$$file \
+                           $(DESTDIR)$(gettextsrcdir)/$$file; \
+         done; \
+         chmod a+x $(DESTDIR)$(gettextsrcdir)/config.charset; \
+         dists="$(DISTFILES.generated)"; \
+         for file in $$dists; do \
+           if test -f $$file; then dir=.; else dir=$(srcdir); fi; \
+           $(INSTALL_DATA) $$dir/$$file \
+                           $(DESTDIR)$(gettextsrcdir)/$$file; \
+         done; \
+         dists="$(DISTFILES.obsolete)"; \
+         for file in $$dists; do \
+           rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \
+         done; \
+       else \
+         : ; \
+       fi
+
+install-strip: install
+
+installdirs:
+       if { test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; } \
+          && test '@USE_INCLUDED_LIBINTL@' = yes; then \
+         $(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir); \
+       else \
+         : ; \
+       fi
+       if test "$(PACKAGE)" = "gettext-tools" \
+          && test '@USE_INCLUDED_LIBINTL@' = no \
+          && test @GLIBC2@ != no; then \
+         $(mkinstalldirs) $(DESTDIR)$(libdir); \
+       else \
+         : ; \
+       fi
+       if test '@USE_INCLUDED_LIBINTL@' = yes; then \
+         test @GLIBC21@ != no || $(mkinstalldirs) $(DESTDIR)$(libdir); \
+         $(mkinstalldirs) $(DESTDIR)$(localedir); \
+       else \
+         : ; \
+       fi
+       if test "$(PACKAGE)" = "gettext-tools"; then \
+         $(mkinstalldirs) $(DESTDIR)$(gettextsrcdir); \
+       else \
+         : ; \
+       fi
+
+# Define this as empty until I found a useful application.
+installcheck:
+
+uninstall:
+       if { test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; } \
+          && test '@USE_INCLUDED_LIBINTL@' = yes; then \
+         rm -f $(DESTDIR)$(includedir)/libintl.h; \
+         $(LIBTOOL) --mode=uninstall \
+           rm -f $(DESTDIR)$(libdir)/libintl.$la; \
+       else \
+         : ; \
+       fi
+       if test "$(PACKAGE)" = "gettext-tools" \
+          && test '@USE_INCLUDED_LIBINTL@' = no \
+          && test @GLIBC2@ != no; then \
+         rm -f $(DESTDIR)$(libdir)/preloadable_libintl.so; \
+       else \
+         : ; \
+       fi
+       if test '@USE_INCLUDED_LIBINTL@' = yes; then \
+         if test -f $(DESTDIR)$(libdir)/charset.alias; then \
+           temp=$(DESTDIR)$(libdir)/t-charset.alias; \
+           dest=$(DESTDIR)$(libdir)/charset.alias; \
+           sed -f ref-del.sed $$dest > $$temp; \
+           if grep '^# Packages using this file: $$' $$temp > /dev/null; then \
+             rm -f $$dest; \
+           else \
+             $(INSTALL_DATA) $$temp $$dest; \
+           fi; \
+           rm -f $$temp; \
+         fi; \
+         if test -f $(DESTDIR)$(localedir)/locale.alias; then \
+           temp=$(DESTDIR)$(localedir)/t-locale.alias; \
+           dest=$(DESTDIR)$(localedir)/locale.alias; \
+           sed -f ref-del.sed $$dest > $$temp; \
+           if grep '^# Packages using this file: $$' $$temp > /dev/null; then \
+             rm -f $$dest; \
+           else \
+             $(INSTALL_DATA) $$temp $$dest; \
+           fi; \
+           rm -f $$temp; \
+         fi; \
+       else \
+         : ; \
+       fi
+       if test "$(PACKAGE)" = "gettext-tools"; then \
+         for file in VERSION ChangeLog COPYING.LIB-2.0 COPYING.LIB-2.1 $(DISTFILES.common) $(DISTFILES.generated); do \
+           rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \
+         done; \
+       else \
+         : ; \
+       fi
+
+info dvi ps pdf html:
+
+$(OBJECTS): ../config.h libgnuintl.h
+bindtextdom.$lo dcgettext.$lo dcigettext.$lo dcngettext.$lo dgettext.$lo dngettext.$lo finddomain.$lo gettext.$lo intl-compat.$lo loadmsgcat.$lo localealias.$lo ngettext.$lo textdomain.$lo: $(srcdir)/gettextP.h $(srcdir)/gmo.h $(srcdir)/loadinfo.h
+dcigettext.$lo loadmsgcat.$lo: $(srcdir)/hash-string.h
+explodename.$lo l10nflist.$lo: $(srcdir)/loadinfo.h
+dcigettext.$lo loadmsgcat.$lo plural.$lo plural-exp.$lo: $(srcdir)/plural-exp.h
+dcigettext.$lo: $(srcdir)/eval-plural.h
+localcharset.$lo: $(srcdir)/localcharset.h
+localealias.$lo localcharset.$lo relocatable.$lo: $(srcdir)/relocatable.h
+printf.$lo: $(srcdir)/printf-args.h $(srcdir)/printf-args.c $(srcdir)/printf-parse.h $(srcdir)/wprintf-parse.h $(srcdir)/xsize.h $(srcdir)/printf-parse.c $(srcdir)/vasnprintf.h $(srcdir)/vasnwprintf.h $(srcdir)/vasnprintf.c
+
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES)
+       here=`pwd`; cd $(srcdir) && etags -o $$here/TAGS $(HEADERS) $(SOURCES)
+
+ctags: CTAGS
+
+CTAGS: $(HEADERS) $(SOURCES)
+       here=`pwd`; cd $(srcdir) && ctags -o $$here/CTAGS $(HEADERS) $(SOURCES)
+
+id: ID
+
+ID: $(HEADERS) $(SOURCES)
+       here=`pwd`; cd $(srcdir) && mkid -f$$here/ID $(HEADERS) $(SOURCES)
+
+
+mostlyclean:
+       rm -f *.a *.la *.o *.obj *.lo core core.*
+       rm -f libgnuintl.h libintl.h charset.alias ref-add.sed ref-del.sed
+       rm -f -r .libs _libs
+
+clean: mostlyclean
+
+distclean: clean
+       rm -f Makefile ID TAGS
+       if test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; then \
+         rm -f ChangeLog.inst $(DISTFILES.normal); \
+       else \
+         : ; \
+       fi
+
+maintainer-clean: distclean
+       @echo "This command is intended for maintainers to use;"
+       @echo "it deletes files that may require special tools to rebuild."
+
+
+# GNU gettext needs not contain the file `VERSION' but contains some
+# other files which should not be distributed in other packages.
+distdir = ../$(PACKAGE)-$(VERSION)/$(subdir)
+dist distdir: Makefile
+       if test "$(PACKAGE)" = "gettext-tools"; then \
+         : ; \
+       else \
+         if test "$(PACKAGE)" = "gettext-runtime"; then \
+           additional="$(DISTFILES.gettext)"; \
+         else \
+           additional="$(DISTFILES.normal)"; \
+         fi; \
+         $(MAKE) $(DISTFILES.common) $(DISTFILES.generated) $$additional; \
+         for file in ChangeLog $(DISTFILES.common) $(DISTFILES.generated) $$additional; do \
+           if test -f $$file; then dir=.; else dir=$(srcdir); fi; \
+           cp -p $$dir/$$file $(distdir) || test $$file = Makefile.in || exit 1; \
+         done; \
+       fi
+
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+       cd $(top_builddir) && $(SHELL) ./config.status
+# This would be more efficient, but doesn't work any more with autoconf-2.57,
+# when AC_CONFIG_FILES([intl/Makefile:somedir/Makefile.in]) is used.
+#      cd $(top_builddir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
+
+# Tell versions [3.59,3.63) of GNU make not to export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/intl/VERSION b/intl/VERSION
new file mode 100644 (file)
index 0000000..615910c
--- /dev/null
@@ -0,0 +1 @@
+GNU gettext library from gettext-0.14.4
diff --git a/intl/bindtextdom.c b/intl/bindtextdom.c
new file mode 100644 (file)
index 0000000..dcdc400
--- /dev/null
@@ -0,0 +1,363 @@
+/* Implementation of the bindtextdomain(3) function
+   Copyright (C) 1995-1998, 2000-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef _LIBC
+# include <libintl.h>
+#else
+# include "libgnuintl.h"
+#endif
+#include "gettextP.h"
+
+#ifdef _LIBC
+/* We have to handle multi-threaded applications.  */
+# include <bits/libc-lock.h>
+#else
+/* Provide dummy implementation if this is outside glibc.  */
+# define __libc_rwlock_define(CLASS, NAME)
+# define __libc_rwlock_wrlock(NAME)
+# define __libc_rwlock_unlock(NAME)
+#endif
+
+/* The internal variables in the standalone libintl.a must have different
+   names than the internal variables in GNU libc, otherwise programs
+   using libintl.a cannot be linked statically.  */
+#if !defined _LIBC
+# define _nl_default_dirname libintl_nl_default_dirname
+# define _nl_domain_bindings libintl_nl_domain_bindings
+#endif
+
+/* Some compilers, like SunOS4 cc, don't have offsetof in <stddef.h>.  */
+#ifndef offsetof
+# define offsetof(type,ident) ((size_t)&(((type*)0)->ident))
+#endif
+
+/* @@ end of prolog @@ */
+
+/* Contains the default location of the message catalogs.  */
+extern const char _nl_default_dirname[];
+#ifdef _LIBC
+extern const char _nl_default_dirname_internal[] attribute_hidden;
+#else
+# define INTUSE(name) name
+#endif
+
+/* List with bindings of specific domains.  */
+extern struct binding *_nl_domain_bindings;
+
+/* Lock variable to protect the global data in the gettext implementation.  */
+__libc_rwlock_define (extern, _nl_state_lock attribute_hidden)
+
+
+/* Names for the libintl functions are a problem.  They must not clash
+   with existing names and they should follow ANSI C.  But this source
+   code is also used in GNU C Library where the names have a __
+   prefix.  So we have to make a difference here.  */
+#ifdef _LIBC
+# define BINDTEXTDOMAIN __bindtextdomain
+# define BIND_TEXTDOMAIN_CODESET __bind_textdomain_codeset
+# ifndef strdup
+#  define strdup(str) __strdup (str)
+# endif
+#else
+# define BINDTEXTDOMAIN libintl_bindtextdomain
+# define BIND_TEXTDOMAIN_CODESET libintl_bind_textdomain_codeset
+#endif
+
+/* Specifies the directory name *DIRNAMEP and the output codeset *CODESETP
+   to be used for the DOMAINNAME message catalog.
+   If *DIRNAMEP or *CODESETP is NULL, the corresponding attribute is not
+   modified, only the current value is returned.
+   If DIRNAMEP or CODESETP is NULL, the corresponding attribute is neither
+   modified nor returned.  */
+static void
+set_binding_values (const char *domainname,
+                   const char **dirnamep, const char **codesetp)
+{
+  struct binding *binding;
+  int modified;
+
+  /* Some sanity checks.  */
+  if (domainname == NULL || domainname[0] == '\0')
+    {
+      if (dirnamep)
+       *dirnamep = NULL;
+      if (codesetp)
+       *codesetp = NULL;
+      return;
+    }
+
+  __libc_rwlock_wrlock (_nl_state_lock);
+
+  modified = 0;
+
+  for (binding = _nl_domain_bindings; binding != NULL; binding = binding->next)
+    {
+      int compare = strcmp (domainname, binding->domainname);
+      if (compare == 0)
+       /* We found it!  */
+       break;
+      if (compare < 0)
+       {
+         /* It is not in the list.  */
+         binding = NULL;
+         break;
+       }
+    }
+
+  if (binding != NULL)
+    {
+      if (dirnamep)
+       {
+         const char *dirname = *dirnamep;
+
+         if (dirname == NULL)
+           /* The current binding has be to returned.  */
+           *dirnamep = binding->dirname;
+         else
+           {
+             /* The domain is already bound.  If the new value and the old
+                one are equal we simply do nothing.  Otherwise replace the
+                old binding.  */
+             char *result = binding->dirname;
+             if (strcmp (dirname, result) != 0)
+               {
+                 if (strcmp (dirname, INTUSE(_nl_default_dirname)) == 0)
+                   result = (char *) INTUSE(_nl_default_dirname);
+                 else
+                   {
+#if defined _LIBC || defined HAVE_STRDUP
+                     result = strdup (dirname);
+#else
+                     size_t len = strlen (dirname) + 1;
+                     result = (char *) malloc (len);
+                     if (__builtin_expect (result != NULL, 1))
+                       memcpy (result, dirname, len);
+#endif
+                   }
+
+                 if (__builtin_expect (result != NULL, 1))
+                   {
+                     if (binding->dirname != INTUSE(_nl_default_dirname))
+                       free (binding->dirname);
+
+                     binding->dirname = result;
+                     modified = 1;
+                   }
+               }
+             *dirnamep = result;
+           }
+       }
+
+      if (codesetp)
+       {
+         const char *codeset = *codesetp;
+
+         if (codeset == NULL)
+           /* The current binding has be to returned.  */
+           *codesetp = binding->codeset;
+         else
+           {
+             /* The domain is already bound.  If the new value and the old
+                one are equal we simply do nothing.  Otherwise replace the
+                old binding.  */
+             char *result = binding->codeset;
+             if (result == NULL || strcmp (codeset, result) != 0)
+               {
+#if defined _LIBC || defined HAVE_STRDUP
+                 result = strdup (codeset);
+#else
+                 size_t len = strlen (codeset) + 1;
+                 result = (char *) malloc (len);
+                 if (__builtin_expect (result != NULL, 1))
+                   memcpy (result, codeset, len);
+#endif
+
+                 if (__builtin_expect (result != NULL, 1))
+                   {
+                     if (binding->codeset != NULL)
+                       free (binding->codeset);
+
+                     binding->codeset = result;
+                     binding->codeset_cntr++;
+                     modified = 1;
+                   }
+               }
+             *codesetp = result;
+           }
+       }
+    }
+  else if ((dirnamep == NULL || *dirnamep == NULL)
+          && (codesetp == NULL || *codesetp == NULL))
+    {
+      /* Simply return the default values.  */
+      if (dirnamep)
+       *dirnamep = INTUSE(_nl_default_dirname);
+      if (codesetp)
+       *codesetp = NULL;
+    }
+  else
+    {
+      /* We have to create a new binding.  */
+      size_t len = strlen (domainname) + 1;
+      struct binding *new_binding =
+       (struct binding *) malloc (offsetof (struct binding, domainname) + len);
+
+      if (__builtin_expect (new_binding == NULL, 0))
+       goto failed;
+
+      memcpy (new_binding->domainname, domainname, len);
+
+      if (dirnamep)
+       {
+         const char *dirname = *dirnamep;
+
+         if (dirname == NULL)
+           /* The default value.  */
+           dirname = INTUSE(_nl_default_dirname);
+         else
+           {
+             if (strcmp (dirname, INTUSE(_nl_default_dirname)) == 0)
+               dirname = INTUSE(_nl_default_dirname);
+             else
+               {
+                 char *result;
+#if defined _LIBC || defined HAVE_STRDUP
+                 result = strdup (dirname);
+                 if (__builtin_expect (result == NULL, 0))
+                   goto failed_dirname;
+#else
+                 size_t len = strlen (dirname) + 1;
+                 result = (char *) malloc (len);
+                 if (__builtin_expect (result == NULL, 0))
+                   goto failed_dirname;
+                 memcpy (result, dirname, len);
+#endif
+                 dirname = result;
+               }
+           }
+         *dirnamep = dirname;
+         new_binding->dirname = (char *) dirname;
+       }
+      else
+       /* The default value.  */
+       new_binding->dirname = (char *) INTUSE(_nl_default_dirname);
+
+      new_binding->codeset_cntr = 0;
+
+      if (codesetp)
+       {
+         const char *codeset = *codesetp;
+
+         if (codeset != NULL)
+           {
+             char *result;
+
+#if defined _LIBC || defined HAVE_STRDUP
+             result = strdup (codeset);
+             if (__builtin_expect (result == NULL, 0))
+               goto failed_codeset;
+#else
+             size_t len = strlen (codeset) + 1;
+             result = (char *) malloc (len);
+             if (__builtin_expect (result == NULL, 0))
+               goto failed_codeset;
+             memcpy (result, codeset, len);
+#endif
+             codeset = result;
+             new_binding->codeset_cntr++;
+           }
+         *codesetp = codeset;
+         new_binding->codeset = (char *) codeset;
+       }
+      else
+       new_binding->codeset = NULL;
+
+      /* Now enqueue it.  */
+      if (_nl_domain_bindings == NULL
+         || strcmp (domainname, _nl_domain_bindings->domainname) < 0)
+       {
+         new_binding->next = _nl_domain_bindings;
+         _nl_domain_bindings = new_binding;
+       }
+      else
+       {
+         binding = _nl_domain_bindings;
+         while (binding->next != NULL
+                && strcmp (domainname, binding->next->domainname) > 0)
+           binding = binding->next;
+
+         new_binding->next = binding->next;
+         binding->next = new_binding;
+       }
+
+      modified = 1;
+
+      /* Here we deal with memory allocation failures.  */
+      if (0)
+       {
+       failed_codeset:
+         if (new_binding->dirname != INTUSE(_nl_default_dirname))
+           free (new_binding->dirname);
+       failed_dirname:
+         free (new_binding);
+       failed:
+         if (dirnamep)
+           *dirnamep = NULL;
+         if (codesetp)
+           *codesetp = NULL;
+       }
+    }
+
+  /* If we modified any binding, we flush the caches.  */
+  if (modified)
+    ++_nl_msg_cat_cntr;
+
+  __libc_rwlock_unlock (_nl_state_lock);
+}
+
+/* Specify that the DOMAINNAME message catalog will be found
+   in DIRNAME rather than in the system locale data base.  */
+char *
+BINDTEXTDOMAIN (const char *domainname, const char *dirname)
+{
+  set_binding_values (domainname, &dirname, NULL);
+  return (char *) dirname;
+}
+
+/* Specify the character encoding in which the messages from the
+   DOMAINNAME message catalog will be returned.  */
+char *
+BIND_TEXTDOMAIN_CODESET (const char *domainname, const char *codeset)
+{
+  set_binding_values (domainname, NULL, &codeset);
+  return (char *) codeset;
+}
+
+#ifdef _LIBC
+/* Aliases for function names in GNU C Library.  */
+weak_alias (__bindtextdomain, bindtextdomain);
+weak_alias (__bind_textdomain_codeset, bind_textdomain_codeset);
+#endif
diff --git a/intl/config.charset b/intl/config.charset
new file mode 100755 (executable)
index 0000000..5036580
--- /dev/null
@@ -0,0 +1,638 @@
+#! /bin/sh
+# Output a system dependent table of character encoding aliases.
+#
+#   Copyright (C) 2000-2004 Free Software Foundation, Inc.
+#
+#   This program is free software; you can redistribute it and/or modify it
+#   under the terms of the GNU Library General Public License as published
+#   by the Free Software Foundation; either version 2, or (at your option)
+#   any later version.
+#
+#   This program 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
+#   Library General Public License for more details.
+#
+#   You should have received a copy of the GNU Library General Public
+#   License along with this program; if not, write to the Free Software
+#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+#   USA.
+#
+# The table consists of lines of the form
+#    ALIAS  CANONICAL
+#
+# ALIAS is the (system dependent) result of "nl_langinfo (CODESET)".
+# ALIAS is compared in a case sensitive way.
+#
+# CANONICAL is the GNU canonical name for this character encoding.
+# It must be an encoding supported by libiconv. Support by GNU libc is
+# also desirable. CANONICAL is case insensitive. Usually an upper case
+# MIME charset name is preferred.
+# The current list of GNU canonical charset names is as follows.
+#
+#       name              MIME?             used by which systems
+#   ASCII, ANSI_X3.4-1968       glibc solaris freebsd darwin
+#   ISO-8859-1              Y   glibc aix hpux irix osf solaris freebsd darwin
+#   ISO-8859-2              Y   glibc aix hpux irix osf solaris freebsd darwin
+#   ISO-8859-3              Y   glibc solaris
+#   ISO-8859-4              Y   osf solaris freebsd darwin
+#   ISO-8859-5              Y   glibc aix hpux irix osf solaris freebsd darwin
+#   ISO-8859-6              Y   glibc aix hpux solaris
+#   ISO-8859-7              Y   glibc aix hpux irix osf solaris darwin
+#   ISO-8859-8              Y   glibc aix hpux osf solaris
+#   ISO-8859-9              Y   glibc aix hpux irix osf solaris darwin
+#   ISO-8859-13                 glibc darwin
+#   ISO-8859-14                 glibc
+#   ISO-8859-15                 glibc aix osf solaris freebsd darwin
+#   KOI8-R                  Y   glibc solaris freebsd darwin
+#   KOI8-U                  Y   glibc freebsd darwin
+#   KOI8-T                      glibc
+#   CP437                       dos
+#   CP775                       dos
+#   CP850                       aix osf dos
+#   CP852                       dos
+#   CP855                       dos
+#   CP856                       aix
+#   CP857                       dos
+#   CP861                       dos
+#   CP862                       dos
+#   CP864                       dos
+#   CP865                       dos
+#   CP866                       freebsd darwin dos
+#   CP869                       dos
+#   CP874                       woe32 dos
+#   CP922                       aix
+#   CP932                       aix woe32 dos
+#   CP943                       aix
+#   CP949                       osf woe32 dos
+#   CP950                       woe32 dos
+#   CP1046                      aix
+#   CP1124                      aix
+#   CP1125                      dos
+#   CP1129                      aix
+#   CP1250                      woe32
+#   CP1251                      glibc solaris darwin woe32
+#   CP1252                      aix woe32
+#   CP1253                      woe32
+#   CP1254                      woe32
+#   CP1255                      glibc woe32
+#   CP1256                      woe32
+#   CP1257                      woe32
+#   GB2312                  Y   glibc aix hpux irix solaris freebsd darwin
+#   EUC-JP                  Y   glibc aix hpux irix osf solaris freebsd darwin
+#   EUC-KR                  Y   glibc aix hpux irix osf solaris freebsd darwin
+#   EUC-TW                      glibc aix hpux irix osf solaris
+#   BIG5                    Y   glibc aix hpux osf solaris freebsd darwin
+#   BIG5-HKSCS                  glibc solaris
+#   GBK                         glibc aix osf solaris woe32 dos
+#   GB18030                     glibc solaris
+#   SHIFT_JIS               Y   hpux osf solaris freebsd darwin
+#   JOHAB                       glibc solaris woe32
+#   TIS-620                     glibc aix hpux osf solaris
+#   VISCII                  Y   glibc
+#   TCVN5712-1                  glibc
+#   GEORGIAN-PS                 glibc
+#   HP-ROMAN8                   hpux
+#   HP-ARABIC8                  hpux
+#   HP-GREEK8                   hpux
+#   HP-HEBREW8                  hpux
+#   HP-TURKISH8                 hpux
+#   HP-KANA8                    hpux
+#   DEC-KANJI                   osf
+#   DEC-HANYU                   osf
+#   UTF-8                   Y   glibc aix hpux osf solaris darwin
+#
+# Note: Names which are not marked as being a MIME name should not be used in
+# Internet protocols for information interchange (mail, news, etc.).
+#
+# Note: ASCII and ANSI_X3.4-1968 are synonymous canonical names. Applications
+# must understand both names and treat them as equivalent.
+#
+# The first argument passed to this file is the canonical host specification,
+#    CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or
+#    CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+
+host="$1"
+os=`echo "$host" | sed -e 's/^[^-]*-[^-]*-\(.*\)$/\1/'`
+echo "# This file contains a table of character encoding aliases,"
+echo "# suitable for operating system '${os}'."
+echo "# It was automatically generated from config.charset."
+# List of references, updated during installation:
+echo "# Packages using this file: "
+case "$os" in
+    linux-gnulibc1*)
+       # Linux libc5 doesn't have nl_langinfo(CODESET); therefore
+       # localcharset.c falls back to using the full locale name
+       # from the environment variables.
+       echo "C ASCII"
+       echo "POSIX ASCII"
+       for l in af af_ZA ca ca_ES da da_DK de de_AT de_BE de_CH de_DE de_LU \
+                en en_AU en_BW en_CA en_DK en_GB en_IE en_NZ en_US en_ZA \
+                en_ZW es es_AR es_BO es_CL es_CO es_DO es_EC es_ES es_GT \
+                es_HN es_MX es_PA es_PE es_PY es_SV es_US es_UY es_VE et \
+                et_EE eu eu_ES fi fi_FI fo fo_FO fr fr_BE fr_CA fr_CH fr_FR \
+                fr_LU ga ga_IE gl gl_ES id id_ID in in_ID is is_IS it it_CH \
+                it_IT kl kl_GL nl nl_BE nl_NL no no_NO pt pt_BR pt_PT sv \
+                sv_FI sv_SE; do
+         echo "$l ISO-8859-1"
+         echo "$l.iso-8859-1 ISO-8859-1"
+         echo "$l.iso-8859-15 ISO-8859-15"
+         echo "$l.iso-8859-15@euro ISO-8859-15"
+         echo "$l@euro ISO-8859-15"
+         echo "$l.cp-437 CP437"
+         echo "$l.cp-850 CP850"
+         echo "$l.cp-1252 CP1252"
+         echo "$l.cp-1252@euro CP1252"
+         #echo "$l.atari-st ATARI-ST" # not a commonly used encoding
+         echo "$l.utf-8 UTF-8"
+         echo "$l.utf-8@euro UTF-8"
+       done
+       for l in cs cs_CZ hr hr_HR hu hu_HU pl pl_PL ro ro_RO sk sk_SK sl \
+                sl_SI sr sr_CS sr_YU; do
+         echo "$l ISO-8859-2"
+         echo "$l.iso-8859-2 ISO-8859-2"
+         echo "$l.cp-852 CP852"
+         echo "$l.cp-1250 CP1250"
+         echo "$l.utf-8 UTF-8"
+       done
+       for l in mk mk_MK ru ru_RU; do
+         echo "$l ISO-8859-5"
+         echo "$l.iso-8859-5 ISO-8859-5"
+         echo "$l.koi8-r KOI8-R"
+         echo "$l.cp-866 CP866"
+         echo "$l.cp-1251 CP1251"
+         echo "$l.utf-8 UTF-8"
+       done
+       for l in ar ar_SA; do
+         echo "$l ISO-8859-6"
+         echo "$l.iso-8859-6 ISO-8859-6"
+         echo "$l.cp-864 CP864"
+         #echo "$l.cp-868 CP868" # not a commonly used encoding
+         echo "$l.cp-1256 CP1256"
+         echo "$l.utf-8 UTF-8"
+       done
+       for l in el el_GR gr gr_GR; do
+         echo "$l ISO-8859-7"
+         echo "$l.iso-8859-7 ISO-8859-7"
+         echo "$l.cp-869 CP869"
+         echo "$l.cp-1253 CP1253"
+         echo "$l.cp-1253@euro CP1253"
+         echo "$l.utf-8 UTF-8"
+         echo "$l.utf-8@euro UTF-8"
+       done
+       for l in he he_IL iw iw_IL; do
+         echo "$l ISO-8859-8"
+         echo "$l.iso-8859-8 ISO-8859-8"
+         echo "$l.cp-862 CP862"
+         echo "$l.cp-1255 CP1255"
+         echo "$l.utf-8 UTF-8"
+       done
+       for l in tr tr_TR; do
+         echo "$l ISO-8859-9"
+         echo "$l.iso-8859-9 ISO-8859-9"
+         echo "$l.cp-857 CP857"
+         echo "$l.cp-1254 CP1254"
+         echo "$l.utf-8 UTF-8"
+       done
+       for l in lt lt_LT lv lv_LV; do
+         #echo "$l BALTIC" # not a commonly used encoding, wrong encoding name
+         echo "$l ISO-8859-13"
+       done
+       for l in ru_UA uk uk_UA; do
+         echo "$l KOI8-U"
+       done
+       for l in zh zh_CN; do
+         #echo "$l GB_2312-80" # not a commonly used encoding, wrong encoding name
+         echo "$l GB2312"
+       done
+       for l in ja ja_JP ja_JP.EUC; do
+         echo "$l EUC-JP"
+       done
+       for l in ko ko_KR; do
+         echo "$l EUC-KR"
+       done
+       for l in th th_TH; do
+         echo "$l TIS-620"
+       done
+       for l in fa fa_IR; do
+         #echo "$l ISIRI-3342" # a broken encoding
+         echo "$l.utf-8 UTF-8"
+       done
+       ;;
+    linux* | *-gnu*)
+       # With glibc-2.1 or newer, we don't need any canonicalization,
+       # because glibc has iconv and both glibc and libiconv support all
+       # GNU canonical names directly. Therefore, the Makefile does not
+       # need to install the alias file at all.
+       # The following applies only to glibc-2.0.x and older libcs.
+       echo "ISO_646.IRV:1983 ASCII"
+       ;;
+    aix*)
+       echo "ISO8859-1 ISO-8859-1"
+       echo "ISO8859-2 ISO-8859-2"
+       echo "ISO8859-5 ISO-8859-5"
+       echo "ISO8859-6 ISO-8859-6"
+       echo "ISO8859-7 ISO-8859-7"
+       echo "ISO8859-8 ISO-8859-8"
+       echo "ISO8859-9 ISO-8859-9"
+       echo "ISO8859-15 ISO-8859-15"
+       echo "IBM-850 CP850"
+       echo "IBM-856 CP856"
+       echo "IBM-921 ISO-8859-13"
+       echo "IBM-922 CP922"
+       echo "IBM-932 CP932"
+       echo "IBM-943 CP943"
+       echo "IBM-1046 CP1046"
+       echo "IBM-1124 CP1124"
+       echo "IBM-1129 CP1129"
+       echo "IBM-1252 CP1252"
+       echo "IBM-eucCN GB2312"
+       echo "IBM-eucJP EUC-JP"
+       echo "IBM-eucKR EUC-KR"
+       echo "IBM-eucTW EUC-TW"
+       echo "big5 BIG5"
+       echo "GBK GBK"
+       echo "TIS-620 TIS-620"
+       echo "UTF-8 UTF-8"
+       ;;
+    hpux*)
+       echo "iso88591 ISO-8859-1"
+       echo "iso88592 ISO-8859-2"
+       echo "iso88595 ISO-8859-5"
+       echo "iso88596 ISO-8859-6"
+       echo "iso88597 ISO-8859-7"
+       echo "iso88598 ISO-8859-8"
+       echo "iso88599 ISO-8859-9"
+       echo "iso885915 ISO-8859-15"
+       echo "roman8 HP-ROMAN8"
+       echo "arabic8 HP-ARABIC8"
+       echo "greek8 HP-GREEK8"
+       echo "hebrew8 HP-HEBREW8"
+       echo "turkish8 HP-TURKISH8"
+       echo "kana8 HP-KANA8"
+       echo "tis620 TIS-620"
+       echo "big5 BIG5"
+       echo "eucJP EUC-JP"
+       echo "eucKR EUC-KR"
+       echo "eucTW EUC-TW"
+       echo "hp15CN GB2312"
+       #echo "ccdc ?" # what is this?
+       echo "SJIS SHIFT_JIS"
+       echo "utf8 UTF-8"
+       ;;
+    irix*)
+       echo "ISO8859-1 ISO-8859-1"
+       echo "ISO8859-2 ISO-8859-2"
+       echo "ISO8859-5 ISO-8859-5"
+       echo "ISO8859-7 ISO-8859-7"
+       echo "ISO8859-9 ISO-8859-9"
+       echo "eucCN GB2312"
+       echo "eucJP EUC-JP"
+       echo "eucKR EUC-KR"
+       echo "eucTW EUC-TW"
+       ;;
+    osf*)
+       echo "ISO8859-1 ISO-8859-1"
+       echo "ISO8859-2 ISO-8859-2"
+       echo "ISO8859-4 ISO-8859-4"
+       echo "ISO8859-5 ISO-8859-5"
+       echo "ISO8859-7 ISO-8859-7"
+       echo "ISO8859-8 ISO-8859-8"
+       echo "ISO8859-9 ISO-8859-9"
+       echo "ISO8859-15 ISO-8859-15"
+       echo "cp850 CP850"
+       echo "big5 BIG5"
+       echo "dechanyu DEC-HANYU"
+       echo "dechanzi GB2312"
+       echo "deckanji DEC-KANJI"
+       echo "deckorean EUC-KR"
+       echo "eucJP EUC-JP"
+       echo "eucKR EUC-KR"
+       echo "eucTW EUC-TW"
+       echo "GBK GBK"
+       echo "KSC5601 CP949"
+       echo "sdeckanji EUC-JP"
+       echo "SJIS SHIFT_JIS"
+       echo "TACTIS TIS-620"
+       echo "UTF-8 UTF-8"
+       ;;
+    solaris*)
+       echo "646 ASCII"
+       echo "ISO8859-1 ISO-8859-1"
+       echo "ISO8859-2 ISO-8859-2"
+       echo "ISO8859-3 ISO-8859-3"
+       echo "ISO8859-4 ISO-8859-4"
+       echo "ISO8859-5 ISO-8859-5"
+       echo "ISO8859-6 ISO-8859-6"
+       echo "ISO8859-7 ISO-8859-7"
+       echo "ISO8859-8 ISO-8859-8"
+       echo "ISO8859-9 ISO-8859-9"
+       echo "ISO8859-15 ISO-8859-15"
+       echo "koi8-r KOI8-R"
+       echo "ansi-1251 CP1251"
+       echo "BIG5 BIG5"
+       echo "Big5-HKSCS BIG5-HKSCS"
+       echo "gb2312 GB2312"
+       echo "GBK GBK"
+       echo "GB18030 GB18030"
+       echo "cns11643 EUC-TW"
+       echo "5601 EUC-KR"
+       echo "ko_KR.johap92 JOHAB"
+       echo "eucJP EUC-JP"
+       echo "PCK SHIFT_JIS"
+       echo "TIS620.2533 TIS-620"
+       #echo "sun_eu_greek ?" # what is this?
+       echo "UTF-8 UTF-8"
+       ;;
+    freebsd* | os2*)
+       # FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore
+       # localcharset.c falls back to using the full locale name
+       # from the environment variables.
+       # Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just
+       # reuse FreeBSD's locale data for OS/2.
+       echo "C ASCII"
+       echo "US-ASCII ASCII"
+       for l in la_LN lt_LN; do
+         echo "$l.ASCII ASCII"
+       done
+       for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \
+                fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT la_LN \
+                lt_LN nl_BE nl_NL no_NO pt_PT sv_SE; do
+         echo "$l.ISO_8859-1 ISO-8859-1"
+         echo "$l.DIS_8859-15 ISO-8859-15"
+       done
+       for l in cs_CZ hr_HR hu_HU la_LN lt_LN pl_PL sl_SI; do
+         echo "$l.ISO_8859-2 ISO-8859-2"
+       done
+       for l in la_LN lt_LT; do
+         echo "$l.ISO_8859-4 ISO-8859-4"
+       done
+       for l in ru_RU ru_SU; do
+         echo "$l.KOI8-R KOI8-R"
+         echo "$l.ISO_8859-5 ISO-8859-5"
+         echo "$l.CP866 CP866"
+       done
+       echo "uk_UA.KOI8-U KOI8-U"
+       echo "zh_TW.BIG5 BIG5"
+       echo "zh_TW.Big5 BIG5"
+       echo "zh_CN.EUC GB2312"
+       echo "ja_JP.EUC EUC-JP"
+       echo "ja_JP.SJIS SHIFT_JIS"
+       echo "ja_JP.Shift_JIS SHIFT_JIS"
+       echo "ko_KR.EUC EUC-KR"
+       ;;
+    netbsd*)
+       echo "646 ASCII"
+       echo "ISO8859-1 ISO-8859-1"
+       echo "ISO8859-2 ISO-8859-2"
+       echo "ISO8859-4 ISO-8859-4"
+       echo "ISO8859-5 ISO-8859-5"
+       echo "ISO8859-15 ISO-8859-15"
+       echo "eucCN GB2312"
+       echo "eucJP EUC-JP"
+       echo "eucKR EUC-KR"
+       echo "eucTW EUC-TW"
+       echo "BIG5 BIG5"
+       echo "SJIS SHIFT_JIS"
+       ;;
+    darwin[56]*)
+       # Darwin 6.8 doesn't have nl_langinfo(CODESET); therefore
+       # localcharset.c falls back to using the full locale name
+       # from the environment variables.
+       echo "C ASCII"
+       for l in en_AU en_CA en_GB en_US la_LN; do
+         echo "$l.US-ASCII ASCII"
+       done
+       for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \
+                fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT nl_BE \
+                nl_NL no_NO pt_PT sv_SE; do
+         echo "$l ISO-8859-1"
+         echo "$l.ISO8859-1 ISO-8859-1"
+         echo "$l.ISO8859-15 ISO-8859-15"
+       done
+       for l in la_LN; do
+         echo "$l.ISO8859-1 ISO-8859-1"
+         echo "$l.ISO8859-15 ISO-8859-15"
+       done
+       for l in cs_CZ hr_HR hu_HU la_LN pl_PL sl_SI; do
+         echo "$l.ISO8859-2 ISO-8859-2"
+       done
+       for l in la_LN lt_LT; do
+         echo "$l.ISO8859-4 ISO-8859-4"
+       done
+       for l in ru_RU; do
+         echo "$l.KOI8-R KOI8-R"
+         echo "$l.ISO8859-5 ISO-8859-5"
+         echo "$l.CP866 CP866"
+       done
+       for l in bg_BG; do
+         echo "$l.CP1251 CP1251"
+       done
+       echo "uk_UA.KOI8-U KOI8-U"
+       echo "zh_TW.BIG5 BIG5"
+       echo "zh_TW.Big5 BIG5"
+       echo "zh_CN.EUC GB2312"
+       echo "ja_JP.EUC EUC-JP"
+       echo "ja_JP.SJIS SHIFT_JIS"
+       echo "ko_KR.EUC EUC-KR"
+       ;;
+    darwin*)
+       # Darwin 7.5 has nl_langinfo(CODESET), but it is useless:
+       # - It returns the empty string when LANG is set to a locale of the
+       #   form ll_CC, although ll_CC/LC_CTYPE is a symlink to an UTF-8
+       #   LC_CTYPE file.
+       # - The environment variables LANG, LC_CTYPE, LC_ALL are not set by
+       #   the system; nl_langinfo(CODESET) returns "US-ASCII" in this case.
+       # - The documentation says:
+       #     "... all code that calls BSD system routines should ensure
+       #      that the const *char parameters of these routines are in UTF-8
+       #      encoding. All BSD system functions expect their string
+       #      parameters to be in UTF-8 encoding and nothing else."
+       #   It also says
+       #     "An additional caveat is that string parameters for files,
+       #      paths, and other file-system entities must be in canonical
+       #      UTF-8. In a canonical UTF-8 Unicode string, all decomposable
+       #      characters are decomposed ..."
+       #   but this is not true: You can pass non-decomposed UTF-8 strings
+       #   to file system functions, and it is the OS which will convert
+       #   them to decomposed UTF-8 before accessing the file system.
+       # - The Apple Terminal application displays UTF-8 by default.
+       # - However, other applications are free to use different encodings:
+       #   - xterm uses ISO-8859-1 by default.
+       #   - TextEdit uses MacRoman by default.
+       # We prefer UTF-8 over decomposed UTF-8-MAC because one should
+       # minimize the use of decomposed Unicode. Unfortunately, through the
+       # Darwin file system, decomposed UTF-8 strings are leaked into user
+       # space nevertheless.
+       echo "* UTF-8"
+       ;;
+    beos*)
+       # BeOS has a single locale, and it has UTF-8 encoding.
+       echo "* UTF-8"
+       ;;
+    msdosdjgpp*)
+       # DJGPP 2.03 doesn't have nl_langinfo(CODESET); therefore
+       # localcharset.c falls back to using the full locale name
+       # from the environment variables.
+       echo "#"
+       echo "# The encodings given here may not all be correct."
+       echo "# If you find that the encoding given for your language and"
+       echo "# country is not the one your DOS machine actually uses, just"
+       echo "# correct it in this file, and send a mail to"
+       echo "# Juan Manuel Guerrero <st001906@hrz1.hrz.tu-darmstadt.de>"
+       echo "# and Bruno Haible <bruno@clisp.org>."
+       echo "#"
+       echo "C ASCII"
+       # ISO-8859-1 languages
+       echo "ca CP850"
+       echo "ca_ES CP850"
+       echo "da CP865"    # not CP850 ??
+       echo "da_DK CP865" # not CP850 ??
+       echo "de CP850"
+       echo "de_AT CP850"
+       echo "de_CH CP850"
+       echo "de_DE CP850"
+       echo "en CP850"
+       echo "en_AU CP850" # not CP437 ??
+       echo "en_CA CP850"
+       echo "en_GB CP850"
+       echo "en_NZ CP437"
+       echo "en_US CP437"
+       echo "en_ZA CP850" # not CP437 ??
+       echo "es CP850"
+       echo "es_AR CP850"
+       echo "es_BO CP850"
+       echo "es_CL CP850"
+       echo "es_CO CP850"
+       echo "es_CR CP850"
+       echo "es_CU CP850"
+       echo "es_DO CP850"
+       echo "es_EC CP850"
+       echo "es_ES CP850"
+       echo "es_GT CP850"
+       echo "es_HN CP850"
+       echo "es_MX CP850"
+       echo "es_NI CP850"
+       echo "es_PA CP850"
+       echo "es_PY CP850"
+       echo "es_PE CP850"
+       echo "es_SV CP850"
+       echo "es_UY CP850"
+       echo "es_VE CP850"
+       echo "et CP850"
+       echo "et_EE CP850"
+       echo "eu CP850"
+       echo "eu_ES CP850"
+       echo "fi CP850"
+       echo "fi_FI CP850"
+       echo "fr CP850"
+       echo "fr_BE CP850"
+       echo "fr_CA CP850"
+       echo "fr_CH CP850"
+       echo "fr_FR CP850"
+       echo "ga CP850"
+       echo "ga_IE CP850"
+       echo "gd CP850"
+       echo "gd_GB CP850"
+       echo "gl CP850"
+       echo "gl_ES CP850"
+       echo "id CP850"    # not CP437 ??
+       echo "id_ID CP850" # not CP437 ??
+       echo "is CP861"    # not CP850 ??
+       echo "is_IS CP861" # not CP850 ??
+       echo "it CP850"
+       echo "it_CH CP850"
+       echo "it_IT CP850"
+       echo "lt CP775"
+       echo "lt_LT CP775"
+       echo "lv CP775"
+       echo "lv_LV CP775"
+       echo "nb CP865"    # not CP850 ??
+       echo "nb_NO CP865" # not CP850 ??
+       echo "nl CP850"
+       echo "nl_BE CP850"
+       echo "nl_NL CP850"
+       echo "nn CP865"    # not CP850 ??
+       echo "nn_NO CP865" # not CP850 ??
+       echo "no CP865"    # not CP850 ??
+       echo "no_NO CP865" # not CP850 ??
+       echo "pt CP850"
+       echo "pt_BR CP850"
+       echo "pt_PT CP850"
+       echo "sv CP850"
+       echo "sv_SE CP850"
+       # ISO-8859-2 languages
+       echo "cs CP852"
+       echo "cs_CZ CP852"
+       echo "hr CP852"
+       echo "hr_HR CP852"
+       echo "hu CP852"
+       echo "hu_HU CP852"
+       echo "pl CP852"
+       echo "pl_PL CP852"
+       echo "ro CP852"
+       echo "ro_RO CP852"
+       echo "sk CP852"
+       echo "sk_SK CP852"
+       echo "sl CP852"
+       echo "sl_SI CP852"
+       echo "sq CP852"
+       echo "sq_AL CP852"
+       echo "sr CP852"    # CP852 or CP866 or CP855 ??
+       echo "sr_CS CP852" # CP852 or CP866 or CP855 ??
+       echo "sr_YU CP852" # CP852 or CP866 or CP855 ??
+       # ISO-8859-3 languages
+       echo "mt CP850"
+       echo "mt_MT CP850"
+       # ISO-8859-5 languages
+       echo "be CP866"
+       echo "be_BE CP866"
+       echo "bg CP866"    # not CP855 ??
+       echo "bg_BG CP866" # not CP855 ??
+       echo "mk CP866"    # not CP855 ??
+       echo "mk_MK CP866" # not CP855 ??
+       echo "ru CP866"
+       echo "ru_RU CP866"
+       echo "uk CP1125"
+       echo "uk_UA CP1125"
+       # ISO-8859-6 languages
+       echo "ar CP864"
+       echo "ar_AE CP864"
+       echo "ar_DZ CP864"
+       echo "ar_EG CP864"
+       echo "ar_IQ CP864"
+       echo "ar_IR CP864"
+       echo "ar_JO CP864"
+       echo "ar_KW CP864"
+       echo "ar_MA CP864"
+       echo "ar_OM CP864"
+       echo "ar_QA CP864"
+       echo "ar_SA CP864"
+       echo "ar_SY CP864"
+       # ISO-8859-7 languages
+       echo "el CP869"
+       echo "el_GR CP869"
+       # ISO-8859-8 languages
+       echo "he CP862"
+       echo "he_IL CP862"
+       # ISO-8859-9 languages
+       echo "tr CP857"
+       echo "tr_TR CP857"
+       # Japanese
+       echo "ja CP932"
+       echo "ja_JP CP932"
+       # Chinese
+       echo "zh_CN GBK"
+       echo "zh_TW CP950" # not CP938 ??
+       # Korean
+       echo "kr CP949"    # not CP934 ??
+       echo "kr_KR CP949" # not CP934 ??
+       # Thai
+       echo "th CP874"
+       echo "th_TH CP874"
+       # Other
+       echo "eo CP850"
+       echo "eo_EO CP850"
+       ;;
+esac
diff --git a/intl/dcgettext.c b/intl/dcgettext.c
new file mode 100644 (file)
index 0000000..850acde
--- /dev/null
@@ -0,0 +1,56 @@
+/* Implementation of the dcgettext(3) function.
+   Copyright (C) 1995-1999, 2000-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "gettextP.h"
+#ifdef _LIBC
+# include <libintl.h>
+#else
+# include "libgnuintl.h"
+#endif
+
+/* @@ end of prolog @@ */
+
+/* Names for the libintl functions are a problem.  They must not clash
+   with existing names and they should follow ANSI C.  But this source
+   code is also used in GNU C Library where the names have a __
+   prefix.  So we have to make a difference here.  */
+#ifdef _LIBC
+# define DCGETTEXT __dcgettext
+# define DCIGETTEXT __dcigettext
+#else
+# define DCGETTEXT libintl_dcgettext
+# define DCIGETTEXT libintl_dcigettext
+#endif
+
+/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
+   locale.  */
+char *
+DCGETTEXT (const char *domainname, const char *msgid, int category)
+{
+  return DCIGETTEXT (domainname, msgid, NULL, 0, 0, category);
+}
+
+#ifdef _LIBC
+/* Alias for function name in GNU C Library.  */
+INTDEF(__dcgettext)
+weak_alias (__dcgettext, dcgettext);
+#endif
diff --git a/intl/dcigettext.c b/intl/dcigettext.c
new file mode 100644 (file)
index 0000000..7f4c12c
--- /dev/null
@@ -0,0 +1,1258 @@
+/* Implementation of the internal dcigettext function.
+   Copyright (C) 1995-1999, 2000-2005 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+/* Tell glibc's <string.h> to provide a prototype for mempcpy().
+   This must come before <config.h> because <config.h> may include
+   <features.h>, and once <features.h> has been included, it's too late.  */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE   1
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/types.h>
+
+#ifdef __GNUC__
+# define alloca __builtin_alloca
+# define HAVE_ALLOCA 1
+#else
+# ifdef _MSC_VER
+#  include <malloc.h>
+#  define alloca _alloca
+# else
+#  if defined HAVE_ALLOCA_H || defined _LIBC
+#   include <alloca.h>
+#  else
+#   ifdef _AIX
+ #pragma alloca
+#   else
+#    ifndef alloca
+char *alloca ();
+#    endif
+#   endif
+#  endif
+# endif
+#endif
+
+#include <errno.h>
+#ifndef errno
+extern int errno;
+#endif
+#ifndef __set_errno
+# define __set_errno(val) errno = (val)
+#endif
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined HAVE_UNISTD_H || defined _LIBC
+# include <unistd.h>
+#endif
+
+#include <locale.h>
+
+#ifdef _LIBC
+  /* Guess whether integer division by zero raises signal SIGFPE.
+     Set to 1 only if you know for sure.  In case of doubt, set to 0.  */
+# if defined __alpha__ || defined __arm__ || defined __i386__ \
+     || defined __m68k__ || defined __s390__
+#  define INTDIV0_RAISES_SIGFPE 1
+# else
+#  define INTDIV0_RAISES_SIGFPE 0
+# endif
+#endif
+#if !INTDIV0_RAISES_SIGFPE
+# include <signal.h>
+#endif
+
+#if defined HAVE_SYS_PARAM_H || defined _LIBC
+# include <sys/param.h>
+#endif
+
+#include "gettextP.h"
+#include "plural-exp.h"
+#ifdef _LIBC
+# include <libintl.h>
+#else
+# include "libgnuintl.h"
+#endif
+#include "hash-string.h"
+
+/* Thread safetyness.  */
+#ifdef _LIBC
+# include <bits/libc-lock.h>
+#else
+/* Provide dummy implementation if this is outside glibc.  */
+# define __libc_lock_define_initialized(CLASS, NAME)
+# define __libc_lock_lock(NAME)
+# define __libc_lock_unlock(NAME)
+# define __libc_rwlock_define_initialized(CLASS, NAME)
+# define __libc_rwlock_rdlock(NAME)
+# define __libc_rwlock_unlock(NAME)
+#endif
+
+/* Alignment of types.  */
+#if defined __GNUC__ && __GNUC__ >= 2
+# define alignof(TYPE) __alignof__ (TYPE)
+#else
+# define alignof(TYPE) \
+    ((int) &((struct { char dummy1; TYPE dummy2; } *) 0)->dummy2)
+#endif
+
+/* The internal variables in the standalone libintl.a must have different
+   names than the internal variables in GNU libc, otherwise programs
+   using libintl.a cannot be linked statically.  */
+#if !defined _LIBC
+# define _nl_default_default_domain libintl_nl_default_default_domain
+# define _nl_current_default_domain libintl_nl_current_default_domain
+# define _nl_default_dirname libintl_nl_default_dirname
+# define _nl_domain_bindings libintl_nl_domain_bindings
+#endif
+
+/* Some compilers, like SunOS4 cc, don't have offsetof in <stddef.h>.  */
+#ifndef offsetof
+# define offsetof(type,ident) ((size_t)&(((type*)0)->ident))
+#endif
+
+/* @@ end of prolog @@ */
+
+#ifdef _LIBC
+/* Rename the non ANSI C functions.  This is required by the standard
+   because some ANSI C functions will require linking with this object
+   file and the name space must not be polluted.  */
+# define getcwd __getcwd
+# ifndef stpcpy
+#  define stpcpy __stpcpy
+# endif
+# define tfind __tfind
+#else
+# if !defined HAVE_GETCWD
+char *getwd ();
+#  define getcwd(buf, max) getwd (buf)
+# else
+#  if VMS
+#   define getcwd(buf, max) (getcwd) (buf, max, 0)
+#  else
+char *getcwd ();
+#  endif
+# endif
+# ifndef HAVE_STPCPY
+static char *stpcpy (char *dest, const char *src);
+# endif
+# ifndef HAVE_MEMPCPY
+static void *mempcpy (void *dest, const void *src, size_t n);
+# endif
+#endif
+
+/* Amount to increase buffer size by in each try.  */
+#define PATH_INCR 32
+
+/* The following is from pathmax.h.  */
+/* Non-POSIX BSD systems might have gcc's limits.h, which doesn't define
+   PATH_MAX but might cause redefinition warnings when sys/param.h is
+   later included (as on MORE/BSD 4.3).  */
+#if defined _POSIX_VERSION || (defined HAVE_LIMITS_H && !defined __GNUC__)
+# include <limits.h>
+#endif
+
+#ifndef _POSIX_PATH_MAX
+# define _POSIX_PATH_MAX 255
+#endif
+
+#if !defined PATH_MAX && defined _PC_PATH_MAX
+# define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 : pathconf ("/", _PC_PATH_MAX))
+#endif
+
+/* Don't include sys/param.h if it already has been.  */
+#if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
+# include <sys/param.h>
+#endif
+
+#if !defined PATH_MAX && defined MAXPATHLEN
+# define PATH_MAX MAXPATHLEN
+#endif
+
+#ifndef PATH_MAX
+# define PATH_MAX _POSIX_PATH_MAX
+#endif
+
+/* Pathname support.
+   ISSLASH(C)           tests whether C is a directory separator character.
+   IS_ABSOLUTE_PATH(P)  tests whether P is an absolute path.  If it is not,
+                        it may be concatenated to a directory pathname.
+   IS_PATH_WITH_DIR(P)  tests whether P contains a directory specification.
+ */
+#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
+  /* Win32, Cygwin, OS/2, DOS */
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+# define HAS_DEVICE(P) \
+    ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
+     && (P)[1] == ':')
+# define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P))
+# define IS_PATH_WITH_DIR(P) \
+    (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
+#else
+  /* Unix */
+# define ISSLASH(C) ((C) == '/')
+# define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0])
+# define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
+#endif
+
+/* This is the type used for the search tree where known translations
+   are stored.  */
+struct known_translation_t
+{
+  /* Domain in which to search.  */
+  char *domainname;
+
+  /* The category.  */
+  int category;
+
+  /* State of the catalog counter at the point the string was found.  */
+  int counter;
+
+  /* Catalog where the string was found.  */
+  struct loaded_l10nfile *domain;
+
+  /* And finally the translation.  */
+  const char *translation;
+  size_t translation_length;
+
+  /* Pointer to the string in question.  */
+  char msgid[ZERO];
+};
+
+/* Root of the search tree with known translations.  We can use this
+   only if the system provides the `tsearch' function family.  */
+#if defined HAVE_TSEARCH || defined _LIBC
+# include <search.h>
+
+static void *root;
+
+# ifdef _LIBC
+#  define tsearch __tsearch
+# endif
+
+/* Function to compare two entries in the table of known translations.  */
+static int
+transcmp (const void *p1, const void *p2)
+{
+  const struct known_translation_t *s1;
+  const struct known_translation_t *s2;
+  int result;
+
+  s1 = (const struct known_translation_t *) p1;
+  s2 = (const struct known_translation_t *) p2;
+
+  result = strcmp (s1->msgid, s2->msgid);
+  if (result == 0)
+    {
+      result = strcmp (s1->domainname, s2->domainname);
+      if (result == 0)
+       /* We compare the category last (though this is the cheapest
+          operation) since it is hopefully always the same (namely
+          LC_MESSAGES).  */
+       result = s1->category - s2->category;
+    }
+
+  return result;
+}
+#endif
+
+#ifndef INTVARDEF
+# define INTVARDEF(name)
+#endif
+#ifndef INTUSE
+# define INTUSE(name) name
+#endif
+
+/* Name of the default domain used for gettext(3) prior any call to
+   textdomain(3).  The default value for this is "messages".  */
+const char _nl_default_default_domain[] attribute_hidden = "messages";
+
+/* Value used as the default domain for gettext(3).  */
+const char *_nl_current_default_domain attribute_hidden
+     = _nl_default_default_domain;
+
+/* Contains the default location of the message catalogs.  */
+#if defined __EMX__
+extern const char _nl_default_dirname[];
+#else
+const char _nl_default_dirname[] = LOCALEDIR;
+INTVARDEF (_nl_default_dirname)
+#endif
+
+/* List with bindings of specific domains created by bindtextdomain()
+   calls.  */
+struct binding *_nl_domain_bindings;
+
+/* Prototypes for local functions.  */
+static char *plural_lookup (struct loaded_l10nfile *domain,
+                           unsigned long int n,
+                           const char *translation, size_t translation_len)
+     internal_function;
+static const char *guess_category_value (int category,
+                                        const char *categoryname)
+     internal_function;
+#ifdef _LIBC
+# include "../locale/localeinfo.h"
+# define category_to_name(category)    _nl_category_names[category]
+#else
+static const char *category_to_name (int category) internal_function;
+#endif
+
+
+/* For those loosing systems which don't have `alloca' we have to add
+   some additional code emulating it.  */
+#ifdef HAVE_ALLOCA
+/* Nothing has to be done.  */
+# define freea(p) /* nothing */
+# define ADD_BLOCK(list, address) /* nothing */
+# define FREE_BLOCKS(list) /* nothing */
+#else
+struct block_list
+{
+  void *address;
+  struct block_list *next;
+};
+# define ADD_BLOCK(list, addr)                                               \
+  do {                                                                       \
+    struct block_list *newp = (struct block_list *) malloc (sizeof (*newp));  \
+    /* If we cannot get a free block we cannot add the new element to        \
+       the list.  */                                                         \
+    if (newp != NULL) {                                                              \
+      newp->address = (addr);                                                \
+      newp->next = (list);                                                   \
+      (list) = newp;                                                         \
+    }                                                                        \
+  } while (0)
+# define FREE_BLOCKS(list)                                                   \
+  do {                                                                       \
+    while (list != NULL) {                                                   \
+      struct block_list *old = list;                                         \
+      list = list->next;                                                     \
+      free (old->address);                                                   \
+      free (old);                                                            \
+    }                                                                        \
+  } while (0)
+# undef alloca
+# define alloca(size) (malloc (size))
+# define freea(p) free (p)
+#endif /* have alloca */
+
+
+#ifdef _LIBC
+/* List of blocks allocated for translations.  */
+typedef struct transmem_list
+{
+  struct transmem_list *next;
+  char data[ZERO];
+} transmem_block_t;
+static struct transmem_list *transmem_list;
+#else
+typedef unsigned char transmem_block_t;
+#endif
+
+
+/* Names for the libintl functions are a problem.  They must not clash
+   with existing names and they should follow ANSI C.  But this source
+   code is also used in GNU C Library where the names have a __
+   prefix.  So we have to make a difference here.  */
+#ifdef _LIBC
+# define DCIGETTEXT __dcigettext
+#else
+# define DCIGETTEXT libintl_dcigettext
+#endif
+
+/* Lock variable to protect the global data in the gettext implementation.  */
+#ifdef _LIBC
+__libc_rwlock_define_initialized (, _nl_state_lock attribute_hidden)
+#endif
+
+/* Checking whether the binaries runs SUID must be done and glibc provides
+   easier methods therefore we make a difference here.  */
+#ifdef _LIBC
+# define ENABLE_SECURE __libc_enable_secure
+# define DETERMINE_SECURE
+#else
+# ifndef HAVE_GETUID
+#  define getuid() 0
+# endif
+# ifndef HAVE_GETGID
+#  define getgid() 0
+# endif
+# ifndef HAVE_GETEUID
+#  define geteuid() getuid()
+# endif
+# ifndef HAVE_GETEGID
+#  define getegid() getgid()
+# endif
+static int enable_secure;
+# define ENABLE_SECURE (enable_secure == 1)
+# define DETERMINE_SECURE \
+  if (enable_secure == 0)                                                    \
+    {                                                                        \
+      if (getuid () != geteuid () || getgid () != getegid ())                \
+       enable_secure = 1;                                                    \
+      else                                                                   \
+       enable_secure = -1;                                                   \
+    }
+#endif
+
+/* Get the function to evaluate the plural expression.  */
+#include "eval-plural.h"
+
+/* Look up MSGID in the DOMAINNAME message catalog for the current
+   CATEGORY locale and, if PLURAL is nonzero, search over string
+   depending on the plural form determined by N.  */
+char *
+DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2,
+           int plural, unsigned long int n, int category)
+{
+#ifndef HAVE_ALLOCA
+  struct block_list *block_list = NULL;
+#endif
+  struct loaded_l10nfile *domain;
+  struct binding *binding;
+  const char *categoryname;
+  const char *categoryvalue;
+  char *dirname, *xdomainname;
+  char *single_locale;
+  char *retval;
+  size_t retlen;
+  int saved_errno;
+#if defined HAVE_TSEARCH || defined _LIBC
+  struct known_translation_t *search;
+  struct known_translation_t **foundp = NULL;
+  size_t msgid_len;
+#endif
+  size_t domainname_len;
+
+  /* If no real MSGID is given return NULL.  */
+  if (msgid1 == NULL)
+    return NULL;
+
+#ifdef _LIBC
+  if (category < 0 || category >= __LC_LAST || category == LC_ALL)
+    /* Bogus.  */
+    return (plural == 0
+           ? (char *) msgid1
+           /* Use the Germanic plural rule.  */
+           : n == 1 ? (char *) msgid1 : (char *) msgid2);
+#endif
+
+  __libc_rwlock_rdlock (_nl_state_lock);
+
+  /* If DOMAINNAME is NULL, we are interested in the default domain.  If
+     CATEGORY is not LC_MESSAGES this might not make much sense but the
+     definition left this undefined.  */
+  if (domainname == NULL)
+    domainname = _nl_current_default_domain;
+
+  /* OS/2 specific: backward compatibility with older libintl versions  */
+#ifdef LC_MESSAGES_COMPAT
+  if (category == LC_MESSAGES_COMPAT)
+    category = LC_MESSAGES;
+#endif
+
+#if defined HAVE_TSEARCH || defined _LIBC
+  msgid_len = strlen (msgid1) + 1;
+
+  /* Try to find the translation among those which we found at
+     some time.  */
+  search = (struct known_translation_t *)
+          alloca (offsetof (struct known_translation_t, msgid) + msgid_len);
+  memcpy (search->msgid, msgid1, msgid_len);
+  search->domainname = (char *) domainname;
+  search->category = category;
+
+  foundp = (struct known_translation_t **) tfind (search, &root, transcmp);
+  freea (search);
+  if (foundp != NULL && (*foundp)->counter == _nl_msg_cat_cntr)
+    {
+      /* Now deal with plural.  */
+      if (plural)
+       retval = plural_lookup ((*foundp)->domain, n, (*foundp)->translation,
+                               (*foundp)->translation_length);
+      else
+       retval = (char *) (*foundp)->translation;
+
+      __libc_rwlock_unlock (_nl_state_lock);
+      return retval;
+    }
+#endif
+
+  /* Preserve the `errno' value.  */
+  saved_errno = errno;
+
+  /* See whether this is a SUID binary or not.  */
+  DETERMINE_SECURE;
+
+  /* First find matching binding.  */
+  for (binding = _nl_domain_bindings; binding != NULL; binding = binding->next)
+    {
+      int compare = strcmp (domainname, binding->domainname);
+      if (compare == 0)
+       /* We found it!  */
+       break;
+      if (compare < 0)
+       {
+         /* It is not in the list.  */
+         binding = NULL;
+         break;
+       }
+    }
+
+  if (binding == NULL)
+    dirname = (char *) INTUSE(_nl_default_dirname);
+  else if (IS_ABSOLUTE_PATH (binding->dirname))
+    dirname = binding->dirname;
+  else
+    {
+      /* We have a relative path.  Make it absolute now.  */
+      size_t dirname_len = strlen (binding->dirname) + 1;
+      size_t path_max;
+      char *ret;
+
+      path_max = (unsigned int) PATH_MAX;
+      path_max += 2;           /* The getcwd docs say to do this.  */
+
+      for (;;)
+       {
+         dirname = (char *) alloca (path_max + dirname_len);
+         ADD_BLOCK (block_list, dirname);
+
+         __set_errno (0);
+         ret = getcwd (dirname, path_max);
+         if (ret != NULL || errno != ERANGE)
+           break;
+
+         path_max += path_max / 2;
+         path_max += PATH_INCR;
+       }
+
+      if (ret == NULL)
+       /* We cannot get the current working directory.  Don't signal an
+          error but simply return the default string.  */
+       goto return_untranslated;
+
+      stpcpy (stpcpy (strchr (dirname, '\0'), "/"), binding->dirname);
+    }
+
+  /* Now determine the symbolic name of CATEGORY and its value.  */
+  categoryname = category_to_name (category);
+  categoryvalue = guess_category_value (category, categoryname);
+
+  domainname_len = strlen (domainname);
+  xdomainname = (char *) alloca (strlen (categoryname)
+                                + domainname_len + 5);
+  ADD_BLOCK (block_list, xdomainname);
+
+  stpcpy (mempcpy (stpcpy (stpcpy (xdomainname, categoryname), "/"),
+                 domainname, domainname_len),
+         ".mo");
+
+  /* Creating working area.  */
+  single_locale = (char *) alloca (strlen (categoryvalue) + 1);
+  ADD_BLOCK (block_list, single_locale);
+
+
+  /* Search for the given string.  This is a loop because we perhaps
+     got an ordered list of languages to consider for the translation.  */
+  while (1)
+    {
+      /* Make CATEGORYVALUE point to the next element of the list.  */
+      while (categoryvalue[0] != '\0' && categoryvalue[0] == ':')
+       ++categoryvalue;
+      if (categoryvalue[0] == '\0')
+       {
+         /* The whole contents of CATEGORYVALUE has been searched but
+            no valid entry has been found.  We solve this situation
+            by implicitly appending a "C" entry, i.e. no translation
+            will take place.  */
+         single_locale[0] = 'C';
+         single_locale[1] = '\0';
+       }
+      else
+       {
+         char *cp = single_locale;
+         while (categoryvalue[0] != '\0' && categoryvalue[0] != ':')
+           *cp++ = *categoryvalue++;
+         *cp = '\0';
+
+         /* When this is a SUID binary we must not allow accessing files
+            outside the dedicated directories.  */
+         if (ENABLE_SECURE && IS_PATH_WITH_DIR (single_locale))
+           /* Ingore this entry.  */
+           continue;
+       }
+
+      /* If the current locale value is C (or POSIX) we don't load a
+        domain.  Return the MSGID.  */
+      if (strcmp (single_locale, "C") == 0
+         || strcmp (single_locale, "POSIX") == 0)
+       break;
+
+      /* Find structure describing the message catalog matching the
+        DOMAINNAME and CATEGORY.  */
+      domain = _nl_find_domain (dirname, single_locale, xdomainname, binding);
+
+      if (domain != NULL)
+       {
+         retval = _nl_find_msg (domain, binding, msgid1, &retlen);
+
+         if (retval == NULL)
+           {
+             int cnt;
+
+             for (cnt = 0; domain->successor[cnt] != NULL; ++cnt)
+               {
+                 retval = _nl_find_msg (domain->successor[cnt], binding,
+                                        msgid1, &retlen);
+
+                 if (retval != NULL)
+                   {
+                     domain = domain->successor[cnt];
+                     break;
+                   }
+               }
+           }
+
+         if (retval != NULL)
+           {
+             /* Found the translation of MSGID1 in domain DOMAIN:
+                starting at RETVAL, RETLEN bytes.  */
+             FREE_BLOCKS (block_list);
+#if defined HAVE_TSEARCH || defined _LIBC
+             if (foundp == NULL)
+               {
+                 /* Create a new entry and add it to the search tree.  */
+                 struct known_translation_t *newp;
+
+                 newp = (struct known_translation_t *)
+                   malloc (offsetof (struct known_translation_t, msgid)
+                           + msgid_len + domainname_len + 1);
+                 if (newp != NULL)
+                   {
+                     newp->domainname =
+                       mempcpy (newp->msgid, msgid1, msgid_len);
+                     memcpy (newp->domainname, domainname, domainname_len + 1);
+                     newp->category = category;
+                     newp->counter = _nl_msg_cat_cntr;
+                     newp->domain = domain;
+                     newp->translation = retval;
+                     newp->translation_length = retlen;
+
+                     /* Insert the entry in the search tree.  */
+                     foundp = (struct known_translation_t **)
+                       tsearch (newp, &root, transcmp);
+                     if (foundp == NULL
+                         || __builtin_expect (*foundp != newp, 0))
+                       /* The insert failed.  */
+                       free (newp);
+                   }
+               }
+             else
+               {
+                 /* We can update the existing entry.  */
+                 (*foundp)->counter = _nl_msg_cat_cntr;
+                 (*foundp)->domain = domain;
+                 (*foundp)->translation = retval;
+                 (*foundp)->translation_length = retlen;
+               }
+#endif
+             __set_errno (saved_errno);
+
+             /* Now deal with plural.  */
+             if (plural)
+               retval = plural_lookup (domain, n, retval, retlen);
+
+             __libc_rwlock_unlock (_nl_state_lock);
+             return retval;
+           }
+       }
+    }
+
+ return_untranslated:
+  /* Return the untranslated MSGID.  */
+  FREE_BLOCKS (block_list);
+  __libc_rwlock_unlock (_nl_state_lock);
+#ifndef _LIBC
+  if (!ENABLE_SECURE)
+    {
+      extern void _nl_log_untranslated (const char *logfilename,
+                                       const char *domainname,
+                                       const char *msgid1, const char *msgid2,
+                                       int plural);
+      const char *logfilename = getenv ("GETTEXT_LOG_UNTRANSLATED");
+
+      if (logfilename != NULL && logfilename[0] != '\0')
+       _nl_log_untranslated (logfilename, domainname, msgid1, msgid2, plural);
+    }
+#endif
+  __set_errno (saved_errno);
+  return (plural == 0
+         ? (char *) msgid1
+         /* Use the Germanic plural rule.  */
+         : n == 1 ? (char *) msgid1 : (char *) msgid2);
+}
+
+
+char *
+internal_function
+_nl_find_msg (struct loaded_l10nfile *domain_file,
+             struct binding *domainbinding, const char *msgid,
+             size_t *lengthp)
+{
+  struct loaded_domain *domain;
+  nls_uint32 nstrings;
+  size_t act;
+  char *result;
+  size_t resultlen;
+
+  if (domain_file->decided == 0)
+    _nl_load_domain (domain_file, domainbinding);
+
+  if (domain_file->data == NULL)
+    return NULL;
+
+  domain = (struct loaded_domain *) domain_file->data;
+
+  nstrings = domain->nstrings;
+
+  /* Locate the MSGID and its translation.  */
+  if (domain->hash_tab != NULL)
+    {
+      /* Use the hashing table.  */
+      nls_uint32 len = strlen (msgid);
+      nls_uint32 hash_val = hash_string (msgid);
+      nls_uint32 idx = hash_val % domain->hash_size;
+      nls_uint32 incr = 1 + (hash_val % (domain->hash_size - 2));
+
+      while (1)
+       {
+         nls_uint32 nstr =
+           W (domain->must_swap_hash_tab, domain->hash_tab[idx]);
+
+         if (nstr == 0)
+           /* Hash table entry is empty.  */
+           return NULL;
+
+         nstr--;
+
+         /* Compare msgid with the original string at index nstr.
+            We compare the lengths with >=, not ==, because plural entries
+            are represented by strings with an embedded NUL.  */
+         if (nstr < nstrings
+             ? W (domain->must_swap, domain->orig_tab[nstr].length) >= len
+               && (strcmp (msgid,
+                           domain->data + W (domain->must_swap,
+                                             domain->orig_tab[nstr].offset))
+                   == 0)
+             : domain->orig_sysdep_tab[nstr - nstrings].length > len
+               && (strcmp (msgid,
+                           domain->orig_sysdep_tab[nstr - nstrings].pointer)
+                   == 0))
+           {
+             act = nstr;
+             goto found;
+           }
+
+         if (idx >= domain->hash_size - incr)
+           idx -= domain->hash_size - incr;
+         else
+           idx += incr;
+       }
+      /* NOTREACHED */
+    }
+  else
+    {
+      /* Try the default method:  binary search in the sorted array of
+        messages.  */
+      size_t top, bottom;
+
+      bottom = 0;
+      top = nstrings;
+      while (bottom < top)
+       {
+         int cmp_val;
+
+         act = (bottom + top) / 2;
+         cmp_val = strcmp (msgid, (domain->data
+                                   + W (domain->must_swap,
+                                        domain->orig_tab[act].offset)));
+         if (cmp_val < 0)
+           top = act;
+         else if (cmp_val > 0)
+           bottom = act + 1;
+         else
+           goto found;
+       }
+      /* No translation was found.  */
+      return NULL;
+    }
+
+ found:
+  /* The translation was found at index ACT.  If we have to convert the
+     string to use a different character set, this is the time.  */
+  if (act < nstrings)
+    {
+      result = (char *)
+       (domain->data + W (domain->must_swap, domain->trans_tab[act].offset));
+      resultlen = W (domain->must_swap, domain->trans_tab[act].length) + 1;
+    }
+  else
+    {
+      result = (char *) domain->trans_sysdep_tab[act - nstrings].pointer;
+      resultlen = domain->trans_sysdep_tab[act - nstrings].length;
+    }
+
+#if defined _LIBC || HAVE_ICONV
+  if (domain->codeset_cntr
+      != (domainbinding != NULL ? domainbinding->codeset_cntr : 0))
+    {
+      /* The domain's codeset has changed through bind_textdomain_codeset()
+        since the message catalog was initialized or last accessed.  We
+        have to reinitialize the converter.  */
+      _nl_free_domain_conv (domain);
+      _nl_init_domain_conv (domain_file, domain, domainbinding);
+    }
+
+  if (
+# ifdef _LIBC
+      domain->conv != (__gconv_t) -1
+# else
+#  if HAVE_ICONV
+      domain->conv != (iconv_t) -1
+#  endif
+# endif
+      )
+    {
+      /* We are supposed to do a conversion.  First allocate an
+        appropriate table with the same structure as the table
+        of translations in the file, where we can put the pointers
+        to the converted strings in.
+        There is a slight complication with plural entries.  They
+        are represented by consecutive NUL terminated strings.  We
+        handle this case by converting RESULTLEN bytes, including
+        NULs.  */
+
+      if (domain->conv_tab == NULL
+         && ((domain->conv_tab =
+                (char **) calloc (nstrings + domain->n_sysdep_strings,
+                                  sizeof (char *)))
+             == NULL))
+       /* Mark that we didn't succeed allocating a table.  */
+       domain->conv_tab = (char **) -1;
+
+      if (__builtin_expect (domain->conv_tab == (char **) -1, 0))
+       /* Nothing we can do, no more memory.  */
+       goto converted;
+
+      if (domain->conv_tab[act] == NULL)
+       {
+         /* We haven't used this string so far, so it is not
+            translated yet.  Do this now.  */
+         /* We use a bit more efficient memory handling.
+            We allocate always larger blocks which get used over
+            time.  This is faster than many small allocations.   */
+         __libc_lock_define_initialized (static, lock)
+# define INITIAL_BLOCK_SIZE    4080
+         static unsigned char *freemem;
+         static size_t freemem_size;
+
+         const unsigned char *inbuf;
+         unsigned char *outbuf;
+         int malloc_count;
+# ifndef _LIBC
+         transmem_block_t *transmem_list = NULL;
+# endif
+
+         __libc_lock_lock (lock);
+
+         inbuf = (const unsigned char *) result;
+         outbuf = freemem + sizeof (size_t);
+
+         malloc_count = 0;
+         while (1)
+           {
+             transmem_block_t *newmem;
+# ifdef _LIBC
+             size_t non_reversible;
+             int res;
+
+             if (freemem_size < sizeof (size_t))
+               goto resize_freemem;
+
+             res = __gconv (domain->conv,
+                            &inbuf, inbuf + resultlen,
+                            &outbuf,
+                            outbuf + freemem_size - sizeof (size_t),
+                            &non_reversible);
+
+             if (res == __GCONV_OK || res == __GCONV_EMPTY_INPUT)
+               break;
+
+             if (res != __GCONV_FULL_OUTPUT)
+               {
+                 __libc_lock_unlock (lock);
+                 goto converted;
+               }
+
+             inbuf = result;
+# else
+#  if HAVE_ICONV
+             const char *inptr = (const char *) inbuf;
+             size_t inleft = resultlen;
+             char *outptr = (char *) outbuf;
+             size_t outleft;
+
+             if (freemem_size < sizeof (size_t))
+               goto resize_freemem;
+
+             outleft = freemem_size - sizeof (size_t);
+             if (iconv (domain->conv,
+                        (ICONV_CONST char **) &inptr, &inleft,
+                        &outptr, &outleft)
+                 != (size_t) (-1))
+               {
+                 outbuf = (unsigned char *) outptr;
+                 break;
+               }
+             if (errno != E2BIG)
+               {
+                 __libc_lock_unlock (lock);
+                 goto converted;
+               }
+#  endif
+# endif
+
+           resize_freemem:
+             /* We must allocate a new buffer or resize the old one.  */
+             if (malloc_count > 0)
+               {
+                 ++malloc_count;
+                 freemem_size = malloc_count * INITIAL_BLOCK_SIZE;
+                 newmem = (transmem_block_t *) realloc (transmem_list,
+                                                        freemem_size);
+# ifdef _LIBC
+                 if (newmem != NULL)
+                   transmem_list = transmem_list->next;
+                 else
+                   {
+                     struct transmem_list *old = transmem_list;
+
+                     transmem_list = transmem_list->next;
+                     free (old);
+                   }
+# endif
+               }
+             else
+               {
+                 malloc_count = 1;
+                 freemem_size = INITIAL_BLOCK_SIZE;
+                 newmem = (transmem_block_t *) malloc (freemem_size);
+               }
+             if (__builtin_expect (newmem == NULL, 0))
+               {
+                 freemem = NULL;
+                 freemem_size = 0;
+                 __libc_lock_unlock (lock);
+                 goto converted;
+               }
+
+# ifdef _LIBC
+             /* Add the block to the list of blocks we have to free
+                 at some point.  */
+             newmem->next = transmem_list;
+             transmem_list = newmem;
+
+             freemem = newmem->data;
+             freemem_size -= offsetof (struct transmem_list, data);
+# else
+             transmem_list = newmem;
+             freemem = newmem;
+# endif
+
+             outbuf = freemem + sizeof (size_t);
+           }
+
+         /* We have now in our buffer a converted string.  Put this
+            into the table of conversions.  */
+         *(size_t *) freemem = outbuf - freemem - sizeof (size_t);
+         domain->conv_tab[act] = (char *) freemem;
+         /* Shrink freemem, but keep it aligned.  */
+         freemem_size -= outbuf - freemem;
+         freemem = outbuf;
+         freemem += freemem_size & (alignof (size_t) - 1);
+         freemem_size = freemem_size & ~ (alignof (size_t) - 1);
+
+         __libc_lock_unlock (lock);
+       }
+
+      /* Now domain->conv_tab[act] contains the translation of all
+        the plural variants.  */
+      result = domain->conv_tab[act] + sizeof (size_t);
+      resultlen = *(size_t *) domain->conv_tab[act];
+    }
+
+ converted:
+  /* The result string is converted.  */
+
+#endif /* _LIBC || HAVE_ICONV */
+
+  *lengthp = resultlen;
+  return result;
+}
+
+
+/* Look up a plural variant.  */
+static char *
+internal_function
+plural_lookup (struct loaded_l10nfile *domain, unsigned long int n,
+              const char *translation, size_t translation_len)
+{
+  struct loaded_domain *domaindata = (struct loaded_domain *) domain->data;
+  unsigned long int index;
+  const char *p;
+
+  index = plural_eval (domaindata->plural, n);
+  if (index >= domaindata->nplurals)
+    /* This should never happen.  It means the plural expression and the
+       given maximum value do not match.  */
+    index = 0;
+
+  /* Skip INDEX strings at TRANSLATION.  */
+  p = translation;
+  while (index-- > 0)
+    {
+#ifdef _LIBC
+      p = __rawmemchr (p, '\0');
+#else
+      p = strchr (p, '\0');
+#endif
+      /* And skip over the NUL byte.  */
+      p++;
+
+      if (p >= translation + translation_len)
+       /* This should never happen.  It means the plural expression
+          evaluated to a value larger than the number of variants
+          available for MSGID1.  */
+       return (char *) translation;
+    }
+  return (char *) p;
+}
+
+#ifndef _LIBC
+/* Return string representation of locale CATEGORY.  */
+static const char *
+internal_function
+category_to_name (int category)
+{
+  const char *retval;
+
+  switch (category)
+  {
+#ifdef LC_COLLATE
+  case LC_COLLATE:
+    retval = "LC_COLLATE";
+    break;
+#endif
+#ifdef LC_CTYPE
+  case LC_CTYPE:
+    retval = "LC_CTYPE";
+    break;
+#endif
+#ifdef LC_MONETARY
+  case LC_MONETARY:
+    retval = "LC_MONETARY";
+    break;
+#endif
+#ifdef LC_NUMERIC
+  case LC_NUMERIC:
+    retval = "LC_NUMERIC";
+    break;
+#endif
+#ifdef LC_TIME
+  case LC_TIME:
+    retval = "LC_TIME";
+    break;
+#endif
+#ifdef LC_MESSAGES
+  case LC_MESSAGES:
+    retval = "LC_MESSAGES";
+    break;
+#endif
+#ifdef LC_RESPONSE
+  case LC_RESPONSE:
+    retval = "LC_RESPONSE";
+    break;
+#endif
+#ifdef LC_ALL
+  case LC_ALL:
+    /* This might not make sense but is perhaps better than any other
+       value.  */
+    retval = "LC_ALL";
+    break;
+#endif
+  default:
+    /* If you have a better idea for a default value let me know.  */
+    retval = "LC_XXX";
+  }
+
+  return retval;
+}
+#endif
+
+/* Guess value of current locale from value of the environment variables
+   or system-dependent defaults.  */
+static const char *
+internal_function
+guess_category_value (int category, const char *categoryname)
+{
+  const char *language;
+  const char *locale;
+#ifndef _LIBC
+  const char *language_default;
+  int locale_defaulted;
+#endif
+
+  /* We use the settings in the following order:
+     1. The value of the environment variable 'LANGUAGE'.  This is a GNU
+        extension.  Its value can be a colon-separated list of locale names.
+     2. The value of the environment variable 'LC_ALL', 'LC_xxx', or 'LANG'.
+        More precisely, the first among these that is set to a non-empty value.
+        This is how POSIX specifies it.  The value is a single locale name.
+     3. A system-dependent preference list of languages.  Its value can be a
+        colon-separated list of locale names.
+     4. A system-dependent default locale name.
+     This way:
+       - System-dependent settings can be overridden by environment variables.
+       - If the system provides both a list of languages and a default locale,
+         the former is used.  */
+
+  /* Fetch the locale name, through the POSIX method of looking to `LC_ALL',
+     `LC_xxx', and `LANG'.  On some systems this can be done by the
+     `setlocale' function itself.  */
+#ifdef _LIBC
+  locale = __current_locale_name (category);
+#else
+  locale = _nl_locale_name_posix (category, categoryname);
+  locale_defaulted = 0;
+  if (locale == NULL)
+    {
+      locale = _nl_locale_name_default ();
+      locale_defaulted = 1;
+    }
+#endif
+
+  /* Ignore LANGUAGE and its system-dependent analogon if the locale is set
+     to "C" because
+     1. "C" locale usually uses the ASCII encoding, and most international
+       messages use non-ASCII characters. These characters get displayed
+       as question marks (if using glibc's iconv()) or as invalid 8-bit
+       characters (because other iconv()s refuse to convert most non-ASCII
+       characters to ASCII). In any case, the output is ugly.
+     2. The precise output of some programs in the "C" locale is specified
+       by POSIX and should not depend on environment variables like
+       "LANGUAGE" or system-dependent information.  We allow such programs
+        to use gettext().  */
+  if (strcmp (locale, "C") == 0)
+    return locale;
+
+  /* The highest priority value is the value of the 'LANGUAGE' environment
+     variable.  */
+  language = getenv ("LANGUAGE");
+  if (language != NULL && language[0] != '\0')
+    return language;
+#ifndef _LIBC
+  /* The next priority value is the locale name, if not defaulted.  */
+  if (locale_defaulted)
+    {
+      /* The next priority value is the default language preferences list. */
+      language_default = _nl_language_preferences_default ();
+      if (language_default != NULL)
+        return language_default;
+    }
+  /* The least priority value is the locale name, if defaulted.  */
+#endif
+  return locale;
+}
+
+/* @@ begin of epilog @@ */
+
+/* We don't want libintl.a to depend on any other library.  So we
+   avoid the non-standard function stpcpy.  In GNU C Library this
+   function is available, though.  Also allow the symbol HAVE_STPCPY
+   to be defined.  */
+#if !_LIBC && !HAVE_STPCPY
+static char *
+stpcpy (char *dest, const char *src)
+{
+  while ((*dest++ = *src++) != '\0')
+    /* Do nothing. */ ;
+  return dest - 1;
+}
+#endif
+
+#if !_LIBC && !HAVE_MEMPCPY
+static void *
+mempcpy (void *dest, const void *src, size_t n)
+{
+  return (void *) ((char *) memcpy (dest, src, n) + n);
+}
+#endif
+
+
+#ifdef _LIBC
+/* If we want to free all resources we have to do some work at
+   program's end.  */
+libc_freeres_fn (free_mem)
+{
+  void *old;
+
+  while (_nl_domain_bindings != NULL)
+    {
+      struct binding *oldp = _nl_domain_bindings;
+      _nl_domain_bindings = _nl_domain_bindings->next;
+      if (oldp->dirname != INTUSE(_nl_default_dirname))
+       /* Yes, this is a pointer comparison.  */
+       free (oldp->dirname);
+      free (oldp->codeset);
+      free (oldp);
+    }
+
+  if (_nl_current_default_domain != _nl_default_default_domain)
+    /* Yes, again a pointer comparison.  */
+    free ((char *) _nl_current_default_domain);
+
+  /* Remove the search tree with the known translations.  */
+  __tdestroy (root, free);
+  root = NULL;
+
+  while (transmem_list != NULL)
+    {
+      old = transmem_list;
+      transmem_list = transmem_list->next;
+      free (old);
+    }
+}
+#endif
diff --git a/intl/dcngettext.c b/intl/dcngettext.c
new file mode 100644 (file)
index 0000000..48a3e09
--- /dev/null
@@ -0,0 +1,57 @@
+/* Implementation of the dcngettext(3) function.
+   Copyright (C) 1995-1999, 2000-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "gettextP.h"
+#ifdef _LIBC
+# include <libintl.h>
+#else
+# include "libgnuintl.h"
+#endif
+
+/* @@ end of prolog @@ */
+
+/* Names for the libintl functions are a problem.  They must not clash
+   with existing names and they should follow ANSI C.  But this source
+   code is also used in GNU C Library where the names have a __
+   prefix.  So we have to make a difference here.  */
+#ifdef _LIBC
+# define DCNGETTEXT __dcngettext
+# define DCIGETTEXT __dcigettext
+#else
+# define DCNGETTEXT libintl_dcngettext
+# define DCIGETTEXT libintl_dcigettext
+#endif
+
+/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
+   locale.  */
+char *
+DCNGETTEXT (const char *domainname,
+           const char *msgid1, const char *msgid2, unsigned long int n,
+           int category)
+{
+  return DCIGETTEXT (domainname, msgid1, msgid2, 1, n, category);
+}
+
+#ifdef _LIBC
+/* Alias for function name in GNU C Library.  */
+weak_alias (__dcngettext, dcngettext);
+#endif
diff --git a/intl/dgettext.c b/intl/dgettext.c
new file mode 100644 (file)
index 0000000..b64b0f5
--- /dev/null
@@ -0,0 +1,58 @@
+/* Implementation of the dgettext(3) function.
+   Copyright (C) 1995-1997, 2000-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "gettextP.h"
+
+#include <locale.h>
+
+#ifdef _LIBC
+# include <libintl.h>
+#else
+# include "libgnuintl.h"
+#endif
+
+/* @@ end of prolog @@ */
+
+/* Names for the libintl functions are a problem.  They must not clash
+   with existing names and they should follow ANSI C.  But this source
+   code is also used in GNU C Library where the names have a __
+   prefix.  So we have to make a difference here.  */
+#ifdef _LIBC
+# define DGETTEXT __dgettext
+# define DCGETTEXT INTUSE(__dcgettext)
+#else
+# define DGETTEXT libintl_dgettext
+# define DCGETTEXT libintl_dcgettext
+#endif
+
+/* Look up MSGID in the DOMAINNAME message catalog of the current
+   LC_MESSAGES locale.  */
+char *
+DGETTEXT (const char *domainname, const char *msgid)
+{
+  return DCGETTEXT (domainname, msgid, LC_MESSAGES);
+}
+
+#ifdef _LIBC
+/* Alias for function name in GNU C Library.  */
+weak_alias (__dgettext, dgettext);
+#endif
diff --git a/intl/dngettext.c b/intl/dngettext.c
new file mode 100644 (file)
index 0000000..7815637
--- /dev/null
@@ -0,0 +1,59 @@
+/* Implementation of the dngettext(3) function.
+   Copyright (C) 1995-1997, 2000-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "gettextP.h"
+
+#include <locale.h>
+
+#ifdef _LIBC
+# include <libintl.h>
+#else
+# include "libgnuintl.h"
+#endif
+
+/* @@ end of prolog @@ */
+
+/* Names for the libintl functions are a problem.  They must not clash
+   with existing names and they should follow ANSI C.  But this source
+   code is also used in GNU C Library where the names have a __
+   prefix.  So we have to make a difference here.  */
+#ifdef _LIBC
+# define DNGETTEXT __dngettext
+# define DCNGETTEXT __dcngettext
+#else
+# define DNGETTEXT libintl_dngettext
+# define DCNGETTEXT libintl_dcngettext
+#endif
+
+/* Look up MSGID in the DOMAINNAME message catalog of the current
+   LC_MESSAGES locale and skip message according to the plural form.  */
+char *
+DNGETTEXT (const char *domainname,
+          const char *msgid1, const char *msgid2, unsigned long int n)
+{
+  return DCNGETTEXT (domainname, msgid1, msgid2, n, LC_MESSAGES);
+}
+
+#ifdef _LIBC
+/* Alias for function name in GNU C Library.  */
+weak_alias (__dngettext, dngettext);
+#endif
diff --git a/intl/eval-plural.h b/intl/eval-plural.h
new file mode 100644 (file)
index 0000000..01bd5af
--- /dev/null
@@ -0,0 +1,108 @@
+/* Plural expression evaluation.
+   Copyright (C) 2000-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifndef STATIC
+#define STATIC static
+#endif
+
+/* Evaluate the plural expression and return an index value.  */
+STATIC
+unsigned long int
+internal_function
+plural_eval (struct expression *pexp, unsigned long int n)
+{
+  switch (pexp->nargs)
+    {
+    case 0:
+      switch (pexp->operation)
+       {
+       case var:
+         return n;
+       case num:
+         return pexp->val.num;
+       default:
+         break;
+       }
+      /* NOTREACHED */
+      break;
+    case 1:
+      {
+       /* pexp->operation must be lnot.  */
+       unsigned long int arg = plural_eval (pexp->val.args[0], n);
+       return ! arg;
+      }
+    case 2:
+      {
+       unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
+       if (pexp->operation == lor)
+         return leftarg || plural_eval (pexp->val.args[1], n);
+       else if (pexp->operation == land)
+         return leftarg && plural_eval (pexp->val.args[1], n);
+       else
+         {
+           unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
+
+           switch (pexp->operation)
+             {
+             case mult:
+               return leftarg * rightarg;
+             case divide:
+#if !INTDIV0_RAISES_SIGFPE
+               if (rightarg == 0)
+                 raise (SIGFPE);
+#endif
+               return leftarg / rightarg;
+             case module:
+#if !INTDIV0_RAISES_SIGFPE
+               if (rightarg == 0)
+                 raise (SIGFPE);
+#endif
+               return leftarg % rightarg;
+             case plus:
+               return leftarg + rightarg;
+             case minus:
+               return leftarg - rightarg;
+             case less_than:
+               return leftarg < rightarg;
+             case greater_than:
+               return leftarg > rightarg;
+             case less_or_equal:
+               return leftarg <= rightarg;
+             case greater_or_equal:
+               return leftarg >= rightarg;
+             case equal:
+               return leftarg == rightarg;
+             case not_equal:
+               return leftarg != rightarg;
+             default:
+               break;
+             }
+         }
+       /* NOTREACHED */
+       break;
+      }
+    case 3:
+      {
+       /* pexp->operation must be qmop.  */
+       unsigned long int boolarg = plural_eval (pexp->val.args[0], n);
+       return plural_eval (pexp->val.args[boolarg ? 1 : 2], n);
+      }
+    }
+  /* NOTREACHED */
+  return 0;
+}
diff --git a/intl/explodename.c b/intl/explodename.c
new file mode 100644 (file)
index 0000000..52c25e7
--- /dev/null
@@ -0,0 +1,185 @@
+/* Copyright (C) 1995-1998, 2000-2001, 2003 Free Software Foundation, Inc.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include "loadinfo.h"
+
+/* On some strange systems still no definition of NULL is found.  Sigh!  */
+#ifndef NULL
+# if defined __STDC__ && __STDC__
+#  define NULL ((void *) 0)
+# else
+#  define NULL 0
+# endif
+#endif
+
+/* @@ end of prolog @@ */
+
+char *
+_nl_find_language (const char *name)
+{
+  while (name[0] != '\0' && name[0] != '_' && name[0] != '@'
+        && name[0] != '+' && name[0] != ',')
+    ++name;
+
+  return (char *) name;
+}
+
+
+int
+_nl_explode_name (char *name,
+                 const char **language, const char **modifier,
+                 const char **territory, const char **codeset,
+                 const char **normalized_codeset, const char **special,
+                 const char **sponsor, const char **revision)
+{
+  enum { undecided, xpg, cen } syntax;
+  char *cp;
+  int mask;
+
+  *modifier = NULL;
+  *territory = NULL;
+  *codeset = NULL;
+  *normalized_codeset = NULL;
+  *special = NULL;
+  *sponsor = NULL;
+  *revision = NULL;
+
+  /* Now we determine the single parts of the locale name.  First
+     look for the language.  Termination symbols are `_' and `@' if
+     we use XPG4 style, and `_', `+', and `,' if we use CEN syntax.  */
+  mask = 0;
+  syntax = undecided;
+  *language = cp = name;
+  cp = _nl_find_language (*language);
+
+  if (*language == cp)
+    /* This does not make sense: language has to be specified.  Use
+       this entry as it is without exploding.  Perhaps it is an alias.  */
+    cp = strchr (*language, '\0');
+  else if (cp[0] == '_')
+    {
+      /* Next is the territory.  */
+      cp[0] = '\0';
+      *territory = ++cp;
+
+      while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
+            && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
+       ++cp;
+
+      mask |= TERRITORY;
+
+      if (cp[0] == '.')
+       {
+         /* Next is the codeset.  */
+         syntax = xpg;
+         cp[0] = '\0';
+         *codeset = ++cp;
+
+         while (cp[0] != '\0' && cp[0] != '@')
+           ++cp;
+
+         mask |= XPG_CODESET;
+
+         if (*codeset != cp && (*codeset)[0] != '\0')
+           {
+             *normalized_codeset = _nl_normalize_codeset (*codeset,
+                                                          cp - *codeset);
+             if (strcmp (*codeset, *normalized_codeset) == 0)
+               free ((char *) *normalized_codeset);
+             else
+               mask |= XPG_NORM_CODESET;
+           }
+       }
+    }
+
+  if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
+    {
+      /* Next is the modifier.  */
+      syntax = cp[0] == '@' ? xpg : cen;
+      cp[0] = '\0';
+      *modifier = ++cp;
+
+      while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
+            && cp[0] != ',' && cp[0] != '_')
+       ++cp;
+
+      mask |= XPG_MODIFIER | CEN_AUDIENCE;
+    }
+
+  if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
+    {
+      syntax = cen;
+
+      if (cp[0] == '+')
+       {
+         /* Next is special application (CEN syntax).  */
+         cp[0] = '\0';
+         *special = ++cp;
+
+         while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
+           ++cp;
+
+         mask |= CEN_SPECIAL;
+       }
+
+      if (cp[0] == ',')
+       {
+         /* Next is sponsor (CEN syntax).  */
+         cp[0] = '\0';
+         *sponsor = ++cp;
+
+         while (cp[0] != '\0' && cp[0] != '_')
+           ++cp;
+
+         mask |= CEN_SPONSOR;
+       }
+
+      if (cp[0] == '_')
+       {
+         /* Next is revision (CEN syntax).  */
+         cp[0] = '\0';
+         *revision = ++cp;
+
+         mask |= CEN_REVISION;
+       }
+    }
+
+  /* For CEN syntax values it might be important to have the
+     separator character in the file name, not for XPG syntax.  */
+  if (syntax == xpg)
+    {
+      if (*territory != NULL && (*territory)[0] == '\0')
+       mask &= ~TERRITORY;
+
+      if (*codeset != NULL && (*codeset)[0] == '\0')
+       mask &= ~XPG_CODESET;
+
+      if (*modifier != NULL && (*modifier)[0] == '\0')
+       mask &= ~XPG_MODIFIER;
+    }
+
+  return mask;
+}
diff --git a/intl/finddomain.c b/intl/finddomain.c
new file mode 100644 (file)
index 0000000..4992a8c
--- /dev/null
@@ -0,0 +1,192 @@
+/* Handle list of needed message catalogs
+   Copyright (C) 1995-1999, 2000-2001, 2003 Free Software Foundation, Inc.
+   Written by Ulrich Drepper <drepper@gnu.org>, 1995.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined HAVE_UNISTD_H || defined _LIBC
+# include <unistd.h>
+#endif
+
+#include "gettextP.h"
+#ifdef _LIBC
+# include <libintl.h>
+#else
+# include "libgnuintl.h"
+#endif
+
+/* @@ end of prolog @@ */
+/* List of already loaded domains.  */
+static struct loaded_l10nfile *_nl_loaded_domains;
+
+
+/* Return a data structure describing the message catalog described by
+   the DOMAINNAME and CATEGORY parameters with respect to the currently
+   established bindings.  */
+struct loaded_l10nfile *
+internal_function
+_nl_find_domain (const char *dirname, char *locale,
+                const char *domainname, struct binding *domainbinding)
+{
+  struct loaded_l10nfile *retval;
+  const char *language;
+  const char *modifier;
+  const char *territory;
+  const char *codeset;
+  const char *normalized_codeset;
+  const char *special;
+  const char *sponsor;
+  const char *revision;
+  const char *alias_value;
+  int mask;
+
+  /* LOCALE can consist of up to four recognized parts for the XPG syntax:
+
+               language[_territory[.codeset]][@modifier]
+
+     and six parts for the CEN syntax:
+
+       language[_territory][+audience][+special][,[sponsor][_revision]]
+
+     Beside the first part all of them are allowed to be missing.  If
+     the full specified locale is not found, the less specific one are
+     looked for.  The various parts will be stripped off according to
+     the following order:
+               (1) revision
+               (2) sponsor
+               (3) special
+               (4) codeset
+               (5) normalized codeset
+               (6) territory
+               (7) audience/modifier
+   */
+
+  /* If we have already tested for this locale entry there has to
+     be one data set in the list of loaded domains.  */
+  retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
+                              strlen (dirname) + 1, 0, locale, NULL, NULL,
+                              NULL, NULL, NULL, NULL, NULL, domainname, 0);
+  if (retval != NULL)
+    {
+      /* We know something about this locale.  */
+      int cnt;
+
+      if (retval->decided == 0)
+       _nl_load_domain (retval, domainbinding);
+
+      if (retval->data != NULL)
+       return retval;
+
+      for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
+       {
+         if (retval->successor[cnt]->decided == 0)
+           _nl_load_domain (retval->successor[cnt], domainbinding);
+
+         if (retval->successor[cnt]->data != NULL)
+           break;
+       }
+      return cnt >= 0 ? retval : NULL;
+      /* NOTREACHED */
+    }
+
+  /* See whether the locale value is an alias.  If yes its value
+     *overwrites* the alias name.  No test for the original value is
+     done.  */
+  alias_value = _nl_expand_alias (locale);
+  if (alias_value != NULL)
+    {
+#if defined _LIBC || defined HAVE_STRDUP
+      locale = strdup (alias_value);
+      if (locale == NULL)
+       return NULL;
+#else
+      size_t len = strlen (alias_value) + 1;
+      locale = (char *) malloc (len);
+      if (locale == NULL)
+       return NULL;
+
+      memcpy (locale, alias_value, len);
+#endif
+    }
+
+  /* Now we determine the single parts of the locale name.  First
+     look for the language.  Termination symbols are `_' and `@' if
+     we use XPG4 style, and `_', `+', and `,' if we use CEN syntax.  */
+  mask = _nl_explode_name (locale, &language, &modifier, &territory,
+                          &codeset, &normalized_codeset, &special,
+                          &sponsor, &revision);
+
+  /* Create all possible locale entries which might be interested in
+     generalization.  */
+  retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
+                              strlen (dirname) + 1, mask, language, territory,
+                              codeset, normalized_codeset, modifier, special,
+                              sponsor, revision, domainname, 1);
+  if (retval == NULL)
+    /* This means we are out of core.  */
+    return NULL;
+
+  if (retval->decided == 0)
+    _nl_load_domain (retval, domainbinding);
+  if (retval->data == NULL)
+    {
+      int cnt;
+      for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
+       {
+         if (retval->successor[cnt]->decided == 0)
+           _nl_load_domain (retval->successor[cnt], domainbinding);
+         if (retval->successor[cnt]->data != NULL)
+           break;
+       }
+    }
+
+  /* The room for an alias was dynamically allocated.  Free it now.  */
+  if (alias_value != NULL)
+    free (locale);
+
+  /* The space for normalized_codeset is dynamically allocated.  Free it.  */
+  if (mask & XPG_NORM_CODESET)
+    free ((void *) normalized_codeset);
+
+  return retval;
+}
+
+
+#ifdef _LIBC
+libc_freeres_fn (free_mem)
+{
+  struct loaded_l10nfile *runp = _nl_loaded_domains;
+
+  while (runp != NULL)
+    {
+      struct loaded_l10nfile *here = runp;
+      if (runp->data != NULL)
+       _nl_unload_domain ((struct loaded_domain *) runp->data);
+      runp = runp->next;
+      free ((char *) here->filename);
+      free (here);
+    }
+}
+#endif
diff --git a/intl/gettext.c b/intl/gettext.c
new file mode 100644 (file)
index 0000000..92c42fa
--- /dev/null
@@ -0,0 +1,63 @@
+/* Implementation of gettext(3) function.
+   Copyright (C) 1995, 1997, 2000-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef _LIBC
+# define __need_NULL
+# include <stddef.h>
+#else
+# include <stdlib.h>           /* Just for NULL.  */
+#endif
+
+#include "gettextP.h"
+#ifdef _LIBC
+# include <libintl.h>
+#else
+# include "libgnuintl.h"
+#endif
+
+/* @@ end of prolog @@ */
+
+/* Names for the libintl functions are a problem.  They must not clash
+   with existing names and they should follow ANSI C.  But this source
+   code is also used in GNU C Library where the names have a __
+   prefix.  So we have to make a difference here.  */
+#ifdef _LIBC
+# define GETTEXT __gettext
+# define DCGETTEXT INTUSE(__dcgettext)
+#else
+# define GETTEXT libintl_gettext
+# define DCGETTEXT libintl_dcgettext
+#endif
+
+/* Look up MSGID in the current default message catalog for the current
+   LC_MESSAGES locale.  If not found, returns MSGID itself (the default
+   text).  */
+char *
+GETTEXT (const char *msgid)
+{
+  return DCGETTEXT (NULL, msgid, LC_MESSAGES);
+}
+
+#ifdef _LIBC
+/* Alias for function name in GNU C Library.  */
+weak_alias (__gettext, gettext);
+#endif
diff --git a/intl/gettextP.h b/intl/gettextP.h
new file mode 100644 (file)
index 0000000..d73b3e1
--- /dev/null
@@ -0,0 +1,218 @@
+/* Header describing internals of libintl library.
+   Copyright (C) 1995-1999, 2000-2005 Free Software Foundation, Inc.
+   Written by Ulrich Drepper <drepper@cygnus.com>, 1995.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifndef _GETTEXTP_H
+#define _GETTEXTP_H
+
+#include <stddef.h>            /* Get size_t.  */
+
+#ifdef _LIBC
+# include "../iconv/gconv_int.h"
+#else
+# if HAVE_ICONV
+#  include <iconv.h>
+# endif
+#endif
+
+#include "loadinfo.h"
+
+#include "gmo.h"               /* Get nls_uint32.  */
+
+/* @@ end of prolog @@ */
+
+#ifndef internal_function
+# define internal_function
+#endif
+
+#ifndef attribute_hidden
+# define attribute_hidden
+#endif
+
+/* Tell the compiler when a conditional or integer expression is
+   almost always true or almost always false.  */
+#ifndef HAVE_BUILTIN_EXPECT
+# define __builtin_expect(expr, val) (expr)
+#endif
+
+#ifndef W
+# define W(flag, data) ((flag) ? SWAP (data) : (data))
+#endif
+
+
+#ifdef _LIBC
+# include <byteswap.h>
+# define SWAP(i) bswap_32 (i)
+#else
+static inline nls_uint32
+SWAP (i)
+     nls_uint32 i;
+{
+  return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
+}
+#endif
+
+
+/* In-memory representation of system dependent string.  */
+struct sysdep_string_desc
+{
+  /* Length of addressed string, including the trailing NUL.  */
+  size_t length;
+  /* Pointer to addressed string.  */
+  const char *pointer;
+};
+
+/* The representation of an opened message catalog.  */
+struct loaded_domain
+{
+  /* Pointer to memory containing the .mo file.  */
+  const char *data;
+  /* 1 if the memory is mmap()ed, 0 if the memory is malloc()ed.  */
+  int use_mmap;
+  /* Size of mmap()ed memory.  */
+  size_t mmap_size;
+  /* 1 if the .mo file uses a different endianness than this machine.  */
+  int must_swap;
+  /* Pointer to additional malloc()ed memory.  */
+  void *malloced;
+
+  /* Number of static strings pairs.  */
+  nls_uint32 nstrings;
+  /* Pointer to descriptors of original strings in the file.  */
+  const struct string_desc *orig_tab;
+  /* Pointer to descriptors of translated strings in the file.  */
+  const struct string_desc *trans_tab;
+
+  /* Number of system dependent strings pairs.  */
+  nls_uint32 n_sysdep_strings;
+  /* Pointer to descriptors of original sysdep strings.  */
+  const struct sysdep_string_desc *orig_sysdep_tab;
+  /* Pointer to descriptors of translated sysdep strings.  */
+  const struct sysdep_string_desc *trans_sysdep_tab;
+
+  /* Size of hash table.  */
+  nls_uint32 hash_size;
+  /* Pointer to hash table.  */
+  const nls_uint32 *hash_tab;
+  /* 1 if the hash table uses a different endianness than this machine.  */
+  int must_swap_hash_tab;
+
+  int codeset_cntr;
+#ifdef _LIBC
+  __gconv_t conv;
+#else
+# if HAVE_ICONV
+  iconv_t conv;
+# endif
+#endif
+  char **conv_tab;
+
+  struct expression *plural;
+  unsigned long int nplurals;
+};
+
+/* We want to allocate a string at the end of the struct.  But ISO C
+   doesn't allow zero sized arrays.  */
+#ifdef __GNUC__
+# define ZERO 0
+#else
+# define ZERO 1
+#endif
+
+/* A set of settings bound to a message domain.  Used to store settings
+   from bindtextdomain() and bind_textdomain_codeset().  */
+struct binding
+{
+  struct binding *next;
+  char *dirname;
+  int codeset_cntr;    /* Incremented each time codeset changes.  */
+  char *codeset;
+  char domainname[ZERO];
+};
+
+/* A counter which is incremented each time some previous translations
+   become invalid.
+   This variable is part of the external ABI of the GNU libintl.  */
+extern int _nl_msg_cat_cntr;
+
+#ifndef _LIBC
+const char *_nl_language_preferences_default (void);
+const char *_nl_locale_name_posix (int category, const char *categoryname);
+const char *_nl_locale_name_default (void);
+const char *_nl_locale_name (int category, const char *categoryname);
+#endif
+
+struct loaded_l10nfile *_nl_find_domain (const char *__dirname, char *__locale,
+                                        const char *__domainname,
+                                        struct binding *__domainbinding)
+     internal_function;
+void _nl_load_domain (struct loaded_l10nfile *__domain,
+                     struct binding *__domainbinding)
+     internal_function;
+void _nl_unload_domain (struct loaded_domain *__domain)
+     internal_function;
+const char *_nl_init_domain_conv (struct loaded_l10nfile *__domain_file,
+                                 struct loaded_domain *__domain,
+                                 struct binding *__domainbinding)
+     internal_function;
+void _nl_free_domain_conv (struct loaded_domain *__domain)
+     internal_function;
+
+char *_nl_find_msg (struct loaded_l10nfile *domain_file,
+                   struct binding *domainbinding, const char *msgid,
+                   size_t *lengthp)
+     internal_function;
+
+#ifdef _LIBC
+extern char *__gettext (const char *__msgid);
+extern char *__dgettext (const char *__domainname, const char *__msgid);
+extern char *__dcgettext (const char *__domainname, const char *__msgid,
+                         int __category);
+extern char *__ngettext (const char *__msgid1, const char *__msgid2,
+                        unsigned long int __n);
+extern char *__dngettext (const char *__domainname,
+                         const char *__msgid1, const char *__msgid2,
+                         unsigned long int n);
+extern char *__dcngettext (const char *__domainname,
+                          const char *__msgid1, const char *__msgid2,
+                          unsigned long int __n, int __category);
+extern char *__dcigettext (const char *__domainname,
+                          const char *__msgid1, const char *__msgid2,
+                          int __plural, unsigned long int __n,
+                          int __category);
+extern char *__textdomain (const char *__domainname);
+extern char *__bindtextdomain (const char *__domainname,
+                              const char *__dirname);
+extern char *__bind_textdomain_codeset (const char *__domainname,
+                                       const char *__codeset);
+#else
+/* Declare the exported libintl_* functions, in a way that allows us to
+   call them under their real name.  */
+# undef _INTL_REDIRECT_INLINE
+# undef _INTL_REDIRECT_MACROS
+# define _INTL_REDIRECT_MACROS
+# include "libgnuintl.h"
+extern char *libintl_dcigettext (const char *__domainname,
+                                const char *__msgid1, const char *__msgid2,
+                                int __plural, unsigned long int __n,
+                                int __category);
+#endif
+
+/* @@ begin of epilog @@ */
+
+#endif /* gettextP.h  */
diff --git a/intl/gmo.h b/intl/gmo.h
new file mode 100644 (file)
index 0000000..e7c9cc1
--- /dev/null
@@ -0,0 +1,149 @@
+/* Description of GNU message catalog format: general file layout.
+   Copyright (C) 1995, 1997, 2000-2002, 2004 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifndef _GETTEXT_H
+#define _GETTEXT_H 1
+
+#include <limits.h>
+
+/* @@ end of prolog @@ */
+
+/* The magic number of the GNU message catalog format.  */
+#define _MAGIC 0x950412de
+#define _MAGIC_SWAPPED 0xde120495
+
+/* Revision number of the currently used .mo (binary) file format.  */
+#define MO_REVISION_NUMBER 0
+#define MO_REVISION_NUMBER_WITH_SYSDEP_I 1
+
+/* The following contortions are an attempt to use the C preprocessor
+   to determine an unsigned integral type that is 32 bits wide.  An
+   alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
+   as of version autoconf-2.13, the AC_CHECK_SIZEOF macro doesn't work
+   when cross-compiling.  */
+
+#if __STDC__
+# define UINT_MAX_32_BITS 4294967295U
+#else
+# define UINT_MAX_32_BITS 0xFFFFFFFF
+#endif
+
+/* If UINT_MAX isn't defined, assume it's a 32-bit type.
+   This should be valid for all systems GNU cares about because
+   that doesn't include 16-bit systems, and only modern systems
+   (that certainly have <limits.h>) have 64+-bit integral types.  */
+
+#ifndef UINT_MAX
+# define UINT_MAX UINT_MAX_32_BITS
+#endif
+
+#if UINT_MAX == UINT_MAX_32_BITS
+typedef unsigned nls_uint32;
+#else
+# if USHRT_MAX == UINT_MAX_32_BITS
+typedef unsigned short nls_uint32;
+# else
+#  if ULONG_MAX == UINT_MAX_32_BITS
+typedef unsigned long nls_uint32;
+#  else
+  /* The following line is intended to throw an error.  Using #error is
+     not portable enough.  */
+  "Cannot determine unsigned 32-bit data type."
+#  endif
+# endif
+#endif
+
+
+/* Header for binary .mo file format.  */
+struct mo_file_header
+{
+  /* The magic number.  */
+  nls_uint32 magic;
+  /* The revision number of the file format.  */
+  nls_uint32 revision;
+
+  /* The following are only used in .mo files with major revision 0 or 1.  */
+
+  /* The number of strings pairs.  */
+  nls_uint32 nstrings;
+  /* Offset of table with start offsets of original strings.  */
+  nls_uint32 orig_tab_offset;
+  /* Offset of table with start offsets of translated strings.  */
+  nls_uint32 trans_tab_offset;
+  /* Size of hash table.  */
+  nls_uint32 hash_tab_size;
+  /* Offset of first hash table entry.  */
+  nls_uint32 hash_tab_offset;
+
+  /* The following are only used in .mo files with minor revision >= 1.  */
+
+  /* The number of system dependent segments.  */
+  nls_uint32 n_sysdep_segments;
+  /* Offset of table describing system dependent segments.  */
+  nls_uint32 sysdep_segments_offset;
+  /* The number of system dependent strings pairs.  */
+  nls_uint32 n_sysdep_strings;
+  /* Offset of table with start offsets of original sysdep strings.  */
+  nls_uint32 orig_sysdep_tab_offset;
+  /* Offset of table with start offsets of translated sysdep strings.  */
+  nls_uint32 trans_sysdep_tab_offset;
+};
+
+/* Descriptor for static string contained in the binary .mo file.  */
+struct string_desc
+{
+  /* Length of addressed string, not including the trailing NUL.  */
+  nls_uint32 length;
+  /* Offset of string in file.  */
+  nls_uint32 offset;
+};
+
+/* The following are only used in .mo files with minor revision >= 1.  */
+
+/* Descriptor for system dependent string segment.  */
+struct sysdep_segment
+{
+  /* Length of addressed string, including the trailing NUL.  */
+  nls_uint32 length;
+  /* Offset of string in file.  */
+  nls_uint32 offset;
+};
+
+/* Descriptor for system dependent string.  */
+struct sysdep_string
+{
+  /* Offset of static string segments in file.  */
+  nls_uint32 offset;
+  /* Alternating sequence of static and system dependent segments.
+     The last segment is a static segment, including the trailing NUL.  */
+  struct segment_pair
+  {
+    /* Size of static segment.  */
+    nls_uint32 segsize;
+    /* Reference to system dependent string segment, or ~0 at the end.  */
+    nls_uint32 sysdepref;
+  } segments[1];
+};
+
+/* Marker for the end of the segments[] array.  This has the value 0xFFFFFFFF,
+   regardless whether 'int' is 16 bit, 32 bit, or 64 bit.  */
+#define SEGMENTS_END ((nls_uint32) ~0)
+
+/* @@ begin of epilog @@ */
+
+#endif /* gettext.h  */
diff --git a/intl/hash-string.h b/intl/hash-string.h
new file mode 100644 (file)
index 0000000..093e3b1
--- /dev/null
@@ -0,0 +1,48 @@
+/* Description of GNU message catalog format: string hashing function.
+   Copyright (C) 1995, 1997-1998, 2000-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+/* @@ end of prolog @@ */
+
+/* We assume to have `unsigned long int' value with at least 32 bits.  */
+#define HASHWORDBITS 32
+
+
+/* Defines the so called `hashpjw' function by P.J. Weinberger
+   [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
+   1986, 1987 Bell Telephone Laboratories, Inc.]  */
+static inline unsigned long int
+hash_string (const char *str_param)
+{
+  unsigned long int hval, g;
+  const char *str = str_param;
+
+  /* Compute the hash value for the given string.  */
+  hval = 0;
+  while (*str != '\0')
+    {
+      hval <<= 4;
+      hval += (unsigned char) *str++;
+      g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4));
+      if (g != 0)
+       {
+         hval ^= g >> (HASHWORDBITS - 8);
+         hval ^= g;
+       }
+    }
+  return hval;
+}
diff --git a/intl/intl-compat.c b/intl/intl-compat.c
new file mode 100644 (file)
index 0000000..96f9d95
--- /dev/null
@@ -0,0 +1,131 @@
+/* intl-compat.c - Stub functions to call gettext functions from GNU gettext
+   Library.
+   Copyright (C) 1995, 2000-2003 Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "gettextP.h"
+
+/* @@ end of prolog @@ */
+
+/* This file redirects the gettext functions (without prefix) to those
+   defined in the included GNU libintl library (with "libintl_" prefix).
+   It is compiled into libintl in order to make the AM_GNU_GETTEXT test
+   of gettext <= 0.11.2 work with the libintl library >= 0.11.3 which
+   has the redirections primarily in the <libintl.h> include file.
+   It is also compiled into libgnuintl so that libgnuintl.so can be used
+   as LD_PRELOADable library on glibc systems, to provide the extra
+   features that the functions in the libc don't have (namely, logging).  */
+
+
+#undef gettext
+#undef dgettext
+#undef dcgettext
+#undef ngettext
+#undef dngettext
+#undef dcngettext
+#undef textdomain
+#undef bindtextdomain
+#undef bind_textdomain_codeset
+
+
+/* When building a DLL, we must export some functions.  Note that because
+   the functions are only defined for binary backward compatibility, we
+   don't need to use __declspec(dllimport) in any case.  */
+#if defined _MSC_VER && BUILDING_DLL
+# define DLL_EXPORTED __declspec(dllexport)
+#else
+# define DLL_EXPORTED
+#endif
+
+
+DLL_EXPORTED
+char *
+gettext (const char *msgid)
+{
+  return libintl_gettext (msgid);
+}
+
+
+DLL_EXPORTED
+char *
+dgettext (const char *domainname, const char *msgid)
+{
+  return libintl_dgettext (domainname, msgid);
+}
+
+
+DLL_EXPORTED
+char *
+dcgettext (const char *domainname, const char *msgid, int category)
+{
+  return libintl_dcgettext (domainname, msgid, category);
+}
+
+
+DLL_EXPORTED
+char *
+ngettext (const char *msgid1, const char *msgid2, unsigned long int n)
+{
+  return libintl_ngettext (msgid1, msgid2, n);
+}
+
+
+DLL_EXPORTED
+char *
+dngettext (const char *domainname,
+          const char *msgid1, const char *msgid2, unsigned long int n)
+{
+  return libintl_dngettext (domainname, msgid1, msgid2, n);
+}
+
+
+DLL_EXPORTED
+char *
+dcngettext (const char *domainname,
+           const char *msgid1, const char *msgid2, unsigned long int n,
+           int category)
+{
+  return libintl_dcngettext (domainname, msgid1, msgid2, n, category);
+}
+
+
+DLL_EXPORTED
+char *
+textdomain (const char *domainname)
+{
+  return libintl_textdomain (domainname);
+}
+
+
+DLL_EXPORTED
+char *
+bindtextdomain (const char *domainname, const char *dirname)
+{
+  return libintl_bindtextdomain (domainname, dirname);
+}
+
+
+DLL_EXPORTED
+char *
+bind_textdomain_codeset (const char *domainname, const char *codeset)
+{
+  return libintl_bind_textdomain_codeset (domainname, codeset);
+}
diff --git a/intl/l10nflist.c b/intl/l10nflist.c
new file mode 100644 (file)
index 0000000..5124d73
--- /dev/null
@@ -0,0 +1,421 @@
+/* Copyright (C) 1995-1999, 2000-2004 Free Software Foundation, Inc.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+/* Tell glibc's <string.h> to provide a prototype for stpcpy().
+   This must come before <config.h> because <config.h> may include
+   <features.h>, and once <features.h> has been included, it's too late.  */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE   1
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <string.h>
+
+#if defined _LIBC || defined HAVE_ARGZ_H
+# include <argz.h>
+#endif
+#include <ctype.h>
+#include <sys/types.h>
+#include <stdlib.h>
+
+#include "loadinfo.h"
+
+/* On some strange systems still no definition of NULL is found.  Sigh!  */
+#ifndef NULL
+# if defined __STDC__ && __STDC__
+#  define NULL ((void *) 0)
+# else
+#  define NULL 0
+# endif
+#endif
+
+/* @@ end of prolog @@ */
+
+#ifdef _LIBC
+/* Rename the non ANSI C functions.  This is required by the standard
+   because some ANSI C functions will require linking with this object
+   file and the name space must not be polluted.  */
+# ifndef stpcpy
+#  define stpcpy(dest, src) __stpcpy(dest, src)
+# endif
+#else
+# ifndef HAVE_STPCPY
+static char *stpcpy (char *dest, const char *src);
+# endif
+#endif
+
+/* Pathname support.
+   ISSLASH(C)           tests whether C is a directory separator character.
+   IS_ABSOLUTE_PATH(P)  tests whether P is an absolute path.  If it is not,
+                        it may be concatenated to a directory pathname.
+ */
+#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
+  /* Win32, Cygwin, OS/2, DOS */
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+# define HAS_DEVICE(P) \
+    ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
+     && (P)[1] == ':')
+# define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P))
+#else
+  /* Unix */
+# define ISSLASH(C) ((C) == '/')
+# define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0])
+#endif
+
+/* Define function which are usually not available.  */
+
+#if !defined _LIBC && !defined HAVE___ARGZ_COUNT
+/* Returns the number of strings in ARGZ.  */
+static size_t
+argz_count__ (const char *argz, size_t len)
+{
+  size_t count = 0;
+  while (len > 0)
+    {
+      size_t part_len = strlen (argz);
+      argz += part_len + 1;
+      len -= part_len + 1;
+      count++;
+    }
+  return count;
+}
+# undef __argz_count
+# define __argz_count(argz, len) argz_count__ (argz, len)
+#else
+# ifdef _LIBC
+#  define __argz_count(argz, len) INTUSE(__argz_count) (argz, len)
+# endif
+#endif /* !_LIBC && !HAVE___ARGZ_COUNT */
+
+#if !defined _LIBC && !defined HAVE___ARGZ_STRINGIFY
+/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
+   except the last into the character SEP.  */
+static void
+argz_stringify__ (char *argz, size_t len, int sep)
+{
+  while (len > 0)
+    {
+      size_t part_len = strlen (argz);
+      argz += part_len;
+      len -= part_len + 1;
+      if (len > 0)
+       *argz++ = sep;
+    }
+}
+# undef __argz_stringify
+# define __argz_stringify(argz, len, sep) argz_stringify__ (argz, len, sep)
+#else
+# ifdef _LIBC
+#  define __argz_stringify(argz, len, sep) \
+  INTUSE(__argz_stringify) (argz, len, sep)
+# endif
+#endif /* !_LIBC && !HAVE___ARGZ_STRINGIFY */
+
+#if !defined _LIBC && !defined HAVE___ARGZ_NEXT
+static char *
+argz_next__ (char *argz, size_t argz_len, const char *entry)
+{
+  if (entry)
+    {
+      if (entry < argz + argz_len)
+        entry = strchr (entry, '\0') + 1;
+
+      return entry >= argz + argz_len ? NULL : (char *) entry;
+    }
+  else
+    if (argz_len > 0)
+      return argz;
+    else
+      return 0;
+}
+# undef __argz_next
+# define __argz_next(argz, len, entry) argz_next__ (argz, len, entry)
+#endif /* !_LIBC && !HAVE___ARGZ_NEXT */
+
+
+/* Return number of bits set in X.  */
+static inline int
+pop (int x)
+{
+  /* We assume that no more than 16 bits are used.  */
+  x = ((x & ~0x5555) >> 1) + (x & 0x5555);
+  x = ((x & ~0x3333) >> 2) + (x & 0x3333);
+  x = ((x >> 4) + x) & 0x0f0f;
+  x = ((x >> 8) + x) & 0xff;
+
+  return x;
+}
+
+\f
+struct loaded_l10nfile *
+_nl_make_l10nflist (struct loaded_l10nfile **l10nfile_list,
+                   const char *dirlist, size_t dirlist_len,
+                   int mask, const char *language, const char *territory,
+                   const char *codeset, const char *normalized_codeset,
+                   const char *modifier, const char *special,
+                   const char *sponsor, const char *revision,
+                   const char *filename, int do_allocate)
+{
+  char *abs_filename;
+  struct loaded_l10nfile **lastp;
+  struct loaded_l10nfile *retval;
+  char *cp;
+  size_t dirlist_count;
+  size_t entries;
+  int cnt;
+
+  /* If LANGUAGE contains an absolute directory specification, we ignore
+     DIRLIST.  */
+  if (IS_ABSOLUTE_PATH (language))
+    dirlist_len = 0;
+
+  /* Allocate room for the full file name.  */
+  abs_filename = (char *) malloc (dirlist_len
+                                 + strlen (language)
+                                 + ((mask & TERRITORY) != 0
+                                    ? strlen (territory) + 1 : 0)
+                                 + ((mask & XPG_CODESET) != 0
+                                    ? strlen (codeset) + 1 : 0)
+                                 + ((mask & XPG_NORM_CODESET) != 0
+                                    ? strlen (normalized_codeset) + 1 : 0)
+                                 + (((mask & XPG_MODIFIER) != 0
+                                     || (mask & CEN_AUDIENCE) != 0)
+                                    ? strlen (modifier) + 1 : 0)
+                                 + ((mask & CEN_SPECIAL) != 0
+                                    ? strlen (special) + 1 : 0)
+                                 + (((mask & CEN_SPONSOR) != 0
+                                     || (mask & CEN_REVISION) != 0)
+                                    ? (1 + ((mask & CEN_SPONSOR) != 0
+                                            ? strlen (sponsor) : 0)
+                                       + ((mask & CEN_REVISION) != 0
+                                          ? strlen (revision) + 1 : 0)) : 0)
+                                 + 1 + strlen (filename) + 1);
+
+  if (abs_filename == NULL)
+    return NULL;
+
+  /* Construct file name.  */
+  cp = abs_filename;
+  if (dirlist_len > 0)
+    {
+      memcpy (cp, dirlist, dirlist_len);
+      __argz_stringify (cp, dirlist_len, PATH_SEPARATOR);
+      cp += dirlist_len;
+      cp[-1] = '/';
+    }
+
+  cp = stpcpy (cp, language);
+
+  if ((mask & TERRITORY) != 0)
+    {
+      *cp++ = '_';
+      cp = stpcpy (cp, territory);
+    }
+  if ((mask & XPG_CODESET) != 0)
+    {
+      *cp++ = '.';
+      cp = stpcpy (cp, codeset);
+    }
+  if ((mask & XPG_NORM_CODESET) != 0)
+    {
+      *cp++ = '.';
+      cp = stpcpy (cp, normalized_codeset);
+    }
+  if ((mask & (XPG_MODIFIER | CEN_AUDIENCE)) != 0)
+    {
+      /* This component can be part of both syntaces but has different
+        leading characters.  For CEN we use `+', else `@'.  */
+      *cp++ = (mask & CEN_AUDIENCE) != 0 ? '+' : '@';
+      cp = stpcpy (cp, modifier);
+    }
+  if ((mask & CEN_SPECIAL) != 0)
+    {
+      *cp++ = '+';
+      cp = stpcpy (cp, special);
+    }
+  if ((mask & (CEN_SPONSOR | CEN_REVISION)) != 0)
+    {
+      *cp++ = ',';
+      if ((mask & CEN_SPONSOR) != 0)
+       cp = stpcpy (cp, sponsor);
+      if ((mask & CEN_REVISION) != 0)
+       {
+         *cp++ = '_';
+         cp = stpcpy (cp, revision);
+       }
+    }
+
+  *cp++ = '/';
+  stpcpy (cp, filename);
+
+  /* Look in list of already loaded domains whether it is already
+     available.  */
+  lastp = l10nfile_list;
+  for (retval = *l10nfile_list; retval != NULL; retval = retval->next)
+    if (retval->filename != NULL)
+      {
+       int compare = strcmp (retval->filename, abs_filename);
+       if (compare == 0)
+         /* We found it!  */
+         break;
+       if (compare < 0)
+         {
+           /* It's not in the list.  */
+           retval = NULL;
+           break;
+         }
+
+       lastp = &retval->next;
+      }
+
+  if (retval != NULL || do_allocate == 0)
+    {
+      free (abs_filename);
+      return retval;
+    }
+
+  dirlist_count = (dirlist_len > 0 ? __argz_count (dirlist, dirlist_len) : 1);
+
+  /* Allocate a new loaded_l10nfile.  */
+  retval =
+    (struct loaded_l10nfile *)
+    malloc (sizeof (*retval)
+           + (((dirlist_count << pop (mask)) + (dirlist_count > 1 ? 1 : 0))
+              * sizeof (struct loaded_l10nfile *)));
+  if (retval == NULL)
+    return NULL;
+
+  retval->filename = abs_filename;
+
+  /* We set retval->data to NULL here; it is filled in later.
+     Setting retval->decided to 1 here means that retval does not
+     correspond to a real file (dirlist_count > 1) or is not worth
+     looking up (if an unnormalized codeset was specified).  */
+  retval->decided = (dirlist_count > 1
+                    || ((mask & XPG_CODESET) != 0
+                        && (mask & XPG_NORM_CODESET) != 0));
+  retval->data = NULL;
+
+  retval->next = *lastp;
+  *lastp = retval;
+
+  entries = 0;
+  /* Recurse to fill the inheritance list of RETVAL.
+     If the DIRLIST is a real list (i.e. DIRLIST_COUNT > 1), the RETVAL
+     entry does not correspond to a real file; retval->filename contains
+     colons.  In this case we loop across all elements of DIRLIST and
+     across all bit patterns dominated by MASK.
+     If the DIRLIST is a single directory or entirely redundant (i.e.
+     DIRLIST_COUNT == 1), we loop across all bit patterns dominated by
+     MASK, excluding MASK itself.
+     In either case, we loop down from MASK to 0.  This has the effect
+     that the extra bits in the locale name are dropped in this order:
+     first the modifier, then the territory, then the codeset, then the
+     normalized_codeset.  */
+  for (cnt = dirlist_count > 1 ? mask : mask - 1; cnt >= 0; --cnt)
+    if ((cnt & ~mask) == 0
+       && ((cnt & CEN_SPECIFIC) == 0 || (cnt & XPG_SPECIFIC) == 0)
+       && ((cnt & XPG_CODESET) == 0 || (cnt & XPG_NORM_CODESET) == 0))
+      {
+       if (dirlist_count > 1)
+         {
+           /* Iterate over all elements of the DIRLIST.  */
+           char *dir = NULL;
+
+           while ((dir = __argz_next ((char *) dirlist, dirlist_len, dir))
+                  != NULL)
+             retval->successor[entries++]
+               = _nl_make_l10nflist (l10nfile_list, dir, strlen (dir) + 1,
+                                     cnt, language, territory, codeset,
+                                     normalized_codeset, modifier, special,
+                                     sponsor, revision, filename, 1);
+         }
+       else
+         retval->successor[entries++]
+           = _nl_make_l10nflist (l10nfile_list, dirlist, dirlist_len,
+                                 cnt, language, territory, codeset,
+                                 normalized_codeset, modifier, special,
+                                 sponsor, revision, filename, 1);
+      }
+  retval->successor[entries] = NULL;
+
+  return retval;
+}
+\f
+/* Normalize codeset name.  There is no standard for the codeset
+   names.  Normalization allows the user to use any of the common
+   names.  The return value is dynamically allocated and has to be
+   freed by the caller.  */
+const char *
+_nl_normalize_codeset (const char *codeset, size_t name_len)
+{
+  int len = 0;
+  int only_digit = 1;
+  char *retval;
+  char *wp;
+  size_t cnt;
+
+  for (cnt = 0; cnt < name_len; ++cnt)
+    if (isalnum ((unsigned char) codeset[cnt]))
+      {
+       ++len;
+
+       if (isalpha ((unsigned char) codeset[cnt]))
+         only_digit = 0;
+      }
+
+  retval = (char *) malloc ((only_digit ? 3 : 0) + len + 1);
+
+  if (retval != NULL)
+    {
+      if (only_digit)
+       wp = stpcpy (retval, "iso");
+      else
+       wp = retval;
+
+      for (cnt = 0; cnt < name_len; ++cnt)
+       if (isalpha ((unsigned char) codeset[cnt]))
+         *wp++ = tolower ((unsigned char) codeset[cnt]);
+       else if (isdigit ((unsigned char) codeset[cnt]))
+         *wp++ = codeset[cnt];
+
+      *wp = '\0';
+    }
+
+  return (const char *) retval;
+}
+
+
+/* @@ begin of epilog @@ */
+
+/* We don't want libintl.a to depend on any other library.  So we
+   avoid the non-standard function stpcpy.  In GNU C Library this
+   function is available, though.  Also allow the symbol HAVE_STPCPY
+   to be defined.  */
+#if !_LIBC && !HAVE_STPCPY
+static char *
+stpcpy (char *dest, const char *src)
+{
+  while ((*dest++ = *src++) != '\0')
+    /* Do nothing. */ ;
+  return dest - 1;
+}
+#endif
diff --git a/intl/langprefs.c b/intl/langprefs.c
new file mode 100644 (file)
index 0000000..416398d
--- /dev/null
@@ -0,0 +1,130 @@
+/* Determine the user's language preferences.
+   Copyright (C) 2004-2005 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+
+#if HAVE_CFPREFERENCESCOPYAPPVALUE
+# include <string.h>
+# include <CFPreferences.h>
+# include <CFPropertyList.h>
+# include <CFArray.h>
+# include <CFString.h>
+extern void _nl_locale_name_canonicalize (char *name);
+#endif
+
+/* Determine the user's language preferences, as a colon separated list of
+   locale names in XPG syntax
+     language[_territory[.codeset]][@modifier]
+   The result must not be freed; it is statically allocated.
+   The LANGUAGE environment variable does not need to be considered; it is
+   already taken into account by the caller.  */
+
+const char *
+_nl_language_preferences_default (void)
+{
+#if HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */
+  {
+    /* Cache the preferences list, since CoreFoundation calls are expensive.  */
+    static const char *cached_languages;
+    static int cache_initialized;
+
+    if (!cache_initialized)
+      {
+       CFTypeRef preferences =
+         CFPreferencesCopyAppValue (CFSTR ("AppleLanguages"),
+                                    kCFPreferencesCurrentApplication);
+       if (preferences != NULL
+           && CFGetTypeID (preferences) == CFArrayGetTypeID ())
+         {
+           CFArrayRef prefArray = (CFArrayRef)preferences;
+           int n = CFArrayGetCount (prefArray);
+           char buf[256];
+           size_t size = 0;
+           int i;
+
+           for (i = 0; i < n; i++)
+             {
+               CFTypeRef element = CFArrayGetValueAtIndex (prefArray, i);
+               if (element != NULL
+                   && CFGetTypeID (element) == CFStringGetTypeID ()
+                   && CFStringGetCString ((CFStringRef)element,
+                                          buf, sizeof (buf),
+                                          kCFStringEncodingASCII))
+                 {
+                   _nl_locale_name_canonicalize (buf);
+                   size += strlen (buf) + 1;
+                   /* Most GNU programs use msgids in English and don't ship
+                      an en.mo message catalog.  Therefore when we see "en"
+                      in the preferences list, arrange for gettext() to
+                      return the msgid, and ignore all further elements of
+                      the preferences list.  */
+                   if (strcmp (buf, "en") == 0)
+                     break;
+                 }
+               else
+                 break;
+             }
+           if (size > 0)
+             {
+               char *languages = (char *) malloc (size);
+
+               if (languages != NULL)
+                 {
+                   char *p = languages;
+
+                   for (i = 0; i < n; i++)
+                     {
+                       CFTypeRef element =
+                         CFArrayGetValueAtIndex (prefArray, i);
+                       if (element != NULL
+                           && CFGetTypeID (element) == CFStringGetTypeID ()
+                           && CFStringGetCString ((CFStringRef)element,
+                                                  buf, sizeof (buf),
+                                                  kCFStringEncodingASCII))
+                         {
+                           _nl_locale_name_canonicalize (buf);
+                           strcpy (p, buf);
+                           p += strlen (buf);
+                           *p++ = ':';
+                           if (strcmp (buf, "en") == 0)
+                             break;
+                         }
+                       else
+                         break;
+                     }
+                   *--p = '\0';
+
+                   cached_languages = languages;
+                 }
+             }
+         }
+       cache_initialized = 1;
+      }
+    if (cached_languages != NULL)
+      return cached_languages;
+  }
+#endif
+
+  return NULL;
+}
diff --git a/intl/libgnuintl.h.in b/intl/libgnuintl.h.in
new file mode 100644 (file)
index 0000000..afc21da
--- /dev/null
@@ -0,0 +1,383 @@
+/* Message catalogs for internationalization.
+   Copyright (C) 1995-1997, 2000-2004 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifndef _LIBINTL_H
+#define _LIBINTL_H     1
+
+#include <locale.h>
+
+/* The LC_MESSAGES locale category is the category used by the functions
+   gettext() and dgettext().  It is specified in POSIX, but not in ANSI C.
+   On systems that don't define it, use an arbitrary value instead.
+   On Solaris, <locale.h> defines __LOCALE_H (or _LOCALE_H in Solaris 2.5)
+   then includes <libintl.h> (i.e. this file!) and then only defines
+   LC_MESSAGES.  To avoid a redefinition warning, don't define LC_MESSAGES
+   in this case.  */
+#if !defined LC_MESSAGES && !(defined __LOCALE_H || (defined _LOCALE_H && defined __sun))
+# define LC_MESSAGES 1729
+#endif
+
+/* We define an additional symbol to signal that we use the GNU
+   implementation of gettext.  */
+#define __USE_GNU_GETTEXT 1
+
+/* Provide information about the supported file formats.  Returns the
+   maximum minor revision number supported for a given major revision.  */
+#define __GNU_GETTEXT_SUPPORTED_REVISION(major) \
+  ((major) == 0 || (major) == 1 ? 1 : -1)
+
+/* Resolve a platform specific conflict on DJGPP.  GNU gettext takes
+   precedence over _conio_gettext.  */
+#ifdef __DJGPP__
+# undef gettext
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* We redirect the functions to those prefixed with "libintl_".  This is
+   necessary, because some systems define gettext/textdomain/... in the C
+   library (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer).
+   If we used the unprefixed names, there would be cases where the
+   definition in the C library would override the one in the libintl.so
+   shared library.  Recall that on ELF systems, the symbols are looked
+   up in the following order:
+     1. in the executable,
+     2. in the shared libraries specified on the link command line, in order,
+     3. in the dependencies of the shared libraries specified on the link
+        command line,
+     4. in the dlopen()ed shared libraries, in the order in which they were
+        dlopen()ed.
+   The definition in the C library would override the one in libintl.so if
+   either
+     * -lc is given on the link command line and -lintl isn't, or
+     * -lc is given on the link command line before -lintl, or
+     * libintl.so is a dependency of a dlopen()ed shared library but not
+       linked to the executable at link time.
+   Since Solaris gettext() behaves differently than GNU gettext(), this
+   would be unacceptable.
+
+   The redirection happens by default through macros in C, so that &gettext
+   is independent of the compilation unit, but through inline functions in
+   C++, in order not to interfere with the name mangling of class fields or
+   class methods called 'gettext'.  */
+
+/* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS.
+   If he doesn't, we choose the method.  A third possible method is
+   _INTL_REDIRECT_ASM, supported only by GCC.  */
+#if !(defined _INTL_REDIRECT_INLINE || defined _INTL_REDIRECT_MACROS)
+# if __GNUC__ >= 2 && !defined __APPLE_CC__ && !defined __MINGW32__ && !(__GNUC__ == 2 && defined _AIX) && (defined __STDC__ || defined __cplusplus)
+#  define _INTL_REDIRECT_ASM
+# else
+#  ifdef __cplusplus
+#   define _INTL_REDIRECT_INLINE
+#  else
+#   define _INTL_REDIRECT_MACROS
+#  endif
+# endif
+#endif
+/* Auxiliary macros.  */
+#ifdef _INTL_REDIRECT_ASM
+# define _INTL_ASM(cname) __asm__ (_INTL_ASMNAME (__USER_LABEL_PREFIX__, #cname))
+# define _INTL_ASMNAME(prefix,cnamestring) _INTL_STRINGIFY (prefix) cnamestring
+# define _INTL_STRINGIFY(prefix) #prefix
+#else
+# define _INTL_ASM(cname)
+#endif
+
+/* Look up MSGID in the current default message catalog for the current
+   LC_MESSAGES locale.  If not found, returns MSGID itself (the default
+   text).  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_gettext (const char *__msgid);
+static inline char *gettext (const char *__msgid)
+{
+  return libintl_gettext (__msgid);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define gettext libintl_gettext
+#endif
+extern char *gettext (const char *__msgid)
+       _INTL_ASM (libintl_gettext);
+#endif
+
+/* Look up MSGID in the DOMAINNAME message catalog for the current
+   LC_MESSAGES locale.  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_dgettext (const char *__domainname, const char *__msgid);
+static inline char *dgettext (const char *__domainname, const char *__msgid)
+{
+  return libintl_dgettext (__domainname, __msgid);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define dgettext libintl_dgettext
+#endif
+extern char *dgettext (const char *__domainname, const char *__msgid)
+       _INTL_ASM (libintl_dgettext);
+#endif
+
+/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
+   locale.  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_dcgettext (const char *__domainname, const char *__msgid,
+                               int __category);
+static inline char *dcgettext (const char *__domainname, const char *__msgid,
+                              int __category)
+{
+  return libintl_dcgettext (__domainname, __msgid, __category);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define dcgettext libintl_dcgettext
+#endif
+extern char *dcgettext (const char *__domainname, const char *__msgid,
+                       int __category)
+       _INTL_ASM (libintl_dcgettext);
+#endif
+
+
+/* Similar to `gettext' but select the plural form corresponding to the
+   number N.  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2,
+                              unsigned long int __n);
+static inline char *ngettext (const char *__msgid1, const char *__msgid2,
+                             unsigned long int __n)
+{
+  return libintl_ngettext (__msgid1, __msgid2, __n);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define ngettext libintl_ngettext
+#endif
+extern char *ngettext (const char *__msgid1, const char *__msgid2,
+                      unsigned long int __n)
+       _INTL_ASM (libintl_ngettext);
+#endif
+
+/* Similar to `dgettext' but select the plural form corresponding to the
+   number N.  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_dngettext (const char *__domainname, const char *__msgid1,
+                               const char *__msgid2, unsigned long int __n);
+static inline char *dngettext (const char *__domainname, const char *__msgid1,
+                              const char *__msgid2, unsigned long int __n)
+{
+  return libintl_dngettext (__domainname, __msgid1, __msgid2, __n);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define dngettext libintl_dngettext
+#endif
+extern char *dngettext (const char *__domainname,
+                       const char *__msgid1, const char *__msgid2,
+                       unsigned long int __n)
+       _INTL_ASM (libintl_dngettext);
+#endif
+
+/* Similar to `dcgettext' but select the plural form corresponding to the
+   number N.  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_dcngettext (const char *__domainname,
+                                const char *__msgid1, const char *__msgid2,
+                                unsigned long int __n, int __category);
+static inline char *dcngettext (const char *__domainname,
+                               const char *__msgid1, const char *__msgid2,
+                               unsigned long int __n, int __category)
+{
+  return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define dcngettext libintl_dcngettext
+#endif
+extern char *dcngettext (const char *__domainname,
+                        const char *__msgid1, const char *__msgid2,
+                        unsigned long int __n, int __category)
+       _INTL_ASM (libintl_dcngettext);
+#endif
+
+
+/* Set the current default message catalog to DOMAINNAME.
+   If DOMAINNAME is null, return the current default.
+   If DOMAINNAME is "", reset to the default of "messages".  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_textdomain (const char *__domainname);
+static inline char *textdomain (const char *__domainname)
+{
+  return libintl_textdomain (__domainname);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define textdomain libintl_textdomain
+#endif
+extern char *textdomain (const char *__domainname)
+       _INTL_ASM (libintl_textdomain);
+#endif
+
+/* Specify that the DOMAINNAME message catalog will be found
+   in DIRNAME rather than in the system locale data base.  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_bindtextdomain (const char *__domainname,
+                                    const char *__dirname);
+static inline char *bindtextdomain (const char *__domainname,
+                                   const char *__dirname)
+{
+  return libintl_bindtextdomain (__domainname, __dirname);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define bindtextdomain libintl_bindtextdomain
+#endif
+extern char *bindtextdomain (const char *__domainname, const char *__dirname)
+       _INTL_ASM (libintl_bindtextdomain);
+#endif
+
+/* Specify the character encoding in which the messages from the
+   DOMAINNAME message catalog will be returned.  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_bind_textdomain_codeset (const char *__domainname,
+                                             const char *__codeset);
+static inline char *bind_textdomain_codeset (const char *__domainname,
+                                            const char *__codeset)
+{
+  return libintl_bind_textdomain_codeset (__domainname, __codeset);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define bind_textdomain_codeset libintl_bind_textdomain_codeset
+#endif
+extern char *bind_textdomain_codeset (const char *__domainname,
+                                     const char *__codeset)
+       _INTL_ASM (libintl_bind_textdomain_codeset);
+#endif
+
+
+/* Support for format strings with positions in *printf(), following the
+   POSIX/XSI specification.
+   Note: These replacements for the *printf() functions are visible only
+   in source files that #include <libintl.h> or #include "gettext.h".
+   Packages that use *printf() in source files that don't refer to _()
+   or gettext() but for which the format string could be the return value
+   of _() or gettext() need to add this #include.  Oh well.  */
+
+#if !@HAVE_POSIX_PRINTF@
+
+#include <stdio.h>
+#include <stddef.h>
+
+/* Get va_list.  */
+#if __STDC__ || defined __cplusplus || defined _MSC_VER
+# include <stdarg.h>
+#else
+# include <varargs.h>
+#endif
+
+#undef fprintf
+#define fprintf libintl_fprintf
+extern int fprintf (FILE *, const char *, ...);
+#undef vfprintf
+#define vfprintf libintl_vfprintf
+extern int vfprintf (FILE *, const char *, va_list);
+
+#undef printf
+#define printf libintl_printf
+extern int printf (const char *, ...);
+#undef vprintf
+#define vprintf libintl_vprintf
+extern int vprintf (const char *, va_list);
+
+#undef sprintf
+#define sprintf libintl_sprintf
+extern int sprintf (char *, const char *, ...);
+#undef vsprintf
+#define vsprintf libintl_vsprintf
+extern int vsprintf (char *, const char *, va_list);
+
+#if @HAVE_SNPRINTF@
+
+#undef snprintf
+#define snprintf libintl_snprintf
+extern int snprintf (char *, size_t, const char *, ...);
+#undef vsnprintf
+#define vsnprintf libintl_vsnprintf
+extern int vsnprintf (char *, size_t, const char *, va_list);
+
+#endif
+
+#if @HAVE_ASPRINTF@
+
+#undef asprintf
+#define asprintf libintl_asprintf
+extern int asprintf (char **, const char *, ...);
+#undef vasprintf
+#define vasprintf libintl_vasprintf
+extern int vasprintf (char **, const char *, va_list);
+
+#endif
+
+#if @HAVE_WPRINTF@
+
+#undef fwprintf
+#define fwprintf libintl_fwprintf
+extern int fwprintf (FILE *, const wchar_t *, ...);
+#undef vfwprintf
+#define vfwprintf libintl_vfwprintf
+extern int vfwprintf (FILE *, const wchar_t *, va_list);
+
+#undef wprintf
+#define wprintf libintl_wprintf
+extern int wprintf (const wchar_t *, ...);
+#undef vwprintf
+#define vwprintf libintl_vwprintf
+extern int vwprintf (const wchar_t *, va_list);
+
+#undef swprintf
+#define swprintf libintl_swprintf
+extern int swprintf (wchar_t *, size_t, const wchar_t *, ...);
+#undef vswprintf
+#define vswprintf libintl_vswprintf
+extern int vswprintf (wchar_t *, size_t, const wchar_t *, va_list);
+
+#endif
+
+#endif
+
+
+/* Support for relocatable packages.  */
+
+/* Sets the original and the current installation prefix of the package.
+   Relocation simply replaces a pathname starting with the original prefix
+   by the corresponding pathname with the current prefix instead.  Both
+   prefixes should be directory names without trailing slash (i.e. use ""
+   instead of "/").  */
+#define libintl_set_relocation_prefix libintl_set_relocation_prefix
+extern void
+       libintl_set_relocation_prefix (const char *orig_prefix,
+                                     const char *curr_prefix);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* libintl.h */
diff --git a/intl/loadinfo.h b/intl/loadinfo.h
new file mode 100644 (file)
index 0000000..65e5ebd
--- /dev/null
@@ -0,0 +1,145 @@
+/* Copyright (C) 1996-1999, 2000-2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifndef _LOADINFO_H
+#define _LOADINFO_H    1
+
+/* Declarations of locale dependent catalog lookup functions.
+   Implemented in
+
+     localealias.c    Possibly replace a locale name by another.
+     explodename.c    Split a locale name into its various fields.
+     l10nflist.c      Generate a list of filenames of possible message catalogs.
+     finddomain.c     Find and open the relevant message catalogs.
+
+   The main function _nl_find_domain() in finddomain.c is declared
+   in gettextP.h.
+ */
+
+#ifndef internal_function
+# define internal_function
+#endif
+
+/* Tell the compiler when a conditional or integer expression is
+   almost always true or almost always false.  */
+#ifndef HAVE_BUILTIN_EXPECT
+# define __builtin_expect(expr, val) (expr)
+#endif
+
+/* Separator in PATH like lists of pathnames.  */
+#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
+  /* Win32, OS/2, DOS */
+# define PATH_SEPARATOR ';'
+#else
+  /* Unix */
+# define PATH_SEPARATOR ':'
+#endif
+
+/* Encoding of locale name parts.  */
+#define CEN_REVISION           1
+#define CEN_SPONSOR            2
+#define CEN_SPECIAL            4
+#define XPG_NORM_CODESET       8
+#define XPG_CODESET            16
+#define TERRITORY              32
+#define CEN_AUDIENCE           64
+#define XPG_MODIFIER           128
+
+#define CEN_SPECIFIC   (CEN_REVISION|CEN_SPONSOR|CEN_SPECIAL|CEN_AUDIENCE)
+#define XPG_SPECIFIC   (XPG_CODESET|XPG_NORM_CODESET|XPG_MODIFIER)
+
+
+struct loaded_l10nfile
+{
+  const char *filename;
+  int decided;
+
+  const void *data;
+
+  struct loaded_l10nfile *next;
+  struct loaded_l10nfile *successor[1];
+};
+
+
+/* Normalize codeset name.  There is no standard for the codeset
+   names.  Normalization allows the user to use any of the common
+   names.  The return value is dynamically allocated and has to be
+   freed by the caller.  */
+extern const char *_nl_normalize_codeset (const char *codeset,
+                                         size_t name_len);
+
+/* Lookup a locale dependent file.
+   *L10NFILE_LIST denotes a pool of lookup results of locale dependent
+   files of the same kind, sorted in decreasing order of ->filename.
+   DIRLIST and DIRLIST_LEN are an argz list of directories in which to
+   look, containing at least one directory (i.e. DIRLIST_LEN > 0).
+   MASK, LANGUAGE, TERRITORY, CODESET, NORMALIZED_CODESET, MODIFIER,
+   SPECIAL, SPONSOR, REVISION are the pieces of the locale name, as
+   produced by _nl_explode_name().  FILENAME is the filename suffix.
+   The return value is the lookup result, either found in *L10NFILE_LIST,
+   or - if DO_ALLOCATE is nonzero - freshly allocated, or possibly NULL.
+   If the return value is non-NULL, it is added to *L10NFILE_LIST, and
+   its ->next field denotes the chaining inside *L10NFILE_LIST, and
+   furthermore its ->successor[] field contains a list of other lookup
+   results from which this lookup result inherits.  */
+extern struct loaded_l10nfile *
+_nl_make_l10nflist (struct loaded_l10nfile **l10nfile_list,
+                   const char *dirlist, size_t dirlist_len, int mask,
+                   const char *language, const char *territory,
+                   const char *codeset, const char *normalized_codeset,
+                   const char *modifier, const char *special,
+                   const char *sponsor, const char *revision,
+                   const char *filename, int do_allocate);
+
+/* Lookup the real locale name for a locale alias NAME, or NULL if
+   NAME is not a locale alias (but possibly a real locale name).
+   The return value is statically allocated and must not be freed.  */
+extern const char *_nl_expand_alias (const char *name);
+
+/* Split a locale name NAME into its pieces: language, modifier,
+   territory, codeset, special, sponsor, revision.
+   NAME gets destructively modified: NUL bytes are inserted here and
+   there.  *LANGUAGE gets assigned NAME.  Each of *MODIFIER, *TERRITORY,
+   *CODESET, *SPECIAL, *SPONSOR, *REVISION gets assigned either a
+   pointer into the old NAME string, or NULL.  *NORMALIZED_CODESET
+   gets assigned the expanded *CODESET, if it is different from *CODESET;
+   this one is dynamically allocated and has to be freed by the caller.
+   The return value is a bitmask, where each bit corresponds to one
+   filled-in value:
+     XPG_MODIFIER, CEN_AUDIENCE  for *MODIFIER,
+     TERRITORY                   for *TERRITORY,
+     XPG_CODESET                 for *CODESET,
+     XPG_NORM_CODESET            for *NORMALIZED_CODESET,
+     CEN_SPECIAL                 for *SPECIAL,
+     CEN_SPONSOR                 for *SPONSOR,
+     CEN_REVISION                for *REVISION.
+ */
+extern int _nl_explode_name (char *name, const char **language,
+                            const char **modifier, const char **territory,
+                            const char **codeset,
+                            const char **normalized_codeset,
+                            const char **special, const char **sponsor,
+                            const char **revision);
+
+/* Split a locale name NAME into a leading language part and all the
+   rest.  Return a pointer to the first character after the language,
+   i.e. to the first byte of the rest.  */
+extern char *_nl_find_language (const char *name);
+
+#endif /* loadinfo.h */
diff --git a/intl/loadmsgcat.c b/intl/loadmsgcat.c
new file mode 100644 (file)
index 0000000..99c51b4
--- /dev/null
@@ -0,0 +1,1420 @@
+/* Load needed message catalogs.
+   Copyright (C) 1995-1999, 2000-2004 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+/* Tell glibc's <string.h> to provide a prototype for mempcpy().
+   This must come before <config.h> because <config.h> may include
+   <features.h>, and once <features.h> has been included, it's too late.  */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE    1
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#ifdef __GNUC__
+# undef  alloca
+# define alloca __builtin_alloca
+# define HAVE_ALLOCA 1
+#else
+# ifdef _MSC_VER
+#  include <malloc.h>
+#  define alloca _alloca
+# else
+#  if defined HAVE_ALLOCA_H || defined _LIBC
+#   include <alloca.h>
+#  else
+#   ifdef _AIX
+ #pragma alloca
+#   else
+#    ifndef alloca
+char *alloca ();
+#    endif
+#   endif
+#  endif
+# endif
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#if defined HAVE_UNISTD_H || defined _LIBC
+# include <unistd.h>
+#endif
+
+#ifdef _LIBC
+# include <langinfo.h>
+# include <locale.h>
+#endif
+
+#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
+    || (defined _LIBC && defined _POSIX_MAPPED_FILES)
+# include <sys/mman.h>
+# undef HAVE_MMAP
+# define HAVE_MMAP     1
+#else
+# undef HAVE_MMAP
+#endif
+
+#if defined HAVE_STDINT_H_WITH_UINTMAX || defined _LIBC
+# include <stdint.h>
+#endif
+#if defined HAVE_INTTYPES_H || defined _LIBC
+# include <inttypes.h>
+#endif
+
+#include "gmo.h"
+#include "gettextP.h"
+#include "hash-string.h"
+#include "plural-exp.h"
+
+#ifdef _LIBC
+# include "../locale/localeinfo.h"
+#endif
+
+/* Provide fallback values for macros that ought to be defined in <inttypes.h>.
+   Note that our fallback values need not be literal strings, because we don't
+   use them with preprocessor string concatenation.  */
+#if !defined PRId8 || PRI_MACROS_BROKEN
+# undef PRId8
+# define PRId8 "d"
+#endif
+#if !defined PRIi8 || PRI_MACROS_BROKEN
+# undef PRIi8
+# define PRIi8 "i"
+#endif
+#if !defined PRIo8 || PRI_MACROS_BROKEN
+# undef PRIo8
+# define PRIo8 "o"
+#endif
+#if !defined PRIu8 || PRI_MACROS_BROKEN
+# undef PRIu8
+# define PRIu8 "u"
+#endif
+#if !defined PRIx8 || PRI_MACROS_BROKEN
+# undef PRIx8
+# define PRIx8 "x"
+#endif
+#if !defined PRIX8 || PRI_MACROS_BROKEN
+# undef PRIX8
+# define PRIX8 "X"
+#endif
+#if !defined PRId16 || PRI_MACROS_BROKEN
+# undef PRId16
+# define PRId16 "d"
+#endif
+#if !defined PRIi16 || PRI_MACROS_BROKEN
+# undef PRIi16
+# define PRIi16 "i"
+#endif
+#if !defined PRIo16 || PRI_MACROS_BROKEN
+# undef PRIo16
+# define PRIo16 "o"
+#endif
+#if !defined PRIu16 || PRI_MACROS_BROKEN
+# undef PRIu16
+# define PRIu16 "u"
+#endif
+#if !defined PRIx16 || PRI_MACROS_BROKEN
+# undef PRIx16
+# define PRIx16 "x"
+#endif
+#if !defined PRIX16 || PRI_MACROS_BROKEN
+# undef PRIX16
+# define PRIX16 "X"
+#endif
+#if !defined PRId32 || PRI_MACROS_BROKEN
+# undef PRId32
+# define PRId32 "d"
+#endif
+#if !defined PRIi32 || PRI_MACROS_BROKEN
+# undef PRIi32
+# define PRIi32 "i"
+#endif
+#if !defined PRIo32 || PRI_MACROS_BROKEN
+# undef PRIo32
+# define PRIo32 "o"
+#endif
+#if !defined PRIu32 || PRI_MACROS_BROKEN
+# undef PRIu32
+# define PRIu32 "u"
+#endif
+#if !defined PRIx32 || PRI_MACROS_BROKEN
+# undef PRIx32
+# define PRIx32 "x"
+#endif
+#if !defined PRIX32 || PRI_MACROS_BROKEN
+# undef PRIX32
+# define PRIX32 "X"
+#endif
+#if !defined PRId64 || PRI_MACROS_BROKEN
+# undef PRId64
+# define PRId64 (sizeof (long) == 8 ? "ld" : "lld")
+#endif
+#if !defined PRIi64 || PRI_MACROS_BROKEN
+# undef PRIi64
+# define PRIi64 (sizeof (long) == 8 ? "li" : "lli")
+#endif
+#if !defined PRIo64 || PRI_MACROS_BROKEN
+# undef PRIo64
+# define PRIo64 (sizeof (long) == 8 ? "lo" : "llo")
+#endif
+#if !defined PRIu64 || PRI_MACROS_BROKEN
+# undef PRIu64
+# define PRIu64 (sizeof (long) == 8 ? "lu" : "llu")
+#endif
+#if !defined PRIx64 || PRI_MACROS_BROKEN
+# undef PRIx64
+# define PRIx64 (sizeof (long) == 8 ? "lx" : "llx")
+#endif
+#if !defined PRIX64 || PRI_MACROS_BROKEN
+# undef PRIX64
+# define PRIX64 (sizeof (long) == 8 ? "lX" : "llX")
+#endif
+#if !defined PRIdLEAST8 || PRI_MACROS_BROKEN
+# undef PRIdLEAST8
+# define PRIdLEAST8 "d"
+#endif
+#if !defined PRIiLEAST8 || PRI_MACROS_BROKEN
+# undef PRIiLEAST8
+# define PRIiLEAST8 "i"
+#endif
+#if !defined PRIoLEAST8 || PRI_MACROS_BROKEN
+# undef PRIoLEAST8
+# define PRIoLEAST8 "o"
+#endif
+#if !defined PRIuLEAST8 || PRI_MACROS_BROKEN
+# undef PRIuLEAST8
+# define PRIuLEAST8 "u"
+#endif
+#if !defined PRIxLEAST8 || PRI_MACROS_BROKEN
+# undef PRIxLEAST8
+# define PRIxLEAST8 "x"
+#endif
+#if !defined PRIXLEAST8 || PRI_MACROS_BROKEN
+# undef PRIXLEAST8
+# define PRIXLEAST8 "X"
+#endif
+#if !defined PRIdLEAST16 || PRI_MACROS_BROKEN
+# undef PRIdLEAST16
+# define PRIdLEAST16 "d"
+#endif
+#if !defined PRIiLEAST16 || PRI_MACROS_BROKEN
+# undef PRIiLEAST16
+# define PRIiLEAST16 "i"
+#endif
+#if !defined PRIoLEAST16 || PRI_MACROS_BROKEN
+# undef PRIoLEAST16
+# define PRIoLEAST16 "o"
+#endif
+#if !defined PRIuLEAST16 || PRI_MACROS_BROKEN
+# undef PRIuLEAST16
+# define PRIuLEAST16 "u"
+#endif
+#if !defined PRIxLEAST16 || PRI_MACROS_BROKEN
+# undef PRIxLEAST16
+# define PRIxLEAST16 "x"
+#endif
+#if !defined PRIXLEAST16 || PRI_MACROS_BROKEN
+# undef PRIXLEAST16
+# define PRIXLEAST16 "X"
+#endif
+#if !defined PRIdLEAST32 || PRI_MACROS_BROKEN
+# undef PRIdLEAST32
+# define PRIdLEAST32 "d"
+#endif
+#if !defined PRIiLEAST32 || PRI_MACROS_BROKEN
+# undef PRIiLEAST32
+# define PRIiLEAST32 "i"
+#endif
+#if !defined PRIoLEAST32 || PRI_MACROS_BROKEN
+# undef PRIoLEAST32
+# define PRIoLEAST32 "o"
+#endif
+#if !defined PRIuLEAST32 || PRI_MACROS_BROKEN
+# undef PRIuLEAST32
+# define PRIuLEAST32 "u"
+#endif
+#if !defined PRIxLEAST32 || PRI_MACROS_BROKEN
+# undef PRIxLEAST32
+# define PRIxLEAST32 "x"
+#endif
+#if !defined PRIXLEAST32 || PRI_MACROS_BROKEN
+# undef PRIXLEAST32
+# define PRIXLEAST32 "X"
+#endif
+#if !defined PRIdLEAST64 || PRI_MACROS_BROKEN
+# undef PRIdLEAST64
+# define PRIdLEAST64 PRId64
+#endif
+#if !defined PRIiLEAST64 || PRI_MACROS_BROKEN
+# undef PRIiLEAST64
+# define PRIiLEAST64 PRIi64
+#endif
+#if !defined PRIoLEAST64 || PRI_MACROS_BROKEN
+# undef PRIoLEAST64
+# define PRIoLEAST64 PRIo64
+#endif
+#if !defined PRIuLEAST64 || PRI_MACROS_BROKEN
+# undef PRIuLEAST64
+# define PRIuLEAST64 PRIu64
+#endif
+#if !defined PRIxLEAST64 || PRI_MACROS_BROKEN
+# undef PRIxLEAST64
+# define PRIxLEAST64 PRIx64
+#endif
+#if !defined PRIXLEAST64 || PRI_MACROS_BROKEN
+# undef PRIXLEAST64
+# define PRIXLEAST64 PRIX64
+#endif
+#if !defined PRIdFAST8 || PRI_MACROS_BROKEN
+# undef PRIdFAST8
+# define PRIdFAST8 "d"
+#endif
+#if !defined PRIiFAST8 || PRI_MACROS_BROKEN
+# undef PRIiFAST8
+# define PRIiFAST8 "i"
+#endif
+#if !defined PRIoFAST8 || PRI_MACROS_BROKEN
+# undef PRIoFAST8
+# define PRIoFAST8 "o"
+#endif
+#if !defined PRIuFAST8 || PRI_MACROS_BROKEN
+# undef PRIuFAST8
+# define PRIuFAST8 "u"
+#endif
+#if !defined PRIxFAST8 || PRI_MACROS_BROKEN
+# undef PRIxFAST8
+# define PRIxFAST8 "x"
+#endif
+#if !defined PRIXFAST8 || PRI_MACROS_BROKEN
+# undef PRIXFAST8
+# define PRIXFAST8 "X"
+#endif
+#if !defined PRIdFAST16 || PRI_MACROS_BROKEN
+# undef PRIdFAST16
+# define PRIdFAST16 "d"
+#endif
+#if !defined PRIiFAST16 || PRI_MACROS_BROKEN
+# undef PRIiFAST16
+# define PRIiFAST16 "i"
+#endif
+#if !defined PRIoFAST16 || PRI_MACROS_BROKEN
+# undef PRIoFAST16
+# define PRIoFAST16 "o"
+#endif
+#if !defined PRIuFAST16 || PRI_MACROS_BROKEN
+# undef PRIuFAST16
+# define PRIuFAST16 "u"
+#endif
+#if !defined PRIxFAST16 || PRI_MACROS_BROKEN
+# undef PRIxFAST16
+# define PRIxFAST16 "x"
+#endif
+#if !defined PRIXFAST16 || PRI_MACROS_BROKEN
+# undef PRIXFAST16
+# define PRIXFAST16 "X"
+#endif
+#if !defined PRIdFAST32 || PRI_MACROS_BROKEN
+# undef PRIdFAST32
+# define PRIdFAST32 "d"
+#endif
+#if !defined PRIiFAST32 || PRI_MACROS_BROKEN
+# undef PRIiFAST32
+# define PRIiFAST32 "i"
+#endif
+#if !defined PRIoFAST32 || PRI_MACROS_BROKEN
+# undef PRIoFAST32
+# define PRIoFAST32 "o"
+#endif
+#if !defined PRIuFAST32 || PRI_MACROS_BROKEN
+# undef PRIuFAST32
+# define PRIuFAST32 "u"
+#endif
+#if !defined PRIxFAST32 || PRI_MACROS_BROKEN
+# undef PRIxFAST32
+# define PRIxFAST32 "x"
+#endif
+#if !defined PRIXFAST32 || PRI_MACROS_BROKEN
+# undef PRIXFAST32
+# define PRIXFAST32 "X"
+#endif
+#if !defined PRIdFAST64 || PRI_MACROS_BROKEN
+# undef PRIdFAST64
+# define PRIdFAST64 PRId64
+#endif
+#if !defined PRIiFAST64 || PRI_MACROS_BROKEN
+# undef PRIiFAST64
+# define PRIiFAST64 PRIi64
+#endif
+#if !defined PRIoFAST64 || PRI_MACROS_BROKEN
+# undef PRIoFAST64
+# define PRIoFAST64 PRIo64
+#endif
+#if !defined PRIuFAST64 || PRI_MACROS_BROKEN
+# undef PRIuFAST64
+# define PRIuFAST64 PRIu64
+#endif
+#if !defined PRIxFAST64 || PRI_MACROS_BROKEN
+# undef PRIxFAST64
+# define PRIxFAST64 PRIx64
+#endif
+#if !defined PRIXFAST64 || PRI_MACROS_BROKEN
+# undef PRIXFAST64
+# define PRIXFAST64 PRIX64
+#endif
+#if !defined PRIdMAX || PRI_MACROS_BROKEN
+# undef PRIdMAX
+# define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld")
+#endif
+#if !defined PRIiMAX || PRI_MACROS_BROKEN
+# undef PRIiMAX
+# define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli")
+#endif
+#if !defined PRIoMAX || PRI_MACROS_BROKEN
+# undef PRIoMAX
+# define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo")
+#endif
+#if !defined PRIuMAX || PRI_MACROS_BROKEN
+# undef PRIuMAX
+# define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu")
+#endif
+#if !defined PRIxMAX || PRI_MACROS_BROKEN
+# undef PRIxMAX
+# define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx")
+#endif
+#if !defined PRIXMAX || PRI_MACROS_BROKEN
+# undef PRIXMAX
+# define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX")
+#endif
+#if !defined PRIdPTR || PRI_MACROS_BROKEN
+# undef PRIdPTR
+# define PRIdPTR \
+  (sizeof (void *) == sizeof (long) ? "ld" : \
+   sizeof (void *) == sizeof (int) ? "d" : \
+   "lld")
+#endif
+#if !defined PRIiPTR || PRI_MACROS_BROKEN
+# undef PRIiPTR
+# define PRIiPTR \
+  (sizeof (void *) == sizeof (long) ? "li" : \
+   sizeof (void *) == sizeof (int) ? "i" : \
+   "lli")
+#endif
+#if !defined PRIoPTR || PRI_MACROS_BROKEN
+# undef PRIoPTR
+# define PRIoPTR \
+  (sizeof (void *) == sizeof (long) ? "lo" : \
+   sizeof (void *) == sizeof (int) ? "o" : \
+   "llo")
+#endif
+#if !defined PRIuPTR || PRI_MACROS_BROKEN
+# undef PRIuPTR
+# define PRIuPTR \
+  (sizeof (void *) == sizeof (long) ? "lu" : \
+   sizeof (void *) == sizeof (int) ? "u" : \
+   "llu")
+#endif
+#if !defined PRIxPTR || PRI_MACROS_BROKEN
+# undef PRIxPTR
+# define PRIxPTR \
+  (sizeof (void *) == sizeof (long) ? "lx" : \
+   sizeof (void *) == sizeof (int) ? "x" : \
+   "llx")
+#endif
+#if !defined PRIXPTR || PRI_MACROS_BROKEN
+# undef PRIXPTR
+# define PRIXPTR \
+  (sizeof (void *) == sizeof (long) ? "lX" : \
+   sizeof (void *) == sizeof (int) ? "X" : \
+   "llX")
+#endif
+
+/* @@ end of prolog @@ */
+
+#ifdef _LIBC
+/* Rename the non ISO C functions.  This is required by the standard
+   because some ISO C functions will require linking with this object
+   file and the name space must not be polluted.  */
+# define open   __open
+# define close  __close
+# define read   __read
+# define mmap   __mmap
+# define munmap __munmap
+#endif
+
+/* For those losing systems which don't have `alloca' we have to add
+   some additional code emulating it.  */
+#ifdef HAVE_ALLOCA
+# define freea(p) /* nothing */
+#else
+# define alloca(n) malloc (n)
+# define freea(p) free (p)
+#endif
+
+/* For systems that distinguish between text and binary I/O.
+   O_BINARY is usually declared in <fcntl.h>. */
+#if !defined O_BINARY && defined _O_BINARY
+  /* For MSC-compatible compilers.  */
+# define O_BINARY _O_BINARY
+# define O_TEXT _O_TEXT
+#endif
+#ifdef __BEOS__
+  /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect.  */
+# undef O_BINARY
+# undef O_TEXT
+#endif
+/* On reasonable systems, binary I/O is the default.  */
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
+
+/* We need a sign, whether a new catalog was loaded, which can be associated
+   with all translations.  This is important if the translations are
+   cached by one of GCC's features.  */
+int _nl_msg_cat_cntr;
+
+
+/* Expand a system dependent string segment.  Return NULL if unsupported.  */
+static const char *
+get_sysdep_segment_value (const char *name)
+{
+  /* Test for an ISO C 99 section 7.8.1 format string directive.
+     Syntax:
+     P R I { d | i | o | u | x | X }
+     { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR }  */
+  /* We don't use a table of 14 times 6 'const char *' strings here, because
+     data relocations cost startup time.  */
+  if (name[0] == 'P' && name[1] == 'R' && name[2] == 'I')
+    {
+      if (name[3] == 'd' || name[3] == 'i' || name[3] == 'o' || name[3] == 'u'
+         || name[3] == 'x' || name[3] == 'X')
+       {
+         if (name[4] == '8' && name[5] == '\0')
+           {
+             if (name[3] == 'd')
+               return PRId8;
+             if (name[3] == 'i')
+               return PRIi8;
+             if (name[3] == 'o')
+               return PRIo8;
+             if (name[3] == 'u')
+               return PRIu8;
+             if (name[3] == 'x')
+               return PRIx8;
+             if (name[3] == 'X')
+               return PRIX8;
+             abort ();
+           }
+         if (name[4] == '1' && name[5] == '6' && name[6] == '\0')
+           {
+             if (name[3] == 'd')
+               return PRId16;
+             if (name[3] == 'i')
+               return PRIi16;
+             if (name[3] == 'o')
+               return PRIo16;
+             if (name[3] == 'u')
+               return PRIu16;
+             if (name[3] == 'x')
+               return PRIx16;
+             if (name[3] == 'X')
+               return PRIX16;
+             abort ();
+           }
+         if (name[4] == '3' && name[5] == '2' && name[6] == '\0')
+           {
+             if (name[3] == 'd')
+               return PRId32;
+             if (name[3] == 'i')
+               return PRIi32;
+             if (name[3] == 'o')
+               return PRIo32;
+             if (name[3] == 'u')
+               return PRIu32;
+             if (name[3] == 'x')
+               return PRIx32;
+             if (name[3] == 'X')
+               return PRIX32;
+             abort ();
+           }
+         if (name[4] == '6' && name[5] == '4' && name[6] == '\0')
+           {
+             if (name[3] == 'd')
+               return PRId64;
+             if (name[3] == 'i')
+               return PRIi64;
+             if (name[3] == 'o')
+               return PRIo64;
+             if (name[3] == 'u')
+               return PRIu64;
+             if (name[3] == 'x')
+               return PRIx64;
+             if (name[3] == 'X')
+               return PRIX64;
+             abort ();
+           }
+         if (name[4] == 'L' && name[5] == 'E' && name[6] == 'A'
+             && name[7] == 'S' && name[8] == 'T')
+           {
+             if (name[9] == '8' && name[10] == '\0')
+               {
+                 if (name[3] == 'd')
+                   return PRIdLEAST8;
+                 if (name[3] == 'i')
+                   return PRIiLEAST8;
+                 if (name[3] == 'o')
+                   return PRIoLEAST8;
+                 if (name[3] == 'u')
+                   return PRIuLEAST8;
+                 if (name[3] == 'x')
+                   return PRIxLEAST8;
+                 if (name[3] == 'X')
+                   return PRIXLEAST8;
+                 abort ();
+               }
+             if (name[9] == '1' && name[10] == '6' && name[11] == '\0')
+               {
+                 if (name[3] == 'd')
+                   return PRIdLEAST16;
+                 if (name[3] == 'i')
+                   return PRIiLEAST16;
+                 if (name[3] == 'o')
+                   return PRIoLEAST16;
+                 if (name[3] == 'u')
+                   return PRIuLEAST16;
+                 if (name[3] == 'x')
+                   return PRIxLEAST16;
+                 if (name[3] == 'X')
+                   return PRIXLEAST16;
+                 abort ();
+               }
+             if (name[9] == '3' && name[10] == '2' && name[11] == '\0')
+               {
+                 if (name[3] == 'd')
+                   return PRIdLEAST32;
+                 if (name[3] == 'i')
+                   return PRIiLEAST32;
+                 if (name[3] == 'o')
+                   return PRIoLEAST32;
+                 if (name[3] == 'u')
+                   return PRIuLEAST32;
+                 if (name[3] == 'x')
+                   return PRIxLEAST32;
+                 if (name[3] == 'X')
+                   return PRIXLEAST32;
+                 abort ();
+               }
+             if (name[9] == '6' && name[10] == '4' && name[11] == '\0')
+               {
+                 if (name[3] == 'd')
+                   return PRIdLEAST64;
+                 if (name[3] == 'i')
+                   return PRIiLEAST64;
+                 if (name[3] == 'o')
+                   return PRIoLEAST64;
+                 if (name[3] == 'u')
+                   return PRIuLEAST64;
+                 if (name[3] == 'x')
+                   return PRIxLEAST64;
+                 if (name[3] == 'X')
+                   return PRIXLEAST64;
+                 abort ();
+               }
+           }
+         if (name[4] == 'F' && name[5] == 'A' && name[6] == 'S'
+             && name[7] == 'T')
+           {
+             if (name[8] == '8' && name[9] == '\0')
+               {
+                 if (name[3] == 'd')
+                   return PRIdFAST8;
+                 if (name[3] == 'i')
+                   return PRIiFAST8;
+                 if (name[3] == 'o')
+                   return PRIoFAST8;
+                 if (name[3] == 'u')
+                   return PRIuFAST8;
+                 if (name[3] == 'x')
+                   return PRIxFAST8;
+                 if (name[3] == 'X')
+                   return PRIXFAST8;
+                 abort ();
+               }
+             if (name[8] == '1' && name[9] == '6' && name[10] == '\0')
+               {
+                 if (name[3] == 'd')
+                   return PRIdFAST16;
+                 if (name[3] == 'i')
+                   return PRIiFAST16;
+                 if (name[3] == 'o')
+                   return PRIoFAST16;
+                 if (name[3] == 'u')
+                   return PRIuFAST16;
+                 if (name[3] == 'x')
+                   return PRIxFAST16;
+                 if (name[3] == 'X')
+                   return PRIXFAST16;
+                 abort ();
+               }
+             if (name[8] == '3' && name[9] == '2' && name[10] == '\0')
+               {
+                 if (name[3] == 'd')
+                   return PRIdFAST32;
+                 if (name[3] == 'i')
+                   return PRIiFAST32;
+                 if (name[3] == 'o')
+                   return PRIoFAST32;
+                 if (name[3] == 'u')
+                   return PRIuFAST32;
+                 if (name[3] == 'x')
+                   return PRIxFAST32;
+                 if (name[3] == 'X')
+                   return PRIXFAST32;
+                 abort ();
+               }
+             if (name[8] == '6' && name[9] == '4' && name[10] == '\0')
+               {
+                 if (name[3] == 'd')
+                   return PRIdFAST64;
+                 if (name[3] == 'i')
+                   return PRIiFAST64;
+                 if (name[3] == 'o')
+                   return PRIoFAST64;
+                 if (name[3] == 'u')
+                   return PRIuFAST64;
+                 if (name[3] == 'x')
+                   return PRIxFAST64;
+                 if (name[3] == 'X')
+                   return PRIXFAST64;
+                 abort ();
+               }
+           }
+         if (name[4] == 'M' && name[5] == 'A' && name[6] == 'X'
+             && name[7] == '\0')
+           {
+             if (name[3] == 'd')
+               return PRIdMAX;
+             if (name[3] == 'i')
+               return PRIiMAX;
+             if (name[3] == 'o')
+               return PRIoMAX;
+             if (name[3] == 'u')
+               return PRIuMAX;
+             if (name[3] == 'x')
+               return PRIxMAX;
+             if (name[3] == 'X')
+               return PRIXMAX;
+             abort ();
+           }
+         if (name[4] == 'P' && name[5] == 'T' && name[6] == 'R'
+             && name[7] == '\0')
+           {
+             if (name[3] == 'd')
+               return PRIdPTR;
+             if (name[3] == 'i')
+               return PRIiPTR;
+             if (name[3] == 'o')
+               return PRIoPTR;
+             if (name[3] == 'u')
+               return PRIuPTR;
+             if (name[3] == 'x')
+               return PRIxPTR;
+             if (name[3] == 'X')
+               return PRIXPTR;
+             abort ();
+           }
+       }
+    }
+  /* Test for a glibc specific printf() format directive flag.  */
+  if (name[0] == 'I' && name[1] == '\0')
+    {
+#if defined _LIBC || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
+      /* The 'I' flag, in numeric format directives, replaces ASCII digits
+        with the 'outdigits' defined in the LC_CTYPE locale facet.  This is
+        used for Farsi (Persian) and maybe Arabic.  */
+      return "I";
+#else
+      return "";
+#endif
+    }
+  /* Other system dependent strings are not valid.  */
+  return NULL;
+}
+
+/* Initialize the codeset dependent parts of an opened message catalog.
+   Return the header entry.  */
+const char *
+internal_function
+_nl_init_domain_conv (struct loaded_l10nfile *domain_file,
+                     struct loaded_domain *domain,
+                     struct binding *domainbinding)
+{
+  /* Find out about the character set the file is encoded with.
+     This can be found (in textual form) in the entry "".  If this
+     entry does not exist or if this does not contain the `charset='
+     information, we will assume the charset matches the one the
+     current locale and we don't have to perform any conversion.  */
+  char *nullentry;
+  size_t nullentrylen;
+
+  /* Preinitialize fields, to avoid recursion during _nl_find_msg.  */
+  domain->codeset_cntr =
+    (domainbinding != NULL ? domainbinding->codeset_cntr : 0);
+#ifdef _LIBC
+  domain->conv = (__gconv_t) -1;
+#else
+# if HAVE_ICONV
+  domain->conv = (iconv_t) -1;
+# endif
+#endif
+  domain->conv_tab = NULL;
+
+  /* Get the header entry.  */
+  nullentry = _nl_find_msg (domain_file, domainbinding, "", &nullentrylen);
+
+  if (nullentry != NULL)
+    {
+#if defined _LIBC || HAVE_ICONV
+      const char *charsetstr;
+
+      charsetstr = strstr (nullentry, "charset=");
+      if (charsetstr != NULL)
+       {
+         size_t len;
+         char *charset;
+         const char *outcharset;
+
+         charsetstr += strlen ("charset=");
+         len = strcspn (charsetstr, " \t\n");
+
+         charset = (char *) alloca (len + 1);
+# if defined _LIBC || HAVE_MEMPCPY
+         *((char *) mempcpy (charset, charsetstr, len)) = '\0';
+# else
+         memcpy (charset, charsetstr, len);
+         charset[len] = '\0';
+# endif
+
+         /* The output charset should normally be determined by the
+            locale.  But sometimes the locale is not used or not correctly
+            set up, so we provide a possibility for the user to override
+            this.  Moreover, the value specified through
+            bind_textdomain_codeset overrides both.  */
+         if (domainbinding != NULL && domainbinding->codeset != NULL)
+           outcharset = domainbinding->codeset;
+         else
+           {
+             outcharset = getenv ("OUTPUT_CHARSET");
+             if (outcharset == NULL || outcharset[0] == '\0')
+               {
+# ifdef _LIBC
+                 outcharset = _NL_CURRENT (LC_CTYPE, CODESET);
+# else
+#  if HAVE_ICONV
+                 extern const char *locale_charset (void);
+                 outcharset = locale_charset ();
+#  endif
+# endif
+               }
+           }
+
+# ifdef _LIBC
+         /* We always want to use transliteration.  */
+         outcharset = norm_add_slashes (outcharset, "TRANSLIT");
+         charset = norm_add_slashes (charset, NULL);
+         if (__gconv_open (outcharset, charset, &domain->conv,
+                           GCONV_AVOID_NOCONV)
+             != __GCONV_OK)
+           domain->conv = (__gconv_t) -1;
+# else
+#  if HAVE_ICONV
+         /* When using GNU libc >= 2.2 or GNU libiconv >= 1.5,
+            we want to use transliteration.  */
+#   if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \
+       || _LIBICONV_VERSION >= 0x0105
+         if (strchr (outcharset, '/') == NULL)
+           {
+             char *tmp;
+
+             len = strlen (outcharset);
+             tmp = (char *) alloca (len + 10 + 1);
+             memcpy (tmp, outcharset, len);
+             memcpy (tmp + len, "//TRANSLIT", 10 + 1);
+             outcharset = tmp;
+
+             domain->conv = iconv_open (outcharset, charset);
+
+             freea (outcharset);
+           }
+         else
+#   endif
+           domain->conv = iconv_open (outcharset, charset);
+#  endif
+# endif
+
+         freea (charset);
+       }
+#endif /* _LIBC || HAVE_ICONV */
+    }
+
+  return nullentry;
+}
+
+/* Frees the codeset dependent parts of an opened message catalog.  */
+void
+internal_function
+_nl_free_domain_conv (struct loaded_domain *domain)
+{
+  if (domain->conv_tab != NULL && domain->conv_tab != (char **) -1)
+    free (domain->conv_tab);
+
+#ifdef _LIBC
+  if (domain->conv != (__gconv_t) -1)
+    __gconv_close (domain->conv);
+#else
+# if HAVE_ICONV
+  if (domain->conv != (iconv_t) -1)
+    iconv_close (domain->conv);
+# endif
+#endif
+}
+
+/* Load the message catalogs specified by FILENAME.  If it is no valid
+   message catalog do nothing.  */
+void
+internal_function
+_nl_load_domain (struct loaded_l10nfile *domain_file,
+                struct binding *domainbinding)
+{
+  int fd;
+  size_t size;
+#ifdef _LIBC
+  struct stat64 st;
+#else
+  struct stat st;
+#endif
+  struct mo_file_header *data = (struct mo_file_header *) -1;
+  int use_mmap = 0;
+  struct loaded_domain *domain;
+  int revision;
+  const char *nullentry;
+
+  domain_file->decided = 1;
+  domain_file->data = NULL;
+
+  /* Note that it would be useless to store domainbinding in domain_file
+     because domainbinding might be == NULL now but != NULL later (after
+     a call to bind_textdomain_codeset).  */
+
+  /* If the record does not represent a valid locale the FILENAME
+     might be NULL.  This can happen when according to the given
+     specification the locale file name is different for XPG and CEN
+     syntax.  */
+  if (domain_file->filename == NULL)
+    return;
+
+  /* Try to open the addressed file.  */
+  fd = open (domain_file->filename, O_RDONLY | O_BINARY);
+  if (fd == -1)
+    return;
+
+  /* We must know about the size of the file.  */
+  if (
+#ifdef _LIBC
+      __builtin_expect (fstat64 (fd, &st) != 0, 0)
+#else
+      __builtin_expect (fstat (fd, &st) != 0, 0)
+#endif
+      || __builtin_expect ((size = (size_t) st.st_size) != st.st_size, 0)
+      || __builtin_expect (size < sizeof (struct mo_file_header), 0))
+    {
+      /* Something went wrong.  */
+      close (fd);
+      return;
+    }
+
+#ifdef HAVE_MMAP
+  /* Now we are ready to load the file.  If mmap() is available we try
+     this first.  If not available or it failed we try to load it.  */
+  data = (struct mo_file_header *) mmap (NULL, size, PROT_READ,
+                                        MAP_PRIVATE, fd, 0);
+
+  if (__builtin_expect (data != (struct mo_file_header *) -1, 1))
+    {
+      /* mmap() call was successful.  */
+      close (fd);
+      use_mmap = 1;
+    }
+#endif
+
+  /* If the data is not yet available (i.e. mmap'ed) we try to load
+     it manually.  */
+  if (data == (struct mo_file_header *) -1)
+    {
+      size_t to_read;
+      char *read_ptr;
+
+      data = (struct mo_file_header *) malloc (size);
+      if (data == NULL)
+       return;
+
+      to_read = size;
+      read_ptr = (char *) data;
+      do
+       {
+         long int nb = (long int) read (fd, read_ptr, to_read);
+         if (nb <= 0)
+           {
+#ifdef EINTR
+             if (nb == -1 && errno == EINTR)
+               continue;
+#endif
+             close (fd);
+             return;
+           }
+         read_ptr += nb;
+         to_read -= nb;
+       }
+      while (to_read > 0);
+
+      close (fd);
+    }
+
+  /* Using the magic number we can test whether it really is a message
+     catalog file.  */
+  if (__builtin_expect (data->magic != _MAGIC && data->magic != _MAGIC_SWAPPED,
+                       0))
+    {
+      /* The magic number is wrong: not a message catalog file.  */
+#ifdef HAVE_MMAP
+      if (use_mmap)
+       munmap ((caddr_t) data, size);
+      else
+#endif
+       free (data);
+      return;
+    }
+
+  domain = (struct loaded_domain *) malloc (sizeof (struct loaded_domain));
+  if (domain == NULL)
+    return;
+  domain_file->data = domain;
+
+  domain->data = (char *) data;
+  domain->use_mmap = use_mmap;
+  domain->mmap_size = size;
+  domain->must_swap = data->magic != _MAGIC;
+  domain->malloced = NULL;
+
+  /* Fill in the information about the available tables.  */
+  revision = W (domain->must_swap, data->revision);
+  /* We support only the major revisions 0 and 1.  */
+  switch (revision >> 16)
+    {
+    case 0:
+    case 1:
+      domain->nstrings = W (domain->must_swap, data->nstrings);
+      domain->orig_tab = (const struct string_desc *)
+       ((char *) data + W (domain->must_swap, data->orig_tab_offset));
+      domain->trans_tab = (const struct string_desc *)
+       ((char *) data + W (domain->must_swap, data->trans_tab_offset));
+      domain->hash_size = W (domain->must_swap, data->hash_tab_size);
+      domain->hash_tab =
+       (domain->hash_size > 2
+        ? (const nls_uint32 *)
+          ((char *) data + W (domain->must_swap, data->hash_tab_offset))
+        : NULL);
+      domain->must_swap_hash_tab = domain->must_swap;
+
+      /* Now dispatch on the minor revision.  */
+      switch (revision & 0xffff)
+       {
+       case 0:
+         domain->n_sysdep_strings = 0;
+         domain->orig_sysdep_tab = NULL;
+         domain->trans_sysdep_tab = NULL;
+         break;
+       case 1:
+       default:
+         {
+           nls_uint32 n_sysdep_strings;
+
+           if (domain->hash_tab == NULL)
+             /* This is invalid.  These minor revisions need a hash table.  */
+             goto invalid;
+
+           n_sysdep_strings =
+             W (domain->must_swap, data->n_sysdep_strings);
+           if (n_sysdep_strings > 0)
+             {
+               nls_uint32 n_sysdep_segments;
+               const struct sysdep_segment *sysdep_segments;
+               const char **sysdep_segment_values;
+               const nls_uint32 *orig_sysdep_tab;
+               const nls_uint32 *trans_sysdep_tab;
+               nls_uint32 n_inmem_sysdep_strings;
+               size_t memneed;
+               char *mem;
+               struct sysdep_string_desc *inmem_orig_sysdep_tab;
+               struct sysdep_string_desc *inmem_trans_sysdep_tab;
+               nls_uint32 *inmem_hash_tab;
+               unsigned int i, j;
+
+               /* Get the values of the system dependent segments.  */
+               n_sysdep_segments =
+                 W (domain->must_swap, data->n_sysdep_segments);
+               sysdep_segments = (const struct sysdep_segment *)
+                 ((char *) data
+                  + W (domain->must_swap, data->sysdep_segments_offset));
+               sysdep_segment_values =
+                 alloca (n_sysdep_segments * sizeof (const char *));
+               for (i = 0; i < n_sysdep_segments; i++)
+                 {
+                   const char *name =
+                     (char *) data
+                     + W (domain->must_swap, sysdep_segments[i].offset);
+                   nls_uint32 namelen =
+                     W (domain->must_swap, sysdep_segments[i].length);
+
+                   if (!(namelen > 0 && name[namelen - 1] == '\0'))
+                     {
+                       freea (sysdep_segment_values);
+                       goto invalid;
+                     }
+
+                   sysdep_segment_values[i] = get_sysdep_segment_value (name);
+                 }
+
+               orig_sysdep_tab = (const nls_uint32 *)
+                 ((char *) data
+                  + W (domain->must_swap, data->orig_sysdep_tab_offset));
+               trans_sysdep_tab = (const nls_uint32 *)
+                 ((char *) data
+                  + W (domain->must_swap, data->trans_sysdep_tab_offset));
+
+               /* Compute the amount of additional memory needed for the
+                  system dependent strings and the augmented hash table.
+                  At the same time, also drop string pairs which refer to
+                  an undefined system dependent segment.  */
+               n_inmem_sysdep_strings = 0;
+               memneed = domain->hash_size * sizeof (nls_uint32);
+               for (i = 0; i < n_sysdep_strings; i++)
+                 {
+                   int valid = 1;
+                   size_t needs[2];
+
+                   for (j = 0; j < 2; j++)
+                     {
+                       const struct sysdep_string *sysdep_string =
+                         (const struct sysdep_string *)
+                         ((char *) data
+                          + W (domain->must_swap,
+                               j == 0
+                               ? orig_sysdep_tab[i]
+                               : trans_sysdep_tab[i]));
+                       size_t need = 0;
+                       const struct segment_pair *p = sysdep_string->segments;
+
+                       if (W (domain->must_swap, p->sysdepref) != SEGMENTS_END)
+                         for (p = sysdep_string->segments;; p++)
+                           {
+                             nls_uint32 sysdepref;
+
+                             need += W (domain->must_swap, p->segsize);
+
+                             sysdepref = W (domain->must_swap, p->sysdepref);
+                             if (sysdepref == SEGMENTS_END)
+                               break;
+
+                             if (sysdepref >= n_sysdep_segments)
+                               {
+                                 /* Invalid.  */
+                                 freea (sysdep_segment_values);
+                                 goto invalid;
+                               }
+
+                             if (sysdep_segment_values[sysdepref] == NULL)
+                               {
+                                 /* This particular string pair is invalid.  */
+                                 valid = 0;
+                                 break;
+                               }
+
+                             need += strlen (sysdep_segment_values[sysdepref]);
+                           }
+
+                       needs[j] = need;
+                       if (!valid)
+                         break;
+                     }
+
+                   if (valid)
+                     {
+                       n_inmem_sysdep_strings++;
+                       memneed += needs[0] + needs[1];
+                     }
+                 }
+               memneed += 2 * n_inmem_sysdep_strings
+                          * sizeof (struct sysdep_string_desc);
+
+               if (n_inmem_sysdep_strings > 0)
+                 {
+                   unsigned int k;
+
+                   /* Allocate additional memory.  */
+                   mem = (char *) malloc (memneed);
+                   if (mem == NULL)
+                     goto invalid;
+
+                   domain->malloced = mem;
+                   inmem_orig_sysdep_tab = (struct sysdep_string_desc *) mem;
+                   mem += n_inmem_sysdep_strings
+                          * sizeof (struct sysdep_string_desc);
+                   inmem_trans_sysdep_tab = (struct sysdep_string_desc *) mem;
+                   mem += n_inmem_sysdep_strings
+                          * sizeof (struct sysdep_string_desc);
+                   inmem_hash_tab = (nls_uint32 *) mem;
+                   mem += domain->hash_size * sizeof (nls_uint32);
+
+                   /* Compute the system dependent strings.  */
+                   k = 0;
+                   for (i = 0; i < n_sysdep_strings; i++)
+                     {
+                       int valid = 1;
+
+                       for (j = 0; j < 2; j++)
+                         {
+                           const struct sysdep_string *sysdep_string =
+                             (const struct sysdep_string *)
+                             ((char *) data
+                              + W (domain->must_swap,
+                                   j == 0
+                                   ? orig_sysdep_tab[i]
+                                   : trans_sysdep_tab[i]));
+                           const struct segment_pair *p =
+                             sysdep_string->segments;
+
+                           if (W (domain->must_swap, p->sysdepref)
+                               != SEGMENTS_END)
+                             for (p = sysdep_string->segments;; p++)
+                               {
+                                 nls_uint32 sysdepref;
+
+                                 sysdepref =
+                                   W (domain->must_swap, p->sysdepref);
+                                 if (sysdepref == SEGMENTS_END)
+                                   break;
+
+                                 if (sysdep_segment_values[sysdepref] == NULL)
+                                   {
+                                     /* This particular string pair is
+                                        invalid.  */
+                                     valid = 0;
+                                     break;
+                                   }
+                               }
+
+                           if (!valid)
+                             break;
+                         }
+
+                       if (valid)
+                         {
+                           for (j = 0; j < 2; j++)
+                             {
+                               const struct sysdep_string *sysdep_string =
+                                 (const struct sysdep_string *)
+                                 ((char *) data
+                                  + W (domain->must_swap,
+                                       j == 0
+                                       ? orig_sysdep_tab[i]
+                                       : trans_sysdep_tab[i]));
+                               const char *static_segments =
+                                 (char *) data
+                                 + W (domain->must_swap, sysdep_string->offset);
+                               const struct segment_pair *p =
+                                 sysdep_string->segments;
+
+                               /* Concatenate the segments, and fill
+                                  inmem_orig_sysdep_tab[k] (for j == 0) and
+                                  inmem_trans_sysdep_tab[k] (for j == 1).  */
+
+                               struct sysdep_string_desc *inmem_tab_entry =
+                                 (j == 0
+                                  ? inmem_orig_sysdep_tab
+                                  : inmem_trans_sysdep_tab)
+                                 + k;
+
+                               if (W (domain->must_swap, p->sysdepref)
+                                   == SEGMENTS_END)
+                                 {
+                                   /* Only one static segment.  */
+                                   inmem_tab_entry->length =
+                                     W (domain->must_swap, p->segsize);
+                                   inmem_tab_entry->pointer = static_segments;
+                                 }
+                               else
+                                 {
+                                   inmem_tab_entry->pointer = mem;
+
+                                   for (p = sysdep_string->segments;; p++)
+                                     {
+                                       nls_uint32 segsize =
+                                         W (domain->must_swap, p->segsize);
+                                       nls_uint32 sysdepref =
+                                         W (domain->must_swap, p->sysdepref);
+                                       size_t n;
+
+                                       if (segsize > 0)
+                                         {
+                                           memcpy (mem, static_segments, segsize);
+                                           mem += segsize;
+                                           static_segments += segsize;
+                                         }
+
+                                       if (sysdepref == SEGMENTS_END)
+                                         break;
+
+                                       n = strlen (sysdep_segment_values[sysdepref]);
+                                       memcpy (mem, sysdep_segment_values[sysdepref], n);
+                                       mem += n;
+                                     }
+
+                                   inmem_tab_entry->length =
+                                     mem - inmem_tab_entry->pointer;
+                                 }
+                             }
+
+                           k++;
+                         }
+                     }
+                   if (k != n_inmem_sysdep_strings)
+                     abort ();
+
+                   /* Compute the augmented hash table.  */
+                   for (i = 0; i < domain->hash_size; i++)
+                     inmem_hash_tab[i] =
+                       W (domain->must_swap_hash_tab, domain->hash_tab[i]);
+                   for (i = 0; i < n_inmem_sysdep_strings; i++)
+                     {
+                       const char *msgid = inmem_orig_sysdep_tab[i].pointer;
+                       nls_uint32 hash_val = hash_string (msgid);
+                       nls_uint32 idx = hash_val % domain->hash_size;
+                       nls_uint32 incr =
+                         1 + (hash_val % (domain->hash_size - 2));
+
+                       for (;;)
+                         {
+                           if (inmem_hash_tab[idx] == 0)
+                             {
+                               /* Hash table entry is empty.  Use it.  */
+                               inmem_hash_tab[idx] = 1 + domain->nstrings + i;
+                               break;
+                             }
+
+                           if (idx >= domain->hash_size - incr)
+                             idx -= domain->hash_size - incr;
+                           else
+                             idx += incr;
+                         }
+                     }
+
+                   domain->n_sysdep_strings = n_inmem_sysdep_strings;
+                   domain->orig_sysdep_tab = inmem_orig_sysdep_tab;
+                   domain->trans_sysdep_tab = inmem_trans_sysdep_tab;
+
+                   domain->hash_tab = inmem_hash_tab;
+                   domain->must_swap_hash_tab = 0;
+                 }
+               else
+                 {
+                   domain->n_sysdep_strings = 0;
+                   domain->orig_sysdep_tab = NULL;
+                   domain->trans_sysdep_tab = NULL;
+                 }
+
+               freea (sysdep_segment_values);
+             }
+           else
+             {
+               domain->n_sysdep_strings = 0;
+               domain->orig_sysdep_tab = NULL;
+               domain->trans_sysdep_tab = NULL;
+             }
+         }
+         break;
+       }
+      break;
+    default:
+      /* This is an invalid revision.  */
+    invalid:
+      /* This is an invalid .mo file.  */
+      if (domain->malloced)
+       free (domain->malloced);
+#ifdef HAVE_MMAP
+      if (use_mmap)
+       munmap ((caddr_t) data, size);
+      else
+#endif
+       free (data);
+      free (domain);
+      domain_file->data = NULL;
+      return;
+    }
+
+  /* Now initialize the character set converter from the character set
+     the file is encoded with (found in the header entry) to the domain's
+     specified character set or the locale's character set.  */
+  nullentry = _nl_init_domain_conv (domain_file, domain, domainbinding);
+
+  /* Also look for a plural specification.  */
+  EXTRACT_PLURAL_EXPRESSION (nullentry, &domain->plural, &domain->nplurals);
+}
+
+
+#ifdef _LIBC
+void
+internal_function
+_nl_unload_domain (struct loaded_domain *domain)
+{
+  if (domain->plural != &__gettext_germanic_plural)
+    __gettext_free_exp (domain->plural);
+
+  _nl_free_domain_conv (domain);
+
+  if (domain->malloced)
+    free (domain->malloced);
+
+# ifdef _POSIX_MAPPED_FILES
+  if (domain->use_mmap)
+    munmap ((caddr_t) domain->data, domain->mmap_size);
+  else
+# endif        /* _POSIX_MAPPED_FILES */
+    free ((void *) domain->data);
+
+  free (domain);
+}
+#endif
diff --git a/intl/localcharset.c b/intl/localcharset.c
new file mode 100644 (file)
index 0000000..a3e52ef
--- /dev/null
@@ -0,0 +1,409 @@
+/* Determine a canonical name for the current locale's character encoding.
+
+   Copyright (C) 2000-2004 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Specification.  */
+#include "localcharset.h"
+
+#if HAVE_STDDEF_H
+# include <stddef.h>
+#endif
+
+#include <stdio.h>
+#if HAVE_STRING_H
+# include <string.h>
+#else
+# include <strings.h>
+#endif
+#if HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+
+#if defined _WIN32 || defined __WIN32__
+# undef WIN32   /* avoid warning on mingw32 */
+# define WIN32
+#endif
+
+#if defined __EMX__
+/* Assume EMX program runs on OS/2, even if compiled under DOS.  */
+# define OS2
+#endif
+
+#if !defined WIN32
+# if HAVE_LANGINFO_CODESET
+#  include <langinfo.h>
+# else
+#  if HAVE_SETLOCALE
+#   include <locale.h>
+#  endif
+# endif
+#elif defined WIN32
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+#endif
+#if defined OS2
+# define INCL_DOS
+# include <os2.h>
+#endif
+
+#if ENABLE_RELOCATABLE
+# include "relocatable.h"
+#else
+# define relocate(pathname) (pathname)
+#endif
+
+#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
+  /* Win32, Cygwin, OS/2, DOS */
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+#endif
+
+#ifndef DIRECTORY_SEPARATOR
+# define DIRECTORY_SEPARATOR '/'
+#endif
+
+#ifndef ISSLASH
+# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
+#endif
+
+#if HAVE_DECL_GETC_UNLOCKED
+# undef getc
+# define getc getc_unlocked
+#endif
+
+/* The following static variable is declared 'volatile' to avoid a
+   possible multithread problem in the function get_charset_aliases. If we
+   are running in a threaded environment, and if two threads initialize
+   'charset_aliases' simultaneously, both will produce the same value,
+   and everything will be ok if the two assignments to 'charset_aliases'
+   are atomic. But I don't know what will happen if the two assignments mix.  */
+#if __STDC__ != 1
+# define volatile /* empty */
+#endif
+/* Pointer to the contents of the charset.alias file, if it has already been
+   read, else NULL.  Its format is:
+   ALIAS_1 '\0' CANONICAL_1 '\0' ... ALIAS_n '\0' CANONICAL_n '\0' '\0'  */
+static const char * volatile charset_aliases;
+
+/* Return a pointer to the contents of the charset.alias file.  */
+static const char *
+get_charset_aliases ()
+{
+  const char *cp;
+
+  cp = charset_aliases;
+  if (cp == NULL)
+    {
+#if !(defined VMS || defined WIN32)
+      FILE *fp;
+      const char *dir;
+      const char *base = "charset.alias";
+      char *file_name;
+
+      /* Make it possible to override the charset.alias location.  This is
+        necessary for running the testsuite before "make install".  */
+      dir = getenv ("CHARSETALIASDIR");
+      if (dir == NULL || dir[0] == '\0')
+       dir = relocate (LIBDIR);
+
+      /* Concatenate dir and base into freshly allocated file_name.  */
+      {
+       size_t dir_len = strlen (dir);
+       size_t base_len = strlen (base);
+       int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1]));
+       file_name = (char *) malloc (dir_len + add_slash + base_len + 1);
+       if (file_name != NULL)
+         {
+           memcpy (file_name, dir, dir_len);
+           if (add_slash)
+             file_name[dir_len] = DIRECTORY_SEPARATOR;
+           memcpy (file_name + dir_len + add_slash, base, base_len + 1);
+         }
+      }
+
+      if (file_name == NULL || (fp = fopen (file_name, "r")) == NULL)
+       /* Out of memory or file not found, treat it as empty.  */
+       cp = "";
+      else
+       {
+         /* Parse the file's contents.  */
+         char *res_ptr = NULL;
+         size_t res_size = 0;
+
+         for (;;)
+           {
+             int c;
+             char buf1[50+1];
+             char buf2[50+1];
+             size_t l1, l2;
+             char *old_res_ptr;
+
+             c = getc (fp);
+             if (c == EOF)
+               break;
+             if (c == '\n' || c == ' ' || c == '\t')
+               continue;
+             if (c == '#')
+               {
+                 /* Skip comment, to end of line.  */
+                 do
+                   c = getc (fp);
+                 while (!(c == EOF || c == '\n'));
+                 if (c == EOF)
+                   break;
+                 continue;
+               }
+             ungetc (c, fp);
+             if (fscanf (fp, "%50s %50s", buf1, buf2) < 2)
+               break;
+             l1 = strlen (buf1);
+             l2 = strlen (buf2);
+             old_res_ptr = res_ptr;
+             if (res_size == 0)
+               {
+                 res_size = l1 + 1 + l2 + 1;
+                 res_ptr = (char *) malloc (res_size + 1);
+               }
+             else
+               {
+                 res_size += l1 + 1 + l2 + 1;
+                 res_ptr = (char *) realloc (res_ptr, res_size + 1);
+               }
+             if (res_ptr == NULL)
+               {
+                 /* Out of memory. */
+                 res_size = 0;
+                 if (old_res_ptr != NULL)
+                   free (old_res_ptr);
+                 break;
+               }
+             strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1);
+             strcpy (res_ptr + res_size - (l2 + 1), buf2);
+           }
+         fclose (fp);
+         if (res_size == 0)
+           cp = "";
+         else
+           {
+             *(res_ptr + res_size) = '\0';
+             cp = res_ptr;
+           }
+       }
+
+      if (file_name != NULL)
+       free (file_name);
+
+#else
+
+# if defined VMS
+      /* To avoid the troubles of an extra file charset.alias_vms in the
+        sources of many GNU packages, simply inline the aliases here.  */
+      /* The list of encodings is taken from the OpenVMS 7.3-1 documentation
+        "Compaq C Run-Time Library Reference Manual for OpenVMS systems"
+        section 10.7 "Handling Different Character Sets".  */
+      cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
+          "ISO8859-2" "\0" "ISO-8859-2" "\0"
+          "ISO8859-5" "\0" "ISO-8859-5" "\0"
+          "ISO8859-7" "\0" "ISO-8859-7" "\0"
+          "ISO8859-8" "\0" "ISO-8859-8" "\0"
+          "ISO8859-9" "\0" "ISO-8859-9" "\0"
+          /* Japanese */
+          "eucJP" "\0" "EUC-JP" "\0"
+          "SJIS" "\0" "SHIFT_JIS" "\0"
+          "DECKANJI" "\0" "DEC-KANJI" "\0"
+          "SDECKANJI" "\0" "EUC-JP" "\0"
+          /* Chinese */
+          "eucTW" "\0" "EUC-TW" "\0"
+          "DECHANYU" "\0" "DEC-HANYU" "\0"
+          "DECHANZI" "\0" "GB2312" "\0"
+          /* Korean */
+          "DECKOREAN" "\0" "EUC-KR" "\0";
+# endif
+
+# if defined WIN32
+      /* To avoid the troubles of installing a separate file in the same
+        directory as the DLL and of retrieving the DLL's directory at
+        runtime, simply inline the aliases here.  */
+
+      cp = "CP936" "\0" "GBK" "\0"
+          "CP1361" "\0" "JOHAB" "\0"
+          "CP20127" "\0" "ASCII" "\0"
+          "CP20866" "\0" "KOI8-R" "\0"
+          "CP21866" "\0" "KOI8-RU" "\0"
+          "CP28591" "\0" "ISO-8859-1" "\0"
+          "CP28592" "\0" "ISO-8859-2" "\0"
+          "CP28593" "\0" "ISO-8859-3" "\0"
+          "CP28594" "\0" "ISO-8859-4" "\0"
+          "CP28595" "\0" "ISO-8859-5" "\0"
+          "CP28596" "\0" "ISO-8859-6" "\0"
+          "CP28597" "\0" "ISO-8859-7" "\0"
+          "CP28598" "\0" "ISO-8859-8" "\0"
+          "CP28599" "\0" "ISO-8859-9" "\0"
+          "CP28605" "\0" "ISO-8859-15" "\0";
+# endif
+#endif
+
+      charset_aliases = cp;
+    }
+
+  return cp;
+}
+
+/* Determine the current locale's character encoding, and canonicalize it
+   into one of the canonical names listed in config.charset.
+   The result must not be freed; it is statically allocated.
+   If the canonical name cannot be determined, the result is a non-canonical
+   name.  */
+
+#ifdef STATIC
+STATIC
+#endif
+const char *
+locale_charset ()
+{
+  const char *codeset;
+  const char *aliases;
+
+#if !(defined WIN32 || defined OS2)
+
+# if HAVE_LANGINFO_CODESET
+
+  /* Most systems support nl_langinfo (CODESET) nowadays.  */
+  codeset = nl_langinfo (CODESET);
+
+# else
+
+  /* On old systems which lack it, use setlocale or getenv.  */
+  const char *locale = NULL;
+
+  /* But most old systems don't have a complete set of locales.  Some
+     (like SunOS 4 or DJGPP) have only the C locale.  Therefore we don't
+     use setlocale here; it would return "C" when it doesn't support the
+     locale name the user has set.  */
+#  if HAVE_SETLOCALE && 0
+  locale = setlocale (LC_CTYPE, NULL);
+#  endif
+  if (locale == NULL || locale[0] == '\0')
+    {
+      locale = getenv ("LC_ALL");
+      if (locale == NULL || locale[0] == '\0')
+       {
+         locale = getenv ("LC_CTYPE");
+         if (locale == NULL || locale[0] == '\0')
+           locale = getenv ("LANG");
+       }
+    }
+
+  /* On some old systems, one used to set locale = "iso8859_1". On others,
+     you set it to "language_COUNTRY.charset". In any case, we resolve it
+     through the charset.alias file.  */
+  codeset = locale;
+
+# endif
+
+#elif defined WIN32
+
+  static char buf[2 + 10 + 1];
+
+  /* Woe32 has a function returning the locale's codepage as a number.  */
+  sprintf (buf, "CP%u", GetACP ());
+  codeset = buf;
+
+#elif defined OS2
+
+  const char *locale;
+  static char buf[2 + 10 + 1];
+  ULONG cp[3];
+  ULONG cplen;
+
+  /* Allow user to override the codeset, as set in the operating system,
+     with standard language environment variables.  */
+  locale = getenv ("LC_ALL");
+  if (locale == NULL || locale[0] == '\0')
+    {
+      locale = getenv ("LC_CTYPE");
+      if (locale == NULL || locale[0] == '\0')
+       locale = getenv ("LANG");
+    }
+  if (locale != NULL && locale[0] != '\0')
+    {
+      /* If the locale name contains an encoding after the dot, return it.  */
+      const char *dot = strchr (locale, '.');
+
+      if (dot != NULL)
+       {
+         const char *modifier;
+
+         dot++;
+         /* Look for the possible @... trailer and remove it, if any.  */
+         modifier = strchr (dot, '@');
+         if (modifier == NULL)
+           return dot;
+         if (modifier - dot < sizeof (buf))
+           {
+             memcpy (buf, dot, modifier - dot);
+             buf [modifier - dot] = '\0';
+             return buf;
+           }
+       }
+
+      /* Resolve through the charset.alias file.  */
+      codeset = locale;
+    }
+  else
+    {
+      /* OS/2 has a function returning the locale's codepage as a number.  */
+      if (DosQueryCp (sizeof (cp), cp, &cplen))
+       codeset = "";
+      else
+       {
+         sprintf (buf, "CP%u", cp[0]);
+         codeset = buf;
+       }
+    }
+
+#endif
+
+  if (codeset == NULL)
+    /* The canonical name cannot be determined.  */
+    codeset = "";
+
+  /* Resolve alias. */
+  for (aliases = get_charset_aliases ();
+       *aliases != '\0';
+       aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1)
+    if (strcmp (codeset, aliases) == 0
+       || (aliases[0] == '*' && aliases[1] == '\0'))
+      {
+       codeset = aliases + strlen (aliases) + 1;
+       break;
+      }
+
+  /* Don't return an empty string.  GNU libc and GNU libiconv interpret
+     the empty string as denoting "the locale's character encoding",
+     thus GNU libiconv would call this function a second time.  */
+  if (codeset[0] == '\0')
+    codeset = "ASCII";
+
+  return codeset;
+}
diff --git a/intl/localcharset.h b/intl/localcharset.h
new file mode 100644 (file)
index 0000000..3b137e7
--- /dev/null
@@ -0,0 +1,42 @@
+/* Determine a canonical name for the current locale's character encoding.
+   Copyright (C) 2000-2003 Free Software Foundation, Inc.
+   This file is part of the GNU CHARSET Library.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifndef _LOCALCHARSET_H
+#define _LOCALCHARSET_H
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Determine the current locale's character encoding, and canonicalize it
+   into one of the canonical names listed in config.charset.
+   The result must not be freed; it is statically allocated.
+   If the canonical name cannot be determined, the result is a non-canonical
+   name.  */
+extern const char * locale_charset (void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _LOCALCHARSET_H */
diff --git a/intl/locale.alias b/intl/locale.alias
new file mode 100644 (file)
index 0000000..bd6bb25
--- /dev/null
@@ -0,0 +1,78 @@
+# Locale name alias data base.
+# Copyright (C) 1996-2001,2003 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Library General Public License as published
+# by the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program 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
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+# USA.
+
+# The format of this file is the same as for the corresponding file of
+# the X Window System, which normally can be found in
+#      /usr/lib/X11/locale/locale.alias
+# A single line contains two fields: an alias and a substitution value.
+# All entries are case independent.
+
+# Note: This file is far from being complete.  If you have a value for
+# your own site which you think might be useful for others too, share
+# it with the rest of us.  Send it using the `glibcbug' script to
+# bugs@gnu.org.
+
+# Packages using this file: 
+
+bokmal         nb_NO.ISO-8859-1
+bokmål         nb_NO.ISO-8859-1
+catalan                ca_ES.ISO-8859-1
+croatian       hr_HR.ISO-8859-2
+czech          cs_CZ.ISO-8859-2
+danish          da_DK.ISO-8859-1
+dansk          da_DK.ISO-8859-1
+deutsch                de_DE.ISO-8859-1
+dutch          nl_NL.ISO-8859-1
+eesti          et_EE.ISO-8859-1
+estonian       et_EE.ISO-8859-1
+finnish         fi_FI.ISO-8859-1
+français       fr_FR.ISO-8859-1
+french         fr_FR.ISO-8859-1
+galego         gl_ES.ISO-8859-1
+galician       gl_ES.ISO-8859-1
+german         de_DE.ISO-8859-1
+greek           el_GR.ISO-8859-7
+hebrew          he_IL.ISO-8859-8
+hrvatski       hr_HR.ISO-8859-2
+hungarian       hu_HU.ISO-8859-2
+icelandic       is_IS.ISO-8859-1
+italian         it_IT.ISO-8859-1
+japanese       ja_JP.eucJP
+japanese.euc   ja_JP.eucJP
+ja_JP          ja_JP.eucJP
+ja_JP.ujis     ja_JP.eucJP
+japanese.sjis  ja_JP.SJIS
+korean         ko_KR.eucKR
+korean.euc     ko_KR.eucKR
+ko_KR          ko_KR.eucKR
+lithuanian      lt_LT.ISO-8859-13
+no_NO          nb_NO.ISO-8859-1
+no_NO.ISO-8859-1 nb_NO.ISO-8859-1
+norwegian       nb_NO.ISO-8859-1
+nynorsk                nn_NO.ISO-8859-1
+polish          pl_PL.ISO-8859-2
+portuguese      pt_PT.ISO-8859-1
+romanian        ro_RO.ISO-8859-2
+russian         ru_RU.ISO-8859-5
+slovak          sk_SK.ISO-8859-2
+slovene         sl_SI.ISO-8859-2
+slovenian       sl_SI.ISO-8859-2
+spanish         es_ES.ISO-8859-1
+swedish         sv_SE.ISO-8859-1
+thai           th_TH.TIS-620
+turkish         tr_TR.ISO-8859-9
diff --git a/intl/localealias.c b/intl/localealias.c
new file mode 100644 (file)
index 0000000..2eaf881
--- /dev/null
@@ -0,0 +1,414 @@
+/* Handle aliases for locale names.
+   Copyright (C) 1995-1999, 2000-2001, 2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+/* Tell glibc's <string.h> to provide a prototype for mempcpy().
+   This must come before <config.h> because <config.h> may include
+   <features.h>, and once <features.h> has been included, it's too late.  */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE    1
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <ctype.h>
+#include <stdio.h>
+#if defined _LIBC || defined HAVE___FSETLOCKING
+# include <stdio_ext.h>
+#endif
+#include <sys/types.h>
+
+#ifdef __GNUC__
+# undef alloca
+# define alloca __builtin_alloca
+# define HAVE_ALLOCA 1
+#else
+# ifdef _MSC_VER
+#  include <malloc.h>
+#  define alloca _alloca
+# else
+#  if defined HAVE_ALLOCA_H || defined _LIBC
+#   include <alloca.h>
+#  else
+#   ifdef _AIX
+ #pragma alloca
+#   else
+#    ifndef alloca
+char *alloca ();
+#    endif
+#   endif
+#  endif
+# endif
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "gettextP.h"
+
+#if ENABLE_RELOCATABLE
+# include "relocatable.h"
+#else
+# define relocate(pathname) (pathname)
+#endif
+
+/* @@ end of prolog @@ */
+
+#ifdef _LIBC
+/* Rename the non ANSI C functions.  This is required by the standard
+   because some ANSI C functions will require linking with this object
+   file and the name space must not be polluted.  */
+# define strcasecmp __strcasecmp
+
+# ifndef mempcpy
+#  define mempcpy __mempcpy
+# endif
+# define HAVE_MEMPCPY  1
+# define HAVE___FSETLOCKING    1
+
+/* We need locking here since we can be called from different places.  */
+# include <bits/libc-lock.h>
+
+__libc_lock_define_initialized (static, lock);
+#endif
+
+#ifndef internal_function
+# define internal_function
+#endif
+
+/* Some optimizations for glibc.  */
+#ifdef _LIBC
+# define FEOF(fp)              feof_unlocked (fp)
+# define FGETS(buf, n, fp)     fgets_unlocked (buf, n, fp)
+#else
+# define FEOF(fp)              feof (fp)
+# define FGETS(buf, n, fp)     fgets (buf, n, fp)
+#endif
+
+/* For those losing systems which don't have `alloca' we have to add
+   some additional code emulating it.  */
+#ifdef HAVE_ALLOCA
+# define freea(p) /* nothing */
+#else
+# define alloca(n) malloc (n)
+# define freea(p) free (p)
+#endif
+
+#if defined _LIBC_REENTRANT || HAVE_DECL_FGETS_UNLOCKED
+# undef fgets
+# define fgets(buf, len, s) fgets_unlocked (buf, len, s)
+#endif
+#if defined _LIBC_REENTRANT || HAVE_DECL_FEOF_UNLOCKED
+# undef feof
+# define feof(s) feof_unlocked (s)
+#endif
+
+
+struct alias_map
+{
+  const char *alias;
+  const char *value;
+};
+
+
+#ifndef _LIBC
+# define libc_freeres_ptr(decl) decl
+#endif
+
+libc_freeres_ptr (static char *string_space);
+static size_t string_space_act;
+static size_t string_space_max;
+libc_freeres_ptr (static struct alias_map *map);
+static size_t nmap;
+static size_t maxmap;
+
+
+/* Prototypes for local functions.  */
+static size_t read_alias_file (const char *fname, int fname_len)
+     internal_function;
+static int extend_alias_table (void);
+static int alias_compare (const struct alias_map *map1,
+                         const struct alias_map *map2);
+
+
+const char *
+_nl_expand_alias (const char *name)
+{
+  static const char *locale_alias_path;
+  struct alias_map *retval;
+  const char *result = NULL;
+  size_t added;
+
+#ifdef _LIBC
+  __libc_lock_lock (lock);
+#endif
+
+  if (locale_alias_path == NULL)
+    locale_alias_path = LOCALE_ALIAS_PATH;
+
+  do
+    {
+      struct alias_map item;
+
+      item.alias = name;
+
+      if (nmap > 0)
+       retval = (struct alias_map *) bsearch (&item, map, nmap,
+                                              sizeof (struct alias_map),
+                                              (int (*) (const void *,
+                                                        const void *)
+                                               ) alias_compare);
+      else
+       retval = NULL;
+
+      /* We really found an alias.  Return the value.  */
+      if (retval != NULL)
+       {
+         result = retval->value;
+         break;
+       }
+
+      /* Perhaps we can find another alias file.  */
+      added = 0;
+      while (added == 0 && locale_alias_path[0] != '\0')
+       {
+         const char *start;
+
+         while (locale_alias_path[0] == PATH_SEPARATOR)
+           ++locale_alias_path;
+         start = locale_alias_path;
+
+         while (locale_alias_path[0] != '\0'
+                && locale_alias_path[0] != PATH_SEPARATOR)
+           ++locale_alias_path;
+
+         if (start < locale_alias_path)
+           added = read_alias_file (start, locale_alias_path - start);
+       }
+    }
+  while (added != 0);
+
+#ifdef _LIBC
+  __libc_lock_unlock (lock);
+#endif
+
+  return result;
+}
+
+
+static size_t
+internal_function
+read_alias_file (const char *fname, int fname_len)
+{
+  FILE *fp;
+  char *full_fname;
+  size_t added;
+  static const char aliasfile[] = "/locale.alias";
+
+  full_fname = (char *) alloca (fname_len + sizeof aliasfile);
+#ifdef HAVE_MEMPCPY
+  mempcpy (mempcpy (full_fname, fname, fname_len),
+          aliasfile, sizeof aliasfile);
+#else
+  memcpy (full_fname, fname, fname_len);
+  memcpy (&full_fname[fname_len], aliasfile, sizeof aliasfile);
+#endif
+
+  fp = fopen (relocate (full_fname), "r");
+  freea (full_fname);
+  if (fp == NULL)
+    return 0;
+
+#ifdef HAVE___FSETLOCKING
+  /* No threads present.  */
+  __fsetlocking (fp, FSETLOCKING_BYCALLER);
+#endif
+
+  added = 0;
+  while (!FEOF (fp))
+    {
+      /* It is a reasonable approach to use a fix buffer here because
+        a) we are only interested in the first two fields
+        b) these fields must be usable as file names and so must not
+           be that long
+        We avoid a multi-kilobyte buffer here since this would use up
+        stack space which we might not have if the program ran out of
+        memory.  */
+      char buf[400];
+      char *alias;
+      char *value;
+      char *cp;
+
+      if (FGETS (buf, sizeof buf, fp) == NULL)
+       /* EOF reached.  */
+       break;
+
+      cp = buf;
+      /* Ignore leading white space.  */
+      while (isspace ((unsigned char) cp[0]))
+       ++cp;
+
+      /* A leading '#' signals a comment line.  */
+      if (cp[0] != '\0' && cp[0] != '#')
+       {
+         alias = cp++;
+         while (cp[0] != '\0' && !isspace ((unsigned char) cp[0]))
+           ++cp;
+         /* Terminate alias name.  */
+         if (cp[0] != '\0')
+           *cp++ = '\0';
+
+         /* Now look for the beginning of the value.  */
+         while (isspace ((unsigned char) cp[0]))
+           ++cp;
+
+         if (cp[0] != '\0')
+           {
+             size_t alias_len;
+             size_t value_len;
+
+             value = cp++;
+             while (cp[0] != '\0' && !isspace ((unsigned char) cp[0]))
+               ++cp;
+             /* Terminate value.  */
+             if (cp[0] == '\n')
+               {
+                 /* This has to be done to make the following test
+                    for the end of line possible.  We are looking for
+                    the terminating '\n' which do not overwrite here.  */
+                 *cp++ = '\0';
+                 *cp = '\n';
+               }
+             else if (cp[0] != '\0')
+               *cp++ = '\0';
+
+             if (nmap >= maxmap)
+               if (__builtin_expect (extend_alias_table (), 0))
+                 return added;
+
+             alias_len = strlen (alias) + 1;
+             value_len = strlen (value) + 1;
+
+             if (string_space_act + alias_len + value_len > string_space_max)
+               {
+                 /* Increase size of memory pool.  */
+                 size_t new_size = (string_space_max
+                                    + (alias_len + value_len > 1024
+                                       ? alias_len + value_len : 1024));
+                 char *new_pool = (char *) realloc (string_space, new_size);
+                 if (new_pool == NULL)
+                   return added;
+
+                 if (__builtin_expect (string_space != new_pool, 0))
+                   {
+                     size_t i;
+
+                     for (i = 0; i < nmap; i++)
+                       {
+                         map[i].alias += new_pool - string_space;
+                         map[i].value += new_pool - string_space;
+                       }
+                   }
+
+                 string_space = new_pool;
+                 string_space_max = new_size;
+               }
+
+             map[nmap].alias = memcpy (&string_space[string_space_act],
+                                       alias, alias_len);
+             string_space_act += alias_len;
+
+             map[nmap].value = memcpy (&string_space[string_space_act],
+                                       value, value_len);
+             string_space_act += value_len;
+
+             ++nmap;
+             ++added;
+           }
+       }
+
+      /* Possibly not the whole line fits into the buffer.  Ignore
+        the rest of the line.  */
+      while (strchr (buf, '\n') == NULL)
+       if (FGETS (buf, sizeof buf, fp) == NULL)
+         /* Make sure the inner loop will be left.  The outer loop
+            will exit at the `feof' test.  */
+         break;
+    }
+
+  /* Should we test for ferror()?  I think we have to silently ignore
+     errors.  --drepper  */
+  fclose (fp);
+
+  if (added > 0)
+    qsort (map, nmap, sizeof (struct alias_map),
+          (int (*) (const void *, const void *)) alias_compare);
+
+  return added;
+}
+
+
+static int
+extend_alias_table ()
+{
+  size_t new_size;
+  struct alias_map *new_map;
+
+  new_size = maxmap == 0 ? 100 : 2 * maxmap;
+  new_map = (struct alias_map *) realloc (map, (new_size
+                                               * sizeof (struct alias_map)));
+  if (new_map == NULL)
+    /* Simply don't extend: we don't have any more core.  */
+    return -1;
+
+  map = new_map;
+  maxmap = new_size;
+  return 0;
+}
+
+
+static int
+alias_compare (const struct alias_map *map1, const struct alias_map *map2)
+{
+#if defined _LIBC || defined HAVE_STRCASECMP
+  return strcasecmp (map1->alias, map2->alias);
+#else
+  const unsigned char *p1 = (const unsigned char *) map1->alias;
+  const unsigned char *p2 = (const unsigned char *) map2->alias;
+  unsigned char c1, c2;
+
+  if (p1 == p2)
+    return 0;
+
+  do
+    {
+      /* I know this seems to be odd but the tolower() function in
+        some systems libc cannot handle nonalpha characters.  */
+      c1 = isupper (*p1) ? tolower (*p1) : *p1;
+      c2 = isupper (*p2) ? tolower (*p2) : *p2;
+      if (c1 == '\0')
+       break;
+      ++p1;
+      ++p2;
+    }
+  while (c1 == c2);
+
+  return c1 - c2;
+#endif
+}
diff --git a/intl/localename.c b/intl/localename.c
new file mode 100644 (file)
index 0000000..323c732
--- /dev/null
@@ -0,0 +1,1500 @@
+/* Determine the current selected locale.
+   Copyright (C) 1995-1999, 2000-2005 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+/* Written by Ulrich Drepper <drepper@gnu.org>, 1995.  */
+/* Win32 code written by Tor Lillqvist <tml@iki.fi>.  */
+/* MacOS X code written by Bruno Haible <bruno@clisp.org>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <locale.h>
+
+#if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
+# include <string.h>
+# include <CFString.h>
+# if HAVE_CFLOCALECOPYCURRENT
+#  include <CFLocale.h>
+# elif HAVE_CFPREFERENCESCOPYAPPVALUE
+#  include <CFPreferences.h>
+# endif
+#endif
+
+#if defined _WIN32 || defined __WIN32__
+# undef WIN32   /* avoid warning on mingw32 */
+# define WIN32
+#endif
+
+#ifdef WIN32
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+/* List of language codes, sorted by value:
+   0x01 LANG_ARABIC
+   0x02 LANG_BULGARIAN
+   0x03 LANG_CATALAN
+   0x04 LANG_CHINESE
+   0x05 LANG_CZECH
+   0x06 LANG_DANISH
+   0x07 LANG_GERMAN
+   0x08 LANG_GREEK
+   0x09 LANG_ENGLISH
+   0x0a LANG_SPANISH
+   0x0b LANG_FINNISH
+   0x0c LANG_FRENCH
+   0x0d LANG_HEBREW
+   0x0e LANG_HUNGARIAN
+   0x0f LANG_ICELANDIC
+   0x10 LANG_ITALIAN
+   0x11 LANG_JAPANESE
+   0x12 LANG_KOREAN
+   0x13 LANG_DUTCH
+   0x14 LANG_NORWEGIAN
+   0x15 LANG_POLISH
+   0x16 LANG_PORTUGUESE
+   0x17 LANG_RHAETO_ROMANCE
+   0x18 LANG_ROMANIAN
+   0x19 LANG_RUSSIAN
+   0x1a LANG_CROATIAN == LANG_SERBIAN
+   0x1b LANG_SLOVAK
+   0x1c LANG_ALBANIAN
+   0x1d LANG_SWEDISH
+   0x1e LANG_THAI
+   0x1f LANG_TURKISH
+   0x20 LANG_URDU
+   0x21 LANG_INDONESIAN
+   0x22 LANG_UKRAINIAN
+   0x23 LANG_BELARUSIAN
+   0x24 LANG_SLOVENIAN
+   0x25 LANG_ESTONIAN
+   0x26 LANG_LATVIAN
+   0x27 LANG_LITHUANIAN
+   0x28 LANG_TAJIK
+   0x29 LANG_FARSI
+   0x2a LANG_VIETNAMESE
+   0x2b LANG_ARMENIAN
+   0x2c LANG_AZERI
+   0x2d LANG_BASQUE
+   0x2e LANG_SORBIAN
+   0x2f LANG_MACEDONIAN
+   0x30 LANG_SUTU
+   0x31 LANG_TSONGA
+   0x32 LANG_TSWANA
+   0x33 LANG_VENDA
+   0x34 LANG_XHOSA
+   0x35 LANG_ZULU
+   0x36 LANG_AFRIKAANS
+   0x37 LANG_GEORGIAN
+   0x38 LANG_FAEROESE
+   0x39 LANG_HINDI
+   0x3a LANG_MALTESE
+   0x3b LANG_SAAMI
+   0x3c LANG_GAELIC
+   0x3d LANG_YIDDISH
+   0x3e LANG_MALAY
+   0x3f LANG_KAZAK
+   0x40 LANG_KYRGYZ
+   0x41 LANG_SWAHILI
+   0x42 LANG_TURKMEN
+   0x43 LANG_UZBEK
+   0x44 LANG_TATAR
+   0x45 LANG_BENGALI
+   0x46 LANG_PUNJABI
+   0x47 LANG_GUJARATI
+   0x48 LANG_ORIYA
+   0x49 LANG_TAMIL
+   0x4a LANG_TELUGU
+   0x4b LANG_KANNADA
+   0x4c LANG_MALAYALAM
+   0x4d LANG_ASSAMESE
+   0x4e LANG_MARATHI
+   0x4f LANG_SANSKRIT
+   0x50 LANG_MONGOLIAN
+   0x51 LANG_TIBETAN
+   0x52 LANG_WELSH
+   0x53 LANG_CAMBODIAN
+   0x54 LANG_LAO
+   0x55 LANG_BURMESE
+   0x56 LANG_GALICIAN
+   0x57 LANG_KONKANI
+   0x58 LANG_MANIPURI
+   0x59 LANG_SINDHI
+   0x5a LANG_SYRIAC
+   0x5b LANG_SINHALESE
+   0x5c LANG_CHEROKEE
+   0x5d LANG_INUKTITUT
+   0x5e LANG_AMHARIC
+   0x5f LANG_TAMAZIGHT
+   0x60 LANG_KASHMIRI
+   0x61 LANG_NEPALI
+   0x62 LANG_FRISIAN
+   0x63 LANG_PASHTO
+   0x64 LANG_TAGALOG
+   0x65 LANG_DIVEHI
+   0x66 LANG_EDO
+   0x67 LANG_FULFULDE
+   0x68 LANG_HAUSA
+   0x69 LANG_IBIBIO
+   0x6a LANG_YORUBA
+   0x70 LANG_IGBO
+   0x71 LANG_KANURI
+   0x72 LANG_OROMO
+   0x73 LANG_TIGRINYA
+   0x74 LANG_GUARANI
+   0x75 LANG_HAWAIIAN
+   0x76 LANG_LATIN
+   0x77 LANG_SOMALI
+   0x78 LANG_YI
+   0x79 LANG_PAPIAMENTU
+*/
+/* Mingw headers don't have latest language and sublanguage codes.  */
+# ifndef LANG_AFRIKAANS
+# define LANG_AFRIKAANS 0x36
+# endif
+# ifndef LANG_ALBANIAN
+# define LANG_ALBANIAN 0x1c
+# endif
+# ifndef LANG_AMHARIC
+# define LANG_AMHARIC 0x5e
+# endif
+# ifndef LANG_ARABIC
+# define LANG_ARABIC 0x01
+# endif
+# ifndef LANG_ARMENIAN
+# define LANG_ARMENIAN 0x2b
+# endif
+# ifndef LANG_ASSAMESE
+# define LANG_ASSAMESE 0x4d
+# endif
+# ifndef LANG_AZERI
+# define LANG_AZERI 0x2c
+# endif
+# ifndef LANG_BASQUE
+# define LANG_BASQUE 0x2d
+# endif
+# ifndef LANG_BELARUSIAN
+# define LANG_BELARUSIAN 0x23
+# endif
+# ifndef LANG_BENGALI
+# define LANG_BENGALI 0x45
+# endif
+# ifndef LANG_BURMESE
+# define LANG_BURMESE 0x55
+# endif
+# ifndef LANG_CAMBODIAN
+# define LANG_CAMBODIAN 0x53
+# endif
+# ifndef LANG_CATALAN
+# define LANG_CATALAN 0x03
+# endif
+# ifndef LANG_CHEROKEE
+# define LANG_CHEROKEE 0x5c
+# endif
+# ifndef LANG_DIVEHI
+# define LANG_DIVEHI 0x65
+# endif
+# ifndef LANG_EDO
+# define LANG_EDO 0x66
+# endif
+# ifndef LANG_ESTONIAN
+# define LANG_ESTONIAN 0x25
+# endif
+# ifndef LANG_FAEROESE
+# define LANG_FAEROESE 0x38
+# endif
+# ifndef LANG_FARSI
+# define LANG_FARSI 0x29
+# endif
+# ifndef LANG_FRISIAN
+# define LANG_FRISIAN 0x62
+# endif
+# ifndef LANG_FULFULDE
+# define LANG_FULFULDE 0x67
+# endif
+# ifndef LANG_GAELIC
+# define LANG_GAELIC 0x3c
+# endif
+# ifndef LANG_GALICIAN
+# define LANG_GALICIAN 0x56
+# endif
+# ifndef LANG_GEORGIAN
+# define LANG_GEORGIAN 0x37
+# endif
+# ifndef LANG_GUARANI
+# define LANG_GUARANI 0x74
+# endif
+# ifndef LANG_GUJARATI
+# define LANG_GUJARATI 0x47
+# endif
+# ifndef LANG_HAUSA
+# define LANG_HAUSA 0x68
+# endif
+# ifndef LANG_HAWAIIAN
+# define LANG_HAWAIIAN 0x75
+# endif
+# ifndef LANG_HEBREW
+# define LANG_HEBREW 0x0d
+# endif
+# ifndef LANG_HINDI
+# define LANG_HINDI 0x39
+# endif
+# ifndef LANG_IBIBIO
+# define LANG_IBIBIO 0x69
+# endif
+# ifndef LANG_IGBO
+# define LANG_IGBO 0x70
+# endif
+# ifndef LANG_INDONESIAN
+# define LANG_INDONESIAN 0x21
+# endif
+# ifndef LANG_INUKTITUT
+# define LANG_INUKTITUT 0x5d
+# endif
+# ifndef LANG_KANNADA
+# define LANG_KANNADA 0x4b
+# endif
+# ifndef LANG_KANURI
+# define LANG_KANURI 0x71
+# endif
+# ifndef LANG_KASHMIRI
+# define LANG_KASHMIRI 0x60
+# endif
+# ifndef LANG_KAZAK
+# define LANG_KAZAK 0x3f
+# endif
+# ifndef LANG_KONKANI
+# define LANG_KONKANI 0x57
+# endif
+# ifndef LANG_KYRGYZ
+# define LANG_KYRGYZ 0x40
+# endif
+# ifndef LANG_LAO
+# define LANG_LAO 0x54
+# endif
+# ifndef LANG_LATIN
+# define LANG_LATIN 0x76
+# endif
+# ifndef LANG_LATVIAN
+# define LANG_LATVIAN 0x26
+# endif
+# ifndef LANG_LITHUANIAN
+# define LANG_LITHUANIAN 0x27
+# endif
+# ifndef LANG_MACEDONIAN
+# define LANG_MACEDONIAN 0x2f
+# endif
+# ifndef LANG_MALAY
+# define LANG_MALAY 0x3e
+# endif
+# ifndef LANG_MALAYALAM
+# define LANG_MALAYALAM 0x4c
+# endif
+# ifndef LANG_MALTESE
+# define LANG_MALTESE 0x3a
+# endif
+# ifndef LANG_MANIPURI
+# define LANG_MANIPURI 0x58
+# endif
+# ifndef LANG_MARATHI
+# define LANG_MARATHI 0x4e
+# endif
+# ifndef LANG_MONGOLIAN
+# define LANG_MONGOLIAN 0x50
+# endif
+# ifndef LANG_NEPALI
+# define LANG_NEPALI 0x61
+# endif
+# ifndef LANG_ORIYA
+# define LANG_ORIYA 0x48
+# endif
+# ifndef LANG_OROMO
+# define LANG_OROMO 0x72
+# endif
+# ifndef LANG_PAPIAMENTU
+# define LANG_PAPIAMENTU 0x79
+# endif
+# ifndef LANG_PASHTO
+# define LANG_PASHTO 0x63
+# endif
+# ifndef LANG_PUNJABI
+# define LANG_PUNJABI 0x46
+# endif
+# ifndef LANG_RHAETO_ROMANCE
+# define LANG_RHAETO_ROMANCE 0x17
+# endif
+# ifndef LANG_SAAMI
+# define LANG_SAAMI 0x3b
+# endif
+# ifndef LANG_SANSKRIT
+# define LANG_SANSKRIT 0x4f
+# endif
+# ifndef LANG_SERBIAN
+# define LANG_SERBIAN 0x1a
+# endif
+# ifndef LANG_SINDHI
+# define LANG_SINDHI 0x59
+# endif
+# ifndef LANG_SINHALESE
+# define LANG_SINHALESE 0x5b
+# endif
+# ifndef LANG_SLOVAK
+# define LANG_SLOVAK 0x1b
+# endif
+# ifndef LANG_SOMALI
+# define LANG_SOMALI 0x77
+# endif
+# ifndef LANG_SORBIAN
+# define LANG_SORBIAN 0x2e
+# endif
+# ifndef LANG_SUTU
+# define LANG_SUTU 0x30
+# endif
+# ifndef LANG_SWAHILI
+# define LANG_SWAHILI 0x41
+# endif
+# ifndef LANG_SYRIAC
+# define LANG_SYRIAC 0x5a
+# endif
+# ifndef LANG_TAGALOG
+# define LANG_TAGALOG 0x64
+# endif
+# ifndef LANG_TAJIK
+# define LANG_TAJIK 0x28
+# endif
+# ifndef LANG_TAMAZIGHT
+# define LANG_TAMAZIGHT 0x5f
+# endif
+# ifndef LANG_TAMIL
+# define LANG_TAMIL 0x49
+# endif
+# ifndef LANG_TATAR
+# define LANG_TATAR 0x44
+# endif
+# ifndef LANG_TELUGU
+# define LANG_TELUGU 0x4a
+# endif
+# ifndef LANG_THAI
+# define LANG_THAI 0x1e
+# endif
+# ifndef LANG_TIBETAN
+# define LANG_TIBETAN 0x51
+# endif
+# ifndef LANG_TIGRINYA
+# define LANG_TIGRINYA 0x73
+# endif
+# ifndef LANG_TSONGA
+# define LANG_TSONGA 0x31
+# endif
+# ifndef LANG_TSWANA
+# define LANG_TSWANA 0x32
+# endif
+# ifndef LANG_TURKMEN
+# define LANG_TURKMEN 0x42
+# endif
+# ifndef LANG_UKRAINIAN
+# define LANG_UKRAINIAN 0x22
+# endif
+# ifndef LANG_URDU
+# define LANG_URDU 0x20
+# endif
+# ifndef LANG_UZBEK
+# define LANG_UZBEK 0x43
+# endif
+# ifndef LANG_VENDA
+# define LANG_VENDA 0x33
+# endif
+# ifndef LANG_VIETNAMESE
+# define LANG_VIETNAMESE 0x2a
+# endif
+# ifndef LANG_WELSH
+# define LANG_WELSH 0x52
+# endif
+# ifndef LANG_XHOSA
+# define LANG_XHOSA 0x34
+# endif
+# ifndef LANG_YI
+# define LANG_YI 0x78
+# endif
+# ifndef LANG_YIDDISH
+# define LANG_YIDDISH 0x3d
+# endif
+# ifndef LANG_YORUBA
+# define LANG_YORUBA 0x6a
+# endif
+# ifndef LANG_ZULU
+# define LANG_ZULU 0x35
+# endif
+# ifndef SUBLANG_ARABIC_SAUDI_ARABIA
+# define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
+# endif
+# ifndef SUBLANG_ARABIC_IRAQ
+# define SUBLANG_ARABIC_IRAQ 0x02
+# endif
+# ifndef SUBLANG_ARABIC_EGYPT
+# define SUBLANG_ARABIC_EGYPT 0x03
+# endif
+# ifndef SUBLANG_ARABIC_LIBYA
+# define SUBLANG_ARABIC_LIBYA 0x04
+# endif
+# ifndef SUBLANG_ARABIC_ALGERIA
+# define SUBLANG_ARABIC_ALGERIA 0x05
+# endif
+# ifndef SUBLANG_ARABIC_MOROCCO
+# define SUBLANG_ARABIC_MOROCCO 0x06
+# endif
+# ifndef SUBLANG_ARABIC_TUNISIA
+# define SUBLANG_ARABIC_TUNISIA 0x07
+# endif
+# ifndef SUBLANG_ARABIC_OMAN
+# define SUBLANG_ARABIC_OMAN 0x08
+# endif
+# ifndef SUBLANG_ARABIC_YEMEN
+# define SUBLANG_ARABIC_YEMEN 0x09
+# endif
+# ifndef SUBLANG_ARABIC_SYRIA
+# define SUBLANG_ARABIC_SYRIA 0x0a
+# endif
+# ifndef SUBLANG_ARABIC_JORDAN
+# define SUBLANG_ARABIC_JORDAN 0x0b
+# endif
+# ifndef SUBLANG_ARABIC_LEBANON
+# define SUBLANG_ARABIC_LEBANON 0x0c
+# endif
+# ifndef SUBLANG_ARABIC_KUWAIT
+# define SUBLANG_ARABIC_KUWAIT 0x0d
+# endif
+# ifndef SUBLANG_ARABIC_UAE
+# define SUBLANG_ARABIC_UAE 0x0e
+# endif
+# ifndef SUBLANG_ARABIC_BAHRAIN
+# define SUBLANG_ARABIC_BAHRAIN 0x0f
+# endif
+# ifndef SUBLANG_ARABIC_QATAR
+# define SUBLANG_ARABIC_QATAR 0x10
+# endif
+# ifndef SUBLANG_AZERI_LATIN
+# define SUBLANG_AZERI_LATIN 0x01
+# endif
+# ifndef SUBLANG_AZERI_CYRILLIC
+# define SUBLANG_AZERI_CYRILLIC 0x02
+# endif
+# ifndef SUBLANG_BENGALI_INDIA
+# define SUBLANG_BENGALI_INDIA 0x00
+# endif
+# ifndef SUBLANG_BENGALI_BANGLADESH
+# define SUBLANG_BENGALI_BANGLADESH 0x01
+# endif
+# ifndef SUBLANG_CHINESE_MACAU
+# define SUBLANG_CHINESE_MACAU 0x05
+# endif
+# ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
+# define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
+# endif
+# ifndef SUBLANG_ENGLISH_JAMAICA
+# define SUBLANG_ENGLISH_JAMAICA 0x08
+# endif
+# ifndef SUBLANG_ENGLISH_CARIBBEAN
+# define SUBLANG_ENGLISH_CARIBBEAN 0x09
+# endif
+# ifndef SUBLANG_ENGLISH_BELIZE
+# define SUBLANG_ENGLISH_BELIZE 0x0a
+# endif
+# ifndef SUBLANG_ENGLISH_TRINIDAD
+# define SUBLANG_ENGLISH_TRINIDAD 0x0b
+# endif
+# ifndef SUBLANG_ENGLISH_ZIMBABWE
+# define SUBLANG_ENGLISH_ZIMBABWE 0x0c
+# endif
+# ifndef SUBLANG_ENGLISH_PHILIPPINES
+# define SUBLANG_ENGLISH_PHILIPPINES 0x0d
+# endif
+# ifndef SUBLANG_ENGLISH_INDONESIA
+# define SUBLANG_ENGLISH_INDONESIA 0x0e
+# endif
+# ifndef SUBLANG_ENGLISH_HONGKONG
+# define SUBLANG_ENGLISH_HONGKONG 0x0f
+# endif
+# ifndef SUBLANG_ENGLISH_INDIA
+# define SUBLANG_ENGLISH_INDIA 0x10
+# endif
+# ifndef SUBLANG_ENGLISH_MALAYSIA
+# define SUBLANG_ENGLISH_MALAYSIA 0x11
+# endif
+# ifndef SUBLANG_ENGLISH_SINGAPORE
+# define SUBLANG_ENGLISH_SINGAPORE 0x12
+# endif
+# ifndef SUBLANG_FRENCH_LUXEMBOURG
+# define SUBLANG_FRENCH_LUXEMBOURG 0x05
+# endif
+# ifndef SUBLANG_FRENCH_MONACO
+# define SUBLANG_FRENCH_MONACO 0x06
+# endif
+# ifndef SUBLANG_FRENCH_WESTINDIES
+# define SUBLANG_FRENCH_WESTINDIES 0x07
+# endif
+# ifndef SUBLANG_FRENCH_REUNION
+# define SUBLANG_FRENCH_REUNION 0x08
+# endif
+# ifndef SUBLANG_FRENCH_CONGO
+# define SUBLANG_FRENCH_CONGO 0x09
+# endif
+# ifndef SUBLANG_FRENCH_SENEGAL
+# define SUBLANG_FRENCH_SENEGAL 0x0a
+# endif
+# ifndef SUBLANG_FRENCH_CAMEROON
+# define SUBLANG_FRENCH_CAMEROON 0x0b
+# endif
+# ifndef SUBLANG_FRENCH_COTEDIVOIRE
+# define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
+# endif
+# ifndef SUBLANG_FRENCH_MALI
+# define SUBLANG_FRENCH_MALI 0x0d
+# endif
+# ifndef SUBLANG_FRENCH_MOROCCO
+# define SUBLANG_FRENCH_MOROCCO 0x0e
+# endif
+# ifndef SUBLANG_FRENCH_HAITI
+# define SUBLANG_FRENCH_HAITI 0x0f
+# endif
+# ifndef SUBLANG_GERMAN_LUXEMBOURG
+# define SUBLANG_GERMAN_LUXEMBOURG 0x04
+# endif
+# ifndef SUBLANG_GERMAN_LIECHTENSTEIN
+# define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
+# endif
+# ifndef SUBLANG_KASHMIRI_INDIA
+# define SUBLANG_KASHMIRI_INDIA 0x02
+# endif
+# ifndef SUBLANG_MALAY_MALAYSIA
+# define SUBLANG_MALAY_MALAYSIA 0x01
+# endif
+# ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
+# define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
+# endif
+# ifndef SUBLANG_NEPALI_INDIA
+# define SUBLANG_NEPALI_INDIA 0x02
+# endif
+# ifndef SUBLANG_PUNJABI_INDIA
+# define SUBLANG_PUNJABI_INDIA 0x00
+# endif
+# ifndef SUBLANG_PUNJABI_PAKISTAN
+# define SUBLANG_PUNJABI_PAKISTAN 0x01
+# endif
+# ifndef SUBLANG_ROMANIAN_ROMANIA
+# define SUBLANG_ROMANIAN_ROMANIA 0x00
+# endif
+# ifndef SUBLANG_ROMANIAN_MOLDOVA
+# define SUBLANG_ROMANIAN_MOLDOVA 0x01
+# endif
+# ifndef SUBLANG_SERBIAN_LATIN
+# define SUBLANG_SERBIAN_LATIN 0x02
+# endif
+# ifndef SUBLANG_SERBIAN_CYRILLIC
+# define SUBLANG_SERBIAN_CYRILLIC 0x03
+# endif
+# ifndef SUBLANG_SINDHI_INDIA
+# define SUBLANG_SINDHI_INDIA 0x00
+# endif
+# ifndef SUBLANG_SINDHI_PAKISTAN
+# define SUBLANG_SINDHI_PAKISTAN 0x01
+# endif
+# ifndef SUBLANG_SPANISH_GUATEMALA
+# define SUBLANG_SPANISH_GUATEMALA 0x04
+# endif
+# ifndef SUBLANG_SPANISH_COSTA_RICA
+# define SUBLANG_SPANISH_COSTA_RICA 0x05
+# endif
+# ifndef SUBLANG_SPANISH_PANAMA
+# define SUBLANG_SPANISH_PANAMA 0x06
+# endif
+# ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
+# define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
+# endif
+# ifndef SUBLANG_SPANISH_VENEZUELA
+# define SUBLANG_SPANISH_VENEZUELA 0x08
+# endif
+# ifndef SUBLANG_SPANISH_COLOMBIA
+# define SUBLANG_SPANISH_COLOMBIA 0x09
+# endif
+# ifndef SUBLANG_SPANISH_PERU
+# define SUBLANG_SPANISH_PERU 0x0a
+# endif
+# ifndef SUBLANG_SPANISH_ARGENTINA
+# define SUBLANG_SPANISH_ARGENTINA 0x0b
+# endif
+# ifndef SUBLANG_SPANISH_ECUADOR
+# define SUBLANG_SPANISH_ECUADOR 0x0c
+# endif
+# ifndef SUBLANG_SPANISH_CHILE
+# define SUBLANG_SPANISH_CHILE 0x0d
+# endif
+# ifndef SUBLANG_SPANISH_URUGUAY
+# define SUBLANG_SPANISH_URUGUAY 0x0e
+# endif
+# ifndef SUBLANG_SPANISH_PARAGUAY
+# define SUBLANG_SPANISH_PARAGUAY 0x0f
+# endif
+# ifndef SUBLANG_SPANISH_BOLIVIA
+# define SUBLANG_SPANISH_BOLIVIA 0x10
+# endif
+# ifndef SUBLANG_SPANISH_EL_SALVADOR
+# define SUBLANG_SPANISH_EL_SALVADOR 0x11
+# endif
+# ifndef SUBLANG_SPANISH_HONDURAS
+# define SUBLANG_SPANISH_HONDURAS 0x12
+# endif
+# ifndef SUBLANG_SPANISH_NICARAGUA
+# define SUBLANG_SPANISH_NICARAGUA 0x13
+# endif
+# ifndef SUBLANG_SPANISH_PUERTO_RICO
+# define SUBLANG_SPANISH_PUERTO_RICO 0x14
+# endif
+# ifndef SUBLANG_SWEDISH_FINLAND
+# define SUBLANG_SWEDISH_FINLAND 0x02
+# endif
+# ifndef SUBLANG_TAMAZIGHT_ARABIC
+# define SUBLANG_TAMAZIGHT_ARABIC 0x01
+# endif
+# ifndef SUBLANG_TAMAZIGHT_LATIN
+# define SUBLANG_TAMAZIGHT_LATIN 0x02
+# endif
+# ifndef SUBLANG_TIGRINYA_ETHIOPIA
+# define SUBLANG_TIGRINYA_ETHIOPIA 0x00
+# endif
+# ifndef SUBLANG_TIGRINYA_ERITREA
+# define SUBLANG_TIGRINYA_ERITREA 0x01
+# endif
+# ifndef SUBLANG_URDU_PAKISTAN
+# define SUBLANG_URDU_PAKISTAN 0x01
+# endif
+# ifndef SUBLANG_URDU_INDIA
+# define SUBLANG_URDU_INDIA 0x02
+# endif
+# ifndef SUBLANG_UZBEK_LATIN
+# define SUBLANG_UZBEK_LATIN 0x01
+# endif
+# ifndef SUBLANG_UZBEK_CYRILLIC
+# define SUBLANG_UZBEK_CYRILLIC 0x02
+# endif
+#endif
+
+# if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
+/* MacOS X 10.2 or newer */
+
+/* Canonicalize a MacOS X locale name to a Unix locale name.
+   NAME is a sufficiently large buffer.
+   On input, it contains the MacOS X locale name.
+   On output, it contains the Unix locale name.  */
+void
+_nl_locale_name_canonicalize (char *name)
+{
+  /* This conversion is based on a posting by
+     Deborah GoldSmith <goldsmit@apple.com> on 2005-03-08,
+     http://lists.apple.com/archives/carbon-dev/2005/Mar/msg00293.html */
+
+  /* Convert legacy (NeXTstep inherited) English names to Unix (ISO 639 and
+     ISO 3166) names.  Prior to MacOS X 10.3, there is no API for doing this.
+     Therefore we do it ourselves, using a table based on the results of the
+     MacOS X 10.3.8 function
+     CFLocaleCreateCanonicalLocaleIdentifierFromString().  */
+  typedef struct { const char legacy[21+1]; const char unixy[5+1]; }
+         legacy_entry;
+  static const legacy_entry legacy_table[] = {
+    { "Afrikaans",             "af" },
+    { "Albanian",              "sq" },
+    { "Amharic",               "am" },
+    { "Arabic",                "ar" },
+    { "Armenian",              "hy" },
+    { "Assamese",              "as" },
+    { "Aymara",                "ay" },
+    { "Azerbaijani",           "az" },
+    { "Basque",                "eu" },
+    { "Belarusian",            "be" },
+    { "Belorussian",           "be" },
+    { "Bengali",               "bn" },
+    { "Brazilian Portugese",   "pt_BR" },
+    { "Brazilian Portuguese",  "pt_BR" },
+    { "Breton",                "br" },
+    { "Bulgarian",             "bg" },
+    { "Burmese",               "my" },
+    { "Byelorussian",          "be" },
+    { "Catalan",               "ca" },
+    { "Chewa",                 "ny" },
+    { "Chichewa",              "ny" },
+    { "Chinese",               "zh" },
+    { "Chinese, Simplified",   "zh_CN" },
+    { "Chinese, Traditional",  "zh_TW" },
+    { "Chinese, Tradtional",   "zh_TW" },
+    { "Croatian",              "hr" },
+    { "Czech",                 "cs" },
+    { "Danish",                "da" },
+    { "Dutch",                 "nl" },
+    { "Dzongkha",              "dz" },
+    { "English",               "en" },
+    { "Esperanto",             "eo" },
+    { "Estonian",              "et" },
+    { "Faroese",               "fo" },
+    { "Farsi",                 "fa" },
+    { "Finnish",               "fi" },
+    { "Flemish",               "nl_BE" },
+    { "French",                "fr" },
+    { "Galician",              "gl" },
+    { "Gallegan",              "gl" },
+    { "Georgian",              "ka" },
+    { "German",                "de" },
+    { "Greek",                 "el" },
+    { "Greenlandic",           "kl" },
+    { "Guarani",               "gn" },
+    { "Gujarati",              "gu" },
+    { "Hawaiian",              "haw" }, /* Yes, "haw", not "cpe".  */
+    { "Hebrew",                "he" },
+    { "Hindi",                 "hi" },
+    { "Hungarian",             "hu" },
+    { "Icelandic",             "is" },
+    { "Indonesian",            "id" },
+    { "Inuktitut",             "iu" },
+    { "Irish",                 "ga" },
+    { "Italian",               "it" },
+    { "Japanese",              "ja" },
+    { "Javanese",              "jv" },
+    { "Kalaallisut",           "kl" },
+    { "Kannada",               "kn" },
+    { "Kashmiri",              "ks" },
+    { "Kazakh",                "kk" },
+    { "Khmer",                 "km" },
+    { "Kinyarwanda",           "rw" },
+    { "Kirghiz",               "ky" },
+    { "Korean",                "ko" },
+    { "Kurdish",               "ku" },
+    { "Latin",                 "la" },
+    { "Latvian",               "lv" },
+    { "Lithuanian",            "lt" },
+    { "Macedonian",            "mk" },
+    { "Malagasy",              "mg" },
+    { "Malay",                 "ms" },
+    { "Malayalam",             "ml" },
+    { "Maltese",               "mt" },
+    { "Manx",                  "gv" },
+    { "Marathi",               "mr" },
+    { "Moldavian",             "mo" },
+    { "Mongolian",             "mn" },
+    { "Nepali",                "ne" },
+    { "Norwegian",             "nb" }, /* Yes, "nb", not the obsolete "no".  */
+    { "Nyanja",                "ny" },
+    { "Nynorsk",               "nn" },
+    { "Oriya",                 "or" },
+    { "Oromo",                 "om" },
+    { "Panjabi",               "pa" },
+    { "Pashto",                "ps" },
+    { "Persian",               "fa" },
+    { "Polish",                "pl" },
+    { "Portuguese",            "pt" },
+    { "Portuguese, Brazilian", "pt_BR" },
+    { "Punjabi",               "pa" },
+    { "Pushto",                "ps" },
+    { "Quechua",               "qu" },
+    { "Romanian",              "ro" },
+    { "Ruanda",                "rw" },
+    { "Rundi",                 "rn" },
+    { "Russian",               "ru" },
+    { "Sami",                  "se_NO" }, /* Not just "se".  */
+    { "Sanskrit",              "sa" },
+    { "Scottish",              "gd" },
+    { "Serbian",               "sr" },
+    { "Simplified Chinese",    "zh_CN" },
+    { "Sindhi",                "sd" },
+    { "Sinhalese",             "si" },
+    { "Slovak",                "sk" },
+    { "Slovenian",             "sl" },
+    { "Somali",                "so" },
+    { "Spanish",               "es" },
+    { "Sundanese",             "su" },
+    { "Swahili",               "sw" },
+    { "Swedish",               "sv" },
+    { "Tagalog",               "tl" },
+    { "Tajik",                 "tg" },
+    { "Tajiki",                "tg" },
+    { "Tamil",                 "ta" },
+    { "Tatar",                 "tt" },
+    { "Telugu",                "te" },
+    { "Thai",                  "th" },
+    { "Tibetan",               "bo" },
+    { "Tigrinya",              "ti" },
+    { "Tongan",                "to" },
+    { "Traditional Chinese",   "zh_TW" },
+    { "Turkish",               "tr" },
+    { "Turkmen",               "tk" },
+    { "Uighur",                "ug" },
+    { "Ukrainian",             "uk" },
+    { "Urdu",                  "ur" },
+    { "Uzbek",                 "uz" },
+    { "Vietnamese",            "vi" },
+    { "Welsh",                 "cy" },
+    { "Yiddish",               "yi" }
+  };
+
+  /* Convert new-style locale names with language tags (ISO 639 and ISO 15924)
+     to Unix (ISO 639 and ISO 3166) names.  */
+  typedef struct { const char langtag[7+1]; const char unixy[12+1]; }
+         langtag_entry;
+  static const langtag_entry langtag_table[] = {
+    /* MacOS X has "az-Arab", "az-Cyrl", "az-Latn".
+       The default script for az on Unix is Latin.  */
+    { "az-Latn", "az" },
+    /* MacOS X has "ga-dots".  Does not yet exist on Unix.  */
+    { "ga-dots", "ga" },
+    /* MacOS X has "kk-Cyrl".  Does not yet exist on Unix.  */
+    /* MacOS X has "mn-Cyrl", "mn-Mong".
+       The default script for mn on Unix is Cyrillic.  */
+    { "mn-Cyrl", "mn" },
+    /* MacOS X has "ms-Arab", "ms-Latn".
+       The default script for ms on Unix is Latin.  */
+    { "ms-Latn", "ms" },
+    /* MacOS X has "tg-Cyrl".
+       The default script for tg on Unix is Cyrillic.  */
+    { "tg-Cyrl", "tg" },
+    /* MacOS X has "tk-Cyrl".  Does not yet exist on Unix.  */
+    /* MacOS X has "tt-Cyrl".
+       The default script for tt on Unix is Cyrillic.  */
+    { "tt-Cyrl", "tt" },
+    /* MacOS X has "zh-Hans", "zh-Hant".
+       Country codes are used to distinguish these on Unix.  */
+    { "zh-Hans", "zh_CN" },
+    { "zh-Hant", "zh_TW" }
+  };
+
+  /* Convert script names (ISO 15924) to Unix conventions.
+     See http://www.unicode.org/iso15924/iso15924-codes.html  */
+  typedef struct { const char script[4+1]; const char unixy[9+1]; }
+         script_entry;
+  static const script_entry script_table[] = {
+    { "Arab", "arabic" },
+    { "Cyrl", "cyrillic" },
+    { "Mong", "mongolian" }
+  };
+
+  /* Step 1: Convert using legacy_table.  */
+  if (name[0] >= 'A' && name[0] <= 'Z')
+    {
+      unsigned int i1, i2;
+      i1 = 0;
+      i2 = sizeof (legacy_table) / sizeof (legacy_entry);
+      while (i2 - i1 > 1)
+       {
+         /* At this point we know that if name occurs in legacy_table,
+            its index must be >= i1 and < i2.  */
+         unsigned int i = (i1 + i2) >> 1;
+         const legacy_entry *p = &legacy_table[i];
+         if (strcmp (name, p->legacy) < 0)
+           i2 = i;
+         else
+           i1 = i;
+       }
+      if (strcmp (name, legacy_table[i1].legacy) == 0)
+       {
+         strcpy (name, legacy_table[i1].unixy);
+         return;
+       }
+    }
+
+  /* Step 2: Convert using langtag_table and script_table.  */
+  if (strlen (name) == 7 && name[2] == '-')
+    {
+      unsigned int i1, i2;
+      i1 = 0;
+      i2 = sizeof (langtag_table) / sizeof (langtag_entry);
+      while (i2 - i1 > 1)
+       {
+         /* At this point we know that if name occurs in langtag_table,
+            its index must be >= i1 and < i2.  */
+         unsigned int i = (i1 + i2) >> 1;
+         const langtag_entry *p = &langtag_table[i];
+         if (strcmp (name, p->langtag) < 0)
+           i2 = i;
+         else
+           i1 = i;
+       }
+      if (strcmp (name, langtag_table[i1].langtag) == 0)
+       {
+         strcpy (name, langtag_table[i1].unixy);
+         return;
+       }
+
+      i1 = 0;
+      i2 = sizeof (script_table) / sizeof (script_entry);
+      while (i2 - i1 > 1)
+       {
+         /* At this point we know that if (name + 3) occurs in script_table,
+            its index must be >= i1 and < i2.  */
+         unsigned int i = (i1 + i2) >> 1;
+         const script_entry *p = &script_table[i];
+         if (strcmp (name + 3, p->script) < 0)
+           i2 = i;
+         else
+           i1 = i;
+       }
+      if (strcmp (name + 3, script_table[i1].script) == 0)
+       {
+         name[2] = '@';
+         strcpy (name + 3, script_table[i1].unixy);
+         return;
+       }
+    }
+
+  /* Step 3: Convert new-style dash to Unix underscore. */
+  {
+    char *p;
+    for (p = name; *p != '\0'; p++)
+      if (*p == '-')
+       *p = '_';
+  }
+}
+
+#endif
+
+/* XPG3 defines the result of 'setlocale (category, NULL)' as:
+   "Directs 'setlocale()' to query 'category' and return the current
+    setting of 'local'."
+   However it does not specify the exact format.  Neither do SUSV2 and
+   ISO C 99.  So we can use this feature only on selected systems (e.g.
+   those using GNU C Library).  */
+#if defined _LIBC || (defined __GNU_LIBRARY__ && __GNU_LIBRARY__ >= 2)
+# define HAVE_LOCALE_NULL
+#endif
+
+/* Determine the current locale's name, and canonicalize it into XPG syntax
+     language[_territory[.codeset]][@modifier]
+   The codeset part in the result is not reliable; the locale_charset()
+   should be used for codeset information instead.
+   The result must not be freed; it is statically allocated.  */
+
+const char *
+_nl_locale_name_posix (int category, const char *categoryname)
+{
+  /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
+     On some systems this can be done by the 'setlocale' function itself.  */
+#if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
+  return setlocale (category, NULL);
+#else
+  const char *retval;
+
+  /* Setting of LC_ALL overrides all other.  */
+  retval = getenv ("LC_ALL");
+  if (retval != NULL && retval[0] != '\0')
+    return retval;
+  /* Next comes the name of the desired category.  */
+  retval = getenv (categoryname);
+  if (retval != NULL && retval[0] != '\0')
+    return retval;
+  /* Last possibility is the LANG environment variable.  */
+  retval = getenv ("LANG");
+  if (retval != NULL && retval[0] != '\0')
+    return retval;
+
+  return NULL;
+#endif
+}
+
+const char *
+_nl_locale_name_default (void)
+{
+  /* POSIX:2001 says:
+     "All implementations shall define a locale as the default locale, to be
+      invoked when no environment variables are set, or set to the empty
+      string.  This default locale can be the POSIX locale or any other
+      implementation-defined locale.  Some implementations may provide
+      facilities for local installation administrators to set the default
+      locale, customizing it for each location.  POSIX:2001 does not require
+      such a facility.  */
+
+#if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined(WIN32))
+
+  /* The system does not have a way of setting the locale, other than the
+     POSIX specified environment variables.  We use C as default locale.  */
+  return "C";
+
+#else
+
+  /* Return an XPG style locale name language[_territory][@modifier].
+     Don't even bother determining the codeset; it's not useful in this
+     context, because message catalogs are not specific to a single
+     codeset.  */
+
+# if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
+  /* MacOS X 10.2 or newer */
+  {
+    /* Cache the locale name, since CoreFoundation calls are expensive.  */
+    static const char *cached_localename;
+
+    if (cached_localename == NULL)
+      {
+       char namebuf[256];
+#  if HAVE_CFLOCALECOPYCURRENT /* MacOS X 10.3 or newer */
+       CFLocaleRef locale = CFLocaleCopyCurrent ();
+       CFStringRef name = CFLocaleGetIdentifier (locale);
+
+       if (CFStringGetCString (name, namebuf, sizeof(namebuf),
+                               kCFStringEncodingASCII))
+         {
+           _nl_locale_name_canonicalize (namebuf);
+           cached_localename = strdup (namebuf);
+         }
+       CFRelease (locale);
+#  elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */
+       CFTypeRef value =
+         CFPreferencesCopyAppValue (CFSTR ("AppleLocale"),
+                                    kCFPreferencesCurrentApplication);
+       if (value != NULL
+           && CFGetTypeID (value) == CFStringGetTypeID ()
+           && CFStringGetCString ((CFStringRef)value, namebuf, sizeof(namebuf),
+                                  kCFStringEncodingASCII))
+         {
+           _nl_locale_name_canonicalize (namebuf);
+           cached_localename = strdup (namebuf);
+         }
+#  endif
+       if (cached_localename == NULL)
+         cached_localename = "C";
+      }
+    return cached_localename;
+  }
+
+# endif
+
+# if defined(WIN32) /* WIN32 */
+  {
+    LCID lcid;
+    LANGID langid;
+    int primary, sub;
+
+    /* Use native Win32 API locale ID.  */
+    lcid = GetThreadLocale ();
+
+    /* Strip off the sorting rules, keep only the language part.  */
+    langid = LANGIDFROMLCID (lcid);
+
+    /* Split into language and territory part.  */
+    primary = PRIMARYLANGID (langid);
+    sub = SUBLANGID (langid);
+
+    /* Dispatch on language.
+       See also http://www.unicode.org/unicode/onlinedat/languages.html .
+       For details about languages, see http://www.ethnologue.com/ .  */
+    switch (primary)
+      {
+      case LANG_AFRIKAANS: return "af_ZA";
+      case LANG_ALBANIAN: return "sq_AL";
+      case LANG_AMHARIC: return "am_ET";
+      case LANG_ARABIC:
+       switch (sub)
+         {
+         case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA";
+         case SUBLANG_ARABIC_IRAQ: return "ar_IQ";
+         case SUBLANG_ARABIC_EGYPT: return "ar_EG";
+         case SUBLANG_ARABIC_LIBYA: return "ar_LY";
+         case SUBLANG_ARABIC_ALGERIA: return "ar_DZ";
+         case SUBLANG_ARABIC_MOROCCO: return "ar_MA";
+         case SUBLANG_ARABIC_TUNISIA: return "ar_TN";
+         case SUBLANG_ARABIC_OMAN: return "ar_OM";
+         case SUBLANG_ARABIC_YEMEN: return "ar_YE";
+         case SUBLANG_ARABIC_SYRIA: return "ar_SY";
+         case SUBLANG_ARABIC_JORDAN: return "ar_JO";
+         case SUBLANG_ARABIC_LEBANON: return "ar_LB";
+         case SUBLANG_ARABIC_KUWAIT: return "ar_KW";
+         case SUBLANG_ARABIC_UAE: return "ar_AE";
+         case SUBLANG_ARABIC_BAHRAIN: return "ar_BH";
+         case SUBLANG_ARABIC_QATAR: return "ar_QA";
+         }
+       return "ar";
+      case LANG_ARMENIAN: return "hy_AM";
+      case LANG_ASSAMESE: return "as_IN";
+      case LANG_AZERI:
+       switch (sub)
+         {
+         /* FIXME: Adjust this when Azerbaijani locales appear on Unix.  */
+         case SUBLANG_AZERI_LATIN: return "az_AZ@latin";
+         case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic";
+         }
+       return "az";
+      case LANG_BASQUE:
+       switch (sub)
+         {
+         case SUBLANG_DEFAULT: return "eu_ES";
+         }
+       return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR".  */
+      case LANG_BELARUSIAN: return "be_BY";
+      case LANG_BENGALI:
+       switch (sub)
+         {
+         case SUBLANG_BENGALI_INDIA: return "bn_IN";
+         case SUBLANG_BENGALI_BANGLADESH: return "bn_BD";
+         }
+       return "bn";
+      case LANG_BULGARIAN: return "bg_BG";
+      case LANG_BURMESE: return "my_MM";
+      case LANG_CAMBODIAN: return "km_KH";
+      case LANG_CATALAN: return "ca_ES";
+      case LANG_CHEROKEE: return "chr_US";
+      case LANG_CHINESE:
+       switch (sub)
+         {
+         case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW";
+         case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN";
+         case SUBLANG_CHINESE_HONGKONG: return "zh_HK";
+         case SUBLANG_CHINESE_SINGAPORE: return "zh_SG";
+         case SUBLANG_CHINESE_MACAU: return "zh_MO";
+         }
+       return "zh";
+      case LANG_CROATIAN:       /* LANG_CROATIAN == LANG_SERBIAN
+                                * What used to be called Serbo-Croatian
+                                * should really now be two separate
+                                * languages because of political reasons.
+                                * (Says tml, who knows nothing about Serbian
+                                * or Croatian.)
+                                * (I can feel those flames coming already.)
+                                */
+       switch (sub)
+         {
+         case SUBLANG_DEFAULT: return "hr_HR";
+         case SUBLANG_SERBIAN_LATIN: return "sr_CS";
+         case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic";
+         }
+       return "hr";
+      case LANG_CZECH: return "cs_CZ";
+      case LANG_DANISH: return "da_DK";
+      case LANG_DIVEHI: return "dv_MV";
+      case LANG_DUTCH:
+       switch (sub)
+         {
+         case SUBLANG_DUTCH: return "nl_NL";
+         case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE";
+         }
+       return "nl";
+      case LANG_EDO: return "bin_NG";
+      case LANG_ENGLISH:
+       switch (sub)
+         {
+         /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
+          * English was the language spoken in England.
+          * Oh well.
+          */
+         case SUBLANG_ENGLISH_US: return "en_US";
+         case SUBLANG_ENGLISH_UK: return "en_GB";
+         case SUBLANG_ENGLISH_AUS: return "en_AU";
+         case SUBLANG_ENGLISH_CAN: return "en_CA";
+         case SUBLANG_ENGLISH_NZ: return "en_NZ";
+         case SUBLANG_ENGLISH_EIRE: return "en_IE";
+         case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA";
+         case SUBLANG_ENGLISH_JAMAICA: return "en_JM";
+         case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */
+         case SUBLANG_ENGLISH_BELIZE: return "en_BZ";
+         case SUBLANG_ENGLISH_TRINIDAD: return "en_TT";
+         case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW";
+         case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH";
+         case SUBLANG_ENGLISH_INDONESIA: return "en_ID";
+         case SUBLANG_ENGLISH_HONGKONG: return "en_HK";
+         case SUBLANG_ENGLISH_INDIA: return "en_IN";
+         case SUBLANG_ENGLISH_MALAYSIA: return "en_MY";
+         case SUBLANG_ENGLISH_SINGAPORE: return "en_SG";
+         }
+       return "en";
+      case LANG_ESTONIAN: return "et_EE";
+      case LANG_FAEROESE: return "fo_FO";
+      case LANG_FARSI: return "fa_IR";
+      case LANG_FINNISH: return "fi_FI";
+      case LANG_FRENCH:
+       switch (sub)
+         {
+         case SUBLANG_FRENCH: return "fr_FR";
+         case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE";
+         case SUBLANG_FRENCH_CANADIAN: return "fr_CA";
+         case SUBLANG_FRENCH_SWISS: return "fr_CH";
+         case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU";
+         case SUBLANG_FRENCH_MONACO: return "fr_MC";
+         case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */
+         case SUBLANG_FRENCH_REUNION: return "fr_RE";
+         case SUBLANG_FRENCH_CONGO: return "fr_CG";
+         case SUBLANG_FRENCH_SENEGAL: return "fr_SN";
+         case SUBLANG_FRENCH_CAMEROON: return "fr_CM";
+         case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI";
+         case SUBLANG_FRENCH_MALI: return "fr_ML";
+         case SUBLANG_FRENCH_MOROCCO: return "fr_MA";
+         case SUBLANG_FRENCH_HAITI: return "fr_HT";
+         }
+       return "fr";
+      case LANG_FRISIAN: return "fy_NL";
+      case LANG_FULFULDE:
+       /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin.  */
+       return "ff_NG";
+      case LANG_GAELIC:
+       switch (sub)
+         {
+         case 0x01: /* SCOTTISH */ return "gd_GB";
+         case 0x02: /* IRISH */ return "ga_IE";
+         }
+       return "C";
+      case LANG_GALICIAN: return "gl_ES";
+      case LANG_GEORGIAN: return "ka_GE";
+      case LANG_GERMAN:
+       switch (sub)
+         {
+         case SUBLANG_GERMAN: return "de_DE";
+         case SUBLANG_GERMAN_SWISS: return "de_CH";
+         case SUBLANG_GERMAN_AUSTRIAN: return "de_AT";
+         case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU";
+         case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI";
+         }
+       return "de";
+      case LANG_GREEK: return "el_GR";
+      case LANG_GUARANI: return "gn_PY";
+      case LANG_GUJARATI: return "gu_IN";
+      case LANG_HAUSA: return "ha_NG";
+      case LANG_HAWAIIAN:
+       /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers)
+          or Hawaii Creole English ("cpe_US", 600000 speakers)?  */
+       return "cpe_US";
+      case LANG_HEBREW: return "he_IL";
+      case LANG_HINDI: return "hi_IN";
+      case LANG_HUNGARIAN: return "hu_HU";
+      case LANG_IBIBIO: return "nic_NG";
+      case LANG_ICELANDIC: return "is_IS";
+      case LANG_IGBO: return "ig_NG";
+      case LANG_INDONESIAN: return "id_ID";
+      case LANG_INUKTITUT: return "iu_CA";
+      case LANG_ITALIAN:
+       switch (sub)
+         {
+         case SUBLANG_ITALIAN: return "it_IT";
+         case SUBLANG_ITALIAN_SWISS: return "it_CH";
+         }
+       return "it";
+      case LANG_JAPANESE: return "ja_JP";
+      case LANG_KANNADA: return "kn_IN";
+      case LANG_KANURI: return "kr_NG";
+      case LANG_KASHMIRI:
+       switch (sub)
+         {
+         case SUBLANG_DEFAULT: return "ks_PK";
+         case SUBLANG_KASHMIRI_INDIA: return "ks_IN";
+         }
+       return "ks";
+      case LANG_KAZAK: return "kk_KZ";
+      case LANG_KONKANI:
+       /* FIXME: Adjust this when such locales appear on Unix.  */
+       return "kok_IN";
+      case LANG_KOREAN: return "ko_KR";
+      case LANG_KYRGYZ: return "ky_KG";
+      case LANG_LAO: return "lo_LA";
+      case LANG_LATIN: return "la_VA";
+      case LANG_LATVIAN: return "lv_LV";
+      case LANG_LITHUANIAN: return "lt_LT";
+      case LANG_MACEDONIAN: return "mk_MK";
+      case LANG_MALAY:
+       switch (sub)
+         {
+         case SUBLANG_MALAY_MALAYSIA: return "ms_MY";
+         case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN";
+         }
+       return "ms";
+      case LANG_MALAYALAM: return "ml_IN";
+      case LANG_MALTESE: return "mt_MT";
+      case LANG_MANIPURI:
+       /* FIXME: Adjust this when such locales appear on Unix.  */
+       return "mni_IN";
+      case LANG_MARATHI: return "mr_IN";
+      case LANG_MONGOLIAN:
+       switch (sub)
+         {
+         case SUBLANG_DEFAULT: return "mn_MN";
+         }
+       return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN".  */
+      case LANG_NEPALI:
+       switch (sub)
+         {
+         case SUBLANG_DEFAULT: return "ne_NP";
+         case SUBLANG_NEPALI_INDIA: return "ne_IN";
+         }
+       return "ne";
+      case LANG_NORWEGIAN:
+       switch (sub)
+         {
+         case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO";
+         case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO";
+         }
+       return "no";
+      case LANG_ORIYA: return "or_IN";
+      case LANG_OROMO: return "om_ET";
+      case LANG_PAPIAMENTU: return "pap_AN";
+      case LANG_PASHTO:
+       return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF".  */
+      case LANG_POLISH: return "pl_PL";
+      case LANG_PORTUGUESE:
+       switch (sub)
+         {
+         case SUBLANG_PORTUGUESE: return "pt_PT";
+         /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT.
+            Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */
+         case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR";
+         }
+       return "pt";
+      case LANG_PUNJABI:
+       switch (sub)
+         {
+         case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */
+         case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */
+         }
+       return "pa";
+      case LANG_RHAETO_ROMANCE: return "rm_CH";
+      case LANG_ROMANIAN:
+       switch (sub)
+         {
+         case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO";
+         case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD";
+         }
+       return "ro";
+      case LANG_RUSSIAN:
+       switch (sub)
+         {
+         case SUBLANG_DEFAULT: return "ru_RU";
+         }
+       return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD".  */
+      case LANG_SAAMI: /* actually Northern Sami */ return "se_NO";
+      case LANG_SANSKRIT: return "sa_IN";
+      case LANG_SINDHI:
+       switch (sub)
+         {
+         case SUBLANG_SINDHI_INDIA: return "sd_IN";
+         case SUBLANG_SINDHI_PAKISTAN: return "sd_PK";
+         }
+       return "sd";
+      case LANG_SINHALESE: return "si_LK";
+      case LANG_SLOVAK: return "sk_SK";
+      case LANG_SLOVENIAN: return "sl_SI";
+      case LANG_SOMALI: return "so_SO";
+      case LANG_SORBIAN:
+       /* FIXME: Adjust this when such locales appear on Unix.  */
+       return "wen_DE";
+      case LANG_SPANISH:
+       switch (sub)
+         {
+         case SUBLANG_SPANISH: return "es_ES";
+         case SUBLANG_SPANISH_MEXICAN: return "es_MX";
+         case SUBLANG_SPANISH_MODERN:
+           return "es_ES@modern";      /* not seen on Unix */
+         case SUBLANG_SPANISH_GUATEMALA: return "es_GT";
+         case SUBLANG_SPANISH_COSTA_RICA: return "es_CR";
+         case SUBLANG_SPANISH_PANAMA: return "es_PA";
+         case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO";
+         case SUBLANG_SPANISH_VENEZUELA: return "es_VE";
+         case SUBLANG_SPANISH_COLOMBIA: return "es_CO";
+         case SUBLANG_SPANISH_PERU: return "es_PE";
+         case SUBLANG_SPANISH_ARGENTINA: return "es_AR";
+         case SUBLANG_SPANISH_ECUADOR: return "es_EC";
+         case SUBLANG_SPANISH_CHILE: return "es_CL";
+         case SUBLANG_SPANISH_URUGUAY: return "es_UY";
+         case SUBLANG_SPANISH_PARAGUAY: return "es_PY";
+         case SUBLANG_SPANISH_BOLIVIA: return "es_BO";
+         case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV";
+         case SUBLANG_SPANISH_HONDURAS: return "es_HN";
+         case SUBLANG_SPANISH_NICARAGUA: return "es_NI";
+         case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR";
+         }
+       return "es";
+      case LANG_SUTU: return "bnt_TZ"; /* or "st_LS" or "nso_ZA"? */
+      case LANG_SWAHILI: return "sw_KE";
+      case LANG_SWEDISH:
+       switch (sub)
+         {
+         case SUBLANG_DEFAULT: return "sv_SE";
+         case SUBLANG_SWEDISH_FINLAND: return "sv_FI";
+         }
+       return "sv";
+      case LANG_SYRIAC: return "syr_TR"; /* An extinct language.  */
+      case LANG_TAGALOG: return "tl_PH";
+      case LANG_TAJIK: return "tg_TJ";
+      case LANG_TAMAZIGHT:
+       switch (sub)
+         {
+         /* FIXME: Adjust this when Tamazight locales appear on Unix.  */
+         case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic";
+         case SUBLANG_TAMAZIGHT_LATIN: return "ber_MA@latin";
+         }
+       return "ber_MA";
+      case LANG_TAMIL:
+       switch (sub)
+         {
+         case SUBLANG_DEFAULT: return "ta_IN";
+         }
+       return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG".  */
+      case LANG_TATAR: return "tt_RU";
+      case LANG_TELUGU: return "te_IN";
+      case LANG_THAI: return "th_TH";
+      case LANG_TIBETAN: return "bo_CN";
+      case LANG_TIGRINYA:
+       switch (sub)
+         {
+         case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET";
+         case SUBLANG_TIGRINYA_ERITREA: return "ti_ER";
+         }
+       return "ti";
+      case LANG_TSONGA: return "ts_ZA";
+      case LANG_TSWANA: return "tn_BW";
+      case LANG_TURKISH: return "tr_TR";
+      case LANG_TURKMEN: return "tk_TM";
+      case LANG_UKRAINIAN: return "uk_UA";
+      case LANG_URDU:
+       switch (sub)
+         {
+         case SUBLANG_URDU_PAKISTAN: return "ur_PK";
+         case SUBLANG_URDU_INDIA: return "ur_IN";
+         }
+       return "ur";
+      case LANG_UZBEK:
+       switch (sub)
+         {
+         case SUBLANG_UZBEK_LATIN: return "uz_UZ";
+         case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic";
+         }
+       return "uz";
+      case LANG_VENDA: return "ve_ZA";
+      case LANG_VIETNAMESE: return "vi_VN";
+      case LANG_WELSH: return "cy_GB";
+      case LANG_XHOSA: return "xh_ZA";
+      case LANG_YI: return "sit_CN";
+      case LANG_YIDDISH: return "yi_IL";
+      case LANG_YORUBA: return "yo_NG";
+      case LANG_ZULU: return "zu_ZA";
+      default: return "C";
+      }
+  }
+# endif
+#endif
+}
+
+const char *
+_nl_locale_name (int category, const char *categoryname)
+{
+  const char *retval;
+
+  retval = _nl_locale_name_posix (category, categoryname);
+  if (retval != NULL)
+    return retval;
+
+  return _nl_locale_name_default ();
+}
diff --git a/intl/log.c b/intl/log.c
new file mode 100644 (file)
index 0000000..cb6076e
--- /dev/null
@@ -0,0 +1,98 @@
+/* Log file output.
+   Copyright (C) 2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* Print an ASCII string with quotes and escape sequences where needed.  */
+static void
+print_escaped (FILE *stream, const char *str)
+{
+  putc ('"', stream);
+  for (; *str != '\0'; str++)
+    if (*str == '\n')
+      {
+       fputs ("\\n\"", stream);
+       if (str[1] == '\0')
+         return;
+       fputs ("\n\"", stream);
+      }
+    else
+      {
+       if (*str == '"' || *str == '\\')
+         putc ('\\', stream);
+       putc (*str, stream);
+      }
+  putc ('"', stream);
+}
+
+/* Add to the log file an entry denoting a failed translation.  */
+void
+_nl_log_untranslated (const char *logfilename, const char *domainname,
+                     const char *msgid1, const char *msgid2, int plural)
+{
+  static char *last_logfilename = NULL;
+  static FILE *last_logfile = NULL;
+  FILE *logfile;
+
+  /* Can we reuse the last opened logfile?  */
+  if (last_logfilename == NULL || strcmp (logfilename, last_logfilename) != 0)
+    {
+      /* Close the last used logfile.  */
+      if (last_logfilename != NULL)
+       {
+         if (last_logfile != NULL)
+           {
+             fclose (last_logfile);
+             last_logfile = NULL;
+           }
+         free (last_logfilename);
+         last_logfilename = NULL;
+       }
+      /* Open the logfile.  */
+      last_logfilename = (char *) malloc (strlen (logfilename) + 1);
+      if (last_logfilename == NULL)
+       return;
+      strcpy (last_logfilename, logfilename);
+      last_logfile = fopen (logfilename, "a");
+      if (last_logfile == NULL)
+       return;
+    }
+  logfile = last_logfile;
+
+  fprintf (logfile, "domain ");
+  print_escaped (logfile, domainname);
+  fprintf (logfile, "\nmsgid ");
+  print_escaped (logfile, msgid1);
+  if (plural)
+    {
+      fprintf (logfile, "\nmsgid_plural ");
+      print_escaped (logfile, msgid2);
+      fprintf (logfile, "\nmsgstr[0] \"\"\n");
+    }
+  else
+    fprintf (logfile, "\nmsgstr \"\"\n");
+  putc ('\n', logfile);
+}
diff --git a/intl/ngettext.c b/intl/ngettext.c
new file mode 100644 (file)
index 0000000..e73e00c
--- /dev/null
@@ -0,0 +1,65 @@
+/* Implementation of ngettext(3) function.
+   Copyright (C) 1995, 1997, 2000-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef _LIBC
+# define __need_NULL
+# include <stddef.h>
+#else
+# include <stdlib.h>           /* Just for NULL.  */
+#endif
+
+#include "gettextP.h"
+#ifdef _LIBC
+# include <libintl.h>
+#else
+# include "libgnuintl.h"
+#endif
+
+#include <locale.h>
+
+/* @@ end of prolog @@ */
+
+/* Names for the libintl functions are a problem.  They must not clash
+   with existing names and they should follow ANSI C.  But this source
+   code is also used in GNU C Library where the names have a __
+   prefix.  So we have to make a difference here.  */
+#ifdef _LIBC
+# define NGETTEXT __ngettext
+# define DCNGETTEXT __dcngettext
+#else
+# define NGETTEXT libintl_ngettext
+# define DCNGETTEXT libintl_dcngettext
+#endif
+
+/* Look up MSGID in the current default message catalog for the current
+   LC_MESSAGES locale.  If not found, returns MSGID itself (the default
+   text).  */
+char *
+NGETTEXT (const char *msgid1, const char *msgid2, unsigned long int n)
+{
+  return DCNGETTEXT (NULL, msgid1, msgid2, n, LC_MESSAGES);
+}
+
+#ifdef _LIBC
+/* Alias for function name in GNU C Library.  */
+weak_alias (__ngettext, ngettext);
+#endif
diff --git a/intl/os2compat.c b/intl/os2compat.c
new file mode 100644 (file)
index 0000000..c8dc33e
--- /dev/null
@@ -0,0 +1,98 @@
+/* OS/2 compatibility functions.
+   Copyright (C) 2001-2002 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#define OS2_AWARE
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/param.h>
+
+/* A version of getenv() that works from DLLs */
+extern unsigned long DosScanEnv (const unsigned char *pszName, unsigned char **ppszValue);
+
+char *
+_nl_getenv (const char *name)
+{
+  unsigned char *value;
+  if (DosScanEnv (name, &value))
+    return NULL;
+  else
+    return value;
+}
+
+/* A fixed size buffer.  */
+char libintl_nl_default_dirname[MAXPATHLEN+1];
+
+char *_nlos2_libdir = NULL;
+char *_nlos2_localealiaspath = NULL;
+char *_nlos2_localedir = NULL;
+
+static __attribute__((constructor)) void
+nlos2_initialize ()
+{
+  char *root = getenv ("UNIXROOT");
+  char *gnulocaledir = getenv ("GNULOCALEDIR");
+
+  _nlos2_libdir = gnulocaledir;
+  if (!_nlos2_libdir)
+    {
+      if (root)
+        {
+          size_t sl = strlen (root);
+          _nlos2_libdir = (char *) malloc (sl + strlen (LIBDIR) + 1);
+          memcpy (_nlos2_libdir, root, sl);
+          memcpy (_nlos2_libdir + sl, LIBDIR, strlen (LIBDIR) + 1);
+        }
+      else
+        _nlos2_libdir = LIBDIR;
+    }
+
+  _nlos2_localealiaspath = gnulocaledir;
+  if (!_nlos2_localealiaspath)
+    {
+      if (root)
+        {
+          size_t sl = strlen (root);
+          _nlos2_localealiaspath = (char *) malloc (sl + strlen (LOCALE_ALIAS_PATH) + 1);
+          memcpy (_nlos2_localealiaspath, root, sl);
+          memcpy (_nlos2_localealiaspath + sl, LOCALE_ALIAS_PATH, strlen (LOCALE_ALIAS_PATH) + 1);
+        }
+     else
+        _nlos2_localealiaspath = LOCALE_ALIAS_PATH;
+    }
+
+  _nlos2_localedir = gnulocaledir;
+  if (!_nlos2_localedir)
+    {
+      if (root)
+        {
+          size_t sl = strlen (root);
+          _nlos2_localedir = (char *) malloc (sl + strlen (LOCALEDIR) + 1);
+          memcpy (_nlos2_localedir, root, sl);
+          memcpy (_nlos2_localedir + sl, LOCALEDIR, strlen (LOCALEDIR) + 1);
+        }
+      else
+        _nlos2_localedir = LOCALEDIR;
+    }
+
+  if (strlen (_nlos2_localedir) <= MAXPATHLEN)
+    strcpy (libintl_nl_default_dirname, _nlos2_localedir);
+}
diff --git a/intl/os2compat.h b/intl/os2compat.h
new file mode 100644 (file)
index 0000000..4f74e8c
--- /dev/null
@@ -0,0 +1,46 @@
+/* OS/2 compatibility defines.
+   This file is intended to be included from config.h
+   Copyright (C) 2001-2002 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+/* When included from os2compat.h we need all the original definitions */
+#ifndef OS2_AWARE
+
+#undef LIBDIR
+#define LIBDIR                 _nlos2_libdir
+extern char *_nlos2_libdir;
+
+#undef LOCALEDIR
+#define LOCALEDIR              _nlos2_localedir
+extern char *_nlos2_localedir;
+
+#undef LOCALE_ALIAS_PATH
+#define LOCALE_ALIAS_PATH      _nlos2_localealiaspath
+extern char *_nlos2_localealiaspath;
+
+#endif
+
+#undef HAVE_STRCASECMP
+#define HAVE_STRCASECMP 1
+#define strcasecmp stricmp
+#define strncasecmp strnicmp
+
+/* We have our own getenv() which works even if library is compiled as DLL */
+#define getenv _nl_getenv
+
+/* Older versions of gettext used -1 as the value of LC_MESSAGES */
+#define LC_MESSAGES_COMPAT (-1)
diff --git a/intl/osdep.c b/intl/osdep.c
new file mode 100644 (file)
index 0000000..b372598
--- /dev/null
@@ -0,0 +1,24 @@
+/* OS dependent parts of libintl.
+   Copyright (C) 2001-2002 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#if defined __EMX__
+# include "os2compat.c"
+#else
+/* Avoid AIX compiler warning.  */
+typedef int dummy;
+#endif
diff --git a/intl/plural-exp.c b/intl/plural-exp.c
new file mode 100644 (file)
index 0000000..8c04e64
--- /dev/null
@@ -0,0 +1,154 @@
+/* Expression parsing for plural form selection.
+   Copyright (C) 2000-2001, 2003 Free Software Foundation, Inc.
+   Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "plural-exp.h"
+
+#if (defined __GNUC__ && !defined __APPLE_CC__) \
+    || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
+
+/* These structs are the constant expression for the germanic plural
+   form determination.  It represents the expression  "n != 1".  */
+static const struct expression plvar =
+{
+  .nargs = 0,
+  .operation = var,
+};
+static const struct expression plone =
+{
+  .nargs = 0,
+  .operation = num,
+  .val =
+  {
+    .num = 1
+  }
+};
+struct expression GERMANIC_PLURAL =
+{
+  .nargs = 2,
+  .operation = not_equal,
+  .val =
+  {
+    .args =
+    {
+      [0] = (struct expression *) &plvar,
+      [1] = (struct expression *) &plone
+    }
+  }
+};
+
+# define INIT_GERMANIC_PLURAL()
+
+#else
+
+/* For compilers without support for ISO C 99 struct/union initializers:
+   Initialization at run-time.  */
+
+static struct expression plvar;
+static struct expression plone;
+struct expression GERMANIC_PLURAL;
+
+static void
+init_germanic_plural ()
+{
+  if (plone.val.num == 0)
+    {
+      plvar.nargs = 0;
+      plvar.operation = var;
+
+      plone.nargs = 0;
+      plone.operation = num;
+      plone.val.num = 1;
+
+      GERMANIC_PLURAL.nargs = 2;
+      GERMANIC_PLURAL.operation = not_equal;
+      GERMANIC_PLURAL.val.args[0] = &plvar;
+      GERMANIC_PLURAL.val.args[1] = &plone;
+    }
+}
+
+# define INIT_GERMANIC_PLURAL() init_germanic_plural ()
+
+#endif
+
+void
+internal_function
+EXTRACT_PLURAL_EXPRESSION (const char *nullentry, struct expression **pluralp,
+                          unsigned long int *npluralsp)
+{
+  if (nullentry != NULL)
+    {
+      const char *plural;
+      const char *nplurals;
+
+      plural = strstr (nullentry, "plural=");
+      nplurals = strstr (nullentry, "nplurals=");
+      if (plural == NULL || nplurals == NULL)
+       goto no_plural;
+      else
+       {
+         char *endp;
+         unsigned long int n;
+         struct parse_args args;
+
+         /* First get the number.  */
+         nplurals += 9;
+         while (*nplurals != '\0' && isspace ((unsigned char) *nplurals))
+           ++nplurals;
+         if (!(*nplurals >= '0' && *nplurals <= '9'))
+           goto no_plural;
+#if defined HAVE_STRTOUL || defined _LIBC
+         n = strtoul (nplurals, &endp, 10);
+#else
+         for (endp = nplurals, n = 0; *endp >= '0' && *endp <= '9'; endp++)
+           n = n * 10 + (*endp - '0');
+#endif
+         if (nplurals == endp)
+           goto no_plural;
+         *npluralsp = n;
+
+         /* Due to the restrictions bison imposes onto the interface of the
+            scanner function we have to put the input string and the result
+            passed up from the parser into the same structure which address
+            is passed down to the parser.  */
+         plural += 7;
+         args.cp = plural;
+         if (PLURAL_PARSE (&args) != 0)
+           goto no_plural;
+         *pluralp = args.res;
+       }
+    }
+  else
+    {
+      /* By default we are using the Germanic form: singular form only
+         for `one', the plural form otherwise.  Yes, this is also what
+         English is using since English is a Germanic language.  */
+    no_plural:
+      INIT_GERMANIC_PLURAL ();
+      *pluralp = &GERMANIC_PLURAL;
+      *npluralsp = 2;
+    }
+}
diff --git a/intl/plural-exp.h b/intl/plural-exp.h
new file mode 100644 (file)
index 0000000..49e2c5b
--- /dev/null
@@ -0,0 +1,118 @@
+/* Expression parsing and evaluation for plural form selection.
+   Copyright (C) 2000-2003 Free Software Foundation, Inc.
+   Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifndef _PLURAL_EXP_H
+#define _PLURAL_EXP_H
+
+#ifndef internal_function
+# define internal_function
+#endif
+
+#ifndef attribute_hidden
+# define attribute_hidden
+#endif
+
+
+/* This is the representation of the expressions to determine the
+   plural form.  */
+struct expression
+{
+  int nargs;                   /* Number of arguments.  */
+  enum operator
+  {
+    /* Without arguments:  */
+    var,                       /* The variable "n".  */
+    num,                       /* Decimal number.  */
+    /* Unary operators:  */
+    lnot,                      /* Logical NOT.  */
+    /* Binary operators:  */
+    mult,                      /* Multiplication.  */
+    divide,                    /* Division.  */
+    module,                    /* Modulo operation.  */
+    plus,                      /* Addition.  */
+    minus,                     /* Subtraction.  */
+    less_than,                 /* Comparison.  */
+    greater_than,              /* Comparison.  */
+    less_or_equal,             /* Comparison.  */
+    greater_or_equal,          /* Comparison.  */
+    equal,                     /* Comparison for equality.  */
+    not_equal,                 /* Comparison for inequality.  */
+    land,                      /* Logical AND.  */
+    lor,                       /* Logical OR.  */
+    /* Ternary operators:  */
+    qmop                       /* Question mark operator.  */
+  } operation;
+  union
+  {
+    unsigned long int num;     /* Number value for `num'.  */
+    struct expression *args[3];        /* Up to three arguments.  */
+  } val;
+};
+
+/* This is the data structure to pass information to the parser and get
+   the result in a thread-safe way.  */
+struct parse_args
+{
+  const char *cp;
+  struct expression *res;
+};
+
+
+/* Names for the libintl functions are a problem.  This source code is used
+   1. in the GNU C Library library,
+   2. in the GNU libintl library,
+   3. in the GNU gettext tools.
+   The function names in each situation must be different, to allow for
+   binary incompatible changes in 'struct expression'.  Furthermore,
+   1. in the GNU C Library library, the names have a __ prefix,
+   2.+3. in the GNU libintl library and in the GNU gettext tools, the names
+         must follow ANSI C and not start with __.
+   So we have to distinguish the three cases.  */
+#ifdef _LIBC
+# define FREE_EXPRESSION __gettext_free_exp
+# define PLURAL_PARSE __gettextparse
+# define GERMANIC_PLURAL __gettext_germanic_plural
+# define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural
+#elif defined (IN_LIBINTL)
+# define FREE_EXPRESSION libintl_gettext_free_exp
+# define PLURAL_PARSE libintl_gettextparse
+# define GERMANIC_PLURAL libintl_gettext_germanic_plural
+# define EXTRACT_PLURAL_EXPRESSION libintl_gettext_extract_plural
+#else
+# define FREE_EXPRESSION free_plural_expression
+# define PLURAL_PARSE parse_plural_expression
+# define GERMANIC_PLURAL germanic_plural
+# define EXTRACT_PLURAL_EXPRESSION extract_plural_expression
+#endif
+
+extern void FREE_EXPRESSION (struct expression *exp)
+     internal_function;
+extern int PLURAL_PARSE (void *arg);
+extern struct expression GERMANIC_PLURAL attribute_hidden;
+extern void EXTRACT_PLURAL_EXPRESSION (const char *nullentry,
+                                      struct expression **pluralp,
+                                      unsigned long int *npluralsp)
+     internal_function;
+
+#if !defined (_LIBC) && !defined (IN_LIBINTL)
+extern unsigned long int plural_eval (struct expression *pexp,
+                                     unsigned long int n);
+#endif
+
+#endif /* _PLURAL_EXP_H */
diff --git a/intl/plural.c b/intl/plural.c
new file mode 100644 (file)
index 0000000..72494f9
--- /dev/null
@@ -0,0 +1,1490 @@
+/* A Bison parser, made from plural.y
+   by GNU bison 1.35.  */
+
+#define YYBISON 1  /* Identify Bison output.  */
+
+#define yyparse __gettextparse
+#define yylex __gettextlex
+#define yyerror __gettexterror
+#define yylval __gettextlval
+#define yychar __gettextchar
+#define yydebug __gettextdebug
+#define yynerrs __gettextnerrs
+# define       EQUOP2  257
+# define       CMPOP2  258
+# define       ADDOP2  259
+# define       MULOP2  260
+# define       NUMBER  261
+
+#line 1 "plural.y"
+
+/* Expression parsing for plural form selection.
+   Copyright (C) 2000-2001, 2003 Free Software Foundation, Inc.
+   Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+/* The bison generated parser uses alloca.  AIX 3 forces us to put this
+   declaration at the beginning of the file.  The declaration in bison's
+   skeleton file comes too late.  This must come before <config.h>
+   because <config.h> may include arbitrary system headers.  */
+#if defined _AIX && !defined __GNUC__
+ #pragma alloca
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stddef.h>
+#include <stdlib.h>
+#include "plural-exp.h"
+
+/* The main function generated by the parser is called __gettextparse,
+   but we want it to be called PLURAL_PARSE.  */
+#ifndef _LIBC
+# define __gettextparse PLURAL_PARSE
+#endif
+
+#define YYLEX_PARAM    &((struct parse_args *) arg)->cp
+#define YYPARSE_PARAM  arg
+
+#line 49 "plural.y"
+#ifndef YYSTYPE
+typedef union {
+  unsigned long int num;
+  enum operator op;
+  struct expression *exp;
+} yystype;
+# define YYSTYPE yystype
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+#line 55 "plural.y"
+
+/* Prototypes for local functions.  */
+static int yylex (YYSTYPE *lval, const char **pexp);
+static void yyerror (const char *str);
+
+/* Allocation of expressions.  */
+
+static struct expression *
+new_exp (int nargs, enum operator op, struct expression * const *args)
+{
+  int i;
+  struct expression *newp;
+
+  /* If any of the argument could not be malloc'ed, just return NULL.  */
+  for (i = nargs - 1; i >= 0; i--)
+    if (args[i] == NULL)
+      goto fail;
+
+  /* Allocate a new expression.  */
+  newp = (struct expression *) malloc (sizeof (*newp));
+  if (newp != NULL)
+    {
+      newp->nargs = nargs;
+      newp->operation = op;
+      for (i = nargs - 1; i >= 0; i--)
+       newp->val.args[i] = args[i];
+      return newp;
+    }
+
+ fail:
+  for (i = nargs - 1; i >= 0; i--)
+    FREE_EXPRESSION (args[i]);
+
+  return NULL;
+}
+
+static inline struct expression *
+new_exp_0 (enum operator op)
+{
+  return new_exp (0, op, NULL);
+}
+
+static inline struct expression *
+new_exp_1 (enum operator op, struct expression *right)
+{
+  struct expression *args[1];
+
+  args[0] = right;
+  return new_exp (1, op, args);
+}
+
+static struct expression *
+new_exp_2 (enum operator op, struct expression *left, struct expression *right)
+{
+  struct expression *args[2];
+
+  args[0] = left;
+  args[1] = right;
+  return new_exp (2, op, args);
+}
+
+static inline struct expression *
+new_exp_3 (enum operator op, struct expression *bexp,
+          struct expression *tbranch, struct expression *fbranch)
+{
+  struct expression *args[3];
+
+  args[0] = bexp;
+  args[1] = tbranch;
+  args[2] = fbranch;
+  return new_exp (3, op, args);
+}
+
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+
+
+
+#define        YYFINAL         27
+#define        YYFLAG          -32768
+#define        YYNTBASE        16
+
+/* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */
+#define YYTRANSLATE(x) ((unsigned)(x) <= 261 ? yytranslate[x] : 18)
+
+/* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */
+static const char yytranslate[] =
+{
+       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,    10,     2,     2,     2,     2,     5,     2,
+      14,    15,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,    12,     2,
+       2,     2,     2,     3,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+      13,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     4,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     1,     6,     7,     8,
+       9,    11
+};
+
+#if YYDEBUG
+static const short yyprhs[] =
+{
+       0,     0,     2,     8,    12,    16,    20,    24,    28,    32,
+      35,    37,    39
+};
+static const short yyrhs[] =
+{
+      17,     0,    17,     3,    17,    12,    17,     0,    17,     4,
+      17,     0,    17,     5,    17,     0,    17,     6,    17,     0,
+      17,     7,    17,     0,    17,     8,    17,     0,    17,     9,
+      17,     0,    10,    17,     0,    13,     0,    11,     0,    14,
+      17,    15,     0
+};
+
+#endif
+
+#if YYDEBUG
+/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
+static const short yyrline[] =
+{
+       0,   150,   158,   162,   166,   170,   174,   178,   182,   186,
+     190,   194,   199
+};
+#endif
+
+
+#if (YYDEBUG) || defined YYERROR_VERBOSE
+
+/* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */
+static const char *const yytname[] =
+{
+  "$", "error", "$undefined.", "'?'", "'|'", "'&'", "EQUOP2", "CMPOP2", 
+  "ADDOP2", "MULOP2", "'!'", "NUMBER", "':'", "'n'", "'('", "')'", 
+  "start", "exp", 0
+};
+#endif
+
+/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
+static const short yyr1[] =
+{
+       0,    16,    17,    17,    17,    17,    17,    17,    17,    17,
+      17,    17,    17
+};
+
+/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
+static const short yyr2[] =
+{
+       0,     1,     5,     3,     3,     3,     3,     3,     3,     2,
+       1,     1,     3
+};
+
+/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
+   doesn't specify something else to do.  Zero means the default is an
+   error. */
+static const short yydefact[] =
+{
+       0,     0,    11,    10,     0,     1,     9,     0,     0,     0,
+       0,     0,     0,     0,     0,    12,     0,     3,     4,     5,
+       6,     7,     8,     0,     2,     0,     0,     0
+};
+
+static const short yydefgoto[] =
+{
+      25,     5
+};
+
+static const short yypact[] =
+{
+      -9,    -9,-32768,-32768,    -9,    34,-32768,    11,    -9,    -9,
+      -9,    -9,    -9,    -9,    -9,-32768,    24,    39,    43,    16,
+      26,    -3,-32768,    -9,    34,    21,    53,-32768
+};
+
+static const short yypgoto[] =
+{
+  -32768,    -1
+};
+
+
+#define        YYLAST          53
+
+
+static const short yytable[] =
+{
+       6,     1,     2,     7,     3,     4,    14,    16,    17,    18,
+      19,    20,    21,    22,     8,     9,    10,    11,    12,    13,
+      14,    26,    24,    12,    13,    14,    15,     8,     9,    10,
+      11,    12,    13,    14,    13,    14,    23,     8,     9,    10,
+      11,    12,    13,    14,    10,    11,    12,    13,    14,    11,
+      12,    13,    14,    27
+};
+
+static const short yycheck[] =
+{
+       1,    10,    11,     4,    13,    14,     9,     8,     9,    10,
+      11,    12,    13,    14,     3,     4,     5,     6,     7,     8,
+       9,     0,    23,     7,     8,     9,    15,     3,     4,     5,
+       6,     7,     8,     9,     8,     9,    12,     3,     4,     5,
+       6,     7,     8,     9,     5,     6,     7,     8,     9,     6,
+       7,     8,     9,     0
+};
+#define YYPURE 1
+
+/* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
+#line 3 "/usr/local/share/bison/bison.simple"
+
+/* Skeleton output parser for bison,
+
+   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software
+   Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+/* As a special exception, when this file is copied by Bison into a
+   Bison output file, you may use that output file without restriction.
+   This special exception was added by the Free Software Foundation
+   in version 1.24 of Bison.  */
+
+/* This is the parser code that is written into each bison parser when
+   the %semantic_parser declaration is not specified in the grammar.
+   It was written by Richard Stallman by simplifying the hairy parser
+   used when %semantic_parser is specified.  */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+   infringing on user name space.  This should be done even for local
+   variables, as they might otherwise be expanded by user macros.
+   There are some unavoidable exceptions within include files to
+   define necessary library symbols; they are noted "INFRINGES ON
+   USER NAME SPACE" below.  */
+
+#if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)
+
+/* The parser invokes alloca or malloc; define the necessary symbols.  */
+
+# if YYSTACK_USE_ALLOCA
+#  define YYSTACK_ALLOC alloca
+# else
+#  ifndef YYSTACK_USE_ALLOCA
+#   if defined (alloca) || defined (_ALLOCA_H)
+#    define YYSTACK_ALLOC alloca
+#   else
+#    ifdef __GNUC__
+#     define YYSTACK_ALLOC __builtin_alloca
+#    endif
+#   endif
+#  endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+   /* Pacify GCC's `empty if-body' warning. */
+#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
+# else
+#  if defined (__STDC__) || defined (__cplusplus)
+#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+#   define YYSIZE_T size_t
+#  endif
+#  define YYSTACK_ALLOC malloc
+#  define YYSTACK_FREE free
+# endif
+#endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */
+
+
+#if (! defined (yyoverflow) \
+     && (! defined (__cplusplus) \
+        || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member.  */
+union yyalloc
+{
+  short yyss;
+  YYSTYPE yyvs;
+# if YYLSP_NEEDED
+  YYLTYPE yyls;
+# endif
+};
+
+/* The size of the maximum gap between one aligned stack and the next.  */
+# define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+   N elements.  */
+# if YYLSP_NEEDED
+#  define YYSTACK_BYTES(N) \
+     ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE))     \
+      + 2 * YYSTACK_GAP_MAX)
+# else
+#  define YYSTACK_BYTES(N) \
+     ((N) * (sizeof (short) + sizeof (YYSTYPE))                                \
+      + YYSTACK_GAP_MAX)
+# endif
+
+/* Copy COUNT objects from FROM to TO.  The source and destination do
+   not overlap.  */
+# ifndef YYCOPY
+#  if 1 < __GNUC__
+#   define YYCOPY(To, From, Count) \
+      __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+#  else
+#   define YYCOPY(To, From, Count)             \
+      do                                       \
+       {                                       \
+         register YYSIZE_T yyi;                \
+         for (yyi = 0; yyi < (Count); yyi++)   \
+           (To)[yyi] = (From)[yyi];            \
+       }                                       \
+      while (0)
+#  endif
+# endif
+
+/* Relocate STACK from its old location to the new one.  The
+   local variables YYSIZE and YYSTACKSIZE give the old and new number of
+   elements in the stack, and YYPTR gives the new location of the
+   stack.  Advance YYPTR to a properly aligned location for the next
+   stack.  */
+# define YYSTACK_RELOCATE(Stack)                                       \
+    do                                                                 \
+      {                                                                        \
+       YYSIZE_T yynewbytes;                                            \
+       YYCOPY (&yyptr->Stack, Stack, yysize);                          \
+       Stack = &yyptr->Stack;                                          \
+       yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX;   \
+       yyptr += yynewbytes / sizeof (*yyptr);                          \
+      }                                                                        \
+    while (0)
+
+#endif
+
+
+#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
+# define YYSIZE_T __SIZE_TYPE__
+#endif
+#if ! defined (YYSIZE_T) && defined (size_t)
+# define YYSIZE_T size_t
+#endif
+#if ! defined (YYSIZE_T)
+# if defined (__STDC__) || defined (__cplusplus)
+#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+#  define YYSIZE_T size_t
+# endif
+#endif
+#if ! defined (YYSIZE_T)
+# define YYSIZE_T unsigned int
+#endif
+
+#define yyerrok                (yyerrstatus = 0)
+#define yyclearin      (yychar = YYEMPTY)
+#define YYEMPTY                -2
+#define YYEOF          0
+#define YYACCEPT       goto yyacceptlab
+#define YYABORT        goto yyabortlab
+#define YYERROR                goto yyerrlab1
+/* Like YYERROR except do call yyerror.  This remains here temporarily
+   to ease the transition to the new meaning of YYERROR, for GCC.
+   Once GCC version 2 has supplanted version 1, this can go.  */
+#define YYFAIL         goto yyerrlab
+#define YYRECOVERING()  (!!yyerrstatus)
+#define YYBACKUP(Token, Value)                                 \
+do                                                             \
+  if (yychar == YYEMPTY && yylen == 1)                         \
+    {                                                          \
+      yychar = (Token);                                                \
+      yylval = (Value);                                                \
+      yychar1 = YYTRANSLATE (yychar);                          \
+      YYPOPSTACK;                                              \
+      goto yybackup;                                           \
+    }                                                          \
+  else                                                         \
+    {                                                          \
+      yyerror ("syntax error: cannot back up");                        \
+      YYERROR;                                                 \
+    }                                                          \
+while (0)
+
+#define YYTERROR       1
+#define YYERRCODE      256
+
+
+/* YYLLOC_DEFAULT -- Compute the default location (before the actions
+   are run).
+
+   When YYLLOC_DEFAULT is run, CURRENT is set the location of the
+   first token.  By default, to implement support for ranges, extend
+   its range to the last symbol.  */
+
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N)               \
+   Current.last_line   = Rhs[N].last_line;     \
+   Current.last_column = Rhs[N].last_column;
+#endif
+
+
+/* YYLEX -- calling `yylex' with the right arguments.  */
+
+#if YYPURE
+# if YYLSP_NEEDED
+#  ifdef YYLEX_PARAM
+#   define YYLEX               yylex (&yylval, &yylloc, YYLEX_PARAM)
+#  else
+#   define YYLEX               yylex (&yylval, &yylloc)
+#  endif
+# else /* !YYLSP_NEEDED */
+#  ifdef YYLEX_PARAM
+#   define YYLEX               yylex (&yylval, YYLEX_PARAM)
+#  else
+#   define YYLEX               yylex (&yylval)
+#  endif
+# endif /* !YYLSP_NEEDED */
+#else /* !YYPURE */
+# define YYLEX                 yylex ()
+#endif /* !YYPURE */
+
+
+/* Enable debugging if requested.  */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+#  define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args)                       \
+do {                                           \
+  if (yydebug)                                 \
+    YYFPRINTF Args;                            \
+} while (0)
+/* Nonzero means print parse trace.  It is left uninitialized so that
+   multiple parsers can coexist.  */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+#endif /* !YYDEBUG */
+
+/* YYINITDEPTH -- initial size of the parser's stacks.  */
+#ifndef        YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+   if the built-in stack extension method is used).
+
+   Do not make this value too large; the results are undefined if
+   SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
+   evaluated with infinite-precision integer arithmetic.  */
+
+#if YYMAXDEPTH == 0
+# undef YYMAXDEPTH
+#endif
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+\f
+#ifdef YYERROR_VERBOSE
+
+# ifndef yystrlen
+#  if defined (__GLIBC__) && defined (_STRING_H)
+#   define yystrlen strlen
+#  else
+/* Return the length of YYSTR.  */
+static YYSIZE_T
+#   if defined (__STDC__) || defined (__cplusplus)
+yystrlen (const char *yystr)
+#   else
+yystrlen (yystr)
+     const char *yystr;
+#   endif
+{
+  register const char *yys = yystr;
+
+  while (*yys++ != '\0')
+    continue;
+
+  return yys - yystr - 1;
+}
+#  endif
+# endif
+
+# ifndef yystpcpy
+#  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
+#   define yystpcpy stpcpy
+#  else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+   YYDEST.  */
+static char *
+#   if defined (__STDC__) || defined (__cplusplus)
+yystpcpy (char *yydest, const char *yysrc)
+#   else
+yystpcpy (yydest, yysrc)
+     char *yydest;
+     const char *yysrc;
+#   endif
+{
+  register char *yyd = yydest;
+  register const char *yys = yysrc;
+
+  while ((*yyd++ = *yys++) != '\0')
+    continue;
+
+  return yyd - 1;
+}
+#  endif
+# endif
+#endif
+\f
+#line 315 "/usr/local/share/bison/bison.simple"
+
+
+/* The user can define YYPARSE_PARAM as the name of an argument to be passed
+   into yyparse.  The argument should have type void *.
+   It should actually point to an object.
+   Grammar actions can access the variable by casting it
+   to the proper pointer type.  */
+
+#ifdef YYPARSE_PARAM
+# if defined (__STDC__) || defined (__cplusplus)
+#  define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
+#  define YYPARSE_PARAM_DECL
+# else
+#  define YYPARSE_PARAM_ARG YYPARSE_PARAM
+#  define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
+# endif
+#else /* !YYPARSE_PARAM */
+# define YYPARSE_PARAM_ARG
+# define YYPARSE_PARAM_DECL
+#endif /* !YYPARSE_PARAM */
+
+/* Prevent warning if -Wstrict-prototypes.  */
+#ifdef __GNUC__
+# ifdef YYPARSE_PARAM
+int yyparse (void *);
+# else
+int yyparse (void);
+# endif
+#endif
+
+/* YY_DECL_VARIABLES -- depending whether we use a pure parser,
+   variables are global, or local to YYPARSE.  */
+
+#define YY_DECL_NON_LSP_VARIABLES                      \
+/* The lookahead symbol.  */                           \
+int yychar;                                            \
+                                                       \
+/* The semantic value of the lookahead symbol. */      \
+YYSTYPE yylval;                                                \
+                                                       \
+/* Number of parse errors so far.  */                  \
+int yynerrs;
+
+#if YYLSP_NEEDED
+# define YY_DECL_VARIABLES                     \
+YY_DECL_NON_LSP_VARIABLES                      \
+                                               \
+/* Location data for the lookahead symbol.  */ \
+YYLTYPE yylloc;
+#else
+# define YY_DECL_VARIABLES                     \
+YY_DECL_NON_LSP_VARIABLES
+#endif
+
+
+/* If nonreentrant, generate the variables here. */
+
+#if !YYPURE
+YY_DECL_VARIABLES
+#endif  /* !YYPURE */
+
+int
+yyparse (YYPARSE_PARAM_ARG)
+     YYPARSE_PARAM_DECL
+{
+  /* If reentrant, generate the variables here. */
+#if YYPURE
+  YY_DECL_VARIABLES
+#endif  /* !YYPURE */
+
+  register int yystate;
+  register int yyn;
+  int yyresult;
+  /* Number of tokens to shift before error messages enabled.  */
+  int yyerrstatus;
+  /* Lookahead token as an internal (translated) token number.  */
+  int yychar1 = 0;
+
+  /* Three stacks and their tools:
+     `yyss': related to states,
+     `yyvs': related to semantic values,
+     `yyls': related to locations.
+
+     Refer to the stacks thru separate pointers, to allow yyoverflow
+     to reallocate them elsewhere.  */
+
+  /* The state stack. */
+  short        yyssa[YYINITDEPTH];
+  short *yyss = yyssa;
+  register short *yyssp;
+
+  /* The semantic value stack.  */
+  YYSTYPE yyvsa[YYINITDEPTH];
+  YYSTYPE *yyvs = yyvsa;
+  register YYSTYPE *yyvsp;
+
+#if YYLSP_NEEDED
+  /* The location stack.  */
+  YYLTYPE yylsa[YYINITDEPTH];
+  YYLTYPE *yyls = yylsa;
+  YYLTYPE *yylsp;
+#endif
+
+#if YYLSP_NEEDED
+# define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
+#else
+# define YYPOPSTACK   (yyvsp--, yyssp--)
+#endif
+
+  YYSIZE_T yystacksize = YYINITDEPTH;
+
+
+  /* The variables used to return semantic value and location from the
+     action routines.  */
+  YYSTYPE yyval;
+#if YYLSP_NEEDED
+  YYLTYPE yyloc;
+#endif
+
+  /* When reducing, the number of symbols on the RHS of the reduced
+     rule. */
+  int yylen;
+
+  YYDPRINTF ((stderr, "Starting parse\n"));
+
+  yystate = 0;
+  yyerrstatus = 0;
+  yynerrs = 0;
+  yychar = YYEMPTY;            /* Cause a token to be read.  */
+
+  /* Initialize stack pointers.
+     Waste one element of value and location stack
+     so that they stay on the same level as the state stack.
+     The wasted elements are never initialized.  */
+
+  yyssp = yyss;
+  yyvsp = yyvs;
+#if YYLSP_NEEDED
+  yylsp = yyls;
+#endif
+  goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate.  |
+`------------------------------------------------------------*/
+ yynewstate:
+  /* In all cases, when you get here, the value and location stacks
+     have just been pushed. so pushing a state here evens the stacks.
+     */
+  yyssp++;
+
+ yysetstate:
+  *yyssp = yystate;
+
+  if (yyssp >= yyss + yystacksize - 1)
+    {
+      /* Get the current used size of the three stacks, in elements.  */
+      YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+      {
+       /* Give user a chance to reallocate the stack. Use copies of
+          these so that the &'s don't force the real ones into
+          memory.  */
+       YYSTYPE *yyvs1 = yyvs;
+       short *yyss1 = yyss;
+
+       /* Each stack pointer address is followed by the size of the
+          data in use in that stack, in bytes.  */
+# if YYLSP_NEEDED
+       YYLTYPE *yyls1 = yyls;
+       /* This used to be a conditional around just the two extra args,
+          but that might be undefined if yyoverflow is a macro.  */
+       yyoverflow ("parser stack overflow",
+                   &yyss1, yysize * sizeof (*yyssp),
+                   &yyvs1, yysize * sizeof (*yyvsp),
+                   &yyls1, yysize * sizeof (*yylsp),
+                   &yystacksize);
+       yyls = yyls1;
+# else
+       yyoverflow ("parser stack overflow",
+                   &yyss1, yysize * sizeof (*yyssp),
+                   &yyvs1, yysize * sizeof (*yyvsp),
+                   &yystacksize);
+# endif
+       yyss = yyss1;
+       yyvs = yyvs1;
+      }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+      goto yyoverflowlab;
+# else
+      /* Extend the stack our own way.  */
+      if (yystacksize >= YYMAXDEPTH)
+       goto yyoverflowlab;
+      yystacksize *= 2;
+      if (yystacksize > YYMAXDEPTH)
+       yystacksize = YYMAXDEPTH;
+
+      {
+       short *yyss1 = yyss;
+       union yyalloc *yyptr =
+         (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+       if (! yyptr)
+         goto yyoverflowlab;
+       YYSTACK_RELOCATE (yyss);
+       YYSTACK_RELOCATE (yyvs);
+# if YYLSP_NEEDED
+       YYSTACK_RELOCATE (yyls);
+# endif
+# undef YYSTACK_RELOCATE
+       if (yyss1 != yyssa)
+         YYSTACK_FREE (yyss1);
+      }
+# endif
+#endif /* no yyoverflow */
+
+      yyssp = yyss + yysize - 1;
+      yyvsp = yyvs + yysize - 1;
+#if YYLSP_NEEDED
+      yylsp = yyls + yysize - 1;
+#endif
+
+      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+                 (unsigned long int) yystacksize));
+
+      if (yyssp >= yyss + yystacksize - 1)
+       YYABORT;
+    }
+
+  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+  goto yybackup;
+
+
+/*-----------.
+| yybackup.  |
+`-----------*/
+yybackup:
+
+/* Do appropriate processing given the current state.  */
+/* Read a lookahead token if we need one and don't already have one.  */
+/* yyresume: */
+
+  /* First try to decide what to do without reference to lookahead token.  */
+
+  yyn = yypact[yystate];
+  if (yyn == YYFLAG)
+    goto yydefault;
+
+  /* Not known => get a lookahead token if don't already have one.  */
+
+  /* yychar is either YYEMPTY or YYEOF
+     or a valid token in external form.  */
+
+  if (yychar == YYEMPTY)
+    {
+      YYDPRINTF ((stderr, "Reading a token: "));
+      yychar = YYLEX;
+    }
+
+  /* Convert token to internal form (in yychar1) for indexing tables with */
+
+  if (yychar <= 0)             /* This means end of input. */
+    {
+      yychar1 = 0;
+      yychar = YYEOF;          /* Don't call YYLEX any more */
+
+      YYDPRINTF ((stderr, "Now at end of input.\n"));
+    }
+  else
+    {
+      yychar1 = YYTRANSLATE (yychar);
+
+#if YYDEBUG
+     /* We have to keep this `#if YYDEBUG', since we use variables
+       which are defined only if `YYDEBUG' is set.  */
+      if (yydebug)
+       {
+         YYFPRINTF (stderr, "Next token is %d (%s",
+                    yychar, yytname[yychar1]);
+         /* Give the individual parser a way to print the precise
+            meaning of a token, for further debugging info.  */
+# ifdef YYPRINT
+         YYPRINT (stderr, yychar, yylval);
+# endif
+         YYFPRINTF (stderr, ")\n");
+       }
+#endif
+    }
+
+  yyn += yychar1;
+  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
+    goto yydefault;
+
+  yyn = yytable[yyn];
+
+  /* yyn is what to do for this token type in this state.
+     Negative => reduce, -yyn is rule number.
+     Positive => shift, yyn is new state.
+       New state is final state => don't bother to shift,
+       just return success.
+     0, or most negative number => error.  */
+
+  if (yyn < 0)
+    {
+      if (yyn == YYFLAG)
+       goto yyerrlab;
+      yyn = -yyn;
+      goto yyreduce;
+    }
+  else if (yyn == 0)
+    goto yyerrlab;
+
+  if (yyn == YYFINAL)
+    YYACCEPT;
+
+  /* Shift the lookahead token.  */
+  YYDPRINTF ((stderr, "Shifting token %d (%s), ",
+             yychar, yytname[yychar1]));
+
+  /* Discard the token being shifted unless it is eof.  */
+  if (yychar != YYEOF)
+    yychar = YYEMPTY;
+
+  *++yyvsp = yylval;
+#if YYLSP_NEEDED
+  *++yylsp = yylloc;
+#endif
+
+  /* Count tokens shifted since error; after three, turn off error
+     status.  */
+  if (yyerrstatus)
+    yyerrstatus--;
+
+  yystate = yyn;
+  goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state.  |
+`-----------------------------------------------------------*/
+yydefault:
+  yyn = yydefact[yystate];
+  if (yyn == 0)
+    goto yyerrlab;
+  goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction.  |
+`-----------------------------*/
+yyreduce:
+  /* yyn is the number of a rule to reduce with.  */
+  yylen = yyr2[yyn];
+
+  /* If YYLEN is nonzero, implement the default value of the action:
+     `$$ = $1'.
+
+     Otherwise, the following line sets YYVAL to the semantic value of
+     the lookahead token.  This behavior is undocumented and Bison
+     users should not rely upon it.  Assigning to YYVAL
+     unconditionally makes the parser a bit smaller, and it avoids a
+     GCC warning that YYVAL may be used uninitialized.  */
+  yyval = yyvsp[1-yylen];
+
+#if YYLSP_NEEDED
+  /* Similarly for the default location.  Let the user run additional
+     commands if for instance locations are ranges.  */
+  yyloc = yylsp[1-yylen];
+  YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
+#endif
+
+#if YYDEBUG
+  /* We have to keep this `#if YYDEBUG', since we use variables which
+     are defined only if `YYDEBUG' is set.  */
+  if (yydebug)
+    {
+      int yyi;
+
+      YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",
+                yyn, yyrline[yyn]);
+
+      /* Print the symbols being reduced, and their result.  */
+      for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)
+       YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
+      YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
+    }
+#endif
+
+  switch (yyn) {
+
+case 1:
+#line 151 "plural.y"
+{
+           if (yyvsp[0].exp == NULL)
+             YYABORT;
+           ((struct parse_args *) arg)->res = yyvsp[0].exp;
+         }
+    break;
+case 2:
+#line 159 "plural.y"
+{
+           yyval.exp = new_exp_3 (qmop, yyvsp[-4].exp, yyvsp[-2].exp, yyvsp[0].exp);
+         }
+    break;
+case 3:
+#line 163 "plural.y"
+{
+           yyval.exp = new_exp_2 (lor, yyvsp[-2].exp, yyvsp[0].exp);
+         }
+    break;
+case 4:
+#line 167 "plural.y"
+{
+           yyval.exp = new_exp_2 (land, yyvsp[-2].exp, yyvsp[0].exp);
+         }
+    break;
+case 5:
+#line 171 "plural.y"
+{
+           yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp);
+         }
+    break;
+case 6:
+#line 175 "plural.y"
+{
+           yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp);
+         }
+    break;
+case 7:
+#line 179 "plural.y"
+{
+           yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp);
+         }
+    break;
+case 8:
+#line 183 "plural.y"
+{
+           yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp);
+         }
+    break;
+case 9:
+#line 187 "plural.y"
+{
+           yyval.exp = new_exp_1 (lnot, yyvsp[0].exp);
+         }
+    break;
+case 10:
+#line 191 "plural.y"
+{
+           yyval.exp = new_exp_0 (var);
+         }
+    break;
+case 11:
+#line 195 "plural.y"
+{
+           if ((yyval.exp = new_exp_0 (num)) != NULL)
+             yyval.exp->val.num = yyvsp[0].num;
+         }
+    break;
+case 12:
+#line 200 "plural.y"
+{
+           yyval.exp = yyvsp[-1].exp;
+         }
+    break;
+}
+
+#line 705 "/usr/local/share/bison/bison.simple"
+
+\f
+  yyvsp -= yylen;
+  yyssp -= yylen;
+#if YYLSP_NEEDED
+  yylsp -= yylen;
+#endif
+
+#if YYDEBUG
+  if (yydebug)
+    {
+      short *yyssp1 = yyss - 1;
+      YYFPRINTF (stderr, "state stack now");
+      while (yyssp1 != yyssp)
+       YYFPRINTF (stderr, " %d", *++yyssp1);
+      YYFPRINTF (stderr, "\n");
+    }
+#endif
+
+  *++yyvsp = yyval;
+#if YYLSP_NEEDED
+  *++yylsp = yyloc;
+#endif
+
+  /* Now `shift' the result of the reduction.  Determine what state
+     that goes to, based on the state we popped back to and the rule
+     number reduced by.  */
+
+  yyn = yyr1[yyn];
+
+  yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
+  if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+    yystate = yytable[yystate];
+  else
+    yystate = yydefgoto[yyn - YYNTBASE];
+
+  goto yynewstate;
+
+
+/*------------------------------------.
+| yyerrlab -- here on detecting error |
+`------------------------------------*/
+yyerrlab:
+  /* If not already recovering from an error, report this error.  */
+  if (!yyerrstatus)
+    {
+      ++yynerrs;
+
+#ifdef YYERROR_VERBOSE
+      yyn = yypact[yystate];
+
+      if (yyn > YYFLAG && yyn < YYLAST)
+       {
+         YYSIZE_T yysize = 0;
+         char *yymsg;
+         int yyx, yycount;
+
+         yycount = 0;
+         /* Start YYX at -YYN if negative to avoid negative indexes in
+            YYCHECK.  */
+         for (yyx = yyn < 0 ? -yyn : 0;
+              yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
+           if (yycheck[yyx + yyn] == yyx)
+             yysize += yystrlen (yytname[yyx]) + 15, yycount++;
+         yysize += yystrlen ("parse error, unexpected ") + 1;
+         yysize += yystrlen (yytname[YYTRANSLATE (yychar)]);
+         yymsg = (char *) YYSTACK_ALLOC (yysize);
+         if (yymsg != 0)
+           {
+             char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
+             yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);
+
+             if (yycount < 5)
+               {
+                 yycount = 0;
+                 for (yyx = yyn < 0 ? -yyn : 0;
+                      yyx < (int) (sizeof (yytname) / sizeof (char *));
+                      yyx++)
+                   if (yycheck[yyx + yyn] == yyx)
+                     {
+                       const char *yyq = ! yycount ? ", expecting " : " or ";
+                       yyp = yystpcpy (yyp, yyq);
+                       yyp = yystpcpy (yyp, yytname[yyx]);
+                       yycount++;
+                     }
+               }
+             yyerror (yymsg);
+             YYSTACK_FREE (yymsg);
+           }
+         else
+           yyerror ("parse error; also virtual memory exhausted");
+       }
+      else
+#endif /* defined (YYERROR_VERBOSE) */
+       yyerror ("parse error");
+    }
+  goto yyerrlab1;
+
+
+/*--------------------------------------------------.
+| yyerrlab1 -- error raised explicitly by an action |
+`--------------------------------------------------*/
+yyerrlab1:
+  if (yyerrstatus == 3)
+    {
+      /* If just tried and failed to reuse lookahead token after an
+        error, discard it.  */
+
+      /* return failure if at end of input */
+      if (yychar == YYEOF)
+       YYABORT;
+      YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
+                 yychar, yytname[yychar1]));
+      yychar = YYEMPTY;
+    }
+
+  /* Else will try to reuse lookahead token after shifting the error
+     token.  */
+
+  yyerrstatus = 3;             /* Each real token shifted decrements this */
+
+  goto yyerrhandle;
+
+
+/*-------------------------------------------------------------------.
+| yyerrdefault -- current state does not do anything special for the |
+| error token.                                                       |
+`-------------------------------------------------------------------*/
+yyerrdefault:
+#if 0
+  /* This is wrong; only states that explicitly want error tokens
+     should shift them.  */
+
+  /* If its default is to accept any token, ok.  Otherwise pop it.  */
+  yyn = yydefact[yystate];
+  if (yyn)
+    goto yydefault;
+#endif
+
+
+/*---------------------------------------------------------------.
+| yyerrpop -- pop the current state because it cannot handle the |
+| error token                                                    |
+`---------------------------------------------------------------*/
+yyerrpop:
+  if (yyssp == yyss)
+    YYABORT;
+  yyvsp--;
+  yystate = *--yyssp;
+#if YYLSP_NEEDED
+  yylsp--;
+#endif
+
+#if YYDEBUG
+  if (yydebug)
+    {
+      short *yyssp1 = yyss - 1;
+      YYFPRINTF (stderr, "Error: state stack now");
+      while (yyssp1 != yyssp)
+       YYFPRINTF (stderr, " %d", *++yyssp1);
+      YYFPRINTF (stderr, "\n");
+    }
+#endif
+
+/*--------------.
+| yyerrhandle.  |
+`--------------*/
+yyerrhandle:
+  yyn = yypact[yystate];
+  if (yyn == YYFLAG)
+    goto yyerrdefault;
+
+  yyn += YYTERROR;
+  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
+    goto yyerrdefault;
+
+  yyn = yytable[yyn];
+  if (yyn < 0)
+    {
+      if (yyn == YYFLAG)
+       goto yyerrpop;
+      yyn = -yyn;
+      goto yyreduce;
+    }
+  else if (yyn == 0)
+    goto yyerrpop;
+
+  if (yyn == YYFINAL)
+    YYACCEPT;
+
+  YYDPRINTF ((stderr, "Shifting error token, "));
+
+  *++yyvsp = yylval;
+#if YYLSP_NEEDED
+  *++yylsp = yylloc;
+#endif
+
+  yystate = yyn;
+  goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here.  |
+`-------------------------------------*/
+yyacceptlab:
+  yyresult = 0;
+  goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here.  |
+`-----------------------------------*/
+yyabortlab:
+  yyresult = 1;
+  goto yyreturn;
+
+/*---------------------------------------------.
+| yyoverflowab -- parser overflow comes here.  |
+`---------------------------------------------*/
+yyoverflowlab:
+  yyerror ("parser stack overflow");
+  yyresult = 2;
+  /* Fall through.  */
+
+yyreturn:
+#ifndef yyoverflow
+  if (yyss != yyssa)
+    YYSTACK_FREE (yyss);
+#endif
+  return yyresult;
+}
+#line 205 "plural.y"
+
+
+void
+internal_function
+FREE_EXPRESSION (struct expression *exp)
+{
+  if (exp == NULL)
+    return;
+
+  /* Handle the recursive case.  */
+  switch (exp->nargs)
+    {
+    case 3:
+      FREE_EXPRESSION (exp->val.args[2]);
+      /* FALLTHROUGH */
+    case 2:
+      FREE_EXPRESSION (exp->val.args[1]);
+      /* FALLTHROUGH */
+    case 1:
+      FREE_EXPRESSION (exp->val.args[0]);
+      /* FALLTHROUGH */
+    default:
+      break;
+    }
+
+  free (exp);
+}
+
+
+static int
+yylex (YYSTYPE *lval, const char **pexp)
+{
+  const char *exp = *pexp;
+  int result;
+
+  while (1)
+    {
+      if (exp[0] == '\0')
+       {
+         *pexp = exp;
+         return YYEOF;
+       }
+
+      if (exp[0] != ' ' && exp[0] != '\t')
+       break;
+
+      ++exp;
+    }
+
+  result = *exp++;
+  switch (result)
+    {
+    case '0': case '1': case '2': case '3': case '4':
+    case '5': case '6': case '7': case '8': case '9':
+      {
+       unsigned long int n = result - '0';
+       while (exp[0] >= '0' && exp[0] <= '9')
+         {
+           n *= 10;
+           n += exp[0] - '0';
+           ++exp;
+         }
+       lval->num = n;
+       result = NUMBER;
+      }
+      break;
+
+    case '=':
+      if (exp[0] == '=')
+       {
+         ++exp;
+         lval->op = equal;
+         result = EQUOP2;
+       }
+      else
+       result = YYERRCODE;
+      break;
+
+    case '!':
+      if (exp[0] == '=')
+       {
+         ++exp;
+         lval->op = not_equal;
+         result = EQUOP2;
+       }
+      break;
+
+    case '&':
+    case '|':
+      if (exp[0] == result)
+       ++exp;
+      else
+       result = YYERRCODE;
+      break;
+
+    case '<':
+      if (exp[0] == '=')
+       {
+         ++exp;
+         lval->op = less_or_equal;
+       }
+      else
+       lval->op = less_than;
+      result = CMPOP2;
+      break;
+
+    case '>':
+      if (exp[0] == '=')
+       {
+         ++exp;
+         lval->op = greater_or_equal;
+       }
+      else
+       lval->op = greater_than;
+      result = CMPOP2;
+      break;
+
+    case '*':
+      lval->op = mult;
+      result = MULOP2;
+      break;
+
+    case '/':
+      lval->op = divide;
+      result = MULOP2;
+      break;
+
+    case '%':
+      lval->op = module;
+      result = MULOP2;
+      break;
+
+    case '+':
+      lval->op = plus;
+      result = ADDOP2;
+      break;
+
+    case '-':
+      lval->op = minus;
+      result = ADDOP2;
+      break;
+
+    case 'n':
+    case '?':
+    case ':':
+    case '(':
+    case ')':
+      /* Nothing, just return the character.  */
+      break;
+
+    case ';':
+    case '\n':
+    case '\0':
+      /* Be safe and let the user call this function again.  */
+      --exp;
+      result = YYEOF;
+      break;
+
+    default:
+      result = YYERRCODE;
+#if YYDEBUG != 0
+      --exp;
+#endif
+      break;
+    }
+
+  *pexp = exp;
+
+  return result;
+}
+
+
+static void
+yyerror (const char *str)
+{
+  /* Do nothing.  We don't print error messages here.  */
+}
diff --git a/intl/plural.y b/intl/plural.y
new file mode 100644 (file)
index 0000000..4d33bd7
--- /dev/null
@@ -0,0 +1,381 @@
+%{
+/* Expression parsing for plural form selection.
+   Copyright (C) 2000-2001, 2003 Free Software Foundation, Inc.
+   Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+/* The bison generated parser uses alloca.  AIX 3 forces us to put this
+   declaration at the beginning of the file.  The declaration in bison's
+   skeleton file comes too late.  This must come before <config.h>
+   because <config.h> may include arbitrary system headers.  */
+#if defined _AIX && !defined __GNUC__
+ #pragma alloca
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stddef.h>
+#include <stdlib.h>
+#include "plural-exp.h"
+
+/* The main function generated by the parser is called __gettextparse,
+   but we want it to be called PLURAL_PARSE.  */
+#ifndef _LIBC
+# define __gettextparse PLURAL_PARSE
+#endif
+
+#define YYLEX_PARAM    &((struct parse_args *) arg)->cp
+#define YYPARSE_PARAM  arg
+%}
+%pure_parser
+%expect 7
+
+%union {
+  unsigned long int num;
+  enum operator op;
+  struct expression *exp;
+}
+
+%{
+/* Prototypes for local functions.  */
+static int yylex (YYSTYPE *lval, const char **pexp);
+static void yyerror (const char *str);
+
+/* Allocation of expressions.  */
+
+static struct expression *
+new_exp (int nargs, enum operator op, struct expression * const *args)
+{
+  int i;
+  struct expression *newp;
+
+  /* If any of the argument could not be malloc'ed, just return NULL.  */
+  for (i = nargs - 1; i >= 0; i--)
+    if (args[i] == NULL)
+      goto fail;
+
+  /* Allocate a new expression.  */
+  newp = (struct expression *) malloc (sizeof (*newp));
+  if (newp != NULL)
+    {
+      newp->nargs = nargs;
+      newp->operation = op;
+      for (i = nargs - 1; i >= 0; i--)
+       newp->val.args[i] = args[i];
+      return newp;
+    }
+
+ fail:
+  for (i = nargs - 1; i >= 0; i--)
+    FREE_EXPRESSION (args[i]);
+
+  return NULL;
+}
+
+static inline struct expression *
+new_exp_0 (enum operator op)
+{
+  return new_exp (0, op, NULL);
+}
+
+static inline struct expression *
+new_exp_1 (enum operator op, struct expression *right)
+{
+  struct expression *args[1];
+
+  args[0] = right;
+  return new_exp (1, op, args);
+}
+
+static struct expression *
+new_exp_2 (enum operator op, struct expression *left, struct expression *right)
+{
+  struct expression *args[2];
+
+  args[0] = left;
+  args[1] = right;
+  return new_exp (2, op, args);
+}
+
+static inline struct expression *
+new_exp_3 (enum operator op, struct expression *bexp,
+          struct expression *tbranch, struct expression *fbranch)
+{
+  struct expression *args[3];
+
+  args[0] = bexp;
+  args[1] = tbranch;
+  args[2] = fbranch;
+  return new_exp (3, op, args);
+}
+
+%}
+
+/* This declares that all operators have the same associativity and the
+   precedence order as in C.  See [Harbison, Steele: C, A Reference Manual].
+   There is no unary minus and no bitwise operators.
+   Operators with the same syntactic behaviour have been merged into a single
+   token, to save space in the array generated by bison.  */
+%right '?'             /*   ?          */
+%left '|'              /*   ||         */
+%left '&'              /*   &&         */
+%left EQUOP2           /*   == !=      */
+%left CMPOP2           /*   < > <= >=  */
+%left ADDOP2           /*   + -        */
+%left MULOP2           /*   * / %      */
+%right '!'             /*   !          */
+
+%token <op> EQUOP2 CMPOP2 ADDOP2 MULOP2
+%token <num> NUMBER
+%type <exp> exp
+
+%%
+
+start:   exp
+         {
+           if ($1 == NULL)
+             YYABORT;
+           ((struct parse_args *) arg)->res = $1;
+         }
+       ;
+
+exp:     exp '?' exp ':' exp
+         {
+           $$ = new_exp_3 (qmop, $1, $3, $5);
+         }
+       | exp '|' exp
+         {
+           $$ = new_exp_2 (lor, $1, $3);
+         }
+       | exp '&' exp
+         {
+           $$ = new_exp_2 (land, $1, $3);
+         }
+       | exp EQUOP2 exp
+         {
+           $$ = new_exp_2 ($2, $1, $3);
+         }
+       | exp CMPOP2 exp
+         {
+           $$ = new_exp_2 ($2, $1, $3);
+         }
+       | exp ADDOP2 exp
+         {
+           $$ = new_exp_2 ($2, $1, $3);
+         }
+       | exp MULOP2 exp
+         {
+           $$ = new_exp_2 ($2, $1, $3);
+         }
+       | '!' exp
+         {
+           $$ = new_exp_1 (lnot, $2);
+         }
+       | 'n'
+         {
+           $$ = new_exp_0 (var);
+         }
+       | NUMBER
+         {
+           if (($$ = new_exp_0 (num)) != NULL)
+             $$->val.num = $1;
+         }
+       | '(' exp ')'
+         {
+           $$ = $2;
+         }
+       ;
+
+%%
+
+void
+internal_function
+FREE_EXPRESSION (struct expression *exp)
+{
+  if (exp == NULL)
+    return;
+
+  /* Handle the recursive case.  */
+  switch (exp->nargs)
+    {
+    case 3:
+      FREE_EXPRESSION (exp->val.args[2]);
+      /* FALLTHROUGH */
+    case 2:
+      FREE_EXPRESSION (exp->val.args[1]);
+      /* FALLTHROUGH */
+    case 1:
+      FREE_EXPRESSION (exp->val.args[0]);
+      /* FALLTHROUGH */
+    default:
+      break;
+    }
+
+  free (exp);
+}
+
+
+static int
+yylex (YYSTYPE *lval, const char **pexp)
+{
+  const char *exp = *pexp;
+  int result;
+
+  while (1)
+    {
+      if (exp[0] == '\0')
+       {
+         *pexp = exp;
+         return YYEOF;
+       }
+
+      if (exp[0] != ' ' && exp[0] != '\t')
+       break;
+
+      ++exp;
+    }
+
+  result = *exp++;
+  switch (result)
+    {
+    case '0': case '1': case '2': case '3': case '4':
+    case '5': case '6': case '7': case '8': case '9':
+      {
+       unsigned long int n = result - '0';
+       while (exp[0] >= '0' && exp[0] <= '9')
+         {
+           n *= 10;
+           n += exp[0] - '0';
+           ++exp;
+         }
+       lval->num = n;
+       result = NUMBER;
+      }
+      break;
+
+    case '=':
+      if (exp[0] == '=')
+       {
+         ++exp;
+         lval->op = equal;
+         result = EQUOP2;
+       }
+      else
+       result = YYERRCODE;
+      break;
+
+    case '!':
+      if (exp[0] == '=')
+       {
+         ++exp;
+         lval->op = not_equal;
+         result = EQUOP2;
+       }
+      break;
+
+    case '&':
+    case '|':
+      if (exp[0] == result)
+       ++exp;
+      else
+       result = YYERRCODE;
+      break;
+
+    case '<':
+      if (exp[0] == '=')
+       {
+         ++exp;
+         lval->op = less_or_equal;
+       }
+      else
+       lval->op = less_than;
+      result = CMPOP2;
+      break;
+
+    case '>':
+      if (exp[0] == '=')
+       {
+         ++exp;
+         lval->op = greater_or_equal;
+       }
+      else
+       lval->op = greater_than;
+      result = CMPOP2;
+      break;
+
+    case '*':
+      lval->op = mult;
+      result = MULOP2;
+      break;
+
+    case '/':
+      lval->op = divide;
+      result = MULOP2;
+      break;
+
+    case '%':
+      lval->op = module;
+      result = MULOP2;
+      break;
+
+    case '+':
+      lval->op = plus;
+      result = ADDOP2;
+      break;
+
+    case '-':
+      lval->op = minus;
+      result = ADDOP2;
+      break;
+
+    case 'n':
+    case '?':
+    case ':':
+    case '(':
+    case ')':
+      /* Nothing, just return the character.  */
+      break;
+
+    case ';':
+    case '\n':
+    case '\0':
+      /* Be safe and let the user call this function again.  */
+      --exp;
+      result = YYEOF;
+      break;
+
+    default:
+      result = YYERRCODE;
+#if YYDEBUG != 0
+      --exp;
+#endif
+      break;
+    }
+
+  *pexp = exp;
+
+  return result;
+}
+
+
+static void
+yyerror (const char *str)
+{
+  /* Do nothing.  We don't print error messages here.  */
+}
diff --git a/intl/printf-args.c b/intl/printf-args.c
new file mode 100644 (file)
index 0000000..f6f3219
--- /dev/null
@@ -0,0 +1,119 @@
+/* Decomposed printf argument list.
+   Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Specification.  */
+#include "printf-args.h"
+
+#ifdef STATIC
+STATIC
+#endif
+int
+printf_fetchargs (va_list args, arguments *a)
+{
+  size_t i;
+  argument *ap;
+
+  for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++)
+    switch (ap->type)
+      {
+      case TYPE_SCHAR:
+       ap->a.a_schar = va_arg (args, /*signed char*/ int);
+       break;
+      case TYPE_UCHAR:
+       ap->a.a_uchar = va_arg (args, /*unsigned char*/ int);
+       break;
+      case TYPE_SHORT:
+       ap->a.a_short = va_arg (args, /*short*/ int);
+       break;
+      case TYPE_USHORT:
+       ap->a.a_ushort = va_arg (args, /*unsigned short*/ int);
+       break;
+      case TYPE_INT:
+       ap->a.a_int = va_arg (args, int);
+       break;
+      case TYPE_UINT:
+       ap->a.a_uint = va_arg (args, unsigned int);
+       break;
+      case TYPE_LONGINT:
+       ap->a.a_longint = va_arg (args, long int);
+       break;
+      case TYPE_ULONGINT:
+       ap->a.a_ulongint = va_arg (args, unsigned long int);
+       break;
+#ifdef HAVE_LONG_LONG
+      case TYPE_LONGLONGINT:
+       ap->a.a_longlongint = va_arg (args, long long int);
+       break;
+      case TYPE_ULONGLONGINT:
+       ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
+       break;
+#endif
+      case TYPE_DOUBLE:
+       ap->a.a_double = va_arg (args, double);
+       break;
+#ifdef HAVE_LONG_DOUBLE
+      case TYPE_LONGDOUBLE:
+       ap->a.a_longdouble = va_arg (args, long double);
+       break;
+#endif
+      case TYPE_CHAR:
+       ap->a.a_char = va_arg (args, int);
+       break;
+#ifdef HAVE_WINT_T
+      case TYPE_WIDE_CHAR:
+       ap->a.a_wide_char = va_arg (args, wint_t);
+       break;
+#endif
+      case TYPE_STRING:
+       ap->a.a_string = va_arg (args, const char *);
+       break;
+#ifdef HAVE_WCHAR_T
+      case TYPE_WIDE_STRING:
+       ap->a.a_wide_string = va_arg (args, const wchar_t *);
+       break;
+#endif
+      case TYPE_POINTER:
+       ap->a.a_pointer = va_arg (args, void *);
+       break;
+      case TYPE_COUNT_SCHAR_POINTER:
+       ap->a.a_count_schar_pointer = va_arg (args, signed char *);
+       break;
+      case TYPE_COUNT_SHORT_POINTER:
+       ap->a.a_count_short_pointer = va_arg (args, short *);
+       break;
+      case TYPE_COUNT_INT_POINTER:
+       ap->a.a_count_int_pointer = va_arg (args, int *);
+       break;
+      case TYPE_COUNT_LONGINT_POINTER:
+       ap->a.a_count_longint_pointer = va_arg (args, long int *);
+       break;
+#ifdef HAVE_LONG_LONG
+      case TYPE_COUNT_LONGLONGINT_POINTER:
+       ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
+       break;
+#endif
+      default:
+       /* Unknown type.  */
+       return -1;
+      }
+  return 0;
+}
diff --git a/intl/printf-args.h b/intl/printf-args.h
new file mode 100644 (file)
index 0000000..f11e64c
--- /dev/null
@@ -0,0 +1,137 @@
+/* Decomposed printf argument list.
+   Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifndef _PRINTF_ARGS_H
+#define _PRINTF_ARGS_H
+
+/* Get size_t.  */
+#include <stddef.h>
+
+/* Get wchar_t.  */
+#ifdef HAVE_WCHAR_T
+# include <stddef.h>
+#endif
+
+/* Get wint_t.  */
+#ifdef HAVE_WINT_T
+# include <wchar.h>
+#endif
+
+/* Get va_list.  */
+#include <stdarg.h>
+
+
+/* Argument types */
+typedef enum
+{
+  TYPE_NONE,
+  TYPE_SCHAR,
+  TYPE_UCHAR,
+  TYPE_SHORT,
+  TYPE_USHORT,
+  TYPE_INT,
+  TYPE_UINT,
+  TYPE_LONGINT,
+  TYPE_ULONGINT,
+#ifdef HAVE_LONG_LONG
+  TYPE_LONGLONGINT,
+  TYPE_ULONGLONGINT,
+#endif
+  TYPE_DOUBLE,
+#ifdef HAVE_LONG_DOUBLE
+  TYPE_LONGDOUBLE,
+#endif
+  TYPE_CHAR,
+#ifdef HAVE_WINT_T
+  TYPE_WIDE_CHAR,
+#endif
+  TYPE_STRING,
+#ifdef HAVE_WCHAR_T
+  TYPE_WIDE_STRING,
+#endif
+  TYPE_POINTER,
+  TYPE_COUNT_SCHAR_POINTER,
+  TYPE_COUNT_SHORT_POINTER,
+  TYPE_COUNT_INT_POINTER,
+  TYPE_COUNT_LONGINT_POINTER
+#ifdef HAVE_LONG_LONG
+, TYPE_COUNT_LONGLONGINT_POINTER
+#endif
+} arg_type;
+
+/* Polymorphic argument */
+typedef struct
+{
+  arg_type type;
+  union
+  {
+    signed char                        a_schar;
+    unsigned char              a_uchar;
+    short                      a_short;
+    unsigned short             a_ushort;
+    int                                a_int;
+    unsigned int               a_uint;
+    long int                   a_longint;
+    unsigned long int          a_ulongint;
+#ifdef HAVE_LONG_LONG
+    long long int              a_longlongint;
+    unsigned long long int     a_ulonglongint;
+#endif
+    float                      a_float;
+    double                     a_double;
+#ifdef HAVE_LONG_DOUBLE
+    long double                        a_longdouble;
+#endif
+    int                                a_char;
+#ifdef HAVE_WINT_T
+    wint_t                     a_wide_char;
+#endif
+    const char*                        a_string;
+#ifdef HAVE_WCHAR_T
+    const wchar_t*             a_wide_string;
+#endif
+    void*                      a_pointer;
+    signed char *              a_count_schar_pointer;
+    short *                    a_count_short_pointer;
+    int *                      a_count_int_pointer;
+    long int *                 a_count_longint_pointer;
+#ifdef HAVE_LONG_LONG
+    long long int *            a_count_longlongint_pointer;
+#endif
+  }
+  a;
+}
+argument;
+
+typedef struct
+{
+  size_t count;
+  argument *arg;
+}
+arguments;
+
+
+/* Fetch the arguments, putting them into a. */
+#ifdef STATIC
+STATIC
+#else
+extern
+#endif
+int printf_fetchargs (va_list args, arguments *a);
+
+#endif /* _PRINTF_ARGS_H */
diff --git a/intl/printf-parse.c b/intl/printf-parse.c
new file mode 100644 (file)
index 0000000..d19f903
--- /dev/null
@@ -0,0 +1,537 @@
+/* Formatted output to strings.
+   Copyright (C) 1999-2000, 2002-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Specification.  */
+#if WIDE_CHAR_VERSION
+# include "wprintf-parse.h"
+#else
+# include "printf-parse.h"
+#endif
+
+/* Get size_t, NULL.  */
+#include <stddef.h>
+
+/* Get intmax_t.  */
+#if HAVE_STDINT_H_WITH_UINTMAX
+# include <stdint.h>
+#endif
+#if HAVE_INTTYPES_H_WITH_UINTMAX
+# include <inttypes.h>
+#endif
+
+/* malloc(), realloc(), free().  */
+#include <stdlib.h>
+
+/* Checked size_t computations.  */
+#include "xsize.h"
+
+#if WIDE_CHAR_VERSION
+# define PRINTF_PARSE wprintf_parse
+# define CHAR_T wchar_t
+# define DIRECTIVE wchar_t_directive
+# define DIRECTIVES wchar_t_directives
+#else
+# define PRINTF_PARSE printf_parse
+# define CHAR_T char
+# define DIRECTIVE char_directive
+# define DIRECTIVES char_directives
+#endif
+
+#ifdef STATIC
+STATIC
+#endif
+int
+PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
+{
+  const CHAR_T *cp = format;           /* pointer into format */
+  size_t arg_posn = 0;         /* number of regular arguments consumed */
+  size_t d_allocated;                  /* allocated elements of d->dir */
+  size_t a_allocated;                  /* allocated elements of a->arg */
+  size_t max_width_length = 0;
+  size_t max_precision_length = 0;
+
+  d->count = 0;
+  d_allocated = 1;
+  d->dir = malloc (d_allocated * sizeof (DIRECTIVE));
+  if (d->dir == NULL)
+    /* Out of memory.  */
+    return -1;
+
+  a->count = 0;
+  a_allocated = 0;
+  a->arg = NULL;
+
+#define REGISTER_ARG(_index_,_type_) \
+  {                                                                    \
+    size_t n = (_index_);                                              \
+    if (n >= a_allocated)                                              \
+      {                                                                        \
+       size_t memory_size;                                             \
+       argument *memory;                                               \
+                                                                       \
+       a_allocated = xtimes (a_allocated, 2);                          \
+       if (a_allocated <= n)                                           \
+         a_allocated = xsum (n, 1);                                    \
+       memory_size = xtimes (a_allocated, sizeof (argument));          \
+       if (size_overflow_p (memory_size))                              \
+         /* Overflow, would lead to out of memory.  */                 \
+         goto error;                                                   \
+       memory = (a->arg                                                \
+                 ? realloc (a->arg, memory_size)                       \
+                 : malloc (memory_size));                              \
+       if (memory == NULL)                                             \
+         /* Out of memory.  */                                         \
+         goto error;                                                   \
+       a->arg = memory;                                                \
+      }                                                                        \
+    while (a->count <= n)                                              \
+      a->arg[a->count++].type = TYPE_NONE;                             \
+    if (a->arg[n].type == TYPE_NONE)                                   \
+      a->arg[n].type = (_type_);                                       \
+    else if (a->arg[n].type != (_type_))                               \
+      /* Ambiguous type for positional argument.  */                   \
+      goto error;                                                      \
+  }
+
+  while (*cp != '\0')
+    {
+      CHAR_T c = *cp++;
+      if (c == '%')
+       {
+         size_t arg_index = ARG_NONE;
+         DIRECTIVE *dp = &d->dir[d->count];/* pointer to next directive */
+
+         /* Initialize the next directive.  */
+         dp->dir_start = cp - 1;
+         dp->flags = 0;
+         dp->width_start = NULL;
+         dp->width_end = NULL;
+         dp->width_arg_index = ARG_NONE;
+         dp->precision_start = NULL;
+         dp->precision_end = NULL;
+         dp->precision_arg_index = ARG_NONE;
+         dp->arg_index = ARG_NONE;
+
+         /* Test for positional argument.  */
+         if (*cp >= '0' && *cp <= '9')
+           {
+             const CHAR_T *np;
+
+             for (np = cp; *np >= '0' && *np <= '9'; np++)
+               ;
+             if (*np == '$')
+               {
+                 size_t n = 0;
+
+                 for (np = cp; *np >= '0' && *np <= '9'; np++)
+                   n = xsum (xtimes (n, 10), *np - '0');
+                 if (n == 0)
+                   /* Positional argument 0.  */
+                   goto error;
+                 if (size_overflow_p (n))
+                   /* n too large, would lead to out of memory later.  */
+                   goto error;
+                 arg_index = n - 1;
+                 cp = np + 1;
+               }
+           }
+
+         /* Read the flags.  */
+         for (;;)
+           {
+             if (*cp == '\'')
+               {
+                 dp->flags |= FLAG_GROUP;
+                 cp++;
+               }
+             else if (*cp == '-')
+               {
+                 dp->flags |= FLAG_LEFT;
+                 cp++;
+               }
+             else if (*cp == '+')
+               {
+                 dp->flags |= FLAG_SHOWSIGN;
+                 cp++;
+               }
+             else if (*cp == ' ')
+               {
+                 dp->flags |= FLAG_SPACE;
+                 cp++;
+               }
+             else if (*cp == '#')
+               {
+                 dp->flags |= FLAG_ALT;
+                 cp++;
+               }
+             else if (*cp == '0')
+               {
+                 dp->flags |= FLAG_ZERO;
+                 cp++;
+               }
+             else
+               break;
+           }
+
+         /* Parse the field width.  */
+         if (*cp == '*')
+           {
+             dp->width_start = cp;
+             cp++;
+             dp->width_end = cp;
+             if (max_width_length < 1)
+               max_width_length = 1;
+
+             /* Test for positional argument.  */
+             if (*cp >= '0' && *cp <= '9')
+               {
+                 const CHAR_T *np;
+
+                 for (np = cp; *np >= '0' && *np <= '9'; np++)
+                   ;
+                 if (*np == '$')
+                   {
+                     size_t n = 0;
+
+                     for (np = cp; *np >= '0' && *np <= '9'; np++)
+                       n = xsum (xtimes (n, 10), *np - '0');
+                     if (n == 0)
+                       /* Positional argument 0.  */
+                       goto error;
+                     if (size_overflow_p (n))
+                       /* n too large, would lead to out of memory later.  */
+                       goto error;
+                     dp->width_arg_index = n - 1;
+                     cp = np + 1;
+                   }
+               }
+             if (dp->width_arg_index == ARG_NONE)
+               {
+                 dp->width_arg_index = arg_posn++;
+                 if (dp->width_arg_index == ARG_NONE)
+                   /* arg_posn wrapped around.  */
+                   goto error;
+               }
+             REGISTER_ARG (dp->width_arg_index, TYPE_INT);
+           }
+         else if (*cp >= '0' && *cp <= '9')
+           {
+             size_t width_length;
+
+             dp->width_start = cp;
+             for (; *cp >= '0' && *cp <= '9'; cp++)
+               ;
+             dp->width_end = cp;
+             width_length = dp->width_end - dp->width_start;
+             if (max_width_length < width_length)
+               max_width_length = width_length;
+           }
+
+         /* Parse the precision.  */
+         if (*cp == '.')
+           {
+             cp++;
+             if (*cp == '*')
+               {
+                 dp->precision_start = cp - 1;
+                 cp++;
+                 dp->precision_end = cp;
+                 if (max_precision_length < 2)
+                   max_precision_length = 2;
+
+                 /* Test for positional argument.  */
+                 if (*cp >= '0' && *cp <= '9')
+                   {
+                     const CHAR_T *np;
+
+                     for (np = cp; *np >= '0' && *np <= '9'; np++)
+                       ;
+                     if (*np == '$')
+                       {
+                         size_t n = 0;
+
+                         for (np = cp; *np >= '0' && *np <= '9'; np++)
+                           n = xsum (xtimes (n, 10), *np - '0');
+                         if (n == 0)
+                           /* Positional argument 0.  */
+                           goto error;
+                         if (size_overflow_p (n))
+                           /* n too large, would lead to out of memory
+                              later.  */
+                           goto error;
+                         dp->precision_arg_index = n - 1;
+                         cp = np + 1;
+                       }
+                   }
+                 if (dp->precision_arg_index == ARG_NONE)
+                   {
+                     dp->precision_arg_index = arg_posn++;
+                     if (dp->precision_arg_index == ARG_NONE)
+                       /* arg_posn wrapped around.  */
+                       goto error;
+                   }
+                 REGISTER_ARG (dp->precision_arg_index, TYPE_INT);
+               }
+             else
+               {
+                 size_t precision_length;
+
+                 dp->precision_start = cp - 1;
+                 for (; *cp >= '0' && *cp <= '9'; cp++)
+                   ;
+                 dp->precision_end = cp;
+                 precision_length = dp->precision_end - dp->precision_start;
+                 if (max_precision_length < precision_length)
+                   max_precision_length = precision_length;
+               }
+           }
+
+         {
+           arg_type type;
+
+           /* Parse argument type/size specifiers.  */
+           {
+             int flags = 0;
+
+             for (;;)
+               {
+                 if (*cp == 'h')
+                   {
+                     flags |= (1 << (flags & 1));
+                     cp++;
+                   }
+                 else if (*cp == 'L')
+                   {
+                     flags |= 4;
+                     cp++;
+                   }
+                 else if (*cp == 'l')
+                   {
+                     flags += 8;
+                     cp++;
+                   }
+#ifdef HAVE_INTMAX_T
+                 else if (*cp == 'j')
+                   {
+                     if (sizeof (intmax_t) > sizeof (long))
+                       {
+                         /* intmax_t = long long */
+                         flags += 16;
+                       }
+                     else if (sizeof (intmax_t) > sizeof (int))
+                       {
+                         /* intmax_t = long */
+                         flags += 8;
+                       }
+                     cp++;
+                   }
+#endif
+                 else if (*cp == 'z' || *cp == 'Z')
+                   {
+                     /* 'z' is standardized in ISO C 99, but glibc uses 'Z'
+                        because the warning facility in gcc-2.95.2 understands
+                        only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784).  */
+                     if (sizeof (size_t) > sizeof (long))
+                       {
+                         /* size_t = long long */
+                         flags += 16;
+                       }
+                     else if (sizeof (size_t) > sizeof (int))
+                       {
+                         /* size_t = long */
+                         flags += 8;
+                       }
+                     cp++;
+                   }
+                 else if (*cp == 't')
+                   {
+                     if (sizeof (ptrdiff_t) > sizeof (long))
+                       {
+                         /* ptrdiff_t = long long */
+                         flags += 16;
+                       }
+                     else if (sizeof (ptrdiff_t) > sizeof (int))
+                       {
+                         /* ptrdiff_t = long */
+                         flags += 8;
+                       }
+                     cp++;
+                   }
+                 else
+                   break;
+               }
+
+             /* Read the conversion character.  */
+             c = *cp++;
+             switch (c)
+               {
+               case 'd': case 'i':
+#ifdef HAVE_LONG_LONG
+                 if (flags >= 16 || (flags & 4))
+                   type = TYPE_LONGLONGINT;
+                 else
+#endif
+                 if (flags >= 8)
+                   type = TYPE_LONGINT;
+                 else if (flags & 2)
+                   type = TYPE_SCHAR;
+                 else if (flags & 1)
+                   type = TYPE_SHORT;
+                 else
+                   type = TYPE_INT;
+                 break;
+               case 'o': case 'u': case 'x': case 'X':
+#ifdef HAVE_LONG_LONG
+                 if (flags >= 16 || (flags & 4))
+                   type = TYPE_ULONGLONGINT;
+                 else
+#endif
+                 if (flags >= 8)
+                   type = TYPE_ULONGINT;
+                 else if (flags & 2)
+                   type = TYPE_UCHAR;
+                 else if (flags & 1)
+                   type = TYPE_USHORT;
+                 else
+                   type = TYPE_UINT;
+                 break;
+               case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
+               case 'a': case 'A':
+#ifdef HAVE_LONG_DOUBLE
+                 if (flags >= 16 || (flags & 4))
+                   type = TYPE_LONGDOUBLE;
+                 else
+#endif
+                 type = TYPE_DOUBLE;
+                 break;
+               case 'c':
+                 if (flags >= 8)
+#ifdef HAVE_WINT_T
+                   type = TYPE_WIDE_CHAR;
+#else
+                   goto error;
+#endif
+                 else
+                   type = TYPE_CHAR;
+                 break;
+#ifdef HAVE_WINT_T
+               case 'C':
+                 type = TYPE_WIDE_CHAR;
+                 c = 'c';
+                 break;
+#endif
+               case 's':
+                 if (flags >= 8)
+#ifdef HAVE_WCHAR_T
+                   type = TYPE_WIDE_STRING;
+#else
+                   goto error;
+#endif
+                 else
+                   type = TYPE_STRING;
+                 break;
+#ifdef HAVE_WCHAR_T
+               case 'S':
+                 type = TYPE_WIDE_STRING;
+                 c = 's';
+                 break;
+#endif
+               case 'p':
+                 type = TYPE_POINTER;
+                 break;
+               case 'n':
+#ifdef HAVE_LONG_LONG
+                 if (flags >= 16 || (flags & 4))
+                   type = TYPE_COUNT_LONGLONGINT_POINTER;
+                 else
+#endif
+                 if (flags >= 8)
+                   type = TYPE_COUNT_LONGINT_POINTER;
+                 else if (flags & 2)
+                   type = TYPE_COUNT_SCHAR_POINTER;
+                 else if (flags & 1)
+                   type = TYPE_COUNT_SHORT_POINTER;
+                 else
+                   type = TYPE_COUNT_INT_POINTER;
+                 break;
+               case '%':
+                 type = TYPE_NONE;
+                 break;
+               default:
+                 /* Unknown conversion character.  */
+                 goto error;
+               }
+           }
+
+           if (type != TYPE_NONE)
+             {
+               dp->arg_index = arg_index;
+               if (dp->arg_index == ARG_NONE)
+                 {
+                   dp->arg_index = arg_posn++;
+                   if (dp->arg_index == ARG_NONE)
+                     /* arg_posn wrapped around.  */
+                     goto error;
+                 }
+               REGISTER_ARG (dp->arg_index, type);
+             }
+           dp->conversion = c;
+           dp->dir_end = cp;
+         }
+
+         d->count++;
+         if (d->count >= d_allocated)
+           {
+             size_t memory_size;
+             DIRECTIVE *memory;
+
+             d_allocated = xtimes (d_allocated, 2);
+             memory_size = xtimes (d_allocated, sizeof (DIRECTIVE));
+             if (size_overflow_p (memory_size))
+               /* Overflow, would lead to out of memory.  */
+               goto error;
+             memory = realloc (d->dir, memory_size);
+             if (memory == NULL)
+               /* Out of memory.  */
+               goto error;
+             d->dir = memory;
+           }
+       }
+    }
+  d->dir[d->count].dir_start = cp;
+
+  d->max_width_length = max_width_length;
+  d->max_precision_length = max_precision_length;
+  return 0;
+
+error:
+  if (a->arg)
+    free (a->arg);
+  if (d->dir)
+    free (d->dir);
+  return -1;
+}
+
+#undef DIRECTIVES
+#undef DIRECTIVE
+#undef CHAR_T
+#undef PRINTF_PARSE
diff --git a/intl/printf-parse.h b/intl/printf-parse.h
new file mode 100644 (file)
index 0000000..8aec50e
--- /dev/null
@@ -0,0 +1,75 @@
+/* Parse printf format string.
+   Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifndef _PRINTF_PARSE_H
+#define _PRINTF_PARSE_H
+
+#include "printf-args.h"
+
+
+/* Flags */
+#define FLAG_GROUP      1      /* ' flag */
+#define FLAG_LEFT       2      /* - flag */
+#define FLAG_SHOWSIGN   4      /* + flag */
+#define FLAG_SPACE      8      /* space flag */
+#define FLAG_ALT       16      /* # flag */
+#define FLAG_ZERO      32
+
+/* arg_index value indicating that no argument is consumed.  */
+#define ARG_NONE       (~(size_t)0)
+
+/* A parsed directive.  */
+typedef struct
+{
+  const char* dir_start;
+  const char* dir_end;
+  int flags;
+  const char* width_start;
+  const char* width_end;
+  size_t width_arg_index;
+  const char* precision_start;
+  const char* precision_end;
+  size_t precision_arg_index;
+  char conversion; /* d i o u x X f e E g G c s p n U % but not C S */
+  size_t arg_index;
+}
+char_directive;
+
+/* A parsed format string.  */
+typedef struct
+{
+  size_t count;
+  char_directive *dir;
+  size_t max_width_length;
+  size_t max_precision_length;
+}
+char_directives;
+
+
+/* Parses the format string.  Fills in the number N of directives, and fills
+   in directives[0], ..., directives[N-1], and sets directives[N].dir_start
+   to the end of the format string.  Also fills in the arg_type fields of the
+   arguments and the needed count of arguments.  */
+#ifdef STATIC
+STATIC
+#else
+extern
+#endif
+int printf_parse (const char *format, char_directives *d, arguments *a);
+
+#endif /* _PRINTF_PARSE_H */
diff --git a/intl/printf.c b/intl/printf.c
new file mode 100644 (file)
index 0000000..878646c
--- /dev/null
@@ -0,0 +1,371 @@
+/* Formatted output to strings, using POSIX/XSI format strings with positions.
+   Copyright (C) 2003 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 2003.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef __GNUC__
+# define alloca __builtin_alloca
+# define HAVE_ALLOCA 1
+#else
+# ifdef _MSC_VER
+#  include <malloc.h>
+#  define alloca _alloca
+# else
+#  if defined HAVE_ALLOCA_H || defined _LIBC
+#   include <alloca.h>
+#  else
+#   ifdef _AIX
+ #pragma alloca
+#   else
+#    ifndef alloca
+char *alloca ();
+#    endif
+#   endif
+#  endif
+# endif
+#endif
+
+#include <stdio.h>
+
+#if !HAVE_POSIX_PRINTF
+
+#include <stdlib.h>
+#include <string.h>
+
+/* When building a DLL, we must export some functions.  Note that because
+   the functions are only defined for binary backward compatibility, we
+   don't need to use __declspec(dllimport) in any case.  */
+#if defined _MSC_VER && BUILDING_DLL
+# define DLL_EXPORTED __declspec(dllexport)
+#else
+# define DLL_EXPORTED
+#endif
+
+#define STATIC static
+
+/* Define auxiliary functions declared in "printf-args.h".  */
+#include "printf-args.c"
+
+/* Define auxiliary functions declared in "printf-parse.h".  */
+#include "printf-parse.c"
+
+/* Define functions declared in "vasnprintf.h".  */
+#define vasnprintf libintl_vasnprintf
+#include "vasnprintf.c"
+#if 0 /* not needed */
+#define asnprintf libintl_asnprintf
+#include "asnprintf.c"
+#endif
+
+DLL_EXPORTED
+int
+libintl_vfprintf (FILE *stream, const char *format, va_list args)
+{
+  if (strchr (format, '$') == NULL)
+    return vfprintf (stream, format, args);
+  else
+    {
+      size_t length;
+      char *result = libintl_vasnprintf (NULL, &length, format, args);
+      int retval = -1;
+      if (result != NULL)
+       {
+         if (fwrite (result, 1, length, stream) == length)
+           retval = length;
+         free (result);
+       }
+      return retval;
+    }
+}
+
+DLL_EXPORTED
+int
+libintl_fprintf (FILE *stream, const char *format, ...)
+{
+  va_list args;
+  int retval;
+
+  va_start (args, format);
+  retval = libintl_vfprintf (stream, format, args);
+  va_end (args);
+  return retval;
+}
+
+DLL_EXPORTED
+int
+libintl_vprintf (const char *format, va_list args)
+{
+  return libintl_vfprintf (stdout, format, args);
+}
+
+DLL_EXPORTED
+int
+libintl_printf (const char *format, ...)
+{
+  va_list args;
+  int retval;
+
+  va_start (args, format);
+  retval = libintl_vprintf (format, args);
+  va_end (args);
+  return retval;
+}
+
+DLL_EXPORTED
+int
+libintl_vsprintf (char *resultbuf, const char *format, va_list args)
+{
+  if (strchr (format, '$') == NULL)
+    return vsprintf (resultbuf, format, args);
+  else
+    {
+      size_t length = (size_t) ~0 / (4 * sizeof (char));
+      char *result = libintl_vasnprintf (resultbuf, &length, format, args);
+      if (result != resultbuf)
+       {
+         free (result);
+         return -1;
+       }
+      else
+       return length;
+    }
+}
+
+DLL_EXPORTED
+int
+libintl_sprintf (char *resultbuf, const char *format, ...)
+{
+  va_list args;
+  int retval;
+
+  va_start (args, format);
+  retval = libintl_vsprintf (resultbuf, format, args);
+  va_end (args);
+  return retval;
+}
+
+#if HAVE_SNPRINTF
+
+# if HAVE_DECL__SNPRINTF
+   /* Windows.  */
+#  define system_vsnprintf _vsnprintf
+# else
+   /* Unix.  */
+#  define system_vsnprintf vsnprintf
+# endif
+
+DLL_EXPORTED
+int
+libintl_vsnprintf (char *resultbuf, size_t length, const char *format, va_list args)
+{
+  if (strchr (format, '$') == NULL)
+    return system_vsnprintf (resultbuf, length, format, args);
+  else
+    {
+      size_t maxlength = length;
+      char *result = libintl_vasnprintf (resultbuf, &length, format, args);
+      if (result != resultbuf)
+       {
+         if (maxlength > 0)
+           {
+             if (length < maxlength)
+               abort ();
+             memcpy (resultbuf, result, maxlength - 1);
+             resultbuf[maxlength - 1] = '\0';
+           }
+         free (result);
+         return -1;
+       }
+      else
+       return length;
+    }
+}
+
+DLL_EXPORTED
+int
+libintl_snprintf (char *resultbuf, size_t length, const char *format, ...)
+{
+  va_list args;
+  int retval;
+
+  va_start (args, format);
+  retval = libintl_vsnprintf (resultbuf, length, format, args);
+  va_end (args);
+  return retval;
+}
+
+#endif
+
+#if HAVE_ASPRINTF
+
+DLL_EXPORTED
+int
+libintl_vasprintf (char **resultp, const char *format, va_list args)
+{
+  size_t length;
+  char *result = libintl_vasnprintf (NULL, &length, format, args);
+  if (result == NULL)
+    return -1;
+  *resultp = result;
+  return length;
+}
+
+DLL_EXPORTED
+int
+libintl_asprintf (char **resultp, const char *format, ...)
+{
+  va_list args;
+  int retval;
+
+  va_start (args, format);
+  retval = libintl_vasprintf (resultp, format, args);
+  va_end (args);
+  return retval;
+}
+
+#endif
+
+#if HAVE_FWPRINTF
+
+#include <wchar.h>
+
+#define WIDE_CHAR_VERSION 1
+
+/* Define auxiliary functions declared in "wprintf-parse.h".  */
+#include "printf-parse.c"
+
+/* Define functions declared in "vasnprintf.h".  */
+#define vasnwprintf libintl_vasnwprintf
+#include "vasnprintf.c"
+#if 0 /* not needed */
+#define asnwprintf libintl_asnwprintf
+#include "asnprintf.c"
+#endif
+
+# if HAVE_DECL__SNWPRINTF
+   /* Windows.  */
+#  define system_vswprintf _vsnwprintf
+# else
+   /* Unix.  */
+#  define system_vswprintf vswprintf
+# endif
+
+DLL_EXPORTED
+int
+libintl_vfwprintf (FILE *stream, const wchar_t *format, va_list args)
+{
+  if (wcschr (format, '$') == NULL)
+    return vfwprintf (stream, format, args);
+  else
+    {
+      size_t length;
+      wchar_t *result = libintl_vasnwprintf (NULL, &length, format, args);
+      int retval = -1;
+      if (result != NULL)
+       {
+         size_t i;
+         for (i = 0; i < length; i++)
+           if (fputwc (result[i], stream) == WEOF)
+             break;
+         if (i == length)
+           retval = length;
+         free (result);
+       }
+      return retval;
+    }
+}
+
+DLL_EXPORTED
+int
+libintl_fwprintf (FILE *stream, const wchar_t *format, ...)
+{
+  va_list args;
+  int retval;
+
+  va_start (args, format);
+  retval = libintl_vfwprintf (stream, format, args);
+  va_end (args);
+  return retval;
+}
+
+DLL_EXPORTED
+int
+libintl_vwprintf (const wchar_t *format, va_list args)
+{
+  return libintl_vfwprintf (stdout, format, args);
+}
+
+DLL_EXPORTED
+int
+libintl_wprintf (const wchar_t *format, ...)
+{
+  va_list args;
+  int retval;
+
+  va_start (args, format);
+  retval = libintl_vwprintf (format, args);
+  va_end (args);
+  return retval;
+}
+
+DLL_EXPORTED
+int
+libintl_vswprintf (wchar_t *resultbuf, size_t length, const wchar_t *format, va_list args)
+{
+  if (wcschr (format, '$') == NULL)
+    return system_vswprintf (resultbuf, length, format, args);
+  else
+    {
+      size_t maxlength = length;
+      wchar_t *result = libintl_vasnwprintf (resultbuf, &length, format, args);
+      if (result != resultbuf)
+       {
+         if (maxlength > 0)
+           {
+             if (length < maxlength)
+               abort ();
+             memcpy (resultbuf, result, (maxlength - 1) * sizeof (wchar_t));
+             resultbuf[maxlength - 1] = 0;
+           }
+         free (result);
+         return -1;
+       }
+      else
+       return length;
+    }
+}
+
+DLL_EXPORTED
+int
+libintl_swprintf (wchar_t *resultbuf, size_t length, const wchar_t *format, ...)
+{
+  va_list args;
+  int retval;
+
+  va_start (args, format);
+  retval = libintl_vswprintf (resultbuf, length, format, args);
+  va_end (args);
+  return retval;
+}
+
+#endif
+
+#endif
diff --git a/intl/ref-add.sin b/intl/ref-add.sin
new file mode 100644 (file)
index 0000000..167374e
--- /dev/null
@@ -0,0 +1,31 @@
+# Add this package to a list of references stored in a text file.
+#
+#   Copyright (C) 2000 Free Software Foundation, Inc.
+#
+#   This program is free software; you can redistribute it and/or modify it
+#   under the terms of the GNU Library General Public License as published
+#   by the Free Software Foundation; either version 2, or (at your option)
+#   any later version.
+#
+#   This program 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
+#   Library General Public License for more details.
+#
+#   You should have received a copy of the GNU Library General Public
+#   License along with this program; if not, write to the Free Software
+#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+#   USA.
+#
+# Written by Bruno Haible <haible@clisp.cons.org>.
+#
+/^# Packages using this file: / {
+  s/# Packages using this file://
+  ta
+  :a
+  s/ @PACKAGE@ / @PACKAGE@ /
+  tb
+  s/ $/ @PACKAGE@ /
+  :b
+  s/^/# Packages using this file:/
+}
diff --git a/intl/ref-del.sin b/intl/ref-del.sin
new file mode 100644 (file)
index 0000000..613cf37
--- /dev/null
@@ -0,0 +1,26 @@
+# Remove this package from a list of references stored in a text file.
+#
+#   Copyright (C) 2000 Free Software Foundation, Inc.
+#
+#   This program is free software; you can redistribute it and/or modify it
+#   under the terms of the GNU Library General Public License as published
+#   by the Free Software Foundation; either version 2, or (at your option)
+#   any later version.
+#
+#   This program 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
+#   Library General Public License for more details.
+#
+#   You should have received a copy of the GNU Library General Public
+#   License along with this program; if not, write to the Free Software
+#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+#   USA.
+#
+# Written by Bruno Haible <haible@clisp.cons.org>.
+#
+/^# Packages using this file: / {
+  s/# Packages using this file://
+  s/ @PACKAGE@ / /
+  s/^/# Packages using this file:/
+}
diff --git a/intl/relocatable.c b/intl/relocatable.c
new file mode 100644 (file)
index 0000000..2683ace
--- /dev/null
@@ -0,0 +1,449 @@
+/* Provide relocatable packages.
+   Copyright (C) 2003-2004 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 2003.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+
+/* Tell glibc's <stdio.h> to provide a prototype for getline().
+   This must come before <config.h> because <config.h> may include
+   <features.h>, and once <features.h> has been included, it's too late.  */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE   1
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+/* Specification.  */
+#include "relocatable.h"
+
+#if ENABLE_RELOCATABLE
+
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef NO_XMALLOC
+# define xmalloc malloc
+#else
+# include "xalloc.h"
+#endif
+
+#if defined _WIN32 || defined __WIN32__
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+#endif
+
+#if DEPENDS_ON_LIBCHARSET
+# include <libcharset.h>
+#endif
+#if DEPENDS_ON_LIBICONV && HAVE_ICONV
+# include <iconv.h>
+#endif
+#if DEPENDS_ON_LIBINTL && ENABLE_NLS
+# include <libintl.h>
+#endif
+
+/* Faked cheap 'bool'.  */
+#undef bool
+#undef false
+#undef true
+#define bool int
+#define false 0
+#define true 1
+
+/* Pathname support.
+   ISSLASH(C)           tests whether C is a directory separator character.
+   IS_PATH_WITH_DIR(P)  tests whether P contains a directory specification.
+ */
+#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
+  /* Win32, Cygwin, OS/2, DOS */
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+# define HAS_DEVICE(P) \
+    ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
+     && (P)[1] == ':')
+# define IS_PATH_WITH_DIR(P) \
+    (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
+# define FILE_SYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
+#else
+  /* Unix */
+# define ISSLASH(C) ((C) == '/')
+# define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
+# define FILE_SYSTEM_PREFIX_LEN(P) 0
+#endif
+
+/* Original installation prefix.  */
+static char *orig_prefix;
+static size_t orig_prefix_len;
+/* Current installation prefix.  */
+static char *curr_prefix;
+static size_t curr_prefix_len;
+/* These prefixes do not end in a slash.  Anything that will be concatenated
+   to them must start with a slash.  */
+
+/* Sets the original and the current installation prefix of this module.
+   Relocation simply replaces a pathname starting with the original prefix
+   by the corresponding pathname with the current prefix instead.  Both
+   prefixes should be directory names without trailing slash (i.e. use ""
+   instead of "/").  */
+static void
+set_this_relocation_prefix (const char *orig_prefix_arg,
+                           const char *curr_prefix_arg)
+{
+  if (orig_prefix_arg != NULL && curr_prefix_arg != NULL
+      /* Optimization: if orig_prefix and curr_prefix are equal, the
+        relocation is a nop.  */
+      && strcmp (orig_prefix_arg, curr_prefix_arg) != 0)
+    {
+      /* Duplicate the argument strings.  */
+      char *memory;
+
+      orig_prefix_len = strlen (orig_prefix_arg);
+      curr_prefix_len = strlen (curr_prefix_arg);
+      memory = (char *) xmalloc (orig_prefix_len + 1 + curr_prefix_len + 1);
+#ifdef NO_XMALLOC
+      if (memory != NULL)
+#endif
+       {
+         memcpy (memory, orig_prefix_arg, orig_prefix_len + 1);
+         orig_prefix = memory;
+         memory += orig_prefix_len + 1;
+         memcpy (memory, curr_prefix_arg, curr_prefix_len + 1);
+         curr_prefix = memory;
+         return;
+       }
+    }
+  orig_prefix = NULL;
+  curr_prefix = NULL;
+  /* Don't worry about wasted memory here - this function is usually only
+     called once.  */
+}
+
+/* Sets the original and the current installation prefix of the package.
+   Relocation simply replaces a pathname starting with the original prefix
+   by the corresponding pathname with the current prefix instead.  Both
+   prefixes should be directory names without trailing slash (i.e. use ""
+   instead of "/").  */
+void
+set_relocation_prefix (const char *orig_prefix_arg, const char *curr_prefix_arg)
+{
+  set_this_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
+
+  /* Now notify all dependent libraries.  */
+#if DEPENDS_ON_LIBCHARSET
+  libcharset_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
+#endif
+#if DEPENDS_ON_LIBICONV && HAVE_ICONV && _LIBICONV_VERSION >= 0x0109
+  libiconv_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
+#endif
+#if DEPENDS_ON_LIBINTL && ENABLE_NLS && defined libintl_set_relocation_prefix
+  libintl_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
+#endif
+}
+
+#if !defined IN_LIBRARY || (defined PIC && defined INSTALLDIR)
+
+/* Convenience function:
+   Computes the current installation prefix, based on the original
+   installation prefix, the original installation directory of a particular
+   file, and the current pathname of this file.  Returns NULL upon failure.  */
+#ifdef IN_LIBRARY
+#define compute_curr_prefix local_compute_curr_prefix
+static
+#endif
+const char *
+compute_curr_prefix (const char *orig_installprefix,
+                    const char *orig_installdir,
+                    const char *curr_pathname)
+{
+  const char *curr_installdir;
+  const char *rel_installdir;
+
+  if (curr_pathname == NULL)
+    return NULL;
+
+  /* Determine the relative installation directory, relative to the prefix.
+     This is simply the difference between orig_installprefix and
+     orig_installdir.  */
+  if (strncmp (orig_installprefix, orig_installdir, strlen (orig_installprefix))
+      != 0)
+    /* Shouldn't happen - nothing should be installed outside $(prefix).  */
+    return NULL;
+  rel_installdir = orig_installdir + strlen (orig_installprefix);
+
+  /* Determine the current installation directory.  */
+  {
+    const char *p_base = curr_pathname + FILE_SYSTEM_PREFIX_LEN (curr_pathname);
+    const char *p = curr_pathname + strlen (curr_pathname);
+    char *q;
+
+    while (p > p_base)
+      {
+       p--;
+       if (ISSLASH (*p))
+         break;
+      }
+
+    q = (char *) xmalloc (p - curr_pathname + 1);
+#ifdef NO_XMALLOC
+    if (q == NULL)
+      return NULL;
+#endif
+    memcpy (q, curr_pathname, p - curr_pathname);
+    q[p - curr_pathname] = '\0';
+    curr_installdir = q;
+  }
+
+  /* Compute the current installation prefix by removing the trailing
+     rel_installdir from it.  */
+  {
+    const char *rp = rel_installdir + strlen (rel_installdir);
+    const char *cp = curr_installdir + strlen (curr_installdir);
+    const char *cp_base =
+      curr_installdir + FILE_SYSTEM_PREFIX_LEN (curr_installdir);
+
+    while (rp > rel_installdir && cp > cp_base)
+      {
+       bool same = false;
+       const char *rpi = rp;
+       const char *cpi = cp;
+
+       while (rpi > rel_installdir && cpi > cp_base)
+         {
+           rpi--;
+           cpi--;
+           if (ISSLASH (*rpi) || ISSLASH (*cpi))
+             {
+               if (ISSLASH (*rpi) && ISSLASH (*cpi))
+                 same = true;
+               break;
+             }
+#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
+           /* Win32, Cygwin, OS/2, DOS - case insignificant filesystem */
+           if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi)
+               != (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi))
+             break;
+#else
+           if (*rpi != *cpi)
+             break;
+#endif
+         }
+       if (!same)
+         break;
+       /* The last pathname component was the same.  opi and cpi now point
+          to the slash before it.  */
+       rp = rpi;
+       cp = cpi;
+      }
+
+    if (rp > rel_installdir)
+      /* Unexpected: The curr_installdir does not end with rel_installdir.  */
+      return NULL;
+
+    {
+      size_t curr_prefix_len = cp - curr_installdir;
+      char *curr_prefix;
+
+      curr_prefix = (char *) xmalloc (curr_prefix_len + 1);
+#ifdef NO_XMALLOC
+      if (curr_prefix == NULL)
+       return NULL;
+#endif
+      memcpy (curr_prefix, curr_installdir, curr_prefix_len);
+      curr_prefix[curr_prefix_len] = '\0';
+
+      return curr_prefix;
+    }
+  }
+}
+
+#endif /* !IN_LIBRARY || PIC */
+
+#if defined PIC && defined INSTALLDIR
+
+/* Full pathname of shared library, or NULL.  */
+static char *shared_library_fullname;
+
+#if defined _WIN32 || defined __WIN32__
+
+/* Determine the full pathname of the shared library when it is loaded.  */
+
+BOOL WINAPI
+DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved)
+{
+  (void) reserved;
+
+  if (event == DLL_PROCESS_ATTACH)
+    {
+      /* The DLL is being loaded into an application's address range.  */
+      static char location[MAX_PATH];
+
+      if (!GetModuleFileName (module_handle, location, sizeof (location)))
+       /* Shouldn't happen.  */
+       return FALSE;
+
+      if (!IS_PATH_WITH_DIR (location))
+       /* Shouldn't happen.  */
+       return FALSE;
+
+      shared_library_fullname = strdup (location);
+    }
+
+  return TRUE;
+}
+
+#else /* Unix */
+
+static void
+find_shared_library_fullname ()
+{
+#if defined __linux__ && __GLIBC__ >= 2
+  /* Linux has /proc/self/maps. glibc 2 has the getline() function.  */
+  FILE *fp;
+
+  /* Open the current process' maps file.  It describes one VMA per line.  */
+  fp = fopen ("/proc/self/maps", "r");
+  if (fp)
+    {
+      unsigned long address = (unsigned long) &find_shared_library_fullname;
+      for (;;)
+       {
+         unsigned long start, end;
+         int c;
+
+         if (fscanf (fp, "%lx-%lx", &start, &end) != 2)
+           break;
+         if (address >= start && address <= end - 1)
+           {
+             /* Found it.  Now see if this line contains a filename.  */
+             while (c = getc (fp), c != EOF && c != '\n' && c != '/')
+               continue;
+             if (c == '/')
+               {
+                 size_t size;
+                 int len;
+
+                 ungetc (c, fp);
+                 shared_library_fullname = NULL; size = 0;
+                 len = getline (&shared_library_fullname, &size, fp);
+                 if (len >= 0)
+                   {
+                     /* Success: filled shared_library_fullname.  */
+                     if (len > 0 && shared_library_fullname[len - 1] == '\n')
+                       shared_library_fullname[len - 1] = '\0';
+                   }
+               }
+             break;
+           }
+         while (c = getc (fp), c != EOF && c != '\n')
+           continue;
+       }
+      fclose (fp);
+    }
+#endif
+}
+
+#endif /* WIN32 / Unix */
+
+/* Return the full pathname of the current shared library.
+   Return NULL if unknown.
+   Guaranteed to work only on Linux and Woe32.  */
+static char *
+get_shared_library_fullname ()
+{
+#if !(defined _WIN32 || defined __WIN32__)
+  static bool tried_find_shared_library_fullname;
+  if (!tried_find_shared_library_fullname)
+    {
+      find_shared_library_fullname ();
+      tried_find_shared_library_fullname = true;
+    }
+#endif
+  return shared_library_fullname;
+}
+
+#endif /* PIC */
+
+/* Returns the pathname, relocated according to the current installation
+   directory.  */
+const char *
+relocate (const char *pathname)
+{
+#if defined PIC && defined INSTALLDIR
+  static int initialized;
+
+  /* Initialization code for a shared library.  */
+  if (!initialized)
+    {
+      /* At this point, orig_prefix and curr_prefix likely have already been
+        set through the main program's set_program_name_and_installdir
+        function.  This is sufficient in the case that the library has
+        initially been installed in the same orig_prefix.  But we can do
+        better, to also cover the cases that 1. it has been installed
+        in a different prefix before being moved to orig_prefix and (later)
+        to curr_prefix, 2. unlike the program, it has not moved away from
+        orig_prefix.  */
+      const char *orig_installprefix = INSTALLPREFIX;
+      const char *orig_installdir = INSTALLDIR;
+      const char *curr_prefix_better;
+
+      curr_prefix_better =
+       compute_curr_prefix (orig_installprefix, orig_installdir,
+                            get_shared_library_fullname ());
+      if (curr_prefix_better == NULL)
+       curr_prefix_better = curr_prefix;
+
+      set_relocation_prefix (orig_installprefix, curr_prefix_better);
+
+      initialized = 1;
+    }
+#endif
+
+  /* Note: It is not necessary to perform case insensitive comparison here,
+     even for DOS-like filesystems, because the pathname argument was
+     typically created from the same Makefile variable as orig_prefix came
+     from.  */
+  if (orig_prefix != NULL && curr_prefix != NULL
+      && strncmp (pathname, orig_prefix, orig_prefix_len) == 0)
+    {
+      if (pathname[orig_prefix_len] == '\0')
+       /* pathname equals orig_prefix.  */
+       return curr_prefix;
+      if (ISSLASH (pathname[orig_prefix_len]))
+       {
+         /* pathname starts with orig_prefix.  */
+         const char *pathname_tail = &pathname[orig_prefix_len];
+         char *result =
+           (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1);
+
+#ifdef NO_XMALLOC
+         if (result != NULL)
+#endif
+           {
+             memcpy (result, curr_prefix, curr_prefix_len);
+             strcpy (result + curr_prefix_len, pathname_tail);
+             return result;
+           }
+       }
+    }
+  /* Nothing to relocate.  */
+  return pathname;
+}
+
+#endif
diff --git a/intl/relocatable.h b/intl/relocatable.h
new file mode 100644 (file)
index 0000000..48c5b71
--- /dev/null
@@ -0,0 +1,77 @@
+/* Provide relocatable packages.
+   Copyright (C) 2003 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 2003.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifndef _RELOCATABLE_H
+#define _RELOCATABLE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* This can be enabled through the configure --enable-relocatable option.  */
+#if ENABLE_RELOCATABLE
+
+/* When building a DLL, we must export some functions.  Note that because
+   this is a private .h file, we don't need to use __declspec(dllimport)
+   in any case.  */
+#if defined _MSC_VER && BUILDING_DLL
+# define RELOCATABLE_DLL_EXPORTED __declspec(dllexport)
+#else
+# define RELOCATABLE_DLL_EXPORTED
+#endif
+
+/* Sets the original and the current installation prefix of the package.
+   Relocation simply replaces a pathname starting with the original prefix
+   by the corresponding pathname with the current prefix instead.  Both
+   prefixes should be directory names without trailing slash (i.e. use ""
+   instead of "/").  */
+extern RELOCATABLE_DLL_EXPORTED void
+       set_relocation_prefix (const char *orig_prefix,
+                             const char *curr_prefix);
+
+/* Returns the pathname, relocated according to the current installation
+   directory.  */
+extern const char * relocate (const char *pathname);
+
+/* Memory management: relocate() leaks memory, because it has to construct
+   a fresh pathname.  If this is a problem because your program calls
+   relocate() frequently, think about caching the result.  */
+
+/* Convenience function:
+   Computes the current installation prefix, based on the original
+   installation prefix, the original installation directory of a particular
+   file, and the current pathname of this file.  Returns NULL upon failure.  */
+extern const char * compute_curr_prefix (const char *orig_installprefix,
+                                        const char *orig_installdir,
+                                        const char *curr_pathname);
+
+#else
+
+/* By default, we use the hardwired pathnames.  */
+#define relocate(pathname) (pathname)
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RELOCATABLE_H */
diff --git a/intl/textdomain.c b/intl/textdomain.c
new file mode 100644 (file)
index 0000000..8745a84
--- /dev/null
@@ -0,0 +1,141 @@
+/* Implementation of the textdomain(3) function.
+   Copyright (C) 1995-1998, 2000-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef _LIBC
+# include <libintl.h>
+#else
+# include "libgnuintl.h"
+#endif
+#include "gettextP.h"
+
+#ifdef _LIBC
+/* We have to handle multi-threaded applications.  */
+# include <bits/libc-lock.h>
+#else
+/* Provide dummy implementation if this is outside glibc.  */
+# define __libc_rwlock_define(CLASS, NAME)
+# define __libc_rwlock_wrlock(NAME)
+# define __libc_rwlock_unlock(NAME)
+#endif
+
+/* The internal variables in the standalone libintl.a must have different
+   names than the internal variables in GNU libc, otherwise programs
+   using libintl.a cannot be linked statically.  */
+#if !defined _LIBC
+# define _nl_default_default_domain libintl_nl_default_default_domain
+# define _nl_current_default_domain libintl_nl_current_default_domain
+#endif
+
+/* @@ end of prolog @@ */
+
+/* Name of the default text domain.  */
+extern const char _nl_default_default_domain[] attribute_hidden;
+
+/* Default text domain in which entries for gettext(3) are to be found.  */
+extern const char *_nl_current_default_domain attribute_hidden;
+
+
+/* Names for the libintl functions are a problem.  They must not clash
+   with existing names and they should follow ANSI C.  But this source
+   code is also used in GNU C Library where the names have a __
+   prefix.  So we have to make a difference here.  */
+#ifdef _LIBC
+# define TEXTDOMAIN __textdomain
+# ifndef strdup
+#  define strdup(str) __strdup (str)
+# endif
+#else
+# define TEXTDOMAIN libintl_textdomain
+#endif
+
+/* Lock variable to protect the global data in the gettext implementation.  */
+__libc_rwlock_define (extern, _nl_state_lock attribute_hidden)
+
+/* Set the current default message catalog to DOMAINNAME.
+   If DOMAINNAME is null, return the current default.
+   If DOMAINNAME is "", reset to the default of "messages".  */
+char *
+TEXTDOMAIN (const char *domainname)
+{
+  char *new_domain;
+  char *old_domain;
+
+  /* A NULL pointer requests the current setting.  */
+  if (domainname == NULL)
+    return (char *) _nl_current_default_domain;
+
+  __libc_rwlock_wrlock (_nl_state_lock);
+
+  old_domain = (char *) _nl_current_default_domain;
+
+  /* If domain name is the null string set to default domain "messages".  */
+  if (domainname[0] == '\0'
+      || strcmp (domainname, _nl_default_default_domain) == 0)
+    {
+      _nl_current_default_domain = _nl_default_default_domain;
+      new_domain = (char *) _nl_current_default_domain;
+    }
+  else if (strcmp (domainname, old_domain) == 0)
+    /* This can happen and people will use it to signal that some
+       environment variable changed.  */
+    new_domain = old_domain;
+  else
+    {
+      /* If the following malloc fails `_nl_current_default_domain'
+        will be NULL.  This value will be returned and so signals we
+        are out of core.  */
+#if defined _LIBC || defined HAVE_STRDUP
+      new_domain = strdup (domainname);
+#else
+      size_t len = strlen (domainname) + 1;
+      new_domain = (char *) malloc (len);
+      if (new_domain != NULL)
+       memcpy (new_domain, domainname, len);
+#endif
+
+      if (new_domain != NULL)
+       _nl_current_default_domain = new_domain;
+    }
+
+  /* We use this possibility to signal a change of the loaded catalogs
+     since this is most likely the case and there is no other easy we
+     to do it.  Do it only when the call was successful.  */
+  if (new_domain != NULL)
+    {
+      ++_nl_msg_cat_cntr;
+
+      if (old_domain != new_domain && old_domain != _nl_default_default_domain)
+       free (old_domain);
+    }
+
+  __libc_rwlock_unlock (_nl_state_lock);
+
+  return new_domain;
+}
+
+#ifdef _LIBC
+/* Alias for function name in GNU C Library.  */
+weak_alias (__textdomain, textdomain);
+#endif
diff --git a/intl/vasnprintf.c b/intl/vasnprintf.c
new file mode 100644 (file)
index 0000000..ad0a067
--- /dev/null
@@ -0,0 +1,902 @@
+/* vsprintf with automatic memory allocation.
+   Copyright (C) 1999, 2002-2005 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+/* Tell glibc's <stdio.h> to provide a prototype for snprintf().
+   This must come before <config.h> because <config.h> may include
+   <features.h>, and once <features.h> has been included, it's too late.  */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE    1
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#ifndef IN_LIBINTL
+# include <alloca.h>
+#endif
+
+/* Specification.  */
+#if WIDE_CHAR_VERSION
+# include "vasnwprintf.h"
+#else
+# include "vasnprintf.h"
+#endif
+
+#include <stdio.h>     /* snprintf(), sprintf() */
+#include <stdlib.h>    /* abort(), malloc(), realloc(), free() */
+#include <string.h>    /* memcpy(), strlen() */
+#include <errno.h>     /* errno */
+#include <limits.h>    /* CHAR_BIT, INT_MAX */
+#include <float.h>     /* DBL_MAX_EXP, LDBL_MAX_EXP */
+#if WIDE_CHAR_VERSION
+# include "wprintf-parse.h"
+#else
+# include "printf-parse.h"
+#endif
+
+/* Checked size_t computations.  */
+#include "xsize.h"
+
+/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW.  */
+#ifndef EOVERFLOW
+# define EOVERFLOW E2BIG
+#endif
+
+#ifdef HAVE_WCHAR_T
+# ifdef HAVE_WCSLEN
+#  define local_wcslen wcslen
+# else
+   /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid
+      a dependency towards this library, here is a local substitute.
+      Define this substitute only once, even if this file is included
+      twice in the same compilation unit.  */
+#  ifndef local_wcslen_defined
+#   define local_wcslen_defined 1
+static size_t
+local_wcslen (const wchar_t *s)
+{
+  const wchar_t *ptr;
+
+  for (ptr = s; *ptr != (wchar_t) 0; ptr++)
+    ;
+  return ptr - s;
+}
+#  endif
+# endif
+#endif
+
+#if WIDE_CHAR_VERSION
+# define VASNPRINTF vasnwprintf
+# define CHAR_T wchar_t
+# define DIRECTIVE wchar_t_directive
+# define DIRECTIVES wchar_t_directives
+# define PRINTF_PARSE wprintf_parse
+# define USE_SNPRINTF 1
+# if HAVE_DECL__SNWPRINTF
+   /* On Windows, the function swprintf() has a different signature than
+      on Unix; we use the _snwprintf() function instead.  */
+#  define SNPRINTF _snwprintf
+# else
+   /* Unix.  */
+#  define SNPRINTF swprintf
+# endif
+#else
+# define VASNPRINTF vasnprintf
+# define CHAR_T char
+# define DIRECTIVE char_directive
+# define DIRECTIVES char_directives
+# define PRINTF_PARSE printf_parse
+# define USE_SNPRINTF (HAVE_DECL__SNPRINTF || HAVE_SNPRINTF)
+# if HAVE_DECL__SNPRINTF
+   /* Windows.  */
+#  define SNPRINTF _snprintf
+# else
+   /* Unix.  */
+#  define SNPRINTF snprintf
+# endif
+#endif
+
+CHAR_T *
+VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list args)
+{
+  DIRECTIVES d;
+  arguments a;
+
+  if (PRINTF_PARSE (format, &d, &a) < 0)
+    {
+      errno = EINVAL;
+      return NULL;
+    }
+
+#define CLEANUP() \
+  free (d.dir);                                                                \
+  if (a.arg)                                                           \
+    free (a.arg);
+
+  if (printf_fetchargs (args, &a) < 0)
+    {
+      CLEANUP ();
+      errno = EINVAL;
+      return NULL;
+    }
+
+  {
+    size_t buf_neededlength;
+    CHAR_T *buf;
+    CHAR_T *buf_malloced;
+    const CHAR_T *cp;
+    size_t i;
+    DIRECTIVE *dp;
+    /* Output string accumulator.  */
+    CHAR_T *result;
+    size_t allocated;
+    size_t length;
+
+    /* Allocate a small buffer that will hold a directive passed to
+       sprintf or snprintf.  */
+    buf_neededlength =
+      xsum4 (7, d.max_width_length, d.max_precision_length, 6);
+#if HAVE_ALLOCA
+    if (buf_neededlength < 4000 / sizeof (CHAR_T))
+      {
+       buf = (CHAR_T *) alloca (buf_neededlength * sizeof (CHAR_T));
+       buf_malloced = NULL;
+      }
+    else
+#endif
+      {
+       size_t buf_memsize = xtimes (buf_neededlength, sizeof (CHAR_T));
+       if (size_overflow_p (buf_memsize))
+         goto out_of_memory_1;
+       buf = (CHAR_T *) malloc (buf_memsize);
+       if (buf == NULL)
+         goto out_of_memory_1;
+       buf_malloced = buf;
+      }
+
+    if (resultbuf != NULL)
+      {
+       result = resultbuf;
+       allocated = *lengthp;
+      }
+    else
+      {
+       result = NULL;
+       allocated = 0;
+      }
+    length = 0;
+    /* Invariants:
+       result is either == resultbuf or == NULL or malloc-allocated.
+       If length > 0, then result != NULL.  */
+
+    /* Ensures that allocated >= needed.  Aborts through a jump to
+       out_of_memory if needed is SIZE_MAX or otherwise too big.  */
+#define ENSURE_ALLOCATION(needed) \
+    if ((needed) > allocated)                                               \
+      {                                                                             \
+       size_t memory_size;                                                  \
+       CHAR_T *memory;                                                      \
+                                                                            \
+       allocated = (allocated > 0 ? xtimes (allocated, 2) : 12);            \
+       if ((needed) > allocated)                                            \
+         allocated = (needed);                                              \
+       memory_size = xtimes (allocated, sizeof (CHAR_T));                   \
+       if (size_overflow_p (memory_size))                                   \
+         goto out_of_memory;                                                \
+       if (result == resultbuf || result == NULL)                           \
+         memory = (CHAR_T *) malloc (memory_size);                          \
+       else                                                                 \
+         memory = (CHAR_T *) realloc (result, memory_size);                 \
+       if (memory == NULL)                                                  \
+         goto out_of_memory;                                                \
+       if (result == resultbuf && length > 0)                               \
+         memcpy (memory, result, length * sizeof (CHAR_T));                 \
+       result = memory;                                                     \
+      }
+
+    for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++)
+      {
+       if (cp != dp->dir_start)
+         {
+           size_t n = dp->dir_start - cp;
+           size_t augmented_length = xsum (length, n);
+
+           ENSURE_ALLOCATION (augmented_length);
+           memcpy (result + length, cp, n * sizeof (CHAR_T));
+           length = augmented_length;
+         }
+       if (i == d.count)
+         break;
+
+       /* Execute a single directive.  */
+       if (dp->conversion == '%')
+         {
+           size_t augmented_length;
+
+           if (!(dp->arg_index == ARG_NONE))
+             abort ();
+           augmented_length = xsum (length, 1);
+           ENSURE_ALLOCATION (augmented_length);
+           result[length] = '%';
+           length = augmented_length;
+         }
+       else
+         {
+           if (!(dp->arg_index != ARG_NONE))
+             abort ();
+
+           if (dp->conversion == 'n')
+             {
+               switch (a.arg[dp->arg_index].type)
+                 {
+                 case TYPE_COUNT_SCHAR_POINTER:
+                   *a.arg[dp->arg_index].a.a_count_schar_pointer = length;
+                   break;
+                 case TYPE_COUNT_SHORT_POINTER:
+                   *a.arg[dp->arg_index].a.a_count_short_pointer = length;
+                   break;
+                 case TYPE_COUNT_INT_POINTER:
+                   *a.arg[dp->arg_index].a.a_count_int_pointer = length;
+                   break;
+                 case TYPE_COUNT_LONGINT_POINTER:
+                   *a.arg[dp->arg_index].a.a_count_longint_pointer = length;
+                   break;
+#ifdef HAVE_LONG_LONG
+                 case TYPE_COUNT_LONGLONGINT_POINTER:
+                   *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length;
+                   break;
+#endif
+                 default:
+                   abort ();
+                 }
+             }
+           else
+             {
+               arg_type type = a.arg[dp->arg_index].type;
+               CHAR_T *p;
+               unsigned int prefix_count;
+               int prefixes[2];
+#if !USE_SNPRINTF
+               size_t tmp_length;
+               CHAR_T tmpbuf[700];
+               CHAR_T *tmp;
+
+               /* Allocate a temporary buffer of sufficient size for calling
+                  sprintf.  */
+               {
+                 size_t width;
+                 size_t precision;
+
+                 width = 0;
+                 if (dp->width_start != dp->width_end)
+                   {
+                     if (dp->width_arg_index != ARG_NONE)
+                       {
+                         int arg;
+
+                         if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
+                           abort ();
+                         arg = a.arg[dp->width_arg_index].a.a_int;
+                         width = (arg < 0 ? (unsigned int) (-arg) : arg);
+                       }
+                     else
+                       {
+                         const CHAR_T *digitp = dp->width_start;
+
+                         do
+                           width = xsum (xtimes (width, 10), *digitp++ - '0');
+                         while (digitp != dp->width_end);
+                       }
+                   }
+
+                 precision = 6;
+                 if (dp->precision_start != dp->precision_end)
+                   {
+                     if (dp->precision_arg_index != ARG_NONE)
+                       {
+                         int arg;
+
+                         if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
+                           abort ();
+                         arg = a.arg[dp->precision_arg_index].a.a_int;
+                         precision = (arg < 0 ? 0 : arg);
+                       }
+                     else
+                       {
+                         const CHAR_T *digitp = dp->precision_start + 1;
+
+                         precision = 0;
+                         while (digitp != dp->precision_end)
+                           precision = xsum (xtimes (precision, 10), *digitp++ - '0');
+                       }
+                   }
+
+                 switch (dp->conversion)
+                   {
+
+                   case 'd': case 'i': case 'u':
+# ifdef HAVE_LONG_LONG
+                     if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
+                       tmp_length =
+                         (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
+                                         * 0.30103 /* binary -> decimal */
+                                         * 2 /* estimate for FLAG_GROUP */
+                                        )
+                         + 1 /* turn floor into ceil */
+                         + 1; /* account for leading sign */
+                     else
+# endif
+                     if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
+                       tmp_length =
+                         (unsigned int) (sizeof (unsigned long) * CHAR_BIT
+                                         * 0.30103 /* binary -> decimal */
+                                         * 2 /* estimate for FLAG_GROUP */
+                                        )
+                         + 1 /* turn floor into ceil */
+                         + 1; /* account for leading sign */
+                     else
+                       tmp_length =
+                         (unsigned int) (sizeof (unsigned int) * CHAR_BIT
+                                         * 0.30103 /* binary -> decimal */
+                                         * 2 /* estimate for FLAG_GROUP */
+                                        )
+                         + 1 /* turn floor into ceil */
+                         + 1; /* account for leading sign */
+                     break;
+
+                   case 'o':
+# ifdef HAVE_LONG_LONG
+                     if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
+                       tmp_length =
+                         (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
+                                         * 0.333334 /* binary -> octal */
+                                        )
+                         + 1 /* turn floor into ceil */
+                         + 1; /* account for leading sign */
+                     else
+# endif
+                     if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
+                       tmp_length =
+                         (unsigned int) (sizeof (unsigned long) * CHAR_BIT
+                                         * 0.333334 /* binary -> octal */
+                                        )
+                         + 1 /* turn floor into ceil */
+                         + 1; /* account for leading sign */
+                     else
+                       tmp_length =
+                         (unsigned int) (sizeof (unsigned int) * CHAR_BIT
+                                         * 0.333334 /* binary -> octal */
+                                        )
+                         + 1 /* turn floor into ceil */
+                         + 1; /* account for leading sign */
+                     break;
+
+                   case 'x': case 'X':
+# ifdef HAVE_LONG_LONG
+                     if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
+                       tmp_length =
+                         (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
+                                         * 0.25 /* binary -> hexadecimal */
+                                        )
+                         + 1 /* turn floor into ceil */
+                         + 2; /* account for leading sign or alternate form */
+                     else
+# endif
+                     if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
+                       tmp_length =
+                         (unsigned int) (sizeof (unsigned long) * CHAR_BIT
+                                         * 0.25 /* binary -> hexadecimal */
+                                        )
+                         + 1 /* turn floor into ceil */
+                         + 2; /* account for leading sign or alternate form */
+                     else
+                       tmp_length =
+                         (unsigned int) (sizeof (unsigned int) * CHAR_BIT
+                                         * 0.25 /* binary -> hexadecimal */
+                                        )
+                         + 1 /* turn floor into ceil */
+                         + 2; /* account for leading sign or alternate form */
+                     break;
+
+                   case 'f': case 'F':
+# ifdef HAVE_LONG_DOUBLE
+                     if (type == TYPE_LONGDOUBLE)
+                       tmp_length =
+                         (unsigned int) (LDBL_MAX_EXP
+                                         * 0.30103 /* binary -> decimal */
+                                         * 2 /* estimate for FLAG_GROUP */
+                                        )
+                         + 1 /* turn floor into ceil */
+                         + 10; /* sign, decimal point etc. */
+                     else
+# endif
+                       tmp_length =
+                         (unsigned int) (DBL_MAX_EXP
+                                         * 0.30103 /* binary -> decimal */
+                                         * 2 /* estimate for FLAG_GROUP */
+                                        )
+                         + 1 /* turn floor into ceil */
+                         + 10; /* sign, decimal point etc. */
+                     tmp_length = xsum (tmp_length, precision);
+                     break;
+
+                   case 'e': case 'E': case 'g': case 'G':
+                   case 'a': case 'A':
+                     tmp_length =
+                       12; /* sign, decimal point, exponent etc. */
+                     tmp_length = xsum (tmp_length, precision);
+                     break;
+
+                   case 'c':
+# if defined HAVE_WINT_T && !WIDE_CHAR_VERSION
+                     if (type == TYPE_WIDE_CHAR)
+                       tmp_length = MB_CUR_MAX;
+                     else
+# endif
+                       tmp_length = 1;
+                     break;
+
+                   case 's':
+# ifdef HAVE_WCHAR_T
+                     if (type == TYPE_WIDE_STRING)
+                       {
+                         tmp_length =
+                           local_wcslen (a.arg[dp->arg_index].a.a_wide_string);
+
+#  if !WIDE_CHAR_VERSION
+                         tmp_length = xtimes (tmp_length, MB_CUR_MAX);
+#  endif
+                       }
+                     else
+# endif
+                       tmp_length = strlen (a.arg[dp->arg_index].a.a_string);
+                     break;
+
+                   case 'p':
+                     tmp_length =
+                       (unsigned int) (sizeof (void *) * CHAR_BIT
+                                       * 0.25 /* binary -> hexadecimal */
+                                      )
+                         + 1 /* turn floor into ceil */
+                         + 2; /* account for leading 0x */
+                     break;
+
+                   default:
+                     abort ();
+                   }
+
+                 if (tmp_length < width)
+                   tmp_length = width;
+
+                 tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
+               }
+
+               if (tmp_length <= sizeof (tmpbuf) / sizeof (CHAR_T))
+                 tmp = tmpbuf;
+               else
+                 {
+                   size_t tmp_memsize = xtimes (tmp_length, sizeof (CHAR_T));
+
+                   if (size_overflow_p (tmp_memsize))
+                     /* Overflow, would lead to out of memory.  */
+                     goto out_of_memory;
+                   tmp = (CHAR_T *) malloc (tmp_memsize);
+                   if (tmp == NULL)
+                     /* Out of memory.  */
+                     goto out_of_memory;
+                 }
+#endif
+
+               /* Construct the format string for calling snprintf or
+                  sprintf.  */
+               p = buf;
+               *p++ = '%';
+               if (dp->flags & FLAG_GROUP)
+                 *p++ = '\'';
+               if (dp->flags & FLAG_LEFT)
+                 *p++ = '-';
+               if (dp->flags & FLAG_SHOWSIGN)
+                 *p++ = '+';
+               if (dp->flags & FLAG_SPACE)
+                 *p++ = ' ';
+               if (dp->flags & FLAG_ALT)
+                 *p++ = '#';
+               if (dp->flags & FLAG_ZERO)
+                 *p++ = '0';
+               if (dp->width_start != dp->width_end)
+                 {
+                   size_t n = dp->width_end - dp->width_start;
+                   memcpy (p, dp->width_start, n * sizeof (CHAR_T));
+                   p += n;
+                 }
+               if (dp->precision_start != dp->precision_end)
+                 {
+                   size_t n = dp->precision_end - dp->precision_start;
+                   memcpy (p, dp->precision_start, n * sizeof (CHAR_T));
+                   p += n;
+                 }
+
+               switch (type)
+                 {
+#ifdef HAVE_LONG_LONG
+                 case TYPE_LONGLONGINT:
+                 case TYPE_ULONGLONGINT:
+                   *p++ = 'l';
+                   /*FALLTHROUGH*/
+#endif
+                 case TYPE_LONGINT:
+                 case TYPE_ULONGINT:
+#ifdef HAVE_WINT_T
+                 case TYPE_WIDE_CHAR:
+#endif
+#ifdef HAVE_WCHAR_T
+                 case TYPE_WIDE_STRING:
+#endif
+                   *p++ = 'l';
+                   break;
+#ifdef HAVE_LONG_DOUBLE
+                 case TYPE_LONGDOUBLE:
+                   *p++ = 'L';
+                   break;
+#endif
+                 default:
+                   break;
+                 }
+               *p = dp->conversion;
+#if USE_SNPRINTF
+               p[1] = '%';
+               p[2] = 'n';
+               p[3] = '\0';
+#else
+               p[1] = '\0';
+#endif
+
+               /* Construct the arguments for calling snprintf or sprintf.  */
+               prefix_count = 0;
+               if (dp->width_arg_index != ARG_NONE)
+                 {
+                   if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
+                     abort ();
+                   prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int;
+                 }
+               if (dp->precision_arg_index != ARG_NONE)
+                 {
+                   if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
+                     abort ();
+                   prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int;
+                 }
+
+#if USE_SNPRINTF
+               /* Prepare checking whether snprintf returns the count
+                  via %n.  */
+               ENSURE_ALLOCATION (xsum (length, 1));
+               result[length] = '\0';
+#endif
+
+               for (;;)
+                 {
+                   size_t maxlen;
+                   int count;
+                   int retcount;
+
+                   maxlen = allocated - length;
+                   count = -1;
+                   retcount = 0;
+
+#if USE_SNPRINTF
+# define SNPRINTF_BUF(arg) \
+                   switch (prefix_count)                                   \
+                     {                                                     \
+                     case 0:                                               \
+                       retcount = SNPRINTF (result + length, maxlen, buf,  \
+                                            arg, &count);                  \
+                       break;                                              \
+                     case 1:                                               \
+                       retcount = SNPRINTF (result + length, maxlen, buf,  \
+                                            prefixes[0], arg, &count);     \
+                       break;                                              \
+                     case 2:                                               \
+                       retcount = SNPRINTF (result + length, maxlen, buf,  \
+                                            prefixes[0], prefixes[1], arg, \
+                                            &count);                       \
+                       break;                                              \
+                     default:                                              \
+                       abort ();                                           \
+                     }
+#else
+# define SNPRINTF_BUF(arg) \
+                   switch (prefix_count)                                   \
+                     {                                                     \
+                     case 0:                                               \
+                       count = sprintf (tmp, buf, arg);                    \
+                       break;                                              \
+                     case 1:                                               \
+                       count = sprintf (tmp, buf, prefixes[0], arg);       \
+                       break;                                              \
+                     case 2:                                               \
+                       count = sprintf (tmp, buf, prefixes[0], prefixes[1],\
+                                        arg);                              \
+                       break;                                              \
+                     default:                                              \
+                       abort ();                                           \
+                     }
+#endif
+
+                   switch (type)
+                     {
+                     case TYPE_SCHAR:
+                       {
+                         int arg = a.arg[dp->arg_index].a.a_schar;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+                     case TYPE_UCHAR:
+                       {
+                         unsigned int arg = a.arg[dp->arg_index].a.a_uchar;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+                     case TYPE_SHORT:
+                       {
+                         int arg = a.arg[dp->arg_index].a.a_short;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+                     case TYPE_USHORT:
+                       {
+                         unsigned int arg = a.arg[dp->arg_index].a.a_ushort;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+                     case TYPE_INT:
+                       {
+                         int arg = a.arg[dp->arg_index].a.a_int;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+                     case TYPE_UINT:
+                       {
+                         unsigned int arg = a.arg[dp->arg_index].a.a_uint;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+                     case TYPE_LONGINT:
+                       {
+                         long int arg = a.arg[dp->arg_index].a.a_longint;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+                     case TYPE_ULONGINT:
+                       {
+                         unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+#ifdef HAVE_LONG_LONG
+                     case TYPE_LONGLONGINT:
+                       {
+                         long long int arg = a.arg[dp->arg_index].a.a_longlongint;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+                     case TYPE_ULONGLONGINT:
+                       {
+                         unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+#endif
+                     case TYPE_DOUBLE:
+                       {
+                         double arg = a.arg[dp->arg_index].a.a_double;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+#ifdef HAVE_LONG_DOUBLE
+                     case TYPE_LONGDOUBLE:
+                       {
+                         long double arg = a.arg[dp->arg_index].a.a_longdouble;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+#endif
+                     case TYPE_CHAR:
+                       {
+                         int arg = a.arg[dp->arg_index].a.a_char;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+#ifdef HAVE_WINT_T
+                     case TYPE_WIDE_CHAR:
+                       {
+                         wint_t arg = a.arg[dp->arg_index].a.a_wide_char;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+#endif
+                     case TYPE_STRING:
+                       {
+                         const char *arg = a.arg[dp->arg_index].a.a_string;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+#ifdef HAVE_WCHAR_T
+                     case TYPE_WIDE_STRING:
+                       {
+                         const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+#endif
+                     case TYPE_POINTER:
+                       {
+                         void *arg = a.arg[dp->arg_index].a.a_pointer;
+                         SNPRINTF_BUF (arg);
+                       }
+                       break;
+                     default:
+                       abort ();
+                     }
+
+#if USE_SNPRINTF
+                   /* Portability: Not all implementations of snprintf()
+                      are ISO C 99 compliant.  Determine the number of
+                      bytes that snprintf() has produced or would have
+                      produced.  */
+                   if (count >= 0)
+                     {
+                       /* Verify that snprintf() has NUL-terminated its
+                          result.  */
+                       if (count < maxlen && result[length + count] != '\0')
+                         abort ();
+                       /* Portability hack.  */
+                       if (retcount > count)
+                         count = retcount;
+                     }
+                   else
+                     {
+                       /* snprintf() doesn't understand the '%n'
+                          directive.  */
+                       if (p[1] != '\0')
+                         {
+                           /* Don't use the '%n' directive; instead, look
+                              at the snprintf() return value.  */
+                           p[1] = '\0';
+                           continue;
+                         }
+                       else
+                         {
+                           /* Look at the snprintf() return value.  */
+                           if (retcount < 0)
+                             {
+                               /* HP-UX 10.20 snprintf() is doubly deficient:
+                                  It doesn't understand the '%n' directive,
+                                  *and* it returns -1 (rather than the length
+                                  that would have been required) when the
+                                  buffer is too small.  */
+                               size_t bigger_need =
+                                 xsum (xtimes (allocated, 2), 12);
+                               ENSURE_ALLOCATION (bigger_need);
+                               continue;
+                             }
+                           else
+                             count = retcount;
+                         }
+                     }
+#endif
+
+                   /* Attempt to handle failure.  */
+                   if (count < 0)
+                     {
+                       if (!(result == resultbuf || result == NULL))
+                         free (result);
+                       if (buf_malloced != NULL)
+                         free (buf_malloced);
+                       CLEANUP ();
+                       errno = EINVAL;
+                       return NULL;
+                     }
+
+#if !USE_SNPRINTF
+                   if (count >= tmp_length)
+                     /* tmp_length was incorrectly calculated - fix the
+                        code above!  */
+                     abort ();
+#endif
+
+                   /* Make room for the result.  */
+                   if (count >= maxlen)
+                     {
+                       /* Need at least count bytes.  But allocate
+                          proportionally, to avoid looping eternally if
+                          snprintf() reports a too small count.  */
+                       size_t n =
+                         xmax (xsum (length, count), xtimes (allocated, 2));
+
+                       ENSURE_ALLOCATION (n);
+#if USE_SNPRINTF
+                       continue;
+#endif
+                     }
+
+#if USE_SNPRINTF
+                   /* The snprintf() result did fit.  */
+#else
+                   /* Append the sprintf() result.  */
+                   memcpy (result + length, tmp, count * sizeof (CHAR_T));
+                   if (tmp != tmpbuf)
+                     free (tmp);
+#endif
+
+                   length += count;
+                   break;
+                 }
+             }
+         }
+      }
+
+    /* Add the final NUL.  */
+    ENSURE_ALLOCATION (xsum (length, 1));
+    result[length] = '\0';
+
+    if (result != resultbuf && length + 1 < allocated)
+      {
+       /* Shrink the allocated memory if possible.  */
+       CHAR_T *memory;
+
+       memory = (CHAR_T *) realloc (result, (length + 1) * sizeof (CHAR_T));
+       if (memory != NULL)
+         result = memory;
+      }
+
+    if (buf_malloced != NULL)
+      free (buf_malloced);
+    CLEANUP ();
+    *lengthp = length;
+    if (length > INT_MAX)
+      goto length_overflow;
+    return result;
+
+  length_overflow:
+    /* We could produce such a big string, but its length doesn't fit into
+       an 'int'.  POSIX says that snprintf() fails with errno = EOVERFLOW in
+       this case.  */
+    if (result != resultbuf)
+      free (result);
+    errno = EOVERFLOW;
+    return NULL;
+
+  out_of_memory:
+    if (!(result == resultbuf || result == NULL))
+      free (result);
+    if (buf_malloced != NULL)
+      free (buf_malloced);
+  out_of_memory_1:
+    CLEANUP ();
+    errno = ENOMEM;
+    return NULL;
+  }
+}
+
+#undef SNPRINTF
+#undef USE_SNPRINTF
+#undef PRINTF_PARSE
+#undef DIRECTIVES
+#undef DIRECTIVE
+#undef CHAR_T
+#undef VASNPRINTF
diff --git a/intl/vasnprintf.h b/intl/vasnprintf.h
new file mode 100644 (file)
index 0000000..84da208
--- /dev/null
@@ -0,0 +1,78 @@
+/* vsprintf with automatic memory allocation.
+   Copyright (C) 2002-2004 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifndef _VASNPRINTF_H
+#define _VASNPRINTF_H
+
+/* Get va_list.  */
+#include <stdarg.h>
+
+/* Get size_t.  */
+#include <stddef.h>
+
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
+#  define __attribute__(Spec) /* empty */
+# endif
+/* The __-protected variants of `format' and `printf' attributes
+   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+#  define __format__ format
+#  define __printf__ printf
+# endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Write formatted output to a string dynamically allocated with malloc().
+   You can pass a preallocated buffer for the result in RESULTBUF and its
+   size in *LENGTHP; otherwise you pass RESULTBUF = NULL.
+   If successful, return the address of the string (this may be = RESULTBUF
+   if no dynamic memory allocation was necessary) and set *LENGTHP to the
+   number of resulting bytes, excluding the trailing NUL.  Upon error, set
+   errno and return NULL.
+
+   When dynamic memory allocation occurs, the preallocated buffer is left
+   alone (with possibly modified contents).  This makes it possible to use
+   a statically allocated or stack-allocated buffer, like this:
+
+          char buf[100];
+          size_t len = sizeof (buf);
+          char *output = vasnprintf (buf, &len, format, args);
+          if (output == NULL)
+            ... error handling ...;
+          else
+            {
+              ... use the output string ...;
+              if (output != buf)
+                free (output);
+            }
+  */
+extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
+       __attribute__ ((__format__ (__printf__, 3, 4)));
+extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
+       __attribute__ ((__format__ (__printf__, 3, 0)));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VASNPRINTF_H */
diff --git a/intl/vasnwprintf.h b/intl/vasnwprintf.h
new file mode 100644 (file)
index 0000000..d3cef4c
--- /dev/null
@@ -0,0 +1,46 @@
+/* vswprintf with automatic memory allocation.
+   Copyright (C) 2002-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifndef _VASNWPRINTF_H
+#define _VASNWPRINTF_H
+
+/* Get va_list.  */
+#include <stdarg.h>
+
+/* Get wchar_t, size_t.  */
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Write formatted output to a string dynamically allocated with malloc().
+   You can pass a preallocated buffer for the result in RESULTBUF and its
+   size in *LENGTHP; otherwise you pass RESULTBUF = NULL.
+   If successful, return the address of the string (this may be = RESULTBUF
+   if no dynamic memory allocation was necessary) and set *LENGTHP to the
+   number of resulting bytes, excluding the trailing NUL.  Upon error, set
+   errno and return NULL.  */
+extern wchar_t * asnwprintf (wchar_t *resultbuf, size_t *lengthp, const wchar_t *format, ...);
+extern wchar_t * vasnwprintf (wchar_t *resultbuf, size_t *lengthp, const wchar_t *format, va_list args);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VASNWPRINTF_H */
diff --git a/intl/wprintf-parse.h b/intl/wprintf-parse.h
new file mode 100644 (file)
index 0000000..24a2cfc
--- /dev/null
@@ -0,0 +1,75 @@
+/* Parse printf format string.
+   Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifndef _WPRINTF_PARSE_H
+#define _WPRINTF_PARSE_H
+
+#include "printf-args.h"
+
+
+/* Flags */
+#define FLAG_GROUP      1      /* ' flag */
+#define FLAG_LEFT       2      /* - flag */
+#define FLAG_SHOWSIGN   4      /* + flag */
+#define FLAG_SPACE      8      /* space flag */
+#define FLAG_ALT       16      /* # flag */
+#define FLAG_ZERO      32
+
+/* arg_index value indicating that no argument is consumed.  */
+#define ARG_NONE       (~(size_t)0)
+
+/* A parsed directive.  */
+typedef struct
+{
+  const wchar_t* dir_start;
+  const wchar_t* dir_end;
+  int flags;
+  const wchar_t* width_start;
+  const wchar_t* width_end;
+  size_t width_arg_index;
+  const wchar_t* precision_start;
+  const wchar_t* precision_end;
+  size_t precision_arg_index;
+  wchar_t conversion; /* d i o u x X f e E g G c s p n U % but not C S */
+  size_t arg_index;
+}
+wchar_t_directive;
+
+/* A parsed format string.  */
+typedef struct
+{
+  size_t count;
+  wchar_t_directive *dir;
+  size_t max_width_length;
+  size_t max_precision_length;
+}
+wchar_t_directives;
+
+
+/* Parses the format string.  Fills in the number N of directives, and fills
+   in directives[0], ..., directives[N-1], and sets directives[N].dir_start
+   to the end of the format string.  Also fills in the arg_type fields of the
+   arguments and the needed count of arguments.  */
+#ifdef STATIC
+STATIC
+#else
+extern
+#endif
+int wprintf_parse (const wchar_t *format, wchar_t_directives *d, arguments *a);
+
+#endif /* _WPRINTF_PARSE_H */
diff --git a/intl/xsize.h b/intl/xsize.h
new file mode 100644 (file)
index 0000000..362e24b
--- /dev/null
@@ -0,0 +1,109 @@
+/* xsize.h -- Checked size_t computations.
+
+   Copyright (C) 2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+   USA.  */
+
+#ifndef _XSIZE_H
+#define _XSIZE_H
+
+/* Get size_t.  */
+#include <stddef.h>
+
+/* Get SIZE_MAX.  */
+#include <limits.h>
+#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+
+/* The size of memory objects is often computed through expressions of
+   type size_t. Example:
+      void* p = malloc (header_size + n * element_size).
+   These computations can lead to overflow.  When this happens, malloc()
+   returns a piece of memory that is way too small, and the program then
+   crashes while attempting to fill the memory.
+   To avoid this, the functions and macros in this file check for overflow.
+   The convention is that SIZE_MAX represents overflow.
+   malloc (SIZE_MAX) is not guaranteed to fail -- think of a malloc
+   implementation that uses mmap --, it's recommended to use size_overflow_p()
+   or size_in_bounds_p() before invoking malloc().
+   The example thus becomes:
+      size_t size = xsum (header_size, xtimes (n, element_size));
+      void *p = (size_in_bounds_p (size) ? malloc (size) : NULL);
+*/
+
+/* Convert an arbitrary value >= 0 to type size_t.  */
+#define xcast_size_t(N) \
+  ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX)
+
+/* Sum of two sizes, with overflow check.  */
+static inline size_t
+#if __GNUC__ >= 3
+__attribute__ ((__pure__))
+#endif
+xsum (size_t size1, size_t size2)
+{
+  size_t sum = size1 + size2;
+  return (sum >= size1 ? sum : SIZE_MAX);
+}
+
+/* Sum of three sizes, with overflow check.  */
+static inline size_t
+#if __GNUC__ >= 3
+__attribute__ ((__pure__))
+#endif
+xsum3 (size_t size1, size_t size2, size_t size3)
+{
+  return xsum (xsum (size1, size2), size3);
+}
+
+/* Sum of four sizes, with overflow check.  */
+static inline size_t
+#if __GNUC__ >= 3
+__attribute__ ((__pure__))
+#endif
+xsum4 (size_t size1, size_t size2, size_t size3, size_t size4)
+{
+  return xsum (xsum (xsum (size1, size2), size3), size4);
+}
+
+/* Maximum of two sizes, with overflow check.  */
+static inline size_t
+#if __GNUC__ >= 3
+__attribute__ ((__pure__))
+#endif
+xmax (size_t size1, size_t size2)
+{
+  /* No explicit check is needed here, because for any n:
+     max (SIZE_MAX, n) == SIZE_MAX and max (n, SIZE_MAX) == SIZE_MAX.  */
+  return (size1 >= size2 ? size1 : size2);
+}
+
+/* Multiplication of a count with an element size, with overflow check.
+   The count must be >= 0 and the element size must be > 0.
+   This is a macro, not an inline function, so that it works correctly even
+   when N is of a wider tupe and N > SIZE_MAX.  */
+#define xtimes(N, ELSIZE) \
+  ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX)
+
+/* Check for overflow.  */
+#define size_overflow_p(SIZE) \
+  ((SIZE) == SIZE_MAX)
+/* Check against overflow.  */
+#define size_in_bounds_p(SIZE) \
+  ((SIZE) != SIZE_MAX)
+
+#endif /* _XSIZE_H */
diff --git a/ltmain.sh b/ltmain.sh
new file mode 100755 (executable)
index 0000000..3506ead
--- /dev/null
+++ b/ltmain.sh
@@ -0,0 +1,8413 @@
+# Generated from ltmain.m4sh.
+
+# ltmain.sh (GNU libtool) 2.2.6
+# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
+
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007 2008 Free Software Foundation, Inc.
+# This is free software; see the source for copying conditions.  There is NO
+# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# GNU Libtool is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# As a special exception to the GNU General Public License,
+# if you distribute this file as part of a program or library that
+# is built using GNU Libtool, you may include this file under the
+# same distribution terms that you use for the rest of that program.
+#
+# GNU Libtool 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Libtool; see the file COPYING.  If not, a copy
+# can be downloaded from http://www.gnu.org/licenses/gpl.html,
+# or obtained by writing to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# Usage: $progname [OPTION]... [MODE-ARG]...
+#
+# Provide generalized library-building support services.
+#
+#     --config             show all configuration variables
+#     --debug              enable verbose shell tracing
+# -n, --dry-run            display commands without modifying any files
+#     --features           display basic configuration information and exit
+#     --mode=MODE          use operation mode MODE
+#     --preserve-dup-deps  don't remove duplicate dependency libraries
+#     --quiet, --silent    don't print informational messages
+#     --tag=TAG            use configuration variables from tag TAG
+# -v, --verbose            print informational messages (default)
+#     --version            print version information
+# -h, --help               print short or long help message
+#
+# MODE must be one of the following:
+#
+#       clean              remove files from the build directory
+#       compile            compile a source file into a libtool object
+#       execute            automatically set library path, then run a program
+#       finish             complete the installation of libtool libraries
+#       install            install libraries or executables
+#       link               create a library or an executable
+#       uninstall          remove libraries from an installed directory
+#
+# MODE-ARGS vary depending on the MODE.
+# Try `$progname --help --mode=MODE' for a more detailed description of MODE.
+#
+# When reporting a bug, please describe a test case to reproduce it and
+# include the following information:
+#
+#       host-triplet:  $host
+#       shell:         $SHELL
+#       compiler:              $LTCC
+#       compiler flags:                $LTCFLAGS
+#       linker:                $LD (gnu? $with_gnu_ld)
+#       $progname:             (GNU libtool) 2.2.6 Debian-2.2.6a-4
+#       automake:              $automake_version
+#       autoconf:              $autoconf_version
+#
+# Report bugs to <bug-libtool@gnu.org>.
+
+PROGRAM=ltmain.sh
+PACKAGE=libtool
+VERSION="2.2.6 Debian-2.2.6a-4"
+TIMESTAMP=""
+package_revision=1.3012
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# NLS nuisances: We save the old values to restore during execute mode.
+# Only set LANG and LC_ALL to C if already set.
+# These must not be set unconditionally because not all systems understand
+# e.g. LANG=C (notably SCO).
+lt_user_locale=
+lt_safe_locale=
+for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
+do
+  eval "if test \"\${$lt_var+set}\" = set; then
+          save_$lt_var=\$$lt_var
+          $lt_var=C
+         export $lt_var
+         lt_user_locale=\"$lt_var=\\\$save_\$lt_var; \$lt_user_locale\"
+         lt_safe_locale=\"$lt_var=C; \$lt_safe_locale\"
+       fi"
+done
+
+$lt_unset CDPATH
+
+
+
+
+
+: ${CP="cp -f"}
+: ${ECHO="echo"}
+: ${EGREP="/bin/grep -E"}
+: ${FGREP="/bin/grep -F"}
+: ${GREP="/bin/grep"}
+: ${LN_S="ln -s"}
+: ${MAKE="make"}
+: ${MKDIR="mkdir"}
+: ${MV="mv -f"}
+: ${RM="rm -f"}
+: ${SED="/bin/sed"}
+: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
+: ${Xsed="$SED -e 1s/^X//"}
+
+# Global variables:
+EXIT_SUCCESS=0
+EXIT_FAILURE=1
+EXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
+EXIT_SKIP=77     # $? = 77 is used to indicate a skipped test to automake.
+
+exit_status=$EXIT_SUCCESS
+
+# Make sure IFS has a sensible default
+lt_nl='
+'
+IFS="  $lt_nl"
+
+dirname="s,/[^/]*$,,"
+basename="s,^.*/,,"
+
+# func_dirname_and_basename file append nondir_replacement
+# perform func_basename and func_dirname in a single function
+# call:
+#   dirname:  Compute the dirname of FILE.  If nonempty,
+#             add APPEND to the result, otherwise set result
+#             to NONDIR_REPLACEMENT.
+#             value returned in "$func_dirname_result"
+#   basename: Compute filename of FILE.
+#             value retuned in "$func_basename_result"
+# Implementation must be kept synchronized with func_dirname
+# and func_basename. For efficiency, we do not delegate to
+# those functions but instead duplicate the functionality here.
+func_dirname_and_basename ()
+{
+  # Extract subdirectory from the argument.
+  func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"`
+  if test "X$func_dirname_result" = "X${1}"; then
+    func_dirname_result="${3}"
+  else
+    func_dirname_result="$func_dirname_result${2}"
+  fi
+  func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
+}
+
+# Generated shell functions inserted here.
+
+# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
+# is ksh but when the shell is invoked as "sh" and the current value of
+# the _XPG environment variable is not equal to 1 (one), the special
+# positional parameter $0, within a function call, is the name of the
+# function.
+progpath="$0"
+
+# The name of this program:
+# In the unlikely event $progname began with a '-', it would play havoc with
+# func_echo (imagine progname=-n), so we prepend ./ in that case:
+func_dirname_and_basename "$progpath"
+progname=$func_basename_result
+case $progname in
+  -*) progname=./$progname ;;
+esac
+
+# Make sure we have an absolute path for reexecution:
+case $progpath in
+  [\\/]*|[A-Za-z]:\\*) ;;
+  *[\\/]*)
+     progdir=$func_dirname_result
+     progdir=`cd "$progdir" && pwd`
+     progpath="$progdir/$progname"
+     ;;
+  *)
+     save_IFS="$IFS"
+     IFS=:
+     for progdir in $PATH; do
+       IFS="$save_IFS"
+       test -x "$progdir/$progname" && break
+     done
+     IFS="$save_IFS"
+     test -n "$progdir" || progdir=`pwd`
+     progpath="$progdir/$progname"
+     ;;
+esac
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+Xsed="${SED}"' -e 1s/^X//'
+sed_quote_subst='s/\([`"$\\]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\(["`\\]\)/\\\1/g'
+
+# Re-`\' parameter expansions in output of double_quote_subst that were
+# `\'-ed in input to the same.  If an odd number of `\' preceded a '$'
+# in input to double_quote_subst, that '$' was protected from expansion.
+# Since each input `\' is now two `\'s, look for any number of runs of
+# four `\'s followed by two `\'s and then a '$'.  `\' that '$'.
+bs='\\'
+bs2='\\\\'
+bs4='\\\\\\\\'
+dollar='\$'
+sed_double_backslash="\
+  s/$bs4/&\\
+/g
+  s/^$bs2$dollar/$bs&/
+  s/\\([^$bs]\\)$bs2$dollar/\\1$bs2$bs$dollar/g
+  s/\n//g"
+
+# Standard options:
+opt_dry_run=false
+opt_help=false
+opt_quiet=false
+opt_verbose=false
+opt_warning=:
+
+# func_echo arg...
+# Echo program name prefixed message, along with the current mode
+# name if it has been set yet.
+func_echo ()
+{
+    $ECHO "$progname${mode+: }$mode: $*"
+}
+
+# func_verbose arg...
+# Echo program name prefixed message in verbose mode only.
+func_verbose ()
+{
+    $opt_verbose && func_echo ${1+"$@"}
+
+    # A bug in bash halts the script if the last line of a function
+    # fails when set -e is in force, so we need another command to
+    # work around that:
+    :
+}
+
+# func_error arg...
+# Echo program name prefixed message to standard error.
+func_error ()
+{
+    $ECHO "$progname${mode+: }$mode: "${1+"$@"} 1>&2
+}
+
+# func_warning arg...
+# Echo program name prefixed warning message to standard error.
+func_warning ()
+{
+    $opt_warning && $ECHO "$progname${mode+: }$mode: warning: "${1+"$@"} 1>&2
+
+    # bash bug again:
+    :
+}
+
+# func_fatal_error arg...
+# Echo program name prefixed message to standard error, and exit.
+func_fatal_error ()
+{
+    func_error ${1+"$@"}
+    exit $EXIT_FAILURE
+}
+
+# func_fatal_help arg...
+# Echo program name prefixed message to standard error, followed by
+# a help hint, and exit.
+func_fatal_help ()
+{
+    func_error ${1+"$@"}
+    func_fatal_error "$help"
+}
+help="Try \`$progname --help' for more information."  ## default
+
+
+# func_grep expression filename
+# Check whether EXPRESSION matches any line of FILENAME, without output.
+func_grep ()
+{
+    $GREP "$1" "$2" >/dev/null 2>&1
+}
+
+
+# func_mkdir_p directory-path
+# Make sure the entire path to DIRECTORY-PATH is available.
+func_mkdir_p ()
+{
+    my_directory_path="$1"
+    my_dir_list=
+
+    if test -n "$my_directory_path" && test "$opt_dry_run" != ":"; then
+
+      # Protect directory names starting with `-'
+      case $my_directory_path in
+        -*) my_directory_path="./$my_directory_path" ;;
+      esac
+
+      # While some portion of DIR does not yet exist...
+      while test ! -d "$my_directory_path"; do
+        # ...make a list in topmost first order.  Use a colon delimited
+       # list incase some portion of path contains whitespace.
+        my_dir_list="$my_directory_path:$my_dir_list"
+
+        # If the last portion added has no slash in it, the list is done
+        case $my_directory_path in */*) ;; *) break ;; esac
+
+        # ...otherwise throw away the child directory and loop
+        my_directory_path=`$ECHO "X$my_directory_path" | $Xsed -e "$dirname"`
+      done
+      my_dir_list=`$ECHO "X$my_dir_list" | $Xsed -e 's,:*$,,'`
+
+      save_mkdir_p_IFS="$IFS"; IFS=':'
+      for my_dir in $my_dir_list; do
+       IFS="$save_mkdir_p_IFS"
+        # mkdir can fail with a `File exist' error if two processes
+        # try to create one of the directories concurrently.  Don't
+        # stop in that case!
+        $MKDIR "$my_dir" 2>/dev/null || :
+      done
+      IFS="$save_mkdir_p_IFS"
+
+      # Bail out if we (or some other process) failed to create a directory.
+      test -d "$my_directory_path" || \
+        func_fatal_error "Failed to create \`$1'"
+    fi
+}
+
+
+# func_mktempdir [string]
+# Make a temporary directory that won't clash with other running
+# libtool processes, and avoids race conditions if possible.  If
+# given, STRING is the basename for that directory.
+func_mktempdir ()
+{
+    my_template="${TMPDIR-/tmp}/${1-$progname}"
+
+    if test "$opt_dry_run" = ":"; then
+      # Return a directory name, but don't create it in dry-run mode
+      my_tmpdir="${my_template}-$$"
+    else
+
+      # If mktemp works, use that first and foremost
+      my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null`
+
+      if test ! -d "$my_tmpdir"; then
+        # Failing that, at least try and use $RANDOM to avoid a race
+        my_tmpdir="${my_template}-${RANDOM-0}$$"
+
+        save_mktempdir_umask=`umask`
+        umask 0077
+        $MKDIR "$my_tmpdir"
+        umask $save_mktempdir_umask
+      fi
+
+      # If we're not in dry-run mode, bomb out on failure
+      test -d "$my_tmpdir" || \
+        func_fatal_error "cannot create temporary directory \`$my_tmpdir'"
+    fi
+
+    $ECHO "X$my_tmpdir" | $Xsed
+}
+
+
+# func_quote_for_eval arg
+# Aesthetically quote ARG to be evaled later.
+# This function returns two values: FUNC_QUOTE_FOR_EVAL_RESULT
+# is double-quoted, suitable for a subsequent eval, whereas
+# FUNC_QUOTE_FOR_EVAL_UNQUOTED_RESULT has merely all characters
+# which are still active within double quotes backslashified.
+func_quote_for_eval ()
+{
+    case $1 in
+      *[\\\`\"\$]*)
+       func_quote_for_eval_unquoted_result=`$ECHO "X$1" | $Xsed -e "$sed_quote_subst"` ;;
+      *)
+        func_quote_for_eval_unquoted_result="$1" ;;
+    esac
+
+    case $func_quote_for_eval_unquoted_result in
+      # Double-quote args containing shell metacharacters to delay
+      # word splitting, command substitution and and variable
+      # expansion for a subsequent eval.
+      # Many Bourne shells cannot handle close brackets correctly
+      # in scan sets, so we specify it separately.
+      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \    ]*|*]*|"")
+        func_quote_for_eval_result="\"$func_quote_for_eval_unquoted_result\""
+        ;;
+      *)
+        func_quote_for_eval_result="$func_quote_for_eval_unquoted_result"
+    esac
+}
+
+
+# func_quote_for_expand arg
+# Aesthetically quote ARG to be evaled later; same as above,
+# but do not quote variable references.
+func_quote_for_expand ()
+{
+    case $1 in
+      *[\\\`\"]*)
+       my_arg=`$ECHO "X$1" | $Xsed \
+           -e "$double_quote_subst" -e "$sed_double_backslash"` ;;
+      *)
+        my_arg="$1" ;;
+    esac
+
+    case $my_arg in
+      # Double-quote args containing shell metacharacters to delay
+      # word splitting and command substitution for a subsequent eval.
+      # Many Bourne shells cannot handle close brackets correctly
+      # in scan sets, so we specify it separately.
+      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \    ]*|*]*|"")
+        my_arg="\"$my_arg\""
+        ;;
+    esac
+
+    func_quote_for_expand_result="$my_arg"
+}
+
+
+# func_show_eval cmd [fail_exp]
+# Unless opt_silent is true, then output CMD.  Then, if opt_dryrun is
+# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
+# is given, then evaluate it.
+func_show_eval ()
+{
+    my_cmd="$1"
+    my_fail_exp="${2-:}"
+
+    ${opt_silent-false} || {
+      func_quote_for_expand "$my_cmd"
+      eval "func_echo $func_quote_for_expand_result"
+    }
+
+    if ${opt_dry_run-false}; then :; else
+      eval "$my_cmd"
+      my_status=$?
+      if test "$my_status" -eq 0; then :; else
+       eval "(exit $my_status); $my_fail_exp"
+      fi
+    fi
+}
+
+
+# func_show_eval_locale cmd [fail_exp]
+# Unless opt_silent is true, then output CMD.  Then, if opt_dryrun is
+# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
+# is given, then evaluate it.  Use the saved locale for evaluation.
+func_show_eval_locale ()
+{
+    my_cmd="$1"
+    my_fail_exp="${2-:}"
+
+    ${opt_silent-false} || {
+      func_quote_for_expand "$my_cmd"
+      eval "func_echo $func_quote_for_expand_result"
+    }
+
+    if ${opt_dry_run-false}; then :; else
+      eval "$lt_user_locale
+           $my_cmd"
+      my_status=$?
+      eval "$lt_safe_locale"
+      if test "$my_status" -eq 0; then :; else
+       eval "(exit $my_status); $my_fail_exp"
+      fi
+    fi
+}
+
+
+
+
+
+# func_version
+# Echo version message to standard output and exit.
+func_version ()
+{
+    $SED -n '/^# '$PROGRAM' (GNU /,/# warranty; / {
+        s/^# //
+       s/^# *$//
+        s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/
+        p
+     }' < "$progpath"
+     exit $?
+}
+
+# func_usage
+# Echo short help message to standard output and exit.
+func_usage ()
+{
+    $SED -n '/^# Usage:/,/# -h/ {
+        s/^# //
+       s/^# *$//
+       s/\$progname/'$progname'/
+       p
+    }' < "$progpath"
+    $ECHO
+    $ECHO "run \`$progname --help | more' for full usage"
+    exit $?
+}
+
+# func_help
+# Echo long help message to standard output and exit.
+func_help ()
+{
+    $SED -n '/^# Usage:/,/# Report bugs to/ {
+        s/^# //
+       s/^# *$//
+       s*\$progname*'$progname'*
+       s*\$host*'"$host"'*
+       s*\$SHELL*'"$SHELL"'*
+       s*\$LTCC*'"$LTCC"'*
+       s*\$LTCFLAGS*'"$LTCFLAGS"'*
+       s*\$LD*'"$LD"'*
+       s/\$with_gnu_ld/'"$with_gnu_ld"'/
+       s/\$automake_version/'"`(automake --version) 2>/dev/null |$SED 1q`"'/
+       s/\$autoconf_version/'"`(autoconf --version) 2>/dev/null |$SED 1q`"'/
+       p
+     }' < "$progpath"
+    exit $?
+}
+
+# func_missing_arg argname
+# Echo program name prefixed message to standard error and set global
+# exit_cmd.
+func_missing_arg ()
+{
+    func_error "missing argument for $1"
+    exit_cmd=exit
+}
+
+exit_cmd=:
+
+
+
+
+
+# Check that we have a working $ECHO.
+if test "X$1" = X--no-reexec; then
+  # Discard the --no-reexec flag, and continue.
+  shift
+elif test "X$1" = X--fallback-echo; then
+  # Avoid inline document here, it may be left over
+  :
+elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t'; then
+  # Yippee, $ECHO works!
+  :
+else
+  # Restart under the correct shell, and then maybe $ECHO will work.
+  exec $SHELL "$progpath" --no-reexec ${1+"$@"}
+fi
+
+if test "X$1" = X--fallback-echo; then
+  # used as fallback echo
+  shift
+  cat <<EOF
+$*
+EOF
+  exit $EXIT_SUCCESS
+fi
+
+magic="%%%MAGIC variable%%%"
+magic_exe="%%%MAGIC EXE variable%%%"
+
+# Global variables.
+# $mode is unset
+nonopt=
+execute_dlfiles=
+preserve_args=
+lo2o="s/\\.lo\$/.${objext}/"
+o2lo="s/\\.${objext}\$/.lo/"
+extracted_archives=
+extracted_serial=0
+
+opt_dry_run=false
+opt_duplicate_deps=false
+opt_silent=false
+opt_debug=:
+
+# If this variable is set in any of the actions, the command in it
+# will be execed at the end.  This prevents here-documents from being
+# left over by shells.
+exec_cmd=
+
+# func_fatal_configuration arg...
+# Echo program name prefixed message to standard error, followed by
+# a configuration failure hint, and exit.
+func_fatal_configuration ()
+{
+    func_error ${1+"$@"}
+    func_error "See the $PACKAGE documentation for more information."
+    func_fatal_error "Fatal configuration error."
+}
+
+
+# func_config
+# Display the configuration for all the tags in this script.
+func_config ()
+{
+    re_begincf='^# ### BEGIN LIBTOOL'
+    re_endcf='^# ### END LIBTOOL'
+
+    # Default configuration.
+    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
+
+    # Now print the configurations for the tags.
+    for tagname in $taglist; do
+      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
+    done
+
+    exit $?
+}
+
+# func_features
+# Display the features supported by this script.
+func_features ()
+{
+    $ECHO "host: $host"
+    if test "$build_libtool_libs" = yes; then
+      $ECHO "enable shared libraries"
+    else
+      $ECHO "disable shared libraries"
+    fi
+    if test "$build_old_libs" = yes; then
+      $ECHO "enable static libraries"
+    else
+      $ECHO "disable static libraries"
+    fi
+
+    exit $?
+}
+
+# func_enable_tag tagname
+# Verify that TAGNAME is valid, and either flag an error and exit, or
+# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
+# variable here.
+func_enable_tag ()
+{
+  # Global variable:
+  tagname="$1"
+
+  re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
+  re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
+  sed_extractcf="/$re_begincf/,/$re_endcf/p"
+
+  # Validate tagname.
+  case $tagname in
+    *[!-_A-Za-z0-9,/]*)
+      func_fatal_error "invalid tag name: $tagname"
+      ;;
+  esac
+
+  # Don't test for the "default" C tag, as we know it's
+  # there but not specially marked.
+  case $tagname in
+    CC) ;;
+    *)
+      if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
+       taglist="$taglist $tagname"
+
+       # Evaluate the configuration.  Be careful to quote the path
+       # and the sed script, to avoid splitting on whitespace, but
+       # also don't use non-portable quotes within backquotes within
+       # quotes we have to do it in 2 steps:
+       extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
+       eval "$extractedcf"
+      else
+       func_error "ignoring unknown tag $tagname"
+      fi
+      ;;
+  esac
+}
+
+# Parse options once, thoroughly.  This comes as soon as possible in
+# the script to make things like `libtool --version' happen quickly.
+{
+
+  # Shorthand for --mode=foo, only valid as the first argument
+  case $1 in
+  clean|clea|cle|cl)
+    shift; set dummy --mode clean ${1+"$@"}; shift
+    ;;
+  compile|compil|compi|comp|com|co|c)
+    shift; set dummy --mode compile ${1+"$@"}; shift
+    ;;
+  execute|execut|execu|exec|exe|ex|e)
+    shift; set dummy --mode execute ${1+"$@"}; shift
+    ;;
+  finish|finis|fini|fin|fi|f)
+    shift; set dummy --mode finish ${1+"$@"}; shift
+    ;;
+  install|instal|insta|inst|ins|in|i)
+    shift; set dummy --mode install ${1+"$@"}; shift
+    ;;
+  link|lin|li|l)
+    shift; set dummy --mode link ${1+"$@"}; shift
+    ;;
+  uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
+    shift; set dummy --mode uninstall ${1+"$@"}; shift
+    ;;
+  esac
+
+  # Parse non-mode specific arguments:
+  while test "$#" -gt 0; do
+    opt="$1"
+    shift
+
+    case $opt in
+      --config)                func_config                                     ;;
+
+      --debug)         preserve_args="$preserve_args $opt"
+                       func_echo "enabling shell trace mode"
+                       opt_debug='set -x'
+                       $opt_debug
+                       ;;
+
+      -dlopen)         test "$#" -eq 0 && func_missing_arg "$opt" && break
+                       execute_dlfiles="$execute_dlfiles $1"
+                       shift
+                       ;;
+
+      --dry-run | -n)  opt_dry_run=:                                   ;;
+      --features)       func_features                                  ;;
+      --finish)                mode="finish"                                   ;;
+
+      --mode)          test "$#" -eq 0 && func_missing_arg "$opt" && break
+                       case $1 in
+                         # Valid mode arguments:
+                         clean)        ;;
+                         compile)      ;;
+                         execute)      ;;
+                         finish)       ;;
+                         install)      ;;
+                         link)         ;;
+                         relink)       ;;
+                         uninstall)    ;;
+
+                         # Catch anything else as an error
+                         *) func_error "invalid argument for $opt"
+                            exit_cmd=exit
+                            break
+                            ;;
+                       esac
+
+                       mode="$1"
+                       shift
+                       ;;
+
+      --preserve-dup-deps)
+                       opt_duplicate_deps=:                            ;;
+
+      --quiet|--silent)        preserve_args="$preserve_args $opt"
+                       opt_silent=:
+                       ;;
+
+      --verbose| -v)   preserve_args="$preserve_args $opt"
+                       opt_silent=false
+                       ;;
+
+      --tag)           test "$#" -eq 0 && func_missing_arg "$opt" && break
+                       preserve_args="$preserve_args $opt $1"
+                       func_enable_tag "$1"    # tagname is set here
+                       shift
+                       ;;
+
+      # Separate optargs to long options:
+      -dlopen=*|--mode=*|--tag=*)
+                       func_opt_split "$opt"
+                       set dummy "$func_opt_split_opt" "$func_opt_split_arg" ${1+"$@"}
+                       shift
+                       ;;
+
+      -\?|-h)          func_usage                                      ;;
+      --help)          opt_help=:                                      ;;
+      --version)       func_version                                    ;;
+
+      -*)              func_fatal_help "unrecognized option \`$opt'"   ;;
+
+      *)               nonopt="$opt"
+                       break
+                       ;;
+    esac
+  done
+
+
+  case $host in
+    *cygwin* | *mingw* | *pw32* | *cegcc*)
+      # don't eliminate duplications in $postdeps and $predeps
+      opt_duplicate_compiler_generated_deps=:
+      ;;
+    *)
+      opt_duplicate_compiler_generated_deps=$opt_duplicate_deps
+      ;;
+  esac
+
+  # Having warned about all mis-specified options, bail out if
+  # anything was wrong.
+  $exit_cmd $EXIT_FAILURE
+}
+
+# func_check_version_match
+# Ensure that we are using m4 macros, and libtool script from the same
+# release of libtool.
+func_check_version_match ()
+{
+  if test "$package_revision" != "$macro_revision"; then
+    if test "$VERSION" != "$macro_version"; then
+      if test -z "$macro_version"; then
+        cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
+$progname: definition of this LT_INIT comes from an older release.
+$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
+$progname: and run autoconf again.
+_LT_EOF
+      else
+        cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
+$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
+$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
+$progname: and run autoconf again.
+_LT_EOF
+      fi
+    else
+      cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
+$progname: but the definition of this LT_INIT comes from revision $macro_revision.
+$progname: You should recreate aclocal.m4 with macros from revision $package_revision
+$progname: of $PACKAGE $VERSION and run autoconf again.
+_LT_EOF
+    fi
+
+    exit $EXIT_MISMATCH
+  fi
+}
+
+
+## ----------- ##
+##    Main.    ##
+## ----------- ##
+
+$opt_help || {
+  # Sanity checks first:
+  func_check_version_match
+
+  if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then
+    func_fatal_configuration "not configured to build any kind of library"
+  fi
+
+  test -z "$mode" && func_fatal_error "error: you must specify a MODE."
+
+
+  # Darwin sucks
+  eval std_shrext=\"$shrext_cmds\"
+
+
+  # Only execute mode is allowed to have -dlopen flags.
+  if test -n "$execute_dlfiles" && test "$mode" != execute; then
+    func_error "unrecognized option \`-dlopen'"
+    $ECHO "$help" 1>&2
+    exit $EXIT_FAILURE
+  fi
+
+  # Change the help message to a mode-specific one.
+  generic_help="$help"
+  help="Try \`$progname --help --mode=$mode' for more information."
+}
+
+
+# func_lalib_p file
+# True iff FILE is a libtool `.la' library or `.lo' object file.
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_lalib_p ()
+{
+    test -f "$1" &&
+      $SED -e 4q "$1" 2>/dev/null \
+        | $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
+}
+
+# func_lalib_unsafe_p file
+# True iff FILE is a libtool `.la' library or `.lo' object file.
+# This function implements the same check as func_lalib_p without
+# resorting to external programs.  To this end, it redirects stdin and
+# closes it afterwards, without saving the original file descriptor.
+# As a safety measure, use it only where a negative result would be
+# fatal anyway.  Works if `file' does not exist.
+func_lalib_unsafe_p ()
+{
+    lalib_p=no
+    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
+       for lalib_p_l in 1 2 3 4
+       do
+           read lalib_p_line
+           case "$lalib_p_line" in
+               \#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
+           esac
+       done
+       exec 0<&5 5<&-
+    fi
+    test "$lalib_p" = yes
+}
+
+# func_ltwrapper_script_p file
+# True iff FILE is a libtool wrapper script
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_script_p ()
+{
+    func_lalib_p "$1"
+}
+
+# func_ltwrapper_executable_p file
+# True iff FILE is a libtool wrapper executable
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_executable_p ()
+{
+    func_ltwrapper_exec_suffix=
+    case $1 in
+    *.exe) ;;
+    *) func_ltwrapper_exec_suffix=.exe ;;
+    esac
+    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
+}
+
+# func_ltwrapper_scriptname file
+# Assumes file is an ltwrapper_executable
+# uses $file to determine the appropriate filename for a
+# temporary ltwrapper_script.
+func_ltwrapper_scriptname ()
+{
+    func_ltwrapper_scriptname_result=""
+    if func_ltwrapper_executable_p "$1"; then
+       func_dirname_and_basename "$1" "" "."
+       func_stripname '' '.exe' "$func_basename_result"
+       func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper"
+    fi
+}
+
+# func_ltwrapper_p file
+# True iff FILE is a libtool wrapper script or wrapper executable
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_p ()
+{
+    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
+}
+
+
+# func_execute_cmds commands fail_cmd
+# Execute tilde-delimited COMMANDS.
+# If FAIL_CMD is given, eval that upon failure.
+# FAIL_CMD may read-access the current command in variable CMD!
+func_execute_cmds ()
+{
+    $opt_debug
+    save_ifs=$IFS; IFS='~'
+    for cmd in $1; do
+      IFS=$save_ifs
+      eval cmd=\"$cmd\"
+      func_show_eval "$cmd" "${2-:}"
+    done
+    IFS=$save_ifs
+}
+
+
+# func_source file
+# Source FILE, adding directory component if necessary.
+# Note that it is not necessary on cygwin/mingw to append a dot to
+# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
+# behavior happens only for exec(3), not for open(2)!  Also, sourcing
+# `FILE.' does not work on cygwin managed mounts.
+func_source ()
+{
+    $opt_debug
+    case $1 in
+    */* | *\\*)        . "$1" ;;
+    *)         . "./$1" ;;
+    esac
+}
+
+
+# func_infer_tag arg
+# Infer tagged configuration to use if any are available and
+# if one wasn't chosen via the "--tag" command line option.
+# Only attempt this if the compiler in the base compile
+# command doesn't match the default compiler.
+# arg is usually of the form 'gcc ...'
+func_infer_tag ()
+{
+    $opt_debug
+    if test -n "$available_tags" && test -z "$tagname"; then
+      CC_quoted=
+      for arg in $CC; do
+        func_quote_for_eval "$arg"
+       CC_quoted="$CC_quoted $func_quote_for_eval_result"
+      done
+      case $@ in
+      # Blanks in the command may have been stripped by the calling shell,
+      # but not from the CC environment variable when configure was run.
+      " $CC "* | "$CC "* | " `$ECHO $CC` "* | "`$ECHO $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$ECHO $CC_quoted` "* | "`$ECHO $CC_quoted` "*) ;;
+      # Blanks at the start of $base_compile will cause this to fail
+      # if we don't check for them as well.
+      *)
+       for z in $available_tags; do
+         if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
+           # Evaluate the configuration.
+           eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
+           CC_quoted=
+           for arg in $CC; do
+             # Double-quote args containing other shell metacharacters.
+             func_quote_for_eval "$arg"
+             CC_quoted="$CC_quoted $func_quote_for_eval_result"
+           done
+           case "$@ " in
+             " $CC "* | "$CC "* | " `$ECHO $CC` "* | "`$ECHO $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$ECHO $CC_quoted` "* | "`$ECHO $CC_quoted` "*)
+             # The compiler in the base compile command matches
+             # the one in the tagged configuration.
+             # Assume this is the tagged configuration we want.
+             tagname=$z
+             break
+             ;;
+           esac
+         fi
+       done
+       # If $tagname still isn't set, then no tagged configuration
+       # was found and let the user know that the "--tag" command
+       # line option must be used.
+       if test -z "$tagname"; then
+         func_echo "unable to infer tagged configuration"
+         func_fatal_error "specify a tag with \`--tag'"
+#      else
+#        func_verbose "using $tagname tagged configuration"
+       fi
+       ;;
+      esac
+    fi
+}
+
+
+
+# func_write_libtool_object output_name pic_name nonpic_name
+# Create a libtool object file (analogous to a ".la" file),
+# but don't create it if we're doing a dry run.
+func_write_libtool_object ()
+{
+    write_libobj=${1}
+    if test "$build_libtool_libs" = yes; then
+      write_lobj=\'${2}\'
+    else
+      write_lobj=none
+    fi
+
+    if test "$build_old_libs" = yes; then
+      write_oldobj=\'${3}\'
+    else
+      write_oldobj=none
+    fi
+
+    $opt_dry_run || {
+      cat >${write_libobj}T <<EOF
+# $write_libobj - a libtool object file
+# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# Name of the PIC object.
+pic_object=$write_lobj
+
+# Name of the non-PIC object
+non_pic_object=$write_oldobj
+
+EOF
+      $MV "${write_libobj}T" "${write_libobj}"
+    }
+}
+
+# func_mode_compile arg...
+func_mode_compile ()
+{
+    $opt_debug
+    # Get the compilation command and the source file.
+    base_compile=
+    srcfile="$nonopt"  #  always keep a non-empty value in "srcfile"
+    suppress_opt=yes
+    suppress_output=
+    arg_mode=normal
+    libobj=
+    later=
+    pie_flag=
+
+    for arg
+    do
+      case $arg_mode in
+      arg  )
+       # do not "continue".  Instead, add this to base_compile
+       lastarg="$arg"
+       arg_mode=normal
+       ;;
+
+      target )
+       libobj="$arg"
+       arg_mode=normal
+       continue
+       ;;
+
+      normal )
+       # Accept any command-line options.
+       case $arg in
+       -o)
+         test -n "$libobj" && \
+           func_fatal_error "you cannot specify \`-o' more than once"
+         arg_mode=target
+         continue
+         ;;
+
+       -pie | -fpie | -fPIE)
+          pie_flag="$pie_flag $arg"
+         continue
+         ;;
+
+       -shared | -static | -prefer-pic | -prefer-non-pic)
+         later="$later $arg"
+         continue
+         ;;
+
+       -no-suppress)
+         suppress_opt=no
+         continue
+         ;;
+
+       -Xcompiler)
+         arg_mode=arg  #  the next one goes into the "base_compile" arg list
+         continue      #  The current "srcfile" will either be retained or
+         ;;            #  replaced later.  I would guess that would be a bug.
+
+       -Wc,*)
+         func_stripname '-Wc,' '' "$arg"
+         args=$func_stripname_result
+         lastarg=
+         save_ifs="$IFS"; IFS=','
+         for arg in $args; do
+           IFS="$save_ifs"
+           func_quote_for_eval "$arg"
+           lastarg="$lastarg $func_quote_for_eval_result"
+         done
+         IFS="$save_ifs"
+         func_stripname ' ' '' "$lastarg"
+         lastarg=$func_stripname_result
+
+         # Add the arguments to base_compile.
+         base_compile="$base_compile $lastarg"
+         continue
+         ;;
+
+       *)
+         # Accept the current argument as the source file.
+         # The previous "srcfile" becomes the current argument.
+         #
+         lastarg="$srcfile"
+         srcfile="$arg"
+         ;;
+       esac  #  case $arg
+       ;;
+      esac    #  case $arg_mode
+
+      # Aesthetically quote the previous argument.
+      func_quote_for_eval "$lastarg"
+      base_compile="$base_compile $func_quote_for_eval_result"
+    done # for arg
+
+    case $arg_mode in
+    arg)
+      func_fatal_error "you must specify an argument for -Xcompile"
+      ;;
+    target)
+      func_fatal_error "you must specify a target with \`-o'"
+      ;;
+    *)
+      # Get the name of the library object.
+      test -z "$libobj" && {
+       func_basename "$srcfile"
+       libobj="$func_basename_result"
+      }
+      ;;
+    esac
+
+    # Recognize several different file suffixes.
+    # If the user specifies -o file.o, it is replaced with file.lo
+    case $libobj in
+    *.[cCFSifmso] | \
+    *.ada | *.adb | *.ads | *.asm | \
+    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
+    *.[fF][09]? | *.for | *.java | *.obj | *.sx)
+      func_xform "$libobj"
+      libobj=$func_xform_result
+      ;;
+    esac
+
+    case $libobj in
+    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
+    *)
+      func_fatal_error "cannot determine name of library object from \`$libobj'"
+      ;;
+    esac
+
+    func_infer_tag $base_compile
+
+    for arg in $later; do
+      case $arg in
+      -shared)
+       test "$build_libtool_libs" != yes && \
+         func_fatal_configuration "can not build a shared library"
+       build_old_libs=no
+       continue
+       ;;
+
+      -static)
+       build_libtool_libs=no
+       build_old_libs=yes
+       continue
+       ;;
+
+      -prefer-pic)
+       pic_mode=yes
+       continue
+       ;;
+
+      -prefer-non-pic)
+       pic_mode=no
+       continue
+       ;;
+      esac
+    done
+
+    func_quote_for_eval "$libobj"
+    test "X$libobj" != "X$func_quote_for_eval_result" \
+      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'   &()|`$[]' \
+      && func_warning "libobj name \`$libobj' may not contain shell special characters."
+    func_dirname_and_basename "$obj" "/" ""
+    objname="$func_basename_result"
+    xdir="$func_dirname_result"
+    lobj=${xdir}$objdir/$objname
+
+    test -z "$base_compile" && \
+      func_fatal_help "you must specify a compilation command"
+
+    # Delete any leftover library objects.
+    if test "$build_old_libs" = yes; then
+      removelist="$obj $lobj $libobj ${libobj}T"
+    else
+      removelist="$lobj $libobj ${libobj}T"
+    fi
+
+    # On Cygwin there's no "real" PIC flag so we must build both object types
+    case $host_os in
+    cygwin* | mingw* | pw32* | os2* | cegcc*)
+      pic_mode=default
+      ;;
+    esac
+    if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then
+      # non-PIC code in shared libraries is not supported
+      pic_mode=default
+    fi
+
+    # Calculate the filename of the output object if compiler does
+    # not support -o with -c
+    if test "$compiler_c_o" = no; then
+      output_obj=`$ECHO "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext}
+      lockfile="$output_obj.lock"
+    else
+      output_obj=
+      need_locks=no
+      lockfile=
+    fi
+
+    # Lock this critical section if it is needed
+    # We use this script file to make the link, it avoids creating a new file
+    if test "$need_locks" = yes; then
+      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
+       func_echo "Waiting for $lockfile to be removed"
+       sleep 2
+      done
+    elif test "$need_locks" = warn; then
+      if test -f "$lockfile"; then
+       $ECHO "\
+*** ERROR, $lockfile exists and contains:
+`cat $lockfile 2>/dev/null`
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support \`-c' and \`-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+       $opt_dry_run || $RM $removelist
+       exit $EXIT_FAILURE
+      fi
+      removelist="$removelist $output_obj"
+      $ECHO "$srcfile" > "$lockfile"
+    fi
+
+    $opt_dry_run || $RM $removelist
+    removelist="$removelist $lockfile"
+    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
+
+    if test -n "$fix_srcfile_path"; then
+      eval srcfile=\"$fix_srcfile_path\"
+    fi
+    func_quote_for_eval "$srcfile"
+    qsrcfile=$func_quote_for_eval_result
+
+    # Only build a PIC object if we are building libtool libraries.
+    if test "$build_libtool_libs" = yes; then
+      # Without this assignment, base_compile gets emptied.
+      fbsd_hideous_sh_bug=$base_compile
+
+      if test "$pic_mode" != no; then
+       command="$base_compile $qsrcfile $pic_flag"
+      else
+       # Don't build PIC code
+       command="$base_compile $qsrcfile"
+      fi
+
+      func_mkdir_p "$xdir$objdir"
+
+      if test -z "$output_obj"; then
+       # Place PIC objects in $objdir
+       command="$command -o $lobj"
+      fi
+
+      func_show_eval_locale "$command" \
+          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
+
+      if test "$need_locks" = warn &&
+        test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
+       $ECHO "\
+*** ERROR, $lockfile contains:
+`cat $lockfile 2>/dev/null`
+
+but it should contain:
+$srcfile
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support \`-c' and \`-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+       $opt_dry_run || $RM $removelist
+       exit $EXIT_FAILURE
+      fi
+
+      # Just move the object if needed, then go on to compile the next one
+      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
+       func_show_eval '$MV "$output_obj" "$lobj"' \
+         'error=$?; $opt_dry_run || $RM $removelist; exit $error'
+      fi
+
+      # Allow error messages only from the first compilation.
+      if test "$suppress_opt" = yes; then
+       suppress_output=' >/dev/null 2>&1'
+      fi
+    fi
+
+    # Only build a position-dependent object if we build old libraries.
+    if test "$build_old_libs" = yes; then
+      if test "$pic_mode" != yes; then
+       # Don't build PIC code
+       command="$base_compile $qsrcfile$pie_flag"
+      else
+       command="$base_compile $qsrcfile $pic_flag"
+      fi
+      if test "$compiler_c_o" = yes; then
+       command="$command -o $obj"
+      fi
+
+      # Suppress compiler output if we already did a PIC compilation.
+      command="$command$suppress_output"
+      func_show_eval_locale "$command" \
+        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
+
+      if test "$need_locks" = warn &&
+        test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
+       $ECHO "\
+*** ERROR, $lockfile contains:
+`cat $lockfile 2>/dev/null`
+
+but it should contain:
+$srcfile
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support \`-c' and \`-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+       $opt_dry_run || $RM $removelist
+       exit $EXIT_FAILURE
+      fi
+
+      # Just move the object if needed
+      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
+       func_show_eval '$MV "$output_obj" "$obj"' \
+         'error=$?; $opt_dry_run || $RM $removelist; exit $error'
+      fi
+    fi
+
+    $opt_dry_run || {
+      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
+
+      # Unlock the critical section if it was locked
+      if test "$need_locks" != no; then
+       removelist=$lockfile
+        $RM "$lockfile"
+      fi
+    }
+
+    exit $EXIT_SUCCESS
+}
+
+$opt_help || {
+test "$mode" = compile && func_mode_compile ${1+"$@"}
+}
+
+func_mode_help ()
+{
+    # We need to display help for each of the modes.
+    case $mode in
+      "")
+        # Generic help is extracted from the usage comments
+        # at the start of this file.
+        func_help
+        ;;
+
+      clean)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
+
+Remove files from the build directory.
+
+RM is the name of the program to use to delete files associated with each FILE
+(typically \`/bin/rm').  RM-OPTIONS are options (such as \`-f') to be passed
+to RM.
+
+If FILE is a libtool library, object or program, all the files associated
+with it are deleted. Otherwise, only FILE itself is deleted using RM."
+        ;;
+
+      compile)
+      $ECHO \
+"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
+
+Compile a source file into a libtool library object.
+
+This mode accepts the following additional options:
+
+  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
+  -no-suppress      do not suppress compiler output for multiple passes
+  -prefer-pic       try to building PIC objects only
+  -prefer-non-pic   try to building non-PIC objects only
+  -shared           do not build a \`.o' file suitable for static linking
+  -static           only build a \`.o' file suitable for static linking
+
+COMPILE-COMMAND is a command to be used in creating a \`standard' object file
+from the given SOURCEFILE.
+
+The output file name is determined by removing the directory component from
+SOURCEFILE, then substituting the C source code suffix \`.c' with the
+library object suffix, \`.lo'."
+        ;;
+
+      execute)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
+
+Automatically set library path, then run a program.
+
+This mode accepts the following additional options:
+
+  -dlopen FILE      add the directory containing FILE to the library path
+
+This mode sets the library path environment variable according to \`-dlopen'
+flags.
+
+If any of the ARGS are libtool executable wrappers, then they are translated
+into their corresponding uninstalled binary, and any of their required library
+directories are added to the library path.
+
+Then, COMMAND is executed, with ARGS as arguments."
+        ;;
+
+      finish)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
+
+Complete the installation of libtool libraries.
+
+Each LIBDIR is a directory that contains libtool libraries.
+
+The commands that this mode executes may require superuser privileges.  Use
+the \`--dry-run' option if you just want to see what would be executed."
+        ;;
+
+      install)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
+
+Install executables or libraries.
+
+INSTALL-COMMAND is the installation command.  The first component should be
+either the \`install' or \`cp' program.
+
+The following components of INSTALL-COMMAND are treated specially:
+
+  -inst-prefix PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
+
+The rest of the components are interpreted as arguments to that command (only
+BSD-compatible install options are recognized)."
+        ;;
+
+      link)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
+
+Link object files or libraries together to form another library, or to
+create an executable program.
+
+LINK-COMMAND is a command using the C compiler that you would use to create
+a program from several object files.
+
+The following components of LINK-COMMAND are treated specially:
+
+  -all-static       do not do any dynamic linking at all
+  -avoid-version    do not add a version suffix if possible
+  -dlopen FILE      \`-dlpreopen' FILE if it cannot be dlopened at runtime
+  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
+  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
+  -export-symbols SYMFILE
+                    try to export only the symbols listed in SYMFILE
+  -export-symbols-regex REGEX
+                    try to export only the symbols matching REGEX
+  -LLIBDIR          search LIBDIR for required installed libraries
+  -lNAME            OUTPUT-FILE requires the installed library libNAME
+  -module           build a library that can dlopened
+  -no-fast-install  disable the fast-install mode
+  -no-install       link a not-installable executable
+  -no-undefined     declare that a library does not refer to external symbols
+  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
+  -objectlist FILE  Use a list of object files found in FILE to specify objects
+  -precious-files-regex REGEX
+                    don't remove output files matching REGEX
+  -release RELEASE  specify package release information
+  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
+  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
+  -shared           only do dynamic linking of libtool libraries
+  -shrext SUFFIX    override the standard shared library file extension
+  -static           do not do any dynamic linking of uninstalled libtool libraries
+  -static-libtool-libs
+                    do not do any dynamic linking of libtool libraries
+  -version-info CURRENT[:REVISION[:AGE]]
+                    specify library version info [each variable defaults to 0]
+  -weak LIBNAME     declare that the target provides the LIBNAME interface
+
+All other options (arguments beginning with \`-') are ignored.
+
+Every other argument is treated as a filename.  Files ending in \`.la' are
+treated as uninstalled libtool libraries, other files are standard or library
+object files.
+
+If the OUTPUT-FILE ends in \`.la', then a libtool library is created,
+only library objects (\`.lo' files) may be specified, and \`-rpath' is
+required, except when creating a convenience library.
+
+If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created
+using \`ar' and \`ranlib', or on Windows using \`lib'.
+
+If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file
+is created, otherwise an executable program is created."
+        ;;
+
+      uninstall)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
+
+Remove libraries from an installation directory.
+
+RM is the name of the program to use to delete files associated with each FILE
+(typically \`/bin/rm').  RM-OPTIONS are options (such as \`-f') to be passed
+to RM.
+
+If FILE is a libtool library, all the files associated with it are deleted.
+Otherwise, only FILE itself is deleted using RM."
+        ;;
+
+      *)
+        func_fatal_help "invalid operation mode \`$mode'"
+        ;;
+    esac
+
+    $ECHO
+    $ECHO "Try \`$progname --help' for more information about other modes."
+
+    exit $?
+}
+
+  # Now that we've collected a possible --mode arg, show help if necessary
+  $opt_help && func_mode_help
+
+
+# func_mode_execute arg...
+func_mode_execute ()
+{
+    $opt_debug
+    # The first argument is the command name.
+    cmd="$nonopt"
+    test -z "$cmd" && \
+      func_fatal_help "you must specify a COMMAND"
+
+    # Handle -dlopen flags immediately.
+    for file in $execute_dlfiles; do
+      test -f "$file" \
+       || func_fatal_help "\`$file' is not a file"
+
+      dir=
+      case $file in
+      *.la)
+       # Check to see that this really is a libtool archive.
+       func_lalib_unsafe_p "$file" \
+         || func_fatal_help "\`$lib' is not a valid libtool archive"
+
+       # Read the libtool library.
+       dlname=
+       library_names=
+       func_source "$file"
+
+       # Skip this library if it cannot be dlopened.
+       if test -z "$dlname"; then
+         # Warn if it was a shared library.
+         test -n "$library_names" && \
+           func_warning "\`$file' was not linked with \`-export-dynamic'"
+         continue
+       fi
+
+       func_dirname "$file" "" "."
+       dir="$func_dirname_result"
+
+       if test -f "$dir/$objdir/$dlname"; then
+         dir="$dir/$objdir"
+       else
+         if test ! -f "$dir/$dlname"; then
+           func_fatal_error "cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'"
+         fi
+       fi
+       ;;
+
+      *.lo)
+       # Just add the directory containing the .lo file.
+       func_dirname "$file" "" "."
+       dir="$func_dirname_result"
+       ;;
+
+      *)
+       func_warning "\`-dlopen' is ignored for non-libtool libraries and objects"
+       continue
+       ;;
+      esac
+
+      # Get the absolute pathname.
+      absdir=`cd "$dir" && pwd`
+      test -n "$absdir" && dir="$absdir"
+
+      # Now add the directory to shlibpath_var.
+      if eval "test -z \"\$$shlibpath_var\""; then
+       eval "$shlibpath_var=\"\$dir\""
+      else
+       eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
+      fi
+    done
+
+    # This variable tells wrapper scripts just to set shlibpath_var
+    # rather than running their programs.
+    libtool_execute_magic="$magic"
+
+    # Check if any of the arguments is a wrapper script.
+    args=
+    for file
+    do
+      case $file in
+      -*) ;;
+      *)
+       # Do a test to see if this is really a libtool program.
+       if func_ltwrapper_script_p "$file"; then
+         func_source "$file"
+         # Transform arg to wrapped name.
+         file="$progdir/$program"
+       elif func_ltwrapper_executable_p "$file"; then
+         func_ltwrapper_scriptname "$file"
+         func_source "$func_ltwrapper_scriptname_result"
+         # Transform arg to wrapped name.
+         file="$progdir/$program"
+       fi
+       ;;
+      esac
+      # Quote arguments (to preserve shell metacharacters).
+      func_quote_for_eval "$file"
+      args="$args $func_quote_for_eval_result"
+    done
+
+    if test "X$opt_dry_run" = Xfalse; then
+      if test -n "$shlibpath_var"; then
+       # Export the shlibpath_var.
+       eval "export $shlibpath_var"
+      fi
+
+      # Restore saved environment variables
+      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
+      do
+       eval "if test \"\${save_$lt_var+set}\" = set; then
+                $lt_var=\$save_$lt_var; export $lt_var
+             else
+               $lt_unset $lt_var
+             fi"
+      done
+
+      # Now prepare to actually exec the command.
+      exec_cmd="\$cmd$args"
+    else
+      # Display what would be done.
+      if test -n "$shlibpath_var"; then
+       eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
+       $ECHO "export $shlibpath_var"
+      fi
+      $ECHO "$cmd$args"
+      exit $EXIT_SUCCESS
+    fi
+}
+
+test "$mode" = execute && func_mode_execute ${1+"$@"}
+
+
+# func_mode_finish arg...
+func_mode_finish ()
+{
+    $opt_debug
+    libdirs="$nonopt"
+    admincmds=
+
+    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
+      for dir
+      do
+       libdirs="$libdirs $dir"
+      done
+
+      for libdir in $libdirs; do
+       if test -n "$finish_cmds"; then
+         # Do each command in the finish commands.
+         func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
+'"$cmd"'"'
+       fi
+       if test -n "$finish_eval"; then
+         # Do the single finish_eval.
+         eval cmds=\"$finish_eval\"
+         $opt_dry_run || eval "$cmds" || admincmds="$admincmds
+       $cmds"
+       fi
+      done
+    fi
+
+    # Exit here if they wanted silent mode.
+    $opt_silent && exit $EXIT_SUCCESS
+
+    $ECHO "X----------------------------------------------------------------------" | $Xsed
+    $ECHO "Libraries have been installed in:"
+    for libdir in $libdirs; do
+      $ECHO "   $libdir"
+    done
+    $ECHO
+    $ECHO "If you ever happen to want to link against installed libraries"
+    $ECHO "in a given directory, LIBDIR, you must either use libtool, and"
+    $ECHO "specify the full pathname of the library, or use the \`-LLIBDIR'"
+    $ECHO "flag during linking and do at least one of the following:"
+    if test -n "$shlibpath_var"; then
+      $ECHO "   - add LIBDIR to the \`$shlibpath_var' environment variable"
+      $ECHO "     during execution"
+    fi
+    if test -n "$runpath_var"; then
+      $ECHO "   - add LIBDIR to the \`$runpath_var' environment variable"
+      $ECHO "     during linking"
+    fi
+    if test -n "$hardcode_libdir_flag_spec"; then
+      libdir=LIBDIR
+      eval flag=\"$hardcode_libdir_flag_spec\"
+
+      $ECHO "   - use the \`$flag' linker flag"
+    fi
+    if test -n "$admincmds"; then
+      $ECHO "   - have your system administrator run these commands:$admincmds"
+    fi
+    if test -f /etc/ld.so.conf; then
+      $ECHO "   - have your system administrator add LIBDIR to \`/etc/ld.so.conf'"
+    fi
+    $ECHO
+
+    $ECHO "See any operating system documentation about shared libraries for"
+    case $host in
+      solaris2.[6789]|solaris2.1[0-9])
+        $ECHO "more information, such as the ld(1), crle(1) and ld.so(8) manual"
+       $ECHO "pages."
+       ;;
+      *)
+        $ECHO "more information, such as the ld(1) and ld.so(8) manual pages."
+        ;;
+    esac
+    $ECHO "X----------------------------------------------------------------------" | $Xsed
+    exit $EXIT_SUCCESS
+}
+
+test "$mode" = finish && func_mode_finish ${1+"$@"}
+
+
+# func_mode_install arg...
+func_mode_install ()
+{
+    $opt_debug
+    # There may be an optional sh(1) argument at the beginning of
+    # install_prog (especially on Windows NT).
+    if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh ||
+       # Allow the use of GNU shtool's install command.
+       $ECHO "X$nonopt" | $GREP shtool >/dev/null; then
+      # Aesthetically quote it.
+      func_quote_for_eval "$nonopt"
+      install_prog="$func_quote_for_eval_result "
+      arg=$1
+      shift
+    else
+      install_prog=
+      arg=$nonopt
+    fi
+
+    # The real first argument should be the name of the installation program.
+    # Aesthetically quote it.
+    func_quote_for_eval "$arg"
+    install_prog="$install_prog$func_quote_for_eval_result"
+
+    # We need to accept at least all the BSD install flags.
+    dest=
+    files=
+    opts=
+    prev=
+    install_type=
+    isdir=no
+    stripme=
+    for arg
+    do
+      if test -n "$dest"; then
+       files="$files $dest"
+       dest=$arg
+       continue
+      fi
+
+      case $arg in
+      -d) isdir=yes ;;
+      -f)
+       case " $install_prog " in
+       *[\\\ /]cp\ *) ;;
+       *) prev=$arg ;;
+       esac
+       ;;
+      -g | -m | -o)
+       prev=$arg
+       ;;
+      -s)
+       stripme=" -s"
+       continue
+       ;;
+      -*)
+       ;;
+      *)
+       # If the previous option needed an argument, then skip it.
+       if test -n "$prev"; then
+         prev=
+       else
+         dest=$arg
+         continue
+       fi
+       ;;
+      esac
+
+      # Aesthetically quote the argument.
+      func_quote_for_eval "$arg"
+      install_prog="$install_prog $func_quote_for_eval_result"
+    done
+
+    test -z "$install_prog" && \
+      func_fatal_help "you must specify an install program"
+
+    test -n "$prev" && \
+      func_fatal_help "the \`$prev' option requires an argument"
+
+    if test -z "$files"; then
+      if test -z "$dest"; then
+       func_fatal_help "no file or destination specified"
+      else
+       func_fatal_help "you must specify a destination"
+      fi
+    fi
+
+    # Strip any trailing slash from the destination.
+    func_stripname '' '/' "$dest"
+    dest=$func_stripname_result
+
+    # Check to see that the destination is a directory.
+    test -d "$dest" && isdir=yes
+    if test "$isdir" = yes; then
+      destdir="$dest"
+      destname=
+    else
+      func_dirname_and_basename "$dest" "" "."
+      destdir="$func_dirname_result"
+      destname="$func_basename_result"
+
+      # Not a directory, so check to see that there is only one file specified.
+      set dummy $files; shift
+      test "$#" -gt 1 && \
+       func_fatal_help "\`$dest' is not a directory"
+    fi
+    case $destdir in
+    [\\/]* | [A-Za-z]:[\\/]*) ;;
+    *)
+      for file in $files; do
+       case $file in
+       *.lo) ;;
+       *)
+         func_fatal_help "\`$destdir' must be an absolute directory name"
+         ;;
+       esac
+      done
+      ;;
+    esac
+
+    # This variable tells wrapper scripts just to set variables rather
+    # than running their programs.
+    libtool_install_magic="$magic"
+
+    staticlibs=
+    future_libdirs=
+    current_libdirs=
+    for file in $files; do
+
+      # Do each installation.
+      case $file in
+      *.$libext)
+       # Do the static libraries later.
+       staticlibs="$staticlibs $file"
+       ;;
+
+      *.la)
+       # Check to see that this really is a libtool archive.
+       func_lalib_unsafe_p "$file" \
+         || func_fatal_help "\`$file' is not a valid libtool archive"
+
+       library_names=
+       old_library=
+       relink_command=
+       func_source "$file"
+
+       # Add the libdir to current_libdirs if it is the destination.
+       if test "X$destdir" = "X$libdir"; then
+         case "$current_libdirs " in
+         *" $libdir "*) ;;
+         *) current_libdirs="$current_libdirs $libdir" ;;
+         esac
+       else
+         # Note the libdir as a future libdir.
+         case "$future_libdirs " in
+         *" $libdir "*) ;;
+         *) future_libdirs="$future_libdirs $libdir" ;;
+         esac
+       fi
+
+       func_dirname "$file" "/" ""
+       dir="$func_dirname_result"
+       dir="$dir$objdir"
+
+       if test -n "$relink_command"; then
+         # Determine the prefix the user has applied to our future dir.
+         inst_prefix_dir=`$ECHO "X$destdir" | $Xsed -e "s%$libdir\$%%"`
+
+         # Don't allow the user to place us outside of our expected
+         # location b/c this prevents finding dependent libraries that
+         # are installed to the same prefix.
+         # At present, this check doesn't affect windows .dll's that
+         # are installed into $libdir/../bin (currently, that works fine)
+         # but it's something to keep an eye on.
+         test "$inst_prefix_dir" = "$destdir" && \
+           func_fatal_error "error: cannot install \`$file' to a directory not ending in $libdir"
+
+         if test -n "$inst_prefix_dir"; then
+           # Stick the inst_prefix_dir data into the link command.
+           relink_command=`$ECHO "X$relink_command" | $Xsed -e "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
+         else
+           relink_command=`$ECHO "X$relink_command" | $Xsed -e "s%@inst_prefix_dir@%%"`
+         fi
+
+         func_warning "relinking \`$file'"
+         func_show_eval "$relink_command" \
+           'func_fatal_error "error: relink \`$file'\'' with the above command before installing it"'
+       fi
+
+       # See the names of the shared library.
+       set dummy $library_names; shift
+       if test -n "$1"; then
+         realname="$1"
+         shift
+
+         srcname="$realname"
+         test -n "$relink_command" && srcname="$realname"T
+
+         # Install the shared library and build the symlinks.
+         func_show_eval "$install_prog $dir/$srcname $destdir/$realname" \
+             'exit $?'
+         tstripme="$stripme"
+         case $host_os in
+         cygwin* | mingw* | pw32* | cegcc*)
+           case $realname in
+           *.dll.a)
+             tstripme=""
+             ;;
+           esac
+           ;;
+         esac
+         if test -n "$tstripme" && test -n "$striplib"; then
+           func_show_eval "$striplib $destdir/$realname" 'exit $?'
+         fi
+
+         if test "$#" -gt 0; then
+           # Delete the old symlinks, and create new ones.
+           # Try `ln -sf' first, because the `ln' binary might depend on
+           # the symlink we replace!  Solaris /bin/ln does not understand -f,
+           # so we also need to try rm && ln -s.
+           for linkname
+           do
+             test "$linkname" != "$realname" \
+               && func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
+           done
+         fi
+
+         # Do each command in the postinstall commands.
+         lib="$destdir/$realname"
+         func_execute_cmds "$postinstall_cmds" 'exit $?'
+       fi
+
+       # Install the pseudo-library for information purposes.
+       func_basename "$file"
+       name="$func_basename_result"
+       instname="$dir/$name"i
+       func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
+
+       # Maybe install the static library, too.
+       test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library"
+       ;;
+
+      *.lo)
+       # Install (i.e. copy) a libtool object.
+
+       # Figure out destination file name, if it wasn't already specified.
+       if test -n "$destname"; then
+         destfile="$destdir/$destname"
+       else
+         func_basename "$file"
+         destfile="$func_basename_result"
+         destfile="$destdir/$destfile"
+       fi
+
+       # Deduce the name of the destination old-style object file.
+       case $destfile in
+       *.lo)
+         func_lo2o "$destfile"
+         staticdest=$func_lo2o_result
+         ;;
+       *.$objext)
+         staticdest="$destfile"
+         destfile=
+         ;;
+       *)
+         func_fatal_help "cannot copy a libtool object to \`$destfile'"
+         ;;
+       esac
+
+       # Install the libtool object if requested.
+       test -n "$destfile" && \
+         func_show_eval "$install_prog $file $destfile" 'exit $?'
+
+       # Install the old object if enabled.
+       if test "$build_old_libs" = yes; then
+         # Deduce the name of the old-style object file.
+         func_lo2o "$file"
+         staticobj=$func_lo2o_result
+         func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
+       fi
+       exit $EXIT_SUCCESS
+       ;;
+
+      *)
+       # Figure out destination file name, if it wasn't already specified.
+       if test -n "$destname"; then
+         destfile="$destdir/$destname"
+       else
+         func_basename "$file"
+         destfile="$func_basename_result"
+         destfile="$destdir/$destfile"
+       fi
+
+       # If the file is missing, and there is a .exe on the end, strip it
+       # because it is most likely a libtool script we actually want to
+       # install
+       stripped_ext=""
+       case $file in
+         *.exe)
+           if test ! -f "$file"; then
+             func_stripname '' '.exe' "$file"
+             file=$func_stripname_result
+             stripped_ext=".exe"
+           fi
+           ;;
+       esac
+
+       # Do a test to see if this is really a libtool program.
+       case $host in
+       *cygwin* | *mingw*)
+           if func_ltwrapper_executable_p "$file"; then
+             func_ltwrapper_scriptname "$file"
+             wrapper=$func_ltwrapper_scriptname_result
+           else
+             func_stripname '' '.exe' "$file"
+             wrapper=$func_stripname_result
+           fi
+           ;;
+       *)
+           wrapper=$file
+           ;;
+       esac
+       if func_ltwrapper_script_p "$wrapper"; then
+         notinst_deplibs=
+         relink_command=
+
+         func_source "$wrapper"
+
+         # Check the variables that should have been set.
+         test -z "$generated_by_libtool_version" && \
+           func_fatal_error "invalid libtool wrapper script \`$wrapper'"
+
+         finalize=yes
+         for lib in $notinst_deplibs; do
+           # Check to see that each library is installed.
+           libdir=
+           if test -f "$lib"; then
+             func_source "$lib"
+           fi
+           libfile="$libdir/"`$ECHO "X$lib" | $Xsed -e 's%^.*/%%g'` ### testsuite: skip nested quoting test
+           if test -n "$libdir" && test ! -f "$libfile"; then
+             func_warning "\`$lib' has not been installed in \`$libdir'"
+             finalize=no
+           fi
+         done
+
+         relink_command=
+         func_source "$wrapper"
+
+         outputname=
+         if test "$fast_install" = no && test -n "$relink_command"; then
+           $opt_dry_run || {
+             if test "$finalize" = yes; then
+               tmpdir=`func_mktempdir`
+               func_basename "$file$stripped_ext"
+               file="$func_basename_result"
+               outputname="$tmpdir/$file"
+               # Replace the output file specification.
+               relink_command=`$ECHO "X$relink_command" | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g'`
+
+               $opt_silent || {
+                 func_quote_for_expand "$relink_command"
+                 eval "func_echo $func_quote_for_expand_result"
+               }
+               if eval "$relink_command"; then :
+                 else
+                 func_error "error: relink \`$file' with the above command before installing it"
+                 $opt_dry_run || ${RM}r "$tmpdir"
+                 continue
+               fi
+               file="$outputname"
+             else
+               func_warning "cannot relink \`$file'"
+             fi
+           }
+         else
+           # Install the binary that we compiled earlier.
+           file=`$ECHO "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"`
+         fi
+       fi
+
+       # remove .exe since cygwin /usr/bin/install will append another
+       # one anyway
+       case $install_prog,$host in
+       */usr/bin/install*,*cygwin*)
+         case $file:$destfile in
+         *.exe:*.exe)
+           # this is ok
+           ;;
+         *.exe:*)
+           destfile=$destfile.exe
+           ;;
+         *:*.exe)
+           func_stripname '' '.exe' "$destfile"
+           destfile=$func_stripname_result
+           ;;
+         esac
+         ;;
+       esac
+       func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
+       $opt_dry_run || if test -n "$outputname"; then
+         ${RM}r "$tmpdir"
+       fi
+       ;;
+      esac
+    done
+
+    for file in $staticlibs; do
+      func_basename "$file"
+      name="$func_basename_result"
+
+      # Set up the ranlib parameters.
+      oldlib="$destdir/$name"
+
+      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
+
+      if test -n "$stripme" && test -n "$old_striplib"; then
+       func_show_eval "$old_striplib $oldlib" 'exit $?'
+      fi
+
+      # Do each command in the postinstall commands.
+      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
+    done
+
+    test -n "$future_libdirs" && \
+      func_warning "remember to run \`$progname --finish$future_libdirs'"
+
+    if test -n "$current_libdirs"; then
+      # Maybe just do a dry run.
+      $opt_dry_run && current_libdirs=" -n$current_libdirs"
+      exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs'
+    else
+      exit $EXIT_SUCCESS
+    fi
+}
+
+test "$mode" = install && func_mode_install ${1+"$@"}
+
+
+# func_generate_dlsyms outputname originator pic_p
+# Extract symbols from dlprefiles and create ${outputname}S.o with
+# a dlpreopen symbol table.
+func_generate_dlsyms ()
+{
+    $opt_debug
+    my_outputname="$1"
+    my_originator="$2"
+    my_pic_p="${3-no}"
+    my_prefix=`$ECHO "$my_originator" | sed 's%[^a-zA-Z0-9]%_%g'`
+    my_dlsyms=
+
+    if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
+      if test -n "$NM" && test -n "$global_symbol_pipe"; then
+       my_dlsyms="${my_outputname}S.c"
+      else
+       func_error "not configured to extract global symbols from dlpreopened files"
+      fi
+    fi
+
+    if test -n "$my_dlsyms"; then
+      case $my_dlsyms in
+      "") ;;
+      *.c)
+       # Discover the nlist of each of the dlfiles.
+       nlist="$output_objdir/${my_outputname}.nm"
+
+       func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
+
+       # Parse the name list into a source file.
+       func_verbose "creating $output_objdir/$my_dlsyms"
+
+       $opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
+/* $my_dlsyms - symbol resolution table for \`$my_outputname' dlsym emulation. */
+/* Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION */
+
+#ifdef __cplusplus
+extern \"C\" {
+#endif
+
+/* External symbol declarations for the compiler. */\
+"
+
+       if test "$dlself" = yes; then
+         func_verbose "generating symbol list for \`$output'"
+
+         $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
+
+         # Add our own program objects to the symbol list.
+         progfiles=`$ECHO "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+         for progfile in $progfiles; do
+           func_verbose "extracting global C symbols from \`$progfile'"
+           $opt_dry_run || eval "$NM $progfile | $global_symbol_pipe >> '$nlist'"
+         done
+
+         if test -n "$exclude_expsyms"; then
+           $opt_dry_run || {
+             eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
+             eval '$MV "$nlist"T "$nlist"'
+           }
+         fi
+
+         if test -n "$export_symbols_regex"; then
+           $opt_dry_run || {
+             eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
+             eval '$MV "$nlist"T "$nlist"'
+           }
+         fi
+
+         # Prepare the list of exported symbols
+         if test -z "$export_symbols"; then
+           export_symbols="$output_objdir/$outputname.exp"
+           $opt_dry_run || {
+             $RM $export_symbols
+             eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
+             case $host in
+             *cygwin* | *mingw* | *cegcc* )
+                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
+                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
+               ;;
+             esac
+           }
+         else
+           $opt_dry_run || {
+             eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
+             eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
+             eval '$MV "$nlist"T "$nlist"'
+             case $host in
+               *cygwin | *mingw* | *cegcc* )
+                 eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
+                 eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
+                 ;;
+             esac
+           }
+         fi
+       fi
+
+       for dlprefile in $dlprefiles; do
+         func_verbose "extracting global C symbols from \`$dlprefile'"
+         func_basename "$dlprefile"
+         name="$func_basename_result"
+         $opt_dry_run || {
+           eval '$ECHO ": $name " >> "$nlist"'
+           eval "$NM $dlprefile 2>/dev/null | $global_symbol_pipe >> '$nlist'"
+         }
+       done
+
+       $opt_dry_run || {
+         # Make sure we have at least an empty file.
+         test -f "$nlist" || : > "$nlist"
+
+         if test -n "$exclude_expsyms"; then
+           $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
+           $MV "$nlist"T "$nlist"
+         fi
+
+         # Try sorting and uniquifying the output.
+         if $GREP -v "^: " < "$nlist" |
+             if sort -k 3 </dev/null >/dev/null 2>&1; then
+               sort -k 3
+             else
+               sort +2
+             fi |
+             uniq > "$nlist"S; then
+           :
+         else
+           $GREP -v "^: " < "$nlist" > "$nlist"S
+         fi
+
+         if test -f "$nlist"S; then
+           eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
+         else
+           $ECHO '/* NONE */' >> "$output_objdir/$my_dlsyms"
+         fi
+
+         $ECHO >> "$output_objdir/$my_dlsyms" "\
+
+/* The mapping between symbol names and symbols.  */
+typedef struct {
+  const char *name;
+  void *address;
+} lt_dlsymlist;
+"
+         case $host in
+         *cygwin* | *mingw* | *cegcc* )
+           $ECHO >> "$output_objdir/$my_dlsyms" "\
+/* DATA imports from DLLs on WIN32 con't be const, because
+   runtime relocations are performed -- see ld's documentation
+   on pseudo-relocs.  */"
+           lt_dlsym_const= ;;
+         *osf5*)
+           echo >> "$output_objdir/$my_dlsyms" "\
+/* This system does not cope well with relocations in const data */"
+           lt_dlsym_const= ;;
+         *)
+           lt_dlsym_const=const ;;
+         esac
+
+         $ECHO >> "$output_objdir/$my_dlsyms" "\
+extern $lt_dlsym_const lt_dlsymlist
+lt_${my_prefix}_LTX_preloaded_symbols[];
+$lt_dlsym_const lt_dlsymlist
+lt_${my_prefix}_LTX_preloaded_symbols[] =
+{\
+  { \"$my_originator\", (void *) 0 },"
+
+         case $need_lib_prefix in
+         no)
+           eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
+           ;;
+         *)
+           eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
+           ;;
+         esac
+         $ECHO >> "$output_objdir/$my_dlsyms" "\
+  {0, (void *) 0}
+};
+
+/* This works around a problem in FreeBSD linker */
+#ifdef FREEBSD_WORKAROUND
+static const void *lt_preloaded_setup() {
+  return lt_${my_prefix}_LTX_preloaded_symbols;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif\
+"
+       } # !$opt_dry_run
+
+       pic_flag_for_symtable=
+       case "$compile_command " in
+       *" -static "*) ;;
+       *)
+         case $host in
+         # compiling the symbol table file with pic_flag works around
+         # a FreeBSD bug that causes programs to crash when -lm is
+         # linked before any other PIC object.  But we must not use
+         # pic_flag when linking with -static.  The problem exists in
+         # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
+         *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
+           pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
+         *-*-hpux*)
+           pic_flag_for_symtable=" $pic_flag"  ;;
+         *)
+           if test "X$my_pic_p" != Xno; then
+             pic_flag_for_symtable=" $pic_flag"
+           fi
+           ;;
+         esac
+         ;;
+       esac
+       symtab_cflags=
+       for arg in $LTCFLAGS; do
+         case $arg in
+         -pie | -fpie | -fPIE) ;;
+         *) symtab_cflags="$symtab_cflags $arg" ;;
+         esac
+       done
+
+       # Now compile the dynamic symbol file.
+       func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
+
+       # Clean up the generated files.
+       func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T"'
+
+       # Transform the symbol file into the correct name.
+       symfileobj="$output_objdir/${my_outputname}S.$objext"
+       case $host in
+       *cygwin* | *mingw* | *cegcc* )
+         if test -f "$output_objdir/$my_outputname.def"; then
+           compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
+           finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
+         else
+           compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
+           finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
+         fi
+         ;;
+       *)
+         compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
+         finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
+         ;;
+       esac
+       ;;
+      *)
+       func_fatal_error "unknown suffix for \`$my_dlsyms'"
+       ;;
+      esac
+    else
+      # We keep going just in case the user didn't refer to
+      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
+      # really was required.
+
+      # Nullify the symbol file.
+      compile_command=`$ECHO "X$compile_command" | $Xsed -e "s% @SYMFILE@%%"`
+      finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s% @SYMFILE@%%"`
+    fi
+}
+
+# func_win32_libid arg
+# return the library type of file 'arg'
+#
+# Need a lot of goo to handle *both* DLLs and import libs
+# Has to be a shell function in order to 'eat' the argument
+# that is supplied when $file_magic_command is called.
+func_win32_libid ()
+{
+  $opt_debug
+  win32_libid_type="unknown"
+  win32_fileres=`file -L $1 2>/dev/null`
+  case $win32_fileres in
+  *ar\ archive\ import\ library*) # definitely import
+    win32_libid_type="x86 archive import"
+    ;;
+  *ar\ archive*) # could be an import, or static
+    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
+       $EGREP 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then
+      win32_nmres=`eval $NM -f posix -A $1 |
+       $SED -n -e '
+           1,100{
+               / I /{
+                   s,.*,import,
+                   p
+                   q
+               }
+           }'`
+      case $win32_nmres in
+      import*)  win32_libid_type="x86 archive import";;
+      *)        win32_libid_type="x86 archive static";;
+      esac
+    fi
+    ;;
+  *DLL*)
+    win32_libid_type="x86 DLL"
+    ;;
+  *executable*) # but shell scripts are "executable" too...
+    case $win32_fileres in
+    *MS\ Windows\ PE\ Intel*)
+      win32_libid_type="x86 DLL"
+      ;;
+    esac
+    ;;
+  esac
+  $ECHO "$win32_libid_type"
+}
+
+
+
+# func_extract_an_archive dir oldlib
+func_extract_an_archive ()
+{
+    $opt_debug
+    f_ex_an_ar_dir="$1"; shift
+    f_ex_an_ar_oldlib="$1"
+    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" 'exit $?'
+    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
+     :
+    else
+      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
+    fi
+}
+
+
+# func_extract_archives gentop oldlib ...
+func_extract_archives ()
+{
+    $opt_debug
+    my_gentop="$1"; shift
+    my_oldlibs=${1+"$@"}
+    my_oldobjs=""
+    my_xlib=""
+    my_xabs=""
+    my_xdir=""
+
+    for my_xlib in $my_oldlibs; do
+      # Extract the objects.
+      case $my_xlib in
+       [\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;;
+       *) my_xabs=`pwd`"/$my_xlib" ;;
+      esac
+      func_basename "$my_xlib"
+      my_xlib="$func_basename_result"
+      my_xlib_u=$my_xlib
+      while :; do
+        case " $extracted_archives " in
+       *" $my_xlib_u "*)
+         func_arith $extracted_serial + 1
+         extracted_serial=$func_arith_result
+         my_xlib_u=lt$extracted_serial-$my_xlib ;;
+       *) break ;;
+       esac
+      done
+      extracted_archives="$extracted_archives $my_xlib_u"
+      my_xdir="$my_gentop/$my_xlib_u"
+
+      func_mkdir_p "$my_xdir"
+
+      case $host in
+      *-darwin*)
+       func_verbose "Extracting $my_xabs"
+       # Do not bother doing anything if just a dry run
+       $opt_dry_run || {
+         darwin_orig_dir=`pwd`
+         cd $my_xdir || exit $?
+         darwin_archive=$my_xabs
+         darwin_curdir=`pwd`
+         darwin_base_archive=`basename "$darwin_archive"`
+         darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
+         if test -n "$darwin_arches"; then
+           darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
+           darwin_arch=
+           func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
+           for darwin_arch in  $darwin_arches ; do
+             func_mkdir_p "unfat-$$/${darwin_base_archive}-${darwin_arch}"
+             $LIPO -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}"
+             cd "unfat-$$/${darwin_base_archive}-${darwin_arch}"
+             func_extract_an_archive "`pwd`" "${darwin_base_archive}"
+             cd "$darwin_curdir"
+             $RM "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}"
+           done # $darwin_arches
+            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
+           darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$basename" | sort -u`
+           darwin_file=
+           darwin_files=
+           for darwin_file in $darwin_filelist; do
+             darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP`
+             $LIPO -create -output "$darwin_file" $darwin_files
+           done # $darwin_filelist
+           $RM -rf unfat-$$
+           cd "$darwin_orig_dir"
+         else
+           cd $darwin_orig_dir
+           func_extract_an_archive "$my_xdir" "$my_xabs"
+         fi # $darwin_arches
+       } # !$opt_dry_run
+       ;;
+      *)
+        func_extract_an_archive "$my_xdir" "$my_xabs"
+       ;;
+      esac
+      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP`
+    done
+
+    func_extract_archives_result="$my_oldobjs"
+}
+
+
+
+# func_emit_wrapper_part1 [arg=no]
+#
+# Emit the first part of a libtool wrapper script on stdout.
+# For more information, see the description associated with
+# func_emit_wrapper(), below.
+func_emit_wrapper_part1 ()
+{
+       func_emit_wrapper_part1_arg1=no
+       if test -n "$1" ; then
+         func_emit_wrapper_part1_arg1=$1
+       fi
+
+       $ECHO "\
+#! $SHELL
+
+# $output - temporary wrapper script for $objdir/$outputname
+# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+#
+# The $output program cannot be directly executed until all the libtool
+# libraries that it depends on are installed.
+#
+# This wrapper script should never be moved out of the build directory.
+# If it is, it will not operate correctly.
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+Xsed='${SED} -e 1s/^X//'
+sed_quote_subst='$sed_quote_subst'
+
+# Be Bourne compatible
+if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '\${1+\"\$@\"}'='\"\$@\"'
+  setopt NO_GLOB_SUBST
+else
+  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+relink_command=\"$relink_command\"
+
+# This environment variable determines our operation mode.
+if test \"\$libtool_install_magic\" = \"$magic\"; then
+  # install mode needs the following variables:
+  generated_by_libtool_version='$macro_version'
+  notinst_deplibs='$notinst_deplibs'
+else
+  # When we are sourced in execute mode, \$file and \$ECHO are already set.
+  if test \"\$libtool_execute_magic\" != \"$magic\"; then
+    ECHO=\"$qecho\"
+    file=\"\$0\"
+    # Make sure echo works.
+    if test \"X\$1\" = X--no-reexec; then
+      # Discard the --no-reexec flag, and continue.
+      shift
+    elif test \"X\`{ \$ECHO '\t'; } 2>/dev/null\`\" = 'X\t'; then
+      # Yippee, \$ECHO works!
+      :
+    else
+      # Restart under the correct shell, and then maybe \$ECHO will work.
+      exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"}
+    fi
+  fi\
+"
+       $ECHO "\
+
+  # Find the directory that this script lives in.
+  thisdir=\`\$ECHO \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\`
+  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
+
+  # Follow symbolic links until we get to the real thisdir.
+  file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\`
+  while test -n \"\$file\"; do
+    destdir=\`\$ECHO \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\`
+
+    # If there was a directory component, then change thisdir.
+    if test \"x\$destdir\" != \"x\$file\"; then
+      case \"\$destdir\" in
+      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
+      *) thisdir=\"\$thisdir/\$destdir\" ;;
+      esac
+    fi
+
+    file=\`\$ECHO \"X\$file\" | \$Xsed -e 's%^.*/%%'\`
+    file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\`
+  done
+"
+}
+# end: func_emit_wrapper_part1
+
+# func_emit_wrapper_part2 [arg=no]
+#
+# Emit the second part of a libtool wrapper script on stdout.
+# For more information, see the description associated with
+# func_emit_wrapper(), below.
+func_emit_wrapper_part2 ()
+{
+       func_emit_wrapper_part2_arg1=no
+       if test -n "$1" ; then
+         func_emit_wrapper_part2_arg1=$1
+       fi
+
+       $ECHO "\
+
+  # Usually 'no', except on cygwin/mingw when embedded into
+  # the cwrapper.
+  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_part2_arg1
+  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
+    # special case for '.'
+    if test \"\$thisdir\" = \".\"; then
+      thisdir=\`pwd\`
+    fi
+    # remove .libs from thisdir
+    case \"\$thisdir\" in
+    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"X\$thisdir\" | \$Xsed -e 's%[\\\\/][^\\\\/]*$%%'\` ;;
+    $objdir )   thisdir=. ;;
+    esac
+  fi
+
+  # Try to get the absolute directory name.
+  absdir=\`cd \"\$thisdir\" && pwd\`
+  test -n \"\$absdir\" && thisdir=\"\$absdir\"
+"
+
+       if test "$fast_install" = yes; then
+         $ECHO "\
+  program=lt-'$outputname'$exeext
+  progdir=\"\$thisdir/$objdir\"
+
+  if test ! -f \"\$progdir/\$program\" ||
+     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\
+       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
+
+    file=\"\$\$-\$program\"
+
+    if test ! -d \"\$progdir\"; then
+      $MKDIR \"\$progdir\"
+    else
+      $RM \"\$progdir/\$file\"
+    fi"
+
+         $ECHO "\
+
+    # relink executable if necessary
+    if test -n \"\$relink_command\"; then
+      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
+      else
+       $ECHO \"\$relink_command_output\" >&2
+       $RM \"\$progdir/\$file\"
+       exit 1
+      fi
+    fi
+
+    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
+    { $RM \"\$progdir/\$program\";
+      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
+    $RM \"\$progdir/\$file\"
+  fi"
+       else
+         $ECHO "\
+  program='$outputname'
+  progdir=\"\$thisdir/$objdir\"
+"
+       fi
+
+       $ECHO "\
+
+  if test -f \"\$progdir/\$program\"; then"
+
+       # Export our shlibpath_var if we have one.
+       if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
+         $ECHO "\
+    # Add our own library path to $shlibpath_var
+    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
+
+    # Some systems cannot cope with colon-terminated $shlibpath_var
+    # The second colon is a workaround for a bug in BeOS R4 sed
+    $shlibpath_var=\`\$ECHO \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\`
+
+    export $shlibpath_var
+"
+       fi
+
+       # fixup the dll searchpath if we need to.
+       if test -n "$dllsearchpath"; then
+         $ECHO "\
+    # Add the dll search path components to the executable PATH
+    PATH=$dllsearchpath:\$PATH
+"
+       fi
+
+       $ECHO "\
+    if test \"\$libtool_execute_magic\" != \"$magic\"; then
+      # Run the actual program with our arguments.
+"
+       case $host in
+       # Backslashes separate directories on plain windows
+       *-*-mingw | *-*-os2* | *-cegcc*)
+         $ECHO "\
+      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
+"
+         ;;
+
+       *)
+         $ECHO "\
+      exec \"\$progdir/\$program\" \${1+\"\$@\"}
+"
+         ;;
+       esac
+       $ECHO "\
+      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
+      exit 1
+    fi
+  else
+    # The program doesn't exist.
+    \$ECHO \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2
+    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
+    $ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
+    exit 1
+  fi
+fi\
+"
+}
+# end: func_emit_wrapper_part2
+
+
+# func_emit_wrapper [arg=no]
+#
+# Emit a libtool wrapper script on stdout.
+# Don't directly open a file because we may want to
+# incorporate the script contents within a cygwin/mingw
+# wrapper executable.  Must ONLY be called from within
+# func_mode_link because it depends on a number of variables
+# set therein.
+#
+# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
+# variable will take.  If 'yes', then the emitted script
+# will assume that the directory in which it is stored is
+# the $objdir directory.  This is a cygwin/mingw-specific
+# behavior.
+func_emit_wrapper ()
+{
+       func_emit_wrapper_arg1=no
+       if test -n "$1" ; then
+         func_emit_wrapper_arg1=$1
+       fi
+
+       # split this up so that func_emit_cwrapperexe_src
+       # can call each part independently.
+       func_emit_wrapper_part1 "${func_emit_wrapper_arg1}"
+       func_emit_wrapper_part2 "${func_emit_wrapper_arg1}"
+}
+
+
+# func_to_host_path arg
+#
+# Convert paths to host format when used with build tools.
+# Intended for use with "native" mingw (where libtool itself
+# is running under the msys shell), or in the following cross-
+# build environments:
+#    $build          $host
+#    mingw (msys)    mingw  [e.g. native]
+#    cygwin          mingw
+#    *nix + wine     mingw
+# where wine is equipped with the `winepath' executable.
+# In the native mingw case, the (msys) shell automatically
+# converts paths for any non-msys applications it launches,
+# but that facility isn't available from inside the cwrapper.
+# Similar accommodations are necessary for $host mingw and
+# $build cygwin.  Calling this function does no harm for other
+# $host/$build combinations not listed above.
+#
+# ARG is the path (on $build) that should be converted to
+# the proper representation for $host. The result is stored
+# in $func_to_host_path_result.
+func_to_host_path ()
+{
+  func_to_host_path_result="$1"
+  if test -n "$1" ; then
+    case $host in
+      *mingw* )
+        lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
+        case $build in
+          *mingw* ) # actually, msys
+            # awkward: cmd appends spaces to result
+            lt_sed_strip_trailing_spaces="s/[ ]*\$//"
+            func_to_host_path_tmp1=`( cmd //c echo "$1" |\
+              $SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""`
+            func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
+              $SED -e "$lt_sed_naive_backslashify"`
+            ;;
+          *cygwin* )
+            func_to_host_path_tmp1=`cygpath -w "$1"`
+            func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
+              $SED -e "$lt_sed_naive_backslashify"`
+            ;;
+          * )
+            # Unfortunately, winepath does not exit with a non-zero
+            # error code, so we are forced to check the contents of
+            # stdout. On the other hand, if the command is not
+            # found, the shell will set an exit code of 127 and print
+            # *an error message* to stdout. So we must check for both
+            # error code of zero AND non-empty stdout, which explains
+            # the odd construction:
+            func_to_host_path_tmp1=`winepath -w "$1" 2>/dev/null`
+            if test "$?" -eq 0 && test -n "${func_to_host_path_tmp1}"; then
+              func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
+                $SED -e "$lt_sed_naive_backslashify"`
+            else
+              # Allow warning below.
+              func_to_host_path_result=""
+            fi
+            ;;
+        esac
+        if test -z "$func_to_host_path_result" ; then
+          func_error "Could not determine host path corresponding to"
+          func_error "  '$1'"
+          func_error "Continuing, but uninstalled executables may not work."
+          # Fallback:
+          func_to_host_path_result="$1"
+        fi
+        ;;
+    esac
+  fi
+}
+# end: func_to_host_path
+
+# func_to_host_pathlist arg
+#
+# Convert pathlists to host format when used with build tools.
+# See func_to_host_path(), above. This function supports the
+# following $build/$host combinations (but does no harm for
+# combinations not listed here):
+#    $build          $host
+#    mingw (msys)    mingw  [e.g. native]
+#    cygwin          mingw
+#    *nix + wine     mingw
+#
+# Path separators are also converted from $build format to
+# $host format. If ARG begins or ends with a path separator
+# character, it is preserved (but converted to $host format)
+# on output.
+#
+# ARG is a pathlist (on $build) that should be converted to
+# the proper representation on $host. The result is stored
+# in $func_to_host_pathlist_result.
+func_to_host_pathlist ()
+{
+  func_to_host_pathlist_result="$1"
+  if test -n "$1" ; then
+    case $host in
+      *mingw* )
+        lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
+        # Remove leading and trailing path separator characters from
+        # ARG. msys behavior is inconsistent here, cygpath turns them
+        # into '.;' and ';.', and winepath ignores them completely.
+        func_to_host_pathlist_tmp2="$1"
+        # Once set for this call, this variable should not be
+        # reassigned. It is used in tha fallback case.
+        func_to_host_pathlist_tmp1=`echo "$func_to_host_pathlist_tmp2" |\
+          $SED -e 's|^:*||' -e 's|:*$||'`
+        case $build in
+          *mingw* ) # Actually, msys.
+            # Awkward: cmd appends spaces to result.
+            lt_sed_strip_trailing_spaces="s/[ ]*\$//"
+            func_to_host_pathlist_tmp2=`( cmd //c echo "$func_to_host_pathlist_tmp1" |\
+              $SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""`
+            func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\
+              $SED -e "$lt_sed_naive_backslashify"`
+            ;;
+          *cygwin* )
+            func_to_host_pathlist_tmp2=`cygpath -w -p "$func_to_host_pathlist_tmp1"`
+            func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\
+              $SED -e "$lt_sed_naive_backslashify"`
+            ;;
+          * )
+            # unfortunately, winepath doesn't convert pathlists
+            func_to_host_pathlist_result=""
+            func_to_host_pathlist_oldIFS=$IFS
+            IFS=:
+            for func_to_host_pathlist_f in $func_to_host_pathlist_tmp1 ; do
+              IFS=$func_to_host_pathlist_oldIFS
+              if test -n "$func_to_host_pathlist_f" ; then
+                func_to_host_path "$func_to_host_pathlist_f"
+                if test -n "$func_to_host_path_result" ; then
+                  if test -z "$func_to_host_pathlist_result" ; then
+                    func_to_host_pathlist_result="$func_to_host_path_result"
+                  else
+                    func_to_host_pathlist_result="$func_to_host_pathlist_result;$func_to_host_path_result"
+                  fi
+                fi
+              fi
+              IFS=:
+            done
+            IFS=$func_to_host_pathlist_oldIFS
+            ;;
+        esac
+        if test -z "$func_to_host_pathlist_result" ; then
+          func_error "Could not determine the host path(s) corresponding to"
+          func_error "  '$1'"
+          func_error "Continuing, but uninstalled executables may not work."
+          # Fallback. This may break if $1 contains DOS-style drive
+          # specifications. The fix is not to complicate the expression
+          # below, but for the user to provide a working wine installation
+          # with winepath so that path translation in the cross-to-mingw
+          # case works properly.
+          lt_replace_pathsep_nix_to_dos="s|:|;|g"
+          func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp1" |\
+            $SED -e "$lt_replace_pathsep_nix_to_dos"`
+        fi
+        # Now, add the leading and trailing path separators back
+        case "$1" in
+          :* ) func_to_host_pathlist_result=";$func_to_host_pathlist_result"
+            ;;
+        esac
+        case "$1" in
+          *: ) func_to_host_pathlist_result="$func_to_host_pathlist_result;"
+            ;;
+        esac
+        ;;
+    esac
+  fi
+}
+# end: func_to_host_pathlist
+
+# func_emit_cwrapperexe_src
+# emit the source code for a wrapper executable on stdout
+# Must ONLY be called from within func_mode_link because
+# it depends on a number of variable set therein.
+func_emit_cwrapperexe_src ()
+{
+       cat <<EOF
+
+/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
+   Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+
+   The $output program cannot be directly executed until all the libtool
+   libraries that it depends on are installed.
+
+   This wrapper executable should never be moved out of the build directory.
+   If it is, it will not operate correctly.
+
+   Currently, it simply execs the wrapper *script* "$SHELL $output",
+   but could eventually absorb all of the scripts functionality and
+   exec $objdir/$outputname directly.
+*/
+EOF
+           cat <<"EOF"
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef _MSC_VER
+# include <direct.h>
+# include <process.h>
+# include <io.h>
+# define setmode _setmode
+#else
+# include <unistd.h>
+# include <stdint.h>
+# ifdef __CYGWIN__
+#  include <io.h>
+#  define HAVE_SETENV
+#  ifdef __STRICT_ANSI__
+char *realpath (const char *, char *);
+int putenv (char *);
+int setenv (const char *, const char *, int);
+#  endif
+# endif
+#endif
+#include <malloc.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#if defined(PATH_MAX)
+# define LT_PATHMAX PATH_MAX
+#elif defined(MAXPATHLEN)
+# define LT_PATHMAX MAXPATHLEN
+#else
+# define LT_PATHMAX 1024
+#endif
+
+#ifndef S_IXOTH
+# define S_IXOTH 0
+#endif
+#ifndef S_IXGRP
+# define S_IXGRP 0
+#endif
+
+#ifdef _MSC_VER
+# define S_IXUSR _S_IEXEC
+# define stat _stat
+# ifndef _INTPTR_T_DEFINED
+#  define intptr_t int
+# endif
+#endif
+
+#ifndef DIR_SEPARATOR
+# define DIR_SEPARATOR '/'
+# define PATH_SEPARATOR ':'
+#endif
+
+#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
+  defined (__OS2__)
+# define HAVE_DOS_BASED_FILE_SYSTEM
+# define FOPEN_WB "wb"
+# ifndef DIR_SEPARATOR_2
+#  define DIR_SEPARATOR_2 '\\'
+# endif
+# ifndef PATH_SEPARATOR_2
+#  define PATH_SEPARATOR_2 ';'
+# endif
+#endif
+
+#ifndef DIR_SEPARATOR_2
+# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
+#else /* DIR_SEPARATOR_2 */
+# define IS_DIR_SEPARATOR(ch) \
+       (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
+#endif /* DIR_SEPARATOR_2 */
+
+#ifndef PATH_SEPARATOR_2
+# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
+#else /* PATH_SEPARATOR_2 */
+# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
+#endif /* PATH_SEPARATOR_2 */
+
+#ifdef __CYGWIN__
+# define FOPEN_WB "wb"
+#endif
+
+#ifndef FOPEN_WB
+# define FOPEN_WB "w"
+#endif
+#ifndef _O_BINARY
+# define _O_BINARY 0
+#endif
+
+#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
+#define XFREE(stale) do { \
+  if (stale) { free ((void *) stale); stale = 0; } \
+} while (0)
+
+#undef LTWRAPPER_DEBUGPRINTF
+#if defined DEBUGWRAPPER
+# define LTWRAPPER_DEBUGPRINTF(args) ltwrapper_debugprintf args
+static void
+ltwrapper_debugprintf (const char *fmt, ...)
+{
+    va_list args;
+    va_start (args, fmt);
+    (void) vfprintf (stderr, fmt, args);
+    va_end (args);
+}
+#else
+# define LTWRAPPER_DEBUGPRINTF(args)
+#endif
+
+const char *program_name = NULL;
+
+void *xmalloc (size_t num);
+char *xstrdup (const char *string);
+const char *base_name (const char *name);
+char *find_executable (const char *wrapper);
+char *chase_symlinks (const char *pathspec);
+int make_executable (const char *path);
+int check_executable (const char *path);
+char *strendzap (char *str, const char *pat);
+void lt_fatal (const char *message, ...);
+void lt_setenv (const char *name, const char *value);
+char *lt_extend_str (const char *orig_value, const char *add, int to_end);
+void lt_opt_process_env_set (const char *arg);
+void lt_opt_process_env_prepend (const char *arg);
+void lt_opt_process_env_append (const char *arg);
+int lt_split_name_value (const char *arg, char** name, char** value);
+void lt_update_exe_path (const char *name, const char *value);
+void lt_update_lib_path (const char *name, const char *value);
+
+static const char *script_text_part1 =
+EOF
+
+           func_emit_wrapper_part1 yes |
+               $SED -e 's/\([\\"]\)/\\\1/g' \
+                    -e 's/^/  "/' -e 's/$/\\n"/'
+           echo ";"
+           cat <<EOF
+
+static const char *script_text_part2 =
+EOF
+           func_emit_wrapper_part2 yes |
+               $SED -e 's/\([\\"]\)/\\\1/g' \
+                    -e 's/^/  "/' -e 's/$/\\n"/'
+           echo ";"
+
+           cat <<EOF
+const char * MAGIC_EXE = "$magic_exe";
+const char * LIB_PATH_VARNAME = "$shlibpath_var";
+EOF
+
+           if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
+              func_to_host_pathlist "$temp_rpath"
+             cat <<EOF
+const char * LIB_PATH_VALUE   = "$func_to_host_pathlist_result";
+EOF
+           else
+             cat <<"EOF"
+const char * LIB_PATH_VALUE   = "";
+EOF
+           fi
+
+           if test -n "$dllsearchpath"; then
+              func_to_host_pathlist "$dllsearchpath:"
+             cat <<EOF
+const char * EXE_PATH_VARNAME = "PATH";
+const char * EXE_PATH_VALUE   = "$func_to_host_pathlist_result";
+EOF
+           else
+             cat <<"EOF"
+const char * EXE_PATH_VARNAME = "";
+const char * EXE_PATH_VALUE   = "";
+EOF
+           fi
+
+           if test "$fast_install" = yes; then
+             cat <<EOF
+const char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
+EOF
+           else
+             cat <<EOF
+const char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
+EOF
+           fi
+
+
+           cat <<"EOF"
+
+#define LTWRAPPER_OPTION_PREFIX         "--lt-"
+#define LTWRAPPER_OPTION_PREFIX_LENGTH  5
+
+static const size_t opt_prefix_len         = LTWRAPPER_OPTION_PREFIX_LENGTH;
+static const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
+
+static const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
+
+static const size_t env_set_opt_len     = LTWRAPPER_OPTION_PREFIX_LENGTH + 7;
+static const char *env_set_opt          = LTWRAPPER_OPTION_PREFIX "env-set";
+  /* argument is putenv-style "foo=bar", value of foo is set to bar */
+
+static const size_t env_prepend_opt_len = LTWRAPPER_OPTION_PREFIX_LENGTH + 11;
+static const char *env_prepend_opt      = LTWRAPPER_OPTION_PREFIX "env-prepend";
+  /* argument is putenv-style "foo=bar", new value of foo is bar${foo} */
+
+static const size_t env_append_opt_len  = LTWRAPPER_OPTION_PREFIX_LENGTH + 10;
+static const char *env_append_opt       = LTWRAPPER_OPTION_PREFIX "env-append";
+  /* argument is putenv-style "foo=bar", new value of foo is ${foo}bar */
+
+int
+main (int argc, char *argv[])
+{
+  char **newargz;
+  int  newargc;
+  char *tmp_pathspec;
+  char *actual_cwrapper_path;
+  char *actual_cwrapper_name;
+  char *target_name;
+  char *lt_argv_zero;
+  intptr_t rval = 127;
+
+  int i;
+
+  program_name = (char *) xstrdup (base_name (argv[0]));
+  LTWRAPPER_DEBUGPRINTF (("(main) argv[0]      : %s\n", argv[0]));
+  LTWRAPPER_DEBUGPRINTF (("(main) program_name : %s\n", program_name));
+
+  /* very simple arg parsing; don't want to rely on getopt */
+  for (i = 1; i < argc; i++)
+    {
+      if (strcmp (argv[i], dumpscript_opt) == 0)
+       {
+EOF
+           case "$host" in
+             *mingw* | *cygwin* )
+               # make stdout use "unix" line endings
+               echo "          setmode(1,_O_BINARY);"
+               ;;
+             esac
+
+           cat <<"EOF"
+         printf ("%s", script_text_part1);
+         printf ("%s", script_text_part2);
+         return 0;
+       }
+    }
+
+  newargz = XMALLOC (char *, argc + 1);
+  tmp_pathspec = find_executable (argv[0]);
+  if (tmp_pathspec == NULL)
+    lt_fatal ("Couldn't find %s", argv[0]);
+  LTWRAPPER_DEBUGPRINTF (("(main) found exe (before symlink chase) at : %s\n",
+                         tmp_pathspec));
+
+  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
+  LTWRAPPER_DEBUGPRINTF (("(main) found exe (after symlink chase) at : %s\n",
+                         actual_cwrapper_path));
+  XFREE (tmp_pathspec);
+
+  actual_cwrapper_name = xstrdup( base_name (actual_cwrapper_path));
+  strendzap (actual_cwrapper_path, actual_cwrapper_name);
+
+  /* wrapper name transforms */
+  strendzap (actual_cwrapper_name, ".exe");
+  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
+  XFREE (actual_cwrapper_name);
+  actual_cwrapper_name = tmp_pathspec;
+  tmp_pathspec = 0;
+
+  /* target_name transforms -- use actual target program name; might have lt- prefix */
+  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
+  strendzap (target_name, ".exe");
+  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
+  XFREE (target_name);
+  target_name = tmp_pathspec;
+  tmp_pathspec = 0;
+
+  LTWRAPPER_DEBUGPRINTF (("(main) libtool target name: %s\n",
+                         target_name));
+EOF
+
+           cat <<EOF
+  newargz[0] =
+    XMALLOC (char, (strlen (actual_cwrapper_path) +
+                   strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
+  strcpy (newargz[0], actual_cwrapper_path);
+  strcat (newargz[0], "$objdir");
+  strcat (newargz[0], "/");
+EOF
+
+           cat <<"EOF"
+  /* stop here, and copy so we don't have to do this twice */
+  tmp_pathspec = xstrdup (newargz[0]);
+
+  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
+  strcat (newargz[0], actual_cwrapper_name);
+
+  /* DO want the lt- prefix here if it exists, so use target_name */
+  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
+  XFREE (tmp_pathspec);
+  tmp_pathspec = NULL;
+EOF
+
+           case $host_os in
+             mingw*)
+           cat <<"EOF"
+  {
+    char* p;
+    while ((p = strchr (newargz[0], '\\')) != NULL)
+      {
+       *p = '/';
+      }
+    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
+      {
+       *p = '/';
+      }
+  }
+EOF
+           ;;
+           esac
+
+           cat <<"EOF"
+  XFREE (target_name);
+  XFREE (actual_cwrapper_path);
+  XFREE (actual_cwrapper_name);
+
+  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
+  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
+  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
+  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
+
+  newargc=0;
+  for (i = 1; i < argc; i++)
+    {
+      if (strncmp (argv[i], env_set_opt, env_set_opt_len) == 0)
+        {
+          if (argv[i][env_set_opt_len] == '=')
+            {
+              const char *p = argv[i] + env_set_opt_len + 1;
+              lt_opt_process_env_set (p);
+            }
+          else if (argv[i][env_set_opt_len] == '\0' && i + 1 < argc)
+            {
+              lt_opt_process_env_set (argv[++i]); /* don't copy */
+            }
+          else
+            lt_fatal ("%s missing required argument", env_set_opt);
+          continue;
+        }
+      if (strncmp (argv[i], env_prepend_opt, env_prepend_opt_len) == 0)
+        {
+          if (argv[i][env_prepend_opt_len] == '=')
+            {
+              const char *p = argv[i] + env_prepend_opt_len + 1;
+              lt_opt_process_env_prepend (p);
+            }
+          else if (argv[i][env_prepend_opt_len] == '\0' && i + 1 < argc)
+            {
+              lt_opt_process_env_prepend (argv[++i]); /* don't copy */
+            }
+          else
+            lt_fatal ("%s missing required argument", env_prepend_opt);
+          continue;
+        }
+      if (strncmp (argv[i], env_append_opt, env_append_opt_len) == 0)
+        {
+          if (argv[i][env_append_opt_len] == '=')
+            {
+              const char *p = argv[i] + env_append_opt_len + 1;
+              lt_opt_process_env_append (p);
+            }
+          else if (argv[i][env_append_opt_len] == '\0' && i + 1 < argc)
+            {
+              lt_opt_process_env_append (argv[++i]); /* don't copy */
+            }
+          else
+            lt_fatal ("%s missing required argument", env_append_opt);
+          continue;
+        }
+      if (strncmp (argv[i], ltwrapper_option_prefix, opt_prefix_len) == 0)
+        {
+          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
+             namespace, but it is not one of the ones we know about and
+             have already dealt with, above (inluding dump-script), then
+             report an error. Otherwise, targets might begin to believe
+             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
+             namespace. The first time any user complains about this, we'll
+             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
+             or a configure.ac-settable value.
+           */
+          lt_fatal ("Unrecognized option in %s namespace: '%s'",
+                    ltwrapper_option_prefix, argv[i]);
+        }
+      /* otherwise ... */
+      newargz[++newargc] = xstrdup (argv[i]);
+    }
+  newargz[++newargc] = NULL;
+
+  LTWRAPPER_DEBUGPRINTF     (("(main) lt_argv_zero : %s\n", (lt_argv_zero ? lt_argv_zero : "<NULL>")));
+  for (i = 0; i < newargc; i++)
+    {
+      LTWRAPPER_DEBUGPRINTF (("(main) newargz[%d]   : %s\n", i, (newargz[i] ? newargz[i] : "<NULL>")));
+    }
+
+EOF
+
+           case $host_os in
+             mingw*)
+               cat <<"EOF"
+  /* execv doesn't actually work on mingw as expected on unix */
+  rval = _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
+  if (rval == -1)
+    {
+      /* failed to start process */
+      LTWRAPPER_DEBUGPRINTF (("(main) failed to launch target \"%s\": errno = %d\n", lt_argv_zero, errno));
+      return 127;
+    }
+  return rval;
+EOF
+               ;;
+             *)
+               cat <<"EOF"
+  execv (lt_argv_zero, newargz);
+  return rval; /* =127, but avoids unused variable warning */
+EOF
+               ;;
+           esac
+
+           cat <<"EOF"
+}
+
+void *
+xmalloc (size_t num)
+{
+  void *p = (void *) malloc (num);
+  if (!p)
+    lt_fatal ("Memory exhausted");
+
+  return p;
+}
+
+char *
+xstrdup (const char *string)
+{
+  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
+                         string) : NULL;
+}
+
+const char *
+base_name (const char *name)
+{
+  const char *base;
+
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+  /* Skip over the disk name in MSDOS pathnames. */
+  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
+    name += 2;
+#endif
+
+  for (base = name; *name; name++)
+    if (IS_DIR_SEPARATOR (*name))
+      base = name + 1;
+  return base;
+}
+
+int
+check_executable (const char *path)
+{
+  struct stat st;
+
+  LTWRAPPER_DEBUGPRINTF (("(check_executable)  : %s\n",
+                         path ? (*path ? path : "EMPTY!") : "NULL!"));
+  if ((!path) || (!*path))
+    return 0;
+
+  if ((stat (path, &st) >= 0)
+      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
+    return 1;
+  else
+    return 0;
+}
+
+int
+make_executable (const char *path)
+{
+  int rval = 0;
+  struct stat st;
+
+  LTWRAPPER_DEBUGPRINTF (("(make_executable)   : %s\n",
+                         path ? (*path ? path : "EMPTY!") : "NULL!"));
+  if ((!path) || (!*path))
+    return 0;
+
+  if (stat (path, &st) >= 0)
+    {
+      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
+    }
+  return rval;
+}
+
+/* Searches for the full path of the wrapper.  Returns
+   newly allocated full path name if found, NULL otherwise
+   Does not chase symlinks, even on platforms that support them.
+*/
+char *
+find_executable (const char *wrapper)
+{
+  int has_slash = 0;
+  const char *p;
+  const char *p_next;
+  /* static buffer for getcwd */
+  char tmp[LT_PATHMAX + 1];
+  int tmp_len;
+  char *concat_name;
+
+  LTWRAPPER_DEBUGPRINTF (("(find_executable)   : %s\n",
+                         wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!"));
+
+  if ((wrapper == NULL) || (*wrapper == '\0'))
+    return NULL;
+
+  /* Absolute path? */
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
+    {
+      concat_name = xstrdup (wrapper);
+      if (check_executable (concat_name))
+       return concat_name;
+      XFREE (concat_name);
+    }
+  else
+    {
+#endif
+      if (IS_DIR_SEPARATOR (wrapper[0]))
+       {
+         concat_name = xstrdup (wrapper);
+         if (check_executable (concat_name))
+           return concat_name;
+         XFREE (concat_name);
+       }
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+    }
+#endif
+
+  for (p = wrapper; *p; p++)
+    if (*p == '/')
+      {
+       has_slash = 1;
+       break;
+      }
+  if (!has_slash)
+    {
+      /* no slashes; search PATH */
+      const char *path = getenv ("PATH");
+      if (path != NULL)
+       {
+         for (p = path; *p; p = p_next)
+           {
+             const char *q;
+             size_t p_len;
+             for (q = p; *q; q++)
+               if (IS_PATH_SEPARATOR (*q))
+                 break;
+             p_len = q - p;
+             p_next = (*q == '\0' ? q : q + 1);
+             if (p_len == 0)
+               {
+                 /* empty path: current directory */
+                 if (getcwd (tmp, LT_PATHMAX) == NULL)
+                   lt_fatal ("getcwd failed");
+                 tmp_len = strlen (tmp);
+                 concat_name =
+                   XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
+                 memcpy (concat_name, tmp, tmp_len);
+                 concat_name[tmp_len] = '/';
+                 strcpy (concat_name + tmp_len + 1, wrapper);
+               }
+             else
+               {
+                 concat_name =
+                   XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
+                 memcpy (concat_name, p, p_len);
+                 concat_name[p_len] = '/';
+                 strcpy (concat_name + p_len + 1, wrapper);
+               }
+             if (check_executable (concat_name))
+               return concat_name;
+             XFREE (concat_name);
+           }
+       }
+      /* not found in PATH; assume curdir */
+    }
+  /* Relative path | not found in path: prepend cwd */
+  if (getcwd (tmp, LT_PATHMAX) == NULL)
+    lt_fatal ("getcwd failed");
+  tmp_len = strlen (tmp);
+  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
+  memcpy (concat_name, tmp, tmp_len);
+  concat_name[tmp_len] = '/';
+  strcpy (concat_name + tmp_len + 1, wrapper);
+
+  if (check_executable (concat_name))
+    return concat_name;
+  XFREE (concat_name);
+  return NULL;
+}
+
+char *
+chase_symlinks (const char *pathspec)
+{
+#ifndef S_ISLNK
+  return xstrdup (pathspec);
+#else
+  char buf[LT_PATHMAX];
+  struct stat s;
+  char *tmp_pathspec = xstrdup (pathspec);
+  char *p;
+  int has_symlinks = 0;
+  while (strlen (tmp_pathspec) && !has_symlinks)
+    {
+      LTWRAPPER_DEBUGPRINTF (("checking path component for symlinks: %s\n",
+                             tmp_pathspec));
+      if (lstat (tmp_pathspec, &s) == 0)
+       {
+         if (S_ISLNK (s.st_mode) != 0)
+           {
+             has_symlinks = 1;
+             break;
+           }
+
+         /* search backwards for last DIR_SEPARATOR */
+         p = tmp_pathspec + strlen (tmp_pathspec) - 1;
+         while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
+           p--;
+         if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
+           {
+             /* no more DIR_SEPARATORS left */
+             break;
+           }
+         *p = '\0';
+       }
+      else
+       {
+         char *errstr = strerror (errno);
+         lt_fatal ("Error accessing file %s (%s)", tmp_pathspec, errstr);
+       }
+    }
+  XFREE (tmp_pathspec);
+
+  if (!has_symlinks)
+    {
+      return xstrdup (pathspec);
+    }
+
+  tmp_pathspec = realpath (pathspec, buf);
+  if (tmp_pathspec == 0)
+    {
+      lt_fatal ("Could not follow symlinks for %s", pathspec);
+    }
+  return xstrdup (tmp_pathspec);
+#endif
+}
+
+char *
+strendzap (char *str, const char *pat)
+{
+  size_t len, patlen;
+
+  assert (str != NULL);
+  assert (pat != NULL);
+
+  len = strlen (str);
+  patlen = strlen (pat);
+
+  if (patlen <= len)
+    {
+      str += len - patlen;
+      if (strcmp (str, pat) == 0)
+       *str = '\0';
+    }
+  return str;
+}
+
+static void
+lt_error_core (int exit_status, const char *mode,
+              const char *message, va_list ap)
+{
+  fprintf (stderr, "%s: %s: ", program_name, mode);
+  vfprintf (stderr, message, ap);
+  fprintf (stderr, ".\n");
+
+  if (exit_status >= 0)
+    exit (exit_status);
+}
+
+void
+lt_fatal (const char *message, ...)
+{
+  va_list ap;
+  va_start (ap, message);
+  lt_error_core (EXIT_FAILURE, "FATAL", message, ap);
+  va_end (ap);
+}
+
+void
+lt_setenv (const char *name, const char *value)
+{
+  LTWRAPPER_DEBUGPRINTF (("(lt_setenv) setting '%s' to '%s'\n",
+                          (name ? name : "<NULL>"),
+                          (value ? value : "<NULL>")));
+  {
+#ifdef HAVE_SETENV
+    /* always make a copy, for consistency with !HAVE_SETENV */
+    char *str = xstrdup (value);
+    setenv (name, str, 1);
+#else
+    int len = strlen (name) + 1 + strlen (value) + 1;
+    char *str = XMALLOC (char, len);
+    sprintf (str, "%s=%s", name, value);
+    if (putenv (str) != EXIT_SUCCESS)
+      {
+        XFREE (str);
+      }
+#endif
+  }
+}
+
+char *
+lt_extend_str (const char *orig_value, const char *add, int to_end)
+{
+  char *new_value;
+  if (orig_value && *orig_value)
+    {
+      int orig_value_len = strlen (orig_value);
+      int add_len = strlen (add);
+      new_value = XMALLOC (char, add_len + orig_value_len + 1);
+      if (to_end)
+        {
+          strcpy (new_value, orig_value);
+          strcpy (new_value + orig_value_len, add);
+        }
+      else
+        {
+          strcpy (new_value, add);
+          strcpy (new_value + add_len, orig_value);
+        }
+    }
+  else
+    {
+      new_value = xstrdup (add);
+    }
+  return new_value;
+}
+
+int
+lt_split_name_value (const char *arg, char** name, char** value)
+{
+  const char *p;
+  int len;
+  if (!arg || !*arg)
+    return 1;
+
+  p = strchr (arg, (int)'=');
+
+  if (!p)
+    return 1;
+
+  *value = xstrdup (++p);
+
+  len = strlen (arg) - strlen (*value);
+  *name = XMALLOC (char, len);
+  strncpy (*name, arg, len-1);
+  (*name)[len - 1] = '\0';
+
+  return 0;
+}
+
+void
+lt_opt_process_env_set (const char *arg)
+{
+  char *name = NULL;
+  char *value = NULL;
+
+  if (lt_split_name_value (arg, &name, &value) != 0)
+    {
+      XFREE (name);
+      XFREE (value);
+      lt_fatal ("bad argument for %s: '%s'", env_set_opt, arg);
+    }
+
+  lt_setenv (name, value);
+  XFREE (name);
+  XFREE (value);
+}
+
+void
+lt_opt_process_env_prepend (const char *arg)
+{
+  char *name = NULL;
+  char *value = NULL;
+  char *new_value = NULL;
+
+  if (lt_split_name_value (arg, &name, &value) != 0)
+    {
+      XFREE (name);
+      XFREE (value);
+      lt_fatal ("bad argument for %s: '%s'", env_prepend_opt, arg);
+    }
+
+  new_value = lt_extend_str (getenv (name), value, 0);
+  lt_setenv (name, new_value);
+  XFREE (new_value);
+  XFREE (name);
+  XFREE (value);
+}
+
+void
+lt_opt_process_env_append (const char *arg)
+{
+  char *name = NULL;
+  char *value = NULL;
+  char *new_value = NULL;
+
+  if (lt_split_name_value (arg, &name, &value) != 0)
+    {
+      XFREE (name);
+      XFREE (value);
+      lt_fatal ("bad argument for %s: '%s'", env_append_opt, arg);
+    }
+
+  new_value = lt_extend_str (getenv (name), value, 1);
+  lt_setenv (name, new_value);
+  XFREE (new_value);
+  XFREE (name);
+  XFREE (value);
+}
+
+void
+lt_update_exe_path (const char *name, const char *value)
+{
+  LTWRAPPER_DEBUGPRINTF (("(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
+                          (name ? name : "<NULL>"),
+                          (value ? value : "<NULL>")));
+
+  if (name && *name && value && *value)
+    {
+      char *new_value = lt_extend_str (getenv (name), value, 0);
+      /* some systems can't cope with a ':'-terminated path #' */
+      int len = strlen (new_value);
+      while (((len = strlen (new_value)) > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
+        {
+          new_value[len-1] = '\0';
+        }
+      lt_setenv (name, new_value);
+      XFREE (new_value);
+    }
+}
+
+void
+lt_update_lib_path (const char *name, const char *value)
+{
+  LTWRAPPER_DEBUGPRINTF (("(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
+                          (name ? name : "<NULL>"),
+                          (value ? value : "<NULL>")));
+
+  if (name && *name && value && *value)
+    {
+      char *new_value = lt_extend_str (getenv (name), value, 0);
+      lt_setenv (name, new_value);
+      XFREE (new_value);
+    }
+}
+
+
+EOF
+}
+# end: func_emit_cwrapperexe_src
+
+# func_mode_link arg...
+func_mode_link ()
+{
+    $opt_debug
+    case $host in
+    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+      # It is impossible to link a dll without this setting, and
+      # we shouldn't force the makefile maintainer to figure out
+      # which system we are compiling for in order to pass an extra
+      # flag for every libtool invocation.
+      # allow_undefined=no
+
+      # FIXME: Unfortunately, there are problems with the above when trying
+      # to make a dll which has undefined symbols, in which case not
+      # even a static library is built.  For now, we need to specify
+      # -no-undefined on the libtool link line when we can be certain
+      # that all symbols are satisfied, otherwise we get a static library.
+      allow_undefined=yes
+      ;;
+    *)
+      allow_undefined=yes
+      ;;
+    esac
+    libtool_args=$nonopt
+    base_compile="$nonopt $@"
+    compile_command=$nonopt
+    finalize_command=$nonopt
+
+    compile_rpath=
+    finalize_rpath=
+    compile_shlibpath=
+    finalize_shlibpath=
+    convenience=
+    old_convenience=
+    deplibs=
+    old_deplibs=
+    compiler_flags=
+    linker_flags=
+    dllsearchpath=
+    lib_search_path=`pwd`
+    inst_prefix_dir=
+    new_inherited_linker_flags=
+
+    avoid_version=no
+    dlfiles=
+    dlprefiles=
+    dlself=no
+    export_dynamic=no
+    export_symbols=
+    export_symbols_regex=
+    generated=
+    libobjs=
+    ltlibs=
+    module=no
+    no_install=no
+    objs=
+    non_pic_objects=
+    precious_files_regex=
+    prefer_static_libs=no
+    preload=no
+    prev=
+    prevarg=
+    release=
+    rpath=
+    xrpath=
+    perm_rpath=
+    temp_rpath=
+    thread_safe=no
+    vinfo=
+    vinfo_number=no
+    weak_libs=
+    single_module="${wl}-single_module"
+    func_infer_tag $base_compile
+
+    # We need to know -static, to get the right output filenames.
+    for arg
+    do
+      case $arg in
+      -shared)
+       test "$build_libtool_libs" != yes && \
+         func_fatal_configuration "can not build a shared library"
+       build_old_libs=no
+       break
+       ;;
+      -all-static | -static | -static-libtool-libs)
+       case $arg in
+       -all-static)
+         if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then
+           func_warning "complete static linking is impossible in this configuration"
+         fi
+         if test -n "$link_static_flag"; then
+           dlopen_self=$dlopen_self_static
+         fi
+         prefer_static_libs=yes
+         ;;
+       -static)
+         if test -z "$pic_flag" && test -n "$link_static_flag"; then
+           dlopen_self=$dlopen_self_static
+         fi
+         prefer_static_libs=built
+         ;;
+       -static-libtool-libs)
+         if test -z "$pic_flag" && test -n "$link_static_flag"; then
+           dlopen_self=$dlopen_self_static
+         fi
+         prefer_static_libs=yes
+         ;;
+       esac
+       build_libtool_libs=no
+       build_old_libs=yes
+       break
+       ;;
+      esac
+    done
+
+    # See if our shared archives depend on static archives.
+    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
+
+    # Go through the arguments, transforming them on the way.
+    while test "$#" -gt 0; do
+      arg="$1"
+      shift
+      func_quote_for_eval "$arg"
+      qarg=$func_quote_for_eval_unquoted_result
+      func_append libtool_args " $func_quote_for_eval_result"
+
+      # If the previous option needs an argument, assign it.
+      if test -n "$prev"; then
+       case $prev in
+       output)
+         func_append compile_command " @OUTPUT@"
+         func_append finalize_command " @OUTPUT@"
+         ;;
+       esac
+
+       case $prev in
+       dlfiles|dlprefiles)
+         if test "$preload" = no; then
+           # Add the symbol object into the linking commands.
+           func_append compile_command " @SYMFILE@"
+           func_append finalize_command " @SYMFILE@"
+           preload=yes
+         fi
+         case $arg in
+         *.la | *.lo) ;;  # We handle these cases below.
+         force)
+           if test "$dlself" = no; then
+             dlself=needless
+             export_dynamic=yes
+           fi
+           prev=
+           continue
+           ;;
+         self)
+           if test "$prev" = dlprefiles; then
+             dlself=yes
+           elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then
+             dlself=yes
+           else
+             dlself=needless
+             export_dynamic=yes
+           fi
+           prev=
+           continue
+           ;;
+         *)
+           if test "$prev" = dlfiles; then
+             dlfiles="$dlfiles $arg"
+           else
+             dlprefiles="$dlprefiles $arg"
+           fi
+           prev=
+           continue
+           ;;
+         esac
+         ;;
+       expsyms)
+         export_symbols="$arg"
+         test -f "$arg" \
+           || func_fatal_error "symbol file \`$arg' does not exist"
+         prev=
+         continue
+         ;;
+       expsyms_regex)
+         export_symbols_regex="$arg"
+         prev=
+         continue
+         ;;
+       framework)
+         case $host in
+           *-*-darwin*)
+             case "$deplibs " in
+               *" $qarg.ltframework "*) ;;
+               *) deplibs="$deplibs $qarg.ltframework" # this is fixed later
+                  ;;
+             esac
+             ;;
+         esac
+         prev=
+         continue
+         ;;
+       inst_prefix)
+         inst_prefix_dir="$arg"
+         prev=
+         continue
+         ;;
+       objectlist)
+         if test -f "$arg"; then
+           save_arg=$arg
+           moreargs=
+           for fil in `cat "$save_arg"`
+           do
+#            moreargs="$moreargs $fil"
+             arg=$fil
+             # A libtool-controlled object.
+
+             # Check to see that this really is a libtool object.
+             if func_lalib_unsafe_p "$arg"; then
+               pic_object=
+               non_pic_object=
+
+               # Read the .lo file
+               func_source "$arg"
+
+               if test -z "$pic_object" ||
+                  test -z "$non_pic_object" ||
+                  test "$pic_object" = none &&
+                  test "$non_pic_object" = none; then
+                 func_fatal_error "cannot find name of object for \`$arg'"
+               fi
+
+               # Extract subdirectory from the argument.
+               func_dirname "$arg" "/" ""
+               xdir="$func_dirname_result"
+
+               if test "$pic_object" != none; then
+                 # Prepend the subdirectory the object is found in.
+                 pic_object="$xdir$pic_object"
+
+                 if test "$prev" = dlfiles; then
+                   if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
+                     dlfiles="$dlfiles $pic_object"
+                     prev=
+                     continue
+                   else
+                     # If libtool objects are unsupported, then we need to preload.
+                     prev=dlprefiles
+                   fi
+                 fi
+
+                 # CHECK ME:  I think I busted this.  -Ossama
+                 if test "$prev" = dlprefiles; then
+                   # Preload the old-style object.
+                   dlprefiles="$dlprefiles $pic_object"
+                   prev=
+                 fi
+
+                 # A PIC object.
+                 func_append libobjs " $pic_object"
+                 arg="$pic_object"
+               fi
+
+               # Non-PIC object.
+               if test "$non_pic_object" != none; then
+                 # Prepend the subdirectory the object is found in.
+                 non_pic_object="$xdir$non_pic_object"
+
+                 # A standard non-PIC object
+                 func_append non_pic_objects " $non_pic_object"
+                 if test -z "$pic_object" || test "$pic_object" = none ; then
+                   arg="$non_pic_object"
+                 fi
+               else
+                 # If the PIC object exists, use it instead.
+                 # $xdir was prepended to $pic_object above.
+                 non_pic_object="$pic_object"
+                 func_append non_pic_objects " $non_pic_object"
+               fi
+             else
+               # Only an error if not doing a dry-run.
+               if $opt_dry_run; then
+                 # Extract subdirectory from the argument.
+                 func_dirname "$arg" "/" ""
+                 xdir="$func_dirname_result"
+
+                 func_lo2o "$arg"
+                 pic_object=$xdir$objdir/$func_lo2o_result
+                 non_pic_object=$xdir$func_lo2o_result
+                 func_append libobjs " $pic_object"
+                 func_append non_pic_objects " $non_pic_object"
+               else
+                 func_fatal_error "\`$arg' is not a valid libtool object"
+               fi
+             fi
+           done
+         else
+           func_fatal_error "link input file \`$arg' does not exist"
+         fi
+         arg=$save_arg
+         prev=
+         continue
+         ;;
+       precious_regex)
+         precious_files_regex="$arg"
+         prev=
+         continue
+         ;;
+       release)
+         release="-$arg"
+         prev=
+         continue
+         ;;
+       rpath | xrpath)
+         # We need an absolute path.
+         case $arg in
+         [\\/]* | [A-Za-z]:[\\/]*) ;;
+         *)
+           func_fatal_error "only absolute run-paths are allowed"
+           ;;
+         esac
+         if test "$prev" = rpath; then
+           case "$rpath " in
+           *" $arg "*) ;;
+           *) rpath="$rpath $arg" ;;
+           esac
+         else
+           case "$xrpath " in
+           *" $arg "*) ;;
+           *) xrpath="$xrpath $arg" ;;
+           esac
+         fi
+         prev=
+         continue
+         ;;
+       shrext)
+         shrext_cmds="$arg"
+         prev=
+         continue
+         ;;
+       weak)
+         weak_libs="$weak_libs $arg"
+         prev=
+         continue
+         ;;
+       xcclinker)
+         linker_flags="$linker_flags $qarg"
+         compiler_flags="$compiler_flags $qarg"
+         prev=
+         func_append compile_command " $qarg"
+         func_append finalize_command " $qarg"
+         continue
+         ;;
+       xcompiler)
+         compiler_flags="$compiler_flags $qarg"
+         prev=
+         func_append compile_command " $qarg"
+         func_append finalize_command " $qarg"
+         continue
+         ;;
+       xlinker)
+         linker_flags="$linker_flags $qarg"
+         compiler_flags="$compiler_flags $wl$qarg"
+         prev=
+         func_append compile_command " $wl$qarg"
+         func_append finalize_command " $wl$qarg"
+         continue
+         ;;
+       *)
+         eval "$prev=\"\$arg\""
+         prev=
+         continue
+         ;;
+       esac
+      fi # test -n "$prev"
+
+      prevarg="$arg"
+
+      case $arg in
+      -all-static)
+       if test -n "$link_static_flag"; then
+         # See comment for -static flag below, for more details.
+         func_append compile_command " $link_static_flag"
+         func_append finalize_command " $link_static_flag"
+       fi
+       continue
+       ;;
+
+      -allow-undefined)
+       # FIXME: remove this flag sometime in the future.
+       func_fatal_error "\`-allow-undefined' must not be used because it is the default"
+       ;;
+
+      -avoid-version)
+       avoid_version=yes
+       continue
+       ;;
+
+      -dlopen)
+       prev=dlfiles
+       continue
+       ;;
+
+      -dlpreopen)
+       prev=dlprefiles
+       continue
+       ;;
+
+      -export-dynamic)
+       export_dynamic=yes
+       continue
+       ;;
+
+      -export-symbols | -export-symbols-regex)
+       if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
+         func_fatal_error "more than one -exported-symbols argument is not allowed"
+       fi
+       if test "X$arg" = "X-export-symbols"; then
+         prev=expsyms
+       else
+         prev=expsyms_regex
+       fi
+       continue
+       ;;
+
+      -framework)
+       prev=framework
+       continue
+       ;;
+
+      -inst-prefix-dir)
+       prev=inst_prefix
+       continue
+       ;;
+
+      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
+      # so, if we see these flags be careful not to treat them like -L
+      -L[A-Z][A-Z]*:*)
+       case $with_gcc/$host in
+       no/*-*-irix* | /*-*-irix*)
+         func_append compile_command " $arg"
+         func_append finalize_command " $arg"
+         ;;
+       esac
+       continue
+       ;;
+
+      -L*)
+       func_stripname '-L' '' "$arg"
+       dir=$func_stripname_result
+       if test -z "$dir"; then
+         if test "$#" -gt 0; then
+           func_fatal_error "require no space between \`-L' and \`$1'"
+         else
+           func_fatal_error "need path for \`-L' option"
+         fi
+       fi
+       # We need an absolute path.
+       case $dir in
+       [\\/]* | [A-Za-z]:[\\/]*) ;;
+       *)
+         absdir=`cd "$dir" && pwd`
+         test -z "$absdir" && \
+           func_fatal_error "cannot determine absolute directory name of \`$dir'"
+         dir="$absdir"
+         ;;
+       esac
+       case "$deplibs " in
+       *" -L$dir "*) ;;
+       *)
+         deplibs="$deplibs -L$dir"
+         lib_search_path="$lib_search_path $dir"
+         ;;
+       esac
+       case $host in
+       *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+         testbindir=`$ECHO "X$dir" | $Xsed -e 's*/lib$*/bin*'`
+         case :$dllsearchpath: in
+         *":$dir:"*) ;;
+         ::) dllsearchpath=$dir;;
+         *) dllsearchpath="$dllsearchpath:$dir";;
+         esac
+         case :$dllsearchpath: in
+         *":$testbindir:"*) ;;
+         ::) dllsearchpath=$testbindir;;
+         *) dllsearchpath="$dllsearchpath:$testbindir";;
+         esac
+         ;;
+       esac
+       continue
+       ;;
+
+      -l*)
+       if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then
+         case $host in
+         *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc*)
+           # These systems don't actually have a C or math library (as such)
+           continue
+           ;;
+         *-*-os2*)
+           # These systems don't actually have a C library (as such)
+           test "X$arg" = "X-lc" && continue
+           ;;
+         *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+           # Do not include libc due to us having libc/libc_r.
+           test "X$arg" = "X-lc" && continue
+           ;;
+         *-*-rhapsody* | *-*-darwin1.[012])
+           # Rhapsody C and math libraries are in the System framework
+           deplibs="$deplibs System.ltframework"
+           continue
+           ;;
+         *-*-sco3.2v5* | *-*-sco5v6*)
+           # Causes problems with __ctype
+           test "X$arg" = "X-lc" && continue
+           ;;
+         *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
+           # Compiler inserts libc in the correct place for threads to work
+           test "X$arg" = "X-lc" && continue
+           ;;
+         esac
+       elif test "X$arg" = "X-lc_r"; then
+        case $host in
+        *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+          # Do not include libc_r directly, use -pthread flag.
+          continue
+          ;;
+        esac
+       fi
+       deplibs="$deplibs $arg"
+       continue
+       ;;
+
+      -module)
+       module=yes
+       continue
+       ;;
+
+      # Tru64 UNIX uses -model [arg] to determine the layout of C++
+      # classes, name mangling, and exception handling.
+      # Darwin uses the -arch flag to determine output architecture.
+      -model|-arch|-isysroot)
+       compiler_flags="$compiler_flags $arg"
+       func_append compile_command " $arg"
+       func_append finalize_command " $arg"
+       prev=xcompiler
+       continue
+       ;;
+
+      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads)
+       compiler_flags="$compiler_flags $arg"
+       func_append compile_command " $arg"
+       func_append finalize_command " $arg"
+       case "$new_inherited_linker_flags " in
+           *" $arg "*) ;;
+           * ) new_inherited_linker_flags="$new_inherited_linker_flags $arg" ;;
+       esac
+       continue
+       ;;
+
+      -multi_module)
+       single_module="${wl}-multi_module"
+       continue
+       ;;
+
+      -no-fast-install)
+       fast_install=no
+       continue
+       ;;
+
+      -no-install)
+       case $host in
+       *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
+         # The PATH hackery in wrapper scripts is required on Windows
+         # and Darwin in order for the loader to find any dlls it needs.
+         func_warning "\`-no-install' is ignored for $host"
+         func_warning "assuming \`-no-fast-install' instead"
+         fast_install=no
+         ;;
+       *) no_install=yes ;;
+       esac
+       continue
+       ;;
+
+      -no-undefined)
+       allow_undefined=no
+       continue
+       ;;
+
+      -objectlist)
+       prev=objectlist
+       continue
+       ;;
+
+      -o) prev=output ;;
+
+      -precious-files-regex)
+       prev=precious_regex
+       continue
+       ;;
+
+      -release)
+       prev=release
+       continue
+       ;;
+
+      -rpath)
+       prev=rpath
+       continue
+       ;;
+
+      -R)
+       prev=xrpath
+       continue
+       ;;
+
+      -R*)
+       func_stripname '-R' '' "$arg"
+       dir=$func_stripname_result
+       # We need an absolute path.
+       case $dir in
+       [\\/]* | [A-Za-z]:[\\/]*) ;;
+       *)
+         func_fatal_error "only absolute run-paths are allowed"
+         ;;
+       esac
+       case "$xrpath " in
+       *" $dir "*) ;;
+       *) xrpath="$xrpath $dir" ;;
+       esac
+       continue
+       ;;
+
+      -shared)
+       # The effects of -shared are defined in a previous loop.
+       continue
+       ;;
+
+      -shrext)
+       prev=shrext
+       continue
+       ;;
+
+      -static | -static-libtool-libs)
+       # The effects of -static are defined in a previous loop.
+       # We used to do the same as -all-static on platforms that
+       # didn't have a PIC flag, but the assumption that the effects
+       # would be equivalent was wrong.  It would break on at least
+       # Digital Unix and AIX.
+       continue
+       ;;
+
+      -thread-safe)
+       thread_safe=yes
+       continue
+       ;;
+
+      -version-info)
+       prev=vinfo
+       continue
+       ;;
+
+      -version-number)
+       prev=vinfo
+       vinfo_number=yes
+       continue
+       ;;
+
+      -weak)
+        prev=weak
+       continue
+       ;;
+
+      -Wc,*)
+       func_stripname '-Wc,' '' "$arg"
+       args=$func_stripname_result
+       arg=
+       save_ifs="$IFS"; IFS=','
+       for flag in $args; do
+         IFS="$save_ifs"
+          func_quote_for_eval "$flag"
+         arg="$arg $wl$func_quote_for_eval_result"
+         compiler_flags="$compiler_flags $func_quote_for_eval_result"
+       done
+       IFS="$save_ifs"
+       func_stripname ' ' '' "$arg"
+       arg=$func_stripname_result
+       ;;
+
+      -Wl,*)
+       func_stripname '-Wl,' '' "$arg"
+       args=$func_stripname_result
+       arg=
+       save_ifs="$IFS"; IFS=','
+       for flag in $args; do
+         IFS="$save_ifs"
+          func_quote_for_eval "$flag"
+         arg="$arg $wl$func_quote_for_eval_result"
+         compiler_flags="$compiler_flags $wl$func_quote_for_eval_result"
+         linker_flags="$linker_flags $func_quote_for_eval_result"
+       done
+       IFS="$save_ifs"
+       func_stripname ' ' '' "$arg"
+       arg=$func_stripname_result
+       ;;
+
+      -Xcompiler)
+       prev=xcompiler
+       continue
+       ;;
+
+      -Xlinker)
+       prev=xlinker
+       continue
+       ;;
+
+      -XCClinker)
+       prev=xcclinker
+       continue
+       ;;
+
+      # -msg_* for osf cc
+      -msg_*)
+       func_quote_for_eval "$arg"
+       arg="$func_quote_for_eval_result"
+       ;;
+
+      # -64, -mips[0-9] enable 64-bit mode on the SGI compiler
+      # -r[0-9][0-9]* specifies the processor on the SGI compiler
+      # -xarch=*, -xtarget=* enable 64-bit mode on the Sun compiler
+      # +DA*, +DD* enable 64-bit mode on the HP compiler
+      # -q* pass through compiler args for the IBM compiler
+      # -m*, -t[45]*, -txscale* pass through architecture-specific
+      # compiler args for GCC
+      # -F/path gives path to uninstalled frameworks, gcc on darwin
+      # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC
+      # @file GCC response files
+      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
+      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*)
+        func_quote_for_eval "$arg"
+       arg="$func_quote_for_eval_result"
+        func_append compile_command " $arg"
+        func_append finalize_command " $arg"
+        compiler_flags="$compiler_flags $arg"
+        continue
+        ;;
+
+      # Some other compiler flag.
+      -* | +*)
+        func_quote_for_eval "$arg"
+       arg="$func_quote_for_eval_result"
+       ;;
+
+      *.$objext)
+       # A standard object.
+       objs="$objs $arg"
+       ;;
+
+      *.lo)
+       # A libtool-controlled object.
+
+       # Check to see that this really is a libtool object.
+       if func_lalib_unsafe_p "$arg"; then
+         pic_object=
+         non_pic_object=
+
+         # Read the .lo file
+         func_source "$arg"
+
+         if test -z "$pic_object" ||
+            test -z "$non_pic_object" ||
+            test "$pic_object" = none &&
+            test "$non_pic_object" = none; then
+           func_fatal_error "cannot find name of object for \`$arg'"
+         fi
+
+         # Extract subdirectory from the argument.
+         func_dirname "$arg" "/" ""
+         xdir="$func_dirname_result"
+
+         if test "$pic_object" != none; then
+           # Prepend the subdirectory the object is found in.
+           pic_object="$xdir$pic_object"
+
+           if test "$prev" = dlfiles; then
+             if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
+               dlfiles="$dlfiles $pic_object"
+               prev=
+               continue
+             else
+               # If libtool objects are unsupported, then we need to preload.
+               prev=dlprefiles
+             fi
+           fi
+
+           # CHECK ME:  I think I busted this.  -Ossama
+           if test "$prev" = dlprefiles; then
+             # Preload the old-style object.
+             dlprefiles="$dlprefiles $pic_object"
+             prev=
+           fi
+
+           # A PIC object.
+           func_append libobjs " $pic_object"
+           arg="$pic_object"
+         fi
+
+         # Non-PIC object.
+         if test "$non_pic_object" != none; then
+           # Prepend the subdirectory the object is found in.
+           non_pic_object="$xdir$non_pic_object"
+
+           # A standard non-PIC object
+           func_append non_pic_objects " $non_pic_object"
+           if test -z "$pic_object" || test "$pic_object" = none ; then
+             arg="$non_pic_object"
+           fi
+         else
+           # If the PIC object exists, use it instead.
+           # $xdir was prepended to $pic_object above.
+           non_pic_object="$pic_object"
+           func_append non_pic_objects " $non_pic_object"
+         fi
+       else
+         # Only an error if not doing a dry-run.
+         if $opt_dry_run; then
+           # Extract subdirectory from the argument.
+           func_dirname "$arg" "/" ""
+           xdir="$func_dirname_result"
+
+           func_lo2o "$arg"
+           pic_object=$xdir$objdir/$func_lo2o_result
+           non_pic_object=$xdir$func_lo2o_result
+           func_append libobjs " $pic_object"
+           func_append non_pic_objects " $non_pic_object"
+         else
+           func_fatal_error "\`$arg' is not a valid libtool object"
+         fi
+       fi
+       ;;
+
+      *.$libext)
+       # An archive.
+       deplibs="$deplibs $arg"
+       old_deplibs="$old_deplibs $arg"
+       continue
+       ;;
+
+      *.la)
+       # A libtool-controlled library.
+
+       if test "$prev" = dlfiles; then
+         # This library was specified with -dlopen.
+         dlfiles="$dlfiles $arg"
+         prev=
+       elif test "$prev" = dlprefiles; then
+         # The library was specified with -dlpreopen.
+         dlprefiles="$dlprefiles $arg"
+         prev=
+       else
+         deplibs="$deplibs $arg"
+       fi
+       continue
+       ;;
+
+      # Some other compiler argument.
+      *)
+       # Unknown arguments in both finalize_command and compile_command need
+       # to be aesthetically quoted because they are evaled later.
+       func_quote_for_eval "$arg"
+       arg="$func_quote_for_eval_result"
+       ;;
+      esac # arg
+
+      # Now actually substitute the argument into the commands.
+      if test -n "$arg"; then
+       func_append compile_command " $arg"
+       func_append finalize_command " $arg"
+      fi
+    done # argument parsing loop
+
+    test -n "$prev" && \
+      func_fatal_help "the \`$prevarg' option requires an argument"
+
+    if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then
+      eval arg=\"$export_dynamic_flag_spec\"
+      func_append compile_command " $arg"
+      func_append finalize_command " $arg"
+    fi
+
+    oldlibs=
+    # calculate the name of the file, without its directory
+    func_basename "$output"
+    outputname="$func_basename_result"
+    libobjs_save="$libobjs"
+
+    if test -n "$shlibpath_var"; then
+      # get the directories listed in $shlibpath_var
+      eval shlib_search_path=\`\$ECHO \"X\${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\`
+    else
+      shlib_search_path=
+    fi
+    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
+    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
+
+    func_dirname "$output" "/" ""
+    output_objdir="$func_dirname_result$objdir"
+    # Create the object directory.
+    func_mkdir_p "$output_objdir"
+
+    # Determine the type of output
+    case $output in
+    "")
+      func_fatal_help "you must specify an output file"
+      ;;
+    *.$libext) linkmode=oldlib ;;
+    *.lo | *.$objext) linkmode=obj ;;
+    *.la) linkmode=lib ;;
+    *) linkmode=prog ;; # Anything else should be a program.
+    esac
+
+    specialdeplibs=
+
+    libs=
+    # Find all interdependent deplibs by searching for libraries
+    # that are linked more than once (e.g. -la -lb -la)
+    for deplib in $deplibs; do
+      if $opt_duplicate_deps ; then
+       case "$libs " in
+       *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+       esac
+      fi
+      libs="$libs $deplib"
+    done
+
+    if test "$linkmode" = lib; then
+      libs="$predeps $libs $compiler_lib_search_path $postdeps"
+
+      # Compute libraries that are listed more than once in $predeps
+      # $postdeps and mark them as special (i.e., whose duplicates are
+      # not to be eliminated).
+      pre_post_deps=
+      if $opt_duplicate_compiler_generated_deps; then
+       for pre_post_dep in $predeps $postdeps; do
+         case "$pre_post_deps " in
+         *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;;
+         esac
+         pre_post_deps="$pre_post_deps $pre_post_dep"
+       done
+      fi
+      pre_post_deps=
+    fi
+
+    deplibs=
+    newdependency_libs=
+    newlib_search_path=
+    need_relink=no # whether we're linking any uninstalled libtool libraries
+    notinst_deplibs= # not-installed libtool libraries
+    notinst_path= # paths that contain not-installed libtool libraries
+
+    case $linkmode in
+    lib)
+       passes="conv dlpreopen link"
+       for file in $dlfiles $dlprefiles; do
+         case $file in
+         *.la) ;;
+         *)
+           func_fatal_help "libraries can \`-dlopen' only libtool libraries: $file"
+           ;;
+         esac
+       done
+       ;;
+    prog)
+       compile_deplibs=
+       finalize_deplibs=
+       alldeplibs=no
+       newdlfiles=
+       newdlprefiles=
+       passes="conv scan dlopen dlpreopen link"
+       ;;
+    *)  passes="conv"
+       ;;
+    esac
+
+    for pass in $passes; do
+      # The preopen pass in lib mode reverses $deplibs; put it back here
+      # so that -L comes before libs that need it for instance...
+      if test "$linkmode,$pass" = "lib,link"; then
+       ## FIXME: Find the place where the list is rebuilt in the wrong
+       ##        order, and fix it there properly
+        tmp_deplibs=
+       for deplib in $deplibs; do
+         tmp_deplibs="$deplib $tmp_deplibs"
+       done
+       deplibs="$tmp_deplibs"
+      fi
+
+      if test "$linkmode,$pass" = "lib,link" ||
+        test "$linkmode,$pass" = "prog,scan"; then
+       libs="$deplibs"
+       deplibs=
+      fi
+      if test "$linkmode" = prog; then
+       case $pass in
+       dlopen) libs="$dlfiles" ;;
+       dlpreopen) libs="$dlprefiles" ;;
+       link)
+         libs="$deplibs %DEPLIBS%"
+         test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs"
+         ;;
+       esac
+      fi
+      if test "$linkmode,$pass" = "lib,dlpreopen"; then
+       # Collect and forward deplibs of preopened libtool libs
+       for lib in $dlprefiles; do
+         # Ignore non-libtool-libs
+         dependency_libs=
+         case $lib in
+         *.la) func_source "$lib" ;;
+         esac
+
+         # Collect preopened libtool deplibs, except any this library
+         # has declared as weak libs
+         for deplib in $dependency_libs; do
+            deplib_base=`$ECHO "X$deplib" | $Xsed -e "$basename"`
+           case " $weak_libs " in
+           *" $deplib_base "*) ;;
+           *) deplibs="$deplibs $deplib" ;;
+           esac
+         done
+       done
+       libs="$dlprefiles"
+      fi
+      if test "$pass" = dlopen; then
+       # Collect dlpreopened libraries
+       save_deplibs="$deplibs"
+       deplibs=
+      fi
+
+      for deplib in $libs; do
+       lib=
+       found=no
+       case $deplib in
+       -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads)
+         if test "$linkmode,$pass" = "prog,link"; then
+           compile_deplibs="$deplib $compile_deplibs"
+           finalize_deplibs="$deplib $finalize_deplibs"
+         else
+           compiler_flags="$compiler_flags $deplib"
+           if test "$linkmode" = lib ; then
+               case "$new_inherited_linker_flags " in
+                   *" $deplib "*) ;;
+                   * ) new_inherited_linker_flags="$new_inherited_linker_flags $deplib" ;;
+               esac
+           fi
+         fi
+         continue
+         ;;
+       -l*)
+         if test "$linkmode" != lib && test "$linkmode" != prog; then
+           func_warning "\`-l' is ignored for archives/objects"
+           continue
+         fi
+         func_stripname '-l' '' "$deplib"
+         name=$func_stripname_result
+         if test "$linkmode" = lib; then
+           searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
+         else
+           searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
+         fi
+         for searchdir in $searchdirs; do
+           for search_ext in .la $std_shrext .so .a; do
+             # Search the libtool library
+             lib="$searchdir/lib${name}${search_ext}"
+             if test -f "$lib"; then
+               if test "$search_ext" = ".la"; then
+                 found=yes
+               else
+                 found=no
+               fi
+               break 2
+             fi
+           done
+         done
+         if test "$found" != yes; then
+           # deplib doesn't seem to be a libtool library
+           if test "$linkmode,$pass" = "prog,link"; then
+             compile_deplibs="$deplib $compile_deplibs"
+             finalize_deplibs="$deplib $finalize_deplibs"
+           else
+             deplibs="$deplib $deplibs"
+             test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs"
+           fi
+           continue
+         else # deplib is a libtool library
+           # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
+           # We need to do some special things here, and not later.
+           if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+             case " $predeps $postdeps " in
+             *" $deplib "*)
+               if func_lalib_p "$lib"; then
+                 library_names=
+                 old_library=
+                 func_source "$lib"
+                 for l in $old_library $library_names; do
+                   ll="$l"
+                 done
+                 if test "X$ll" = "X$old_library" ; then # only static version available
+                   found=no
+                   func_dirname "$lib" "" "."
+                   ladir="$func_dirname_result"
+                   lib=$ladir/$old_library
+                   if test "$linkmode,$pass" = "prog,link"; then
+                     compile_deplibs="$deplib $compile_deplibs"
+                     finalize_deplibs="$deplib $finalize_deplibs"
+                   else
+                     deplibs="$deplib $deplibs"
+                     test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs"
+                   fi
+                   continue
+                 fi
+               fi
+               ;;
+             *) ;;
+             esac
+           fi
+         fi
+         ;; # -l
+       *.ltframework)
+         if test "$linkmode,$pass" = "prog,link"; then
+           compile_deplibs="$deplib $compile_deplibs"
+           finalize_deplibs="$deplib $finalize_deplibs"
+         else
+           deplibs="$deplib $deplibs"
+           if test "$linkmode" = lib ; then
+               case "$new_inherited_linker_flags " in
+                   *" $deplib "*) ;;
+                   * ) new_inherited_linker_flags="$new_inherited_linker_flags $deplib" ;;
+               esac
+           fi
+         fi
+         continue
+         ;;
+       -L*)
+         case $linkmode in
+         lib)
+           deplibs="$deplib $deplibs"
+           test "$pass" = conv && continue
+           newdependency_libs="$deplib $newdependency_libs"
+           func_stripname '-L' '' "$deplib"
+           newlib_search_path="$newlib_search_path $func_stripname_result"
+           ;;
+         prog)
+           if test "$pass" = conv; then
+             deplibs="$deplib $deplibs"
+             continue
+           fi
+           if test "$pass" = scan; then
+             deplibs="$deplib $deplibs"
+           else
+             compile_deplibs="$deplib $compile_deplibs"
+             finalize_deplibs="$deplib $finalize_deplibs"
+           fi
+           func_stripname '-L' '' "$deplib"
+           newlib_search_path="$newlib_search_path $func_stripname_result"
+           ;;
+         *)
+           func_warning "\`-L' is ignored for archives/objects"
+           ;;
+         esac # linkmode
+         continue
+         ;; # -L
+       -R*)
+         if test "$pass" = link; then
+           func_stripname '-R' '' "$deplib"
+           dir=$func_stripname_result
+           # Make sure the xrpath contains only unique directories.
+           case "$xrpath " in
+           *" $dir "*) ;;
+           *) xrpath="$xrpath $dir" ;;
+           esac
+         fi
+         deplibs="$deplib $deplibs"
+         continue
+         ;;
+       *.la) lib="$deplib" ;;
+       *.$libext)
+         if test "$pass" = conv; then
+           deplibs="$deplib $deplibs"
+           continue
+         fi
+         case $linkmode in
+         lib)
+           # Linking convenience modules into shared libraries is allowed,
+           # but linking other static libraries is non-portable.
+           case " $dlpreconveniencelibs " in
+           *" $deplib "*) ;;
+           *)
+             valid_a_lib=no
+             case $deplibs_check_method in
+               match_pattern*)
+                 set dummy $deplibs_check_method; shift
+                 match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+                 if eval "\$ECHO \"X$deplib\"" 2>/dev/null | $Xsed -e 10q \
+                   | $EGREP "$match_pattern_regex" > /dev/null; then
+                   valid_a_lib=yes
+                 fi
+               ;;
+               pass_all)
+                 valid_a_lib=yes
+               ;;
+             esac
+             if test "$valid_a_lib" != yes; then
+               $ECHO
+               $ECHO "*** Warning: Trying to link with static lib archive $deplib."
+               $ECHO "*** I have the capability to make that library automatically link in when"
+               $ECHO "*** you link to this library.  But I can only do this if you have a"
+               $ECHO "*** shared version of the library, which you do not appear to have"
+               $ECHO "*** because the file extensions .$libext of this argument makes me believe"
+               $ECHO "*** that it is just a static archive that I should not use here."
+             else
+               $ECHO
+               $ECHO "*** Warning: Linking the shared library $output against the"
+               $ECHO "*** static library $deplib is not portable!"
+               deplibs="$deplib $deplibs"
+             fi
+             ;;
+           esac
+           continue
+           ;;
+         prog)
+           if test "$pass" != link; then
+             deplibs="$deplib $deplibs"
+           else
+             compile_deplibs="$deplib $compile_deplibs"
+             finalize_deplibs="$deplib $finalize_deplibs"
+           fi
+           continue
+           ;;
+         esac # linkmode
+         ;; # *.$libext
+       *.lo | *.$objext)
+         if test "$pass" = conv; then
+           deplibs="$deplib $deplibs"
+         elif test "$linkmode" = prog; then
+           if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then
+             # If there is no dlopen support or we're linking statically,
+             # we need to preload.
+             newdlprefiles="$newdlprefiles $deplib"
+             compile_deplibs="$deplib $compile_deplibs"
+             finalize_deplibs="$deplib $finalize_deplibs"
+           else
+             newdlfiles="$newdlfiles $deplib"
+           fi
+         fi
+         continue
+         ;;
+       %DEPLIBS%)
+         alldeplibs=yes
+         continue
+         ;;
+       esac # case $deplib
+
+       if test "$found" = yes || test -f "$lib"; then :
+       else
+         func_fatal_error "cannot find the library \`$lib' or unhandled argument \`$deplib'"
+       fi
+
+       # Check to see that this really is a libtool archive.
+       func_lalib_unsafe_p "$lib" \
+         || func_fatal_error "\`$lib' is not a valid libtool archive"
+
+       func_dirname "$lib" "" "."
+       ladir="$func_dirname_result"
+
+       dlname=
+       dlopen=
+       dlpreopen=
+       libdir=
+       library_names=
+       old_library=
+       inherited_linker_flags=
+       # If the library was installed with an old release of libtool,
+       # it will not redefine variables installed, or shouldnotlink
+       installed=yes
+       shouldnotlink=no
+       avoidtemprpath=
+
+
+       # Read the .la file
+       func_source "$lib"
+
+       # Convert "-framework foo" to "foo.ltframework"
+       if test -n "$inherited_linker_flags"; then
+         tmp_inherited_linker_flags=`$ECHO "X$inherited_linker_flags" | $Xsed -e 's/-framework \([^ $]*\)/\1.ltframework/g'`
+         for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
+           case " $new_inherited_linker_flags " in
+             *" $tmp_inherited_linker_flag "*) ;;
+             *) new_inherited_linker_flags="$new_inherited_linker_flags $tmp_inherited_linker_flag";;
+           esac
+         done
+       fi
+       dependency_libs=`$ECHO "X $dependency_libs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+       if test "$linkmode,$pass" = "lib,link" ||
+          test "$linkmode,$pass" = "prog,scan" ||
+          { test "$linkmode" != prog && test "$linkmode" != lib; }; then
+         test -n "$dlopen" && dlfiles="$dlfiles $dlopen"
+         test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen"
+       fi
+
+       if test "$pass" = conv; then
+         # Only check for convenience libraries
+         deplibs="$lib $deplibs"
+         if test -z "$libdir"; then
+           if test -z "$old_library"; then
+             func_fatal_error "cannot find name of link library for \`$lib'"
+           fi
+           # It is a libtool convenience library, so add in its objects.
+           convenience="$convenience $ladir/$objdir/$old_library"
+           old_convenience="$old_convenience $ladir/$objdir/$old_library"
+           tmp_libs=
+           for deplib in $dependency_libs; do
+             deplibs="$deplib $deplibs"
+             if $opt_duplicate_deps ; then
+               case "$tmp_libs " in
+               *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+               esac
+             fi
+             tmp_libs="$tmp_libs $deplib"
+           done
+         elif test "$linkmode" != prog && test "$linkmode" != lib; then
+           func_fatal_error "\`$lib' is not a convenience library"
+         fi
+         continue
+       fi # $pass = conv
+
+
+       # Get the name of the library we link against.
+       linklib=
+       for l in $old_library $library_names; do
+         linklib="$l"
+       done
+       if test -z "$linklib"; then
+         func_fatal_error "cannot find name of link library for \`$lib'"
+       fi
+
+       # This library was specified with -dlopen.
+       if test "$pass" = dlopen; then
+         if test -z "$libdir"; then
+           func_fatal_error "cannot -dlopen a convenience library: \`$lib'"
+         fi
+         if test -z "$dlname" ||
+            test "$dlopen_support" != yes ||
+            test "$build_libtool_libs" = no; then
+           # If there is no dlname, no dlopen support or we're linking
+           # statically, we need to preload.  We also need to preload any
+           # dependent libraries so libltdl's deplib preloader doesn't
+           # bomb out in the load deplibs phase.
+           dlprefiles="$dlprefiles $lib $dependency_libs"
+         else
+           newdlfiles="$newdlfiles $lib"
+         fi
+         continue
+       fi # $pass = dlopen
+
+       # We need an absolute path.
+       case $ladir in
+       [\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;;
+       *)
+         abs_ladir=`cd "$ladir" && pwd`
+         if test -z "$abs_ladir"; then
+           func_warning "cannot determine absolute directory name of \`$ladir'"
+           func_warning "passing it literally to the linker, although it might fail"
+           abs_ladir="$ladir"
+         fi
+         ;;
+       esac
+       func_basename "$lib"
+       laname="$func_basename_result"
+
+       # Find the relevant object directory and library name.
+       if test "X$installed" = Xyes; then
+         if test ! -f "$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
+           func_warning "library \`$lib' was moved."
+           dir="$ladir"
+           absdir="$abs_ladir"
+           libdir="$abs_ladir"
+         else
+           dir="$libdir"
+           absdir="$libdir"
+         fi
+         test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes
+       else
+         if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
+           dir="$ladir"
+           absdir="$abs_ladir"
+           # Remove this search path later
+           notinst_path="$notinst_path $abs_ladir"
+         else
+           dir="$ladir/$objdir"
+           absdir="$abs_ladir/$objdir"
+           # Remove this search path later
+           notinst_path="$notinst_path $abs_ladir"
+         fi
+       fi # $installed = yes
+       func_stripname 'lib' '.la' "$laname"
+       name=$func_stripname_result
+
+       # This library was specified with -dlpreopen.
+       if test "$pass" = dlpreopen; then
+         if test -z "$libdir" && test "$linkmode" = prog; then
+           func_fatal_error "only libraries may -dlpreopen a convenience library: \`$lib'"
+         fi
+         # Prefer using a static library (so that no silly _DYNAMIC symbols
+         # are required to link).
+         if test -n "$old_library"; then
+           newdlprefiles="$newdlprefiles $dir/$old_library"
+           # Keep a list of preopened convenience libraries to check
+           # that they are being used correctly in the link pass.
+           test -z "$libdir" && \
+               dlpreconveniencelibs="$dlpreconveniencelibs $dir/$old_library"
+         # Otherwise, use the dlname, so that lt_dlopen finds it.
+         elif test -n "$dlname"; then
+           newdlprefiles="$newdlprefiles $dir/$dlname"
+         else
+           newdlprefiles="$newdlprefiles $dir/$linklib"
+         fi
+       fi # $pass = dlpreopen
+
+       if test -z "$libdir"; then
+         # Link the convenience library
+         if test "$linkmode" = lib; then
+           deplibs="$dir/$old_library $deplibs"
+         elif test "$linkmode,$pass" = "prog,link"; then
+           compile_deplibs="$dir/$old_library $compile_deplibs"
+           finalize_deplibs="$dir/$old_library $finalize_deplibs"
+         else
+           deplibs="$lib $deplibs" # used for prog,scan pass
+         fi
+         continue
+       fi
+
+
+       if test "$linkmode" = prog && test "$pass" != link; then
+         newlib_search_path="$newlib_search_path $ladir"
+         deplibs="$lib $deplibs"
+
+         linkalldeplibs=no
+         if test "$link_all_deplibs" != no || test -z "$library_names" ||
+            test "$build_libtool_libs" = no; then
+           linkalldeplibs=yes
+         fi
+
+         tmp_libs=
+         for deplib in $dependency_libs; do
+           case $deplib in
+           -L*) func_stripname '-L' '' "$deplib"
+                newlib_search_path="$newlib_search_path $func_stripname_result"
+                ;;
+           esac
+           # Need to link against all dependency_libs?
+           if test "$linkalldeplibs" = yes; then
+             deplibs="$deplib $deplibs"
+           else
+             # Need to hardcode shared library paths
+             # or/and link against static libraries
+             newdependency_libs="$deplib $newdependency_libs"
+           fi
+           if $opt_duplicate_deps ; then
+             case "$tmp_libs " in
+             *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+             esac
+           fi
+           tmp_libs="$tmp_libs $deplib"
+         done # for deplib
+         continue
+       fi # $linkmode = prog...
+
+       if test "$linkmode,$pass" = "prog,link"; then
+         if test -n "$library_names" &&
+            { { test "$prefer_static_libs" = no ||
+                test "$prefer_static_libs,$installed" = "built,yes"; } ||
+              test -z "$old_library"; }; then
+           # We need to hardcode the library path
+           if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then
+             # Make sure the rpath contains only unique directories.
+             case "$temp_rpath:" in
+             *"$absdir:"*) ;;
+             *) temp_rpath="$temp_rpath$absdir:" ;;
+             esac
+           fi
+
+           # Hardcode the library path.
+           # Skip directories that are in the system default run-time
+           # search path.
+           case " $sys_lib_dlsearch_path " in
+           *" $absdir "*) ;;
+           *)
+             case "$compile_rpath " in
+             *" $absdir "*) ;;
+             *) compile_rpath="$compile_rpath $absdir"
+             esac
+             ;;
+           esac
+           case " $sys_lib_dlsearch_path " in
+           *" $libdir "*) ;;
+           *)
+             case "$finalize_rpath " in
+             *" $libdir "*) ;;
+             *) finalize_rpath="$finalize_rpath $libdir"
+             esac
+             ;;
+           esac
+         fi # $linkmode,$pass = prog,link...
+
+         if test "$alldeplibs" = yes &&
+            { test "$deplibs_check_method" = pass_all ||
+              { test "$build_libtool_libs" = yes &&
+                test -n "$library_names"; }; }; then
+           # We only need to search for static libraries
+           continue
+         fi
+       fi
+
+       link_static=no # Whether the deplib will be linked statically
+       use_static_libs=$prefer_static_libs
+       if test "$use_static_libs" = built && test "$installed" = yes; then
+         use_static_libs=no
+       fi
+       if test -n "$library_names" &&
+          { test "$use_static_libs" = no || test -z "$old_library"; }; then
+         case $host in
+         *cygwin* | *mingw* | *cegcc*)
+             # No point in relinking DLLs because paths are not encoded
+             notinst_deplibs="$notinst_deplibs $lib"
+             need_relink=no
+           ;;
+         *)
+           if test "$installed" = no; then
+             notinst_deplibs="$notinst_deplibs $lib"
+             need_relink=yes
+           fi
+           ;;
+         esac
+         # This is a shared library
+
+         # Warn about portability, can't link against -module's on some
+         # systems (darwin).  Don't bleat about dlopened modules though!
+         dlopenmodule=""
+         for dlpremoduletest in $dlprefiles; do
+           if test "X$dlpremoduletest" = "X$lib"; then
+             dlopenmodule="$dlpremoduletest"
+             break
+           fi
+         done
+         if test -z "$dlopenmodule" && test "$shouldnotlink" = yes && test "$pass" = link; then
+           $ECHO
+           if test "$linkmode" = prog; then
+             $ECHO "*** Warning: Linking the executable $output against the loadable module"
+           else
+             $ECHO "*** Warning: Linking the shared library $output against the loadable module"
+           fi
+           $ECHO "*** $linklib is not portable!"
+         fi
+         if test "$linkmode" = lib &&
+            test "$hardcode_into_libs" = yes; then
+           # Hardcode the library path.
+           # Skip directories that are in the system default run-time
+           # search path.
+           case " $sys_lib_dlsearch_path " in
+           *" $absdir "*) ;;
+           *)
+             case "$compile_rpath " in
+             *" $absdir "*) ;;
+             *) compile_rpath="$compile_rpath $absdir"
+             esac
+             ;;
+           esac
+           case " $sys_lib_dlsearch_path " in
+           *" $libdir "*) ;;
+           *)
+             case "$finalize_rpath " in
+             *" $libdir "*) ;;
+             *) finalize_rpath="$finalize_rpath $libdir"
+             esac
+             ;;
+           esac
+         fi
+
+         if test -n "$old_archive_from_expsyms_cmds"; then
+           # figure out the soname
+           set dummy $library_names
+           shift
+           realname="$1"
+           shift
+           libname=`eval "\\$ECHO \"$libname_spec\""`
+           # use dlname if we got it. it's perfectly good, no?
+           if test -n "$dlname"; then
+             soname="$dlname"
+           elif test -n "$soname_spec"; then
+             # bleh windows
+             case $host in
+             *cygwin* | mingw* | *cegcc*)
+               func_arith $current - $age
+               major=$func_arith_result
+               versuffix="-$major"
+               ;;
+             esac
+             eval soname=\"$soname_spec\"
+           else
+             soname="$realname"
+           fi
+
+           # Make a new name for the extract_expsyms_cmds to use
+           soroot="$soname"
+           func_basename "$soroot"
+           soname="$func_basename_result"
+           func_stripname 'lib' '.dll' "$soname"
+           newlib=libimp-$func_stripname_result.a
+
+           # If the library has no export list, then create one now
+           if test -f "$output_objdir/$soname-def"; then :
+           else
+             func_verbose "extracting exported symbol list from \`$soname'"
+             func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
+           fi
+
+           # Create $newlib
+           if test -f "$output_objdir/$newlib"; then :; else
+             func_verbose "generating import library for \`$soname'"
+             func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
+           fi
+           # make sure the library variables are pointing to the new library
+           dir=$output_objdir
+           linklib=$newlib
+         fi # test -n "$old_archive_from_expsyms_cmds"
+
+         if test "$linkmode" = prog || test "$mode" != relink; then
+           add_shlibpath=
+           add_dir=
+           add=
+           lib_linked=yes
+           case $hardcode_action in
+           immediate | unsupported)
+             if test "$hardcode_direct" = no; then
+               add="$dir/$linklib"
+               case $host in
+                 *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;;
+                 *-*-sysv4*uw2*) add_dir="-L$dir" ;;
+                 *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
+                   *-*-unixware7*) add_dir="-L$dir" ;;
+                 *-*-darwin* )
+                   # if the lib is a (non-dlopened) module then we can not
+                   # link against it, someone is ignoring the earlier warnings
+                   if /usr/bin/file -L $add 2> /dev/null |
+                        $GREP ": [^:]* bundle" >/dev/null ; then
+                     if test "X$dlopenmodule" != "X$lib"; then
+                       $ECHO "*** Warning: lib $linklib is a module, not a shared library"
+                       if test -z "$old_library" ; then
+                         $ECHO
+                         $ECHO "*** And there doesn't seem to be a static archive available"
+                         $ECHO "*** The link will probably fail, sorry"
+                       else
+                         add="$dir/$old_library"
+                       fi
+                     elif test -n "$old_library"; then
+                       add="$dir/$old_library"
+                     fi
+                   fi
+               esac
+             elif test "$hardcode_minus_L" = no; then
+               case $host in
+               *-*-sunos*) add_shlibpath="$dir" ;;
+               esac
+               add_dir="-L$dir"
+               add="-l$name"
+             elif test "$hardcode_shlibpath_var" = no; then
+               add_shlibpath="$dir"
+               add="-l$name"
+             else
+               lib_linked=no
+             fi
+             ;;
+           relink)
+             if test "$hardcode_direct" = yes &&
+                test "$hardcode_direct_absolute" = no; then
+               add="$dir/$linklib"
+             elif test "$hardcode_minus_L" = yes; then
+               add_dir="-L$dir"
+               # Try looking first in the location we're being installed to.
+               if test -n "$inst_prefix_dir"; then
+                 case $libdir in
+                   [\\/]*)
+                     add_dir="$add_dir -L$inst_prefix_dir$libdir"
+                     ;;
+                 esac
+               fi
+               add="-l$name"
+             elif test "$hardcode_shlibpath_var" = yes; then
+               add_shlibpath="$dir"
+               add="-l$name"
+             else
+               lib_linked=no
+             fi
+             ;;
+           *) lib_linked=no ;;
+           esac
+
+           if test "$lib_linked" != yes; then
+             func_fatal_configuration "unsupported hardcode properties"
+           fi
+
+           if test -n "$add_shlibpath"; then
+             case :$compile_shlibpath: in
+             *":$add_shlibpath:"*) ;;
+             *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;;
+             esac
+           fi
+           if test "$linkmode" = prog; then
+             test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
+             test -n "$add" && compile_deplibs="$add $compile_deplibs"
+           else
+             test -n "$add_dir" && deplibs="$add_dir $deplibs"
+             test -n "$add" && deplibs="$add $deplibs"
+             if test "$hardcode_direct" != yes &&
+                test "$hardcode_minus_L" != yes &&
+                test "$hardcode_shlibpath_var" = yes; then
+               case :$finalize_shlibpath: in
+               *":$libdir:"*) ;;
+               *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;;
+               esac
+             fi
+           fi
+         fi
+
+         if test "$linkmode" = prog || test "$mode" = relink; then
+           add_shlibpath=
+           add_dir=
+           add=
+           # Finalize command for both is simple: just hardcode it.
+           if test "$hardcode_direct" = yes &&
+              test "$hardcode_direct_absolute" = no; then
+             add="$libdir/$linklib"
+           elif test "$hardcode_minus_L" = yes; then
+             add_dir="-L$libdir"
+             add="-l$name"
+           elif test "$hardcode_shlibpath_var" = yes; then
+             case :$finalize_shlibpath: in
+             *":$libdir:"*) ;;
+             *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;;
+             esac
+             add="-l$name"
+           elif test "$hardcode_automatic" = yes; then
+             if test -n "$inst_prefix_dir" &&
+                test -f "$inst_prefix_dir$libdir/$linklib" ; then
+               add="$inst_prefix_dir$libdir/$linklib"
+             else
+               add="$libdir/$linklib"
+             fi
+           else
+             # We cannot seem to hardcode it, guess we'll fake it.
+             add_dir="-L$libdir"
+             # Try looking first in the location we're being installed to.
+             if test -n "$inst_prefix_dir"; then
+               case $libdir in
+                 [\\/]*)
+                   add_dir="$add_dir -L$inst_prefix_dir$libdir"
+                   ;;
+               esac
+             fi
+             add="-l$name"
+           fi
+
+           if test "$linkmode" = prog; then
+             test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
+             test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
+           else
+             test -n "$add_dir" && deplibs="$add_dir $deplibs"
+             test -n "$add" && deplibs="$add $deplibs"
+           fi
+         fi
+       elif test "$linkmode" = prog; then
+         # Here we assume that one of hardcode_direct or hardcode_minus_L
+         # is not unsupported.  This is valid on all known static and
+         # shared platforms.
+         if test "$hardcode_direct" != unsupported; then
+           test -n "$old_library" && linklib="$old_library"
+           compile_deplibs="$dir/$linklib $compile_deplibs"
+           finalize_deplibs="$dir/$linklib $finalize_deplibs"
+         else
+           compile_deplibs="-l$name -L$dir $compile_deplibs"
+           finalize_deplibs="-l$name -L$dir $finalize_deplibs"
+         fi
+       elif test "$build_libtool_libs" = yes; then
+         # Not a shared library
+         if test "$deplibs_check_method" != pass_all; then
+           # We're trying link a shared library against a static one
+           # but the system doesn't support it.
+
+           # Just print a warning and add the library to dependency_libs so
+           # that the program can be linked against the static library.
+           $ECHO
+           $ECHO "*** Warning: This system can not link to static lib archive $lib."
+           $ECHO "*** I have the capability to make that library automatically link in when"
+           $ECHO "*** you link to this library.  But I can only do this if you have a"
+           $ECHO "*** shared version of the library, which you do not appear to have."
+           if test "$module" = yes; then
+             $ECHO "*** But as you try to build a module library, libtool will still create "
+             $ECHO "*** a static module, that should work as long as the dlopening application"
+             $ECHO "*** is linked with the -dlopen flag to resolve symbols at runtime."
+             if test -z "$global_symbol_pipe"; then
+               $ECHO
+               $ECHO "*** However, this would only work if libtool was able to extract symbol"
+               $ECHO "*** lists from a program, using \`nm' or equivalent, but libtool could"
+               $ECHO "*** not find such a program.  So, this module is probably useless."
+               $ECHO "*** \`nm' from GNU binutils and a full rebuild may help."
+             fi
+             if test "$build_old_libs" = no; then
+               build_libtool_libs=module
+               build_old_libs=yes
+             else
+               build_libtool_libs=no
+             fi
+           fi
+         else
+           deplibs="$dir/$old_library $deplibs"
+           link_static=yes
+         fi
+       fi # link shared/static library?
+
+       if test "$linkmode" = lib; then
+         if test -n "$dependency_libs" &&
+            { test "$hardcode_into_libs" != yes ||
+              test "$build_old_libs" = yes ||
+              test "$link_static" = yes; }; then
+           # Extract -R from dependency_libs
+           temp_deplibs=
+           for libdir in $dependency_libs; do
+             case $libdir in
+             -R*) func_stripname '-R' '' "$libdir"
+                  temp_xrpath=$func_stripname_result
+                  case " $xrpath " in
+                  *" $temp_xrpath "*) ;;
+                  *) xrpath="$xrpath $temp_xrpath";;
+                  esac;;
+             *) temp_deplibs="$temp_deplibs $libdir";;
+             esac
+           done
+           dependency_libs="$temp_deplibs"
+         fi
+
+         newlib_search_path="$newlib_search_path $absdir"
+         # Link against this library
+         test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
+         # ... and its dependency_libs
+         tmp_libs=
+         for deplib in $dependency_libs; do
+           newdependency_libs="$deplib $newdependency_libs"
+           if $opt_duplicate_deps ; then
+             case "$tmp_libs " in
+             *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+             esac
+           fi
+           tmp_libs="$tmp_libs $deplib"
+         done
+
+         if test "$link_all_deplibs" != no; then
+           # Add the search paths of all dependency libraries
+           for deplib in $dependency_libs; do
+             path=
+             case $deplib in
+             -L*) path="$deplib" ;;
+             *.la)
+               func_dirname "$deplib" "" "."
+               dir="$func_dirname_result"
+               # We need an absolute path.
+               case $dir in
+               [\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;;
+               *)
+                 absdir=`cd "$dir" && pwd`
+                 if test -z "$absdir"; then
+                   func_warning "cannot determine absolute directory name of \`$dir'"
+                   absdir="$dir"
+                 fi
+                 ;;
+               esac
+               if $GREP "^installed=no" $deplib > /dev/null; then
+               case $host in
+               *-*-darwin*)
+                 depdepl=
+                 eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
+                 if test -n "$deplibrary_names" ; then
+                   for tmp in $deplibrary_names ; do
+                     depdepl=$tmp
+                   done
+                   if test -f "$absdir/$objdir/$depdepl" ; then
+                     depdepl="$absdir/$objdir/$depdepl"
+                     darwin_install_name=`${OTOOL} -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
+                      if test -z "$darwin_install_name"; then
+                          darwin_install_name=`${OTOOL64} -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
+                      fi
+                     compiler_flags="$compiler_flags ${wl}-dylib_file ${wl}${darwin_install_name}:${depdepl}"
+                     linker_flags="$linker_flags -dylib_file ${darwin_install_name}:${depdepl}"
+                     path=
+                   fi
+                 fi
+                 ;;
+               *)
+                 path="-L$absdir/$objdir"
+                 ;;
+               esac
+               else
+                 eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
+                 test -z "$libdir" && \
+                   func_fatal_error "\`$deplib' is not a valid libtool archive"
+                 test "$absdir" != "$libdir" && \
+                   func_warning "\`$deplib' seems to be moved"
+
+                 path="-L$absdir"
+               fi
+               ;;
+             esac
+             case " $deplibs " in
+             *" $path "*) ;;
+             *) deplibs="$path $deplibs" ;;
+             esac
+           done
+         fi # link_all_deplibs != no
+       fi # linkmode = lib
+      done # for deplib in $libs
+      if test "$pass" = link; then
+       if test "$linkmode" = "prog"; then
+         compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
+         finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
+       else
+         compiler_flags="$compiler_flags "`$ECHO "X $new_inherited_linker_flags" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+       fi
+      fi
+      dependency_libs="$newdependency_libs"
+      if test "$pass" = dlpreopen; then
+       # Link the dlpreopened libraries before other libraries
+       for deplib in $save_deplibs; do
+         deplibs="$deplib $deplibs"
+       done
+      fi
+      if test "$pass" != dlopen; then
+       if test "$pass" != conv; then
+         # Make sure lib_search_path contains only unique directories.
+         lib_search_path=
+         for dir in $newlib_search_path; do
+           case "$lib_search_path " in
+           *" $dir "*) ;;
+           *) lib_search_path="$lib_search_path $dir" ;;
+           esac
+         done
+         newlib_search_path=
+       fi
+
+       if test "$linkmode,$pass" != "prog,link"; then
+         vars="deplibs"
+       else
+         vars="compile_deplibs finalize_deplibs"
+       fi
+       for var in $vars dependency_libs; do
+         # Add libraries to $var in reverse order
+         eval tmp_libs=\"\$$var\"
+         new_libs=
+         for deplib in $tmp_libs; do
+           # FIXME: Pedantically, this is the right thing to do, so
+           #        that some nasty dependency loop isn't accidentally
+           #        broken:
+           #new_libs="$deplib $new_libs"
+           # Pragmatically, this seems to cause very few problems in
+           # practice:
+           case $deplib in
+           -L*) new_libs="$deplib $new_libs" ;;
+           -R*) ;;
+           *)
+             # And here is the reason: when a library appears more
+             # than once as an explicit dependence of a library, or
+             # is implicitly linked in more than once by the
+             # compiler, it is considered special, and multiple
+             # occurrences thereof are not removed.  Compare this
+             # with having the same library being listed as a
+             # dependency of multiple other libraries: in this case,
+             # we know (pedantically, we assume) the library does not
+             # need to be listed more than once, so we keep only the
+             # last copy.  This is not always right, but it is rare
+             # enough that we require users that really mean to play
+             # such unportable linking tricks to link the library
+             # using -Wl,-lname, so that libtool does not consider it
+             # for duplicate removal.
+             case " $specialdeplibs " in
+             *" $deplib "*) new_libs="$deplib $new_libs" ;;
+             *)
+               case " $new_libs " in
+               *" $deplib "*) ;;
+               *) new_libs="$deplib $new_libs" ;;
+               esac
+               ;;
+             esac
+             ;;
+           esac
+         done
+         tmp_libs=
+         for deplib in $new_libs; do
+           case $deplib in
+           -L*)
+             case " $tmp_libs " in
+             *" $deplib "*) ;;
+             *) tmp_libs="$tmp_libs $deplib" ;;
+             esac
+             ;;
+           *) tmp_libs="$tmp_libs $deplib" ;;
+           esac
+         done
+         eval $var=\"$tmp_libs\"
+       done # for var
+      fi
+      # Last step: remove runtime libs from dependency_libs
+      # (they stay in deplibs)
+      tmp_libs=
+      for i in $dependency_libs ; do
+       case " $predeps $postdeps $compiler_lib_search_path " in
+       *" $i "*)
+         i=""
+         ;;
+       esac
+       if test -n "$i" ; then
+         tmp_libs="$tmp_libs $i"
+       fi
+      done
+      dependency_libs=$tmp_libs
+    done # for pass
+    if test "$linkmode" = prog; then
+      dlfiles="$newdlfiles"
+    fi
+    if test "$linkmode" = prog || test "$linkmode" = lib; then
+      dlprefiles="$newdlprefiles"
+    fi
+
+    case $linkmode in
+    oldlib)
+      if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
+       func_warning "\`-dlopen' is ignored for archives"
+      fi
+
+      case " $deplibs" in
+      *\ -l* | *\ -L*)
+       func_warning "\`-l' and \`-L' are ignored for archives" ;;
+      esac
+
+      test -n "$rpath" && \
+       func_warning "\`-rpath' is ignored for archives"
+
+      test -n "$xrpath" && \
+       func_warning "\`-R' is ignored for archives"
+
+      test -n "$vinfo" && \
+       func_warning "\`-version-info/-version-number' is ignored for archives"
+
+      test -n "$release" && \
+       func_warning "\`-release' is ignored for archives"
+
+      test -n "$export_symbols$export_symbols_regex" && \
+       func_warning "\`-export-symbols' is ignored for archives"
+
+      # Now set the variables for building old libraries.
+      build_libtool_libs=no
+      oldlibs="$output"
+      objs="$objs$old_deplibs"
+      ;;
+
+    lib)
+      # Make sure we only generate libraries of the form `libNAME.la'.
+      case $outputname in
+      lib*)
+       func_stripname 'lib' '.la' "$outputname"
+       name=$func_stripname_result
+       eval shared_ext=\"$shrext_cmds\"
+       eval libname=\"$libname_spec\"
+       ;;
+      *)
+       test "$module" = no && \
+         func_fatal_help "libtool library \`$output' must begin with \`lib'"
+
+       if test "$need_lib_prefix" != no; then
+         # Add the "lib" prefix for modules if required
+         func_stripname '' '.la' "$outputname"
+         name=$func_stripname_result
+         eval shared_ext=\"$shrext_cmds\"
+         eval libname=\"$libname_spec\"
+       else
+         func_stripname '' '.la' "$outputname"
+         libname=$func_stripname_result
+       fi
+       ;;
+      esac
+
+      if test -n "$objs"; then
+       if test "$deplibs_check_method" != pass_all; then
+         func_fatal_error "cannot build libtool library \`$output' from non-libtool objects on this host:$objs"
+       else
+         $ECHO
+         $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
+         $ECHO "*** objects $objs is not portable!"
+         libobjs="$libobjs $objs"
+       fi
+      fi
+
+      test "$dlself" != no && \
+       func_warning "\`-dlopen self' is ignored for libtool libraries"
+
+      set dummy $rpath
+      shift
+      test "$#" -gt 1 && \
+       func_warning "ignoring multiple \`-rpath's for a libtool library"
+
+      install_libdir="$1"
+
+      oldlibs=
+      if test -z "$rpath"; then
+       if test "$build_libtool_libs" = yes; then
+         # Building a libtool convenience library.
+         # Some compilers have problems with a `.al' extension so
+         # convenience libraries should have the same extension an
+         # archive normally would.
+         oldlibs="$output_objdir/$libname.$libext $oldlibs"
+         build_libtool_libs=convenience
+         build_old_libs=yes
+       fi
+
+       test -n "$vinfo" && \
+         func_warning "\`-version-info/-version-number' is ignored for convenience libraries"
+
+       test -n "$release" && \
+         func_warning "\`-release' is ignored for convenience libraries"
+      else
+
+       # Parse the version information argument.
+       save_ifs="$IFS"; IFS=':'
+       set dummy $vinfo 0 0 0
+       shift
+       IFS="$save_ifs"
+
+       test -n "$7" && \
+         func_fatal_help "too many parameters to \`-version-info'"
+
+       # convert absolute version numbers to libtool ages
+       # this retains compatibility with .la files and attempts
+       # to make the code below a bit more comprehensible
+
+       case $vinfo_number in
+       yes)
+         number_major="$1"
+         number_minor="$2"
+         number_revision="$3"
+         #
+         # There are really only two kinds -- those that
+         # use the current revision as the major version
+         # and those that subtract age and use age as
+         # a minor version.  But, then there is irix
+         # which has an extra 1 added just for fun
+         #
+         case $version_type in
+         darwin|linux|osf|windows|none)
+           func_arith $number_major + $number_minor
+           current=$func_arith_result
+           age="$number_minor"
+           revision="$number_revision"
+           ;;
+         freebsd-aout|freebsd-elf|sunos)
+           current="$number_major"
+           revision="$number_minor"
+           age="0"
+           ;;
+         irix|nonstopux)
+           func_arith $number_major + $number_minor
+           current=$func_arith_result
+           age="$number_minor"
+           revision="$number_minor"
+           lt_irix_increment=no
+           ;;
+         *)
+           func_fatal_configuration "$modename: unknown library version type \`$version_type'"
+           ;;
+         esac
+         ;;
+       no)
+         current="$1"
+         revision="$2"
+         age="$3"
+         ;;
+       esac
+
+       # Check that each of the things are valid numbers.
+       case $current in
+       0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+       *)
+         func_error "CURRENT \`$current' must be a nonnegative integer"
+         func_fatal_error "\`$vinfo' is not valid version information"
+         ;;
+       esac
+
+       case $revision in
+       0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+       *)
+         func_error "REVISION \`$revision' must be a nonnegative integer"
+         func_fatal_error "\`$vinfo' is not valid version information"
+         ;;
+       esac
+
+       case $age in
+       0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+       *)
+         func_error "AGE \`$age' must be a nonnegative integer"
+         func_fatal_error "\`$vinfo' is not valid version information"
+         ;;
+       esac
+
+       if test "$age" -gt "$current"; then
+         func_error "AGE \`$age' is greater than the current interface number \`$current'"
+         func_fatal_error "\`$vinfo' is not valid version information"
+       fi
+
+       # Calculate the version variables.
+       major=
+       versuffix=
+       verstring=
+       case $version_type in
+       none) ;;
+
+       darwin)
+         # Like Linux, but with the current version available in
+         # verstring for coding it into the library header
+         func_arith $current - $age
+         major=.$func_arith_result
+         versuffix="$major.$age.$revision"
+         # Darwin ld doesn't like 0 for these options...
+         func_arith $current + 1
+         minor_current=$func_arith_result
+         xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision"
+         verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
+         ;;
+
+       freebsd-aout)
+         major=".$current"
+         versuffix=".$current.$revision";
+         ;;
+
+       freebsd-elf)
+         major=".$current"
+         versuffix=".$current"
+         ;;
+
+       irix | nonstopux)
+         if test "X$lt_irix_increment" = "Xno"; then
+           func_arith $current - $age
+         else
+           func_arith $current - $age + 1
+         fi
+         major=$func_arith_result
+
+         case $version_type in
+           nonstopux) verstring_prefix=nonstopux ;;
+           *)         verstring_prefix=sgi ;;
+         esac
+         verstring="$verstring_prefix$major.$revision"
+
+         # Add in all the interfaces that we are compatible with.
+         loop=$revision
+         while test "$loop" -ne 0; do
+           func_arith $revision - $loop
+           iface=$func_arith_result
+           func_arith $loop - 1
+           loop=$func_arith_result
+           verstring="$verstring_prefix$major.$iface:$verstring"
+         done
+
+         # Before this point, $major must not contain `.'.
+         major=.$major
+         versuffix="$major.$revision"
+         ;;
+
+       linux)
+         func_arith $current - $age
+         major=.$func_arith_result
+         versuffix="$major.$age.$revision"
+         ;;
+
+       osf)
+         func_arith $current - $age
+         major=.$func_arith_result
+         versuffix=".$current.$age.$revision"
+         verstring="$current.$age.$revision"
+
+         # Add in all the interfaces that we are compatible with.
+         loop=$age
+         while test "$loop" -ne 0; do
+           func_arith $current - $loop
+           iface=$func_arith_result
+           func_arith $loop - 1
+           loop=$func_arith_result
+           verstring="$verstring:${iface}.0"
+         done
+
+         # Make executables depend on our current version.
+         verstring="$verstring:${current}.0"
+         ;;
+
+       qnx)
+         major=".$current"
+         versuffix=".$current"
+         ;;
+
+       sunos)
+         major=".$current"
+         versuffix=".$current.$revision"
+         ;;
+
+       windows)
+         # Use '-' rather than '.', since we only want one
+         # extension on DOS 8.3 filesystems.
+         func_arith $current - $age
+         major=$func_arith_result
+         versuffix="-$major"
+         ;;
+
+       *)
+         func_fatal_configuration "unknown library version type \`$version_type'"
+         ;;
+       esac
+
+       # Clear the version info if we defaulted, and they specified a release.
+       if test -z "$vinfo" && test -n "$release"; then
+         major=
+         case $version_type in
+         darwin)
+           # we can't check for "0.0" in archive_cmds due to quoting
+           # problems, so we reset it completely
+           verstring=
+           ;;
+         *)
+           verstring="0.0"
+           ;;
+         esac
+         if test "$need_version" = no; then
+           versuffix=
+         else
+           versuffix=".0.0"
+         fi
+       fi
+
+       # Remove version info from name if versioning should be avoided
+       if test "$avoid_version" = yes && test "$need_version" = no; then
+         major=
+         versuffix=
+         verstring=""
+       fi
+
+       # Check to see if the archive will have undefined symbols.
+       if test "$allow_undefined" = yes; then
+         if test "$allow_undefined_flag" = unsupported; then
+           func_warning "undefined symbols not allowed in $host shared libraries"
+           build_libtool_libs=no
+           build_old_libs=yes
+         fi
+       else
+         # Don't allow undefined symbols.
+         allow_undefined_flag="$no_undefined_flag"
+       fi
+
+      fi
+
+      func_generate_dlsyms "$libname" "$libname" "yes"
+      libobjs="$libobjs $symfileobj"
+      test "X$libobjs" = "X " && libobjs=
+
+      if test "$mode" != relink; then
+       # Remove our outputs, but don't remove object files since they
+       # may have been created when compiling PIC objects.
+       removelist=
+       tempremovelist=`$ECHO "$output_objdir/*"`
+       for p in $tempremovelist; do
+         case $p in
+           *.$objext | *.gcno)
+              ;;
+           $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*)
+              if test "X$precious_files_regex" != "X"; then
+                if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
+                then
+                  continue
+                fi
+              fi
+              removelist="$removelist $p"
+              ;;
+           *) ;;
+         esac
+       done
+       test -n "$removelist" && \
+         func_show_eval "${RM}r \$removelist"
+      fi
+
+      # Now set the variables for building old libraries.
+      if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then
+       oldlibs="$oldlibs $output_objdir/$libname.$libext"
+
+       # Transform .lo files to .o files.
+       oldobjs="$objs "`$ECHO "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP`
+      fi
+
+      # Eliminate all temporary directories.
+      #for path in $notinst_path; do
+      #        lib_search_path=`$ECHO "X$lib_search_path " | $Xsed -e "s% $path % %g"`
+      #        deplibs=`$ECHO "X$deplibs " | $Xsed -e "s% -L$path % %g"`
+      #        dependency_libs=`$ECHO "X$dependency_libs " | $Xsed -e "s% -L$path % %g"`
+      #done
+
+      if test -n "$xrpath"; then
+       # If the user specified any rpath flags, then add them.
+       temp_xrpath=
+       for libdir in $xrpath; do
+         temp_xrpath="$temp_xrpath -R$libdir"
+         case "$finalize_rpath " in
+         *" $libdir "*) ;;
+         *) finalize_rpath="$finalize_rpath $libdir" ;;
+         esac
+       done
+       if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then
+         dependency_libs="$temp_xrpath $dependency_libs"
+       fi
+      fi
+
+      # Make sure dlfiles contains only unique files that won't be dlpreopened
+      old_dlfiles="$dlfiles"
+      dlfiles=
+      for lib in $old_dlfiles; do
+       case " $dlprefiles $dlfiles " in
+       *" $lib "*) ;;
+       *) dlfiles="$dlfiles $lib" ;;
+       esac
+      done
+
+      # Make sure dlprefiles contains only unique files
+      old_dlprefiles="$dlprefiles"
+      dlprefiles=
+      for lib in $old_dlprefiles; do
+       case "$dlprefiles " in
+       *" $lib "*) ;;
+       *) dlprefiles="$dlprefiles $lib" ;;
+       esac
+      done
+
+      if test "$build_libtool_libs" = yes; then
+       if test -n "$rpath"; then
+         case $host in
+         *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc*)
+           # these systems don't actually have a c library (as such)!
+           ;;
+         *-*-rhapsody* | *-*-darwin1.[012])
+           # Rhapsody C library is in the System framework
+           deplibs="$deplibs System.ltframework"
+           ;;
+         *-*-netbsd*)
+           # Don't link with libc until the a.out ld.so is fixed.
+           ;;
+         *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+           # Do not include libc due to us having libc/libc_r.
+           ;;
+         *-*-sco3.2v5* | *-*-sco5v6*)
+           # Causes problems with __ctype
+           ;;
+         *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
+           # Compiler inserts libc in the correct place for threads to work
+           ;;
+         *)
+           # Add libc to deplibs on all other systems if necessary.
+           if test "$build_libtool_need_lc" = "yes"; then
+             deplibs="$deplibs -lc"
+           fi
+           ;;
+         esac
+       fi
+
+       # Transform deplibs into only deplibs that can be linked in shared.
+       name_save=$name
+       libname_save=$libname
+       release_save=$release
+       versuffix_save=$versuffix
+       major_save=$major
+       # I'm not sure if I'm treating the release correctly.  I think
+       # release should show up in the -l (ie -lgmp5) so we don't want to
+       # add it in twice.  Is that correct?
+       release=""
+       versuffix=""
+       major=""
+       newdeplibs=
+       droppeddeps=no
+       case $deplibs_check_method in
+       pass_all)
+         # Don't check for shared/static.  Everything works.
+         # This might be a little naive.  We might want to check
+         # whether the library exists or not.  But this is on
+         # osf3 & osf4 and I'm not really sure... Just
+         # implementing what was already the behavior.
+         newdeplibs=$deplibs
+         ;;
+       test_compile)
+         # This code stresses the "libraries are programs" paradigm to its
+         # limits. Maybe even breaks it.  We compile a program, linking it
+         # against the deplibs as a proxy for the library.  Then we can check
+         # whether they linked in statically or dynamically with ldd.
+         $opt_dry_run || $RM conftest.c
+         cat > conftest.c <<EOF
+         int main() { return 0; }
+EOF
+         $opt_dry_run || $RM conftest
+         if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
+           ldd_output=`ldd conftest`
+           for i in $deplibs; do
+             case $i in
+             -l*)
+               func_stripname -l '' "$i"
+               name=$func_stripname_result
+               if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+                 case " $predeps $postdeps " in
+                 *" $i "*)
+                   newdeplibs="$newdeplibs $i"
+                   i=""
+                   ;;
+                 esac
+               fi
+               if test -n "$i" ; then
+                 libname=`eval "\\$ECHO \"$libname_spec\""`
+                 deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
+                 set dummy $deplib_matches; shift
+                 deplib_match=$1
+                 if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
+                   newdeplibs="$newdeplibs $i"
+                 else
+                   droppeddeps=yes
+                   $ECHO
+                   $ECHO "*** Warning: dynamic linker does not accept needed library $i."
+                   $ECHO "*** I have the capability to make that library automatically link in when"
+                   $ECHO "*** you link to this library.  But I can only do this if you have a"
+                   $ECHO "*** shared version of the library, which I believe you do not have"
+                   $ECHO "*** because a test_compile did reveal that the linker did not use it for"
+                   $ECHO "*** its dynamic dependency list that programs get resolved with at runtime."
+                 fi
+               fi
+               ;;
+             *)
+               newdeplibs="$newdeplibs $i"
+               ;;
+             esac
+           done
+         else
+           # Error occurred in the first compile.  Let's try to salvage
+           # the situation: Compile a separate program for each library.
+           for i in $deplibs; do
+             case $i in
+             -l*)
+               func_stripname -l '' "$i"
+               name=$func_stripname_result
+               $opt_dry_run || $RM conftest
+               if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
+                 ldd_output=`ldd conftest`
+                 if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+                   case " $predeps $postdeps " in
+                   *" $i "*)
+                     newdeplibs="$newdeplibs $i"
+                     i=""
+                     ;;
+                   esac
+                 fi
+                 if test -n "$i" ; then
+                   libname=`eval "\\$ECHO \"$libname_spec\""`
+                   deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
+                   set dummy $deplib_matches; shift
+                   deplib_match=$1
+                   if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
+                     newdeplibs="$newdeplibs $i"
+                   else
+                     droppeddeps=yes
+                     $ECHO
+                     $ECHO "*** Warning: dynamic linker does not accept needed library $i."
+                     $ECHO "*** I have the capability to make that library automatically link in when"
+                     $ECHO "*** you link to this library.  But I can only do this if you have a"
+                     $ECHO "*** shared version of the library, which you do not appear to have"
+                     $ECHO "*** because a test_compile did reveal that the linker did not use this one"
+                     $ECHO "*** as a dynamic dependency that programs can get resolved with at runtime."
+                   fi
+                 fi
+               else
+                 droppeddeps=yes
+                 $ECHO
+                 $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
+                 $ECHO "*** make it link in!  You will probably need to install it or some"
+                 $ECHO "*** library that it depends on before this library will be fully"
+                 $ECHO "*** functional.  Installing it before continuing would be even better."
+               fi
+               ;;
+             *)
+               newdeplibs="$newdeplibs $i"
+               ;;
+             esac
+           done
+         fi
+         ;;
+       file_magic*)
+         set dummy $deplibs_check_method; shift
+         file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+         for a_deplib in $deplibs; do
+           case $a_deplib in
+           -l*)
+             func_stripname -l '' "$a_deplib"
+             name=$func_stripname_result
+             if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+               case " $predeps $postdeps " in
+               *" $a_deplib "*)
+                 newdeplibs="$newdeplibs $a_deplib"
+                 a_deplib=""
+                 ;;
+               esac
+             fi
+             if test -n "$a_deplib" ; then
+               libname=`eval "\\$ECHO \"$libname_spec\""`
+               for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
+                 potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
+                 for potent_lib in $potential_libs; do
+                     # Follow soft links.
+                     if ls -lLd "$potent_lib" 2>/dev/null |
+                        $GREP " -> " >/dev/null; then
+                       continue
+                     fi
+                     # The statement above tries to avoid entering an
+                     # endless loop below, in case of cyclic links.
+                     # We might still enter an endless loop, since a link
+                     # loop can be closed while we follow links,
+                     # but so what?
+                     potlib="$potent_lib"
+                     while test -h "$potlib" 2>/dev/null; do
+                       potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'`
+                       case $potliblink in
+                       [\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";;
+                       *) potlib=`$ECHO "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";;
+                       esac
+                     done
+                     if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
+                        $SED -e 10q |
+                        $EGREP "$file_magic_regex" > /dev/null; then
+                       newdeplibs="$newdeplibs $a_deplib"
+                       a_deplib=""
+                       break 2
+                     fi
+                 done
+               done
+             fi
+             if test -n "$a_deplib" ; then
+               droppeddeps=yes
+               $ECHO
+               $ECHO "*** Warning: linker path does not have real file for library $a_deplib."
+               $ECHO "*** I have the capability to make that library automatically link in when"
+               $ECHO "*** you link to this library.  But I can only do this if you have a"
+               $ECHO "*** shared version of the library, which you do not appear to have"
+               $ECHO "*** because I did check the linker path looking for a file starting"
+               if test -z "$potlib" ; then
+                 $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
+               else
+                 $ECHO "*** with $libname and none of the candidates passed a file format test"
+                 $ECHO "*** using a file magic. Last file checked: $potlib"
+               fi
+             fi
+             ;;
+           *)
+             # Add a -L argument.
+             newdeplibs="$newdeplibs $a_deplib"
+             ;;
+           esac
+         done # Gone through all deplibs.
+         ;;
+       match_pattern*)
+         set dummy $deplibs_check_method; shift
+         match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+         for a_deplib in $deplibs; do
+           case $a_deplib in
+           -l*)
+             func_stripname -l '' "$a_deplib"
+             name=$func_stripname_result
+             if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+               case " $predeps $postdeps " in
+               *" $a_deplib "*)
+                 newdeplibs="$newdeplibs $a_deplib"
+                 a_deplib=""
+                 ;;
+               esac
+             fi
+             if test -n "$a_deplib" ; then
+               libname=`eval "\\$ECHO \"$libname_spec\""`
+               for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
+                 potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
+                 for potent_lib in $potential_libs; do
+                   potlib="$potent_lib" # see symlink-check above in file_magic test
+                   if eval "\$ECHO \"X$potent_lib\"" 2>/dev/null | $Xsed -e 10q | \
+                      $EGREP "$match_pattern_regex" > /dev/null; then
+                     newdeplibs="$newdeplibs $a_deplib"
+                     a_deplib=""
+                     break 2
+                   fi
+                 done
+               done
+             fi
+             if test -n "$a_deplib" ; then
+               droppeddeps=yes
+               $ECHO
+               $ECHO "*** Warning: linker path does not have real file for library $a_deplib."
+               $ECHO "*** I have the capability to make that library automatically link in when"
+               $ECHO "*** you link to this library.  But I can only do this if you have a"
+               $ECHO "*** shared version of the library, which you do not appear to have"
+               $ECHO "*** because I did check the linker path looking for a file starting"
+               if test -z "$potlib" ; then
+                 $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
+               else
+                 $ECHO "*** with $libname and none of the candidates passed a file format test"
+                 $ECHO "*** using a regex pattern. Last file checked: $potlib"
+               fi
+             fi
+             ;;
+           *)
+             # Add a -L argument.
+             newdeplibs="$newdeplibs $a_deplib"
+             ;;
+           esac
+         done # Gone through all deplibs.
+         ;;
+       none | unknown | *)
+         newdeplibs=""
+         tmp_deplibs=`$ECHO "X $deplibs" | $Xsed \
+             -e 's/ -lc$//' -e 's/ -[LR][^ ]*//g'`
+         if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+           for i in $predeps $postdeps ; do
+             # can't use Xsed below, because $i might contain '/'
+             tmp_deplibs=`$ECHO "X $tmp_deplibs" | $Xsed -e "s,$i,,"`
+           done
+         fi
+         if $ECHO "X $tmp_deplibs" | $Xsed -e 's/[      ]//g' |
+            $GREP . >/dev/null; then
+           $ECHO
+           if test "X$deplibs_check_method" = "Xnone"; then
+             $ECHO "*** Warning: inter-library dependencies are not supported in this platform."
+           else
+             $ECHO "*** Warning: inter-library dependencies are not known to be supported."
+           fi
+           $ECHO "*** All declared inter-library dependencies are being dropped."
+           droppeddeps=yes
+         fi
+         ;;
+       esac
+       versuffix=$versuffix_save
+       major=$major_save
+       release=$release_save
+       libname=$libname_save
+       name=$name_save
+
+       case $host in
+       *-*-rhapsody* | *-*-darwin1.[012])
+         # On Rhapsody replace the C library with the System framework
+         newdeplibs=`$ECHO "X $newdeplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
+         ;;
+       esac
+
+       if test "$droppeddeps" = yes; then
+         if test "$module" = yes; then
+           $ECHO
+           $ECHO "*** Warning: libtool could not satisfy all declared inter-library"
+           $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
+           $ECHO "*** a static module, that should work as long as the dlopening"
+           $ECHO "*** application is linked with the -dlopen flag."
+           if test -z "$global_symbol_pipe"; then
+             $ECHO
+             $ECHO "*** However, this would only work if libtool was able to extract symbol"
+             $ECHO "*** lists from a program, using \`nm' or equivalent, but libtool could"
+             $ECHO "*** not find such a program.  So, this module is probably useless."
+             $ECHO "*** \`nm' from GNU binutils and a full rebuild may help."
+           fi
+           if test "$build_old_libs" = no; then
+             oldlibs="$output_objdir/$libname.$libext"
+             build_libtool_libs=module
+             build_old_libs=yes
+           else
+             build_libtool_libs=no
+           fi
+         else
+           $ECHO "*** The inter-library dependencies that have been dropped here will be"
+           $ECHO "*** automatically added whenever a program is linked with this library"
+           $ECHO "*** or is declared to -dlopen it."
+
+           if test "$allow_undefined" = no; then
+             $ECHO
+             $ECHO "*** Since this library must not contain undefined symbols,"
+             $ECHO "*** because either the platform does not support them or"
+             $ECHO "*** it was explicitly requested with -no-undefined,"
+             $ECHO "*** libtool will only create a static version of it."
+             if test "$build_old_libs" = no; then
+               oldlibs="$output_objdir/$libname.$libext"
+               build_libtool_libs=module
+               build_old_libs=yes
+             else
+               build_libtool_libs=no
+             fi
+           fi
+         fi
+       fi
+       # Done checking deplibs!
+       deplibs=$newdeplibs
+      fi
+      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
+      case $host in
+       *-*-darwin*)
+         newdeplibs=`$ECHO "X $newdeplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+         new_inherited_linker_flags=`$ECHO "X $new_inherited_linker_flags" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+         deplibs=`$ECHO "X $deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+         ;;
+      esac
+
+      # move library search paths that coincide with paths to not yet
+      # installed libraries to the beginning of the library search list
+      new_libs=
+      for path in $notinst_path; do
+       case " $new_libs " in
+       *" -L$path/$objdir "*) ;;
+       *)
+         case " $deplibs " in
+         *" -L$path/$objdir "*)
+           new_libs="$new_libs -L$path/$objdir" ;;
+         esac
+         ;;
+       esac
+      done
+      for deplib in $deplibs; do
+       case $deplib in
+       -L*)
+         case " $new_libs " in
+         *" $deplib "*) ;;
+         *) new_libs="$new_libs $deplib" ;;
+         esac
+         ;;
+       *) new_libs="$new_libs $deplib" ;;
+       esac
+      done
+      deplibs="$new_libs"
+
+      # All the library-specific variables (install_libdir is set above).
+      library_names=
+      old_library=
+      dlname=
+
+      # Test again, we may have decided not to build it any more
+      if test "$build_libtool_libs" = yes; then
+       if test "$hardcode_into_libs" = yes; then
+         # Hardcode the library paths
+         hardcode_libdirs=
+         dep_rpath=
+         rpath="$finalize_rpath"
+         test "$mode" != relink && rpath="$compile_rpath$rpath"
+         for libdir in $rpath; do
+           if test -n "$hardcode_libdir_flag_spec"; then
+             if test -n "$hardcode_libdir_separator"; then
+               if test -z "$hardcode_libdirs"; then
+                 hardcode_libdirs="$libdir"
+               else
+                 # Just accumulate the unique libdirs.
+                 case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+                 *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+                   ;;
+                 *)
+                   hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
+                   ;;
+                 esac
+               fi
+             else
+               eval flag=\"$hardcode_libdir_flag_spec\"
+               dep_rpath="$dep_rpath $flag"
+             fi
+           elif test -n "$runpath_var"; then
+             case "$perm_rpath " in
+             *" $libdir "*) ;;
+             *) perm_rpath="$perm_rpath $libdir" ;;
+             esac
+           fi
+         done
+         # Substitute the hardcoded libdirs into the rpath.
+         if test -n "$hardcode_libdir_separator" &&
+            test -n "$hardcode_libdirs"; then
+           libdir="$hardcode_libdirs"
+           if test -n "$hardcode_libdir_flag_spec_ld"; then
+             eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\"
+           else
+             eval dep_rpath=\"$hardcode_libdir_flag_spec\"
+           fi
+         fi
+         if test -n "$runpath_var" && test -n "$perm_rpath"; then
+           # We should set the runpath_var.
+           rpath=
+           for dir in $perm_rpath; do
+             rpath="$rpath$dir:"
+           done
+           eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
+         fi
+         test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
+       fi
+
+       shlibpath="$finalize_shlibpath"
+       test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath"
+       if test -n "$shlibpath"; then
+         eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
+       fi
+
+       # Get the real and link names of the library.
+       eval shared_ext=\"$shrext_cmds\"
+       eval library_names=\"$library_names_spec\"
+       set dummy $library_names
+       shift
+       realname="$1"
+       shift
+
+       if test -n "$soname_spec"; then
+         eval soname=\"$soname_spec\"
+       else
+         soname="$realname"
+       fi
+       if test -z "$dlname"; then
+         dlname=$soname
+       fi
+
+       lib="$output_objdir/$realname"
+       linknames=
+       for link
+       do
+         linknames="$linknames $link"
+       done
+
+       # Use standard objects if they are pic
+       test -z "$pic_flag" && libobjs=`$ECHO "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+       test "X$libobjs" = "X " && libobjs=
+
+       delfiles=
+       if test -n "$export_symbols" && test -n "$include_expsyms"; then
+         $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
+         export_symbols="$output_objdir/$libname.uexp"
+         delfiles="$delfiles $export_symbols"
+       fi
+
+       orig_export_symbols=
+       case $host_os in
+       cygwin* | mingw* | cegcc*)
+         if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
+           # exporting using user supplied symfile
+           if test "x`$SED 1q $export_symbols`" != xEXPORTS; then
+             # and it's NOT already a .def file. Must figure out
+             # which of the given symbols are data symbols and tag
+             # them as such. So, trigger use of export_symbols_cmds.
+             # export_symbols gets reassigned inside the "prepare
+             # the list of exported symbols" if statement, so the
+             # include_expsyms logic still works.
+             orig_export_symbols="$export_symbols"
+             export_symbols=
+             always_export_symbols=yes
+           fi
+         fi
+         ;;
+       esac
+
+       # Prepare the list of exported symbols
+       if test -z "$export_symbols"; then
+         if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then
+           func_verbose "generating symbol list for \`$libname.la'"
+           export_symbols="$output_objdir/$libname.exp"
+           $opt_dry_run || $RM $export_symbols
+           cmds=$export_symbols_cmds
+           save_ifs="$IFS"; IFS='~'
+           for cmd in $cmds; do
+             IFS="$save_ifs"
+             eval cmd=\"$cmd\"
+             func_len " $cmd"
+             len=$func_len_result
+             if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+               func_show_eval "$cmd" 'exit $?'
+               skipped_export=false
+             else
+               # The command line is too long to execute in one step.
+               func_verbose "using reloadable object file for export list..."
+               skipped_export=:
+               # Break out early, otherwise skipped_export may be
+               # set to false by a later but shorter cmd.
+               break
+             fi
+           done
+           IFS="$save_ifs"
+           if test -n "$export_symbols_regex" && test "X$skipped_export" != "X:"; then
+             func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
+             func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
+           fi
+         fi
+       fi
+
+       if test -n "$export_symbols" && test -n "$include_expsyms"; then
+         tmp_export_symbols="$export_symbols"
+         test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols"
+         $opt_dry_run || eval '$ECHO "X$include_expsyms" | $Xsed | $SP2NL >> "$tmp_export_symbols"'
+       fi
+
+       if test "X$skipped_export" != "X:" && test -n "$orig_export_symbols"; then
+         # The given exports_symbols file has to be filtered, so filter it.
+         func_verbose "filter symbol list for \`$libname.la' to tag DATA exports"
+         # FIXME: $output_objdir/$libname.filter potentially contains lots of
+         # 's' commands which not all seds can handle. GNU sed should be fine
+         # though. Also, the filter scales superlinearly with the number of
+         # global variables. join(1) would be nice here, but unfortunately
+         # isn't a blessed tool.
+         $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
+         delfiles="$delfiles $export_symbols $output_objdir/$libname.filter"
+         export_symbols=$output_objdir/$libname.def
+         $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
+       fi
+
+       tmp_deplibs=
+       for test_deplib in $deplibs; do
+         case " $convenience " in
+         *" $test_deplib "*) ;;
+         *)
+           tmp_deplibs="$tmp_deplibs $test_deplib"
+           ;;
+         esac
+       done
+       deplibs="$tmp_deplibs"
+
+       if test -n "$convenience"; then
+         if test -n "$whole_archive_flag_spec" &&
+           test "$compiler_needs_object" = yes &&
+           test -z "$libobjs"; then
+           # extract the archives, so we have objects to list.
+           # TODO: could optimize this to just extract one archive.
+           whole_archive_flag_spec=
+         fi
+         if test -n "$whole_archive_flag_spec"; then
+           save_libobjs=$libobjs
+           eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
+           test "X$libobjs" = "X " && libobjs=
+         else
+           gentop="$output_objdir/${outputname}x"
+           generated="$generated $gentop"
+
+           func_extract_archives $gentop $convenience
+           libobjs="$libobjs $func_extract_archives_result"
+           test "X$libobjs" = "X " && libobjs=
+         fi
+       fi
+
+       if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then
+         eval flag=\"$thread_safe_flag_spec\"
+         linker_flags="$linker_flags $flag"
+       fi
+
+       # Make a backup of the uninstalled library when relinking
+       if test "$mode" = relink; then
+         $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
+       fi
+
+       # Do each of the archive commands.
+       if test "$module" = yes && test -n "$module_cmds" ; then
+         if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
+           eval test_cmds=\"$module_expsym_cmds\"
+           cmds=$module_expsym_cmds
+         else
+           eval test_cmds=\"$module_cmds\"
+           cmds=$module_cmds
+         fi
+       else
+         if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
+           eval test_cmds=\"$archive_expsym_cmds\"
+           cmds=$archive_expsym_cmds
+         else
+           eval test_cmds=\"$archive_cmds\"
+           cmds=$archive_cmds
+         fi
+       fi
+
+       if test "X$skipped_export" != "X:" &&
+          func_len " $test_cmds" &&
+          len=$func_len_result &&
+          test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+         :
+       else
+         # The command line is too long to link in one step, link piecewise
+         # or, if using GNU ld and skipped_export is not :, use a linker
+         # script.
+
+         # Save the value of $output and $libobjs because we want to
+         # use them later.  If we have whole_archive_flag_spec, we
+         # want to use save_libobjs as it was before
+         # whole_archive_flag_spec was expanded, because we can't
+         # assume the linker understands whole_archive_flag_spec.
+         # This may have to be revisited, in case too many
+         # convenience libraries get linked in and end up exceeding
+         # the spec.
+         if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
+           save_libobjs=$libobjs
+         fi
+         save_output=$output
+         output_la=`$ECHO "X$output" | $Xsed -e "$basename"`
+
+         # Clear the reloadable object creation command queue and
+         # initialize k to one.
+         test_cmds=
+         concat_cmds=
+         objlist=
+         last_robj=
+         k=1
+
+         if test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "$with_gnu_ld" = yes; then
+           output=${output_objdir}/${output_la}.lnkscript
+           func_verbose "creating GNU ld script: $output"
+           $ECHO 'INPUT (' > $output
+           for obj in $save_libobjs
+           do
+             $ECHO "$obj" >> $output
+           done
+           $ECHO ')' >> $output
+           delfiles="$delfiles $output"
+         elif test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "X$file_list_spec" != X; then
+           output=${output_objdir}/${output_la}.lnk
+           func_verbose "creating linker input file list: $output"
+           : > $output
+           set x $save_libobjs
+           shift
+           firstobj=
+           if test "$compiler_needs_object" = yes; then
+             firstobj="$1 "
+             shift
+           fi
+           for obj
+           do
+             $ECHO "$obj" >> $output
+           done
+           delfiles="$delfiles $output"
+           output=$firstobj\"$file_list_spec$output\"
+         else
+           if test -n "$save_libobjs"; then
+             func_verbose "creating reloadable object files..."
+             output=$output_objdir/$output_la-${k}.$objext
+             eval test_cmds=\"$reload_cmds\"
+             func_len " $test_cmds"
+             len0=$func_len_result
+             len=$len0
+
+             # Loop over the list of objects to be linked.
+             for obj in $save_libobjs
+             do
+               func_len " $obj"
+               func_arith $len + $func_len_result
+               len=$func_arith_result
+               if test "X$objlist" = X ||
+                  test "$len" -lt "$max_cmd_len"; then
+                 func_append objlist " $obj"
+               else
+                 # The command $test_cmds is almost too long, add a
+                 # command to the queue.
+                 if test "$k" -eq 1 ; then
+                   # The first file doesn't have a previous command to add.
+                   eval concat_cmds=\"$reload_cmds $objlist $last_robj\"
+                 else
+                   # All subsequent reloadable object files will link in
+                   # the last one created.
+                   eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj~\$RM $last_robj\"
+                 fi
+                 last_robj=$output_objdir/$output_la-${k}.$objext
+                 func_arith $k + 1
+                 k=$func_arith_result
+                 output=$output_objdir/$output_la-${k}.$objext
+                 objlist=$obj
+                 func_len " $last_robj"
+                 func_arith $len0 + $func_len_result
+                 len=$func_arith_result
+               fi
+             done
+             # Handle the remaining objects by creating one last
+             # reloadable object file.  All subsequent reloadable object
+             # files will link in the last one created.
+             test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+             eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\"
+             if test -n "$last_robj"; then
+               eval concat_cmds=\"\${concat_cmds}~\$RM $last_robj\"
+             fi
+             delfiles="$delfiles $output"
+
+           else
+             output=
+           fi
+
+           if ${skipped_export-false}; then
+             func_verbose "generating symbol list for \`$libname.la'"
+             export_symbols="$output_objdir/$libname.exp"
+             $opt_dry_run || $RM $export_symbols
+             libobjs=$output
+             # Append the command to create the export file.
+             test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+             eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
+             if test -n "$last_robj"; then
+               eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
+             fi
+           fi
+
+           test -n "$save_libobjs" &&
+             func_verbose "creating a temporary reloadable object file: $output"
+
+           # Loop through the commands generated above and execute them.
+           save_ifs="$IFS"; IFS='~'
+           for cmd in $concat_cmds; do
+             IFS="$save_ifs"
+             $opt_silent || {
+                 func_quote_for_expand "$cmd"
+                 eval "func_echo $func_quote_for_expand_result"
+             }
+             $opt_dry_run || eval "$cmd" || {
+               lt_exit=$?
+
+               # Restore the uninstalled library and exit
+               if test "$mode" = relink; then
+                 ( cd "$output_objdir" && \
+                   $RM "${realname}T" && \
+                   $MV "${realname}U" "$realname" )
+               fi
+
+               exit $lt_exit
+             }
+           done
+           IFS="$save_ifs"
+
+           if test -n "$export_symbols_regex" && ${skipped_export-false}; then
+             func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
+             func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
+           fi
+         fi
+
+          if ${skipped_export-false}; then
+           if test -n "$export_symbols" && test -n "$include_expsyms"; then
+             tmp_export_symbols="$export_symbols"
+             test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols"
+             $opt_dry_run || eval '$ECHO "X$include_expsyms" | $Xsed | $SP2NL >> "$tmp_export_symbols"'
+           fi
+
+           if test -n "$orig_export_symbols"; then
+             # The given exports_symbols file has to be filtered, so filter it.
+             func_verbose "filter symbol list for \`$libname.la' to tag DATA exports"
+             # FIXME: $output_objdir/$libname.filter potentially contains lots of
+             # 's' commands which not all seds can handle. GNU sed should be fine
+             # though. Also, the filter scales superlinearly with the number of
+             # global variables. join(1) would be nice here, but unfortunately
+             # isn't a blessed tool.
+             $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
+             delfiles="$delfiles $export_symbols $output_objdir/$libname.filter"
+             export_symbols=$output_objdir/$libname.def
+             $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
+           fi
+         fi
+
+         libobjs=$output
+         # Restore the value of output.
+         output=$save_output
+
+         if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
+           eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
+           test "X$libobjs" = "X " && libobjs=
+         fi
+         # Expand the library linking commands again to reset the
+         # value of $libobjs for piecewise linking.
+
+         # Do each of the archive commands.
+         if test "$module" = yes && test -n "$module_cmds" ; then
+           if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
+             cmds=$module_expsym_cmds
+           else
+             cmds=$module_cmds
+           fi
+         else
+           if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
+             cmds=$archive_expsym_cmds
+           else
+             cmds=$archive_cmds
+           fi
+         fi
+       fi
+
+       if test -n "$delfiles"; then
+         # Append the command to remove temporary files to $cmds.
+         eval cmds=\"\$cmds~\$RM $delfiles\"
+       fi
+
+       # Add any objects from preloaded convenience libraries
+       if test -n "$dlprefiles"; then
+         gentop="$output_objdir/${outputname}x"
+         generated="$generated $gentop"
+
+         func_extract_archives $gentop $dlprefiles
+         libobjs="$libobjs $func_extract_archives_result"
+         test "X$libobjs" = "X " && libobjs=
+       fi
+
+       save_ifs="$IFS"; IFS='~'
+       for cmd in $cmds; do
+         IFS="$save_ifs"
+         eval cmd=\"$cmd\"
+         $opt_silent || {
+           func_quote_for_expand "$cmd"
+           eval "func_echo $func_quote_for_expand_result"
+         }
+         $opt_dry_run || eval "$cmd" || {
+           lt_exit=$?
+
+           # Restore the uninstalled library and exit
+           if test "$mode" = relink; then
+             ( cd "$output_objdir" && \
+               $RM "${realname}T" && \
+               $MV "${realname}U" "$realname" )
+           fi
+
+           exit $lt_exit
+         }
+       done
+       IFS="$save_ifs"
+
+       # Restore the uninstalled library and exit
+       if test "$mode" = relink; then
+         $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
+
+         if test -n "$convenience"; then
+           if test -z "$whole_archive_flag_spec"; then
+             func_show_eval '${RM}r "$gentop"'
+           fi
+         fi
+
+         exit $EXIT_SUCCESS
+       fi
+
+       # Create links to the real library.
+       for linkname in $linknames; do
+         if test "$realname" != "$linkname"; then
+           func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
+         fi
+       done
+
+       # If -module or -export-dynamic was specified, set the dlname.
+       if test "$module" = yes || test "$export_dynamic" = yes; then
+         # On all known operating systems, these are identical.
+         dlname="$soname"
+       fi
+      fi
+      ;;
+
+    obj)
+      if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
+       func_warning "\`-dlopen' is ignored for objects"
+      fi
+
+      case " $deplibs" in
+      *\ -l* | *\ -L*)
+       func_warning "\`-l' and \`-L' are ignored for objects" ;;
+      esac
+
+      test -n "$rpath" && \
+       func_warning "\`-rpath' is ignored for objects"
+
+      test -n "$xrpath" && \
+       func_warning "\`-R' is ignored for objects"
+
+      test -n "$vinfo" && \
+       func_warning "\`-version-info' is ignored for objects"
+
+      test -n "$release" && \
+       func_warning "\`-release' is ignored for objects"
+
+      case $output in
+      *.lo)
+       test -n "$objs$old_deplibs" && \
+         func_fatal_error "cannot build library object \`$output' from non-libtool objects"
+
+       libobj=$output
+       func_lo2o "$libobj"
+       obj=$func_lo2o_result
+       ;;
+      *)
+       libobj=
+       obj="$output"
+       ;;
+      esac
+
+      # Delete the old objects.
+      $opt_dry_run || $RM $obj $libobj
+
+      # Objects from convenience libraries.  This assumes
+      # single-version convenience libraries.  Whenever we create
+      # different ones for PIC/non-PIC, this we'll have to duplicate
+      # the extraction.
+      reload_conv_objs=
+      gentop=
+      # reload_cmds runs $LD directly, so let us get rid of
+      # -Wl from whole_archive_flag_spec and hope we can get by with
+      # turning comma into space..
+      wl=
+
+      if test -n "$convenience"; then
+       if test -n "$whole_archive_flag_spec"; then
+         eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
+         reload_conv_objs=$reload_objs\ `$ECHO "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'`
+       else
+         gentop="$output_objdir/${obj}x"
+         generated="$generated $gentop"
+
+         func_extract_archives $gentop $convenience
+         reload_conv_objs="$reload_objs $func_extract_archives_result"
+       fi
+      fi
+
+      # Create the old-style object.
+      reload_objs="$objs$old_deplibs "`$ECHO "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test
+
+      output="$obj"
+      func_execute_cmds "$reload_cmds" 'exit $?'
+
+      # Exit if we aren't doing a library object file.
+      if test -z "$libobj"; then
+       if test -n "$gentop"; then
+         func_show_eval '${RM}r "$gentop"'
+       fi
+
+       exit $EXIT_SUCCESS
+      fi
+
+      if test "$build_libtool_libs" != yes; then
+       if test -n "$gentop"; then
+         func_show_eval '${RM}r "$gentop"'
+       fi
+
+       # Create an invalid libtool object if no PIC, so that we don't
+       # accidentally link it into a program.
+       # $show "echo timestamp > $libobj"
+       # $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
+       exit $EXIT_SUCCESS
+      fi
+
+      if test -n "$pic_flag" || test "$pic_mode" != default; then
+       # Only do commands if we really have different PIC objects.
+       reload_objs="$libobjs $reload_conv_objs"
+       output="$libobj"
+       func_execute_cmds "$reload_cmds" 'exit $?'
+      fi
+
+      if test -n "$gentop"; then
+       func_show_eval '${RM}r "$gentop"'
+      fi
+
+      exit $EXIT_SUCCESS
+      ;;
+
+    prog)
+      case $host in
+       *cygwin*) func_stripname '' '.exe' "$output"
+                 output=$func_stripname_result.exe;;
+      esac
+      test -n "$vinfo" && \
+       func_warning "\`-version-info' is ignored for programs"
+
+      test -n "$release" && \
+       func_warning "\`-release' is ignored for programs"
+
+      test "$preload" = yes \
+        && test "$dlopen_support" = unknown \
+       && test "$dlopen_self" = unknown \
+       && test "$dlopen_self_static" = unknown && \
+         func_warning "\`LT_INIT([dlopen])' not used. Assuming no dlopen support."
+
+      case $host in
+      *-*-rhapsody* | *-*-darwin1.[012])
+       # On Rhapsody replace the C library is the System framework
+       compile_deplibs=`$ECHO "X $compile_deplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
+       finalize_deplibs=`$ECHO "X $finalize_deplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
+       ;;
+      esac
+
+      case $host in
+      *-*-darwin*)
+       # Don't allow lazy linking, it breaks C++ global constructors
+       # But is supposedly fixed on 10.4 or later (yay!).
+       if test "$tagname" = CXX ; then
+         case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
+           10.[0123])
+             compile_command="$compile_command ${wl}-bind_at_load"
+             finalize_command="$finalize_command ${wl}-bind_at_load"
+           ;;
+         esac
+       fi
+       # Time to change all our "foo.ltframework" stuff back to "-framework foo"
+       compile_deplibs=`$ECHO "X $compile_deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+       finalize_deplibs=`$ECHO "X $finalize_deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+       ;;
+      esac
+
+
+      # move library search paths that coincide with paths to not yet
+      # installed libraries to the beginning of the library search list
+      new_libs=
+      for path in $notinst_path; do
+       case " $new_libs " in
+       *" -L$path/$objdir "*) ;;
+       *)
+         case " $compile_deplibs " in
+         *" -L$path/$objdir "*)
+           new_libs="$new_libs -L$path/$objdir" ;;
+         esac
+         ;;
+       esac
+      done
+      for deplib in $compile_deplibs; do
+       case $deplib in
+       -L*)
+         case " $new_libs " in
+         *" $deplib "*) ;;
+         *) new_libs="$new_libs $deplib" ;;
+         esac
+         ;;
+       *) new_libs="$new_libs $deplib" ;;
+       esac
+      done
+      compile_deplibs="$new_libs"
+
+
+      compile_command="$compile_command $compile_deplibs"
+      finalize_command="$finalize_command $finalize_deplibs"
+
+      if test -n "$rpath$xrpath"; then
+       # If the user specified any rpath flags, then add them.
+       for libdir in $rpath $xrpath; do
+         # This is the magic to use -rpath.
+         case "$finalize_rpath " in
+         *" $libdir "*) ;;
+         *) finalize_rpath="$finalize_rpath $libdir" ;;
+         esac
+       done
+      fi
+
+      # Now hardcode the library paths
+      rpath=
+      hardcode_libdirs=
+      for libdir in $compile_rpath $finalize_rpath; do
+       if test -n "$hardcode_libdir_flag_spec"; then
+         if test -n "$hardcode_libdir_separator"; then
+           if test -z "$hardcode_libdirs"; then
+             hardcode_libdirs="$libdir"
+           else
+             # Just accumulate the unique libdirs.
+             case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+             *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+               ;;
+             *)
+               hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
+               ;;
+             esac
+           fi
+         else
+           eval flag=\"$hardcode_libdir_flag_spec\"
+           rpath="$rpath $flag"
+         fi
+       elif test -n "$runpath_var"; then
+         case "$perm_rpath " in
+         *" $libdir "*) ;;
+         *) perm_rpath="$perm_rpath $libdir" ;;
+         esac
+       fi
+       case $host in
+       *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+         testbindir=`${ECHO} "$libdir" | ${SED} -e 's*/lib$*/bin*'`
+         case :$dllsearchpath: in
+         *":$libdir:"*) ;;
+         ::) dllsearchpath=$libdir;;
+         *) dllsearchpath="$dllsearchpath:$libdir";;
+         esac
+         case :$dllsearchpath: in
+         *":$testbindir:"*) ;;
+         ::) dllsearchpath=$testbindir;;
+         *) dllsearchpath="$dllsearchpath:$testbindir";;
+         esac
+         ;;
+       esac
+      done
+      # Substitute the hardcoded libdirs into the rpath.
+      if test -n "$hardcode_libdir_separator" &&
+        test -n "$hardcode_libdirs"; then
+       libdir="$hardcode_libdirs"
+       eval rpath=\" $hardcode_libdir_flag_spec\"
+      fi
+      compile_rpath="$rpath"
+
+      rpath=
+      hardcode_libdirs=
+      for libdir in $finalize_rpath; do
+       if test -n "$hardcode_libdir_flag_spec"; then
+         if test -n "$hardcode_libdir_separator"; then
+           if test -z "$hardcode_libdirs"; then
+             hardcode_libdirs="$libdir"
+           else
+             # Just accumulate the unique libdirs.
+             case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+             *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+               ;;
+             *)
+               hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
+               ;;
+             esac
+           fi
+         else
+           eval flag=\"$hardcode_libdir_flag_spec\"
+           rpath="$rpath $flag"
+         fi
+       elif test -n "$runpath_var"; then
+         case "$finalize_perm_rpath " in
+         *" $libdir "*) ;;
+         *) finalize_perm_rpath="$finalize_perm_rpath $libdir" ;;
+         esac
+       fi
+      done
+      # Substitute the hardcoded libdirs into the rpath.
+      if test -n "$hardcode_libdir_separator" &&
+        test -n "$hardcode_libdirs"; then
+       libdir="$hardcode_libdirs"
+       eval rpath=\" $hardcode_libdir_flag_spec\"
+      fi
+      finalize_rpath="$rpath"
+
+      if test -n "$libobjs" && test "$build_old_libs" = yes; then
+       # Transform all the library objects into standard objects.
+       compile_command=`$ECHO "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+       finalize_command=`$ECHO "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+      fi
+
+      func_generate_dlsyms "$outputname" "@PROGRAM@" "no"
+
+      # template prelinking step
+      if test -n "$prelink_cmds"; then
+       func_execute_cmds "$prelink_cmds" 'exit $?'
+      fi
+
+      wrappers_required=yes
+      case $host in
+      *cygwin* | *mingw* )
+        if test "$build_libtool_libs" != yes; then
+          wrappers_required=no
+        fi
+        ;;
+      *cegcc)
+        # Disable wrappers for cegcc, we are cross compiling anyway.
+        wrappers_required=no
+        ;;
+      *)
+        if test "$need_relink" = no || test "$build_libtool_libs" != yes; then
+          wrappers_required=no
+        fi
+        ;;
+      esac
+      if test "$wrappers_required" = no; then
+       # Replace the output file specification.
+       compile_command=`$ECHO "X$compile_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
+       link_command="$compile_command$compile_rpath"
+
+       # We have no uninstalled library dependencies, so finalize right now.
+       exit_status=0
+       func_show_eval "$link_command" 'exit_status=$?'
+
+       # Delete the generated files.
+       if test -f "$output_objdir/${outputname}S.${objext}"; then
+         func_show_eval '$RM "$output_objdir/${outputname}S.${objext}"'
+       fi
+
+       exit $exit_status
+      fi
+
+      if test -n "$compile_shlibpath$finalize_shlibpath"; then
+       compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
+      fi
+      if test -n "$finalize_shlibpath"; then
+       finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
+      fi
+
+      compile_var=
+      finalize_var=
+      if test -n "$runpath_var"; then
+       if test -n "$perm_rpath"; then
+         # We should set the runpath_var.
+         rpath=
+         for dir in $perm_rpath; do
+           rpath="$rpath$dir:"
+         done
+         compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
+       fi
+       if test -n "$finalize_perm_rpath"; then
+         # We should set the runpath_var.
+         rpath=
+         for dir in $finalize_perm_rpath; do
+           rpath="$rpath$dir:"
+         done
+         finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
+       fi
+      fi
+
+      if test "$no_install" = yes; then
+       # We don't need to create a wrapper script.
+       link_command="$compile_var$compile_command$compile_rpath"
+       # Replace the output file specification.
+       link_command=`$ECHO "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
+       # Delete the old output file.
+       $opt_dry_run || $RM $output
+       # Link the executable and exit
+       func_show_eval "$link_command" 'exit $?'
+       exit $EXIT_SUCCESS
+      fi
+
+      if test "$hardcode_action" = relink; then
+       # Fast installation is not supported
+       link_command="$compile_var$compile_command$compile_rpath"
+       relink_command="$finalize_var$finalize_command$finalize_rpath"
+
+       func_warning "this platform does not like uninstalled shared libraries"
+       func_warning "\`$output' will be relinked during installation"
+      else
+       if test "$fast_install" != no; then
+         link_command="$finalize_var$compile_command$finalize_rpath"
+         if test "$fast_install" = yes; then
+           relink_command=`$ECHO "X$compile_var$compile_command$compile_rpath" | $Xsed -e 's%@OUTPUT@%\$progdir/\$file%g'`
+         else
+           # fast_install is set to needless
+           relink_command=
+         fi
+       else
+         link_command="$compile_var$compile_command$compile_rpath"
+         relink_command="$finalize_var$finalize_command$finalize_rpath"
+       fi
+      fi
+
+      # Replace the output file specification.
+      link_command=`$ECHO "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
+
+      # Delete the old output files.
+      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
+
+      func_show_eval "$link_command" 'exit $?'
+
+      # Now create the wrapper script.
+      func_verbose "creating $output"
+
+      # Quote the relink command for shipping.
+      if test -n "$relink_command"; then
+       # Preserve any variables that may affect compiler behavior
+       for var in $variables_saved_for_relink; do
+         if eval test -z \"\${$var+set}\"; then
+           relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
+         elif eval var_value=\$$var; test -z "$var_value"; then
+           relink_command="$var=; export $var; $relink_command"
+         else
+           func_quote_for_eval "$var_value"
+           relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
+         fi
+       done
+       relink_command="(cd `pwd`; $relink_command)"
+       relink_command=`$ECHO "X$relink_command" | $Xsed -e "$sed_quote_subst"`
+      fi
+
+      # Quote $ECHO for shipping.
+      if test "X$ECHO" = "X$SHELL $progpath --fallback-echo"; then
+       case $progpath in
+       [\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $progpath --fallback-echo";;
+       *) qecho="$SHELL `pwd`/$progpath --fallback-echo";;
+       esac
+       qecho=`$ECHO "X$qecho" | $Xsed -e "$sed_quote_subst"`
+      else
+       qecho=`$ECHO "X$ECHO" | $Xsed -e "$sed_quote_subst"`
+      fi
+
+      # Only actually do things if not in dry run mode.
+      $opt_dry_run || {
+       # win32 will think the script is a binary if it has
+       # a .exe suffix, so we strip it off here.
+       case $output in
+         *.exe) func_stripname '' '.exe' "$output"
+                output=$func_stripname_result ;;
+       esac
+       # test for cygwin because mv fails w/o .exe extensions
+       case $host in
+         *cygwin*)
+           exeext=.exe
+           func_stripname '' '.exe' "$outputname"
+           outputname=$func_stripname_result ;;
+         *) exeext= ;;
+       esac
+       case $host in
+         *cygwin* | *mingw* )
+           func_dirname_and_basename "$output" "" "."
+           output_name=$func_basename_result
+           output_path=$func_dirname_result
+           cwrappersource="$output_path/$objdir/lt-$output_name.c"
+           cwrapper="$output_path/$output_name.exe"
+           $RM $cwrappersource $cwrapper
+           trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
+
+           func_emit_cwrapperexe_src > $cwrappersource
+
+           # The wrapper executable is built using the $host compiler,
+           # because it contains $host paths and files. If cross-
+           # compiling, it, like the target executable, must be
+           # executed on the $host or under an emulation environment.
+           $opt_dry_run || {
+             $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
+             $STRIP $cwrapper
+           }
+
+           # Now, create the wrapper script for func_source use:
+           func_ltwrapper_scriptname $cwrapper
+           $RM $func_ltwrapper_scriptname_result
+           trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
+           $opt_dry_run || {
+             # note: this script will not be executed, so do not chmod.
+             if test "x$build" = "x$host" ; then
+               $cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
+             else
+               func_emit_wrapper no > $func_ltwrapper_scriptname_result
+             fi
+           }
+         ;;
+         * )
+           $RM $output
+           trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
+
+           func_emit_wrapper no > $output
+           chmod +x $output
+         ;;
+       esac
+      }
+      exit $EXIT_SUCCESS
+      ;;
+    esac
+
+    # See if we need to build an old-fashioned archive.
+    for oldlib in $oldlibs; do
+
+      if test "$build_libtool_libs" = convenience; then
+       oldobjs="$libobjs_save $symfileobj"
+       addlibs="$convenience"
+       build_libtool_libs=no
+      else
+       if test "$build_libtool_libs" = module; then
+         oldobjs="$libobjs_save"
+         build_libtool_libs=no
+       else
+         oldobjs="$old_deplibs $non_pic_objects"
+         if test "$preload" = yes && test -f "$symfileobj"; then
+           oldobjs="$oldobjs $symfileobj"
+         fi
+       fi
+       addlibs="$old_convenience"
+      fi
+
+      if test -n "$addlibs"; then
+       gentop="$output_objdir/${outputname}x"
+       generated="$generated $gentop"
+
+       func_extract_archives $gentop $addlibs
+       oldobjs="$oldobjs $func_extract_archives_result"
+      fi
+
+      # Do each command in the archive commands.
+      if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then
+       cmds=$old_archive_from_new_cmds
+      else
+
+       # Add any objects from preloaded convenience libraries
+       if test -n "$dlprefiles"; then
+         gentop="$output_objdir/${outputname}x"
+         generated="$generated $gentop"
+
+         func_extract_archives $gentop $dlprefiles
+         oldobjs="$oldobjs $func_extract_archives_result"
+       fi
+
+       # POSIX demands no paths to be encoded in archives.  We have
+       # to avoid creating archives with duplicate basenames if we
+       # might have to extract them afterwards, e.g., when creating a
+       # static archive out of a convenience library, or when linking
+       # the entirety of a libtool archive into another (currently
+       # not supported by libtool).
+       if (for obj in $oldobjs
+           do
+             func_basename "$obj"
+             $ECHO "$func_basename_result"
+           done | sort | sort -uc >/dev/null 2>&1); then
+         :
+       else
+         $ECHO "copying selected object files to avoid basename conflicts..."
+         gentop="$output_objdir/${outputname}x"
+         generated="$generated $gentop"
+         func_mkdir_p "$gentop"
+         save_oldobjs=$oldobjs
+         oldobjs=
+         counter=1
+         for obj in $save_oldobjs
+         do
+           func_basename "$obj"
+           objbase="$func_basename_result"
+           case " $oldobjs " in
+           " ") oldobjs=$obj ;;
+           *[\ /]"$objbase "*)
+             while :; do
+               # Make sure we don't pick an alternate name that also
+               # overlaps.
+               newobj=lt$counter-$objbase
+               func_arith $counter + 1
+               counter=$func_arith_result
+               case " $oldobjs " in
+               *[\ /]"$newobj "*) ;;
+               *) if test ! -f "$gentop/$newobj"; then break; fi ;;
+               esac
+             done
+             func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
+             oldobjs="$oldobjs $gentop/$newobj"
+             ;;
+           *) oldobjs="$oldobjs $obj" ;;
+           esac
+         done
+       fi
+       eval cmds=\"$old_archive_cmds\"
+
+       func_len " $cmds"
+       len=$func_len_result
+       if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+         cmds=$old_archive_cmds
+       else
+         # the command line is too long to link in one step, link in parts
+         func_verbose "using piecewise archive linking..."
+         save_RANLIB=$RANLIB
+         RANLIB=:
+         objlist=
+         concat_cmds=
+         save_oldobjs=$oldobjs
+         oldobjs=
+         # Is there a better way of finding the last object in the list?
+         for obj in $save_oldobjs
+         do
+           last_oldobj=$obj
+         done
+         eval test_cmds=\"$old_archive_cmds\"
+         func_len " $test_cmds"
+         len0=$func_len_result
+         len=$len0
+         for obj in $save_oldobjs
+         do
+           func_len " $obj"
+           func_arith $len + $func_len_result
+           len=$func_arith_result
+           func_append objlist " $obj"
+           if test "$len" -lt "$max_cmd_len"; then
+             :
+           else
+             # the above command should be used before it gets too long
+             oldobjs=$objlist
+             if test "$obj" = "$last_oldobj" ; then
+               RANLIB=$save_RANLIB
+             fi
+             test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+             eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\"
+             objlist=
+             len=$len0
+           fi
+         done
+         RANLIB=$save_RANLIB
+         oldobjs=$objlist
+         if test "X$oldobjs" = "X" ; then
+           eval cmds=\"\$concat_cmds\"
+         else
+           eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
+         fi
+       fi
+      fi
+      func_execute_cmds "$cmds" 'exit $?'
+    done
+
+    test -n "$generated" && \
+      func_show_eval "${RM}r$generated"
+
+    # Now create the libtool archive.
+    case $output in
+    *.la)
+      old_library=
+      test "$build_old_libs" = yes && old_library="$libname.$libext"
+      func_verbose "creating $output"
+
+      # Preserve any variables that may affect compiler behavior
+      for var in $variables_saved_for_relink; do
+       if eval test -z \"\${$var+set}\"; then
+         relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
+       elif eval var_value=\$$var; test -z "$var_value"; then
+         relink_command="$var=; export $var; $relink_command"
+       else
+         func_quote_for_eval "$var_value"
+         relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
+       fi
+      done
+      # Quote the link command for shipping.
+      relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
+      relink_command=`$ECHO "X$relink_command" | $Xsed -e "$sed_quote_subst"`
+      if test "$hardcode_automatic" = yes ; then
+       relink_command=
+      fi
+
+      # Only create the output if not a dry run.
+      $opt_dry_run || {
+       for installed in no yes; do
+         if test "$installed" = yes; then
+           if test -z "$install_libdir"; then
+             break
+           fi
+           output="$output_objdir/$outputname"i
+           # Replace all uninstalled libtool libraries with the installed ones
+           newdependency_libs=
+           for deplib in $dependency_libs; do
+             case $deplib in
+             *.la)
+               func_basename "$deplib"
+               name="$func_basename_result"
+               eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
+               test -z "$libdir" && \
+                 func_fatal_error "\`$deplib' is not a valid libtool archive"
+               newdependency_libs="$newdependency_libs $libdir/$name"
+               ;;
+             *) newdependency_libs="$newdependency_libs $deplib" ;;
+             esac
+           done
+           dependency_libs="$newdependency_libs"
+           newdlfiles=
+
+           for lib in $dlfiles; do
+             case $lib in
+             *.la)
+               func_basename "$lib"
+               name="$func_basename_result"
+               eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
+               test -z "$libdir" && \
+                 func_fatal_error "\`$lib' is not a valid libtool archive"
+               newdlfiles="$newdlfiles $libdir/$name"
+               ;;
+             *) newdlfiles="$newdlfiles $lib" ;;
+             esac
+           done
+           dlfiles="$newdlfiles"
+           newdlprefiles=
+           for lib in $dlprefiles; do
+             case $lib in
+             *.la)
+               # Only pass preopened files to the pseudo-archive (for
+               # eventual linking with the app. that links it) if we
+               # didn't already link the preopened objects directly into
+               # the library:
+               func_basename "$lib"
+               name="$func_basename_result"
+               eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
+               test -z "$libdir" && \
+                 func_fatal_error "\`$lib' is not a valid libtool archive"
+               newdlprefiles="$newdlprefiles $libdir/$name"
+               ;;
+             esac
+           done
+           dlprefiles="$newdlprefiles"
+         else
+           newdlfiles=
+           for lib in $dlfiles; do
+             case $lib in
+               [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
+               *) abs=`pwd`"/$lib" ;;
+             esac
+             newdlfiles="$newdlfiles $abs"
+           done
+           dlfiles="$newdlfiles"
+           newdlprefiles=
+           for lib in $dlprefiles; do
+             case $lib in
+               [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
+               *) abs=`pwd`"/$lib" ;;
+             esac
+             newdlprefiles="$newdlprefiles $abs"
+           done
+           dlprefiles="$newdlprefiles"
+         fi
+         $RM $output
+         # place dlname in correct position for cygwin
+         tdlname=$dlname
+         case $host,$output,$installed,$module,$dlname in
+           *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;;
+         esac
+         $ECHO > $output "\
+# $outputname - a libtool library file
+# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# The name that we can dlopen(3).
+dlname='$tdlname'
+
+# Names of this library.
+library_names='$library_names'
+
+# The name of the static archive.
+old_library='$old_library'
+
+# Linker flags that can not go in dependency_libs.
+inherited_linker_flags='$new_inherited_linker_flags'
+
+# Libraries that this one depends upon.
+dependency_libs='$dependency_libs'
+
+# Names of additional weak libraries provided by this library
+weak_library_names='$weak_libs'
+
+# Version information for $libname.
+current=$current
+age=$age
+revision=$revision
+
+# Is this an already installed library?
+installed=$installed
+
+# Should we warn about portability when linking against -modules?
+shouldnotlink=$module
+
+# Files to dlopen/dlpreopen
+dlopen='$dlfiles'
+dlpreopen='$dlprefiles'
+
+# Directory that this library needs to be installed in:
+libdir='$install_libdir'"
+         if test "$installed" = no && test "$need_relink" = yes; then
+           $ECHO >> $output "\
+relink_command=\"$relink_command\""
+         fi
+       done
+      }
+
+      # Do a symbolic link so that the libtool archive can be found in
+      # LD_LIBRARY_PATH before the program is installed.
+      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
+      ;;
+    esac
+    exit $EXIT_SUCCESS
+}
+
+{ test "$mode" = link || test "$mode" = relink; } &&
+    func_mode_link ${1+"$@"}
+
+
+# func_mode_uninstall arg...
+func_mode_uninstall ()
+{
+    $opt_debug
+    RM="$nonopt"
+    files=
+    rmforce=
+    exit_status=0
+
+    # This variable tells wrapper scripts just to set variables rather
+    # than running their programs.
+    libtool_install_magic="$magic"
+
+    for arg
+    do
+      case $arg in
+      -f) RM="$RM $arg"; rmforce=yes ;;
+      -*) RM="$RM $arg" ;;
+      *) files="$files $arg" ;;
+      esac
+    done
+
+    test -z "$RM" && \
+      func_fatal_help "you must specify an RM program"
+
+    rmdirs=
+
+    origobjdir="$objdir"
+    for file in $files; do
+      func_dirname "$file" "" "."
+      dir="$func_dirname_result"
+      if test "X$dir" = X.; then
+       objdir="$origobjdir"
+      else
+       objdir="$dir/$origobjdir"
+      fi
+      func_basename "$file"
+      name="$func_basename_result"
+      test "$mode" = uninstall && objdir="$dir"
+
+      # Remember objdir for removal later, being careful to avoid duplicates
+      if test "$mode" = clean; then
+       case " $rmdirs " in
+         *" $objdir "*) ;;
+         *) rmdirs="$rmdirs $objdir" ;;
+       esac
+      fi
+
+      # Don't error if the file doesn't exist and rm -f was used.
+      if { test -L "$file"; } >/dev/null 2>&1 ||
+        { test -h "$file"; } >/dev/null 2>&1 ||
+        test -f "$file"; then
+       :
+      elif test -d "$file"; then
+       exit_status=1
+       continue
+      elif test "$rmforce" = yes; then
+       continue
+      fi
+
+      rmfiles="$file"
+
+      case $name in
+      *.la)
+       # Possibly a libtool archive, so verify it.
+       if func_lalib_p "$file"; then
+         func_source $dir/$name
+
+         # Delete the libtool libraries and symlinks.
+         for n in $library_names; do
+           rmfiles="$rmfiles $objdir/$n"
+         done
+         test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library"
+
+         case "$mode" in
+         clean)
+           case "  $library_names " in
+           # "  " in the beginning catches empty $dlname
+           *" $dlname "*) ;;
+           *) rmfiles="$rmfiles $objdir/$dlname" ;;
+           esac
+           test -n "$libdir" && rmfiles="$rmfiles $objdir/$name $objdir/${name}i"
+           ;;
+         uninstall)
+           if test -n "$library_names"; then
+             # Do each command in the postuninstall commands.
+             func_execute_cmds "$postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1'
+           fi
+
+           if test -n "$old_library"; then
+             # Do each command in the old_postuninstall commands.
+             func_execute_cmds "$old_postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1'
+           fi
+           # FIXME: should reinstall the best remaining shared library.
+           ;;
+         esac
+       fi
+       ;;
+
+      *.lo)
+       # Possibly a libtool object, so verify it.
+       if func_lalib_p "$file"; then
+
+         # Read the .lo file
+         func_source $dir/$name
+
+         # Add PIC object to the list of files to remove.
+         if test -n "$pic_object" &&
+            test "$pic_object" != none; then
+           rmfiles="$rmfiles $dir/$pic_object"
+         fi
+
+         # Add non-PIC object to the list of files to remove.
+         if test -n "$non_pic_object" &&
+            test "$non_pic_object" != none; then
+           rmfiles="$rmfiles $dir/$non_pic_object"
+         fi
+       fi
+       ;;
+
+      *)
+       if test "$mode" = clean ; then
+         noexename=$name
+         case $file in
+         *.exe)
+           func_stripname '' '.exe' "$file"
+           file=$func_stripname_result
+           func_stripname '' '.exe' "$name"
+           noexename=$func_stripname_result
+           # $file with .exe has already been added to rmfiles,
+           # add $file without .exe
+           rmfiles="$rmfiles $file"
+           ;;
+         esac
+         # Do a test to see if this is a libtool program.
+         if func_ltwrapper_p "$file"; then
+           if func_ltwrapper_executable_p "$file"; then
+             func_ltwrapper_scriptname "$file"
+             relink_command=
+             func_source $func_ltwrapper_scriptname_result
+             rmfiles="$rmfiles $func_ltwrapper_scriptname_result"
+           else
+             relink_command=
+             func_source $dir/$noexename
+           fi
+
+           # note $name still contains .exe if it was in $file originally
+           # as does the version of $file that was added into $rmfiles
+           rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}"
+           if test "$fast_install" = yes && test -n "$relink_command"; then
+             rmfiles="$rmfiles $objdir/lt-$name"
+           fi
+           if test "X$noexename" != "X$name" ; then
+             rmfiles="$rmfiles $objdir/lt-${noexename}.c"
+           fi
+         fi
+       fi
+       ;;
+      esac
+      func_show_eval "$RM $rmfiles" 'exit_status=1'
+    done
+    objdir="$origobjdir"
+
+    # Try to remove the ${objdir}s in the directories where we deleted files
+    for dir in $rmdirs; do
+      if test -d "$dir"; then
+       func_show_eval "rmdir $dir >/dev/null 2>&1"
+      fi
+    done
+
+    exit $exit_status
+}
+
+{ test "$mode" = uninstall || test "$mode" = clean; } &&
+    func_mode_uninstall ${1+"$@"}
+
+test -z "$mode" && {
+  help="$generic_help"
+  func_fatal_help "you must specify a MODE"
+}
+
+test -z "$exec_cmd" && \
+  func_fatal_help "invalid operation mode \`$mode'"
+
+if test -n "$exec_cmd"; then
+  eval exec "$exec_cmd"
+  exit $EXIT_FAILURE
+fi
+
+exit $exit_status
+
+
+# The TAGs below are defined such that we never get into a situation
+# in which we disable both kinds of libraries.  Given conflicting
+# choices, we go for a static library, that is the most portable,
+# since we can't tell whether shared libraries were disabled because
+# the user asked for that or because the platform doesn't support
+# them.  This is particularly important on AIX, because we don't
+# support having both static and shared libraries enabled at the same
+# time on that platform, so we default to a shared-only configuration.
+# If a disable-shared tag is given, we'll fallback to a static-only
+# configuration.  But we'll never go from static-only to shared-only.
+
+# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
+build_libtool_libs=no
+build_old_libs=yes
+# ### END LIBTOOL TAG CONFIG: disable-shared
+
+# ### BEGIN LIBTOOL TAG CONFIG: disable-static
+build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
+# ### END LIBTOOL TAG CONFIG: disable-static
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation:2
+# End:
+# vi:sw=2
+
diff --git a/m17n-config.in b/m17n-config.in
new file mode 100644 (file)
index 0000000..f69517c
--- /dev/null
@@ -0,0 +1,144 @@
+#!/bin/sh
+# m17n-config -- helper script for the m17n library.   -*- coding: euc-jp; -*-
+# Copyright (C) 2003, 2004, 2006, 2007
+#   National Institute of Advanced Industrial Science and Technology (AIST)
+#   Registration Number H15PRO112
+# See the end for copying conditions.
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+
+help ()
+{
+  echo "Usage: $0 [API-LEVEL ...] [--version | --cflags | --libs | --libtool]"
+  echo "  API-LEVEL is CORE, SHELL (default), GUI, or FLT"
+}
+
+if test $# -eq 0; then
+  help 1>&2
+  exit 0
+fi
+
+while true; do
+case $1 in
+CORE) if test "x$API" = "x"; then 
+        API="CORE"; LIBTOOLNAME="m17n-core";
+      fi;
+      shift;;
+
+SHELL) if test "x$API" != "xGUI"; then
+         API="FLT"; LIBSHELL=" -lm17n"
+         if test "x$LIBFLT" = "x"; then
+           LIBTOOLNAME="m17n";
+         else
+           LIBTOOLNAME="m17n m17n-flt";
+        fi
+       fi;
+       shift;;
+
+FLT) if test "x$API" != "xGUI"; then
+       API="FLT"; LIBFLT=" -lm17n-flt"
+       if test "x$LIBSHELL" = "x"; then
+         LIBTOOLNAME="m17n-flt";
+       else
+         LIBTOOLNAME="m17n m17n-flt";
+       fi
+     fi;
+     shift;;
+
+GUI|X) API="GUI";
+       LIBSHELL=" -lm17n"; LIBFLT=" -lm17n-flt"; LIBGUI=" -lm17n-gui";
+       LIBTOOLNAME="m17n-gui";
+       shift;;
+
+*) break;;
+esac
+done
+
+LIBNAME="-lm17n-core"
+
+if test "x$API" = "x"; then
+  LIBNAME="$LIBNAME -lm17n"
+  LIBTOOLNAME="m17n"
+else
+  LIBNAME="$LIBNAME$LIBSHELL$LIBFLT$LIBGUI"
+fi
+
+case $1 in
+--version)
+  echo "@PACKAGE_VERSION@";;
+
+--libs)
+  if test "@libdir@" != "/usr/lib"; then
+    echo "-L@libdir@ ${LIBNAME}"
+  else
+    echo "${LIBNAME}"
+  fi;;
+
+--cflags)
+  if test "@includedir@" != "/usr/include"; then
+    echo "-I@includedir@"
+  fi;;
+
+--libtool)
+  for name in $LIBTOOLNAME; do
+    echo -n "@libdir@/lib${name}.la "
+  done;
+  echo;;
+*)
+    help
+    exit 1;;
+esac
+exit 0
+
+cat > /dev/null <<EOF
+/***en @page m17n-config Print compile/link options of the m17n library */
+/***ja @page m17n-config m17n ¥é¥¤¥Ö¥é¥ê¤Î¥³¥ó¥Ñ¥¤¥ë¡¦¥ê¥ó¥¯¥ª¥×¥·¥ç¥ó¤Îɽ¼¨ */
+
+/***
+@section m17n-config-synopsis SYNOPSIS
+
+m17n-config [API-LEVEL ...] [--cflags | --libs | --libtool] [--version]
+
+@section m17n-config-description DESCRIPTION
+
+The shell script m17n-config prints compile and link options for a
+program that uses the m17n library.
+
+By default, the printed options are for such a program that uses SHELL
+API of the libray.  But, if the first argument is "CORE", "GUI", or
+"FLT", the options are for a program that uses the corresponding API.
+
+The other arguments are as follows.
+
+- --cflags\n
+       Print compile option (e.g. -I/usr/local/include)
+- --libs\n
+       Print link option (e.g. -L/usr/local/lib -lm17n)
+- --libtool\n
+       Print libtool option (e.g. /usr/local/lib/libm17n.la)
+- --version\n
+       Print version number of the m17n library.
+*/ 
+EOF
+
+# Copyright (C) 2003, 2004
+#   National Institute of Advanced Industrial Science and Technology (AIST)
+#   Registration Number H15PRO112
+
+# This file is part of the m17n library.
+
+# The m17n 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.1 of
+# the License, or (at your option) any later version.
+
+# The m17n 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 the m17n library; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
diff --git a/m17n-core.pc.in b/m17n-core.pc.in
new file mode 100644 (file)
index 0000000..aafafa3
--- /dev/null
@@ -0,0 +1,12 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+moduledir=${exec_prefix}/lib/@M17N_MODULE_DIR@
+
+Name: m17n-core
+Description: Core API suport of the m17n library.
+Version: @PACKAGE_VERSION@
+Libs: -L${libdir} -lm17n-core
+Cflags: -I${includedir}
diff --git a/m17n-flt.pc.in b/m17n-flt.pc.in
new file mode 100644 (file)
index 0000000..3445554
--- /dev/null
@@ -0,0 +1,14 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+version=@PACKAGE_VERSION@
+
+moduledir=${exec_prefix}/lib/@M17N_MODULE_DIR@
+
+Name: m17n-flt
+Description: FLT API suport of the m17n library.
+Version: ${version}
+Requires: m17n-core = ${version}
+Libs: -L${libdir} -lm17n-core -lm17n-flt
+Cflags: -I${includedir}
diff --git a/m17n-gui.pc.in b/m17n-gui.pc.in
new file mode 100644 (file)
index 0000000..58ed905
--- /dev/null
@@ -0,0 +1,14 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+version=@PACKAGE_VERSION@
+
+moduledir=${exec_prefix}/lib/@M17N_MODULE_DIR@
+
+Name: m17n-gui
+Description: GUI API suport of the m17n library.
+Version: ${version}
+Requires: m17n-core = ${version}, m17n-shell = ${version}
+Libs: -L${libdir} -lm17n-core -lm17n -lm17n-gui
+Cflags: -I${includedir}
diff --git a/m17n-shell.pc.in b/m17n-shell.pc.in
new file mode 100644 (file)
index 0000000..7a73a3e
--- /dev/null
@@ -0,0 +1,14 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+version=@PACKAGE_VERSION@
+
+moduledir=${exec_prefix}/lib/@M17N_MODULE_DIR@
+
+Name: m17n-shell
+Description: Shell API support of the m17n library.
+Version: ${version}
+Requires: m17n-core = ${version}
+Libs: -L${libdir} -lm17n-core -lm17n
+Cflags: -I${includedir}
diff --git a/m4/ChangeLog b/m4/ChangeLog
new file mode 100644 (file)
index 0000000..a3afd48
--- /dev/null
@@ -0,0 +1,32 @@
+2006-09-21  gettextize  <bug-gnu-gettext@gnu.org>
+
+       * codeset.m4: New file, from gettext-0.14.4.
+       * gettext.m4: New file, from gettext-0.14.4.
+       * glibc2.m4: New file, from gettext-0.14.4.
+       * glibc21.m4: New file, from gettext-0.14.4.
+       * iconv.m4: New file, from gettext-0.14.4.
+       * intdiv0.m4: New file, from gettext-0.14.4.
+       * intmax.m4: New file, from gettext-0.14.4.
+       * inttypes.m4: New file, from gettext-0.14.4.
+       * inttypes_h.m4: New file, from gettext-0.14.4.
+       * inttypes-pri.m4: New file, from gettext-0.14.4.
+       * isc-posix.m4: New file, from gettext-0.14.4.
+       * lcmessage.m4: New file, from gettext-0.14.4.
+       * lib-ld.m4: New file, from gettext-0.14.4.
+       * lib-link.m4: New file, from gettext-0.14.4.
+       * lib-prefix.m4: New file, from gettext-0.14.4.
+       * longdouble.m4: New file, from gettext-0.14.4.
+       * longlong.m4: New file, from gettext-0.14.4.
+       * nls.m4: New file, from gettext-0.14.4.
+       * po.m4: New file, from gettext-0.14.4.
+       * printf-posix.m4: New file, from gettext-0.14.4.
+       * progtest.m4: New file, from gettext-0.14.4.
+       * signed.m4: New file, from gettext-0.14.4.
+       * size_max.m4: New file, from gettext-0.14.4.
+       * stdint_h.m4: New file, from gettext-0.14.4.
+       * uintmax_t.m4: New file, from gettext-0.14.4.
+       * ulonglong.m4: New file, from gettext-0.14.4.
+       * wchar_t.m4: New file, from gettext-0.14.4.
+       * wint_t.m4: New file, from gettext-0.14.4.
+       * xsize.m4: New file, from gettext-0.14.4.
+
diff --git a/m4/codeset.m4 b/m4/codeset.m4
new file mode 100644 (file)
index 0000000..a6e67ec
--- /dev/null
@@ -0,0 +1,21 @@
+# codeset.m4 serial AM1 (gettext-0.10.40)
+dnl Copyright (C) 2000-2002 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+AC_DEFUN([AM_LANGINFO_CODESET],
+[
+  AC_CACHE_CHECK([for nl_langinfo and CODESET], am_cv_langinfo_codeset,
+    [AC_TRY_LINK([#include <langinfo.h>],
+      [char* cs = nl_langinfo(CODESET);],
+      am_cv_langinfo_codeset=yes,
+      am_cv_langinfo_codeset=no)
+    ])
+  if test $am_cv_langinfo_codeset = yes; then
+    AC_DEFINE(HAVE_LANGINFO_CODESET, 1,
+      [Define if you have <langinfo.h> and nl_langinfo(CODESET).])
+  fi
+])
diff --git a/m4/gettext.m4 b/m4/gettext.m4
new file mode 100644 (file)
index 0000000..624a807
--- /dev/null
@@ -0,0 +1,549 @@
+# gettext.m4 serial 37 (gettext-0.14.4)
+dnl Copyright (C) 1995-2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+dnl
+dnl This file can can be used in projects which are not available under
+dnl the GNU General Public License or the GNU Library General Public
+dnl License but which still want to provide support for the GNU gettext
+dnl functionality.
+dnl Please note that the actual code of the GNU gettext library is covered
+dnl by the GNU Library General Public License, and the rest of the GNU
+dnl gettext package package is covered by the GNU General Public License.
+dnl They are *not* in the public domain.
+
+dnl Authors:
+dnl   Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
+dnl   Bruno Haible <haible@clisp.cons.org>, 2000-2003.
+
+dnl Macro to add for using GNU gettext.
+
+dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]).
+dnl INTLSYMBOL can be one of 'external', 'no-libtool', 'use-libtool'. The
+dnl    default (if it is not specified or empty) is 'no-libtool'.
+dnl    INTLSYMBOL should be 'external' for packages with no intl directory,
+dnl    and 'no-libtool' or 'use-libtool' for packages with an intl directory.
+dnl    If INTLSYMBOL is 'use-libtool', then a libtool library
+dnl    $(top_builddir)/intl/libintl.la will be created (shared and/or static,
+dnl    depending on --{enable,disable}-{shared,static} and on the presence of
+dnl    AM-DISABLE-SHARED). If INTLSYMBOL is 'no-libtool', a static library
+dnl    $(top_builddir)/intl/libintl.a will be created.
+dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
+dnl    implementations (in libc or libintl) without the ngettext() function
+dnl    will be ignored.  If NEEDSYMBOL is specified and is
+dnl    'need-formatstring-macros', then GNU gettext implementations that don't
+dnl    support the ISO C 99 <inttypes.h> formatstring macros will be ignored.
+dnl INTLDIR is used to find the intl libraries.  If empty,
+dnl    the value `$(top_builddir)/intl/' is used.
+dnl
+dnl The result of the configuration is one of three cases:
+dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled
+dnl    and used.
+dnl    Catalog format: GNU --> install in $(datadir)
+dnl    Catalog extension: .mo after installation, .gmo in source tree
+dnl 2) GNU gettext has been found in the system's C library.
+dnl    Catalog format: GNU --> install in $(datadir)
+dnl    Catalog extension: .mo after installation, .gmo in source tree
+dnl 3) No internationalization, always use English msgid.
+dnl    Catalog format: none
+dnl    Catalog extension: none
+dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur.
+dnl The use of .gmo is historical (it was needed to avoid overwriting the
+dnl GNU format catalogs when building on a platform with an X/Open gettext),
+dnl but we keep it in order not to force irrelevant filename changes on the
+dnl maintainers.
+dnl
+AC_DEFUN([AM_GNU_GETTEXT],
+[
+  dnl Argument checking.
+  ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], ,
+    [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT
+])])])])])
+  ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], ,
+    [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
+])])])])
+  define([gt_included_intl], ifelse([$1], [external], [no], [yes]))
+  define([gt_libtool_suffix_prefix], ifelse([$1], [use-libtool], [l], []))
+
+  AC_REQUIRE([AM_PO_SUBDIRS])dnl
+  ifelse(gt_included_intl, yes, [
+    AC_REQUIRE([AM_INTL_SUBDIR])dnl
+  ])
+
+  dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
+  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+  AC_REQUIRE([AC_LIB_RPATH])
+
+  dnl Sometimes libintl requires libiconv, so first search for libiconv.
+  dnl Ideally we would do this search only after the
+  dnl      if test "$USE_NLS" = "yes"; then
+  dnl        if test "$gt_cv_func_gnugettext_libc" != "yes"; then
+  dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT
+  dnl the configure script would need to contain the same shell code
+  dnl again, outside any 'if'. There are two solutions:
+  dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'.
+  dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE.
+  dnl Since AC_PROVIDE_IFELSE is only in autoconf >= 2.52 and not
+  dnl documented, we avoid it.
+  ifelse(gt_included_intl, yes, , [
+    AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
+  ])
+
+  dnl Sometimes, on MacOS X, libintl requires linking with CoreFoundation.
+  gt_INTL_MACOSX
+
+  dnl Set USE_NLS.
+  AM_NLS
+
+  ifelse(gt_included_intl, yes, [
+    BUILD_INCLUDED_LIBINTL=no
+    USE_INCLUDED_LIBINTL=no
+  ])
+  LIBINTL=
+  LTLIBINTL=
+  POSUB=
+
+  dnl If we use NLS figure out what method
+  if test "$USE_NLS" = "yes"; then
+    gt_use_preinstalled_gnugettext=no
+    ifelse(gt_included_intl, yes, [
+      AC_MSG_CHECKING([whether included gettext is requested])
+      AC_ARG_WITH(included-gettext,
+        [  --with-included-gettext use the GNU gettext library included here],
+        nls_cv_force_use_gnu_gettext=$withval,
+        nls_cv_force_use_gnu_gettext=no)
+      AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
+
+      nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
+      if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
+    ])
+        dnl User does not insist on using GNU NLS library.  Figure out what
+        dnl to use.  If GNU gettext is available we use this.  Else we have
+        dnl to fall back to GNU NLS library.
+
+        dnl Add a version number to the cache macros.
+        define([gt_api_version], ifelse([$2], [need-formatstring-macros], 3, ifelse([$2], [need-ngettext], 2, 1)))
+        define([gt_cv_func_gnugettext_libc], [gt_cv_func_gnugettext]gt_api_version[_libc])
+        define([gt_cv_func_gnugettext_libintl], [gt_cv_func_gnugettext]gt_api_version[_libintl])
+
+        AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc,
+         [AC_TRY_LINK([#include <libintl.h>
+]ifelse([$2], [need-formatstring-macros],
+[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
+#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
+#endif
+changequote(,)dnl
+typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
+changequote([,])dnl
+], [])[extern int _nl_msg_cat_cntr;
+extern int *_nl_domain_bindings;],
+            [bindtextdomain ("", "");
+return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_domain_bindings],
+            gt_cv_func_gnugettext_libc=yes,
+            gt_cv_func_gnugettext_libc=no)])
+
+        if test "$gt_cv_func_gnugettext_libc" != "yes"; then
+          dnl Sometimes libintl requires libiconv, so first search for libiconv.
+          ifelse(gt_included_intl, yes, , [
+            AM_ICONV_LINK
+          ])
+          dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
+          dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv])
+          dnl because that would add "-liconv" to LIBINTL and LTLIBINTL
+          dnl even if libiconv doesn't exist.
+          AC_LIB_LINKFLAGS_BODY([intl])
+          AC_CACHE_CHECK([for GNU gettext in libintl],
+            gt_cv_func_gnugettext_libintl,
+           [gt_save_CPPFLAGS="$CPPFLAGS"
+            CPPFLAGS="$CPPFLAGS $INCINTL"
+            gt_save_LIBS="$LIBS"
+            LIBS="$LIBS $LIBINTL"
+            dnl Now see whether libintl exists and does not depend on libiconv.
+            AC_TRY_LINK([#include <libintl.h>
+]ifelse([$2], [need-formatstring-macros],
+[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
+#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
+#endif
+changequote(,)dnl
+typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
+changequote([,])dnl
+], [])[extern int _nl_msg_cat_cntr;
+extern
+#ifdef __cplusplus
+"C"
+#endif
+const char *_nl_expand_alias (const char *);],
+              [bindtextdomain ("", "");
+return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias ("")],
+              gt_cv_func_gnugettext_libintl=yes,
+              gt_cv_func_gnugettext_libintl=no)
+            dnl Now see whether libintl exists and depends on libiconv.
+            if test "$gt_cv_func_gnugettext_libintl" != yes && test -n "$LIBICONV"; then
+              LIBS="$LIBS $LIBICONV"
+              AC_TRY_LINK([#include <libintl.h>
+]ifelse([$2], [need-formatstring-macros],
+[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
+#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
+#endif
+changequote(,)dnl
+typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
+changequote([,])dnl
+], [])[extern int _nl_msg_cat_cntr;
+extern
+#ifdef __cplusplus
+"C"
+#endif
+const char *_nl_expand_alias (const char *);],
+                [bindtextdomain ("", "");
+return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias ("")],
+               [LIBINTL="$LIBINTL $LIBICONV"
+                LTLIBINTL="$LTLIBINTL $LTLIBICONV"
+                gt_cv_func_gnugettext_libintl=yes
+               ])
+            fi
+            CPPFLAGS="$gt_save_CPPFLAGS"
+            LIBS="$gt_save_LIBS"])
+        fi
+
+        dnl If an already present or preinstalled GNU gettext() is found,
+        dnl use it.  But if this macro is used in GNU gettext, and GNU
+        dnl gettext is already preinstalled in libintl, we update this
+        dnl libintl.  (Cf. the install rule in intl/Makefile.in.)
+        if test "$gt_cv_func_gnugettext_libc" = "yes" \
+           || { test "$gt_cv_func_gnugettext_libintl" = "yes" \
+                && test "$PACKAGE" != gettext-runtime \
+                && test "$PACKAGE" != gettext-tools; }; then
+          gt_use_preinstalled_gnugettext=yes
+        else
+          dnl Reset the values set by searching for libintl.
+          LIBINTL=
+          LTLIBINTL=
+          INCINTL=
+        fi
+
+    ifelse(gt_included_intl, yes, [
+        if test "$gt_use_preinstalled_gnugettext" != "yes"; then
+          dnl GNU gettext is not found in the C library.
+          dnl Fall back on included GNU gettext library.
+          nls_cv_use_gnu_gettext=yes
+        fi
+      fi
+
+      if test "$nls_cv_use_gnu_gettext" = "yes"; then
+        dnl Mark actions used to generate GNU NLS library.
+        BUILD_INCLUDED_LIBINTL=yes
+        USE_INCLUDED_LIBINTL=yes
+        LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV"
+        LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV"
+        LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
+      fi
+
+      CATOBJEXT=
+      if test "$gt_use_preinstalled_gnugettext" = "yes" \
+         || test "$nls_cv_use_gnu_gettext" = "yes"; then
+        dnl Mark actions to use GNU gettext tools.
+        CATOBJEXT=.gmo
+      fi
+    ])
+
+    if test -n "$INTL_MACOSX_LIBS"; then
+      if test "$gt_use_preinstalled_gnugettext" = "yes" \
+         || test "$nls_cv_use_gnu_gettext" = "yes"; then
+        dnl Some extra flags are needed during linking.
+        LIBINTL="$LIBINTL $INTL_MACOSX_LIBS"
+        LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS"
+      fi
+    fi
+
+    if test "$gt_use_preinstalled_gnugettext" = "yes" \
+       || test "$nls_cv_use_gnu_gettext" = "yes"; then
+      AC_DEFINE(ENABLE_NLS, 1,
+        [Define to 1 if translation of program messages to the user's native language
+   is requested.])
+    else
+      USE_NLS=no
+    fi
+  fi
+
+  AC_MSG_CHECKING([whether to use NLS])
+  AC_MSG_RESULT([$USE_NLS])
+  if test "$USE_NLS" = "yes"; then
+    AC_MSG_CHECKING([where the gettext function comes from])
+    if test "$gt_use_preinstalled_gnugettext" = "yes"; then
+      if test "$gt_cv_func_gnugettext_libintl" = "yes"; then
+        gt_source="external libintl"
+      else
+        gt_source="libc"
+      fi
+    else
+      gt_source="included intl directory"
+    fi
+    AC_MSG_RESULT([$gt_source])
+  fi
+
+  if test "$USE_NLS" = "yes"; then
+
+    if test "$gt_use_preinstalled_gnugettext" = "yes"; then
+      if test "$gt_cv_func_gnugettext_libintl" = "yes"; then
+        AC_MSG_CHECKING([how to link with libintl])
+        AC_MSG_RESULT([$LIBINTL])
+        AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL])
+      fi
+
+      dnl For backward compatibility. Some packages may be using this.
+      AC_DEFINE(HAVE_GETTEXT, 1,
+       [Define if the GNU gettext() function is already present or preinstalled.])
+      AC_DEFINE(HAVE_DCGETTEXT, 1,
+       [Define if the GNU dcgettext() function is already present or preinstalled.])
+    fi
+
+    dnl We need to process the po/ directory.
+    POSUB=po
+  fi
+
+  ifelse(gt_included_intl, yes, [
+    dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL
+    dnl to 'yes' because some of the testsuite requires it.
+    if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then
+      BUILD_INCLUDED_LIBINTL=yes
+    fi
+
+    dnl Make all variables we use known to autoconf.
+    AC_SUBST(BUILD_INCLUDED_LIBINTL)
+    AC_SUBST(USE_INCLUDED_LIBINTL)
+    AC_SUBST(CATOBJEXT)
+
+    dnl For backward compatibility. Some configure.ins may be using this.
+    nls_cv_header_intl=
+    nls_cv_header_libgt=
+
+    dnl For backward compatibility. Some Makefiles may be using this.
+    DATADIRNAME=share
+    AC_SUBST(DATADIRNAME)
+
+    dnl For backward compatibility. Some Makefiles may be using this.
+    INSTOBJEXT=.mo
+    AC_SUBST(INSTOBJEXT)
+
+    dnl For backward compatibility. Some Makefiles may be using this.
+    GENCAT=gencat
+    AC_SUBST(GENCAT)
+
+    dnl For backward compatibility. Some Makefiles may be using this.
+    INTLOBJS=
+    if test "$USE_INCLUDED_LIBINTL" = yes; then
+      INTLOBJS="\$(GETTOBJS)"
+    fi
+    AC_SUBST(INTLOBJS)
+
+    dnl Enable libtool support if the surrounding package wishes it.
+    INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix
+    AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX)
+  ])
+
+  dnl For backward compatibility. Some Makefiles may be using this.
+  INTLLIBS="$LIBINTL"
+  AC_SUBST(INTLLIBS)
+
+  dnl Make all documented variables known to autoconf.
+  AC_SUBST(LIBINTL)
+  AC_SUBST(LTLIBINTL)
+  AC_SUBST(POSUB)
+])
+
+
+dnl Checks for all prerequisites of the intl subdirectory,
+dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS,
+dnl            USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL.
+AC_DEFUN([AM_INTL_SUBDIR],
+[
+  AC_REQUIRE([AC_PROG_INSTALL])dnl
+  AC_REQUIRE([AM_MKINSTALLDIRS])dnl
+  AC_REQUIRE([AC_PROG_CC])dnl
+  AC_REQUIRE([AC_CANONICAL_HOST])dnl
+  AC_REQUIRE([gt_GLIBC2])dnl
+  AC_REQUIRE([AC_PROG_RANLIB])dnl
+  AC_REQUIRE([AC_ISC_POSIX])dnl
+  AC_REQUIRE([AC_HEADER_STDC])dnl
+  AC_REQUIRE([AC_C_CONST])dnl
+  AC_REQUIRE([bh_C_SIGNED])dnl
+  AC_REQUIRE([AC_C_INLINE])dnl
+  AC_REQUIRE([AC_TYPE_OFF_T])dnl
+  AC_REQUIRE([AC_TYPE_SIZE_T])dnl
+  AC_REQUIRE([gl_AC_TYPE_LONG_LONG])dnl
+  AC_REQUIRE([gt_TYPE_LONGDOUBLE])dnl
+  AC_REQUIRE([gt_TYPE_WCHAR_T])dnl
+  AC_REQUIRE([gt_TYPE_WINT_T])dnl
+  AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
+  AC_REQUIRE([gl_AC_HEADER_STDINT_H])
+  AC_REQUIRE([gt_TYPE_INTMAX_T])
+  AC_REQUIRE([gt_PRINTF_POSIX])
+  AC_REQUIRE([AC_FUNC_ALLOCA])dnl
+  AC_REQUIRE([AC_FUNC_MMAP])dnl
+  AC_REQUIRE([gl_GLIBC21])dnl
+  AC_REQUIRE([gt_INTDIV0])dnl
+  AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])dnl
+  AC_REQUIRE([gt_HEADER_INTTYPES_H])dnl
+  AC_REQUIRE([gt_INTTYPES_PRI])dnl
+  AC_REQUIRE([gl_XSIZE])dnl
+  AC_REQUIRE([gt_INTL_MACOSX])dnl
+
+  AC_CHECK_TYPE([ptrdiff_t], ,
+    [AC_DEFINE([ptrdiff_t], [long],
+       [Define as the type of the result of subtracting two pointers, if the system doesn't define it.])
+    ])
+  AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \
+stdlib.h string.h unistd.h sys/param.h])
+  AC_CHECK_FUNCS([asprintf fwprintf getcwd getegid geteuid getgid getuid \
+mempcpy munmap putenv setenv setlocale snprintf stpcpy strcasecmp strdup \
+strtoul tsearch wcslen __argz_count __argz_stringify __argz_next \
+__fsetlocking])
+
+  dnl Use the _snprintf function only if it is declared (because on NetBSD it
+  dnl is defined as a weak alias of snprintf; we prefer to use the latter).
+  gt_CHECK_DECL(_snprintf, [#include <stdio.h>])
+  gt_CHECK_DECL(_snwprintf, [#include <stdio.h>])
+
+  dnl Use the *_unlocked functions only if they are declared.
+  dnl (because some of them were defined without being declared in Solaris
+  dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built
+  dnl on Solaris 2.5.1 to run on Solaris 2.6).
+  dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13.
+  gt_CHECK_DECL(feof_unlocked, [#include <stdio.h>])
+  gt_CHECK_DECL(fgets_unlocked, [#include <stdio.h>])
+  gt_CHECK_DECL(getc_unlocked, [#include <stdio.h>])
+
+  case $gt_cv_func_printf_posix in
+    *yes) HAVE_POSIX_PRINTF=1 ;;
+    *) HAVE_POSIX_PRINTF=0 ;;
+  esac
+  AC_SUBST([HAVE_POSIX_PRINTF])
+  if test "$ac_cv_func_asprintf" = yes; then
+    HAVE_ASPRINTF=1
+  else
+    HAVE_ASPRINTF=0
+  fi
+  AC_SUBST([HAVE_ASPRINTF])
+  if test "$ac_cv_func_snprintf" = yes; then
+    HAVE_SNPRINTF=1
+  else
+    HAVE_SNPRINTF=0
+  fi
+  AC_SUBST([HAVE_SNPRINTF])
+  if test "$ac_cv_func_wprintf" = yes; then
+    HAVE_WPRINTF=1
+  else
+    HAVE_WPRINTF=0
+  fi
+  AC_SUBST([HAVE_WPRINTF])
+
+  AM_ICONV
+  AM_LANGINFO_CODESET
+  if test $ac_cv_header_locale_h = yes; then
+    gt_LC_MESSAGES
+  fi
+
+  if test -n "$INTL_MACOSX_LIBS"; then
+    CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers"
+  fi
+
+  dnl intl/plural.c is generated from intl/plural.y. It requires bison,
+  dnl because plural.y uses bison specific features. It requires at least
+  dnl bison-1.26 because earlier versions generate a plural.c that doesn't
+  dnl compile.
+  dnl bison is only needed for the maintainer (who touches plural.y). But in
+  dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put
+  dnl the rule in general Makefile. Now, some people carelessly touch the
+  dnl files or have a broken "make" program, hence the plural.c rule will
+  dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not
+  dnl present or too old.
+  AC_CHECK_PROGS([INTLBISON], [bison])
+  if test -z "$INTLBISON"; then
+    ac_verc_fail=yes
+  else
+    dnl Found it, now check the version.
+    AC_MSG_CHECKING([version of bison])
+changequote(<<,>>)dnl
+    ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'`
+    case $ac_prog_version in
+      '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
+      1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*)
+changequote([,])dnl
+         ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
+      *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
+    esac
+    AC_MSG_RESULT([$ac_prog_version])
+  fi
+  if test $ac_verc_fail = yes; then
+    INTLBISON=:
+  fi
+])
+
+
+dnl Checks for special options needed on MacOS X.
+dnl Defines INTL_MACOSX_LIBS.
+AC_DEFUN([gt_INTL_MACOSX],
+[
+  dnl Check for API introduced in MacOS X 10.2.
+  AC_CACHE_CHECK([for CFPreferencesCopyAppValue],
+    gt_cv_func_CFPreferencesCopyAppValue,
+    [gt_save_CPPFLAGS="$CPPFLAGS"
+     CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers"
+     gt_save_LIBS="$LIBS"
+     LIBS="$LIBS -framework CoreFoundation"
+     AC_TRY_LINK([#include <CFPreferences.h>],
+       [CFPreferencesCopyAppValue(NULL, NULL)],
+       [gt_cv_func_CFPreferencesCopyAppValue=yes],
+       [gt_cv_func_CFPreferencesCopyAppValue=no])
+     CPPFLAGS="$gt_save_CPPFLAGS"
+     LIBS="$gt_save_LIBS"])
+  if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then
+    AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], 1,
+      [Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in the CoreFoundation framework.])
+  fi
+  dnl Check for API introduced in MacOS X 10.3.
+  AC_CACHE_CHECK([for CFLocaleCopyCurrent], gt_cv_func_CFLocaleCopyCurrent,
+    [gt_save_CPPFLAGS="$CPPFLAGS"
+     CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers"
+     gt_save_LIBS="$LIBS"
+     LIBS="$LIBS -framework CoreFoundation"
+     AC_TRY_LINK([#include <CFLocale.h>], [CFLocaleCopyCurrent();],
+       [gt_cv_func_CFLocaleCopyCurrent=yes],
+       [gt_cv_func_CFLocaleCopyCurrent=no])
+     CPPFLAGS="$gt_save_CPPFLAGS"
+     LIBS="$gt_save_LIBS"])
+  if test $gt_cv_func_CFLocaleCopyCurrent = yes; then
+    AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], 1,
+      [Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the CoreFoundation framework.])
+  fi
+  INTL_MACOSX_LIBS=
+  if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then
+    INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation"
+  fi
+  AC_SUBST([INTL_MACOSX_LIBS])
+])
+
+
+dnl gt_CHECK_DECL(FUNC, INCLUDES)
+dnl Check whether a function is declared.
+AC_DEFUN([gt_CHECK_DECL],
+[
+  AC_CACHE_CHECK([whether $1 is declared], ac_cv_have_decl_$1,
+    [AC_TRY_COMPILE([$2], [
+#ifndef $1
+  char *p = (char *) $1;
+#endif
+], ac_cv_have_decl_$1=yes, ac_cv_have_decl_$1=no)])
+  if test $ac_cv_have_decl_$1 = yes; then
+    gt_value=1
+  else
+    gt_value=0
+  fi
+  AC_DEFINE_UNQUOTED([HAVE_DECL_]translit($1, [a-z], [A-Z]), [$gt_value],
+    [Define to 1 if you have the declaration of `$1', and to 0 if you don't.])
+])
+
+
+dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version])
+AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])
diff --git a/m4/glibc2.m4 b/m4/glibc2.m4
new file mode 100644 (file)
index 0000000..e8f5bfe
--- /dev/null
@@ -0,0 +1,30 @@
+# glibc2.m4 serial 1
+dnl Copyright (C) 2000-2002, 2004 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# Test for the GNU C Library, version 2.0 or newer.
+# From Bruno Haible.
+
+AC_DEFUN([gt_GLIBC2],
+  [
+    AC_CACHE_CHECK(whether we are using the GNU C Library 2 or newer,
+      ac_cv_gnu_library_2,
+      [AC_EGREP_CPP([Lucky GNU user],
+       [
+#include <features.h>
+#ifdef __GNU_LIBRARY__
+ #if (__GLIBC__ >= 2)
+  Lucky GNU user
+ #endif
+#endif
+       ],
+       ac_cv_gnu_library_2=yes,
+       ac_cv_gnu_library_2=no)
+      ]
+    )
+    AC_SUBST(GLIBC2)
+    GLIBC2="$ac_cv_gnu_library_2"
+  ]
+)
diff --git a/m4/glibc21.m4 b/m4/glibc21.m4
new file mode 100644 (file)
index 0000000..d95fd98
--- /dev/null
@@ -0,0 +1,30 @@
+# glibc21.m4 serial 3
+dnl Copyright (C) 2000-2002, 2004 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# Test for the GNU C Library, version 2.1 or newer.
+# From Bruno Haible.
+
+AC_DEFUN([gl_GLIBC21],
+  [
+    AC_CACHE_CHECK(whether we are using the GNU C Library 2.1 or newer,
+      ac_cv_gnu_library_2_1,
+      [AC_EGREP_CPP([Lucky GNU user],
+       [
+#include <features.h>
+#ifdef __GNU_LIBRARY__
+ #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2)
+  Lucky GNU user
+ #endif
+#endif
+       ],
+       ac_cv_gnu_library_2_1=yes,
+       ac_cv_gnu_library_2_1=no)
+      ]
+    )
+    AC_SUBST(GLIBC21)
+    GLIBC21="$ac_cv_gnu_library_2_1"
+  ]
+)
diff --git a/m4/iconv.m4 b/m4/iconv.m4
new file mode 100644 (file)
index 0000000..654c415
--- /dev/null
@@ -0,0 +1,101 @@
+# iconv.m4 serial AM4 (gettext-0.11.3)
+dnl Copyright (C) 2000-2002 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
+[
+  dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
+  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+  AC_REQUIRE([AC_LIB_RPATH])
+
+  dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
+  dnl accordingly.
+  AC_LIB_LINKFLAGS_BODY([iconv])
+])
+
+AC_DEFUN([AM_ICONV_LINK],
+[
+  dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
+  dnl those with the standalone portable GNU libiconv installed).
+
+  dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
+  dnl accordingly.
+  AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
+
+  dnl Add $INCICONV to CPPFLAGS before performing the following checks,
+  dnl because if the user has installed libiconv and not disabled its use
+  dnl via --without-libiconv-prefix, he wants to use it. The first
+  dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed.
+  am_save_CPPFLAGS="$CPPFLAGS"
+  AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
+
+  AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
+    am_cv_func_iconv="no, consider installing GNU libiconv"
+    am_cv_lib_iconv=no
+    AC_TRY_LINK([#include <stdlib.h>
+#include <iconv.h>],
+      [iconv_t cd = iconv_open("","");
+       iconv(cd,NULL,NULL,NULL,NULL);
+       iconv_close(cd);],
+      am_cv_func_iconv=yes)
+    if test "$am_cv_func_iconv" != yes; then
+      am_save_LIBS="$LIBS"
+      LIBS="$LIBS $LIBICONV"
+      AC_TRY_LINK([#include <stdlib.h>
+#include <iconv.h>],
+        [iconv_t cd = iconv_open("","");
+         iconv(cd,NULL,NULL,NULL,NULL);
+         iconv_close(cd);],
+        am_cv_lib_iconv=yes
+        am_cv_func_iconv=yes)
+      LIBS="$am_save_LIBS"
+    fi
+  ])
+  if test "$am_cv_func_iconv" = yes; then
+    AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
+  fi
+  if test "$am_cv_lib_iconv" = yes; then
+    AC_MSG_CHECKING([how to link with libiconv])
+    AC_MSG_RESULT([$LIBICONV])
+  else
+    dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
+    dnl either.
+    CPPFLAGS="$am_save_CPPFLAGS"
+    LIBICONV=
+    LTLIBICONV=
+  fi
+  AC_SUBST(LIBICONV)
+  AC_SUBST(LTLIBICONV)
+])
+
+AC_DEFUN([AM_ICONV],
+[
+  AM_ICONV_LINK
+  if test "$am_cv_func_iconv" = yes; then
+    AC_MSG_CHECKING([for iconv declaration])
+    AC_CACHE_VAL(am_cv_proto_iconv, [
+      AC_TRY_COMPILE([
+#include <stdlib.h>
+#include <iconv.h>
+extern
+#ifdef __cplusplus
+"C"
+#endif
+#if defined(__STDC__) || defined(__cplusplus)
+size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
+#else
+size_t iconv();
+#endif
+], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
+      am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
+    am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
+    AC_MSG_RESULT([$]{ac_t:-
+         }[$]am_cv_proto_iconv)
+    AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
+      [Define as const if the declaration of iconv() needs const.])
+  fi
+])
diff --git a/m4/intdiv0.m4 b/m4/intdiv0.m4
new file mode 100644 (file)
index 0000000..b8d7817
--- /dev/null
@@ -0,0 +1,70 @@
+# intdiv0.m4 serial 1 (gettext-0.11.3)
+dnl Copyright (C) 2002 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+AC_DEFUN([gt_INTDIV0],
+[
+  AC_REQUIRE([AC_PROG_CC])dnl
+  AC_REQUIRE([AC_CANONICAL_HOST])dnl
+
+  AC_CACHE_CHECK([whether integer division by zero raises SIGFPE],
+    gt_cv_int_divbyzero_sigfpe,
+    [
+      AC_TRY_RUN([
+#include <stdlib.h>
+#include <signal.h>
+
+static void
+#ifdef __cplusplus
+sigfpe_handler (int sig)
+#else
+sigfpe_handler (sig) int sig;
+#endif
+{
+  /* Exit with code 0 if SIGFPE, with code 1 if any other signal.  */
+  exit (sig != SIGFPE);
+}
+
+int x = 1;
+int y = 0;
+int z;
+int nan;
+
+int main ()
+{
+  signal (SIGFPE, sigfpe_handler);
+/* IRIX and AIX (when "xlc -qcheck" is used) yield signal SIGTRAP.  */
+#if (defined (__sgi) || defined (_AIX)) && defined (SIGTRAP)
+  signal (SIGTRAP, sigfpe_handler);
+#endif
+/* Linux/SPARC yields signal SIGILL.  */
+#if defined (__sparc__) && defined (__linux__)
+  signal (SIGILL, sigfpe_handler);
+#endif
+
+  z = x / y;
+  nan = y / y;
+  exit (1);
+}
+], gt_cv_int_divbyzero_sigfpe=yes, gt_cv_int_divbyzero_sigfpe=no,
+        [
+          # Guess based on the CPU.
+          case "$host_cpu" in
+            alpha* | i[34567]86 | m68k | s390*)
+              gt_cv_int_divbyzero_sigfpe="guessing yes";;
+            *)
+              gt_cv_int_divbyzero_sigfpe="guessing no";;
+          esac
+        ])
+    ])
+  case "$gt_cv_int_divbyzero_sigfpe" in
+    *yes) value=1;;
+    *) value=0;;
+  esac
+  AC_DEFINE_UNQUOTED(INTDIV0_RAISES_SIGFPE, $value,
+    [Define if integer division by zero raises signal SIGFPE.])
+])
diff --git a/m4/intmax.m4 b/m4/intmax.m4
new file mode 100644 (file)
index 0000000..d99c999
--- /dev/null
@@ -0,0 +1,30 @@
+# intmax.m4 serial 2 (gettext-0.14.2)
+dnl Copyright (C) 2002-2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+dnl Test whether the system has the 'intmax_t' type, but don't attempt to
+dnl find a replacement if it is lacking.
+
+AC_DEFUN([gt_TYPE_INTMAX_T],
+[
+  AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
+  AC_REQUIRE([gl_AC_HEADER_STDINT_H])
+  AC_CACHE_CHECK(for intmax_t, gt_cv_c_intmax_t,
+    [AC_TRY_COMPILE([
+#include <stddef.h>
+#include <stdlib.h>
+#if HAVE_STDINT_H_WITH_UINTMAX
+#include <stdint.h>
+#endif
+#if HAVE_INTTYPES_H_WITH_UINTMAX
+#include <inttypes.h>
+#endif
+], [intmax_t x = -1;], gt_cv_c_intmax_t=yes, gt_cv_c_intmax_t=no)])
+  if test $gt_cv_c_intmax_t = yes; then
+    AC_DEFINE(HAVE_INTMAX_T, 1,
+      [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
+  fi
+])
diff --git a/m4/inttypes-pri.m4 b/m4/inttypes-pri.m4
new file mode 100644 (file)
index 0000000..4d56a9a
--- /dev/null
@@ -0,0 +1,30 @@
+# inttypes-pri.m4 serial 1 (gettext-0.11.4)
+dnl Copyright (C) 1997-2002 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+# Define PRI_MACROS_BROKEN if <inttypes.h> exists and defines the PRI*
+# macros to non-string values.  This is the case on AIX 4.3.3.
+
+AC_DEFUN([gt_INTTYPES_PRI],
+[
+  AC_REQUIRE([gt_HEADER_INTTYPES_H])
+  if test $gt_cv_header_inttypes_h = yes; then
+    AC_CACHE_CHECK([whether the inttypes.h PRIxNN macros are broken],
+      gt_cv_inttypes_pri_broken,
+      [
+        AC_TRY_COMPILE([#include <inttypes.h>
+#ifdef PRId32
+char *p = PRId32;
+#endif
+], [], gt_cv_inttypes_pri_broken=no, gt_cv_inttypes_pri_broken=yes)
+      ])
+  fi
+  if test "$gt_cv_inttypes_pri_broken" = yes; then
+    AC_DEFINE_UNQUOTED(PRI_MACROS_BROKEN, 1,
+      [Define if <inttypes.h> exists and defines unusable PRI* macros.])
+  fi
+])
diff --git a/m4/inttypes.m4 b/m4/inttypes.m4
new file mode 100644 (file)
index 0000000..779bcea
--- /dev/null
@@ -0,0 +1,25 @@
+# inttypes.m4 serial 1 (gettext-0.11.4)
+dnl Copyright (C) 1997-2002 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Paul Eggert.
+
+# Define HAVE_INTTYPES_H if <inttypes.h> exists and doesn't clash with
+# <sys/types.h>.
+
+AC_DEFUN([gt_HEADER_INTTYPES_H],
+[
+  AC_CACHE_CHECK([for inttypes.h], gt_cv_header_inttypes_h,
+  [
+    AC_TRY_COMPILE(
+      [#include <sys/types.h>
+#include <inttypes.h>],
+      [], gt_cv_header_inttypes_h=yes, gt_cv_header_inttypes_h=no)
+  ])
+  if test $gt_cv_header_inttypes_h = yes; then
+    AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H, 1,
+      [Define if <inttypes.h> exists and doesn't clash with <sys/types.h>.])
+  fi
+])
diff --git a/m4/inttypes_h.m4 b/m4/inttypes_h.m4
new file mode 100644 (file)
index 0000000..a5d075d
--- /dev/null
@@ -0,0 +1,26 @@
+# inttypes_h.m4 serial 6
+dnl Copyright (C) 1997-2004 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Paul Eggert.
+
+# Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
+# doesn't clash with <sys/types.h>, and declares uintmax_t.
+
+AC_DEFUN([gl_AC_HEADER_INTTYPES_H],
+[
+  AC_CACHE_CHECK([for inttypes.h], gl_cv_header_inttypes_h,
+  [AC_TRY_COMPILE(
+    [#include <sys/types.h>
+#include <inttypes.h>],
+    [uintmax_t i = (uintmax_t) -1;],
+    gl_cv_header_inttypes_h=yes,
+    gl_cv_header_inttypes_h=no)])
+  if test $gl_cv_header_inttypes_h = yes; then
+    AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H_WITH_UINTMAX, 1,
+      [Define if <inttypes.h> exists, doesn't clash with <sys/types.h>,
+       and declares uintmax_t. ])
+  fi
+])
diff --git a/m4/isc-posix.m4 b/m4/isc-posix.m4
new file mode 100644 (file)
index 0000000..74dc8f2
--- /dev/null
@@ -0,0 +1,24 @@
+# isc-posix.m4 serial 2 (gettext-0.11.2)
+dnl Copyright (C) 1995-2002 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# This file is not needed with autoconf-2.53 and newer.  Remove it in 2005.
+
+# This test replaces the one in autoconf.
+# Currently this macro should have the same name as the autoconf macro
+# because gettext's gettext.m4 (distributed in the automake package)
+# still uses it.  Otherwise, the use in gettext.m4 makes autoheader
+# give these diagnostics:
+#   configure.in:556: AC_TRY_COMPILE was called before AC_ISC_POSIX
+#   configure.in:556: AC_TRY_RUN was called before AC_ISC_POSIX
+
+undefine([AC_ISC_POSIX])
+
+AC_DEFUN([AC_ISC_POSIX],
+  [
+    dnl This test replaces the obsolescent AC_ISC_POSIX kludge.
+    AC_CHECK_LIB(cposix, strerror, [LIBS="$LIBS -lcposix"])
+  ]
+)
diff --git a/m4/lcmessage.m4 b/m4/lcmessage.m4
new file mode 100644 (file)
index 0000000..19aa77e
--- /dev/null
@@ -0,0 +1,30 @@
+# lcmessage.m4 serial 4 (gettext-0.14.2)
+dnl Copyright (C) 1995-2002, 2004-2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+dnl
+dnl This file can can be used in projects which are not available under
+dnl the GNU General Public License or the GNU Library General Public
+dnl License but which still want to provide support for the GNU gettext
+dnl functionality.
+dnl Please note that the actual code of the GNU gettext library is covered
+dnl by the GNU Library General Public License, and the rest of the GNU
+dnl gettext package package is covered by the GNU General Public License.
+dnl They are *not* in the public domain.
+
+dnl Authors:
+dnl   Ulrich Drepper <drepper@cygnus.com>, 1995.
+
+# Check whether LC_MESSAGES is available in <locale.h>.
+
+AC_DEFUN([gt_LC_MESSAGES],
+[
+  AC_CACHE_CHECK([for LC_MESSAGES], gt_cv_val_LC_MESSAGES,
+    [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES],
+       gt_cv_val_LC_MESSAGES=yes, gt_cv_val_LC_MESSAGES=no)])
+  if test $gt_cv_val_LC_MESSAGES = yes; then
+    AC_DEFINE(HAVE_LC_MESSAGES, 1,
+      [Define if your <locale.h> file defines LC_MESSAGES.])
+  fi
+])
diff --git a/m4/lib-ld.m4 b/m4/lib-ld.m4
new file mode 100644 (file)
index 0000000..96c4e2c
--- /dev/null
@@ -0,0 +1,110 @@
+# lib-ld.m4 serial 3 (gettext-0.13)
+dnl Copyright (C) 1996-2003 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Subroutines of libtool.m4,
+dnl with replacements s/AC_/AC_LIB/ and s/lt_cv/acl_cv/ to avoid collision
+dnl with libtool.m4.
+
+dnl From libtool-1.4. Sets the variable with_gnu_ld to yes or no.
+AC_DEFUN([AC_LIB_PROG_LD_GNU],
+[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], acl_cv_prog_gnu_ld,
+[# I'd rather use --version here, but apparently some GNU ld's only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  acl_cv_prog_gnu_ld=yes ;;
+*)
+  acl_cv_prog_gnu_ld=no ;;
+esac])
+with_gnu_ld=$acl_cv_prog_gnu_ld
+])
+
+dnl From libtool-1.4. Sets the variable LD.
+AC_DEFUN([AC_LIB_PROG_LD],
+[AC_ARG_WITH(gnu-ld,
+[  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]],
+test "$withval" = no || with_gnu_ld=yes, with_gnu_ld=no)
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl
+# Prepare PATH_SEPARATOR.
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  AC_MSG_CHECKING([for ld used by GCC])
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [[\\/]* | [A-Za-z]:[\\/]*)]
+      [re_direlt='/[^/][^/]*/\.\./']
+      # Canonicalize the path of ld
+      ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'`
+      while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
+       ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  AC_MSG_CHECKING([for GNU ld])
+else
+  AC_MSG_CHECKING([for non-GNU ld])
+fi
+AC_CACHE_VAL(acl_cv_path_LD,
+[if test -z "$LD"; then
+  IFS="${IFS=  }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}"
+  for ac_dir in $PATH; do
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      acl_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some GNU ld's only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$acl_cv_path_LD" -v 2>&1 < /dev/null` in
+      *GNU* | *'with BFD'*)
+       test "$with_gnu_ld" != no && break ;;
+      *)
+       test "$with_gnu_ld" != yes && break ;;
+      esac
+    fi
+  done
+  IFS="$ac_save_ifs"
+else
+  acl_cv_path_LD="$LD" # Let the user override the test with a path.
+fi])
+LD="$acl_cv_path_LD"
+if test -n "$LD"; then
+  AC_MSG_RESULT($LD)
+else
+  AC_MSG_RESULT(no)
+fi
+test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
+AC_LIB_PROG_LD_GNU
+])
diff --git a/m4/lib-link.m4 b/m4/lib-link.m4
new file mode 100644 (file)
index 0000000..ea0b0c4
--- /dev/null
@@ -0,0 +1,553 @@
+# lib-link.m4 serial 6 (gettext-0.14.3)
+dnl Copyright (C) 2001-2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+AC_PREREQ(2.50)
+
+dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
+dnl the libraries corresponding to explicit and implicit dependencies.
+dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and
+dnl augments the CPPFLAGS variable.
+AC_DEFUN([AC_LIB_LINKFLAGS],
+[
+  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+  AC_REQUIRE([AC_LIB_RPATH])
+  define([Name],[translit([$1],[./-], [___])])
+  define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
+                               [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
+  AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [
+    AC_LIB_LINKFLAGS_BODY([$1], [$2])
+    ac_cv_lib[]Name[]_libs="$LIB[]NAME"
+    ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"
+    ac_cv_lib[]Name[]_cppflags="$INC[]NAME"
+  ])
+  LIB[]NAME="$ac_cv_lib[]Name[]_libs"
+  LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"
+  INC[]NAME="$ac_cv_lib[]Name[]_cppflags"
+  AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
+  AC_SUBST([LIB]NAME)
+  AC_SUBST([LTLIB]NAME)
+  dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the
+  dnl results of this search when this library appears as a dependency.
+  HAVE_LIB[]NAME=yes
+  undefine([Name])
+  undefine([NAME])
+])
+
+dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode)
+dnl searches for libname and the libraries corresponding to explicit and
+dnl implicit dependencies, together with the specified include files and
+dnl the ability to compile and link the specified testcode. If found, it
+dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and
+dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and
+dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
+dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.
+AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
+[
+  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+  AC_REQUIRE([AC_LIB_RPATH])
+  define([Name],[translit([$1],[./-], [___])])
+  define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
+                               [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
+
+  dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME
+  dnl accordingly.
+  AC_LIB_LINKFLAGS_BODY([$1], [$2])
+
+  dnl Add $INC[]NAME to CPPFLAGS before performing the following checks,
+  dnl because if the user has installed lib[]Name and not disabled its use
+  dnl via --without-lib[]Name-prefix, he wants to use it.
+  ac_save_CPPFLAGS="$CPPFLAGS"
+  AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
+
+  AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
+    ac_save_LIBS="$LIBS"
+    LIBS="$LIBS $LIB[]NAME"
+    AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no])
+    LIBS="$ac_save_LIBS"
+  ])
+  if test "$ac_cv_lib[]Name" = yes; then
+    HAVE_LIB[]NAME=yes
+    AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.])
+    AC_MSG_CHECKING([how to link with lib[]$1])
+    AC_MSG_RESULT([$LIB[]NAME])
+  else
+    HAVE_LIB[]NAME=no
+    dnl If $LIB[]NAME didn't lead to a usable library, we don't need
+    dnl $INC[]NAME either.
+    CPPFLAGS="$ac_save_CPPFLAGS"
+    LIB[]NAME=
+    LTLIB[]NAME=
+  fi
+  AC_SUBST([HAVE_LIB]NAME)
+  AC_SUBST([LIB]NAME)
+  AC_SUBST([LTLIB]NAME)
+  undefine([Name])
+  undefine([NAME])
+])
+
+dnl Determine the platform dependent parameters needed to use rpath:
+dnl libext, shlibext, hardcode_libdir_flag_spec, hardcode_libdir_separator,
+dnl hardcode_direct, hardcode_minus_L.
+AC_DEFUN([AC_LIB_RPATH],
+[
+  dnl Tell automake >= 1.10 to complain if config.rpath is missing.
+  m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([config.rpath])])
+  AC_REQUIRE([AC_PROG_CC])                dnl we use $CC, $GCC, $LDFLAGS
+  AC_REQUIRE([AC_LIB_PROG_LD])            dnl we use $LD, $with_gnu_ld
+  AC_REQUIRE([AC_CANONICAL_HOST])         dnl we use $host
+  AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir
+  AC_CACHE_CHECK([for shared library run path origin], acl_cv_rpath, [
+    CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \
+    ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh
+    . ./conftest.sh
+    rm -f ./conftest.sh
+    acl_cv_rpath=done
+  ])
+  wl="$acl_cv_wl"
+  libext="$acl_cv_libext"
+  shlibext="$acl_cv_shlibext"
+  hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
+  hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
+  hardcode_direct="$acl_cv_hardcode_direct"
+  hardcode_minus_L="$acl_cv_hardcode_minus_L"
+  dnl Determine whether the user wants rpath handling at all.
+  AC_ARG_ENABLE(rpath,
+    [  --disable-rpath         do not hardcode runtime library paths],
+    :, enable_rpath=yes)
+])
+
+dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
+dnl the libraries corresponding to explicit and implicit dependencies.
+dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
+AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
+[
+  define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
+                               [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
+  dnl By default, look in $includedir and $libdir.
+  use_additional=yes
+  AC_LIB_WITH_FINAL_PREFIX([
+    eval additional_includedir=\"$includedir\"
+    eval additional_libdir=\"$libdir\"
+  ])
+  AC_LIB_ARG_WITH([lib$1-prefix],
+[  --with-lib$1-prefix[=DIR]  search for lib$1 in DIR/include and DIR/lib
+  --without-lib$1-prefix     don't search for lib$1 in includedir and libdir],
+[
+    if test "X$withval" = "Xno"; then
+      use_additional=no
+    else
+      if test "X$withval" = "X"; then
+        AC_LIB_WITH_FINAL_PREFIX([
+          eval additional_includedir=\"$includedir\"
+          eval additional_libdir=\"$libdir\"
+        ])
+      else
+        additional_includedir="$withval/include"
+        additional_libdir="$withval/lib"
+      fi
+    fi
+])
+  dnl Search the library and its dependencies in $additional_libdir and
+  dnl $LDFLAGS. Using breadth-first-seach.
+  LIB[]NAME=
+  LTLIB[]NAME=
+  INC[]NAME=
+  rpathdirs=
+  ltrpathdirs=
+  names_already_handled=
+  names_next_round='$1 $2'
+  while test -n "$names_next_round"; do
+    names_this_round="$names_next_round"
+    names_next_round=
+    for name in $names_this_round; do
+      already_handled=
+      for n in $names_already_handled; do
+        if test "$n" = "$name"; then
+          already_handled=yes
+          break
+        fi
+      done
+      if test -z "$already_handled"; then
+        names_already_handled="$names_already_handled $name"
+        dnl See if it was already located by an earlier AC_LIB_LINKFLAGS
+        dnl or AC_LIB_HAVE_LINKFLAGS call.
+        uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
+        eval value=\"\$HAVE_LIB$uppername\"
+        if test -n "$value"; then
+          if test "$value" = yes; then
+            eval value=\"\$LIB$uppername\"
+            test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"
+            eval value=\"\$LTLIB$uppername\"
+            test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"
+          else
+            dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined
+            dnl that this library doesn't exist. So just drop it.
+            :
+          fi
+        else
+          dnl Search the library lib$name in $additional_libdir and $LDFLAGS
+          dnl and the already constructed $LIBNAME/$LTLIBNAME.
+          found_dir=
+          found_la=
+          found_so=
+          found_a=
+          if test $use_additional = yes; then
+            if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then
+              found_dir="$additional_libdir"
+              found_so="$additional_libdir/lib$name.$shlibext"
+              if test -f "$additional_libdir/lib$name.la"; then
+                found_la="$additional_libdir/lib$name.la"
+              fi
+            else
+              if test -f "$additional_libdir/lib$name.$libext"; then
+                found_dir="$additional_libdir"
+                found_a="$additional_libdir/lib$name.$libext"
+                if test -f "$additional_libdir/lib$name.la"; then
+                  found_la="$additional_libdir/lib$name.la"
+                fi
+              fi
+            fi
+          fi
+          if test "X$found_dir" = "X"; then
+            for x in $LDFLAGS $LTLIB[]NAME; do
+              AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+              case "$x" in
+                -L*)
+                  dir=`echo "X$x" | sed -e 's/^X-L//'`
+                  if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then
+                    found_dir="$dir"
+                    found_so="$dir/lib$name.$shlibext"
+                    if test -f "$dir/lib$name.la"; then
+                      found_la="$dir/lib$name.la"
+                    fi
+                  else
+                    if test -f "$dir/lib$name.$libext"; then
+                      found_dir="$dir"
+                      found_a="$dir/lib$name.$libext"
+                      if test -f "$dir/lib$name.la"; then
+                        found_la="$dir/lib$name.la"
+                      fi
+                    fi
+                  fi
+                  ;;
+              esac
+              if test "X$found_dir" != "X"; then
+                break
+              fi
+            done
+          fi
+          if test "X$found_dir" != "X"; then
+            dnl Found the library.
+            LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"
+            if test "X$found_so" != "X"; then
+              dnl Linking with a shared library. We attempt to hardcode its
+              dnl directory into the executable's runpath, unless it's the
+              dnl standard /usr/lib.
+              if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; then
+                dnl No hardcoding is needed.
+                LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
+              else
+                dnl Use an explicit option to hardcode DIR into the resulting
+                dnl binary.
+                dnl Potentially add DIR to ltrpathdirs.
+                dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
+                haveit=
+                for x in $ltrpathdirs; do
+                  if test "X$x" = "X$found_dir"; then
+                    haveit=yes
+                    break
+                  fi
+                done
+                if test -z "$haveit"; then
+                  ltrpathdirs="$ltrpathdirs $found_dir"
+                fi
+                dnl The hardcoding into $LIBNAME is system dependent.
+                if test "$hardcode_direct" = yes; then
+                  dnl Using DIR/libNAME.so during linking hardcodes DIR into the
+                  dnl resulting binary.
+                  LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
+                else
+                  if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
+                    dnl Use an explicit option to hardcode DIR into the resulting
+                    dnl binary.
+                    LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
+                    dnl Potentially add DIR to rpathdirs.
+                    dnl The rpathdirs will be appended to $LIBNAME at the end.
+                    haveit=
+                    for x in $rpathdirs; do
+                      if test "X$x" = "X$found_dir"; then
+                        haveit=yes
+                        break
+                      fi
+                    done
+                    if test -z "$haveit"; then
+                      rpathdirs="$rpathdirs $found_dir"
+                    fi
+                  else
+                    dnl Rely on "-L$found_dir".
+                    dnl But don't add it if it's already contained in the LDFLAGS
+                    dnl or the already constructed $LIBNAME
+                    haveit=
+                    for x in $LDFLAGS $LIB[]NAME; do
+                      AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+                      if test "X$x" = "X-L$found_dir"; then
+                        haveit=yes
+                        break
+                      fi
+                    done
+                    if test -z "$haveit"; then
+                      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
+                    fi
+                    if test "$hardcode_minus_L" != no; then
+                      dnl FIXME: Not sure whether we should use
+                      dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
+                      dnl here.
+                      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
+                    else
+                      dnl We cannot use $hardcode_runpath_var and LD_RUN_PATH
+                      dnl here, because this doesn't fit in flags passed to the
+                      dnl compiler. So give up. No hardcoding. This affects only
+                      dnl very old systems.
+                      dnl FIXME: Not sure whether we should use
+                      dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
+                      dnl here.
+                      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
+                    fi
+                  fi
+                fi
+              fi
+            else
+              if test "X$found_a" != "X"; then
+                dnl Linking with a static library.
+                LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"
+              else
+                dnl We shouldn't come here, but anyway it's good to have a
+                dnl fallback.
+                LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"
+              fi
+            fi
+            dnl Assume the include files are nearby.
+            additional_includedir=
+            case "$found_dir" in
+              */lib | */lib/)
+                basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'`
+                additional_includedir="$basedir/include"
+                ;;
+            esac
+            if test "X$additional_includedir" != "X"; then
+              dnl Potentially add $additional_includedir to $INCNAME.
+              dnl But don't add it
+              dnl   1. if it's the standard /usr/include,
+              dnl   2. if it's /usr/local/include and we are using GCC on Linux,
+              dnl   3. if it's already present in $CPPFLAGS or the already
+              dnl      constructed $INCNAME,
+              dnl   4. if it doesn't exist as a directory.
+              if test "X$additional_includedir" != "X/usr/include"; then
+                haveit=
+                if test "X$additional_includedir" = "X/usr/local/include"; then
+                  if test -n "$GCC"; then
+                    case $host_os in
+                      linux* | gnu* | k*bsd*-gnu) haveit=yes;;
+                    esac
+                  fi
+                fi
+                if test -z "$haveit"; then
+                  for x in $CPPFLAGS $INC[]NAME; do
+                    AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+                    if test "X$x" = "X-I$additional_includedir"; then
+                      haveit=yes
+                      break
+                    fi
+                  done
+                  if test -z "$haveit"; then
+                    if test -d "$additional_includedir"; then
+                      dnl Really add $additional_includedir to $INCNAME.
+                      INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"
+                    fi
+                  fi
+                fi
+              fi
+            fi
+            dnl Look for dependencies.
+            if test -n "$found_la"; then
+              dnl Read the .la file. It defines the variables
+              dnl dlname, library_names, old_library, dependency_libs, current,
+              dnl age, revision, installed, dlopen, dlpreopen, libdir.
+              save_libdir="$libdir"
+              case "$found_la" in
+                */* | *\\*) . "$found_la" ;;
+                *) . "./$found_la" ;;
+              esac
+              libdir="$save_libdir"
+              dnl We use only dependency_libs.
+              for dep in $dependency_libs; do
+                case "$dep" in
+                  -L*)
+                    additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
+                    dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME.
+                    dnl But don't add it
+                    dnl   1. if it's the standard /usr/lib,
+                    dnl   2. if it's /usr/local/lib and we are using GCC on Linux,
+                    dnl   3. if it's already present in $LDFLAGS or the already
+                    dnl      constructed $LIBNAME,
+                    dnl   4. if it doesn't exist as a directory.
+                    if test "X$additional_libdir" != "X/usr/lib"; then
+                      haveit=
+                      if test "X$additional_libdir" = "X/usr/local/lib"; then
+                        if test -n "$GCC"; then
+                          case $host_os in
+                            linux* | gnu* | k*bsd*-gnu) haveit=yes;;
+                          esac
+                        fi
+                      fi
+                      if test -z "$haveit"; then
+                        haveit=
+                        for x in $LDFLAGS $LIB[]NAME; do
+                          AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+                          if test "X$x" = "X-L$additional_libdir"; then
+                            haveit=yes
+                            break
+                          fi
+                        done
+                        if test -z "$haveit"; then
+                          if test -d "$additional_libdir"; then
+                            dnl Really add $additional_libdir to $LIBNAME.
+                            LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir"
+                          fi
+                        fi
+                        haveit=
+                        for x in $LDFLAGS $LTLIB[]NAME; do
+                          AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+                          if test "X$x" = "X-L$additional_libdir"; then
+                            haveit=yes
+                            break
+                          fi
+                        done
+                        if test -z "$haveit"; then
+                          if test -d "$additional_libdir"; then
+                            dnl Really add $additional_libdir to $LTLIBNAME.
+                            LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir"
+                          fi
+                        fi
+                      fi
+                    fi
+                    ;;
+                  -R*)
+                    dir=`echo "X$dep" | sed -e 's/^X-R//'`
+                    if test "$enable_rpath" != no; then
+                      dnl Potentially add DIR to rpathdirs.
+                      dnl The rpathdirs will be appended to $LIBNAME at the end.
+                      haveit=
+                      for x in $rpathdirs; do
+                        if test "X$x" = "X$dir"; then
+                          haveit=yes
+                          break
+                        fi
+                      done
+                      if test -z "$haveit"; then
+                        rpathdirs="$rpathdirs $dir"
+                      fi
+                      dnl Potentially add DIR to ltrpathdirs.
+                      dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
+                      haveit=
+                      for x in $ltrpathdirs; do
+                        if test "X$x" = "X$dir"; then
+                          haveit=yes
+                          break
+                        fi
+                      done
+                      if test -z "$haveit"; then
+                        ltrpathdirs="$ltrpathdirs $dir"
+                      fi
+                    fi
+                    ;;
+                  -l*)
+                    dnl Handle this in the next round.
+                    names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
+                    ;;
+                  *.la)
+                    dnl Handle this in the next round. Throw away the .la's
+                    dnl directory; it is already contained in a preceding -L
+                    dnl option.
+                    names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
+                    ;;
+                  *)
+                    dnl Most likely an immediate library name.
+                    LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"
+                    LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep"
+                    ;;
+                esac
+              done
+            fi
+          else
+            dnl Didn't find the library; assume it is in the system directories
+            dnl known to the linker and runtime loader. (All the system
+            dnl directories known to the linker should also be known to the
+            dnl runtime loader, otherwise the system is severely misconfigured.)
+            LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
+            LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
+          fi
+        fi
+      fi
+    done
+  done
+  if test "X$rpathdirs" != "X"; then
+    if test -n "$hardcode_libdir_separator"; then
+      dnl Weird platform: only the last -rpath option counts, the user must
+      dnl pass all path elements in one option. We can arrange that for a
+      dnl single library, but not when more than one $LIBNAMEs are used.
+      alldirs=
+      for found_dir in $rpathdirs; do
+        alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"
+      done
+      dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl.
+      acl_save_libdir="$libdir"
+      libdir="$alldirs"
+      eval flag=\"$hardcode_libdir_flag_spec\"
+      libdir="$acl_save_libdir"
+      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
+    else
+      dnl The -rpath options are cumulative.
+      for found_dir in $rpathdirs; do
+        acl_save_libdir="$libdir"
+        libdir="$found_dir"
+        eval flag=\"$hardcode_libdir_flag_spec\"
+        libdir="$acl_save_libdir"
+        LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
+      done
+    fi
+  fi
+  if test "X$ltrpathdirs" != "X"; then
+    dnl When using libtool, the option that works for both libraries and
+    dnl executables is -R. The -R options are cumulative.
+    for found_dir in $ltrpathdirs; do
+      LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
+    done
+  fi
+])
+
+dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,
+dnl unless already present in VAR.
+dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes
+dnl contains two or three consecutive elements that belong together.
+AC_DEFUN([AC_LIB_APPENDTOVAR],
+[
+  for element in [$2]; do
+    haveit=
+    for x in $[$1]; do
+      AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+      if test "X$x" = "X$element"; then
+        haveit=yes
+        break
+      fi
+    done
+    if test -z "$haveit"; then
+      [$1]="${[$1]}${[$1]:+ }$element"
+    fi
+  done
+])
diff --git a/m4/lib-prefix.m4 b/m4/lib-prefix.m4
new file mode 100644 (file)
index 0000000..0d895ca
--- /dev/null
@@ -0,0 +1,153 @@
+# lib-prefix.m4 serial 4 (gettext-0.14.2)
+dnl Copyright (C) 2001-2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and
+dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't
+dnl require excessive bracketing.
+ifdef([AC_HELP_STRING],
+[AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])],
+[AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])])
+
+dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed
+dnl to access previously installed libraries. The basic assumption is that
+dnl a user will want packages to use other packages he previously installed
+dnl with the same --prefix option.
+dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate
+dnl libraries, but is otherwise very convenient.
+AC_DEFUN([AC_LIB_PREFIX],
+[
+  AC_BEFORE([$0], [AC_LIB_LINKFLAGS])
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+  dnl By default, look in $includedir and $libdir.
+  use_additional=yes
+  AC_LIB_WITH_FINAL_PREFIX([
+    eval additional_includedir=\"$includedir\"
+    eval additional_libdir=\"$libdir\"
+  ])
+  AC_LIB_ARG_WITH([lib-prefix],
+[  --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib
+  --without-lib-prefix    don't search for libraries in includedir and libdir],
+[
+    if test "X$withval" = "Xno"; then
+      use_additional=no
+    else
+      if test "X$withval" = "X"; then
+        AC_LIB_WITH_FINAL_PREFIX([
+          eval additional_includedir=\"$includedir\"
+          eval additional_libdir=\"$libdir\"
+        ])
+      else
+        additional_includedir="$withval/include"
+        additional_libdir="$withval/lib"
+      fi
+    fi
+])
+  if test $use_additional = yes; then
+    dnl Potentially add $additional_includedir to $CPPFLAGS.
+    dnl But don't add it
+    dnl   1. if it's the standard /usr/include,
+    dnl   2. if it's already present in $CPPFLAGS,
+    dnl   3. if it's /usr/local/include and we are using GCC on Linux,
+    dnl   4. if it doesn't exist as a directory.
+    if test "X$additional_includedir" != "X/usr/include"; then
+      haveit=
+      for x in $CPPFLAGS; do
+        AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+        if test "X$x" = "X-I$additional_includedir"; then
+          haveit=yes
+          break
+        fi
+      done
+      if test -z "$haveit"; then
+        if test "X$additional_includedir" = "X/usr/local/include"; then
+          if test -n "$GCC"; then
+            case $host_os in
+              linux* | gnu* | k*bsd*-gnu) haveit=yes;;
+            esac
+          fi
+        fi
+        if test -z "$haveit"; then
+          if test -d "$additional_includedir"; then
+            dnl Really add $additional_includedir to $CPPFLAGS.
+            CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir"
+          fi
+        fi
+      fi
+    fi
+    dnl Potentially add $additional_libdir to $LDFLAGS.
+    dnl But don't add it
+    dnl   1. if it's the standard /usr/lib,
+    dnl   2. if it's already present in $LDFLAGS,
+    dnl   3. if it's /usr/local/lib and we are using GCC on Linux,
+    dnl   4. if it doesn't exist as a directory.
+    if test "X$additional_libdir" != "X/usr/lib"; then
+      haveit=
+      for x in $LDFLAGS; do
+        AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+        if test "X$x" = "X-L$additional_libdir"; then
+          haveit=yes
+          break
+        fi
+      done
+      if test -z "$haveit"; then
+        if test "X$additional_libdir" = "X/usr/local/lib"; then
+          if test -n "$GCC"; then
+            case $host_os in
+              linux*) haveit=yes;;
+            esac
+          fi
+        fi
+        if test -z "$haveit"; then
+          if test -d "$additional_libdir"; then
+            dnl Really add $additional_libdir to $LDFLAGS.
+            LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir"
+          fi
+        fi
+      fi
+    fi
+  fi
+])
+
+dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix,
+dnl acl_final_exec_prefix, containing the values to which $prefix and
+dnl $exec_prefix will expand at the end of the configure script.
+AC_DEFUN([AC_LIB_PREPARE_PREFIX],
+[
+  dnl Unfortunately, prefix and exec_prefix get only finally determined
+  dnl at the end of configure.
+  if test "X$prefix" = "XNONE"; then
+    acl_final_prefix="$ac_default_prefix"
+  else
+    acl_final_prefix="$prefix"
+  fi
+  if test "X$exec_prefix" = "XNONE"; then
+    acl_final_exec_prefix='${prefix}'
+  else
+    acl_final_exec_prefix="$exec_prefix"
+  fi
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  eval acl_final_exec_prefix=\"$acl_final_exec_prefix\"
+  prefix="$acl_save_prefix"
+])
+
+dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the
+dnl variables prefix and exec_prefix bound to the values they will have
+dnl at the end of the configure script.
+AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX],
+[
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  $1
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+])
diff --git a/m4/libtool.m4 b/m4/libtool.m4
new file mode 100644 (file)
index 0000000..1e7ea47
--- /dev/null
@@ -0,0 +1,7376 @@
+# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*-
+#
+#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+#                 2006, 2007, 2008 Free Software Foundation, Inc.
+#   Written by Gordon Matzigkeit, 1996
+#
+# This file 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.
+
+m4_define([_LT_COPYING], [dnl
+#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+#                 2006, 2007, 2008 Free Software Foundation, Inc.
+#   Written by Gordon Matzigkeit, 1996
+#
+#   This file is part of GNU Libtool.
+#
+# GNU Libtool is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# As a special exception to the GNU General Public License,
+# if you distribute this file as part of a program or library that
+# is built using GNU Libtool, you may include this file under the
+# same distribution terms that you use for the rest of that program.
+#
+# GNU Libtool 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Libtool; see the file COPYING.  If not, a copy
+# can be downloaded from http://www.gnu.org/licenses/gpl.html, or
+# obtained by writing to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+])
+
+# serial 56 LT_INIT
+
+
+# LT_PREREQ(VERSION)
+# ------------------
+# Complain and exit if this libtool version is less that VERSION.
+m4_defun([LT_PREREQ],
+[m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1,
+       [m4_default([$3],
+                  [m4_fatal([Libtool version $1 or higher is required],
+                            63)])],
+       [$2])])
+
+
+# _LT_CHECK_BUILDDIR
+# ------------------
+# Complain if the absolute build directory name contains unusual characters
+m4_defun([_LT_CHECK_BUILDDIR],
+[case `pwd` in
+  *\ * | *\    *)
+    AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;;
+esac
+])
+
+
+# LT_INIT([OPTIONS])
+# ------------------
+AC_DEFUN([LT_INIT],
+[AC_PREREQ([2.58])dnl We use AC_INCLUDES_DEFAULT
+AC_BEFORE([$0], [LT_LANG])dnl
+AC_BEFORE([$0], [LT_OUTPUT])dnl
+AC_BEFORE([$0], [LTDL_INIT])dnl
+m4_require([_LT_CHECK_BUILDDIR])dnl
+
+dnl Autoconf doesn't catch unexpanded LT_ macros by default:
+m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl
+m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl
+dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4
+dnl unless we require an AC_DEFUNed macro:
+AC_REQUIRE([LTOPTIONS_VERSION])dnl
+AC_REQUIRE([LTSUGAR_VERSION])dnl
+AC_REQUIRE([LTVERSION_VERSION])dnl
+AC_REQUIRE([LTOBSOLETE_VERSION])dnl
+m4_require([_LT_PROG_LTMAIN])dnl
+
+dnl Parse OPTIONS
+_LT_SET_OPTIONS([$0], [$1])
+
+# This can be used to rebuild libtool when needed
+LIBTOOL_DEPS="$ltmain"
+
+# Always use our own libtool.
+LIBTOOL='$(SHELL) $(top_builddir)/libtool'
+AC_SUBST(LIBTOOL)dnl
+
+_LT_SETUP
+
+# Only expand once:
+m4_define([LT_INIT])
+])# LT_INIT
+
+# Old names:
+AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT])
+AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_PROG_LIBTOOL], [])
+dnl AC_DEFUN([AM_PROG_LIBTOOL], [])
+
+
+# _LT_CC_BASENAME(CC)
+# -------------------
+# Calculate cc_basename.  Skip known compiler wrappers and cross-prefix.
+m4_defun([_LT_CC_BASENAME],
+[for cc_temp in $1""; do
+  case $cc_temp in
+    compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;;
+    distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+])
+
+
+# _LT_FILEUTILS_DEFAULTS
+# ----------------------
+# It is okay to use these file commands and assume they have been set
+# sensibly after `m4_require([_LT_FILEUTILS_DEFAULTS])'.
+m4_defun([_LT_FILEUTILS_DEFAULTS],
+[: ${CP="cp -f"}
+: ${MV="mv -f"}
+: ${RM="rm -f"}
+])# _LT_FILEUTILS_DEFAULTS
+
+
+# _LT_SETUP
+# ---------
+m4_defun([_LT_SETUP],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+_LT_DECL([], [host_alias], [0], [The host system])dnl
+_LT_DECL([], [host], [0])dnl
+_LT_DECL([], [host_os], [0])dnl
+dnl
+_LT_DECL([], [build_alias], [0], [The build system])dnl
+_LT_DECL([], [build], [0])dnl
+_LT_DECL([], [build_os], [0])dnl
+dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([LT_PATH_LD])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+dnl
+AC_REQUIRE([AC_PROG_LN_S])dnl
+test -z "$LN_S" && LN_S="ln -s"
+_LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl
+dnl
+AC_REQUIRE([LT_CMD_MAX_LEN])dnl
+_LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl
+_LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl
+dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_CHECK_SHELL_FEATURES])dnl
+m4_require([_LT_CMD_RELOAD])dnl
+m4_require([_LT_CHECK_MAGIC_METHOD])dnl
+m4_require([_LT_CMD_OLD_ARCHIVE])dnl
+m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl
+
+_LT_CONFIG_LIBTOOL_INIT([
+# See if we are running on zsh, and set the options which allow our
+# commands through without removal of \ escapes INIT.
+if test -n "\${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+])
+if test -n "${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+
+_LT_CHECK_OBJDIR
+
+m4_require([_LT_TAG_COMPILER])dnl
+_LT_PROG_ECHO_BACKSLASH
+
+case $host_os in
+aix3*)
+  # AIX sometimes has problems with the GCC collect2 program.  For some
+  # reason, if we set the COLLECT_NAMES environment variable, the problems
+  # vanish in a puff of smoke.
+  if test "X${COLLECT_NAMES+set}" != Xset; then
+    COLLECT_NAMES=
+    export COLLECT_NAMES
+  fi
+  ;;
+esac
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+sed_quote_subst='s/\([["`$\\]]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\([["`\\]]\)/\\\1/g'
+
+# Sed substitution to delay expansion of an escaped shell variable in a
+# double_quote_subst'ed string.
+delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
+
+# Sed substitution to delay expansion of an escaped single quote.
+delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g'
+
+# Sed substitution to avoid accidental globbing in evaled expressions
+no_glob_subst='s/\*/\\\*/g'
+
+# Global variables:
+ofile=libtool
+can_build_shared=yes
+
+# All known linkers require a `.a' archive for static linking (except MSVC,
+# which needs '.lib').
+libext=a
+
+with_gnu_ld="$lt_cv_prog_gnu_ld"
+
+old_CC="$CC"
+old_CFLAGS="$CFLAGS"
+
+# Set sane defaults for various variables
+test -z "$CC" && CC=cc
+test -z "$LTCC" && LTCC=$CC
+test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS
+test -z "$LD" && LD=ld
+test -z "$ac_objext" && ac_objext=o
+
+_LT_CC_BASENAME([$compiler])
+
+# Only perform the check for file, if the check method requires it
+test -z "$MAGIC_CMD" && MAGIC_CMD=file
+case $deplibs_check_method in
+file_magic*)
+  if test "$file_magic_cmd" = '$MAGIC_CMD'; then
+    _LT_PATH_MAGIC
+  fi
+  ;;
+esac
+
+# Use C for the default configuration in the libtool script
+LT_SUPPORTED_TAG([CC])
+_LT_LANG_C_CONFIG
+_LT_LANG_DEFAULT_CONFIG
+_LT_CONFIG_COMMANDS
+])# _LT_SETUP
+
+
+# _LT_PROG_LTMAIN
+# ---------------
+# Note that this code is called both from `configure', and `config.status'
+# now that we use AC_CONFIG_COMMANDS to generate libtool.  Notably,
+# `config.status' has no value for ac_aux_dir unless we are using Automake,
+# so we pass a copy along to make sure it has a sensible value anyway.
+m4_defun([_LT_PROG_LTMAIN],
+[m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl
+_LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir'])
+ltmain="$ac_aux_dir/ltmain.sh"
+])# _LT_PROG_LTMAIN
+
+
+## ------------------------------------- ##
+## Accumulate code for creating libtool. ##
+## ------------------------------------- ##
+
+# So that we can recreate a full libtool script including additional
+# tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS
+# in macros and then make a single call at the end using the `libtool'
+# label.
+
+
+# _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS])
+# ----------------------------------------
+# Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later.
+m4_define([_LT_CONFIG_LIBTOOL_INIT],
+[m4_ifval([$1],
+          [m4_append([_LT_OUTPUT_LIBTOOL_INIT],
+                     [$1
+])])])
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_INIT])
+
+
+# _LT_CONFIG_LIBTOOL([COMMANDS])
+# ------------------------------
+# Register COMMANDS to be passed to AC_CONFIG_COMMANDS later.
+m4_define([_LT_CONFIG_LIBTOOL],
+[m4_ifval([$1],
+          [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS],
+                     [$1
+])])])
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS])
+
+
+# _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS])
+# -----------------------------------------------------
+m4_defun([_LT_CONFIG_SAVE_COMMANDS],
+[_LT_CONFIG_LIBTOOL([$1])
+_LT_CONFIG_LIBTOOL_INIT([$2])
+])
+
+
+# _LT_FORMAT_COMMENT([COMMENT])
+# -----------------------------
+# Add leading comment marks to the start of each line, and a trailing
+# full-stop to the whole comment if one is not present already.
+m4_define([_LT_FORMAT_COMMENT],
+[m4_ifval([$1], [
+m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])],
+              [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.])
+)])
+
+
+
+## ------------------------ ##
+## FIXME: Eliminate VARNAME ##
+## ------------------------ ##
+
+
+# _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?])
+# -------------------------------------------------------------------
+# CONFIGNAME is the name given to the value in the libtool script.
+# VARNAME is the (base) name used in the configure script.
+# VALUE may be 0, 1 or 2 for a computed quote escaped value based on
+# VARNAME.  Any other value will be used directly.
+m4_define([_LT_DECL],
+[lt_if_append_uniq([lt_decl_varnames], [$2], [, ],
+    [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name],
+       [m4_ifval([$1], [$1], [$2])])
+    lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3])
+    m4_ifval([$4],
+       [lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])])
+    lt_dict_add_subkey([lt_decl_dict], [$2],
+       [tagged?], [m4_ifval([$5], [yes], [no])])])
+])
+
+
+# _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION])
+# --------------------------------------------------------
+m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])])
+
+
+# lt_decl_tag_varnames([SEPARATOR], [VARNAME1...])
+# ------------------------------------------------
+m4_define([lt_decl_tag_varnames],
+[_lt_decl_filter([tagged?], [yes], $@)])
+
+
+# _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..])
+# ---------------------------------------------------------
+m4_define([_lt_decl_filter],
+[m4_case([$#],
+  [0], [m4_fatal([$0: too few arguments: $#])],
+  [1], [m4_fatal([$0: too few arguments: $#: $1])],
+  [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)],
+  [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)],
+  [lt_dict_filter([lt_decl_dict], $@)])[]dnl
+])
+
+
+# lt_decl_quote_varnames([SEPARATOR], [VARNAME1...])
+# --------------------------------------------------
+m4_define([lt_decl_quote_varnames],
+[_lt_decl_filter([value], [1], $@)])
+
+
+# lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...])
+# ---------------------------------------------------
+m4_define([lt_decl_dquote_varnames],
+[_lt_decl_filter([value], [2], $@)])
+
+
+# lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...])
+# ---------------------------------------------------
+m4_define([lt_decl_varnames_tagged],
+[m4_assert([$# <= 2])dnl
+_$0(m4_quote(m4_default([$1], [[, ]])),
+    m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]),
+    m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))])
+m4_define([_lt_decl_varnames_tagged],
+[m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])])
+
+
+# lt_decl_all_varnames([SEPARATOR], [VARNAME1...])
+# ------------------------------------------------
+m4_define([lt_decl_all_varnames],
+[_$0(m4_quote(m4_default([$1], [[, ]])),
+     m4_if([$2], [],
+          m4_quote(lt_decl_varnames),
+       m4_quote(m4_shift($@))))[]dnl
+])
+m4_define([_lt_decl_all_varnames],
+[lt_join($@, lt_decl_varnames_tagged([$1],
+                       lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl
+])
+
+
+# _LT_CONFIG_STATUS_DECLARE([VARNAME])
+# ------------------------------------
+# Quote a variable value, and forward it to `config.status' so that its
+# declaration there will have the same value as in `configure'.  VARNAME
+# must have a single quote delimited value for this to work.
+m4_define([_LT_CONFIG_STATUS_DECLARE],
+[$1='`$ECHO "X$][$1" | $Xsed -e "$delay_single_quote_subst"`'])
+
+
+# _LT_CONFIG_STATUS_DECLARATIONS
+# ------------------------------
+# We delimit libtool config variables with single quotes, so when
+# we write them to config.status, we have to be sure to quote all
+# embedded single quotes properly.  In configure, this macro expands
+# each variable declared with _LT_DECL (and _LT_TAGDECL) into:
+#
+#    <var>='`$ECHO "X$<var>" | $Xsed -e "$delay_single_quote_subst"`'
+m4_defun([_LT_CONFIG_STATUS_DECLARATIONS],
+[m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames),
+    [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])])
+
+
+# _LT_LIBTOOL_TAGS
+# ----------------
+# Output comment and list of tags supported by the script
+m4_defun([_LT_LIBTOOL_TAGS],
+[_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl
+available_tags="_LT_TAGS"dnl
+])
+
+
+# _LT_LIBTOOL_DECLARE(VARNAME, [TAG])
+# -----------------------------------
+# Extract the dictionary values for VARNAME (optionally with TAG) and
+# expand to a commented shell variable setting:
+#
+#    # Some comment about what VAR is for.
+#    visible_name=$lt_internal_name
+m4_define([_LT_LIBTOOL_DECLARE],
+[_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1],
+                                          [description])))[]dnl
+m4_pushdef([_libtool_name],
+    m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl
+m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])),
+    [0], [_libtool_name=[$]$1],
+    [1], [_libtool_name=$lt_[]$1],
+    [2], [_libtool_name=$lt_[]$1],
+    [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl
+m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl
+])
+
+
+# _LT_LIBTOOL_CONFIG_VARS
+# -----------------------
+# Produce commented declarations of non-tagged libtool config variables
+# suitable for insertion in the LIBTOOL CONFIG section of the `libtool'
+# script.  Tagged libtool config variables (even for the LIBTOOL CONFIG
+# section) are produced by _LT_LIBTOOL_TAG_VARS.
+m4_defun([_LT_LIBTOOL_CONFIG_VARS],
+[m4_foreach([_lt_var],
+    m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)),
+    [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])])
+
+
+# _LT_LIBTOOL_TAG_VARS(TAG)
+# -------------------------
+m4_define([_LT_LIBTOOL_TAG_VARS],
+[m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames),
+    [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])])
+
+
+# _LT_TAGVAR(VARNAME, [TAGNAME])
+# ------------------------------
+m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])])
+
+
+# _LT_CONFIG_COMMANDS
+# -------------------
+# Send accumulated output to $CONFIG_STATUS.  Thanks to the lists of
+# variables for single and double quote escaping we saved from calls
+# to _LT_DECL, we can put quote escaped variables declarations
+# into `config.status', and then the shell code to quote escape them in
+# for loops in `config.status'.  Finally, any additional code accumulated
+# from calls to _LT_CONFIG_LIBTOOL_INIT is expanded.
+m4_defun([_LT_CONFIG_COMMANDS],
+[AC_PROVIDE_IFELSE([LT_OUTPUT],
+       dnl If the libtool generation code has been placed in $CONFIG_LT,
+       dnl instead of duplicating it all over again into config.status,
+       dnl then we will have config.status run $CONFIG_LT later, so it
+       dnl needs to know what name is stored there:
+        [AC_CONFIG_COMMANDS([libtool],
+            [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])],
+    dnl If the libtool generation code is destined for config.status,
+    dnl expand the accumulated commands and init code now:
+    [AC_CONFIG_COMMANDS([libtool],
+        [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])])
+])#_LT_CONFIG_COMMANDS
+
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT],
+[
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+sed_quote_subst='$sed_quote_subst'
+double_quote_subst='$double_quote_subst'
+delay_variable_subst='$delay_variable_subst'
+_LT_CONFIG_STATUS_DECLARATIONS
+LTCC='$LTCC'
+LTCFLAGS='$LTCFLAGS'
+compiler='$compiler_DEFAULT'
+
+# Quote evaled strings.
+for var in lt_decl_all_varnames([[ \
+]], lt_decl_quote_varnames); do
+    case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in
+    *[[\\\\\\\`\\"\\\$]]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$sed_quote_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+# Double-quote double-evaled strings.
+for var in lt_decl_all_varnames([[ \
+]], lt_decl_dquote_varnames); do
+    case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in
+    *[[\\\\\\\`\\"\\\$]]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+# Fix-up fallback echo if it was mangled by the above quoting rules.
+case \$lt_ECHO in
+*'\\\[$]0 --fallback-echo"')dnl "
+  lt_ECHO=\`\$ECHO "X\$lt_ECHO" | \$Xsed -e 's/\\\\\\\\\\\\\\\[$]0 --fallback-echo"\[$]/\[$]0 --fallback-echo"/'\`
+  ;;
+esac
+
+_LT_OUTPUT_LIBTOOL_INIT
+])
+
+
+# LT_OUTPUT
+# ---------
+# This macro allows early generation of the libtool script (before
+# AC_OUTPUT is called), incase it is used in configure for compilation
+# tests.
+AC_DEFUN([LT_OUTPUT],
+[: ${CONFIG_LT=./config.lt}
+AC_MSG_NOTICE([creating $CONFIG_LT])
+cat >"$CONFIG_LT" <<_LTEOF
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate a libtool stub with the current configuration.
+
+lt_cl_silent=false
+SHELL=\${CONFIG_SHELL-$SHELL}
+_LTEOF
+
+cat >>"$CONFIG_LT" <<\_LTEOF
+AS_SHELL_SANITIZE
+_AS_PREPARE
+
+exec AS_MESSAGE_FD>&1
+exec AS_MESSAGE_LOG_FD>>config.log
+{
+  echo
+  AS_BOX([Running $as_me.])
+} >&AS_MESSAGE_LOG_FD
+
+lt_cl_help="\
+\`$as_me' creates a local libtool stub from the current configuration,
+for use in further configure time tests before the real libtool is
+generated.
+
+Usage: $[0] [[OPTIONS]]
+
+  -h, --help      print this help, then exit
+  -V, --version   print version number, then exit
+  -q, --quiet     do not print progress messages
+  -d, --debug     don't remove temporary files
+
+Report bugs to <bug-libtool@gnu.org>."
+
+lt_cl_version="\
+m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl
+m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION])
+configured by $[0], generated by m4_PACKAGE_STRING.
+
+Copyright (C) 2008 Free Software Foundation, Inc.
+This config.lt script is free software; the Free Software Foundation
+gives unlimited permision to copy, distribute and modify it."
+
+while test $[#] != 0
+do
+  case $[1] in
+    --version | --v* | -V )
+      echo "$lt_cl_version"; exit 0 ;;
+    --help | --h* | -h )
+      echo "$lt_cl_help"; exit 0 ;;
+    --debug | --d* | -d )
+      debug=: ;;
+    --quiet | --q* | --silent | --s* | -q )
+      lt_cl_silent=: ;;
+
+    -*) AC_MSG_ERROR([unrecognized option: $[1]
+Try \`$[0] --help' for more information.]) ;;
+
+    *) AC_MSG_ERROR([unrecognized argument: $[1]
+Try \`$[0] --help' for more information.]) ;;
+  esac
+  shift
+done
+
+if $lt_cl_silent; then
+  exec AS_MESSAGE_FD>/dev/null
+fi
+_LTEOF
+
+cat >>"$CONFIG_LT" <<_LTEOF
+_LT_OUTPUT_LIBTOOL_COMMANDS_INIT
+_LTEOF
+
+cat >>"$CONFIG_LT" <<\_LTEOF
+AC_MSG_NOTICE([creating $ofile])
+_LT_OUTPUT_LIBTOOL_COMMANDS
+AS_EXIT(0)
+_LTEOF
+chmod +x "$CONFIG_LT"
+
+# configure is writing to config.log, but config.lt does its own redirection,
+# appending to config.log, which fails on DOS, as config.log is still kept
+# open by configure.  Here we exec the FD to /dev/null, effectively closing
+# config.log, so it can be properly (re)opened and appended to by config.lt.
+if test "$no_create" != yes; then
+  lt_cl_success=:
+  test "$silent" = yes &&
+    lt_config_lt_args="$lt_config_lt_args --quiet"
+  exec AS_MESSAGE_LOG_FD>/dev/null
+  $SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false
+  exec AS_MESSAGE_LOG_FD>>config.log
+  $lt_cl_success || AS_EXIT(1)
+fi
+])# LT_OUTPUT
+
+
+# _LT_CONFIG(TAG)
+# ---------------
+# If TAG is the built-in tag, create an initial libtool script with a
+# default configuration from the untagged config vars.  Otherwise add code
+# to config.status for appending the configuration named by TAG from the
+# matching tagged config vars.
+m4_defun([_LT_CONFIG],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+_LT_CONFIG_SAVE_COMMANDS([
+  m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl
+  m4_if(_LT_TAG, [C], [
+    # See if we are running on zsh, and set the options which allow our
+    # commands through without removal of \ escapes.
+    if test -n "${ZSH_VERSION+set}" ; then
+      setopt NO_GLOB_SUBST
+    fi
+
+    cfgfile="${ofile}T"
+    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
+    $RM "$cfgfile"
+
+    cat <<_LT_EOF >> "$cfgfile"
+#! $SHELL
+
+# `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services.
+# Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+# NOTE: Changes made to this file will be lost: look at ltmain.sh.
+#
+_LT_COPYING
+_LT_LIBTOOL_TAGS
+
+# ### BEGIN LIBTOOL CONFIG
+_LT_LIBTOOL_CONFIG_VARS
+_LT_LIBTOOL_TAG_VARS
+# ### END LIBTOOL CONFIG
+
+_LT_EOF
+
+  case $host_os in
+  aix3*)
+    cat <<\_LT_EOF >> "$cfgfile"
+# AIX sometimes has problems with the GCC collect2 program.  For some
+# reason, if we set the COLLECT_NAMES environment variable, the problems
+# vanish in a puff of smoke.
+if test "X${COLLECT_NAMES+set}" != Xset; then
+  COLLECT_NAMES=
+  export COLLECT_NAMES
+fi
+_LT_EOF
+    ;;
+  esac
+
+  _LT_PROG_LTMAIN
+
+  # We use sed instead of cat because bash on DJGPP gets confused if
+  # if finds mixed CR/LF and LF-only lines.  Since sed operates in
+  # text mode, it properly converts lines to CR/LF.  This bash problem
+  # is reportedly fixed, but why not run on old versions too?
+  sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \
+    || (rm -f "$cfgfile"; exit 1)
+
+  _LT_PROG_XSI_SHELLFNS
+
+  sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> "$cfgfile" \
+    || (rm -f "$cfgfile"; exit 1)
+
+  mv -f "$cfgfile" "$ofile" ||
+    (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
+  chmod +x "$ofile"
+],
+[cat <<_LT_EOF >> "$ofile"
+
+dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded
+dnl in a comment (ie after a #).
+# ### BEGIN LIBTOOL TAG CONFIG: $1
+_LT_LIBTOOL_TAG_VARS(_LT_TAG)
+# ### END LIBTOOL TAG CONFIG: $1
+_LT_EOF
+])dnl /m4_if
+],
+[m4_if([$1], [], [
+    PACKAGE='$PACKAGE'
+    VERSION='$VERSION'
+    TIMESTAMP='$TIMESTAMP'
+    RM='$RM'
+    ofile='$ofile'], [])
+])dnl /_LT_CONFIG_SAVE_COMMANDS
+])# _LT_CONFIG
+
+
+# LT_SUPPORTED_TAG(TAG)
+# ---------------------
+# Trace this macro to discover what tags are supported by the libtool
+# --tag option, using:
+#    autoconf --trace 'LT_SUPPORTED_TAG:$1'
+AC_DEFUN([LT_SUPPORTED_TAG], [])
+
+
+# C support is built-in for now
+m4_define([_LT_LANG_C_enabled], [])
+m4_define([_LT_TAGS], [])
+
+
+# LT_LANG(LANG)
+# -------------
+# Enable libtool support for the given language if not already enabled.
+AC_DEFUN([LT_LANG],
+[AC_BEFORE([$0], [LT_OUTPUT])dnl
+m4_case([$1],
+  [C],                 [_LT_LANG(C)],
+  [C++],               [_LT_LANG(CXX)],
+  [Java],              [_LT_LANG(GCJ)],
+  [Fortran 77],                [_LT_LANG(F77)],
+  [Fortran],           [_LT_LANG(FC)],
+  [Windows Resource],  [_LT_LANG(RC)],
+  [m4_ifdef([_LT_LANG_]$1[_CONFIG],
+    [_LT_LANG($1)],
+    [m4_fatal([$0: unsupported language: "$1"])])])dnl
+])# LT_LANG
+
+
+# _LT_LANG(LANGNAME)
+# ------------------
+m4_defun([_LT_LANG],
+[m4_ifdef([_LT_LANG_]$1[_enabled], [],
+  [LT_SUPPORTED_TAG([$1])dnl
+  m4_append([_LT_TAGS], [$1 ])dnl
+  m4_define([_LT_LANG_]$1[_enabled], [])dnl
+  _LT_LANG_$1_CONFIG($1)])dnl
+])# _LT_LANG
+
+
+# _LT_LANG_DEFAULT_CONFIG
+# -----------------------
+m4_defun([_LT_LANG_DEFAULT_CONFIG],
+[AC_PROVIDE_IFELSE([AC_PROG_CXX],
+  [LT_LANG(CXX)],
+  [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])])
+
+AC_PROVIDE_IFELSE([AC_PROG_F77],
+  [LT_LANG(F77)],
+  [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])])
+
+AC_PROVIDE_IFELSE([AC_PROG_FC],
+  [LT_LANG(FC)],
+  [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])])
+
+dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal
+dnl pulling things in needlessly.
+AC_PROVIDE_IFELSE([AC_PROG_GCJ],
+  [LT_LANG(GCJ)],
+  [AC_PROVIDE_IFELSE([A][M_PROG_GCJ],
+    [LT_LANG(GCJ)],
+    [AC_PROVIDE_IFELSE([LT_PROG_GCJ],
+      [LT_LANG(GCJ)],
+      [m4_ifdef([AC_PROG_GCJ],
+       [m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])])
+       m4_ifdef([A][M_PROG_GCJ],
+       [m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])])
+       m4_ifdef([LT_PROG_GCJ],
+       [m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])])
+
+AC_PROVIDE_IFELSE([LT_PROG_RC],
+  [LT_LANG(RC)],
+  [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])])
+])# _LT_LANG_DEFAULT_CONFIG
+
+# Obsolete macros:
+AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)])
+AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)])
+AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)])
+AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_CXX], [])
+dnl AC_DEFUN([AC_LIBTOOL_F77], [])
+dnl AC_DEFUN([AC_LIBTOOL_FC], [])
+dnl AC_DEFUN([AC_LIBTOOL_GCJ], [])
+
+
+# _LT_TAG_COMPILER
+# ----------------
+m4_defun([_LT_TAG_COMPILER],
+[AC_REQUIRE([AC_PROG_CC])dnl
+
+_LT_DECL([LTCC], [CC], [1], [A C compiler])dnl
+_LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl
+_LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl
+_LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+])# _LT_TAG_COMPILER
+
+
+# _LT_COMPILER_BOILERPLATE
+# ------------------------
+# Check for compiler boilerplate output or warnings with
+# the simple compiler test code.
+m4_defun([_LT_COMPILER_BOILERPLATE],
+[m4_require([_LT_DECL_SED])dnl
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$RM conftest*
+])# _LT_COMPILER_BOILERPLATE
+
+
+# _LT_LINKER_BOILERPLATE
+# ----------------------
+# Check for linker boilerplate output or warnings with
+# the simple link test code.
+m4_defun([_LT_LINKER_BOILERPLATE],
+[m4_require([_LT_DECL_SED])dnl
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$RM -r conftest*
+])# _LT_LINKER_BOILERPLATE
+
+# _LT_REQUIRED_DARWIN_CHECKS
+# -------------------------
+m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[
+  case $host_os in
+    rhapsody* | darwin*)
+    AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:])
+    AC_CHECK_TOOL([NMEDIT], [nmedit], [:])
+    AC_CHECK_TOOL([LIPO], [lipo], [:])
+    AC_CHECK_TOOL([OTOOL], [otool], [:])
+    AC_CHECK_TOOL([OTOOL64], [otool64], [:])
+    _LT_DECL([], [DSYMUTIL], [1],
+      [Tool to manipulate archived DWARF debug symbol files on Mac OS X])
+    _LT_DECL([], [NMEDIT], [1],
+      [Tool to change global to local symbols on Mac OS X])
+    _LT_DECL([], [LIPO], [1],
+      [Tool to manipulate fat objects and archives on Mac OS X])
+    _LT_DECL([], [OTOOL], [1],
+      [ldd/readelf like tool for Mach-O binaries on Mac OS X])
+    _LT_DECL([], [OTOOL64], [1],
+      [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4])
+
+    AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod],
+      [lt_cv_apple_cc_single_mod=no
+      if test -z "${LT_MULTI_MODULE}"; then
+       # By default we will add the -single_module flag. You can override
+       # by either setting the environment variable LT_MULTI_MODULE
+       # non-empty at configure time, or by adding -multi_module to the
+       # link flags.
+       rm -rf libconftest.dylib*
+       echo "int foo(void){return 1;}" > conftest.c
+       echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+-dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD
+       $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+         -dynamiclib -Wl,-single_module conftest.c 2>conftest.err
+        _lt_result=$?
+       if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then
+         lt_cv_apple_cc_single_mod=yes
+       else
+         cat conftest.err >&AS_MESSAGE_LOG_FD
+       fi
+       rm -rf libconftest.dylib*
+       rm -f conftest.*
+      fi])
+    AC_CACHE_CHECK([for -exported_symbols_list linker flag],
+      [lt_cv_ld_exported_symbols_list],
+      [lt_cv_ld_exported_symbols_list=no
+      save_LDFLAGS=$LDFLAGS
+      echo "_main" > conftest.sym
+      LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym"
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
+       [lt_cv_ld_exported_symbols_list=yes],
+       [lt_cv_ld_exported_symbols_list=no])
+       LDFLAGS="$save_LDFLAGS"
+    ])
+    case $host_os in
+    rhapsody* | darwin1.[[012]])
+      _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;;
+    darwin1.*)
+      _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+    darwin*) # darwin 5.x on
+      # if running on 10.5 or later, the deployment target defaults
+      # to the OS version, if on x86, and 10.4, the deployment
+      # target defaults to 10.4. Don't you love it?
+      case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
+       10.0,*86*-darwin8*|10.0,*-darwin[[91]]*)
+         _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+       10.[[012]]*)
+         _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+       10.*)
+         _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+      esac
+    ;;
+  esac
+    if test "$lt_cv_apple_cc_single_mod" = "yes"; then
+      _lt_dar_single_mod='$single_module'
+    fi
+    if test "$lt_cv_ld_exported_symbols_list" = "yes"; then
+      _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym'
+    else
+      _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}'
+    fi
+    if test "$DSYMUTIL" != ":"; then
+      _lt_dsymutil='~$DSYMUTIL $lib || :'
+    else
+      _lt_dsymutil=
+    fi
+    ;;
+  esac
+])
+
+
+# _LT_DARWIN_LINKER_FEATURES
+# --------------------------
+# Checks for linker and compiler features on darwin
+m4_defun([_LT_DARWIN_LINKER_FEATURES],
+[
+  m4_require([_LT_REQUIRED_DARWIN_CHECKS])
+  _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+  _LT_TAGVAR(hardcode_direct, $1)=no
+  _LT_TAGVAR(hardcode_automatic, $1)=yes
+  _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+  _LT_TAGVAR(whole_archive_flag_spec, $1)=''
+  _LT_TAGVAR(link_all_deplibs, $1)=yes
+  _LT_TAGVAR(allow_undefined_flag, $1)="$_lt_dar_allow_undefined"
+  case $cc_basename in
+     ifort*) _lt_dar_can_shared=yes ;;
+     *) _lt_dar_can_shared=$GCC ;;
+  esac
+  if test "$_lt_dar_can_shared" = "yes"; then
+    output_verbose_link_cmd=echo
+    _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}"
+    _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}"
+    _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}"
+    _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}"
+    m4_if([$1], [CXX],
+[   if test "$lt_cv_apple_cc_single_mod" != "yes"; then
+      _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}"
+      _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}"
+    fi
+],[])
+  else
+  _LT_TAGVAR(ld_shlibs, $1)=no
+  fi
+])
+
+# _LT_SYS_MODULE_PATH_AIX
+# -----------------------
+# Links a minimal program and checks the executable
+# for the system default hardcoded library path. In most cases,
+# this is /usr/lib:/lib, but when the MPI compilers are used
+# the location of the communication and MPI libs are included too.
+# If we don't find anything, use the default library path according
+# to the aix ld manual.
+m4_defun([_LT_SYS_MODULE_PATH_AIX],
+[m4_require([_LT_DECL_SED])dnl
+AC_LINK_IFELSE(AC_LANG_PROGRAM,[
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+       /^0/ {
+           s/^0  *\(.*\)$/\1/
+           p
+       }
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi],[])
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+])# _LT_SYS_MODULE_PATH_AIX
+
+
+# _LT_SHELL_INIT(ARG)
+# -------------------
+m4_define([_LT_SHELL_INIT],
+[ifdef([AC_DIVERSION_NOTICE],
+            [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)],
+        [AC_DIVERT_PUSH(NOTICE)])
+$1
+AC_DIVERT_POP
+])# _LT_SHELL_INIT
+
+
+# _LT_PROG_ECHO_BACKSLASH
+# -----------------------
+# Add some code to the start of the generated configure script which
+# will find an echo command which doesn't interpret backslashes.
+m4_defun([_LT_PROG_ECHO_BACKSLASH],
+[_LT_SHELL_INIT([
+# Check that we are running under the correct shell.
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+case X$lt_ECHO in
+X*--fallback-echo)
+  # Remove one level of quotation (which was required for Make).
+  ECHO=`echo "$lt_ECHO" | sed 's,\\\\\[$]\\[$]0,'[$]0','`
+  ;;
+esac
+
+ECHO=${lt_ECHO-echo}
+if test "X[$]1" = X--no-reexec; then
+  # Discard the --no-reexec flag, and continue.
+  shift
+elif test "X[$]1" = X--fallback-echo; then
+  # Avoid inline document here, it may be left over
+  :
+elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then
+  # Yippee, $ECHO works!
+  :
+else
+  # Restart under the correct shell.
+  exec $SHELL "[$]0" --no-reexec ${1+"[$]@"}
+fi
+
+if test "X[$]1" = X--fallback-echo; then
+  # used as fallback echo
+  shift
+  cat <<_LT_EOF
+[$]*
+_LT_EOF
+  exit 0
+fi
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+if test -z "$lt_ECHO"; then
+  if test "X${echo_test_string+set}" != Xset; then
+    # find a string as large as possible, as long as the shell can cope with it
+    for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q "[$]0"' 'echo test'; do
+      # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ...
+      if { echo_test_string=`eval $cmd`; } 2>/dev/null &&
+        { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null
+      then
+        break
+      fi
+    done
+  fi
+
+  if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
+     echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
+     test "X$echo_testing_string" = "X$echo_test_string"; then
+    :
+  else
+    # The Solaris, AIX, and Digital Unix default echo programs unquote
+    # backslashes.  This makes it impossible to quote backslashes using
+    #   echo "$something" | sed 's/\\/\\\\/g'
+    #
+    # So, first we look for a working echo in the user's PATH.
+
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for dir in $PATH /usr/ucb; do
+      IFS="$lt_save_ifs"
+      if (test -f $dir/echo || test -f $dir/echo$ac_exeext) &&
+         test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' &&
+         echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` &&
+         test "X$echo_testing_string" = "X$echo_test_string"; then
+        ECHO="$dir/echo"
+        break
+      fi
+    done
+    IFS="$lt_save_ifs"
+
+    if test "X$ECHO" = Xecho; then
+      # We didn't find a better echo, so look for alternatives.
+      if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' &&
+         echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` &&
+         test "X$echo_testing_string" = "X$echo_test_string"; then
+        # This shell has a builtin print -r that does the trick.
+        ECHO='print -r'
+      elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } &&
+          test "X$CONFIG_SHELL" != X/bin/ksh; then
+        # If we have ksh, try running configure again with it.
+        ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
+        export ORIGINAL_CONFIG_SHELL
+        CONFIG_SHELL=/bin/ksh
+        export CONFIG_SHELL
+        exec $CONFIG_SHELL "[$]0" --no-reexec ${1+"[$]@"}
+      else
+        # Try using printf.
+        ECHO='printf %s\n'
+        if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
+          echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
+          test "X$echo_testing_string" = "X$echo_test_string"; then
+         # Cool, printf works
+         :
+        elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` &&
+            test "X$echo_testing_string" = 'X\t' &&
+            echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
+            test "X$echo_testing_string" = "X$echo_test_string"; then
+         CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL
+         export CONFIG_SHELL
+         SHELL="$CONFIG_SHELL"
+         export SHELL
+         ECHO="$CONFIG_SHELL [$]0 --fallback-echo"
+        elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` &&
+            test "X$echo_testing_string" = 'X\t' &&
+            echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
+            test "X$echo_testing_string" = "X$echo_test_string"; then
+         ECHO="$CONFIG_SHELL [$]0 --fallback-echo"
+        else
+         # maybe with a smaller string...
+         prev=:
+
+         for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q "[$]0"' 'sed 50q "[$]0"'; do
+           if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null
+           then
+             break
+           fi
+           prev="$cmd"
+         done
+
+         if test "$prev" != 'sed 50q "[$]0"'; then
+           echo_test_string=`eval $prev`
+           export echo_test_string
+           exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "[$]0" ${1+"[$]@"}
+         else
+           # Oops.  We lost completely, so just stick with echo.
+           ECHO=echo
+         fi
+        fi
+      fi
+    fi
+  fi
+fi
+
+# Copy echo and quote the copy suitably for passing to libtool from
+# the Makefile, instead of quoting the original, which is used later.
+lt_ECHO=$ECHO
+if test "X$lt_ECHO" = "X$CONFIG_SHELL [$]0 --fallback-echo"; then
+   lt_ECHO="$CONFIG_SHELL \\\$\[$]0 --fallback-echo"
+fi
+
+AC_SUBST(lt_ECHO)
+])
+_LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts])
+_LT_DECL([], [ECHO], [1],
+    [An echo program that does not interpret backslashes])
+])# _LT_PROG_ECHO_BACKSLASH
+
+
+# _LT_ENABLE_LOCK
+# ---------------
+m4_defun([_LT_ENABLE_LOCK],
+[AC_ARG_ENABLE([libtool-lock],
+  [AS_HELP_STRING([--disable-libtool-lock],
+    [avoid locking (might break parallel builds)])])
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
+
+# Some flags need to be propagated to the compiler or linker for good
+# libtool support.
+case $host in
+ia64-*-hpux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.$ac_objext` in
+      *ELF-32*)
+       HPUX_IA64_MODE="32"
+       ;;
+      *ELF-64*)
+       HPUX_IA64_MODE="64"
+       ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+*-*-irix6*)
+  # Find out which ABI we are using.
+  echo '[#]line __oline__ "configure"' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    if test "$lt_cv_prog_gnu_ld" = yes; then
+      case `/usr/bin/file conftest.$ac_objext` in
+       *32-bit*)
+         LD="${LD-ld} -melf32bsmip"
+         ;;
+       *N32*)
+         LD="${LD-ld} -melf32bmipn32"
+         ;;
+       *64-bit*)
+         LD="${LD-ld} -melf64bmip"
+       ;;
+      esac
+    else
+      case `/usr/bin/file conftest.$ac_objext` in
+       *32-bit*)
+         LD="${LD-ld} -32"
+         ;;
+       *N32*)
+         LD="${LD-ld} -n32"
+         ;;
+       *64-bit*)
+         LD="${LD-ld} -64"
+         ;;
+      esac
+    fi
+  fi
+  rm -rf conftest*
+  ;;
+
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
+s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.o` in
+      *32-bit*)
+       case $host in
+         x86_64-*kfreebsd*-gnu)
+           LD="${LD-ld} -m elf_i386_fbsd"
+           ;;
+         x86_64-*linux*)
+           LD="${LD-ld} -m elf_i386"
+           ;;
+         ppc64-*linux*|powerpc64-*linux*)
+           LD="${LD-ld} -m elf32ppclinux"
+           ;;
+         s390x-*linux*)
+           LD="${LD-ld} -m elf_s390"
+           ;;
+         sparc64-*linux*)
+           LD="${LD-ld} -m elf32_sparc"
+           ;;
+       esac
+       ;;
+      *64-bit*)
+       case $host in
+         x86_64-*kfreebsd*-gnu)
+           LD="${LD-ld} -m elf_x86_64_fbsd"
+           ;;
+         x86_64-*linux*)
+           LD="${LD-ld} -m elf_x86_64"
+           ;;
+         ppc*-*linux*|powerpc*-*linux*)
+           LD="${LD-ld} -m elf64ppc"
+           ;;
+         s390*-*linux*|s390*-*tpf*)
+           LD="${LD-ld} -m elf64_s390"
+           ;;
+         sparc*-*linux*)
+           LD="${LD-ld} -m elf64_sparc"
+           ;;
+       esac
+       ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+
+*-*-sco3.2v5*)
+  # On SCO OpenServer 5, we need -belf to get full-featured binaries.
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -belf"
+  AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf,
+    [AC_LANG_PUSH(C)
+     AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no])
+     AC_LANG_POP])
+  if test x"$lt_cv_cc_needs_belf" != x"yes"; then
+    # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
+    CFLAGS="$SAVE_CFLAGS"
+  fi
+  ;;
+sparc*-*solaris*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.o` in
+    *64-bit*)
+      case $lt_cv_prog_gnu_ld in
+      yes*) LD="${LD-ld} -m elf64_sparc" ;;
+      *)
+       if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then
+         LD="${LD-ld} -64"
+       fi
+       ;;
+      esac
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+esac
+
+need_locks="$enable_libtool_lock"
+])# _LT_ENABLE_LOCK
+
+
+# _LT_CMD_OLD_ARCHIVE
+# -------------------
+m4_defun([_LT_CMD_OLD_ARCHIVE],
+[AC_CHECK_TOOL(AR, ar, false)
+test -z "$AR" && AR=ar
+test -z "$AR_FLAGS" && AR_FLAGS=cru
+_LT_DECL([], [AR], [1], [The archiver])
+_LT_DECL([], [AR_FLAGS], [1])
+
+AC_CHECK_TOOL(STRIP, strip, :)
+test -z "$STRIP" && STRIP=:
+_LT_DECL([], [STRIP], [1], [A symbol stripping program])
+
+AC_CHECK_TOOL(RANLIB, ranlib, :)
+test -z "$RANLIB" && RANLIB=:
+_LT_DECL([], [RANLIB], [1],
+    [Commands used to install an old-style archive])
+
+# Determine commands to create old-style static archives.
+old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs'
+old_postinstall_cmds='chmod 644 $oldlib'
+old_postuninstall_cmds=
+
+if test -n "$RANLIB"; then
+  case $host_os in
+  openbsd*)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib"
+    ;;
+  *)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib"
+    ;;
+  esac
+  old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib"
+fi
+_LT_DECL([], [old_postinstall_cmds], [2])
+_LT_DECL([], [old_postuninstall_cmds], [2])
+_LT_TAGDECL([], [old_archive_cmds], [2],
+    [Commands used to build an old-style archive])
+])# _LT_CMD_OLD_ARCHIVE
+
+
+# _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
+#              [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE])
+# ----------------------------------------------------------------
+# Check whether the given compiler option works
+AC_DEFUN([_LT_COMPILER_OPTION],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_SED])dnl
+AC_CACHE_CHECK([$1], [$2],
+  [$2=no
+   m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4])
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="$3"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&AS_MESSAGE_LOG_FD
+   echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       $2=yes
+     fi
+   fi
+   $RM conftest*
+])
+
+if test x"[$]$2" = xyes; then
+    m4_if([$5], , :, [$5])
+else
+    m4_if([$6], , :, [$6])
+fi
+])# _LT_COMPILER_OPTION
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], [])
+
+
+# _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
+#                  [ACTION-SUCCESS], [ACTION-FAILURE])
+# ----------------------------------------------------
+# Check whether the given linker option works
+AC_DEFUN([_LT_LINKER_OPTION],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_SED])dnl
+AC_CACHE_CHECK([$1], [$2],
+  [$2=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $3"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&AS_MESSAGE_LOG_FD
+       $ECHO "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         $2=yes
+       fi
+     else
+       $2=yes
+     fi
+   fi
+   $RM -r conftest*
+   LDFLAGS="$save_LDFLAGS"
+])
+
+if test x"[$]$2" = xyes; then
+    m4_if([$4], , :, [$4])
+else
+    m4_if([$5], , :, [$5])
+fi
+])# _LT_LINKER_OPTION
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], [])
+
+
+# LT_CMD_MAX_LEN
+#---------------
+AC_DEFUN([LT_CMD_MAX_LEN],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+# find the maximum length of command line arguments
+AC_MSG_CHECKING([the maximum length of command line arguments])
+AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl
+  i=0
+  teststring="ABCD"
+
+  case $build_os in
+  msdosdjgpp*)
+    # On DJGPP, this test can blow up pretty badly due to problems in libc
+    # (any single argument exceeding 2000 bytes causes a buffer overrun
+    # during glob expansion).  Even if it were fixed, the result of this
+    # check would be larger than it should be.
+    lt_cv_sys_max_cmd_len=12288;    # 12K is about right
+    ;;
+
+  gnu*)
+    # Under GNU Hurd, this test is not required because there is
+    # no limit to the length of command line arguments.
+    # Libtool will interpret -1 as no limit whatsoever
+    lt_cv_sys_max_cmd_len=-1;
+    ;;
+
+  cygwin* | mingw* | cegcc*)
+    # On Win9x/ME, this test blows up -- it succeeds, but takes
+    # about 5 minutes as the teststring grows exponentially.
+    # Worse, since 9x/ME are not pre-emptively multitasking,
+    # you end up with a "frozen" computer, even though with patience
+    # the test eventually succeeds (with a max line length of 256k).
+    # Instead, let's just punt: use the minimum linelength reported by
+    # all of the supported platforms: 8192 (on NT/2K/XP).
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  amigaos*)
+    # On AmigaOS with pdksh, this test takes hours, literally.
+    # So we just punt and use a minimum line length of 8192.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
+    # This has been around since 386BSD, at least.  Likely further.
+    if test -x /sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
+    elif test -x /usr/sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
+    else
+      lt_cv_sys_max_cmd_len=65536      # usable default for all BSDs
+    fi
+    # And add a safety zone
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    ;;
+
+  interix*)
+    # We know the value 262144 and hardcode it with a safety zone (like BSD)
+    lt_cv_sys_max_cmd_len=196608
+    ;;
+
+  osf*)
+    # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
+    # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
+    # nice to cause kernel panics so lets avoid the loop below.
+    # First set a reasonable default.
+    lt_cv_sys_max_cmd_len=16384
+    #
+    if test -x /sbin/sysconfig; then
+      case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
+        *1*) lt_cv_sys_max_cmd_len=-1 ;;
+      esac
+    fi
+    ;;
+  sco3.2v5*)
+    lt_cv_sys_max_cmd_len=102400
+    ;;
+  sysv5* | sco5v6* | sysv4.2uw2*)
+    kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null`
+    if test -n "$kargmax"; then
+      lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[        ]]//'`
+    else
+      lt_cv_sys_max_cmd_len=32768
+    fi
+    ;;
+  *)
+    lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
+    if test -n "$lt_cv_sys_max_cmd_len"; then
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    else
+      # Make teststring a little bigger before we do anything with it.
+      # a 1K string should be a reasonable start.
+      for i in 1 2 3 4 5 6 7 8 ; do
+        teststring=$teststring$teststring
+      done
+      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
+      # If test is not a shell built-in, we'll probably end up computing a
+      # maximum length that is only half of the actual maximum length, but
+      # we can't tell.
+      while { test "X"`$SHELL [$]0 --fallback-echo "X$teststring$teststring" 2>/dev/null` \
+                = "XX$teststring$teststring"; } >/dev/null 2>&1 &&
+             test $i != 17 # 1/2 MB should be enough
+      do
+        i=`expr $i + 1`
+        teststring=$teststring$teststring
+      done
+      # Only check the string length outside the loop.
+      lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1`
+      teststring=
+      # Add a significant safety factor because C++ compilers can tack on
+      # massive amounts of additional arguments before passing them to the
+      # linker.  It appears as though 1/2 is a usable value.
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
+    fi
+    ;;
+  esac
+])
+if test -n $lt_cv_sys_max_cmd_len ; then
+  AC_MSG_RESULT($lt_cv_sys_max_cmd_len)
+else
+  AC_MSG_RESULT(none)
+fi
+max_cmd_len=$lt_cv_sys_max_cmd_len
+_LT_DECL([], [max_cmd_len], [0],
+    [What is the maximum length of a command?])
+])# LT_CMD_MAX_LEN
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], [])
+
+
+# _LT_HEADER_DLFCN
+# ----------------
+m4_defun([_LT_HEADER_DLFCN],
+[AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl
+])# _LT_HEADER_DLFCN
+
+
+# _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE,
+#                      ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING)
+# ----------------------------------------------------------------
+m4_defun([_LT_TRY_DLOPEN_SELF],
+[m4_require([_LT_HEADER_DLFCN])dnl
+if test "$cross_compiling" = yes; then :
+  [$4]
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<_LT_EOF
+[#line __oline__ "configure"
+#include "confdefs.h"
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL          RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL                DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL                0
+#  endif
+#endif
+
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW           RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW         DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW       RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW     DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW     0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+void fnord() { int i=42;}
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
+
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
+
+  return status;
+}]
+_LT_EOF
+  if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) $1 ;;
+      x$lt_dlneed_uscore) $2 ;;
+      x$lt_dlunknown|x*) $3 ;;
+    esac
+  else :
+    # compilation failed
+    $3
+  fi
+fi
+rm -fr conftest*
+])# _LT_TRY_DLOPEN_SELF
+
+
+# LT_SYS_DLOPEN_SELF
+# ------------------
+AC_DEFUN([LT_SYS_DLOPEN_SELF],
+[m4_require([_LT_HEADER_DLFCN])dnl
+if test "x$enable_dlopen" != xyes; then
+  enable_dlopen=unknown
+  enable_dlopen_self=unknown
+  enable_dlopen_self_static=unknown
+else
+  lt_cv_dlopen=no
+  lt_cv_dlopen_libs=
+
+  case $host_os in
+  beos*)
+    lt_cv_dlopen="load_add_on"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ;;
+
+  mingw* | pw32* | cegcc*)
+    lt_cv_dlopen="LoadLibrary"
+    lt_cv_dlopen_libs=
+    ;;
+
+  cygwin*)
+    lt_cv_dlopen="dlopen"
+    lt_cv_dlopen_libs=
+    ;;
+
+  darwin*)
+  # if libdl is installed we need to link against it
+    AC_CHECK_LIB([dl], [dlopen],
+               [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[
+    lt_cv_dlopen="dyld"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ])
+    ;;
+
+  *)
+    AC_CHECK_FUNC([shl_load],
+         [lt_cv_dlopen="shl_load"],
+      [AC_CHECK_LIB([dld], [shl_load],
+           [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"],
+       [AC_CHECK_FUNC([dlopen],
+             [lt_cv_dlopen="dlopen"],
+         [AC_CHECK_LIB([dl], [dlopen],
+               [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],
+           [AC_CHECK_LIB([svld], [dlopen],
+                 [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"],
+             [AC_CHECK_LIB([dld], [dld_link],
+                   [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"])
+             ])
+           ])
+         ])
+       ])
+      ])
+    ;;
+  esac
+
+  if test "x$lt_cv_dlopen" != xno; then
+    enable_dlopen=yes
+  else
+    enable_dlopen=no
+  fi
+
+  case $lt_cv_dlopen in
+  dlopen)
+    save_CPPFLAGS="$CPPFLAGS"
+    test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
+
+    save_LDFLAGS="$LDFLAGS"
+    wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
+
+    save_LIBS="$LIBS"
+    LIBS="$lt_cv_dlopen_libs $LIBS"
+
+    AC_CACHE_CHECK([whether a program can dlopen itself],
+         lt_cv_dlopen_self, [dnl
+         _LT_TRY_DLOPEN_SELF(
+           lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes,
+           lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross)
+    ])
+
+    if test "x$lt_cv_dlopen_self" = xyes; then
+      wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
+      AC_CACHE_CHECK([whether a statically linked program can dlopen itself],
+         lt_cv_dlopen_self_static, [dnl
+         _LT_TRY_DLOPEN_SELF(
+           lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes,
+           lt_cv_dlopen_self_static=no,  lt_cv_dlopen_self_static=cross)
+      ])
+    fi
+
+    CPPFLAGS="$save_CPPFLAGS"
+    LDFLAGS="$save_LDFLAGS"
+    LIBS="$save_LIBS"
+    ;;
+  esac
+
+  case $lt_cv_dlopen_self in
+  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
+  *) enable_dlopen_self=unknown ;;
+  esac
+
+  case $lt_cv_dlopen_self_static in
+  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
+  *) enable_dlopen_self_static=unknown ;;
+  esac
+fi
+_LT_DECL([dlopen_support], [enable_dlopen], [0],
+        [Whether dlopen is supported])
+_LT_DECL([dlopen_self], [enable_dlopen_self], [0],
+        [Whether dlopen of programs is supported])
+_LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0],
+        [Whether dlopen of statically linked programs is supported])
+])# LT_SYS_DLOPEN_SELF
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], [])
+
+
+# _LT_COMPILER_C_O([TAGNAME])
+# ---------------------------
+# Check to see if options -c and -o are simultaneously supported by compiler.
+# This macro does not hard code the compiler like AC_PROG_CC_C_O.
+m4_defun([_LT_COMPILER_C_O],
+[m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext],
+  [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)],
+  [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no
+   $RM -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&AS_MESSAGE_LOG_FD
+   echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
+     fi
+   fi
+   chmod u+w . 2>&AS_MESSAGE_LOG_FD
+   $RM conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
+   $RM out/* && rmdir out
+   cd ..
+   $RM -r conftest
+   $RM conftest*
+])
+_LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1],
+       [Does compiler simultaneously support -c and -o options?])
+])# _LT_COMPILER_C_O
+
+
+# _LT_COMPILER_FILE_LOCKS([TAGNAME])
+# ----------------------------------
+# Check to see if we can do hard links to lock some files if needed
+m4_defun([_LT_COMPILER_FILE_LOCKS],
+[m4_require([_LT_ENABLE_LOCK])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+_LT_COMPILER_C_O([$1])
+
+hard_links="nottested"
+if test "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then
+  # do not overwrite the value of need_locks provided by the user
+  AC_MSG_CHECKING([if we can lock with hard links])
+  hard_links=yes
+  $RM conftest*
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  touch conftest.a
+  ln conftest.a conftest.b 2>&5 || hard_links=no
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  AC_MSG_RESULT([$hard_links])
+  if test "$hard_links" = no; then
+    AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe])
+    need_locks=warn
+  fi
+else
+  need_locks=no
+fi
+_LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?])
+])# _LT_COMPILER_FILE_LOCKS
+
+
+# _LT_CHECK_OBJDIR
+# ----------------
+m4_defun([_LT_CHECK_OBJDIR],
+[AC_CACHE_CHECK([for objdir], [lt_cv_objdir],
+[rm -f .libs 2>/dev/null
+mkdir .libs 2>/dev/null
+if test -d .libs; then
+  lt_cv_objdir=.libs
+else
+  # MS-DOS does not allow filenames that begin with a dot.
+  lt_cv_objdir=_libs
+fi
+rmdir .libs 2>/dev/null])
+objdir=$lt_cv_objdir
+_LT_DECL([], [objdir], [0],
+         [The name of the directory that contains temporary libtool files])dnl
+m4_pattern_allow([LT_OBJDIR])dnl
+AC_DEFINE_UNQUOTED(LT_OBJDIR, "$lt_cv_objdir/",
+  [Define to the sub-directory in which libtool stores uninstalled libraries.])
+])# _LT_CHECK_OBJDIR
+
+
+# _LT_LINKER_HARDCODE_LIBPATH([TAGNAME])
+# --------------------------------------
+# Check hardcoding attributes.
+m4_defun([_LT_LINKER_HARDCODE_LIBPATH],
+[AC_MSG_CHECKING([how to hardcode library paths into programs])
+_LT_TAGVAR(hardcode_action, $1)=
+if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" ||
+   test -n "$_LT_TAGVAR(runpath_var, $1)" ||
+   test "X$_LT_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then
+
+  # We can hardcode non-existent directories.
+  if test "$_LT_TAGVAR(hardcode_direct, $1)" != no &&
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
+     # have to relink, otherwise we might link with an installed library
+     # when we should be linking with a yet-to-be-installed one
+     ## test "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" != no &&
+     test "$_LT_TAGVAR(hardcode_minus_L, $1)" != no; then
+    # Linking always hardcodes the temporary library directory.
+    _LT_TAGVAR(hardcode_action, $1)=relink
+  else
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
+    _LT_TAGVAR(hardcode_action, $1)=immediate
+  fi
+else
+  # We cannot hardcode anything, or else we can only hardcode existing
+  # directories.
+  _LT_TAGVAR(hardcode_action, $1)=unsupported
+fi
+AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)])
+
+if test "$_LT_TAGVAR(hardcode_action, $1)" = relink ||
+   test "$_LT_TAGVAR(inherit_rpath, $1)" = yes; then
+  # Fast installation is not supported
+  enable_fast_install=no
+elif test "$shlibpath_overrides_runpath" = yes ||
+     test "$enable_shared" = no; then
+  # Fast installation is not necessary
+  enable_fast_install=needless
+fi
+_LT_TAGDECL([], [hardcode_action], [0],
+    [How to hardcode a shared library path into an executable])
+])# _LT_LINKER_HARDCODE_LIBPATH
+
+
+# _LT_CMD_STRIPLIB
+# ----------------
+m4_defun([_LT_CMD_STRIPLIB],
+[m4_require([_LT_DECL_EGREP])
+striplib=
+old_striplib=
+AC_MSG_CHECKING([whether stripping libraries is possible])
+if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then
+  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
+  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
+  AC_MSG_RESULT([yes])
+else
+# FIXME - insert some real tests, host_os isn't really good enough
+  case $host_os in
+  darwin*)
+    if test -n "$STRIP" ; then
+      striplib="$STRIP -x"
+      old_striplib="$STRIP -S"
+      AC_MSG_RESULT([yes])
+    else
+      AC_MSG_RESULT([no])
+    fi
+    ;;
+  *)
+    AC_MSG_RESULT([no])
+    ;;
+  esac
+fi
+_LT_DECL([], [old_striplib], [1], [Commands to strip libraries])
+_LT_DECL([], [striplib], [1])
+])# _LT_CMD_STRIPLIB
+
+
+# _LT_SYS_DYNAMIC_LINKER([TAG])
+# -----------------------------
+# PORTME Fill in your ld.so characteristics
+m4_defun([_LT_SYS_DYNAMIC_LINKER],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_OBJDUMP])dnl
+m4_require([_LT_DECL_SED])dnl
+AC_MSG_CHECKING([dynamic linker characteristics])
+m4_if([$1],
+       [], [
+if test "$GCC" = yes; then
+  case $host_os in
+    darwin*) lt_awk_arg="/^libraries:/,/LR/" ;;
+    *) lt_awk_arg="/^libraries:/" ;;
+  esac
+  lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+  if $ECHO "$lt_search_path_spec" | $GREP ';' >/dev/null ; then
+    # if the path contains ";" then we assume it to be the separator
+    # otherwise default to the standard path separator (i.e. ":") - it is
+    # assumed that no part of a normal pathname contains ";" but that should
+    # okay in the real world where ";" in dirpaths is itself problematic.
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e 's/;/ /g'`
+  else
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+  fi
+  # Ok, now we have the path, separated by spaces, we can step through it
+  # and add multilib dir if necessary.
+  lt_tmp_lt_search_path_spec=
+  lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null`
+  for lt_sys_path in $lt_search_path_spec; do
+    if test -d "$lt_sys_path/$lt_multi_os_dir"; then
+      lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir"
+    else
+      test -d "$lt_sys_path" && \
+       lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path"
+    fi
+  done
+  lt_search_path_spec=`$ECHO $lt_tmp_lt_search_path_spec | awk '
+BEGIN {RS=" "; FS="/|\n";} {
+  lt_foo="";
+  lt_count=0;
+  for (lt_i = NF; lt_i > 0; lt_i--) {
+    if ($lt_i != "" && $lt_i != ".") {
+      if ($lt_i == "..") {
+        lt_count++;
+      } else {
+        if (lt_count == 0) {
+          lt_foo="/" $lt_i lt_foo;
+        } else {
+          lt_count--;
+        }
+      }
+    }
+  }
+  if (lt_foo != "") { lt_freq[[lt_foo]]++; }
+  if (lt_freq[[lt_foo]] == 1) { print lt_foo; }
+}'`
+  sys_lib_search_path_spec=`$ECHO $lt_search_path_spec`
+else
+  sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
+fi])
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+shrext_cmds=".so"
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+shlibpath_overrides_runpath=unknown
+version_type=none
+dynamic_linker="$host_os ld.so"
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
+need_lib_prefix=unknown
+hardcode_into_libs=no
+
+# when you set need_version to no, make sure it does not cause -set_version
+# flags to be left without arguments
+need_version=unknown
+
+case $host_os in
+aix3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
+  shlibpath_var=LIBPATH
+
+  # AIX 3 has no versioning support, so we append a major version to the name.
+  soname_spec='${libname}${release}${shared_ext}$major'
+  ;;
+
+aix[[4-9]]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  hardcode_into_libs=yes
+  if test "$host_cpu" = ia64; then
+    # AIX 5 supports IA64
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
+    shlibpath_var=LD_LIBRARY_PATH
+  else
+    # With GCC up to 2.95.x, collect2 would create an import file
+    # for dependence libraries.  The import file would start with
+    # the line `#! .'.  This would cause the generated library to
+    # depend on `.', always an invalid library.  This was fixed in
+    # development snapshots of GCC prior to 3.0.
+    case $host_os in
+      aix4 | aix4.[[01]] | aix4.[[01]].*)
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
+          echo ' yes '
+          echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then
+       :
+      else
+       can_build_shared=no
+      fi
+      ;;
+    esac
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
+    # soname into executable. Probably we can add versioning support to
+    # collect2, so additional links can be useful in future.
+    if test "$aix_use_runtimelinking" = yes; then
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
+      # instead of lib<name>.a to let people know that these are not
+      # typical AIX shared libraries.
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    else
+      # We preserve .a as extension for shared libraries through AIX4.2
+      # and later when we are not doing run time linking.
+      library_names_spec='${libname}${release}.a $libname.a'
+      soname_spec='${libname}${release}${shared_ext}$major'
+    fi
+    shlibpath_var=LIBPATH
+  fi
+  ;;
+
+amigaos*)
+  case $host_cpu in
+  powerpc)
+    # Since July 2007 AmigaOS4 officially supports .so libraries.
+    # When compiling the executable, add -use-dynld -Lsobjs: to the compileline.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    ;;
+  m68k)
+    library_names_spec='$libname.ixlibrary $libname.a'
+    # Create ${libname}_ixlibrary.a entries in /sys/libs.
+    finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$ECHO "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
+    ;;
+  esac
+  ;;
+
+beos*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  ;;
+
+bsdi[[45]]*)
+  version_type=linux
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
+  # the default ld.so.conf also contains /usr/contrib/lib and
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
+  # libtool to hard-code these into programs
+  ;;
+
+cygwin* | mingw* | pw32* | cegcc*)
+  version_type=windows
+  shrext_cmds=".dll"
+  need_version=no
+  need_lib_prefix=no
+
+  case $GCC,$host_os in
+  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
+    library_names_spec='$libname.dll.a'
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname~
+      chmod a+x \$dldir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
+      fi'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $RM \$dlpath'
+    shlibpath_overrides_runpath=yes
+
+    case $host_os in
+    cygwin*)
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib"
+      ;;
+    mingw* | cegcc*)
+      # MinGW DLLs use traditional 'lib' prefix
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec=`$CC -print-search-dirs | $GREP "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+      if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then
+        # It is most probably a Windows format PATH printed by
+        # mingw gcc, but we are running on Cygwin. Gcc prints its search
+        # path with ; separators, and with drive letters. We can handle the
+        # drive letters (cygwin fileutils understands them), so leave them,
+        # especially as we might pass files found there to a mingw objdump,
+        # which wouldn't understand a cygwinified path. Ahh.
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
+      else
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+      fi
+      ;;
+    pw32*)
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    esac
+    ;;
+
+  *)
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib'
+    ;;
+  esac
+  dynamic_linker='Win32 ld.exe'
+  # FIXME: first we should search . and the directory the executable is in
+  shlibpath_var=PATH
+  ;;
+
+darwin* | rhapsody*)
+  dynamic_linker="$host_os dyld"
+  version_type=darwin
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext'
+  soname_spec='${libname}${release}${major}$shared_ext'
+  shlibpath_overrides_runpath=yes
+  shlibpath_var=DYLD_LIBRARY_PATH
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
+m4_if([$1], [],[
+  sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"])
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
+  ;;
+
+dgux*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+freebsd1*)
+  dynamic_linker=no
+  ;;
+
+freebsd* | dragonfly*)
+  # DragonFly does not have aout.  When/if they implement a new
+  # versioning mechanism, adjust this.
+  if test -x /usr/bin/objformat; then
+    objformat=`/usr/bin/objformat`
+  else
+    case $host_os in
+    freebsd[[123]]*) objformat=aout ;;
+    *) objformat=elf ;;
+    esac
+  fi
+  version_type=freebsd-$objformat
+  case $version_type in
+    freebsd-elf*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+      need_version=no
+      need_lib_prefix=no
+      ;;
+    freebsd-*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
+      need_version=yes
+      ;;
+  esac
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_os in
+  freebsd2*)
+    shlibpath_overrides_runpath=yes
+    ;;
+  freebsd3.[[01]]* | freebsdelf3.[[01]]*)
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \
+  freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1)
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
+  *) # from 4.6 on, and DragonFly
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  esac
+  ;;
+
+gnu*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  ;;
+
+hpux9* | hpux10* | hpux11*)
+  # Give a soname corresponding to the major version so that dld.sl refuses to
+  # link against other versions.
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  case $host_cpu in
+  ia64*)
+    shrext_cmds='.so'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.so"
+    shlibpath_var=LD_LIBRARY_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    if test "X$HPUX_IA64_MODE" = X32; then
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
+    else
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
+    fi
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  hppa*64*)
+    shrext_cmds='.sl'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  *)
+    shrext_cmds='.sl'
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=SHLIB_PATH
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    ;;
+  esac
+  # HP-UX runs *really* slowly unless shared libraries are mode 555.
+  postinstall_cmds='chmod 555 $lib'
+  ;;
+
+interix[[3-9]]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $host_os in
+    nonstopux*) version_type=nonstopux ;;
+    *)
+       if test "$lt_cv_prog_gnu_ld" = yes; then
+               version_type=linux
+       else
+               version_type=irix
+       fi ;;
+  esac
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
+  case $host_os in
+  irix5* | nonstopux*)
+    libsuff= shlibsuff=
+    ;;
+  *)
+    case $LD in # libtool.m4 will add one of these switches to LD
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
+      libsuff= shlibsuff= libmagic=32-bit;;
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
+    *) libsuff= shlibsuff= libmagic=never-match;;
+    esac
+    ;;
+  esac
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
+  shlibpath_overrides_runpath=no
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+  hardcode_into_libs=yes
+  ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux*oldld* | linux*aout* | linux*coff*)
+  dynamic_linker=no
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  # Some binutils ld are patched to set DT_RUNPATH
+  save_LDFLAGS=$LDFLAGS
+  save_libdir=$libdir
+  eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \
+       LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\""
+  AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
+    [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null],
+       [shlibpath_overrides_runpath=yes])])
+  LDFLAGS=$save_LDFLAGS
+  libdir=$save_libdir
+
+  # This implies no fast_install, which is unacceptable.
+  # Some rework will be needed to allow for fast_install
+  # before this can be enabled.
+  hardcode_into_libs=yes
+
+  # Append ld.so.conf contents to the search path
+  if test -f /etc/ld.so.conf; then
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[  ]*hwcap[        ]/d;s/[:,      ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
+    sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra"
+  fi
+
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
+  # powerpc, because MkLinux only supported shared libraries with the
+  # GNU dynamic linker.  Since this was broken with cross compilers,
+  # most powerpc-linux boxes support dynamic linking these days and
+  # people can always --disable-shared, the test was removed, and we
+  # assume the GNU/Linux dynamic linker is in use.
+  dynamic_linker='GNU/Linux ld.so'
+  ;;
+
+netbsdelf*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='NetBSD ld.elf_so'
+  ;;
+
+netbsd*)
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+    dynamic_linker='NetBSD (a.out) ld.so'
+  else
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    dynamic_linker='NetBSD ld.elf_so'
+  fi
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  ;;
+
+newsos6)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+*nto* | *qnx*)
+  version_type=qnx
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='ldqnx.so'
+  ;;
+
+openbsd*)
+  version_type=sunos
+  sys_lib_dlsearch_path_spec="/usr/lib"
+  need_lib_prefix=no
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
+  case $host_os in
+    openbsd3.3 | openbsd3.3.*) need_version=yes ;;
+    *)                         need_version=no  ;;
+  esac
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    case $host_os in
+      openbsd2.[[89]] | openbsd2.[[89]].*)
+       shlibpath_overrides_runpath=no
+       ;;
+      *)
+       shlibpath_overrides_runpath=yes
+       ;;
+      esac
+  else
+    shlibpath_overrides_runpath=yes
+  fi
+  ;;
+
+os2*)
+  libname_spec='$name'
+  shrext_cmds=".dll"
+  need_lib_prefix=no
+  library_names_spec='$libname${shared_ext} $libname.a'
+  dynamic_linker='OS/2 ld.exe'
+  shlibpath_var=LIBPATH
+  ;;
+
+osf3* | osf4* | osf5*)
+  version_type=osf
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
+  ;;
+
+rdos*)
+  dynamic_linker=no
+  ;;
+
+solaris*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  # ldd complains unless libraries are executable
+  postinstall_cmds='chmod +x $lib'
+  ;;
+
+sunos4*)
+  version_type=sunos
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  if test "$with_gnu_ld" = yes; then
+    need_lib_prefix=no
+  fi
+  need_version=yes
+  ;;
+
+sysv4 | sysv4.3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_vendor in
+    sni)
+      shlibpath_overrides_runpath=no
+      need_lib_prefix=no
+      runpath_var=LD_RUN_PATH
+      ;;
+    siemens)
+      need_lib_prefix=no
+      ;;
+    motorola)
+      need_lib_prefix=no
+      need_version=no
+      shlibpath_overrides_runpath=no
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
+      ;;
+  esac
+  ;;
+
+sysv4*MP*)
+  if test -d /usr/nec ;then
+    version_type=linux
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
+    soname_spec='$libname${shared_ext}.$major'
+    shlibpath_var=LD_LIBRARY_PATH
+  fi
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  version_type=freebsd-elf
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  if test "$with_gnu_ld" = yes; then
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
+  else
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
+    case $host_os in
+      sco3.2v5*)
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
+       ;;
+    esac
+  fi
+  sys_lib_dlsearch_path_spec='/usr/lib'
+  ;;
+
+tpf*)
+  # TPF is a cross-target only.  Preferred cross-host = GNU/Linux.
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+uts4*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+*)
+  dynamic_linker=no
+  ;;
+esac
+AC_MSG_RESULT([$dynamic_linker])
+test "$dynamic_linker" = no && can_build_shared=no
+
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
+if test "$GCC" = yes; then
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+fi
+
+if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then
+  sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec"
+fi
+if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then
+  sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec"
+fi
+
+_LT_DECL([], [variables_saved_for_relink], [1],
+    [Variables whose values should be saved in libtool wrapper scripts and
+    restored at link time])
+_LT_DECL([], [need_lib_prefix], [0],
+    [Do we need the "lib" prefix for modules?])
+_LT_DECL([], [need_version], [0], [Do we need a version for libraries?])
+_LT_DECL([], [version_type], [0], [Library versioning type])
+_LT_DECL([], [runpath_var], [0],  [Shared library runtime path variable])
+_LT_DECL([], [shlibpath_var], [0],[Shared library path variable])
+_LT_DECL([], [shlibpath_overrides_runpath], [0],
+    [Is shlibpath searched before the hard-coded library search path?])
+_LT_DECL([], [libname_spec], [1], [Format of library name prefix])
+_LT_DECL([], [library_names_spec], [1],
+    [[List of archive names.  First name is the real one, the rest are links.
+    The last name is the one that the linker finds with -lNAME]])
+_LT_DECL([], [soname_spec], [1],
+    [[The coded name of the library, if different from the real name]])
+_LT_DECL([], [postinstall_cmds], [2],
+    [Command to use after installation of a shared archive])
+_LT_DECL([], [postuninstall_cmds], [2],
+    [Command to use after uninstallation of a shared archive])
+_LT_DECL([], [finish_cmds], [2],
+    [Commands used to finish a libtool library installation in a directory])
+_LT_DECL([], [finish_eval], [1],
+    [[As "finish_cmds", except a single script fragment to be evaled but
+    not shown]])
+_LT_DECL([], [hardcode_into_libs], [0],
+    [Whether we should hardcode library paths into libraries])
+_LT_DECL([], [sys_lib_search_path_spec], [2],
+    [Compile-time system search path for libraries])
+_LT_DECL([], [sys_lib_dlsearch_path_spec], [2],
+    [Run-time system search path for libraries])
+])# _LT_SYS_DYNAMIC_LINKER
+
+
+# _LT_PATH_TOOL_PREFIX(TOOL)
+# --------------------------
+# find a file program which can recognize shared library
+AC_DEFUN([_LT_PATH_TOOL_PREFIX],
+[m4_require([_LT_DECL_EGREP])dnl
+AC_MSG_CHECKING([for $1])
+AC_CACHE_VAL(lt_cv_path_MAGIC_CMD,
+[case $MAGIC_CMD in
+[[\\/*] |  ?:[\\/]*])
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+dnl $ac_dummy forces splitting on constant user-supplied paths.
+dnl POSIX.2 word splitting is done only on the output of word expansions,
+dnl not every word.  This closes a longstanding sh security hole.
+  ac_dummy="m4_if([$2], , $PATH, [$2])"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/$1; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/$1"
+      if test -n "$file_magic_test_file"; then
+       case $deplibs_check_method in
+       "file_magic "*)
+         file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+         MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+         if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+           $EGREP "$file_magic_regex" > /dev/null; then
+           :
+         else
+           cat <<_LT_EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool@gnu.org
+
+_LT_EOF
+         fi ;;
+       esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac])
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  AC_MSG_RESULT($MAGIC_CMD)
+else
+  AC_MSG_RESULT(no)
+fi
+_LT_DECL([], [MAGIC_CMD], [0],
+        [Used to examine libraries when file_magic_cmd begins with "file"])dnl
+])# _LT_PATH_TOOL_PREFIX
+
+# Old name:
+AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], [])
+
+
+# _LT_PATH_MAGIC
+# --------------
+# find a file program which can recognize a shared library
+m4_defun([_LT_PATH_MAGIC],
+[_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH)
+if test -z "$lt_cv_path_MAGIC_CMD"; then
+  if test -n "$ac_tool_prefix"; then
+    _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH)
+  else
+    MAGIC_CMD=:
+  fi
+fi
+])# _LT_PATH_MAGIC
+
+
+# LT_PATH_LD
+# ----------
+# find the pathname to the GNU or non-GNU linker
+AC_DEFUN([LT_PATH_LD],
+[AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_DECL_EGREP])dnl
+
+AC_ARG_WITH([gnu-ld],
+    [AS_HELP_STRING([--with-gnu-ld],
+       [assume the C compiler uses GNU ld @<:@default=no@:>@])],
+    [test "$withval" = no || with_gnu_ld=yes],
+    [with_gnu_ld=no])dnl
+
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  AC_MSG_CHECKING([for ld used by $CC])
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [[\\/]]* | ?:[[\\/]]*)
+      re_direlt='/[[^/]][[^/]]*/\.\./'
+      # Canonicalize the pathname of ld
+      ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'`
+      while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do
+       ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  AC_MSG_CHECKING([for GNU ld])
+else
+  AC_MSG_CHECKING([for non-GNU ld])
+fi
+AC_CACHE_VAL(lt_cv_path_LD,
+[if test -z "$LD"; then
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  for ac_dir in $PATH; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      lt_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some variants of GNU ld only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
+      *GNU* | *'with BFD'*)
+       test "$with_gnu_ld" != no && break
+       ;;
+      *)
+       test "$with_gnu_ld" != yes && break
+       ;;
+      esac
+    fi
+  done
+  IFS="$lt_save_ifs"
+else
+  lt_cv_path_LD="$LD" # Let the user override the test with a path.
+fi])
+LD="$lt_cv_path_LD"
+if test -n "$LD"; then
+  AC_MSG_RESULT($LD)
+else
+  AC_MSG_RESULT(no)
+fi
+test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
+_LT_PATH_LD_GNU
+AC_SUBST([LD])
+
+_LT_TAGDECL([], [LD], [1], [The linker used to build libraries])
+])# LT_PATH_LD
+
+# Old names:
+AU_ALIAS([AM_PROG_LD], [LT_PATH_LD])
+AU_ALIAS([AC_PROG_LD], [LT_PATH_LD])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_PROG_LD], [])
+dnl AC_DEFUN([AC_PROG_LD], [])
+
+
+# _LT_PATH_LD_GNU
+#- --------------
+m4_defun([_LT_PATH_LD_GNU],
+[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
+[# I'd rather use --version here, but apparently some GNU lds only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  lt_cv_prog_gnu_ld=yes
+  ;;
+*)
+  lt_cv_prog_gnu_ld=no
+  ;;
+esac])
+with_gnu_ld=$lt_cv_prog_gnu_ld
+])# _LT_PATH_LD_GNU
+
+
+# _LT_CMD_RELOAD
+# --------------
+# find reload flag for linker
+#   -- PORTME Some linkers may need a different reload flag.
+m4_defun([_LT_CMD_RELOAD],
+[AC_CACHE_CHECK([for $LD option to reload object files],
+  lt_cv_ld_reload_flag,
+  [lt_cv_ld_reload_flag='-r'])
+reload_flag=$lt_cv_ld_reload_flag
+case $reload_flag in
+"" | " "*) ;;
+*) reload_flag=" $reload_flag" ;;
+esac
+reload_cmds='$LD$reload_flag -o $output$reload_objs'
+case $host_os in
+  darwin*)
+    if test "$GCC" = yes; then
+      reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs'
+    else
+      reload_cmds='$LD$reload_flag -o $output$reload_objs'
+    fi
+    ;;
+esac
+_LT_DECL([], [reload_flag], [1], [How to create reloadable object files])dnl
+_LT_DECL([], [reload_cmds], [2])dnl
+])# _LT_CMD_RELOAD
+
+
+# _LT_CHECK_MAGIC_METHOD
+# ----------------------
+# how to check for library dependencies
+#  -- PORTME fill in with the dynamic library characteristics
+m4_defun([_LT_CHECK_MAGIC_METHOD],
+[m4_require([_LT_DECL_EGREP])
+m4_require([_LT_DECL_OBJDUMP])
+AC_CACHE_CHECK([how to recognize dependent libraries],
+lt_cv_deplibs_check_method,
+[lt_cv_file_magic_cmd='$MAGIC_CMD'
+lt_cv_file_magic_test_file=
+lt_cv_deplibs_check_method='unknown'
+# Need to set the preceding variable on all platforms that support
+# interlibrary dependencies.
+# 'none' -- dependencies not supported.
+# `unknown' -- same as none, but documents that we really don't know.
+# 'pass_all' -- all dependencies passed with no checks.
+# 'test_compile' -- check by making test program.
+# 'file_magic [[regex]]' -- check by looking for files in library path
+# which responds to the $file_magic_cmd with a given extended regex.
+# If you have `file' or equivalent on your system and you're not sure
+# whether `pass_all' will *always* work, you probably want this one.
+
+case $host_os in
+aix[[4-9]]*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+beos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+bsdi[[45]]*)
+  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib)'
+  lt_cv_file_magic_cmd='/usr/bin/file -L'
+  lt_cv_file_magic_test_file=/shlib/libc.so
+  ;;
+
+cygwin*)
+  # func_win32_libid is a shell function defined in ltmain.sh
+  lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+  lt_cv_file_magic_cmd='func_win32_libid'
+  ;;
+
+mingw* | pw32*)
+  # Base MSYS/MinGW do not provide the 'file' command needed by
+  # func_win32_libid shell function, so use a weaker test based on 'objdump',
+  # unless we find 'file', for example because we are cross-compiling.
+  if ( file / ) >/dev/null 2>&1; then
+    lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+    lt_cv_file_magic_cmd='func_win32_libid'
+  else
+    lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?'
+    lt_cv_file_magic_cmd='$OBJDUMP -f'
+  fi
+  ;;
+
+cegcc)
+  # use the weaker test based on 'objdump'. See mingw*.
+  lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?'
+  lt_cv_file_magic_cmd='$OBJDUMP -f'
+  ;;
+
+darwin* | rhapsody*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+freebsd* | dragonfly*)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    case $host_cpu in
+    i*86 )
+      # Not sure whether the presence of OpenBSD here was a mistake.
+      # Let's accept both of them until this is cleared up.
+      lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library'
+      lt_cv_file_magic_cmd=/usr/bin/file
+      lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
+      ;;
+    esac
+  else
+    lt_cv_deplibs_check_method=pass_all
+  fi
+  ;;
+
+gnu*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+hpux10.20* | hpux11*)
+  lt_cv_file_magic_cmd=/usr/bin/file
+  case $host_cpu in
+  ia64*)
+    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64'
+    lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
+    ;;
+  hppa*64*)
+    [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]']
+    lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
+    ;;
+  *)
+    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]].[[0-9]]) shared library'
+    lt_cv_file_magic_test_file=/usr/lib/libc.sl
+    ;;
+  esac
+  ;;
+
+interix[[3-9]]*)
+  # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here
+  lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$'
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $LD in
+  *-32|*"-32 ") libmagic=32-bit;;
+  *-n32|*"-n32 ") libmagic=N32;;
+  *-64|*"-64 ") libmagic=64-bit;;
+  *) libmagic=never-match;;
+  esac
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+netbsd* | netbsdelf*-gnu)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$'
+  fi
+  ;;
+
+newos6*)
+  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)'
+  lt_cv_file_magic_cmd=/usr/bin/file
+  lt_cv_file_magic_test_file=/usr/lib/libnls.so
+  ;;
+
+*nto* | *qnx*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+openbsd*)
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
+  fi
+  ;;
+
+osf3* | osf4* | osf5*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+rdos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+solaris*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv4 | sysv4.3*)
+  case $host_vendor in
+  motorola)
+    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]'
+    lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
+    ;;
+  ncr)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  sequent)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )'
+    ;;
+  sni)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib"
+    lt_cv_file_magic_test_file=/lib/libc.so
+    ;;
+  siemens)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  pc)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  esac
+  ;;
+
+tpf*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+esac
+])
+file_magic_cmd=$lt_cv_file_magic_cmd
+deplibs_check_method=$lt_cv_deplibs_check_method
+test -z "$deplibs_check_method" && deplibs_check_method=unknown
+
+_LT_DECL([], [deplibs_check_method], [1],
+    [Method to check whether dependent libraries are shared objects])
+_LT_DECL([], [file_magic_cmd], [1],
+    [Command to use when deplibs_check_method == "file_magic"])
+])# _LT_CHECK_MAGIC_METHOD
+
+
+# LT_PATH_NM
+# ----------
+# find the pathname to a BSD- or MS-compatible name lister
+AC_DEFUN([LT_PATH_NM],
+[AC_REQUIRE([AC_PROG_CC])dnl
+AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM,
+[if test -n "$NM"; then
+  # Let the user override the test.
+  lt_cv_path_NM="$NM"
+else
+  lt_nm_to_check="${ac_tool_prefix}nm"
+  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
+    lt_nm_to_check="$lt_nm_to_check nm"
+  fi
+  for lt_tmp_nm in $lt_nm_to_check; do
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
+      IFS="$lt_save_ifs"
+      test -z "$ac_dir" && ac_dir=.
+      tmp_nm="$ac_dir/$lt_tmp_nm"
+      if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
+       # Check to see if the nm accepts a BSD-compat flag.
+       # Adding the `sed 1q' prevents false positives on HP-UX, which says:
+       #   nm: unknown option "B" ignored
+       # Tru64's nm complains that /dev/null is an invalid object file
+       case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
+       */dev/null* | *'Invalid file or object type'*)
+         lt_cv_path_NM="$tmp_nm -B"
+         break
+         ;;
+       *)
+         case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
+         */dev/null*)
+           lt_cv_path_NM="$tmp_nm -p"
+           break
+           ;;
+         *)
+           lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
+           continue # so that we can try to find one that supports BSD flags
+           ;;
+         esac
+         ;;
+       esac
+      fi
+    done
+    IFS="$lt_save_ifs"
+  done
+  : ${lt_cv_path_NM=no}
+fi])
+if test "$lt_cv_path_NM" != "no"; then
+  NM="$lt_cv_path_NM"
+else
+  # Didn't find any BSD compatible name lister, look for dumpbin.
+  AC_CHECK_TOOLS(DUMPBIN, ["dumpbin -symbols" "link -dump -symbols"], :)
+  AC_SUBST([DUMPBIN])
+  if test "$DUMPBIN" != ":"; then
+    NM="$DUMPBIN"
+  fi
+fi
+test -z "$NM" && NM=nm
+AC_SUBST([NM])
+_LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl
+
+AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface],
+  [lt_cv_nm_interface="BSD nm"
+  echo "int some_variable = 0;" > conftest.$ac_ext
+  (eval echo "\"\$as_me:__oline__: $ac_compile\"" >&AS_MESSAGE_LOG_FD)
+  (eval "$ac_compile" 2>conftest.err)
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  (eval echo "\"\$as_me:__oline__: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD)
+  (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  (eval echo "\"\$as_me:__oline__: output\"" >&AS_MESSAGE_LOG_FD)
+  cat conftest.out >&AS_MESSAGE_LOG_FD
+  if $GREP 'External.*some_variable' conftest.out > /dev/null; then
+    lt_cv_nm_interface="MS dumpbin"
+  fi
+  rm -f conftest*])
+])# LT_PATH_NM
+
+# Old names:
+AU_ALIAS([AM_PROG_NM], [LT_PATH_NM])
+AU_ALIAS([AC_PROG_NM], [LT_PATH_NM])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_PROG_NM], [])
+dnl AC_DEFUN([AC_PROG_NM], [])
+
+
+# LT_LIB_M
+# --------
+# check for math library
+AC_DEFUN([LT_LIB_M],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+LIBM=
+case $host in
+*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*)
+  # These system don't have libm, or don't need it
+  ;;
+*-ncr-sysv4.3*)
+  AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
+  AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm")
+  ;;
+*)
+  AC_CHECK_LIB(m, cos, LIBM="-lm")
+  ;;
+esac
+AC_SUBST([LIBM])
+])# LT_LIB_M
+
+# Old name:
+AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_CHECK_LIBM], [])
+
+
+# _LT_COMPILER_NO_RTTI([TAGNAME])
+# -------------------------------
+m4_defun([_LT_COMPILER_NO_RTTI],
+[m4_require([_LT_TAG_COMPILER])dnl
+
+_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
+
+if test "$GCC" = yes; then
+  _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
+
+  _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions],
+    lt_cv_prog_compiler_rtti_exceptions,
+    [-fno-rtti -fno-exceptions], [],
+    [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"])
+fi
+_LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1],
+       [Compiler flag to turn off builtin functions])
+])# _LT_COMPILER_NO_RTTI
+
+
+# _LT_CMD_GLOBAL_SYMBOLS
+# ----------------------
+m4_defun([_LT_CMD_GLOBAL_SYMBOLS],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+AC_REQUIRE([LT_PATH_LD])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+
+# Check for command to grab the raw symbol name followed by C symbol from nm.
+AC_MSG_CHECKING([command to parse $NM output from $compiler object])
+AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe],
+[
+# These are sane defaults that work on at least a few old systems.
+# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
+
+# Character class describing NM global symbol codes.
+symcode='[[BCDEGRST]]'
+
+# Regexp to match symbols that can be accessed directly from C.
+sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)'
+
+# Define system-specific variables.
+case $host_os in
+aix*)
+  symcode='[[BCDT]]'
+  ;;
+cygwin* | mingw* | pw32* | cegcc*)
+  symcode='[[ABCDGISTW]]'
+  ;;
+hpux*)
+  if test "$host_cpu" = ia64; then
+    symcode='[[ABCDEGRST]]'
+  fi
+  ;;
+irix* | nonstopux*)
+  symcode='[[BCDEGRST]]'
+  ;;
+osf*)
+  symcode='[[BCDEGQRST]]'
+  ;;
+solaris*)
+  symcode='[[BDRT]]'
+  ;;
+sco3.2v5*)
+  symcode='[[DT]]'
+  ;;
+sysv4.2uw2*)
+  symcode='[[DT]]'
+  ;;
+sysv5* | sco5v6* | unixware* | OpenUNIX*)
+  symcode='[[ABDT]]'
+  ;;
+sysv4)
+  symcode='[[DFNSTU]]'
+  ;;
+esac
+
+# If we're using GNU nm, then use its standard symbol codes.
+case `$NM -V 2>&1` in
+*GNU* | *'with BFD'*)
+  symcode='[[ABCDGIRSTW]]' ;;
+esac
+
+# Transform an extracted symbol line into a proper C declaration.
+# Some systems (esp. on ia64) link data and code symbols differently,
+# so use this general approach.
+lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
+
+# Transform an extracted symbol line into symbol name and symbol address
+lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"\2\", (void *) \&\2},/p'"
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([[^ ]]*\) $/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \(lib[[^ ]]*\)$/  {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"lib\2\", (void *) \&\2},/p'"
+
+# Handle CRLF in mingw tool chain
+opt_cr=
+case $build_os in
+mingw*)
+  opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp
+  ;;
+esac
+
+# Try without a prefix underscore, then with it.
+for ac_symprfx in "" "_"; do
+
+  # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
+  symxfrm="\\1 $ac_symprfx\\2 \\2"
+
+  # Write the raw and C identifiers.
+  if test "$lt_cv_nm_interface" = "MS dumpbin"; then
+    # Fake it for dumpbin and say T for any non-static function
+    # and D for any global variable.
+    # Also find C++ and __fastcall symbols from MSVC++,
+    # which start with @ or ?.
+    lt_cv_sys_global_symbol_pipe="$AWK ['"\
+"     {last_section=section; section=\$ 3};"\
+"     /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\
+"     \$ 0!~/External *\|/{next};"\
+"     / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\
+"     {if(hide[section]) next};"\
+"     {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\
+"     {split(\$ 0, a, /\||\r/); split(a[2], s)};"\
+"     s[1]~/^[@?]/{print s[1], s[1]; next};"\
+"     s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\
+"     ' prfx=^$ac_symprfx]"
+  else
+    lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[    ]]\($symcode$symcode*\)[[       ]][[    ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
+  fi
+
+  # Check to see that the pipe works correctly.
+  pipe_works=no
+
+  rm -f conftest*
+  cat > conftest.$ac_ext <<_LT_EOF
+#ifdef __cplusplus
+extern "C" {
+#endif
+char nm_test_var;
+void nm_test_func(void);
+void nm_test_func(void){}
+#ifdef __cplusplus
+}
+#endif
+int main(){nm_test_var='a';nm_test_func();return(0);}
+_LT_EOF
+
+  if AC_TRY_EVAL(ac_compile); then
+    # Now try to grab the symbols.
+    nlist=conftest.nm
+    if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) && test -s "$nlist"; then
+      # Try sorting and uniquifying the output.
+      if sort "$nlist" | uniq > "$nlist"T; then
+       mv -f "$nlist"T "$nlist"
+      else
+       rm -f "$nlist"T
+      fi
+
+      # Make sure that we snagged all the symbols we need.
+      if $GREP ' nm_test_var$' "$nlist" >/dev/null; then
+       if $GREP ' nm_test_func$' "$nlist" >/dev/null; then
+         cat <<_LT_EOF > conftest.$ac_ext
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+_LT_EOF
+         # Now generate the symbol file.
+         eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext'
+
+         cat <<_LT_EOF >> conftest.$ac_ext
+
+/* The mapping between symbol names and symbols.  */
+const struct {
+  const char *name;
+  void       *address;
+}
+lt__PROGRAM__LTX_preloaded_symbols[[]] =
+{
+  { "@PROGRAM@", (void *) 0 },
+_LT_EOF
+         $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext
+         cat <<\_LT_EOF >> conftest.$ac_ext
+  {0, (void *) 0}
+};
+
+/* This works around a problem in FreeBSD linker */
+#ifdef FREEBSD_WORKAROUND
+static const void *lt_preloaded_setup() {
+  return lt__PROGRAM__LTX_preloaded_symbols;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+_LT_EOF
+         # Now try linking the two files.
+         mv conftest.$ac_objext conftstm.$ac_objext
+         lt_save_LIBS="$LIBS"
+         lt_save_CFLAGS="$CFLAGS"
+         LIBS="conftstm.$ac_objext"
+         CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)"
+         if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then
+           pipe_works=yes
+         fi
+         LIBS="$lt_save_LIBS"
+         CFLAGS="$lt_save_CFLAGS"
+       else
+         echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD
+       fi
+      else
+       echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD
+      fi
+    else
+      echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD
+    fi
+  else
+    echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD
+    cat conftest.$ac_ext >&5
+  fi
+  rm -rf conftest* conftst*
+
+  # Do not use the global_symbol_pipe unless it works.
+  if test "$pipe_works" = yes; then
+    break
+  else
+    lt_cv_sys_global_symbol_pipe=
+  fi
+done
+])
+if test -z "$lt_cv_sys_global_symbol_pipe"; then
+  lt_cv_sys_global_symbol_to_cdecl=
+fi
+if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
+  AC_MSG_RESULT(failed)
+else
+  AC_MSG_RESULT(ok)
+fi
+
+_LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1],
+    [Take the output of nm and produce a listing of raw symbols and C names])
+_LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1],
+    [Transform the output of nm in a proper C declaration])
+_LT_DECL([global_symbol_to_c_name_address],
+    [lt_cv_sys_global_symbol_to_c_name_address], [1],
+    [Transform the output of nm in a C name address pair])
+_LT_DECL([global_symbol_to_c_name_address_lib_prefix],
+    [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1],
+    [Transform the output of nm in a C name address pair when lib prefix is needed])
+]) # _LT_CMD_GLOBAL_SYMBOLS
+
+
+# _LT_COMPILER_PIC([TAGNAME])
+# ---------------------------
+m4_defun([_LT_COMPILER_PIC],
+[m4_require([_LT_TAG_COMPILER])dnl
+_LT_TAGVAR(lt_prog_compiler_wl, $1)=
+_LT_TAGVAR(lt_prog_compiler_pic, $1)=
+_LT_TAGVAR(lt_prog_compiler_static, $1)=
+
+AC_MSG_CHECKING([for $compiler option to produce PIC])
+m4_if([$1], [CXX], [
+  # C++ specific cases for pic, static, wl, etc.
+  if test "$GXX" = yes; then
+    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+
+    case $host_os in
+    aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+       # AIX 5 now supports IA64 processor
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+        ;;
+      m68k)
+            # FIXME: we need at least 68020 code to build shared libraries, but
+            # adding the `-m68020' flag to GCC prevents building anything better,
+            # like `-m68040'.
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
+        ;;
+      esac
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+    mingw* | cygwin* | os2* | pw32* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      m4_if([$1], [GCJ], [],
+       [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
+      ;;
+    *djgpp*)
+      # DJGPP does not support shared libraries at all
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+      ;;
+    interix[[3-9]]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+    sysv4*MP*)
+      if test -d /usr/nec; then
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
+      fi
+      ;;
+    hpux*)
+      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
+      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
+      # sets the default TLS model and affects inlining.
+      case $host_cpu in
+      hppa*64*)
+       ;;
+      *)
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+       ;;
+      esac
+      ;;
+    *qnx* | *nto*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+    *)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+      ;;
+    esac
+  else
+    case $host_os in
+      aix[[4-9]]*)
+       # All AIX code is PIC.
+       if test "$host_cpu" = ia64; then
+         # AIX 5 now supports IA64 processor
+         _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+       else
+         _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
+       fi
+       ;;
+      chorus*)
+       case $cc_basename in
+       cxch68*)
+         # Green Hills C++ Compiler
+         # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a"
+         ;;
+       esac
+       ;;
+      dgux*)
+       case $cc_basename in
+         ec++*)
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+           ;;
+         ghcx*)
+           # Green Hills C++ Compiler
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      freebsd* | dragonfly*)
+       # FreeBSD uses GNU C++
+       ;;
+      hpux9* | hpux10* | hpux11*)
+       case $cc_basename in
+         CC*)
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+           if test "$host_cpu" != ia64; then
+             _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+           fi
+           ;;
+         aCC*)
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+           case $host_cpu in
+           hppa*64*|ia64*)
+             # +Z the default
+             ;;
+           *)
+             _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+             ;;
+           esac
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      interix*)
+       # This is c89, which is MS Visual C++ (no shared libs)
+       # Anyone wants to do a port?
+       ;;
+      irix5* | irix6* | nonstopux*)
+       case $cc_basename in
+         CC*)
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+           # CC pic flag -KPIC is the default.
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      linux* | k*bsd*-gnu)
+       case $cc_basename in
+         KCC*)
+           # KAI C++ Compiler
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+           ;;
+         ecpc* )
+           # old Intel C++ for x86_64 which still supported -KPIC.
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+           ;;
+         icpc* )
+           # Intel C++, used to be incompatible with GCC.
+           # ICC 10 doesn't accept -KPIC any more.
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+           ;;
+         pgCC* | pgcpp*)
+           # Portland Group C++ compiler
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+           ;;
+         cxx*)
+           # Compaq C++
+           # Make sure the PIC flag is empty.  It appears that all Alpha
+           # Linux and Compaq Tru64 Unix objects are PIC.
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+           ;;
+         xlc* | xlC*)
+           # IBM XL 8.0 on PPC
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink'
+           ;;
+         *)
+           case `$CC -V 2>&1 | sed 5q` in
+           *Sun\ C*)
+             # Sun C++ 5.9
+             _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+             _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+             _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+             ;;
+           esac
+           ;;
+       esac
+       ;;
+      lynxos*)
+       ;;
+      m88k*)
+       ;;
+      mvs*)
+       case $cc_basename in
+         cxx*)
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall'
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      netbsd* | netbsdelf*-gnu)
+       ;;
+      *qnx* | *nto*)
+        # QNX uses GNU C++, but need to define -shared option too, otherwise
+        # it will coredump.
+        _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+        ;;
+      osf3* | osf4* | osf5*)
+       case $cc_basename in
+         KCC*)
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
+           ;;
+         RCC*)
+           # Rational C++ 2.4.1
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+           ;;
+         cxx*)
+           # Digital/Compaq C++
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           # Make sure the PIC flag is empty.  It appears that all Alpha
+           # Linux and Compaq Tru64 Unix objects are PIC.
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      psos*)
+       ;;
+      solaris*)
+       case $cc_basename in
+         CC*)
+           # Sun C++ 4.2, 5.x and Centerline C++
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+           ;;
+         gcx*)
+           # Green Hills C++ Compiler
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      sunos4*)
+       case $cc_basename in
+         CC*)
+           # Sun C++ 4.x
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+           ;;
+         lcc*)
+           # Lucid
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+       case $cc_basename in
+         CC*)
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+           ;;
+       esac
+       ;;
+      tandem*)
+       case $cc_basename in
+         NCC*)
+           # NonStop-UX NCC 3.20
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      vxworks*)
+       ;;
+      *)
+       _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+       ;;
+    esac
+  fi
+],
+[
+  if test "$GCC" = yes; then
+    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+
+    case $host_os in
+      aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+       # AIX 5 now supports IA64 processor
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+        ;;
+      m68k)
+            # FIXME: we need at least 68020 code to build shared libraries, but
+            # adding the `-m68020' flag to GCC prevents building anything better,
+            # like `-m68040'.
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
+        ;;
+      esac
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      m4_if([$1], [GCJ], [],
+       [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
+      ;;
+
+    hpux*)
+      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
+      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
+      # sets the default TLS model and affects inlining.
+      case $host_cpu in
+      hppa*64*)
+       # +Z the default
+       ;;
+      *)
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+       ;;
+      esac
+      ;;
+
+    interix[[3-9]]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+
+    msdosdjgpp*)
+      # Just because we use GCC doesn't mean we suddenly get shared libraries
+      # on systems that don't support them.
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      enable_shared=no
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
+      fi
+      ;;
+
+    *)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+      ;;
+    esac
+  else
+    # PORTME Check for flag to pass linker flags through the system compiler.
+    case $host_os in
+    aix*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      if test "$host_cpu" = ia64; then
+       # AIX 5 now supports IA64 processor
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      else
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
+      fi
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      m4_if([$1], [GCJ], [],
+       [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+
+    hpux9* | hpux10* | hpux11*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+       # +Z the default
+       ;;
+      *)
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+       ;;
+      esac
+      # Is there a better lt_prog_compiler_static that works with the bundled CC?
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # PIC (with -KPIC) is the default.
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    linux* | k*bsd*-gnu)
+      case $cc_basename in
+      # old Intel for x86_64 which still supported -KPIC.
+      ecc*)
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+        ;;
+      # icc used to be incompatible with GCC.
+      # ICC 10 doesn't accept -KPIC any more.
+      icc* | ifort*)
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+        ;;
+      # Lahey Fortran 8.1.
+      lf95*)
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared'
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='--static'
+       ;;
+      pgcc* | pgf77* | pgf90* | pgf95*)
+        # Portland Group compilers (*not* the Pentium gcc compiler,
+       # which looks to be a dead project)
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+        ;;
+      ccc*)
+        _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+        # All Alpha code is PIC.
+        _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+        ;;
+      xl*)
+       # IBM XL C 8.0/Fortran 10.1 on PPC
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic'
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink'
+       ;;
+      *)
+       case `$CC -V 2>&1 | sed 5q` in
+       *Sun\ C*)
+         # Sun C 5.9
+         _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+         _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+         _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+         ;;
+       *Sun\ F*)
+         # Sun Fortran 8.3 passes all unrecognized flags to the linker
+         _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+         _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+         _LT_TAGVAR(lt_prog_compiler_wl, $1)=''
+         ;;
+       esac
+       ;;
+      esac
+      ;;
+
+    newsos6)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+
+    osf3* | osf4* | osf5*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # All OSF/1 code is PIC.
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    rdos*)
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    solaris*)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      case $cc_basename in
+      f77* | f90* | f95*)
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';;
+      *)
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';;
+      esac
+      ;;
+
+    sunos4*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    sysv4 | sysv4.2uw2* | sysv4.3*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec ;then
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic'
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    unicos*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      ;;
+
+    uts4*)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    *)
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      ;;
+    esac
+  fi
+])
+case $host_os in
+  # For platforms which do not support PIC, -DPIC is meaningless:
+  *djgpp*)
+    _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+    ;;
+  *)
+    _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])"
+    ;;
+esac
+AC_MSG_RESULT([$_LT_TAGVAR(lt_prog_compiler_pic, $1)])
+_LT_TAGDECL([wl], [lt_prog_compiler_wl], [1],
+       [How to pass a linker flag through the compiler])
+
+#
+# Check to make sure the PIC flag actually works.
+#
+if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then
+  _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works],
+    [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)],
+    [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [],
+    [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in
+     "" | " "*) ;;
+     *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;;
+     esac],
+    [_LT_TAGVAR(lt_prog_compiler_pic, $1)=
+     _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no])
+fi
+_LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1],
+       [Additional compiler flags for building library objects])
+
+#
+# Check to make sure the static flag actually works.
+#
+wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\"
+_LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works],
+  _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1),
+  $lt_tmp_static_flag,
+  [],
+  [_LT_TAGVAR(lt_prog_compiler_static, $1)=])
+_LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1],
+       [Compiler flag to prevent dynamic linking])
+])# _LT_COMPILER_PIC
+
+
+# _LT_LINKER_SHLIBS([TAGNAME])
+# ----------------------------
+# See if the linker supports building shared libraries.
+m4_defun([_LT_LINKER_SHLIBS],
+[AC_REQUIRE([LT_PATH_LD])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
+m4_if([$1], [CXX], [
+  _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  case $host_os in
+  aix[[4-9]]*)
+    # If we're using GNU nm, then we don't want the "-C" option.
+    # -C means demangle to AIX nm, but means don't demangle with GNU nm
+    if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+    else
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+    fi
+    ;;
+  pw32*)
+    _LT_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds"
+  ;;
+  cygwin* | mingw* | cegcc*)
+    _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;/^.*[[ ]]__nm__/s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols'
+  ;;
+  linux* | k*bsd*-gnu)
+    _LT_TAGVAR(link_all_deplibs, $1)=no
+  ;;
+  *)
+    _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  ;;
+  esac
+  _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*']
+], [
+  runpath_var=
+  _LT_TAGVAR(allow_undefined_flag, $1)=
+  _LT_TAGVAR(always_export_symbols, $1)=no
+  _LT_TAGVAR(archive_cmds, $1)=
+  _LT_TAGVAR(archive_expsym_cmds, $1)=
+  _LT_TAGVAR(compiler_needs_object, $1)=no
+  _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+  _LT_TAGVAR(export_dynamic_flag_spec, $1)=
+  _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  _LT_TAGVAR(hardcode_automatic, $1)=no
+  _LT_TAGVAR(hardcode_direct, $1)=no
+  _LT_TAGVAR(hardcode_direct_absolute, $1)=no
+  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+  _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+  _LT_TAGVAR(hardcode_libdir_separator, $1)=
+  _LT_TAGVAR(hardcode_minus_L, $1)=no
+  _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+  _LT_TAGVAR(inherit_rpath, $1)=no
+  _LT_TAGVAR(link_all_deplibs, $1)=unknown
+  _LT_TAGVAR(module_cmds, $1)=
+  _LT_TAGVAR(module_expsym_cmds, $1)=
+  _LT_TAGVAR(old_archive_from_new_cmds, $1)=
+  _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)=
+  _LT_TAGVAR(thread_safe_flag_spec, $1)=
+  _LT_TAGVAR(whole_archive_flag_spec, $1)=
+  # include_expsyms should be a list of space-separated symbols to be *always*
+  # included in the symbol list
+  _LT_TAGVAR(include_expsyms, $1)=
+  # exclude_expsyms can be an extended regexp of symbols to exclude
+  # it will be wrapped by ` (' and `)$', so one must not match beginning or
+  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
+  # as well as any symbol that contains `d'.
+  _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*']
+  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
+  # platforms (ab)use it in PIC code, but their linkers get confused if
+  # the symbol is explicitly referenced.  Since portable code cannot
+  # rely on this symbol name, it's probably fine to never include it in
+  # preloaded symbol tables.
+  # Exclude shared library initialization/finalization symbols.
+dnl Note also adjust exclude_expsyms for C++ above.
+  extract_expsyms_cmds=
+
+  case $host_os in
+  cygwin* | mingw* | pw32* | cegcc*)
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
+    # When not using gcc, we currently assume that we are using
+    # Microsoft Visual C++.
+    if test "$GCC" != yes; then
+      with_gnu_ld=no
+    fi
+    ;;
+  interix*)
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
+    with_gnu_ld=yes
+    ;;
+  openbsd*)
+    with_gnu_ld=no
+    ;;
+  linux* | k*bsd*-gnu)
+    _LT_TAGVAR(link_all_deplibs, $1)=no
+    ;;
+  esac
+
+  _LT_TAGVAR(ld_shlibs, $1)=yes
+  if test "$with_gnu_ld" = yes; then
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    wlarc='${wl}'
+
+    # Set some defaults for GNU ld with shared library support. These
+    # are reset later if shared libraries are not supported. Putting them
+    # here allows them to be overridden if necessary.
+    runpath_var=LD_RUN_PATH
+    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then
+      _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+    else
+      _LT_TAGVAR(whole_archive_flag_spec, $1)=
+    fi
+    supports_anon_versioning=no
+    case `$LD -v 2>&1` in
+      *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11
+      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
+      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
+      *\ 2.11.*) ;; # other 2.11 versions
+      *) supports_anon_versioning=yes ;;
+    esac
+
+    # See if GNU ld supports shared libraries.
+    case $host_os in
+    aix[[3-9]]*)
+      # On AIX/PPC, the GNU linker is very broken
+      if test "$host_cpu" != ia64; then
+       _LT_TAGVAR(ld_shlibs, $1)=no
+       cat <<_LT_EOF 1>&2
+
+*** Warning: the GNU linker, at least up to release 2.9.1, is reported
+*** to be unable to reliably create shared libraries on AIX.
+*** Therefore, libtool is disabling shared libraries support.  If you
+*** really care for shared libraries, you may want to modify your PATH
+*** so that a non-GNU linker is found, and then restart.
+
+_LT_EOF
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            _LT_TAGVAR(archive_expsym_cmds, $1)=''
+        ;;
+      m68k)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes
+        ;;
+      esac
+      ;;
+
+    beos*)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+       _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+       # Joseph Beckenbach <jrb3@best.com> says some releases of gcc
+       # support --undefined.  This deserves some investigation.  FIXME
+       _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      else
+       _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
+      # as there is no search path for DLLs.
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(always_export_symbols, $1)=no
+      _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols'
+
+      if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+       # If the export-symbols file already is a .def file (1st line
+       # is EXPORTS), use it as is; otherwise, prepend...
+       _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+         cp $export_symbols $output_objdir/$soname.def;
+       else
+         echo EXPORTS > $output_objdir/$soname.def;
+         cat $export_symbols >> $output_objdir/$soname.def;
+       fi~
+       $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      else
+       _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    interix[[3-9]]*)
+      _LT_TAGVAR(hardcode_direct, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+      # Instead, shared libraries are loaded at an image base (0x10000000 by
+      # default) and relocated if they conflict, which is a slow very memory
+      # consuming and fragmenting process.  To avoid this, we pick a random,
+      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+      _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      ;;
+
+    gnu* | linux* | tpf* | k*bsd*-gnu)
+      tmp_diet=no
+      if test "$host_os" = linux-dietlibc; then
+       case $cc_basename in
+         diet\ *) tmp_diet=yes;;       # linux-dietlibc with static linking (!diet-dyn)
+       esac
+      fi
+      if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \
+        && test "$tmp_diet" = no
+      then
+       tmp_addflag=
+       tmp_sharedflag='-shared'
+       case $cc_basename,$host_cpu in
+        pgcc*)                         # Portland Group C compiler
+         _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+         tmp_addflag=' $pic_flag'
+         ;;
+       pgf77* | pgf90* | pgf95*)       # Portland Group f77 and f90 compilers
+         _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+         tmp_addflag=' $pic_flag -Mnomain' ;;
+       ecc*,ia64* | icc*,ia64*)        # Intel C compiler on ia64
+         tmp_addflag=' -i_dynamic' ;;
+       efc*,ia64* | ifort*,ia64*)      # Intel Fortran compiler on ia64
+         tmp_addflag=' -i_dynamic -nofor_main' ;;
+       ifc* | ifort*)                  # Intel Fortran compiler
+         tmp_addflag=' -nofor_main' ;;
+       lf95*)                          # Lahey Fortran 8.1
+         _LT_TAGVAR(whole_archive_flag_spec, $1)=
+         tmp_sharedflag='--shared' ;;
+       xl[[cC]]*)                      # IBM XL C 8.0 on PPC (deal with xlf below)
+         tmp_sharedflag='-qmkshrobj'
+         tmp_addflag= ;;
+       esac
+       case `$CC -V 2>&1 | sed 5q` in
+       *Sun\ C*)                       # Sun C 5.9
+         _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+         _LT_TAGVAR(compiler_needs_object, $1)=yes
+         tmp_sharedflag='-G' ;;
+       *Sun\ F*)                       # Sun Fortran 8.3
+         tmp_sharedflag='-G' ;;
+       esac
+       _LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+
+        if test "x$supports_anon_versioning" = xyes; then
+          _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+           cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+           echo "local: *; };" >> $output_objdir/$libname.ver~
+           $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+        fi
+
+       case $cc_basename in
+       xlf*)
+         # IBM XL Fortran 10.1 on PPC cannot create shared libs itself
+         _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive'
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+         _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='-rpath $libdir'
+         _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $compiler_flags -soname $soname -o $lib'
+         if test "x$supports_anon_versioning" = xyes; then
+           _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+             cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+             echo "local: *; };" >> $output_objdir/$libname.ver~
+             $LD -shared $libobjs $deplibs $compiler_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib'
+         fi
+         ;;
+       esac
+      else
+        _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    netbsd* | netbsdelf*-gnu)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+       _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
+       wlarc=
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      fi
+      ;;
+
+    solaris*)
+      if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then
+       _LT_TAGVAR(ld_shlibs, $1)=no
+       cat <<_LT_EOF 1>&2
+
+*** Warning: The releases 2.8.* of the GNU linker cannot reliably
+*** create shared libraries on Solaris systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.9.1 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+      elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+       _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+      case `$LD -v 2>&1` in
+        *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*)
+       _LT_TAGVAR(ld_shlibs, $1)=no
+       cat <<_LT_EOF 1>&2
+
+*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
+*** reliably create shared libraries on SCO systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+       ;;
+       *)
+         # For security reasons, it is highly recommended that you always
+         # use absolute paths for naming shared libraries, and exclude the
+         # DT_RUNPATH tag from executables and libraries.  But doing so
+         # requires that you compile everything twice, which is a pain.
+         if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+           _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+         else
+           _LT_TAGVAR(ld_shlibs, $1)=no
+         fi
+       ;;
+      esac
+      ;;
+
+    sunos4*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      wlarc=
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+       _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+    esac
+
+    if test "$_LT_TAGVAR(ld_shlibs, $1)" = no; then
+      runpath_var=
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)=
+      _LT_TAGVAR(whole_archive_flag_spec, $1)=
+    fi
+  else
+    # PORTME fill in a description of your system's linker (not GNU ld)
+    case $host_os in
+    aix3*)
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(always_export_symbols, $1)=yes
+      _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
+      # Note: this linker hardcodes the directories in LIBPATH if there
+      # are no directories specified by -L.
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
+       # Neither direct hardcoding nor static linking is supported with a
+       # broken collect2.
+       _LT_TAGVAR(hardcode_direct, $1)=unsupported
+      fi
+      ;;
+
+    aix[[4-9]]*)
+      if test "$host_cpu" = ia64; then
+       # On IA64, the linker does run time linking by default, so we don't
+       # have to do anything special.
+       aix_use_runtimelinking=no
+       exp_sym_flag='-Bexport'
+       no_entry_flag=""
+      else
+       # If we're using GNU nm, then we don't want the "-C" option.
+       # -C means demangle to AIX nm, but means don't demangle with GNU nm
+       if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
+         _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+       else
+         _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+       fi
+       aix_use_runtimelinking=no
+
+       # Test if we are trying to use run time linking or normal
+       # AIX style linking. If -brtl is somewhere in LDFLAGS, we
+       # need to do runtime linking.
+       case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*)
+         for ld_flag in $LDFLAGS; do
+         if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
+           aix_use_runtimelinking=yes
+           break
+         fi
+         done
+         ;;
+       esac
+
+       exp_sym_flag='-bexport'
+       no_entry_flag='-bnoentry'
+      fi
+
+      # When large executables or shared objects are built, AIX ld can
+      # have problems creating the table of contents.  If linking a library
+      # or program results in "error TOC overflow" add -mminimal-toc to
+      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+      _LT_TAGVAR(archive_cmds, $1)=''
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      _LT_TAGVAR(file_list_spec, $1)='${wl}-f,'
+
+      if test "$GCC" = yes; then
+       case $host_os in aix4.[[012]]|aix4.[[012]].*)
+       # We only want to do this on AIX 4.2 and lower, the check
+       # below for broken collect2 doesn't work under 4.3+
+         collect2name=`${CC} -print-prog-name=collect2`
+         if test -f "$collect2name" &&
+          strings "$collect2name" | $GREP resolve_lib_name >/dev/null
+         then
+         # We have reworked collect2
+         :
+         else
+         # We have old collect2
+         _LT_TAGVAR(hardcode_direct, $1)=unsupported
+         # It fails to find uninstalled libraries when the uninstalled
+         # path is not listed in the libpath.  Setting hardcode_minus_L
+         # to unsupported forces relinking
+         _LT_TAGVAR(hardcode_minus_L, $1)=yes
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+         _LT_TAGVAR(hardcode_libdir_separator, $1)=
+         fi
+         ;;
+       esac
+       shared_flag='-shared'
+       if test "$aix_use_runtimelinking" = yes; then
+         shared_flag="$shared_flag "'${wl}-G'
+       fi
+       _LT_TAGVAR(link_all_deplibs, $1)=no
+      else
+       # not using gcc
+       if test "$host_cpu" = ia64; then
+       # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+       # chokes on -Wl,-G. The following line is correct:
+         shared_flag='-G'
+       else
+         if test "$aix_use_runtimelinking" = yes; then
+           shared_flag='${wl}-G'
+         else
+           shared_flag='${wl}-bM:SRE'
+         fi
+       fi
+      fi
+
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall'
+      # It seems that -bexpall does not export symbols beginning with
+      # underscore (_), so it is better to generate a list of symbols to export.
+      _LT_TAGVAR(always_export_symbols, $1)=yes
+      if test "$aix_use_runtimelinking" = yes; then
+       # Warning - without using the other runtime loading flags (-brtl),
+       # -berok will link without error, but may produce a broken library.
+       _LT_TAGVAR(allow_undefined_flag, $1)='-berok'
+        # Determine the default libpath from the value encoded in an
+        # empty executable.
+        _LT_SYS_MODULE_PATH_AIX
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+        _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+      else
+       if test "$host_cpu" = ia64; then
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
+         _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
+         _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+       else
+        # Determine the default libpath from the value encoded in an
+        # empty executable.
+        _LT_SYS_MODULE_PATH_AIX
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+         # Warning - without using the other run time loading flags,
+         # -berok will link without error, but may produce a broken library.
+         _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
+         _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
+         # Exported symbols can be pulled into shared objects from archives
+         _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
+         _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+         # This is similar to how AIX traditionally builds its shared libraries.
+         _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+       fi
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            _LT_TAGVAR(archive_expsym_cmds, $1)=''
+        ;;
+      m68k)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes
+        ;;
+      esac
+      ;;
+
+    bsdi[[45]]*)
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # When not using gcc, we currently assume that we are using
+      # Microsoft Visual C++.
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' '
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      # Tell ltmain to make .lib files, not .a files.
+      libext=lib
+      # Tell ltmain to make .dll files, not .so files.
+      shrext_cmds=".dll"
+      # FIXME: Setting linknames here is a bad hack.
+      _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `$ECHO "X$deplibs" | $Xsed -e '\''s/ -lc$//'\''` -link -dll~linknames='
+      # The linker will automatically build a .lib file if we build a DLL.
+      _LT_TAGVAR(old_archive_from_new_cmds, $1)='true'
+      # FIXME: Should let the user specify the lib program.
+      _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs'
+      _LT_TAGVAR(fix_srcfile_path, $1)='`cygpath -w "$srcfile"`'
+      _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+      ;;
+
+    darwin* | rhapsody*)
+      _LT_DARWIN_LINKER_FEATURES($1)
+      ;;
+
+    dgux*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    freebsd1*)
+      _LT_TAGVAR(ld_shlibs, $1)=no
+      ;;
+
+    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
+    # support.  Future versions do this automatically, but an explicit c++rt0.o
+    # does not break anything, and helps significantly (at the cost of a little
+    # extra space).
+    freebsd2.2*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
+    freebsd2*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
+    freebsd* | dragonfly*)
+      _LT_TAGVAR(archive_cmds, $1)='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    hpux9*)
+      if test "$GCC" = yes; then
+       _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+
+      # hardcode_minus_L: Not really in the search PATH,
+      # but as the default location of the library.
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+      ;;
+
+    hpux10*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      if test "$with_gnu_ld" = no; then
+       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+       _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir'
+       _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+       _LT_TAGVAR(hardcode_direct, $1)=yes
+       _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+       _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+       # hardcode_minus_L: Not really in the search PATH,
+       # but as the default location of the library.
+       _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      fi
+      ;;
+
+    hpux11*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+       case $host_cpu in
+       hppa*64*)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       ia64*)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       *)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       esac
+      else
+       case $host_cpu in
+       hppa*64*)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       ia64*)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       *)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       esac
+      fi
+      if test "$with_gnu_ld" = no; then
+       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+       _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+       case $host_cpu in
+       hppa*64*|ia64*)
+         _LT_TAGVAR(hardcode_direct, $1)=no
+         _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+         ;;
+       *)
+         _LT_TAGVAR(hardcode_direct, $1)=yes
+         _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+         _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+
+         # hardcode_minus_L: Not really in the search PATH,
+         # but as the default location of the library.
+         _LT_TAGVAR(hardcode_minus_L, $1)=yes
+         ;;
+       esac
+      fi
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      if test "$GCC" = yes; then
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+       # Try to use the -exported_symbol ld option, if it does not
+       # work, assume that -exports_file does not work either and
+       # implicitly export all symbols.
+        save_LDFLAGS="$LDFLAGS"
+        LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null"
+        AC_LINK_IFELSE(int foo(void) {},
+          _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib'
+        )
+        LDFLAGS="$save_LDFLAGS"
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(inherit_rpath, $1)=yes
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      ;;
+
+    netbsd* | netbsdelf*-gnu)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+       _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    newsos6)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *nto* | *qnx*)
+      ;;
+
+    openbsd*)
+      if test -f /usr/libexec/ld.so; then
+       _LT_TAGVAR(hardcode_direct, $1)=yes
+       _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+       _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+       if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+         _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+         _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+         _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+       else
+         case $host_os in
+          openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*)
+            _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+            ;;
+          *)
+            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+            ;;
+         esac
+       fi
+      else
+       _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    os2*)
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$ECHO DATA >> $output_objdir/$libname.def~$ECHO " SINGLE NONSHARED" >> $output_objdir/$libname.def~$ECHO EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
+      _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
+      ;;
+
+    osf3*)
+      if test "$GCC" = yes; then
+       _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+       _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      ;;
+
+    osf4* | osf5*)     # as osf3* with the addition of -msym flag
+      if test "$GCC" = yes; then
+       _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      else
+       _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~
+       $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp'
+
+       # Both c and cxx compiler support -rpath directly
+       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      ;;
+
+    solaris*)
+      _LT_TAGVAR(no_undefined_flag, $1)=' -z defs'
+      if test "$GCC" = yes; then
+       wlarc='${wl}'
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+         $CC -shared ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+      else
+       case `$CC -V 2>&1` in
+       *"Compilers 5.0"*)
+         wlarc=''
+         _LT_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
+         _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+         $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp'
+         ;;
+       *)
+         wlarc='${wl}'
+         _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags'
+         _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+         $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+         ;;
+       esac
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      case $host_os in
+      solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+      *)
+       # The compiler driver will combine and reorder linker options,
+       # but understands `-z linker_flag'.  GCC discards it without `$wl',
+       # but is careful enough not to reorder.
+       # Supported since Solaris 2.6 (maybe 2.5.1?)
+       if test "$GCC" = yes; then
+         _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+       else
+         _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
+       fi
+       ;;
+      esac
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      ;;
+
+    sunos4*)
+      if test "x$host_vendor" = xsequent; then
+       # Use $CC to link under sequent, because it throws in some extra .o
+       # files that make .init and .fini sections work.
+       _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    sysv4)
+      case $host_vendor in
+       sni)
+         _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+         _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true???
+       ;;
+       siemens)
+         ## LD is ld it makes a PLAMLIB
+         ## CC just makes a GrossModule.
+         _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags'
+         _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs'
+         _LT_TAGVAR(hardcode_direct, $1)=no
+        ;;
+       motorola)
+         _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+         _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie
+       ;;
+      esac
+      runpath_var='LD_RUN_PATH'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    sysv4.3*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+       _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+       _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+       runpath_var=LD_RUN_PATH
+       hardcode_runpath_var=yes
+       _LT_TAGVAR(ld_shlibs, $1)=yes
+      fi
+      ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6*)
+      # Note: We can NOT use -z defs as we might desire, because we do not
+      # link with -lc, and that would cause any symbols used from libc to
+      # always be unresolved, which means just about no library would
+      # ever link correctly.  If we're not using GNU ld we use -z text
+      # though, which does catch some bad symbols but isn't as heavy-handed
+      # as -z defs.
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    uts4*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *)
+      _LT_TAGVAR(ld_shlibs, $1)=no
+      ;;
+    esac
+
+    if test x$host_vendor = xsni; then
+      case $host in
+      sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
+       _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Blargedynsym'
+       ;;
+      esac
+    fi
+  fi
+])
+AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)])
+test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
+
+_LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld
+
+_LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl
+_LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl
+_LT_DECL([], [extract_expsyms_cmds], [2],
+    [The commands to extract the exported symbol list from a shared archive])
+
+#
+# Do we need to explicitly link libc?
+#
+case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in
+x|xyes)
+  # Assume -lc should be added
+  _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
+    case $_LT_TAGVAR(archive_cmds, $1) in
+    *'~'*)
+      # FIXME: we may have to deal with multi-command sequences.
+      ;;
+    '$CC '*)
+      # Test whether the compiler implicitly links with -lc since on some
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
+      # to ld, don't add -lc before -lgcc.
+      AC_MSG_CHECKING([whether -lc should be explicitly linked in])
+      $RM conftest*
+      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+      if AC_TRY_EVAL(ac_compile) 2>conftest.err; then
+        soname=conftest
+        lib=conftest
+        libobjs=conftest.$ac_objext
+        deplibs=
+        wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1)
+       pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1)
+        compiler_flags=-v
+        linker_flags=-v
+        verstring=
+        output_objdir=.
+        libname=conftest
+        lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1)
+        _LT_TAGVAR(allow_undefined_flag, $1)=
+        if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1)
+        then
+         _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+        else
+         _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+        fi
+        _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag
+      else
+        cat conftest.err 1>&5
+      fi
+      $RM conftest*
+      AC_MSG_RESULT([$_LT_TAGVAR(archive_cmds_need_lc, $1)])
+      ;;
+    esac
+  fi
+  ;;
+esac
+
+_LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0],
+    [Whether or not to add -lc for building shared libraries])
+_LT_TAGDECL([allow_libtool_libs_with_static_runtimes],
+    [enable_shared_with_static_runtimes], [0],
+    [Whether or not to disallow shared libs when runtime libs are static])
+_LT_TAGDECL([], [export_dynamic_flag_spec], [1],
+    [Compiler flag to allow reflexive dlopens])
+_LT_TAGDECL([], [whole_archive_flag_spec], [1],
+    [Compiler flag to generate shared objects directly from archives])
+_LT_TAGDECL([], [compiler_needs_object], [1],
+    [Whether the compiler copes with passing no objects directly])
+_LT_TAGDECL([], [old_archive_from_new_cmds], [2],
+    [Create an old-style archive from a shared archive])
+_LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2],
+    [Create a temporary old-style archive to link instead of a shared archive])
+_LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive])
+_LT_TAGDECL([], [archive_expsym_cmds], [2])
+_LT_TAGDECL([], [module_cmds], [2],
+    [Commands used to build a loadable module if different from building
+    a shared archive.])
+_LT_TAGDECL([], [module_expsym_cmds], [2])
+_LT_TAGDECL([], [with_gnu_ld], [1],
+    [Whether we are building with GNU ld or not])
+_LT_TAGDECL([], [allow_undefined_flag], [1],
+    [Flag that allows shared libraries with undefined symbols to be built])
+_LT_TAGDECL([], [no_undefined_flag], [1],
+    [Flag that enforces no undefined symbols])
+_LT_TAGDECL([], [hardcode_libdir_flag_spec], [1],
+    [Flag to hardcode $libdir into a binary during linking.
+    This must work even if $libdir does not exist])
+_LT_TAGDECL([], [hardcode_libdir_flag_spec_ld], [1],
+    [[If ld is used when linking, flag to hardcode $libdir into a binary
+    during linking.  This must work even if $libdir does not exist]])
+_LT_TAGDECL([], [hardcode_libdir_separator], [1],
+    [Whether we need a single "-rpath" flag with a separated argument])
+_LT_TAGDECL([], [hardcode_direct], [0],
+    [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes
+    DIR into the resulting binary])
+_LT_TAGDECL([], [hardcode_direct_absolute], [0],
+    [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes
+    DIR into the resulting binary and the resulting library dependency is
+    "absolute", i.e impossible to change by setting ${shlibpath_var} if the
+    library is relocated])
+_LT_TAGDECL([], [hardcode_minus_L], [0],
+    [Set to "yes" if using the -LDIR flag during linking hardcodes DIR
+    into the resulting binary])
+_LT_TAGDECL([], [hardcode_shlibpath_var], [0],
+    [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR
+    into the resulting binary])
+_LT_TAGDECL([], [hardcode_automatic], [0],
+    [Set to "yes" if building a shared library automatically hardcodes DIR
+    into the library and all subsequent libraries and executables linked
+    against it])
+_LT_TAGDECL([], [inherit_rpath], [0],
+    [Set to yes if linker adds runtime paths of dependent libraries
+    to runtime path list])
+_LT_TAGDECL([], [link_all_deplibs], [0],
+    [Whether libtool must link a program against all its dependency libraries])
+_LT_TAGDECL([], [fix_srcfile_path], [1],
+    [Fix the shell variable $srcfile for the compiler])
+_LT_TAGDECL([], [always_export_symbols], [0],
+    [Set to "yes" if exported symbols are required])
+_LT_TAGDECL([], [export_symbols_cmds], [2],
+    [The commands to list exported symbols])
+_LT_TAGDECL([], [exclude_expsyms], [1],
+    [Symbols that should not be listed in the preloaded symbols])
+_LT_TAGDECL([], [include_expsyms], [1],
+    [Symbols that must always be exported])
+_LT_TAGDECL([], [prelink_cmds], [2],
+    [Commands necessary for linking programs (against libraries) with templates])
+_LT_TAGDECL([], [file_list_spec], [1],
+    [Specify filename containing input files])
+dnl FIXME: Not yet implemented
+dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1],
+dnl    [Compiler flag to generate thread safe objects])
+])# _LT_LINKER_SHLIBS
+
+
+# _LT_LANG_C_CONFIG([TAG])
+# ------------------------
+# Ensure that the configuration variables for a C compiler are suitably
+# defined.  These variables are subsequently used by _LT_CONFIG to write
+# the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_C_CONFIG],
+[m4_require([_LT_DECL_EGREP])dnl
+lt_save_CC="$CC"
+AC_LANG_PUSH(C)
+
+# Source file extension for C test sources.
+ac_ext=c
+
+# Object file extension for compiled C test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="int some_variable = 0;"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='int main(){return(0);}'
+
+_LT_TAG_COMPILER
+# Save the default compiler, since it gets overwritten when the other
+# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP.
+compiler_DEFAULT=$CC
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+## CAVEAT EMPTOR:
+## There is no encapsulation within the following macros, do not change
+## the running order or otherwise move them around unless you know exactly
+## what you are doing...
+if test -n "$compiler"; then
+  _LT_COMPILER_NO_RTTI($1)
+  _LT_COMPILER_PIC($1)
+  _LT_COMPILER_C_O($1)
+  _LT_COMPILER_FILE_LOCKS($1)
+  _LT_LINKER_SHLIBS($1)
+  _LT_SYS_DYNAMIC_LINKER($1)
+  _LT_LINKER_HARDCODE_LIBPATH($1)
+  LT_SYS_DLOPEN_SELF
+  _LT_CMD_STRIPLIB
+
+  # Report which library types will actually be built
+  AC_MSG_CHECKING([if libtool supports shared libraries])
+  AC_MSG_RESULT([$can_build_shared])
+
+  AC_MSG_CHECKING([whether to build shared libraries])
+  test "$can_build_shared" = "no" && enable_shared=no
+
+  # On AIX, shared libraries and static libraries use the same namespace, and
+  # are all built from PIC.
+  case $host_os in
+  aix3*)
+    test "$enable_shared" = yes && enable_static=no
+    if test -n "$RANLIB"; then
+      archive_cmds="$archive_cmds~\$RANLIB \$lib"
+      postinstall_cmds='$RANLIB $lib'
+    fi
+    ;;
+
+  aix[[4-9]]*)
+    if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+      test "$enable_shared" = yes && enable_static=no
+    fi
+    ;;
+  esac
+  AC_MSG_RESULT([$enable_shared])
+
+  AC_MSG_CHECKING([whether to build static libraries])
+  # Make sure either enable_shared or enable_static is yes.
+  test "$enable_shared" = yes || enable_static=yes
+  AC_MSG_RESULT([$enable_static])
+
+  _LT_CONFIG($1)
+fi
+AC_LANG_POP
+CC="$lt_save_CC"
+])# _LT_LANG_C_CONFIG
+
+
+# _LT_PROG_CXX
+# ------------
+# Since AC_PROG_CXX is broken, in that it returns g++ if there is no c++
+# compiler, we have our own version here.
+m4_defun([_LT_PROG_CXX],
+[
+pushdef([AC_MSG_ERROR], [_lt_caught_CXX_error=yes])
+AC_PROG_CXX
+if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
+    ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
+    (test "X$CXX" != "Xg++"))) ; then
+  AC_PROG_CXXCPP
+else
+  _lt_caught_CXX_error=yes
+fi
+popdef([AC_MSG_ERROR])
+])# _LT_PROG_CXX
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([_LT_PROG_CXX], [])
+
+
+# _LT_LANG_CXX_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for a C++ compiler are suitably
+# defined.  These variables are subsequently used by _LT_CONFIG to write
+# the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_CXX_CONFIG],
+[AC_REQUIRE([_LT_PROG_CXX])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_EGREP])dnl
+
+AC_LANG_PUSH(C++)
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(compiler_needs_object, $1)=no
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for C++ test sources.
+ac_ext=cpp
+
+# Object file extension for compiled C++ test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the CXX compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_caught_CXX_error" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="int some_variable = 0;"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }'
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC=$CC
+  lt_save_LD=$LD
+  lt_save_GCC=$GCC
+  GCC=$GXX
+  lt_save_with_gnu_ld=$with_gnu_ld
+  lt_save_path_LD=$lt_cv_path_LD
+  if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then
+    lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx
+  else
+    $as_unset lt_cv_prog_gnu_ld
+  fi
+  if test -n "${lt_cv_path_LDCXX+set}"; then
+    lt_cv_path_LD=$lt_cv_path_LDCXX
+  else
+    $as_unset lt_cv_path_LD
+  fi
+  test -z "${LDCXX+set}" || LD=$LDCXX
+  CC=${CXX-"c++"}
+  compiler=$CC
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+
+  if test -n "$compiler"; then
+    # We don't want -fno-exception when compiling C++ code, so set the
+    # no_builtin_flag separately
+    if test "$GXX" = yes; then
+      _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
+    else
+      _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
+    fi
+
+    if test "$GXX" = yes; then
+      # Set up default GNU C++ configuration
+
+      LT_PATH_LD
+
+      # Check if GNU C++ uses GNU ld as the underlying linker, since the
+      # archiving commands below assume that GNU ld is being used.
+      if test "$with_gnu_ld" = yes; then
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+        _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+
+        # If archive_cmds runs LD, not CC, wlarc should be empty
+        # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to
+        #     investigate it a little bit more. (MM)
+        wlarc='${wl}'
+
+        # ancient GNU ld didn't support --whole-archive et. al.
+        if eval "`$CC -print-prog-name=ld` --help 2>&1" |
+         $GREP 'no-whole-archive' > /dev/null; then
+          _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+        else
+          _LT_TAGVAR(whole_archive_flag_spec, $1)=
+        fi
+      else
+        with_gnu_ld=no
+        wlarc=
+
+        # A generic and very simple default shared library creation
+        # command for GNU C++ for the case where it uses the native
+        # linker, instead of GNU ld.  If possible, this setting should
+        # overridden to take advantage of the native linker features on
+        # the platform it is being used on.
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
+      fi
+
+      # Commands to make compiler produce verbose output that lists
+      # what "hidden" libraries, object files and flags are used when
+      # linking a shared library.
+      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
+
+    else
+      GXX=no
+      with_gnu_ld=no
+      wlarc=
+    fi
+
+    # PORTME: fill in a description of your system's C++ link characteristics
+    AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
+    _LT_TAGVAR(ld_shlibs, $1)=yes
+    case $host_os in
+      aix3*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+      aix[[4-9]]*)
+        if test "$host_cpu" = ia64; then
+          # On IA64, the linker does run time linking by default, so we don't
+          # have to do anything special.
+          aix_use_runtimelinking=no
+          exp_sym_flag='-Bexport'
+          no_entry_flag=""
+        else
+          aix_use_runtimelinking=no
+
+          # Test if we are trying to use run time linking or normal
+          # AIX style linking. If -brtl is somewhere in LDFLAGS, we
+          # need to do runtime linking.
+          case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*)
+           for ld_flag in $LDFLAGS; do
+             case $ld_flag in
+             *-brtl*)
+               aix_use_runtimelinking=yes
+               break
+               ;;
+             esac
+           done
+           ;;
+          esac
+
+          exp_sym_flag='-bexport'
+          no_entry_flag='-bnoentry'
+        fi
+
+        # When large executables or shared objects are built, AIX ld can
+        # have problems creating the table of contents.  If linking a library
+        # or program results in "error TOC overflow" add -mminimal-toc to
+        # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+        # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+        _LT_TAGVAR(archive_cmds, $1)=''
+        _LT_TAGVAR(hardcode_direct, $1)=yes
+        _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+        _LT_TAGVAR(link_all_deplibs, $1)=yes
+        _LT_TAGVAR(file_list_spec, $1)='${wl}-f,'
+
+        if test "$GXX" = yes; then
+          case $host_os in aix4.[[012]]|aix4.[[012]].*)
+          # We only want to do this on AIX 4.2 and lower, the check
+          # below for broken collect2 doesn't work under 4.3+
+         collect2name=`${CC} -print-prog-name=collect2`
+         if test -f "$collect2name" &&
+            strings "$collect2name" | $GREP resolve_lib_name >/dev/null
+         then
+           # We have reworked collect2
+           :
+         else
+           # We have old collect2
+           _LT_TAGVAR(hardcode_direct, $1)=unsupported
+           # It fails to find uninstalled libraries when the uninstalled
+           # path is not listed in the libpath.  Setting hardcode_minus_L
+           # to unsupported forces relinking
+           _LT_TAGVAR(hardcode_minus_L, $1)=yes
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+           _LT_TAGVAR(hardcode_libdir_separator, $1)=
+         fi
+          esac
+          shared_flag='-shared'
+         if test "$aix_use_runtimelinking" = yes; then
+           shared_flag="$shared_flag "'${wl}-G'
+         fi
+        else
+          # not using gcc
+          if test "$host_cpu" = ia64; then
+         # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+         # chokes on -Wl,-G. The following line is correct:
+         shared_flag='-G'
+          else
+           if test "$aix_use_runtimelinking" = yes; then
+             shared_flag='${wl}-G'
+           else
+             shared_flag='${wl}-bM:SRE'
+           fi
+          fi
+        fi
+
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall'
+        # It seems that -bexpall does not export symbols beginning with
+        # underscore (_), so it is better to generate a list of symbols to
+       # export.
+        _LT_TAGVAR(always_export_symbols, $1)=yes
+        if test "$aix_use_runtimelinking" = yes; then
+          # Warning - without using the other runtime loading flags (-brtl),
+          # -berok will link without error, but may produce a broken library.
+          _LT_TAGVAR(allow_undefined_flag, $1)='-berok'
+          # Determine the default libpath from the value encoded in an empty
+          # executable.
+          _LT_SYS_MODULE_PATH_AIX
+          _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+
+          _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+        else
+          if test "$host_cpu" = ia64; then
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
+           _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
+           _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+          else
+           # Determine the default libpath from the value encoded in an
+           # empty executable.
+           _LT_SYS_MODULE_PATH_AIX
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+           # Warning - without using the other run time loading flags,
+           # -berok will link without error, but may produce a broken library.
+           _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
+           _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
+           # Exported symbols can be pulled into shared objects from archives
+           _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
+           _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+           # This is similar to how AIX traditionally builds its shared
+           # libraries.
+           _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+          fi
+        fi
+        ;;
+
+      beos*)
+       if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+         _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+         # Joseph Beckenbach <jrb3@best.com> says some releases of gcc
+         # support --undefined.  This deserves some investigation.  FIXME
+         _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+       else
+         _LT_TAGVAR(ld_shlibs, $1)=no
+       fi
+       ;;
+
+      chorus*)
+        case $cc_basename in
+          *)
+         # FIXME: insert proper C++ library support
+         _LT_TAGVAR(ld_shlibs, $1)=no
+         ;;
+        esac
+        ;;
+
+      cygwin* | mingw* | pw32* | cegcc*)
+        # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
+        # as there is no search path for DLLs.
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+        _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+        _LT_TAGVAR(always_export_symbols, $1)=no
+        _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+
+        if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
+          _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+          # If the export-symbols file already is a .def file (1st line
+          # is EXPORTS), use it as is; otherwise, prepend...
+          _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+           cp $export_symbols $output_objdir/$soname.def;
+          else
+           echo EXPORTS > $output_objdir/$soname.def;
+           cat $export_symbols >> $output_objdir/$soname.def;
+          fi~
+          $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+        else
+          _LT_TAGVAR(ld_shlibs, $1)=no
+        fi
+        ;;
+      darwin* | rhapsody*)
+        _LT_DARWIN_LINKER_FEATURES($1)
+       ;;
+
+      dgux*)
+        case $cc_basename in
+          ec++*)
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+          ghcx*)
+           # Green Hills C++ Compiler
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+          *)
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+        esac
+        ;;
+
+      freebsd[[12]]*)
+        # C++ shared libraries reported to be fairly broken before
+       # switch to ELF
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      freebsd-elf*)
+        _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+        ;;
+
+      freebsd* | dragonfly*)
+        # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF
+        # conventions
+        _LT_TAGVAR(ld_shlibs, $1)=yes
+        ;;
+
+      gnu*)
+        ;;
+
+      hpux9*)
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+        _LT_TAGVAR(hardcode_direct, $1)=yes
+        _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
+                                            # but as the default
+                                            # location of the library.
+
+        case $cc_basename in
+          CC*)
+            # FIXME: insert proper C++ library support
+            _LT_TAGVAR(ld_shlibs, $1)=no
+            ;;
+          aCC*)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+            # Commands to make compiler produce verbose output that lists
+            # what "hidden" libraries, object files and flags are used when
+            # linking a shared library.
+            #
+            # There doesn't appear to be a way to prevent this compiler from
+            # explicitly linking system object files so we need to strip them
+            # from the output so that they don't get included in the library
+            # dependencies.
+            output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+            ;;
+          *)
+            if test "$GXX" = yes; then
+              _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+            else
+              # FIXME: insert proper C++ library support
+              _LT_TAGVAR(ld_shlibs, $1)=no
+            fi
+            ;;
+        esac
+        ;;
+
+      hpux10*|hpux11*)
+        if test $with_gnu_ld = no; then
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+         _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+          case $host_cpu in
+            hppa*64*|ia64*)
+              ;;
+            *)
+             _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+              ;;
+          esac
+        fi
+        case $host_cpu in
+          hppa*64*|ia64*)
+            _LT_TAGVAR(hardcode_direct, $1)=no
+            _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+            ;;
+          *)
+            _LT_TAGVAR(hardcode_direct, $1)=yes
+            _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
+                                                # but as the default
+                                                # location of the library.
+            ;;
+        esac
+
+        case $cc_basename in
+          CC*)
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+          aCC*)
+           case $host_cpu in
+             hppa*64*)
+               _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+               ;;
+             ia64*)
+               _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+               ;;
+             *)
+               _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+               ;;
+           esac
+           # Commands to make compiler produce verbose output that lists
+           # what "hidden" libraries, object files and flags are used when
+           # linking a shared library.
+           #
+           # There doesn't appear to be a way to prevent this compiler from
+           # explicitly linking system object files so we need to strip them
+           # from the output so that they don't get included in the library
+           # dependencies.
+           output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+           ;;
+          *)
+           if test "$GXX" = yes; then
+             if test $with_gnu_ld = no; then
+               case $host_cpu in
+                 hppa*64*)
+                   _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+                   ;;
+                 ia64*)
+                   _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+                   ;;
+                 *)
+                   _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+                   ;;
+               esac
+             fi
+           else
+             # FIXME: insert proper C++ library support
+             _LT_TAGVAR(ld_shlibs, $1)=no
+           fi
+           ;;
+        esac
+        ;;
+
+      interix[[3-9]]*)
+       _LT_TAGVAR(hardcode_direct, $1)=no
+       _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+       _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+       # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+       # Instead, shared libraries are loaded at an image base (0x10000000 by
+       # default) and relocated if they conflict, which is a slow very memory
+       # consuming and fragmenting process.  To avoid this, we pick a random,
+       # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+       # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+       ;;
+      irix5* | irix6*)
+        case $cc_basename in
+          CC*)
+           # SGI C++
+           _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+
+           # Archives containing C++ object files must be created using
+           # "CC -ar", where "CC" is the IRIX C++ compiler.  This is
+           # necessary to make sure instantiated templates are included
+           # in the archive.
+           _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs'
+           ;;
+          *)
+           if test "$GXX" = yes; then
+             if test "$with_gnu_ld" = no; then
+               _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+             else
+               _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` -o $lib'
+             fi
+           fi
+           _LT_TAGVAR(link_all_deplibs, $1)=yes
+           ;;
+        esac
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+        _LT_TAGVAR(inherit_rpath, $1)=yes
+        ;;
+
+      linux* | k*bsd*-gnu)
+        case $cc_basename in
+          KCC*)
+           # Kuck and Associates, Inc. (KAI) C++ Compiler
+
+           # KCC will only create a shared library if the output file
+           # ends with ".so" (or ".sl" for HP-UX), so rename the library
+           # to its proper name (with version) after linking.
+           _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+           _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib'
+           # Commands to make compiler produce verbose output that lists
+           # what "hidden" libraries, object files and flags are used when
+           # linking a shared library.
+           #
+           # There doesn't appear to be a way to prevent this compiler from
+           # explicitly linking system object files so we need to strip them
+           # from the output so that they don't get included in the library
+           # dependencies.
+           output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+
+           # Archives containing C++ object files must be created using
+           # "CC -Bstatic", where "CC" is the KAI C++ compiler.
+           _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs'
+           ;;
+         icpc* | ecpc* )
+           # Intel C++
+           with_gnu_ld=yes
+           # version 8.0 and above of icpc choke on multiply defined symbols
+           # if we add $predep_objects and $postdep_objects, however 7.1 and
+           # earlier do not add the objects themselves.
+           case `$CC -V 2>&1` in
+             *"Version 7."*)
+               _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+               _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+               ;;
+             *)  # Version 8.0 or newer
+               tmp_idyn=
+               case $host_cpu in
+                 ia64*) tmp_idyn=' -i_dynamic';;
+               esac
+               _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+               _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+               ;;
+           esac
+           _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+           _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
+           ;;
+          pgCC* | pgcpp*)
+            # Portland Group C++ compiler
+           case `$CC -V` in
+           *pgCC\ [[1-5]]* | *pgcpp\ [[1-5]]*)
+             _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~
+               rm -rf $tpldir~
+               $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~
+               compile_command="$compile_command `find $tpldir -name \*.o | $NL2SP`"'
+             _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~
+               rm -rf $tpldir~
+               $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~
+               $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | $NL2SP`~
+               $RANLIB $oldlib'
+             _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~
+               rm -rf $tpldir~
+               $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
+               $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
+             _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~
+               rm -rf $tpldir~
+               $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
+               $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
+             ;;
+           *) # Version 6 will use weak symbols
+             _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
+             _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
+             ;;
+           esac
+
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
+           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+           _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+            ;;
+         cxx*)
+           # Compaq C++
+           _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname  -o $lib ${wl}-retain-symbols-file $wl$export_symbols'
+
+           runpath_var=LD_RUN_PATH
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+           _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+           # Commands to make compiler produce verbose output that lists
+           # what "hidden" libraries, object files and flags are used when
+           # linking a shared library.
+           #
+           # There doesn't appear to be a way to prevent this compiler from
+           # explicitly linking system object files so we need to strip them
+           # from the output so that they don't get included in the library
+           # dependencies.
+           output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+           ;;
+         xl*)
+           # IBM XL 8.0 on PPC, with GNU ld
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+           _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+           if test "x$supports_anon_versioning" = xyes; then
+             _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+               cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+               echo "local: *; };" >> $output_objdir/$libname.ver~
+               $CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+           fi
+           ;;
+         *)
+           case `$CC -V 2>&1 | sed 5q` in
+           *Sun\ C*)
+             # Sun C++ 5.9
+             _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs'
+             _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+             _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols'
+             _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+             _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+             _LT_TAGVAR(compiler_needs_object, $1)=yes
+
+             # Not sure whether something based on
+             # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1
+             # would be better.
+             output_verbose_link_cmd='echo'
+
+             # Archives containing C++ object files must be created using
+             # "CC -xar", where "CC" is the Sun C++ compiler.  This is
+             # necessary to make sure instantiated templates are included
+             # in the archive.
+             _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
+             ;;
+           esac
+           ;;
+       esac
+       ;;
+
+      lynxos*)
+        # FIXME: insert proper C++ library support
+       _LT_TAGVAR(ld_shlibs, $1)=no
+       ;;
+
+      m88k*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+       ;;
+
+      mvs*)
+        case $cc_basename in
+          cxx*)
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+         *)
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+       esac
+       ;;
+
+      netbsd*)
+        if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+         _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable  -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags'
+         wlarc=
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+         _LT_TAGVAR(hardcode_direct, $1)=yes
+         _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+       fi
+       # Workaround some broken pre-1.5 toolchains
+       output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"'
+       ;;
+
+      *nto* | *qnx*)
+        _LT_TAGVAR(ld_shlibs, $1)=yes
+       ;;
+
+      openbsd2*)
+        # C++ shared libraries are fairly broken
+       _LT_TAGVAR(ld_shlibs, $1)=no
+       ;;
+
+      openbsd*)
+       if test -f /usr/libexec/ld.so; then
+         _LT_TAGVAR(hardcode_direct, $1)=yes
+         _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+         _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+         _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+         if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib'
+           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+           _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+         fi
+         output_verbose_link_cmd=echo
+       else
+         _LT_TAGVAR(ld_shlibs, $1)=no
+       fi
+       ;;
+
+      osf3* | osf4* | osf5*)
+        case $cc_basename in
+          KCC*)
+           # Kuck and Associates, Inc. (KAI) C++ Compiler
+
+           # KCC will only create a shared library if the output file
+           # ends with ".so" (or ".sl" for HP-UX), so rename the library
+           # to its proper name (with version) after linking.
+           _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+           _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+           # Archives containing C++ object files must be created using
+           # the KAI C++ compiler.
+           case $host in
+             osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;;
+             *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;;
+           esac
+           ;;
+          RCC*)
+           # Rational C++ 2.4.1
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+          cxx*)
+           case $host in
+             osf3*)
+               _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+               _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && $ECHO "X${wl}-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+               _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+               ;;
+             *)
+               _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+               _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+               _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~
+                 echo "-hidden">> $lib.exp~
+                 $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname ${wl}-input ${wl}$lib.exp  `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~
+                 $RM $lib.exp'
+               _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+               ;;
+           esac
+
+           _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+           # Commands to make compiler produce verbose output that lists
+           # what "hidden" libraries, object files and flags are used when
+           # linking a shared library.
+           #
+           # There doesn't appear to be a way to prevent this compiler from
+           # explicitly linking system object files so we need to strip them
+           # from the output so that they don't get included in the library
+           # dependencies.
+           output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+           ;;
+         *)
+           if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+             _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+             case $host in
+               osf3*)
+                 _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+                 ;;
+               *)
+                 _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+                 ;;
+             esac
+
+             _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+             _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+             # Commands to make compiler produce verbose output that lists
+             # what "hidden" libraries, object files and flags are used when
+             # linking a shared library.
+             output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
+
+           else
+             # FIXME: insert proper C++ library support
+             _LT_TAGVAR(ld_shlibs, $1)=no
+           fi
+           ;;
+        esac
+        ;;
+
+      psos*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      sunos4*)
+        case $cc_basename in
+          CC*)
+           # Sun C++ 4.x
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+          lcc*)
+           # Lucid
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+          *)
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+        esac
+        ;;
+
+      solaris*)
+        case $cc_basename in
+          CC*)
+           # Sun C++ 4.2, 5.x and Centerline C++
+            _LT_TAGVAR(archive_cmds_need_lc,$1)=yes
+           _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs'
+           _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag}  -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+           _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+             $CC -G${allow_undefined_flag} ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+           _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+           case $host_os in
+             solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+             *)
+               # The compiler driver will combine and reorder linker options,
+               # but understands `-z linker_flag'.
+               # Supported since Solaris 2.6 (maybe 2.5.1?)
+               _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
+               ;;
+           esac
+           _LT_TAGVAR(link_all_deplibs, $1)=yes
+
+           output_verbose_link_cmd='echo'
+
+           # Archives containing C++ object files must be created using
+           # "CC -xar", where "CC" is the Sun C++ compiler.  This is
+           # necessary to make sure instantiated templates are included
+           # in the archive.
+           _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
+           ;;
+          gcx*)
+           # Green Hills C++ Compiler
+           _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+
+           # The C++ compiler must be used to create the archive.
+           _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs'
+           ;;
+          *)
+           # GNU C++ compiler with Solaris linker
+           if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+             _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs'
+             if $CC --version | $GREP -v '^2\.7' > /dev/null; then
+               _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+               _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+                 $CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+               # Commands to make compiler produce verbose output that lists
+               # what "hidden" libraries, object files and flags are used when
+               # linking a shared library.
+               output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
+             else
+               # g++ 2.7 appears to require `-G' NOT `-shared' on this
+               # platform.
+               _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+               _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+                 $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+               # Commands to make compiler produce verbose output that lists
+               # what "hidden" libraries, object files and flags are used when
+               # linking a shared library.
+               output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
+             fi
+
+             _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir'
+             case $host_os in
+               solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+               *)
+                 _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+                 ;;
+             esac
+           fi
+           ;;
+        esac
+        ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      runpath_var='LD_RUN_PATH'
+
+      case $cc_basename in
+        CC*)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+         _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       *)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+         _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+      esac
+      ;;
+
+      sysv5* | sco3.2v5* | sco5v6*)
+       # Note: We can NOT use -z defs as we might desire, because we do not
+       # link with -lc, and that would cause any symbols used from libc to
+       # always be unresolved, which means just about no library would
+       # ever link correctly.  If we're not using GNU ld we use -z text
+       # though, which does catch some bad symbols but isn't as heavy-handed
+       # as -z defs.
+       _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+       _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
+       _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+       _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir'
+       _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+       _LT_TAGVAR(link_all_deplibs, $1)=yes
+       _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
+       runpath_var='LD_RUN_PATH'
+
+       case $cc_basename in
+          CC*)
+           _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+           ;;
+         *)
+           _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+           ;;
+       esac
+      ;;
+
+      tandem*)
+        case $cc_basename in
+          NCC*)
+           # NonStop-UX NCC 3.20
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+          *)
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+        esac
+        ;;
+
+      vxworks*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      *)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+    esac
+
+    AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)])
+    test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
+
+    _LT_TAGVAR(GCC, $1)="$GXX"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_SYS_HIDDEN_LIBDEPS($1)
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  CC=$lt_save_CC
+  LDCXX=$LD
+  LD=$lt_save_LD
+  GCC=$lt_save_GCC
+  with_gnu_ld=$lt_save_with_gnu_ld
+  lt_cv_path_LDCXX=$lt_cv_path_LD
+  lt_cv_path_LD=$lt_save_path_LD
+  lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld
+  lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld
+fi # test "$_lt_caught_CXX_error" != yes
+
+AC_LANG_POP
+])# _LT_LANG_CXX_CONFIG
+
+
+# _LT_SYS_HIDDEN_LIBDEPS([TAGNAME])
+# ---------------------------------
+# Figure out "hidden" library dependencies from verbose
+# compiler output when linking a shared library.
+# Parse the compiler output and extract the necessary
+# objects, libraries and library flags.
+m4_defun([_LT_SYS_HIDDEN_LIBDEPS],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+# Dependencies to place before and after the object being linked:
+_LT_TAGVAR(predep_objects, $1)=
+_LT_TAGVAR(postdep_objects, $1)=
+_LT_TAGVAR(predeps, $1)=
+_LT_TAGVAR(postdeps, $1)=
+_LT_TAGVAR(compiler_lib_search_path, $1)=
+
+dnl we can't use the lt_simple_compile_test_code here,
+dnl because it contains code intended for an executable,
+dnl not a library.  It's possible we should let each
+dnl tag define a new lt_????_link_test_code variable,
+dnl but it's only used here...
+m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF
+int a;
+void foo (void) { a = 0; }
+_LT_EOF
+], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF
+class Foo
+{
+public:
+  Foo (void) { a = 0; }
+private:
+  int a;
+};
+_LT_EOF
+], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF
+      subroutine foo
+      implicit none
+      integer*4 a
+      a=0
+      return
+      end
+_LT_EOF
+], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF
+      subroutine foo
+      implicit none
+      integer a
+      a=0
+      return
+      end
+_LT_EOF
+], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF
+public class foo {
+  private int a;
+  public void bar (void) {
+    a = 0;
+  }
+};
+_LT_EOF
+])
+dnl Parse the compiler output and extract the necessary
+dnl objects, libraries and library flags.
+if AC_TRY_EVAL(ac_compile); then
+  # Parse the compiler output and extract the necessary
+  # objects, libraries and library flags.
+
+  # Sentinel used to keep track of whether or not we are before
+  # the conftest object file.
+  pre_test_object_deps_done=no
+
+  for p in `eval "$output_verbose_link_cmd"`; do
+    case $p in
+
+    -L* | -R* | -l*)
+       # Some compilers place space between "-{L,R}" and the path.
+       # Remove the space.
+       if test $p = "-L" ||
+          test $p = "-R"; then
+        prev=$p
+        continue
+       else
+        prev=
+       fi
+
+       if test "$pre_test_object_deps_done" = no; then
+        case $p in
+        -L* | -R*)
+          # Internal compiler library paths should come after those
+          # provided the user.  The postdeps already come after the
+          # user supplied libs so there is no need to process them.
+          if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then
+            _LT_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}"
+          else
+            _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}"
+          fi
+          ;;
+        # The "-l" case would never come before the object being
+        # linked, so don't bother handling this case.
+        esac
+       else
+        if test -z "$_LT_TAGVAR(postdeps, $1)"; then
+          _LT_TAGVAR(postdeps, $1)="${prev}${p}"
+        else
+          _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} ${prev}${p}"
+        fi
+       fi
+       ;;
+
+    *.$objext)
+       # This assumes that the test object file only shows up
+       # once in the compiler output.
+       if test "$p" = "conftest.$objext"; then
+        pre_test_object_deps_done=yes
+        continue
+       fi
+
+       if test "$pre_test_object_deps_done" = no; then
+        if test -z "$_LT_TAGVAR(predep_objects, $1)"; then
+          _LT_TAGVAR(predep_objects, $1)="$p"
+        else
+          _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p"
+        fi
+       else
+        if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then
+          _LT_TAGVAR(postdep_objects, $1)="$p"
+        else
+          _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p"
+        fi
+       fi
+       ;;
+
+    *) ;; # Ignore the rest.
+
+    esac
+  done
+
+  # Clean up.
+  rm -f a.out a.exe
+else
+  echo "libtool.m4: error: problem compiling $1 test program"
+fi
+
+$RM -f confest.$objext
+
+# PORTME: override above test on systems where it is broken
+m4_if([$1], [CXX],
+[case $host_os in
+interix[[3-9]]*)
+  # Interix 3.5 installs completely hosed .la files for C++, so rather than
+  # hack all around it, let's just trust "g++" to DTRT.
+  _LT_TAGVAR(predep_objects,$1)=
+  _LT_TAGVAR(postdep_objects,$1)=
+  _LT_TAGVAR(postdeps,$1)=
+  ;;
+
+linux*)
+  case `$CC -V 2>&1 | sed 5q` in
+  *Sun\ C*)
+    # Sun C++ 5.9
+
+    # The more standards-conforming stlport4 library is
+    # incompatible with the Cstd library. Avoid specifying
+    # it if it's in CXXFLAGS. Ignore libCrun as
+    # -library=stlport4 depends on it.
+    case " $CXX $CXXFLAGS " in
+    *" -library=stlport4 "*)
+      solaris_use_stlport4=yes
+      ;;
+    esac
+
+    if test "$solaris_use_stlport4" != yes; then
+      _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
+    fi
+    ;;
+  esac
+  ;;
+
+solaris*)
+  case $cc_basename in
+  CC*)
+    # The more standards-conforming stlport4 library is
+    # incompatible with the Cstd library. Avoid specifying
+    # it if it's in CXXFLAGS. Ignore libCrun as
+    # -library=stlport4 depends on it.
+    case " $CXX $CXXFLAGS " in
+    *" -library=stlport4 "*)
+      solaris_use_stlport4=yes
+      ;;
+    esac
+
+    # Adding this requires a known-good setup of shared libraries for
+    # Sun compiler versions before 5.6, else PIC objects from an old
+    # archive will be linked into the output, leading to subtle bugs.
+    if test "$solaris_use_stlport4" != yes; then
+      _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
+    fi
+    ;;
+  esac
+  ;;
+esac
+])
+
+case " $_LT_TAGVAR(postdeps, $1) " in
+*" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;;
+esac
+ _LT_TAGVAR(compiler_lib_search_dirs, $1)=
+if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then
+ _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | ${SED} -e 's! -L! !g' -e 's!^ !!'`
+fi
+_LT_TAGDECL([], [compiler_lib_search_dirs], [1],
+    [The directories searched by this compiler when creating a shared library])
+_LT_TAGDECL([], [predep_objects], [1],
+    [Dependencies to place before and after the objects being linked to
+    create a shared library])
+_LT_TAGDECL([], [postdep_objects], [1])
+_LT_TAGDECL([], [predeps], [1])
+_LT_TAGDECL([], [postdeps], [1])
+_LT_TAGDECL([], [compiler_lib_search_path], [1],
+    [The library search path used internally by the compiler when linking
+    a shared library])
+])# _LT_SYS_HIDDEN_LIBDEPS
+
+
+# _LT_PROG_F77
+# ------------
+# Since AC_PROG_F77 is broken, in that it returns the empty string
+# if there is no fortran compiler, we have our own version here.
+m4_defun([_LT_PROG_F77],
+[
+pushdef([AC_MSG_ERROR], [_lt_disable_F77=yes])
+AC_PROG_F77
+if test -z "$F77" || test "X$F77" = "Xno"; then
+  _lt_disable_F77=yes
+fi
+popdef([AC_MSG_ERROR])
+])# _LT_PROG_F77
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([_LT_PROG_F77], [])
+
+
+# _LT_LANG_F77_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for a Fortran 77 compiler are
+# suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_F77_CONFIG],
+[AC_REQUIRE([_LT_PROG_F77])dnl
+AC_LANG_PUSH(Fortran 77)
+
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for f77 test sources.
+ac_ext=f
+
+# Object file extension for compiled f77 test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the F77 compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_disable_F77" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="\
+      subroutine t
+      return
+      end
+"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code="\
+      program t
+      end
+"
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC="$CC"
+  lt_save_GCC=$GCC
+  CC=${F77-"f77"}
+  compiler=$CC
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+  GCC=$G77
+  if test -n "$compiler"; then
+    AC_MSG_CHECKING([if libtool supports shared libraries])
+    AC_MSG_RESULT([$can_build_shared])
+
+    AC_MSG_CHECKING([whether to build shared libraries])
+    test "$can_build_shared" = "no" && enable_shared=no
+
+    # On AIX, shared libraries and static libraries use the same namespace, and
+    # are all built from PIC.
+    case $host_os in
+      aix3*)
+        test "$enable_shared" = yes && enable_static=no
+        if test -n "$RANLIB"; then
+          archive_cmds="$archive_cmds~\$RANLIB \$lib"
+          postinstall_cmds='$RANLIB $lib'
+        fi
+        ;;
+      aix[[4-9]]*)
+       if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+         test "$enable_shared" = yes && enable_static=no
+       fi
+        ;;
+    esac
+    AC_MSG_RESULT([$enable_shared])
+
+    AC_MSG_CHECKING([whether to build static libraries])
+    # Make sure either enable_shared or enable_static is yes.
+    test "$enable_shared" = yes || enable_static=yes
+    AC_MSG_RESULT([$enable_static])
+
+    _LT_TAGVAR(GCC, $1)="$G77"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  GCC=$lt_save_GCC
+  CC="$lt_save_CC"
+fi # test "$_lt_disable_F77" != yes
+
+AC_LANG_POP
+])# _LT_LANG_F77_CONFIG
+
+
+# _LT_PROG_FC
+# -----------
+# Since AC_PROG_FC is broken, in that it returns the empty string
+# if there is no fortran compiler, we have our own version here.
+m4_defun([_LT_PROG_FC],
+[
+pushdef([AC_MSG_ERROR], [_lt_disable_FC=yes])
+AC_PROG_FC
+if test -z "$FC" || test "X$FC" = "Xno"; then
+  _lt_disable_FC=yes
+fi
+popdef([AC_MSG_ERROR])
+])# _LT_PROG_FC
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([_LT_PROG_FC], [])
+
+
+# _LT_LANG_FC_CONFIG([TAG])
+# -------------------------
+# Ensure that the configuration variables for a Fortran compiler are
+# suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_FC_CONFIG],
+[AC_REQUIRE([_LT_PROG_FC])dnl
+AC_LANG_PUSH(Fortran)
+
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for fc test sources.
+ac_ext=${ac_fc_srcext-f}
+
+# Object file extension for compiled fc test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the FC compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_disable_FC" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="\
+      subroutine t
+      return
+      end
+"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code="\
+      program t
+      end
+"
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC="$CC"
+  lt_save_GCC=$GCC
+  CC=${FC-"f95"}
+  compiler=$CC
+  GCC=$ac_cv_fc_compiler_gnu
+
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+
+  if test -n "$compiler"; then
+    AC_MSG_CHECKING([if libtool supports shared libraries])
+    AC_MSG_RESULT([$can_build_shared])
+
+    AC_MSG_CHECKING([whether to build shared libraries])
+    test "$can_build_shared" = "no" && enable_shared=no
+
+    # On AIX, shared libraries and static libraries use the same namespace, and
+    # are all built from PIC.
+    case $host_os in
+      aix3*)
+        test "$enable_shared" = yes && enable_static=no
+        if test -n "$RANLIB"; then
+          archive_cmds="$archive_cmds~\$RANLIB \$lib"
+          postinstall_cmds='$RANLIB $lib'
+        fi
+        ;;
+      aix[[4-9]]*)
+       if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+         test "$enable_shared" = yes && enable_static=no
+       fi
+        ;;
+    esac
+    AC_MSG_RESULT([$enable_shared])
+
+    AC_MSG_CHECKING([whether to build static libraries])
+    # Make sure either enable_shared or enable_static is yes.
+    test "$enable_shared" = yes || enable_static=yes
+    AC_MSG_RESULT([$enable_static])
+
+    _LT_TAGVAR(GCC, $1)="$ac_cv_fc_compiler_gnu"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_SYS_HIDDEN_LIBDEPS($1)
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  GCC=$lt_save_GCC
+  CC="$lt_save_CC"
+fi # test "$_lt_disable_FC" != yes
+
+AC_LANG_POP
+])# _LT_LANG_FC_CONFIG
+
+
+# _LT_LANG_GCJ_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for the GNU Java Compiler compiler
+# are suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_GCJ_CONFIG],
+[AC_REQUIRE([LT_PROG_GCJ])dnl
+AC_LANG_SAVE
+
+# Source file extension for Java test sources.
+ac_ext=java
+
+# Object file extension for compiled Java test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="class foo {}"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }'
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_TAG_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC="$CC"
+lt_save_GCC=$GCC
+GCC=yes
+CC=${GCJ-"gcj"}
+compiler=$CC
+_LT_TAGVAR(compiler, $1)=$CC
+_LT_TAGVAR(LD, $1)="$LD"
+_LT_CC_BASENAME([$compiler])
+
+# GCJ did not exist at the time GCC didn't implicitly link libc in.
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+
+## CAVEAT EMPTOR:
+## There is no encapsulation within the following macros, do not change
+## the running order or otherwise move them around unless you know exactly
+## what you are doing...
+if test -n "$compiler"; then
+  _LT_COMPILER_NO_RTTI($1)
+  _LT_COMPILER_PIC($1)
+  _LT_COMPILER_C_O($1)
+  _LT_COMPILER_FILE_LOCKS($1)
+  _LT_LINKER_SHLIBS($1)
+  _LT_LINKER_HARDCODE_LIBPATH($1)
+
+  _LT_CONFIG($1)
+fi
+
+AC_LANG_RESTORE
+
+GCC=$lt_save_GCC
+CC="$lt_save_CC"
+])# _LT_LANG_GCJ_CONFIG
+
+
+# _LT_LANG_RC_CONFIG([TAG])
+# -------------------------
+# Ensure that the configuration variables for the Windows resource compiler
+# are suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_RC_CONFIG],
+[AC_REQUIRE([LT_PROG_RC])dnl
+AC_LANG_SAVE
+
+# Source file extension for RC test sources.
+ac_ext=rc
+
+# Object file extension for compiled RC test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }'
+
+# Code to be used in simple link tests
+lt_simple_link_test_code="$lt_simple_compile_test_code"
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_TAG_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC="$CC"
+lt_save_GCC=$GCC
+GCC=
+CC=${RC-"windres"}
+compiler=$CC
+_LT_TAGVAR(compiler, $1)=$CC
+_LT_CC_BASENAME([$compiler])
+_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
+
+if test -n "$compiler"; then
+  :
+  _LT_CONFIG($1)
+fi
+
+GCC=$lt_save_GCC
+AC_LANG_RESTORE
+CC="$lt_save_CC"
+])# _LT_LANG_RC_CONFIG
+
+
+# LT_PROG_GCJ
+# -----------
+AC_DEFUN([LT_PROG_GCJ],
+[m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ],
+  [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ],
+    [AC_CHECK_TOOL(GCJ, gcj,)
+      test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2"
+      AC_SUBST(GCJFLAGS)])])[]dnl
+])
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_GCJ], [])
+
+
+# LT_PROG_RC
+# ----------
+AC_DEFUN([LT_PROG_RC],
+[AC_CHECK_TOOL(RC, windres,)
+])
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_RC], [])
+
+
+# _LT_DECL_EGREP
+# --------------
+# If we don't have a new enough Autoconf to choose the best grep
+# available, choose the one first in the user's PATH.
+m4_defun([_LT_DECL_EGREP],
+[AC_REQUIRE([AC_PROG_EGREP])dnl
+AC_REQUIRE([AC_PROG_FGREP])dnl
+test -z "$GREP" && GREP=grep
+_LT_DECL([], [GREP], [1], [A grep program that handles long lines])
+_LT_DECL([], [EGREP], [1], [An ERE matcher])
+_LT_DECL([], [FGREP], [1], [A literal string matcher])
+dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too
+AC_SUBST([GREP])
+])
+
+
+# _LT_DECL_OBJDUMP
+# --------------
+# If we don't have a new enough Autoconf to choose the best objdump
+# available, choose the one first in the user's PATH.
+m4_defun([_LT_DECL_OBJDUMP],
+[AC_CHECK_TOOL(OBJDUMP, objdump, false)
+test -z "$OBJDUMP" && OBJDUMP=objdump
+_LT_DECL([], [OBJDUMP], [1], [An object symbol dumper])
+AC_SUBST([OBJDUMP])
+])
+
+
+# _LT_DECL_SED
+# ------------
+# Check for a fully-functional sed program, that truncates
+# as few characters as possible.  Prefer GNU sed if found.
+m4_defun([_LT_DECL_SED],
+[AC_PROG_SED
+test -z "$SED" && SED=sed
+Xsed="$SED -e 1s/^X//"
+_LT_DECL([], [SED], [1], [A sed program that does not truncate output])
+_LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"],
+    [Sed that helps us avoid accidentally triggering echo(1) options like -n])
+])# _LT_DECL_SED
+
+m4_ifndef([AC_PROG_SED], [
+############################################################
+# NOTE: This macro has been submitted for inclusion into   #
+#  GNU Autoconf as AC_PROG_SED.  When it is available in   #
+#  a released version of Autoconf we should remove this    #
+#  macro and use it instead.                               #
+############################################################
+
+m4_defun([AC_PROG_SED],
+[AC_MSG_CHECKING([for a sed that does not truncate output])
+AC_CACHE_VAL(lt_cv_path_SED,
+[# Loop through the user's path and test for sed and gsed.
+# Then use that list of sed's as ones to test for truncation.
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for lt_ac_prog in sed gsed; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then
+        lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext"
+      fi
+    done
+  done
+done
+IFS=$as_save_IFS
+lt_ac_max=0
+lt_ac_count=0
+# Add /usr/xpg4/bin/sed as it is typically found on Solaris
+# along with /bin/sed that truncates output.
+for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do
+  test ! -f $lt_ac_sed && continue
+  cat /dev/null > conftest.in
+  lt_ac_count=0
+  echo $ECHO_N "0123456789$ECHO_C" >conftest.in
+  # Check for GNU sed and select it if it is found.
+  if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then
+    lt_cv_path_SED=$lt_ac_sed
+    break
+  fi
+  while true; do
+    cat conftest.in conftest.in >conftest.tmp
+    mv conftest.tmp conftest.in
+    cp conftest.in conftest.nl
+    echo >>conftest.nl
+    $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break
+    cmp -s conftest.out conftest.nl || break
+    # 10000 chars as input seems more than enough
+    test $lt_ac_count -gt 10 && break
+    lt_ac_count=`expr $lt_ac_count + 1`
+    if test $lt_ac_count -gt $lt_ac_max; then
+      lt_ac_max=$lt_ac_count
+      lt_cv_path_SED=$lt_ac_sed
+    fi
+  done
+done
+])
+SED=$lt_cv_path_SED
+AC_SUBST([SED])
+AC_MSG_RESULT([$SED])
+])#AC_PROG_SED
+])#m4_ifndef
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_SED], [])
+
+
+# _LT_CHECK_SHELL_FEATURES
+# ------------------------
+# Find out whether the shell is Bourne or XSI compatible,
+# or has some other useful features.
+m4_defun([_LT_CHECK_SHELL_FEATURES],
+[AC_MSG_CHECKING([whether the shell understands some XSI constructs])
+# Try some XSI features
+xsi_shell=no
+( _lt_dummy="a/b/c"
+  test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \
+      = c,a/b,, \
+    && eval 'test $(( 1 + 1 )) -eq 2 \
+    && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \
+  && xsi_shell=yes
+AC_MSG_RESULT([$xsi_shell])
+_LT_CONFIG_LIBTOOL_INIT([xsi_shell='$xsi_shell'])
+
+AC_MSG_CHECKING([whether the shell understands "+="])
+lt_shell_append=no
+( foo=bar; set foo baz; eval "$[1]+=\$[2]" && test "$foo" = barbaz ) \
+    >/dev/null 2>&1 \
+  && lt_shell_append=yes
+AC_MSG_RESULT([$lt_shell_append])
+_LT_CONFIG_LIBTOOL_INIT([lt_shell_append='$lt_shell_append'])
+
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  lt_unset=unset
+else
+  lt_unset=false
+fi
+_LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl
+
+# test EBCDIC or ASCII
+case `echo X|tr X '\101'` in
+ A) # ASCII based system
+    # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr
+  lt_SP2NL='tr \040 \012'
+  lt_NL2SP='tr \015\012 \040\040'
+  ;;
+ *) # EBCDIC based system
+  lt_SP2NL='tr \100 \n'
+  lt_NL2SP='tr \r\n \100\100'
+  ;;
+esac
+_LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl
+_LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl
+])# _LT_CHECK_SHELL_FEATURES
+
+
+# _LT_PROG_XSI_SHELLFNS
+# ---------------------
+# Bourne and XSI compatible variants of some useful shell functions.
+m4_defun([_LT_PROG_XSI_SHELLFNS],
+[case $xsi_shell in
+  yes)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_dirname file append nondir_replacement
+# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
+# otherwise set result to NONDIR_REPLACEMENT.
+func_dirname ()
+{
+  case ${1} in
+    */*) func_dirname_result="${1%/*}${2}" ;;
+    *  ) func_dirname_result="${3}" ;;
+  esac
+}
+
+# func_basename file
+func_basename ()
+{
+  func_basename_result="${1##*/}"
+}
+
+# func_dirname_and_basename file append nondir_replacement
+# perform func_basename and func_dirname in a single function
+# call:
+#   dirname:  Compute the dirname of FILE.  If nonempty,
+#             add APPEND to the result, otherwise set result
+#             to NONDIR_REPLACEMENT.
+#             value returned in "$func_dirname_result"
+#   basename: Compute filename of FILE.
+#             value retuned in "$func_basename_result"
+# Implementation must be kept synchronized with func_dirname
+# and func_basename. For efficiency, we do not delegate to
+# those functions but instead duplicate the functionality here.
+func_dirname_and_basename ()
+{
+  case ${1} in
+    */*) func_dirname_result="${1%/*}${2}" ;;
+    *  ) func_dirname_result="${3}" ;;
+  esac
+  func_basename_result="${1##*/}"
+}
+
+# func_stripname prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+func_stripname ()
+{
+  # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
+  # positional parameters, so assign one to ordinary parameter first.
+  func_stripname_result=${3}
+  func_stripname_result=${func_stripname_result#"${1}"}
+  func_stripname_result=${func_stripname_result%"${2}"}
+}
+
+# func_opt_split
+func_opt_split ()
+{
+  func_opt_split_opt=${1%%=*}
+  func_opt_split_arg=${1#*=}
+}
+
+# func_lo2o object
+func_lo2o ()
+{
+  case ${1} in
+    *.lo) func_lo2o_result=${1%.lo}.${objext} ;;
+    *)    func_lo2o_result=${1} ;;
+  esac
+}
+
+# func_xform libobj-or-source
+func_xform ()
+{
+  func_xform_result=${1%.*}.lo
+}
+
+# func_arith arithmetic-term...
+func_arith ()
+{
+  func_arith_result=$(( $[*] ))
+}
+
+# func_len string
+# STRING may not start with a hyphen.
+func_len ()
+{
+  func_len_result=${#1}
+}
+
+_LT_EOF
+    ;;
+  *) # Bourne compatible functions.
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_dirname file append nondir_replacement
+# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
+# otherwise set result to NONDIR_REPLACEMENT.
+func_dirname ()
+{
+  # Extract subdirectory from the argument.
+  func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"`
+  if test "X$func_dirname_result" = "X${1}"; then
+    func_dirname_result="${3}"
+  else
+    func_dirname_result="$func_dirname_result${2}"
+  fi
+}
+
+# func_basename file
+func_basename ()
+{
+  func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
+}
+
+dnl func_dirname_and_basename
+dnl A portable version of this function is already defined in general.m4sh
+dnl so there is no need for it here.
+
+# func_stripname prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+# func_strip_suffix prefix name
+func_stripname ()
+{
+  case ${2} in
+    .*) func_stripname_result=`$ECHO "X${3}" \
+           | $Xsed -e "s%^${1}%%" -e "s%\\\\${2}\$%%"`;;
+    *)  func_stripname_result=`$ECHO "X${3}" \
+           | $Xsed -e "s%^${1}%%" -e "s%${2}\$%%"`;;
+  esac
+}
+
+# sed scripts:
+my_sed_long_opt='1s/^\(-[[^=]]*\)=.*/\1/;q'
+my_sed_long_arg='1s/^-[[^=]]*=//'
+
+# func_opt_split
+func_opt_split ()
+{
+  func_opt_split_opt=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_opt"`
+  func_opt_split_arg=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_arg"`
+}
+
+# func_lo2o object
+func_lo2o ()
+{
+  func_lo2o_result=`$ECHO "X${1}" | $Xsed -e "$lo2o"`
+}
+
+# func_xform libobj-or-source
+func_xform ()
+{
+  func_xform_result=`$ECHO "X${1}" | $Xsed -e 's/\.[[^.]]*$/.lo/'`
+}
+
+# func_arith arithmetic-term...
+func_arith ()
+{
+  func_arith_result=`expr "$[@]"`
+}
+
+# func_len string
+# STRING may not start with a hyphen.
+func_len ()
+{
+  func_len_result=`expr "$[1]" : ".*" 2>/dev/null || echo $max_cmd_len`
+}
+
+_LT_EOF
+esac
+
+case $lt_shell_append in
+  yes)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_append var value
+# Append VALUE to the end of shell variable VAR.
+func_append ()
+{
+  eval "$[1]+=\$[2]"
+}
+_LT_EOF
+    ;;
+  *)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_append var value
+# Append VALUE to the end of shell variable VAR.
+func_append ()
+{
+  eval "$[1]=\$$[1]\$[2]"
+}
+
+_LT_EOF
+    ;;
+  esac
+])
diff --git a/m4/longdouble.m4 b/m4/longdouble.m4
new file mode 100644 (file)
index 0000000..40cd7ce
--- /dev/null
@@ -0,0 +1,28 @@
+# longdouble.m4 serial 1 (gettext-0.12)
+dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+dnl Test whether the compiler supports the 'long double' type.
+dnl Prerequisite: AC_PROG_CC
+
+AC_DEFUN([gt_TYPE_LONGDOUBLE],
+[
+  AC_CACHE_CHECK([for long double], gt_cv_c_long_double,
+    [if test "$GCC" = yes; then
+       gt_cv_c_long_double=yes
+     else
+       AC_TRY_COMPILE([
+         /* The Stardent Vistra knows sizeof(long double), but does not support it.  */
+         long double foo = 0.0;
+         /* On Ultrix 4.3 cc, long double is 4 and double is 8.  */
+         int array [2*(sizeof(long double) >= sizeof(double)) - 1];
+         ], ,
+         gt_cv_c_long_double=yes, gt_cv_c_long_double=no)
+     fi])
+  if test $gt_cv_c_long_double = yes; then
+    AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the 'long double' type.])
+  fi
+])
diff --git a/m4/longlong.m4 b/m4/longlong.m4
new file mode 100644 (file)
index 0000000..7b399e0
--- /dev/null
@@ -0,0 +1,23 @@
+# longlong.m4 serial 5
+dnl Copyright (C) 1999-2004 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Paul Eggert.
+
+# Define HAVE_LONG_LONG if 'long long' works.
+
+AC_DEFUN([gl_AC_TYPE_LONG_LONG],
+[
+  AC_CACHE_CHECK([for long long], ac_cv_type_long_long,
+  [AC_TRY_LINK([long long ll = 1LL; int i = 63;],
+    [long long llmax = (long long) -1;
+     return ll << i | ll >> i | llmax / ll | llmax % ll;],
+    ac_cv_type_long_long=yes,
+    ac_cv_type_long_long=no)])
+  if test $ac_cv_type_long_long = yes; then
+    AC_DEFINE(HAVE_LONG_LONG, 1,
+      [Define if you have the 'long long' type.])
+  fi
+])
diff --git a/m4/ltoptions.m4 b/m4/ltoptions.m4
new file mode 100644 (file)
index 0000000..34151a3
--- /dev/null
@@ -0,0 +1,368 @@
+# Helper functions for option handling.                    -*- Autoconf -*-
+#
+#   Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
+#   Written by Gary V. Vaughan, 2004
+#
+# This file 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.
+
+# serial 6 ltoptions.m4
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])])
+
+
+# _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME)
+# ------------------------------------------
+m4_define([_LT_MANGLE_OPTION],
+[[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])])
+
+
+# _LT_SET_OPTION(MACRO-NAME, OPTION-NAME)
+# ---------------------------------------
+# Set option OPTION-NAME for macro MACRO-NAME, and if there is a
+# matching handler defined, dispatch to it.  Other OPTION-NAMEs are
+# saved as a flag.
+m4_define([_LT_SET_OPTION],
+[m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl
+m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]),
+        _LT_MANGLE_DEFUN([$1], [$2]),
+    [m4_warning([Unknown $1 option `$2'])])[]dnl
+])
+
+
+# _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET])
+# ------------------------------------------------------------
+# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
+m4_define([_LT_IF_OPTION],
+[m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])])
+
+
+# _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET)
+# -------------------------------------------------------
+# Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME
+# are set.
+m4_define([_LT_UNLESS_OPTIONS],
+[m4_foreach([_LT_Option], m4_split(m4_normalize([$2])),
+           [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option),
+                     [m4_define([$0_found])])])[]dnl
+m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3
+])[]dnl
+])
+
+
+# _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST)
+# ----------------------------------------
+# OPTION-LIST is a space-separated list of Libtool options associated
+# with MACRO-NAME.  If any OPTION has a matching handler declared with
+# LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about
+# the unknown option and exit.
+m4_defun([_LT_SET_OPTIONS],
+[# Set options
+m4_foreach([_LT_Option], m4_split(m4_normalize([$2])),
+    [_LT_SET_OPTION([$1], _LT_Option)])
+
+m4_if([$1],[LT_INIT],[
+  dnl
+  dnl Simply set some default values (i.e off) if boolean options were not
+  dnl specified:
+  _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no
+  ])
+  _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no
+  ])
+  dnl
+  dnl If no reference was made to various pairs of opposing options, then
+  dnl we run the default mode handler for the pair.  For example, if neither
+  dnl `shared' nor `disable-shared' was passed, we enable building of shared
+  dnl archives by default:
+  _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED])
+  _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC])
+  _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC])
+  _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install],
+                  [_LT_ENABLE_FAST_INSTALL])
+  ])
+])# _LT_SET_OPTIONS
+
+
+## --------------------------------- ##
+## Macros to handle LT_INIT options. ##
+## --------------------------------- ##
+
+# _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME)
+# -----------------------------------------
+m4_define([_LT_MANGLE_DEFUN],
+[[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])])
+
+
+# LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE)
+# -----------------------------------------------
+m4_define([LT_OPTION_DEFINE],
+[m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl
+])# LT_OPTION_DEFINE
+
+
+# dlopen
+# ------
+LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes
+])
+
+AU_DEFUN([AC_LIBTOOL_DLOPEN],
+[_LT_SET_OPTION([LT_INIT], [dlopen])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `dlopen' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], [])
+
+
+# win32-dll
+# ---------
+# Declare package support for building win32 dll's.
+LT_OPTION_DEFINE([LT_INIT], [win32-dll],
+[enable_win32_dll=yes
+
+case $host in
+*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-cegcc*)
+  AC_CHECK_TOOL(AS, as, false)
+  AC_CHECK_TOOL(DLLTOOL, dlltool, false)
+  AC_CHECK_TOOL(OBJDUMP, objdump, false)
+  ;;
+esac
+
+test -z "$AS" && AS=as
+_LT_DECL([], [AS],      [0], [Assembler program])dnl
+
+test -z "$DLLTOOL" && DLLTOOL=dlltool
+_LT_DECL([], [DLLTOOL], [0], [DLL creation program])dnl
+
+test -z "$OBJDUMP" && OBJDUMP=objdump
+_LT_DECL([], [OBJDUMP], [0], [Object dumper program])dnl
+])# win32-dll
+
+AU_DEFUN([AC_LIBTOOL_WIN32_DLL],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+_LT_SET_OPTION([LT_INIT], [win32-dll])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `win32-dll' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], [])
+
+
+# _LT_ENABLE_SHARED([DEFAULT])
+# ----------------------------
+# implement the --enable-shared flag, and supports the `shared' and
+# `disable-shared' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_SHARED],
+[m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([shared],
+    [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@],
+       [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_shared=yes ;;
+    no) enable_shared=no ;;
+    *)
+      enable_shared=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+       IFS="$lt_save_ifs"
+       if test "X$pkg" = "X$p"; then
+         enable_shared=yes
+       fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_shared=]_LT_ENABLE_SHARED_DEFAULT)
+
+    _LT_DECL([build_libtool_libs], [enable_shared], [0],
+       [Whether or not to build shared libraries])
+])# _LT_ENABLE_SHARED
+
+LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])])
+
+# Old names:
+AC_DEFUN([AC_ENABLE_SHARED],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared])
+])
+
+AC_DEFUN([AC_DISABLE_SHARED],
+[_LT_SET_OPTION([LT_INIT], [disable-shared])
+])
+
+AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)])
+AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_ENABLE_SHARED], [])
+dnl AC_DEFUN([AM_DISABLE_SHARED], [])
+
+
+
+# _LT_ENABLE_STATIC([DEFAULT])
+# ----------------------------
+# implement the --enable-static flag, and support the `static' and
+# `disable-static' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_STATIC],
+[m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([static],
+    [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@],
+       [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_static=yes ;;
+    no) enable_static=no ;;
+    *)
+     enable_static=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+       IFS="$lt_save_ifs"
+       if test "X$pkg" = "X$p"; then
+         enable_static=yes
+       fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_static=]_LT_ENABLE_STATIC_DEFAULT)
+
+    _LT_DECL([build_old_libs], [enable_static], [0],
+       [Whether or not to build static libraries])
+])# _LT_ENABLE_STATIC
+
+LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])])
+
+# Old names:
+AC_DEFUN([AC_ENABLE_STATIC],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static])
+])
+
+AC_DEFUN([AC_DISABLE_STATIC],
+[_LT_SET_OPTION([LT_INIT], [disable-static])
+])
+
+AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)])
+AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_ENABLE_STATIC], [])
+dnl AC_DEFUN([AM_DISABLE_STATIC], [])
+
+
+
+# _LT_ENABLE_FAST_INSTALL([DEFAULT])
+# ----------------------------------
+# implement the --enable-fast-install flag, and support the `fast-install'
+# and `disable-fast-install' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_FAST_INSTALL],
+[m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([fast-install],
+    [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@],
+    [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_fast_install=yes ;;
+    no) enable_fast_install=no ;;
+    *)
+      enable_fast_install=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+       IFS="$lt_save_ifs"
+       if test "X$pkg" = "X$p"; then
+         enable_fast_install=yes
+       fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT)
+
+_LT_DECL([fast_install], [enable_fast_install], [0],
+        [Whether or not to optimize for fast installation])dnl
+])# _LT_ENABLE_FAST_INSTALL
+
+LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])])
+
+# Old names:
+AU_DEFUN([AC_ENABLE_FAST_INSTALL],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you put
+the `fast-install' option into LT_INIT's first parameter.])
+])
+
+AU_DEFUN([AC_DISABLE_FAST_INSTALL],
+[_LT_SET_OPTION([LT_INIT], [disable-fast-install])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you put
+the `disable-fast-install' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], [])
+dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], [])
+
+
+# _LT_WITH_PIC([MODE])
+# --------------------
+# implement the --with-pic flag, and support the `pic-only' and `no-pic'
+# LT_INIT options.
+# MODE is either `yes' or `no'.  If omitted, it defaults to `both'.
+m4_define([_LT_WITH_PIC],
+[AC_ARG_WITH([pic],
+    [AS_HELP_STRING([--with-pic],
+       [try to use only PIC/non-PIC objects @<:@default=use both@:>@])],
+    [pic_mode="$withval"],
+    [pic_mode=default])
+
+test -z "$pic_mode" && pic_mode=m4_default([$1], [default])
+
+_LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl
+])# _LT_WITH_PIC
+
+LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])])
+LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])])
+
+# Old name:
+AU_DEFUN([AC_LIBTOOL_PICMODE],
+[_LT_SET_OPTION([LT_INIT], [pic-only])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `pic-only' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_PICMODE], [])
+
+## ----------------- ##
+## LTDL_INIT Options ##
+## ----------------- ##
+
+m4_define([_LTDL_MODE], [])
+LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive],
+                [m4_define([_LTDL_MODE], [nonrecursive])])
+LT_OPTION_DEFINE([LTDL_INIT], [recursive],
+                [m4_define([_LTDL_MODE], [recursive])])
+LT_OPTION_DEFINE([LTDL_INIT], [subproject],
+                [m4_define([_LTDL_MODE], [subproject])])
+
+m4_define([_LTDL_TYPE], [])
+LT_OPTION_DEFINE([LTDL_INIT], [installable],
+                [m4_define([_LTDL_TYPE], [installable])])
+LT_OPTION_DEFINE([LTDL_INIT], [convenience],
+                [m4_define([_LTDL_TYPE], [convenience])])
diff --git a/m4/ltsugar.m4 b/m4/ltsugar.m4
new file mode 100644 (file)
index 0000000..9000a05
--- /dev/null
@@ -0,0 +1,123 @@
+# ltsugar.m4 -- libtool m4 base layer.                         -*-Autoconf-*-
+#
+# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
+# Written by Gary V. Vaughan, 2004
+#
+# This file 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.
+
+# serial 6 ltsugar.m4
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
+
+
+# lt_join(SEP, ARG1, [ARG2...])
+# -----------------------------
+# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their
+# associated separator.
+# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier
+# versions in m4sugar had bugs.
+m4_define([lt_join],
+[m4_if([$#], [1], [],
+       [$#], [2], [[$2]],
+       [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])])
+m4_define([_lt_join],
+[m4_if([$#$2], [2], [],
+       [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])])
+
+
+# lt_car(LIST)
+# lt_cdr(LIST)
+# ------------
+# Manipulate m4 lists.
+# These macros are necessary as long as will still need to support
+# Autoconf-2.59 which quotes differently.
+m4_define([lt_car], [[$1]])
+m4_define([lt_cdr],
+[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
+       [$#], 1, [],
+       [m4_dquote(m4_shift($@))])])
+m4_define([lt_unquote], $1)
+
+
+# lt_append(MACRO-NAME, STRING, [SEPARATOR])
+# ------------------------------------------
+# Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'.
+# Note that neither SEPARATOR nor STRING are expanded; they are appended
+# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked).
+# No SEPARATOR is output if MACRO-NAME was previously undefined (different
+# than defined and empty).
+#
+# This macro is needed until we can rely on Autoconf 2.62, since earlier
+# versions of m4sugar mistakenly expanded SEPARATOR but not STRING.
+m4_define([lt_append],
+[m4_define([$1],
+          m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
+
+
+
+# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...])
+# ----------------------------------------------------------
+# Produce a SEP delimited list of all paired combinations of elements of
+# PREFIX-LIST with SUFFIX1 through SUFFIXn.  Each element of the list
+# has the form PREFIXmINFIXSUFFIXn.
+# Needed until we can rely on m4_combine added in Autoconf 2.62.
+m4_define([lt_combine],
+[m4_if(m4_eval([$# > 3]), [1],
+       [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl
+[[m4_foreach([_Lt_prefix], [$2],
+            [m4_foreach([_Lt_suffix],
+               ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
+       [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])])
+
+
+# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])
+# -----------------------------------------------------------------------
+# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited
+# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ.
+m4_define([lt_if_append_uniq],
+[m4_ifdef([$1],
+         [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1],
+                [lt_append([$1], [$2], [$3])$4],
+                [$5])],
+         [lt_append([$1], [$2], [$3])$4])])
+
+
+# lt_dict_add(DICT, KEY, VALUE)
+# -----------------------------
+m4_define([lt_dict_add],
+[m4_define([$1($2)], [$3])])
+
+
+# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE)
+# --------------------------------------------
+m4_define([lt_dict_add_subkey],
+[m4_define([$1($2:$3)], [$4])])
+
+
+# lt_dict_fetch(DICT, KEY, [SUBKEY])
+# ----------------------------------
+m4_define([lt_dict_fetch],
+[m4_ifval([$3],
+       m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]),
+    m4_ifdef([$1($2)], [m4_defn([$1($2)])]))])
+
+
+# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE])
+# -----------------------------------------------------------------
+m4_define([lt_if_dict_fetch],
+[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4],
+       [$5],
+    [$6])])
+
+
+# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...])
+# --------------------------------------------------------------
+m4_define([lt_dict_filter],
+[m4_if([$5], [], [],
+  [lt_join(m4_quote(m4_default([$4], [[, ]])),
+           lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]),
+                     [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl
+])
diff --git a/m4/ltversion.m4 b/m4/ltversion.m4
new file mode 100644 (file)
index 0000000..b8e154f
--- /dev/null
@@ -0,0 +1,23 @@
+# ltversion.m4 -- version numbers                      -*- Autoconf -*-
+#
+#   Copyright (C) 2004 Free Software Foundation, Inc.
+#   Written by Scott James Remnant, 2004
+#
+# This file 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.
+
+# Generated from ltversion.in.
+
+# serial 3012 ltversion.m4
+# This file is part of GNU Libtool
+
+m4_define([LT_PACKAGE_VERSION], [2.2.6])
+m4_define([LT_PACKAGE_REVISION], [1.3012])
+
+AC_DEFUN([LTVERSION_VERSION],
+[macro_version='2.2.6'
+macro_revision='1.3012'
+_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
+_LT_DECL(, macro_revision, 0)
+])
diff --git a/m4/lt~obsolete.m4 b/m4/lt~obsolete.m4
new file mode 100644 (file)
index 0000000..637bb20
--- /dev/null
@@ -0,0 +1,92 @@
+# lt~obsolete.m4 -- aclocal satisfying obsolete definitions.    -*-Autoconf-*-
+#
+#   Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
+#   Written by Scott James Remnant, 2004.
+#
+# This file 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.
+
+# serial 4 lt~obsolete.m4
+
+# These exist entirely to fool aclocal when bootstrapping libtool.
+#
+# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN)
+# which have later been changed to m4_define as they aren't part of the
+# exported API, or moved to Autoconf or Automake where they belong.
+#
+# The trouble is, aclocal is a bit thick.  It'll see the old AC_DEFUN
+# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us
+# using a macro with the same name in our local m4/libtool.m4 it'll
+# pull the old libtool.m4 in (it doesn't see our shiny new m4_define
+# and doesn't know about Autoconf macros at all.)
+#
+# So we provide this file, which has a silly filename so it's always
+# included after everything else.  This provides aclocal with the
+# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything
+# because those macros already exist, or will be overwritten later.
+# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. 
+#
+# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here.
+# Yes, that means every name once taken will need to remain here until
+# we give up compatibility with versions before 1.7, at which point
+# we need to keep only those names which we still refer to.
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])])
+
+m4_ifndef([AC_LIBTOOL_LINKER_OPTION],  [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])])
+m4_ifndef([AC_PROG_EGREP],             [AC_DEFUN([AC_PROG_EGREP])])
+m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH],        [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])])
+m4_ifndef([_LT_AC_SHELL_INIT],         [AC_DEFUN([_LT_AC_SHELL_INIT])])
+m4_ifndef([_LT_AC_SYS_LIBPATH_AIX],    [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])])
+m4_ifndef([_LT_PROG_LTMAIN],           [AC_DEFUN([_LT_PROG_LTMAIN])])
+m4_ifndef([_LT_AC_TAGVAR],             [AC_DEFUN([_LT_AC_TAGVAR])])
+m4_ifndef([AC_LTDL_ENABLE_INSTALL],    [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])])
+m4_ifndef([AC_LTDL_PREOPEN],           [AC_DEFUN([AC_LTDL_PREOPEN])])
+m4_ifndef([_LT_AC_SYS_COMPILER],       [AC_DEFUN([_LT_AC_SYS_COMPILER])])
+m4_ifndef([_LT_AC_LOCK],               [AC_DEFUN([_LT_AC_LOCK])])
+m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE],        [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])])
+m4_ifndef([_LT_AC_TRY_DLOPEN_SELF],    [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])])
+m4_ifndef([AC_LIBTOOL_PROG_CC_C_O],    [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])])
+m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])])
+m4_ifndef([AC_LIBTOOL_OBJDIR],         [AC_DEFUN([AC_LIBTOOL_OBJDIR])])
+m4_ifndef([AC_LTDL_OBJDIR],            [AC_DEFUN([AC_LTDL_OBJDIR])])
+m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])])
+m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP],  [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])])
+m4_ifndef([AC_PATH_MAGIC],             [AC_DEFUN([AC_PATH_MAGIC])])
+m4_ifndef([AC_PROG_LD_GNU],            [AC_DEFUN([AC_PROG_LD_GNU])])
+m4_ifndef([AC_PROG_LD_RELOAD_FLAG],    [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])])
+m4_ifndef([AC_DEPLIBS_CHECK_METHOD],   [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])])
+m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])])
+m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])])
+m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])])
+m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])])
+m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])])
+m4_ifndef([LT_AC_PROG_EGREP],          [AC_DEFUN([LT_AC_PROG_EGREP])])
+m4_ifndef([LT_AC_PROG_SED],            [AC_DEFUN([LT_AC_PROG_SED])])
+m4_ifndef([_LT_CC_BASENAME],           [AC_DEFUN([_LT_CC_BASENAME])])
+m4_ifndef([_LT_COMPILER_BOILERPLATE],  [AC_DEFUN([_LT_COMPILER_BOILERPLATE])])
+m4_ifndef([_LT_LINKER_BOILERPLATE],    [AC_DEFUN([_LT_LINKER_BOILERPLATE])])
+m4_ifndef([_AC_PROG_LIBTOOL],          [AC_DEFUN([_AC_PROG_LIBTOOL])])
+m4_ifndef([AC_LIBTOOL_SETUP],          [AC_DEFUN([AC_LIBTOOL_SETUP])])
+m4_ifndef([_LT_AC_CHECK_DLFCN],                [AC_DEFUN([_LT_AC_CHECK_DLFCN])])
+m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER],     [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])])
+m4_ifndef([_LT_AC_TAGCONFIG],          [AC_DEFUN([_LT_AC_TAGCONFIG])])
+m4_ifndef([AC_DISABLE_FAST_INSTALL],   [AC_DEFUN([AC_DISABLE_FAST_INSTALL])])
+m4_ifndef([_LT_AC_LANG_CXX],           [AC_DEFUN([_LT_AC_LANG_CXX])])
+m4_ifndef([_LT_AC_LANG_F77],           [AC_DEFUN([_LT_AC_LANG_F77])])
+m4_ifndef([_LT_AC_LANG_GCJ],           [AC_DEFUN([_LT_AC_LANG_GCJ])])
+m4_ifndef([AC_LIBTOOL_RC],             [AC_DEFUN([AC_LIBTOOL_RC])])
+m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG],  [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])])
+m4_ifndef([_LT_AC_LANG_C_CONFIG],      [AC_DEFUN([_LT_AC_LANG_C_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG],        [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])])
+m4_ifndef([_LT_AC_LANG_CXX_CONFIG],    [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG],        [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])])
+m4_ifndef([_LT_AC_LANG_F77_CONFIG],    [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG],        [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])])
+m4_ifndef([_LT_AC_LANG_GCJ_CONFIG],    [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])])
+m4_ifndef([_LT_AC_LANG_RC_CONFIG],     [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])])
+m4_ifndef([AC_LIBTOOL_CONFIG],         [AC_DEFUN([AC_LIBTOOL_CONFIG])])
+m4_ifndef([_LT_AC_FILE_LTDLL_C],       [AC_DEFUN([_LT_AC_FILE_LTDLL_C])])
diff --git a/m4/nls.m4 b/m4/nls.m4
new file mode 100644 (file)
index 0000000..2082c3b
--- /dev/null
+++ b/m4/nls.m4
@@ -0,0 +1,51 @@
+# nls.m4 serial 2 (gettext-0.14.3)
+dnl Copyright (C) 1995-2003, 2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+dnl
+dnl This file can can be used in projects which are not available under
+dnl the GNU General Public License or the GNU Library General Public
+dnl License but which still want to provide support for the GNU gettext
+dnl functionality.
+dnl Please note that the actual code of the GNU gettext library is covered
+dnl by the GNU Library General Public License, and the rest of the GNU
+dnl gettext package package is covered by the GNU General Public License.
+dnl They are *not* in the public domain.
+
+dnl Authors:
+dnl   Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
+dnl   Bruno Haible <haible@clisp.cons.org>, 2000-2003.
+
+AC_PREREQ(2.50)
+
+AC_DEFUN([AM_NLS],
+[
+  AC_MSG_CHECKING([whether NLS is requested])
+  dnl Default is enabled NLS
+  AC_ARG_ENABLE(nls,
+    [  --disable-nls           do not use Native Language Support],
+    USE_NLS=$enableval, USE_NLS=yes)
+  AC_MSG_RESULT($USE_NLS)
+  AC_SUBST(USE_NLS)
+])
+
+AC_DEFUN([AM_MKINSTALLDIRS],
+[
+  dnl Tell automake >= 1.10 to complain if mkinstalldirs is missing.
+  m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([mkinstalldirs])])
+  dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
+  dnl find the mkinstalldirs script in another subdir but $(top_srcdir).
+  dnl Try to locate it.
+  MKINSTALLDIRS=
+  if test -n "$ac_aux_dir"; then
+    case "$ac_aux_dir" in
+      /*) MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs" ;;
+      *) MKINSTALLDIRS="\$(top_builddir)/$ac_aux_dir/mkinstalldirs" ;;
+    esac
+  fi
+  if test -z "$MKINSTALLDIRS"; then
+    MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
+  fi
+  AC_SUBST(MKINSTALLDIRS)
+])
diff --git a/m4/po.m4 b/m4/po.m4
new file mode 100644 (file)
index 0000000..f2795ee
--- /dev/null
+++ b/m4/po.m4
@@ -0,0 +1,429 @@
+# po.m4 serial 7 (gettext-0.14.3)
+dnl Copyright (C) 1995-2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+dnl
+dnl This file can can be used in projects which are not available under
+dnl the GNU General Public License or the GNU Library General Public
+dnl License but which still want to provide support for the GNU gettext
+dnl functionality.
+dnl Please note that the actual code of the GNU gettext library is covered
+dnl by the GNU Library General Public License, and the rest of the GNU
+dnl gettext package package is covered by the GNU General Public License.
+dnl They are *not* in the public domain.
+
+dnl Authors:
+dnl   Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
+dnl   Bruno Haible <haible@clisp.cons.org>, 2000-2003.
+
+AC_PREREQ(2.50)
+
+dnl Checks for all prerequisites of the po subdirectory.
+AC_DEFUN([AM_PO_SUBDIRS],
+[
+  AC_REQUIRE([AC_PROG_MAKE_SET])dnl
+  AC_REQUIRE([AC_PROG_INSTALL])dnl
+  AC_REQUIRE([AM_MKINSTALLDIRS])dnl
+  AC_REQUIRE([AM_NLS])dnl
+
+  dnl Perform the following tests also if --disable-nls has been given,
+  dnl because they are needed for "make dist" to work.
+
+  dnl Search for GNU msgfmt in the PATH.
+  dnl The first test excludes Solaris msgfmt and early GNU msgfmt versions.
+  dnl The second test excludes FreeBSD msgfmt.
+  AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
+    [$ac_dir/$ac_word --statistics /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1 &&
+     (if $ac_dir/$ac_word --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)],
+    :)
+  AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
+
+  dnl Search for GNU xgettext 0.12 or newer in the PATH.
+  dnl The first test excludes Solaris xgettext and early GNU xgettext versions.
+  dnl The second test excludes FreeBSD xgettext.
+  AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
+    [$ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1 &&
+     (if $ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)],
+    :)
+  dnl Remove leftover from FreeBSD xgettext call.
+  rm -f messages.po
+
+  dnl Search for GNU msgmerge 0.11 or newer in the PATH.
+  AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge,
+    [$ac_dir/$ac_word --update -q /dev/null /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1], :)
+
+  dnl This could go away some day; the PATH_PROG_WITH_TEST already does it.
+  dnl Test whether we really found GNU msgfmt.
+  if test "$GMSGFMT" != ":"; then
+    dnl If it is no GNU msgfmt we define it as : so that the
+    dnl Makefiles still can work.
+    if $GMSGFMT --statistics /dev/null >/dev/null 2>&1 &&
+       (if $GMSGFMT --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then
+      : ;
+    else
+      GMSGFMT=`echo "$GMSGFMT" | sed -e 's,^.*/,,'`
+      AC_MSG_RESULT(
+        [found $GMSGFMT program is not GNU msgfmt; ignore it])
+      GMSGFMT=":"
+    fi
+  fi
+
+  dnl This could go away some day; the PATH_PROG_WITH_TEST already does it.
+  dnl Test whether we really found GNU xgettext.
+  if test "$XGETTEXT" != ":"; then
+    dnl If it is no GNU xgettext we define it as : so that the
+    dnl Makefiles still can work.
+    if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >/dev/null 2>&1 &&
+       (if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then
+      : ;
+    else
+      AC_MSG_RESULT(
+        [found xgettext program is not GNU xgettext; ignore it])
+      XGETTEXT=":"
+    fi
+    dnl Remove leftover from FreeBSD xgettext call.
+    rm -f messages.po
+  fi
+
+  AC_OUTPUT_COMMANDS([
+    for ac_file in $CONFIG_FILES; do
+      # Support "outfile[:infile[:infile...]]"
+      case "$ac_file" in
+        *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
+      esac
+      # PO directories have a Makefile.in generated from Makefile.in.in.
+      case "$ac_file" in */Makefile.in)
+        # Adjust a relative srcdir.
+        ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
+        ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
+        ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
+        # In autoconf-2.13 it is called $ac_given_srcdir.
+        # In autoconf-2.50 it is called $srcdir.
+        test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
+        case "$ac_given_srcdir" in
+          .)  top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
+          /*) top_srcdir="$ac_given_srcdir" ;;
+          *)  top_srcdir="$ac_dots$ac_given_srcdir" ;;
+        esac
+        # Treat a directory as a PO directory if and only if it has a
+        # POTFILES.in file. This allows packages to have multiple PO
+        # directories under different names or in different locations.
+        if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then
+          rm -f "$ac_dir/POTFILES"
+          test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES"
+          cat "$ac_given_srcdir/$ac_dir/POTFILES.in" | sed -e "/^#/d" -e "/^[  ]*\$/d" -e "s,.*,     $top_srcdir/& \\\\," | sed -e "\$s/\(.*\) \\\\/\1/" > "$ac_dir/POTFILES"
+          POMAKEFILEDEPS="POTFILES.in"
+          # ALL_LINGUAS, POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES depend
+          # on $ac_dir but don't depend on user-specified configuration
+          # parameters.
+          if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then
+            # The LINGUAS file contains the set of available languages.
+            if test -n "$OBSOLETE_ALL_LINGUAS"; then
+              test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete"
+            fi
+            ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"`
+            # Hide the ALL_LINGUAS assigment from automake.
+            eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
+            POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
+          else
+            # The set of available languages was given in configure.in.
+            eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS'
+          fi
+          # Compute POFILES
+          # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
+          # Compute UPDATEPOFILES
+          # as      $(foreach lang, $(ALL_LINGUAS), $(lang).po-update)
+          # Compute DUMMYPOFILES
+          # as      $(foreach lang, $(ALL_LINGUAS), $(lang).nop)
+          # Compute GMOFILES
+          # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo)
+          case "$ac_given_srcdir" in
+            .) srcdirpre= ;;
+            *) srcdirpre='$(srcdir)/' ;;
+          esac
+          POFILES=
+          UPDATEPOFILES=
+          DUMMYPOFILES=
+          GMOFILES=
+          for lang in $ALL_LINGUAS; do
+            POFILES="$POFILES $srcdirpre$lang.po"
+            UPDATEPOFILES="$UPDATEPOFILES $lang.po-update"
+            DUMMYPOFILES="$DUMMYPOFILES $lang.nop"
+            GMOFILES="$GMOFILES $srcdirpre$lang.gmo"
+          done
+          # CATALOGS depends on both $ac_dir and the user's LINGUAS
+          # environment variable.
+          INST_LINGUAS=
+          if test -n "$ALL_LINGUAS"; then
+            for presentlang in $ALL_LINGUAS; do
+              useit=no
+              if test "%UNSET%" != "$LINGUAS"; then
+                desiredlanguages="$LINGUAS"
+              else
+                desiredlanguages="$ALL_LINGUAS"
+              fi
+              for desiredlang in $desiredlanguages; do
+                # Use the presentlang catalog if desiredlang is
+                #   a. equal to presentlang, or
+                #   b. a variant of presentlang (because in this case,
+                #      presentlang can be used as a fallback for messages
+                #      which are not translated in the desiredlang catalog).
+                case "$desiredlang" in
+                  "$presentlang"*) useit=yes;;
+                esac
+              done
+              if test $useit = yes; then
+                INST_LINGUAS="$INST_LINGUAS $presentlang"
+              fi
+            done
+          fi
+          CATALOGS=
+          if test -n "$INST_LINGUAS"; then
+            for lang in $INST_LINGUAS; do
+              CATALOGS="$CATALOGS $lang.gmo"
+            done
+          fi
+          test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile"
+          sed -e "/^POTFILES =/r $ac_dir/POTFILES" -e "/^# Makevars/r $ac_given_srcdir/$ac_dir/Makevars" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@POMAKEFILEDEPS@|$POMAKEFILEDEPS|g" "$ac_dir/Makefile.in" > "$ac_dir/Makefile"
+          for f in "$ac_given_srcdir/$ac_dir"/Rules-*; do
+            if test -f "$f"; then
+              case "$f" in
+                *.orig | *.bak | *~) ;;
+                *) cat "$f" >> "$ac_dir/Makefile" ;;
+              esac
+            fi
+          done
+        fi
+        ;;
+      esac
+    done],
+   [# Capture the value of obsolete ALL_LINGUAS because we need it to compute
+    # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it
+    # from automake.
+    eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"'
+    # Capture the value of LINGUAS because we need it to compute CATALOGS.
+    LINGUAS="${LINGUAS-%UNSET%}"
+   ])
+])
+
+dnl Postprocesses a Makefile in a directory containing PO files.
+AC_DEFUN([AM_POSTPROCESS_PO_MAKEFILE],
+[
+  # When this code is run, in config.status, two variables have already been
+  # set:
+  # - OBSOLETE_ALL_LINGUAS is the value of LINGUAS set in configure.in,
+  # - LINGUAS is the value of the environment variable LINGUAS at configure
+  #   time.
+
+changequote(,)dnl
+  # Adjust a relative srcdir.
+  ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
+  ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
+  ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
+  # In autoconf-2.13 it is called $ac_given_srcdir.
+  # In autoconf-2.50 it is called $srcdir.
+  test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
+  case "$ac_given_srcdir" in
+    .)  top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
+    /*) top_srcdir="$ac_given_srcdir" ;;
+    *)  top_srcdir="$ac_dots$ac_given_srcdir" ;;
+  esac
+
+  # Find a way to echo strings without interpreting backslash.
+  if test "X`(echo '\t') 2>/dev/null`" = 'X\t'; then
+    gt_echo='echo'
+  else
+    if test "X`(printf '%s\n' '\t') 2>/dev/null`" = 'X\t'; then
+      gt_echo='printf %s\n'
+    else
+      echo_func () {
+        cat <<EOT
+$*
+EOT
+      }
+      gt_echo='echo_func'
+    fi
+  fi
+
+  # A sed script that extracts the value of VARIABLE from a Makefile.
+  sed_x_variable='
+# Test if the hold space is empty.
+x
+s/P/P/
+x
+ta
+# Yes it was empty. Look if we have the expected variable definition.
+/^[     ]*VARIABLE[     ]*=/{
+  # Seen the first line of the variable definition.
+  s/^[  ]*VARIABLE[     ]*=//
+  ba
+}
+bd
+:a
+# Here we are processing a line from the variable definition.
+# Remove comment, more precisely replace it with a space.
+s/#.*$/ /
+# See if the line ends in a backslash.
+tb
+:b
+s/\\$//
+# Print the line, without the trailing backslash.
+p
+tc
+# There was no trailing backslash. The end of the variable definition is
+# reached. Clear the hold space.
+s/^.*$//
+x
+bd
+:c
+# A trailing backslash means that the variable definition continues in the
+# next line. Put a nonempty string into the hold space to indicate this.
+s/^.*$/P/
+x
+:d
+'
+changequote([,])dnl
+
+  # Set POTFILES to the value of the Makefile variable POTFILES.
+  sed_x_POTFILES="`$gt_echo \"$sed_x_variable\" | sed -e '/^ *#/d' -e 's/VARIABLE/POTFILES/g'`"
+  POTFILES=`sed -n -e "$sed_x_POTFILES" < "$ac_file"`
+  # Compute POTFILES_DEPS as
+  #   $(foreach file, $(POTFILES), $(top_srcdir)/$(file))
+  POTFILES_DEPS=
+  for file in $POTFILES; do
+    POTFILES_DEPS="$POTFILES_DEPS "'$(top_srcdir)/'"$file"
+  done
+  POMAKEFILEDEPS=""
+
+  if test -n "$OBSOLETE_ALL_LINGUAS"; then
+    test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete"
+  fi
+  if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then
+    # The LINGUAS file contains the set of available languages.
+    ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"`
+    POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
+  else
+    # Set ALL_LINGUAS to the value of the Makefile variable LINGUAS.
+    sed_x_LINGUAS="`$gt_echo \"$sed_x_variable\" | sed -e '/^ *#/d' -e 's/VARIABLE/LINGUAS/g'`"
+    ALL_LINGUAS_=`sed -n -e "$sed_x_LINGUAS" < "$ac_file"`
+  fi
+  # Hide the ALL_LINGUAS assigment from automake.
+  eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
+  # Compute POFILES
+  # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
+  # Compute UPDATEPOFILES
+  # as      $(foreach lang, $(ALL_LINGUAS), $(lang).po-update)
+  # Compute DUMMYPOFILES
+  # as      $(foreach lang, $(ALL_LINGUAS), $(lang).nop)
+  # Compute GMOFILES
+  # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo)
+  # Compute PROPERTIESFILES
+  # as      $(foreach lang, $(ALL_LINGUAS), $(top_srcdir)/$(DOMAIN)_$(lang).properties)
+  # Compute CLASSFILES
+  # as      $(foreach lang, $(ALL_LINGUAS), $(top_srcdir)/$(DOMAIN)_$(lang).class)
+  # Compute QMFILES
+  # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).qm)
+  # Compute MSGFILES
+  # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(frob $(lang)).msg)
+  # Compute RESOURCESDLLFILES
+  # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(frob $(lang))/$(DOMAIN).resources.dll)
+  case "$ac_given_srcdir" in
+    .) srcdirpre= ;;
+    *) srcdirpre='$(srcdir)/' ;;
+  esac
+  POFILES=
+  UPDATEPOFILES=
+  DUMMYPOFILES=
+  GMOFILES=
+  PROPERTIESFILES=
+  CLASSFILES=
+  QMFILES=
+  MSGFILES=
+  RESOURCESDLLFILES=
+  for lang in $ALL_LINGUAS; do
+    POFILES="$POFILES $srcdirpre$lang.po"
+    UPDATEPOFILES="$UPDATEPOFILES $lang.po-update"
+    DUMMYPOFILES="$DUMMYPOFILES $lang.nop"
+    GMOFILES="$GMOFILES $srcdirpre$lang.gmo"
+    PROPERTIESFILES="$PROPERTIESFILES \$(top_srcdir)/\$(DOMAIN)_$lang.properties"
+    CLASSFILES="$CLASSFILES \$(top_srcdir)/\$(DOMAIN)_$lang.class"
+    QMFILES="$QMFILES $srcdirpre$lang.qm"
+    frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
+    MSGFILES="$MSGFILES $srcdirpre$frobbedlang.msg"
+    frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'`
+    RESOURCESDLLFILES="$RESOURCESDLLFILES $srcdirpre$frobbedlang/\$(DOMAIN).resources.dll"
+  done
+  # CATALOGS depends on both $ac_dir and the user's LINGUAS
+  # environment variable.
+  INST_LINGUAS=
+  if test -n "$ALL_LINGUAS"; then
+    for presentlang in $ALL_LINGUAS; do
+      useit=no
+      if test "%UNSET%" != "$LINGUAS"; then
+        desiredlanguages="$LINGUAS"
+      else
+        desiredlanguages="$ALL_LINGUAS"
+      fi
+      for desiredlang in $desiredlanguages; do
+        # Use the presentlang catalog if desiredlang is
+        #   a. equal to presentlang, or
+        #   b. a variant of presentlang (because in this case,
+        #      presentlang can be used as a fallback for messages
+        #      which are not translated in the desiredlang catalog).
+        case "$desiredlang" in
+          "$presentlang"*) useit=yes;;
+        esac
+      done
+      if test $useit = yes; then
+        INST_LINGUAS="$INST_LINGUAS $presentlang"
+      fi
+    done
+  fi
+  CATALOGS=
+  JAVACATALOGS=
+  QTCATALOGS=
+  TCLCATALOGS=
+  CSHARPCATALOGS=
+  if test -n "$INST_LINGUAS"; then
+    for lang in $INST_LINGUAS; do
+      CATALOGS="$CATALOGS $lang.gmo"
+      JAVACATALOGS="$JAVACATALOGS \$(DOMAIN)_$lang.properties"
+      QTCATALOGS="$QTCATALOGS $lang.qm"
+      frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
+      TCLCATALOGS="$TCLCATALOGS $frobbedlang.msg"
+      frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'`
+      CSHARPCATALOGS="$CSHARPCATALOGS $frobbedlang/\$(DOMAIN).resources.dll"
+    done
+  fi
+
+  sed -e "s|@POTFILES_DEPS@|$POTFILES_DEPS|g" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@PROPERTIESFILES@|$PROPERTIESFILES|g" -e "s|@CLASSFILES@|$CLASSFILES|g" -e "s|@QMFILES@|$QMFILES|g" -e "s|@MSGFILES@|$MSGFILES|g" -e "s|@RESOURCESDLLFILES@|$RESOURCESDLLFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@JAVACATALOGS@|$JAVACATALOGS|g" -e "s|@QTCATALOGS@|$QTCATALOGS|g" -e "s|@TCLCATALOGS@|$TCLCATALOGS|g" -e "s|@CSHARPCATALOGS@|$CSHARPCATALOGS|g" -e 's,^#distdir:,distdir:,' < "$ac_file" > "$ac_file.tmp"
+  if grep -l '@TCLCATALOGS@' "$ac_file" > /dev/null; then
+    # Add dependencies that cannot be formulated as a simple suffix rule.
+    for lang in $ALL_LINGUAS; do
+      frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
+      cat >> "$ac_file.tmp" <<EOF
+$frobbedlang.msg: $lang.po
+       @echo "\$(MSGFMT) -c --tcl -d \$(srcdir) -l $lang $srcdirpre$lang.po"; \
+       \$(MSGFMT) -c --tcl -d "\$(srcdir)" -l $lang $srcdirpre$lang.po || { rm -f "\$(srcdir)/$frobbedlang.msg"; exit 1; }
+EOF
+    done
+  fi
+  if grep -l '@CSHARPCATALOGS@' "$ac_file" > /dev/null; then
+    # Add dependencies that cannot be formulated as a simple suffix rule.
+    for lang in $ALL_LINGUAS; do
+      frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'`
+      cat >> "$ac_file.tmp" <<EOF
+$frobbedlang/\$(DOMAIN).resources.dll: $lang.po
+       @echo "\$(MSGFMT) -c --csharp -d \$(srcdir) -l $lang $srcdirpre$lang.po -r \$(DOMAIN)"; \
+       \$(MSGFMT) -c --csharp -d "\$(srcdir)" -l $lang $srcdirpre$lang.po -r "\$(DOMAIN)" || { rm -f "\$(srcdir)/$frobbedlang.msg"; exit 1; }
+EOF
+    done
+  fi
+  if test -n "$POMAKEFILEDEPS"; then
+    cat >> "$ac_file.tmp" <<EOF
+Makefile: $POMAKEFILEDEPS
+EOF
+  fi
+  mv "$ac_file.tmp" "$ac_file"
+])
diff --git a/m4/printf-posix.m4 b/m4/printf-posix.m4
new file mode 100644 (file)
index 0000000..af10170
--- /dev/null
@@ -0,0 +1,44 @@
+# printf-posix.m4 serial 2 (gettext-0.13.1)
+dnl Copyright (C) 2003 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+dnl Test whether the printf() function supports POSIX/XSI format strings with
+dnl positions.
+
+AC_DEFUN([gt_PRINTF_POSIX],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_CACHE_CHECK([whether printf() supports POSIX/XSI format strings],
+    gt_cv_func_printf_posix,
+    [
+      AC_TRY_RUN([
+#include <stdio.h>
+#include <string.h>
+/* The string "%2$d %1$d", with dollar characters protected from the shell's
+   dollar expansion (possibly an autoconf bug).  */
+static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
+static char buf[100];
+int main ()
+{
+  sprintf (buf, format, 33, 55);
+  return (strcmp (buf, "55 33") != 0);
+}], gt_cv_func_printf_posix=yes, gt_cv_func_printf_posix=no,
+      [
+        AC_EGREP_CPP(notposix, [
+#if defined __NetBSD__ || defined _MSC_VER || defined __MINGW32__ || defined __CYGWIN__
+  notposix
+#endif
+        ], gt_cv_func_printf_posix="guessing no",
+           gt_cv_func_printf_posix="guessing yes")
+      ])
+    ])
+  case $gt_cv_func_printf_posix in
+    *yes)
+      AC_DEFINE(HAVE_POSIX_PRINTF, 1,
+        [Define if your printf() function supports format strings with positions.])
+      ;;
+  esac
+])
diff --git a/m4/progtest.m4 b/m4/progtest.m4
new file mode 100644 (file)
index 0000000..a56365c
--- /dev/null
@@ -0,0 +1,92 @@
+# progtest.m4 serial 4 (gettext-0.14.2)
+dnl Copyright (C) 1996-2003, 2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+dnl
+dnl This file can can be used in projects which are not available under
+dnl the GNU General Public License or the GNU Library General Public
+dnl License but which still want to provide support for the GNU gettext
+dnl functionality.
+dnl Please note that the actual code of the GNU gettext library is covered
+dnl by the GNU Library General Public License, and the rest of the GNU
+dnl gettext package package is covered by the GNU General Public License.
+dnl They are *not* in the public domain.
+
+dnl Authors:
+dnl   Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+AC_PREREQ(2.50)
+
+# Search path for a program which passes the given test.
+
+dnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
+dnl   TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
+AC_DEFUN([AM_PATH_PROG_WITH_TEST],
+[
+# Prepare PATH_SEPARATOR.
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+
+# Find out how to test for executable files. Don't use a zero-byte file,
+# as systems may use methods other than mode bits to determine executability.
+cat >conf$$.file <<_ASEOF
+#! /bin/sh
+exit 0
+_ASEOF
+chmod +x conf$$.file
+if test -x conf$$.file >/dev/null 2>&1; then
+  ac_executable_p="test -x"
+else
+  ac_executable_p="test -f"
+fi
+rm -f conf$$.file
+
+# Extract the first word of "$2", so it can be a program name with args.
+set dummy $2; ac_word=[$]2
+AC_MSG_CHECKING([for $ac_word])
+AC_CACHE_VAL(ac_cv_path_$1,
+[case "[$]$1" in
+  [[\\/]]* | ?:[[\\/]]*)
+    ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
+    ;;
+  *)
+    ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in ifelse([$5], , $PATH, [$5]); do
+      IFS="$ac_save_IFS"
+      test -z "$ac_dir" && ac_dir=.
+      for ac_exec_ext in '' $ac_executable_extensions; do
+        if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then
+          echo "$as_me: trying $ac_dir/$ac_word..." >&AS_MESSAGE_LOG_FD
+          if [$3]; then
+            ac_cv_path_$1="$ac_dir/$ac_word$ac_exec_ext"
+            break 2
+          fi
+        fi
+      done
+    done
+    IFS="$ac_save_IFS"
+dnl If no 4th arg is given, leave the cache variable unset,
+dnl so AC_PATH_PROGS will keep looking.
+ifelse([$4], , , [  test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
+])dnl
+    ;;
+esac])dnl
+$1="$ac_cv_path_$1"
+if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then
+  AC_MSG_RESULT([$]$1)
+else
+  AC_MSG_RESULT(no)
+fi
+AC_SUBST($1)dnl
+])
diff --git a/m4/signed.m4 b/m4/signed.m4
new file mode 100644 (file)
index 0000000..048f593
--- /dev/null
@@ -0,0 +1,17 @@
+# signed.m4 serial 1 (gettext-0.10.40)
+dnl Copyright (C) 2001-2002 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+AC_DEFUN([bh_C_SIGNED],
+[
+  AC_CACHE_CHECK([for signed], bh_cv_c_signed,
+   [AC_TRY_COMPILE(, [signed char x;], bh_cv_c_signed=yes, bh_cv_c_signed=no)])
+  if test $bh_cv_c_signed = no; then
+    AC_DEFINE(signed, ,
+              [Define to empty if the C compiler doesn't support this keyword.])
+  fi
+])
diff --git a/m4/size_max.m4 b/m4/size_max.m4
new file mode 100644 (file)
index 0000000..4fe81c7
--- /dev/null
@@ -0,0 +1,59 @@
+# size_max.m4 serial 2
+dnl Copyright (C) 2003 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+AC_DEFUN([gl_SIZE_MAX],
+[
+  AC_CHECK_HEADERS(stdint.h)
+  dnl First test whether the system already has SIZE_MAX.
+  AC_MSG_CHECKING([for SIZE_MAX])
+  result=
+  AC_EGREP_CPP([Found it], [
+#include <limits.h>
+#if HAVE_STDINT_H
+#include <stdint.h>
+#endif
+#ifdef SIZE_MAX
+Found it
+#endif
+], result=yes)
+  if test -z "$result"; then
+    dnl Define it ourselves. Here we assume that the type 'size_t' is not wider
+    dnl than the type 'unsigned long'.
+    dnl The _AC_COMPUTE_INT macro works up to LONG_MAX, since it uses 'expr',
+    dnl which is guaranteed to work from LONG_MIN to LONG_MAX.
+    _AC_COMPUTE_INT([~(size_t)0 / 10], res_hi,
+      [#include <stddef.h>], result=?)
+    _AC_COMPUTE_INT([~(size_t)0 % 10], res_lo,
+      [#include <stddef.h>], result=?)
+    _AC_COMPUTE_INT([sizeof (size_t) <= sizeof (unsigned int)], fits_in_uint,
+      [#include <stddef.h>], result=?)
+    if test "$fits_in_uint" = 1; then
+      dnl Even though SIZE_MAX fits in an unsigned int, it must be of type
+      dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'.
+      AC_TRY_COMPILE([#include <stddef.h>
+        extern size_t foo;
+        extern unsigned long foo;
+        ], [], fits_in_uint=0)
+    fi
+    if test -z "$result"; then
+      if test "$fits_in_uint" = 1; then
+        result="$res_hi$res_lo"U
+      else
+        result="$res_hi$res_lo"UL
+      fi
+    else
+      dnl Shouldn't happen, but who knows...
+      result='~(size_t)0'
+    fi
+  fi
+  AC_MSG_RESULT([$result])
+  if test "$result" != yes; then
+    AC_DEFINE_UNQUOTED([SIZE_MAX], [$result],
+      [Define as the maximum value of type 'size_t', if the system doesn't define it.])
+  fi
+])
diff --git a/m4/stdint_h.m4 b/m4/stdint_h.m4
new file mode 100644 (file)
index 0000000..3355f35
--- /dev/null
@@ -0,0 +1,26 @@
+# stdint_h.m4 serial 5
+dnl Copyright (C) 1997-2004 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Paul Eggert.
+
+# Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
+# doesn't clash with <sys/types.h>, and declares uintmax_t.
+
+AC_DEFUN([gl_AC_HEADER_STDINT_H],
+[
+  AC_CACHE_CHECK([for stdint.h], gl_cv_header_stdint_h,
+  [AC_TRY_COMPILE(
+    [#include <sys/types.h>
+#include <stdint.h>],
+    [uintmax_t i = (uintmax_t) -1;],
+    gl_cv_header_stdint_h=yes,
+    gl_cv_header_stdint_h=no)])
+  if test $gl_cv_header_stdint_h = yes; then
+    AC_DEFINE_UNQUOTED(HAVE_STDINT_H_WITH_UINTMAX, 1,
+      [Define if <stdint.h> exists, doesn't clash with <sys/types.h>,
+       and declares uintmax_t. ])
+  fi
+])
diff --git a/m4/uintmax_t.m4 b/m4/uintmax_t.m4
new file mode 100644 (file)
index 0000000..bf83ed7
--- /dev/null
@@ -0,0 +1,30 @@
+# uintmax_t.m4 serial 9
+dnl Copyright (C) 1997-2004 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Paul Eggert.
+
+AC_PREREQ(2.13)
+
+# Define uintmax_t to 'unsigned long' or 'unsigned long long'
+# if it is not already defined in <stdint.h> or <inttypes.h>.
+
+AC_DEFUN([gl_AC_TYPE_UINTMAX_T],
+[
+  AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
+  AC_REQUIRE([gl_AC_HEADER_STDINT_H])
+  if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then
+    AC_REQUIRE([gl_AC_TYPE_UNSIGNED_LONG_LONG])
+    test $ac_cv_type_unsigned_long_long = yes \
+      && ac_type='unsigned long long' \
+      || ac_type='unsigned long'
+    AC_DEFINE_UNQUOTED(uintmax_t, $ac_type,
+      [Define to unsigned long or unsigned long long
+       if <stdint.h> and <inttypes.h> don't define.])
+  else
+    AC_DEFINE(HAVE_UINTMAX_T, 1,
+      [Define if you have the 'uintmax_t' type in <stdint.h> or <inttypes.h>.])
+  fi
+])
diff --git a/m4/ulonglong.m4 b/m4/ulonglong.m4
new file mode 100644 (file)
index 0000000..dee10cc
--- /dev/null
@@ -0,0 +1,23 @@
+# ulonglong.m4 serial 4
+dnl Copyright (C) 1999-2004 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Paul Eggert.
+
+# Define HAVE_UNSIGNED_LONG_LONG if 'unsigned long long' works.
+
+AC_DEFUN([gl_AC_TYPE_UNSIGNED_LONG_LONG],
+[
+  AC_CACHE_CHECK([for unsigned long long], ac_cv_type_unsigned_long_long,
+  [AC_TRY_LINK([unsigned long long ull = 1ULL; int i = 63;],
+    [unsigned long long ullmax = (unsigned long long) -1;
+     return ull << i | ull >> i | ullmax / ull | ullmax % ull;],
+    ac_cv_type_unsigned_long_long=yes,
+    ac_cv_type_unsigned_long_long=no)])
+  if test $ac_cv_type_unsigned_long_long = yes; then
+    AC_DEFINE(HAVE_UNSIGNED_LONG_LONG, 1,
+      [Define if you have the 'unsigned long long' type.])
+  fi
+])
diff --git a/m4/wchar_t.m4 b/m4/wchar_t.m4
new file mode 100644 (file)
index 0000000..cde2129
--- /dev/null
@@ -0,0 +1,20 @@
+# wchar_t.m4 serial 1 (gettext-0.12)
+dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+dnl Test whether <stddef.h> has the 'wchar_t' type.
+dnl Prerequisite: AC_PROG_CC
+
+AC_DEFUN([gt_TYPE_WCHAR_T],
+[
+  AC_CACHE_CHECK([for wchar_t], gt_cv_c_wchar_t,
+    [AC_TRY_COMPILE([#include <stddef.h>
+       wchar_t foo = (wchar_t)'\0';], ,
+       gt_cv_c_wchar_t=yes, gt_cv_c_wchar_t=no)])
+  if test $gt_cv_c_wchar_t = yes; then
+    AC_DEFINE(HAVE_WCHAR_T, 1, [Define if you have the 'wchar_t' type.])
+  fi
+])
diff --git a/m4/wint_t.m4 b/m4/wint_t.m4
new file mode 100644 (file)
index 0000000..b8fff9c
--- /dev/null
@@ -0,0 +1,20 @@
+# wint_t.m4 serial 1 (gettext-0.12)
+dnl Copyright (C) 2003 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+dnl Test whether <wchar.h> has the 'wint_t' type.
+dnl Prerequisite: AC_PROG_CC
+
+AC_DEFUN([gt_TYPE_WINT_T],
+[
+  AC_CACHE_CHECK([for wint_t], gt_cv_c_wint_t,
+    [AC_TRY_COMPILE([#include <wchar.h>
+       wint_t foo = (wchar_t)'\0';], ,
+       gt_cv_c_wint_t=yes, gt_cv_c_wint_t=no)])
+  if test $gt_cv_c_wint_t = yes; then
+    AC_DEFINE(HAVE_WINT_T, 1, [Define if you have the 'wint_t' type.])
+  fi
+])
diff --git a/m4/xsize.m4 b/m4/xsize.m4
new file mode 100644 (file)
index 0000000..85bb721
--- /dev/null
@@ -0,0 +1,13 @@
+# xsize.m4 serial 3
+dnl Copyright (C) 2003-2004 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_XSIZE],
+[
+  dnl Prerequisites of lib/xsize.h.
+  AC_REQUIRE([gl_SIZE_MAX])
+  AC_REQUIRE([AC_C_INLINE])
+  AC_CHECK_HEADERS(stdint.h)
+])
diff --git a/missing b/missing
new file mode 100755 (executable)
index 0000000..28055d2
--- /dev/null
+++ b/missing
@@ -0,0 +1,376 @@
+#! /bin/sh
+# Common stub for a few missing GNU programs while installing.
+
+scriptversion=2009-04-28.21; # UTC
+
+# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
+# 2008, 2009 Free Software Foundation, Inc.
+# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program 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 General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+if test $# -eq 0; then
+  echo 1>&2 "Try \`$0 --help' for more information"
+  exit 1
+fi
+
+run=:
+sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
+sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
+
+# In the cases where this matters, `missing' is being run in the
+# srcdir already.
+if test -f configure.ac; then
+  configure_ac=configure.ac
+else
+  configure_ac=configure.in
+fi
+
+msg="missing on your system"
+
+case $1 in
+--run)
+  # Try to run requested program, and just exit if it succeeds.
+  run=
+  shift
+  "$@" && exit 0
+  # Exit code 63 means version mismatch.  This often happens
+  # when the user try to use an ancient version of a tool on
+  # a file that requires a minimum version.  In this case we
+  # we should proceed has if the program had been absent, or
+  # if --run hadn't been passed.
+  if test $? = 63; then
+    run=:
+    msg="probably too old"
+  fi
+  ;;
+
+  -h|--h|--he|--hel|--help)
+    echo "\
+$0 [OPTION]... PROGRAM [ARGUMENT]...
+
+Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
+error status if there is no known handling for PROGRAM.
+
+Options:
+  -h, --help      display this help and exit
+  -v, --version   output version information and exit
+  --run           try to run the given command, and emulate it if it fails
+
+Supported PROGRAM values:
+  aclocal      touch file \`aclocal.m4'
+  autoconf     touch file \`configure'
+  autoheader   touch file \`config.h.in'
+  autom4te     touch the output file, or create a stub one
+  automake     touch all \`Makefile.in' files
+  bison        create \`y.tab.[ch]', if possible, from existing .[ch]
+  flex         create \`lex.yy.c', if possible, from existing .c
+  help2man     touch the output file
+  lex          create \`lex.yy.c', if possible, from existing .c
+  makeinfo     touch the output file
+  tar          try tar, gnutar, gtar, then tar without non-portable flags
+  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
+
+Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
+\`g' are ignored when checking the name.
+
+Send bug reports to <bug-automake@gnu.org>."
+    exit $?
+    ;;
+
+  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
+    echo "missing $scriptversion (GNU Automake)"
+    exit $?
+    ;;
+
+  -*)
+    echo 1>&2 "$0: Unknown \`$1' option"
+    echo 1>&2 "Try \`$0 --help' for more information"
+    exit 1
+    ;;
+
+esac
+
+# normalize program name to check for.
+program=`echo "$1" | sed '
+  s/^gnu-//; t
+  s/^gnu//; t
+  s/^g//; t'`
+
+# Now exit if we have it, but it failed.  Also exit now if we
+# don't have it and --version was passed (most likely to detect
+# the program).  This is about non-GNU programs, so use $1 not
+# $program.
+case $1 in
+  lex*|yacc*)
+    # Not GNU programs, they don't have --version.
+    ;;
+
+  tar*)
+    if test -n "$run"; then
+       echo 1>&2 "ERROR: \`tar' requires --run"
+       exit 1
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
+       exit 1
+    fi
+    ;;
+
+  *)
+    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
+       # We have it, but it failed.
+       exit 1
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
+       # Could not run --version or --help.  This is probably someone
+       # running `$TOOL --version' or `$TOOL --help' to check whether
+       # $TOOL exists and not knowing $TOOL uses missing.
+       exit 1
+    fi
+    ;;
+esac
+
+# If it does not exist, or fails to run (possibly an outdated version),
+# try to emulate it.
+case $program in
+  aclocal*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
+         to install the \`Automake' and \`Perl' packages.  Grab them from
+         any GNU archive site."
+    touch aclocal.m4
+    ;;
+
+  autoconf*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`${configure_ac}'.  You might want to install the
+         \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
+         archive site."
+    touch configure
+    ;;
+
+  autoheader*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`acconfig.h' or \`${configure_ac}'.  You might want
+         to install the \`Autoconf' and \`GNU m4' packages.  Grab them
+         from any GNU archive site."
+    files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
+    test -z "$files" && files="config.h"
+    touch_files=
+    for f in $files; do
+      case $f in
+      *:*) touch_files="$touch_files "`echo "$f" |
+                                      sed -e 's/^[^:]*://' -e 's/:.*//'`;;
+      *) touch_files="$touch_files $f.in";;
+      esac
+    done
+    touch $touch_files
+    ;;
+
+  automake*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
+         You might want to install the \`Automake' and \`Perl' packages.
+         Grab them from any GNU archive site."
+    find . -type f -name Makefile.am -print |
+          sed 's/\.am$/.in/' |
+          while read f; do touch "$f"; done
+    ;;
+
+  autom4te*)
+    echo 1>&2 "\
+WARNING: \`$1' is needed, but is $msg.
+         You might have modified some files without having the
+         proper tools for further handling them.
+         You can get \`$1' as part of \`Autoconf' from any GNU
+         archive site."
+
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
+    if test -f "$file"; then
+       touch $file
+    else
+       test -z "$file" || exec >$file
+       echo "#! /bin/sh"
+       echo "# Created by GNU Automake missing as a replacement of"
+       echo "#  $ $@"
+       echo "exit 0"
+       chmod +x $file
+       exit 1
+    fi
+    ;;
+
+  bison*|yacc*)
+    echo 1>&2 "\
+WARNING: \`$1' $msg.  You should only need it if
+         you modified a \`.y' file.  You may need the \`Bison' package
+         in order for those modifications to take effect.  You can get
+         \`Bison' from any GNU archive site."
+    rm -f y.tab.c y.tab.h
+    if test $# -ne 1; then
+        eval LASTARG="\${$#}"
+       case $LASTARG in
+       *.y)
+           SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
+           if test -f "$SRCFILE"; then
+                cp "$SRCFILE" y.tab.c
+           fi
+           SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
+           if test -f "$SRCFILE"; then
+                cp "$SRCFILE" y.tab.h
+           fi
+         ;;
+       esac
+    fi
+    if test ! -f y.tab.h; then
+       echo >y.tab.h
+    fi
+    if test ! -f y.tab.c; then
+       echo 'main() { return 0; }' >y.tab.c
+    fi
+    ;;
+
+  lex*|flex*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified a \`.l' file.  You may need the \`Flex' package
+         in order for those modifications to take effect.  You can get
+         \`Flex' from any GNU archive site."
+    rm -f lex.yy.c
+    if test $# -ne 1; then
+        eval LASTARG="\${$#}"
+       case $LASTARG in
+       *.l)
+           SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
+           if test -f "$SRCFILE"; then
+                cp "$SRCFILE" lex.yy.c
+           fi
+         ;;
+       esac
+    fi
+    if test ! -f lex.yy.c; then
+       echo 'main() { return 0; }' >lex.yy.c
+    fi
+    ;;
+
+  help2man*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+        you modified a dependency of a manual page.  You may need the
+        \`Help2man' package in order for those modifications to take
+        effect.  You can get \`Help2man' from any GNU archive site."
+
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
+    if test -f "$file"; then
+       touch $file
+    else
+       test -z "$file" || exec >$file
+       echo ".ab help2man is required to generate this page"
+       exit $?
+    fi
+    ;;
+
+  makeinfo*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified a \`.texi' or \`.texinfo' file, or any other file
+         indirectly affecting the aspect of the manual.  The spurious
+         call might also be the consequence of using a buggy \`make' (AIX,
+         DU, IRIX).  You might want to install the \`Texinfo' package or
+         the \`GNU make' package.  Grab either from any GNU archive site."
+    # The file to touch is that specified with -o ...
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
+    if test -z "$file"; then
+      # ... or it is the one specified with @setfilename ...
+      infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
+      file=`sed -n '
+       /^@setfilename/{
+         s/.* \([^ ]*\) *$/\1/
+         p
+         q
+       }' $infile`
+      # ... or it is derived from the source name (dir/f.texi becomes f.info)
+      test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
+    fi
+    # If the file does not exist, the user really needs makeinfo;
+    # let's fail without touching anything.
+    test -f $file || exit 1
+    touch $file
+    ;;
+
+  tar*)
+    shift
+
+    # We have already tried tar in the generic part.
+    # Look for gnutar/gtar before invocation to avoid ugly error
+    # messages.
+    if (gnutar --version > /dev/null 2>&1); then
+       gnutar "$@" && exit 0
+    fi
+    if (gtar --version > /dev/null 2>&1); then
+       gtar "$@" && exit 0
+    fi
+    firstarg="$1"
+    if shift; then
+       case $firstarg in
+       *o*)
+           firstarg=`echo "$firstarg" | sed s/o//`
+           tar "$firstarg" "$@" && exit 0
+           ;;
+       esac
+       case $firstarg in
+       *h*)
+           firstarg=`echo "$firstarg" | sed s/h//`
+           tar "$firstarg" "$@" && exit 0
+           ;;
+       esac
+    fi
+
+    echo 1>&2 "\
+WARNING: I can't seem to be able to run \`tar' with the given arguments.
+         You may want to install GNU tar or Free paxutils, or check the
+         command line arguments."
+    exit 1
+    ;;
+
+  *)
+    echo 1>&2 "\
+WARNING: \`$1' is needed, and is $msg.
+         You might have modified some files without having the
+         proper tools for further handling them.  Check the \`README' file,
+         it often tells you about the needed prerequisites for installing
+         this package.  You may also peek at any GNU archive site, in case
+         some other package would contain this missing \`$1' program."
+    exit 1
+    ;;
+esac
+
+exit 0
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/mkinstalldirs b/mkinstalldirs
new file mode 100755 (executable)
index 0000000..4191a45
--- /dev/null
@@ -0,0 +1,162 @@
+#! /bin/sh
+# mkinstalldirs --- make directory hierarchy
+
+scriptversion=2009-04-28.21; # UTC
+
+# Original author: Noah Friedman <friedman@prep.ai.mit.edu>
+# Created: 1993-05-16
+# Public domain.
+#
+# This file is maintained in Automake, please report
+# bugs to <bug-automake@gnu.org> or send patches to
+# <automake-patches@gnu.org>.
+
+nl='
+'
+IFS=" ""       $nl"
+errstatus=0
+dirmode=
+
+usage="\
+Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
+
+Create each directory DIR (with mode MODE, if specified), including all
+leading file name components.
+
+Report bugs to <bug-automake@gnu.org>."
+
+# process command line arguments
+while test $# -gt 0 ; do
+  case $1 in
+    -h | --help | --h*)         # -h for help
+      echo "$usage"
+      exit $?
+      ;;
+    -m)                         # -m PERM arg
+      shift
+      test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
+      dirmode=$1
+      shift
+      ;;
+    --version)
+      echo "$0 $scriptversion"
+      exit $?
+      ;;
+    --)                         # stop option processing
+      shift
+      break
+      ;;
+    -*)                         # unknown option
+      echo "$usage" 1>&2
+      exit 1
+      ;;
+    *)                          # first non-opt arg
+      break
+      ;;
+  esac
+done
+
+for file
+do
+  if test -d "$file"; then
+    shift
+  else
+    break
+  fi
+done
+
+case $# in
+  0) exit 0 ;;
+esac
+
+# Solaris 8's mkdir -p isn't thread-safe.  If you mkdir -p a/b and
+# mkdir -p a/c at the same time, both will detect that a is missing,
+# one will create a, then the other will try to create a and die with
+# a "File exists" error.  This is a problem when calling mkinstalldirs
+# from a parallel make.  We use --version in the probe to restrict
+# ourselves to GNU mkdir, which is thread-safe.
+case $dirmode in
+  '')
+    if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
+      echo "mkdir -p -- $*"
+      exec mkdir -p -- "$@"
+    else
+      # On NextStep and OpenStep, the `mkdir' command does not
+      # recognize any option.  It will interpret all options as
+      # directories to create, and then abort because `.' already
+      # exists.
+      test -d ./-p && rmdir ./-p
+      test -d ./--version && rmdir ./--version
+    fi
+    ;;
+  *)
+    if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
+       test ! -d ./--version; then
+      echo "mkdir -m $dirmode -p -- $*"
+      exec mkdir -m "$dirmode" -p -- "$@"
+    else
+      # Clean up after NextStep and OpenStep mkdir.
+      for d in ./-m ./-p ./--version "./$dirmode";
+      do
+        test -d $d && rmdir $d
+      done
+    fi
+    ;;
+esac
+
+for file
+do
+  case $file in
+    /*) pathcomp=/ ;;
+    *)  pathcomp= ;;
+  esac
+  oIFS=$IFS
+  IFS=/
+  set fnord $file
+  shift
+  IFS=$oIFS
+
+  for d
+  do
+    test "x$d" = x && continue
+
+    pathcomp=$pathcomp$d
+    case $pathcomp in
+      -*) pathcomp=./$pathcomp ;;
+    esac
+
+    if test ! -d "$pathcomp"; then
+      echo "mkdir $pathcomp"
+
+      mkdir "$pathcomp" || lasterr=$?
+
+      if test ! -d "$pathcomp"; then
+       errstatus=$lasterr
+      else
+       if test ! -z "$dirmode"; then
+         echo "chmod $dirmode $pathcomp"
+         lasterr=
+         chmod "$dirmode" "$pathcomp" || lasterr=$?
+
+         if test ! -z "$lasterr"; then
+           errstatus=$lasterr
+         fi
+       fi
+      fi
+    fi
+
+    pathcomp=$pathcomp/
+  done
+done
+
+exit $errstatus
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/packaging/m17n-lib-nobuild-examples.patch b/packaging/m17n-lib-nobuild-examples.patch
new file mode 100644 (file)
index 0000000..859121f
--- /dev/null
@@ -0,0 +1,11 @@
+--- m17n-lib-1.3.1/Makefile.am~        2005-11-21 16:39:00.000000000 +0900
++++ m17n-lib-1.3.1/Makefile.am 2006-02-02 16:01:48.000000000 +0900
+@@ -22,7 +22,7 @@
+ ## Process this file with Automake to create Makefile.in
+-SUBDIRS = intl po src example
++SUBDIRS = intl po src
+ bin_SCRIPTS = m17n-config
diff --git a/packaging/m17n-lib.changes b/packaging/m17n-lib.changes
new file mode 100644 (file)
index 0000000..1bf0a74
--- /dev/null
@@ -0,0 +1,3 @@
+* Sat Sep 15 00:16:44 UTC 2012 - tracy.graydon@intel.com
+- Initial commit to support emacs 
+
diff --git a/packaging/m17n-lib.spec b/packaging/m17n-lib.spec
new file mode 100644 (file)
index 0000000..89ae287
--- /dev/null
@@ -0,0 +1,98 @@
+# set to 1 to build with GUI and OpenType Font support
+%define with_gui 0
+# set to 1 to build examples (including anthy support)
+%define with_examples 0
+
+Name:          m17n-lib
+Version:       1.6.1
+Release:       1
+Summary:       Multilingual text library
+Group:         System Environment/Libraries
+License:       LGPLv2
+URL:           http://www.m17n.org/m17n-lib/index.html
+Source0:       %{name}-%{version}.tar.gz
+
+BuildRequires:  m17n-db >= 1.4.0
+%if %{with_gui}
+BuildRequires:  libxml2-devel, xorg-x11-devel
+BuildRequires:  freetype-devel >= 2.0, fribidi-devel, gd-devel >= 2.0
+BuildRequires:  libotf-devel >= %{libotf_version}
+%else
+BuildRequires:  autoconf
+BuildRequires:  libtool
+BuildRequires:  pkgconfig
+%endif
+%if %{with_examples}
+BuildRequires:  anthy-devel
+%endif
+Requires:  m17n-db >= 1.4.0
+Patch2:    m17n-lib-nobuild-examples.patch
+
+%description
+m17n-lib is a multilingual text library used primarily to allow
+the input of many languages with the input table maps from m17n-db.
+
+
+%package  devel
+Summary:  Development file for m17n-lib 
+Group:    Development/Libraries
+Requires:  %{name} =  %{version}-%{release} 
+
+%description devel
+Development files for %{name}.
+
+
+%prep
+%setup -q
+
+%if ! %{with_examples}
+%patch2 -p1 -b .examples
+%endif
+# patch2 touches Makefile.am
+autoreconf -v -f -i
+
+
+%build
+libtoolize --copy --force
+%configure --disable-static \
+%if ! %{with_gui}
+  --with-gui=no
+%else
+  %{nil}
+%endif
+make
+
+
+%install
+rm -rf $RPM_BUILD_ROOT
+make install DESTDIR=$RPM_BUILD_ROOT INSTALL="%{__install} -c -p"
+
+# remove unneeded files
+rm $RPM_BUILD_ROOT%{_bindir}/m17n-config
+rm $RPM_BUILD_ROOT%{_libdir}/lib*.la
+
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+
+%post -p /sbin/ldconfig
+
+
+%postun -p /sbin/ldconfig
+
+
+%files
+%defattr(-,root,root)
+%doc AUTHORS COPYING NEWS
+%{_libdir}/lib*.so.*
+
+%files devel
+%defattr(-,root,root)
+%doc ChangeLog README
+%{_includedir}/*
+%{_libdir}/lib*.so
+%{_libdir}/pkgconfig/*
+
+
diff --git a/po/ChangeLog b/po/ChangeLog
new file mode 100644 (file)
index 0000000..f816a94
--- /dev/null
@@ -0,0 +1,12 @@
+2006-09-21  gettextize  <bug-gnu-gettext@gnu.org>
+
+       * Makefile.in.in: New file, from gettext-0.14.4.
+       * Rules-quot: New file, from gettext-0.14.4.
+       * boldquot.sed: New file, from gettext-0.14.4.
+       * en@boldquot.header: New file, from gettext-0.14.4.
+       * en@quot.header: New file, from gettext-0.14.4.
+       * insert-header.sin: New file, from gettext-0.14.4.
+       * quot.sed: New file, from gettext-0.14.4.
+       * remove-potcdate.sin: New file, from gettext-0.14.4.
+       * POTFILES.in: New file.
+
diff --git a/po/Makefile.in.in b/po/Makefile.in.in
new file mode 100644 (file)
index 0000000..1f5cc28
--- /dev/null
@@ -0,0 +1,384 @@
+# Makefile for PO directory in any package using GNU gettext.
+# Copyright (C) 1995-1997, 2000-2005 by Ulrich Drepper <drepper@gnu.ai.mit.edu>
+#
+# This file can be copied and used freely without restrictions.  It can
+# be used in projects which are not available under the GNU General Public
+# License but which still want to provide support for the GNU gettext
+# functionality.
+# Please note that the actual code of GNU gettext is covered by the GNU
+# General Public License and is *not* in the public domain.
+#
+# Origin: gettext-0.14.4
+
+PACKAGE = @PACKAGE@
+VERSION = @VERSION@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+
+SHELL = /bin/sh
+@SET_MAKE@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+datadir = @datadir@
+localedir = $(datadir)/locale
+gettextsrcdir = $(datadir)/gettext/po
+
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+MKINSTALLDIRS = @MKINSTALLDIRS@
+mkinstalldirs = $(SHELL) $(MKINSTALLDIRS)
+
+GMSGFMT = @GMSGFMT@
+MSGFMT = @MSGFMT@
+XGETTEXT = @XGETTEXT@
+MSGMERGE = msgmerge
+MSGMERGE_UPDATE = @MSGMERGE@ --update
+MSGINIT = msginit
+MSGCONV = msgconv
+MSGFILTER = msgfilter
+
+POFILES = @POFILES@
+GMOFILES = @GMOFILES@
+UPDATEPOFILES = @UPDATEPOFILES@
+DUMMYPOFILES = @DUMMYPOFILES@
+DISTFILES.common = Makefile.in.in remove-potcdate.sin \
+$(DISTFILES.common.extra1) $(DISTFILES.common.extra2) $(DISTFILES.common.extra3)
+DISTFILES = $(DISTFILES.common) Makevars POTFILES.in \
+$(POFILES) $(GMOFILES) \
+$(DISTFILES.extra1) $(DISTFILES.extra2) $(DISTFILES.extra3)
+
+POTFILES = \
+
+CATALOGS = @CATALOGS@
+
+# Makevars gets inserted here. (Don't remove this line!)
+
+.SUFFIXES:
+.SUFFIXES: .po .gmo .mo .sed .sin .nop .po-create .po-update
+
+.po.mo:
+       @echo "$(MSGFMT) -c -o $@ $<"; \
+       $(MSGFMT) -c -o t-$@ $< && mv t-$@ $@
+
+.po.gmo:
+       @lang=`echo $* | sed -e 's,.*/,,'`; \
+       test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \
+       echo "$${cdcmd}rm -f $${lang}.gmo && $(GMSGFMT) -c --statistics -o $${lang}.gmo $${lang}.po"; \
+       cd $(srcdir) && rm -f $${lang}.gmo && $(GMSGFMT) -c --statistics -o t-$${lang}.gmo $${lang}.po && mv t-$${lang}.gmo $${lang}.gmo
+
+.sin.sed:
+       sed -e '/^#/d' $< > t-$@
+       mv t-$@ $@
+
+
+all: all-@USE_NLS@
+
+all-yes: stamp-po
+all-no:
+
+# $(srcdir)/$(DOMAIN).pot is only created when needed. When xgettext finds no
+# internationalized messages, no $(srcdir)/$(DOMAIN).pot is created (because
+# we don't want to bother translators with empty POT files). We assume that
+# LINGUAS is empty in this case, i.e. $(POFILES) and $(GMOFILES) are empty.
+# In this case, stamp-po is a nop (i.e. a phony target).
+
+# stamp-po is a timestamp denoting the last time at which the CATALOGS have
+# been loosely updated. Its purpose is that when a developer or translator
+# checks out the package via CVS, and the $(DOMAIN).pot file is not in CVS,
+# "make" will update the $(DOMAIN).pot and the $(CATALOGS), but subsequent
+# invocations of "make" will do nothing. This timestamp would not be necessary
+# if updating the $(CATALOGS) would always touch them; however, the rule for
+# $(POFILES) has been designed to not touch files that don't need to be
+# changed.
+stamp-po: $(srcdir)/$(DOMAIN).pot
+       test ! -f $(srcdir)/$(DOMAIN).pot || \
+         test -z "$(GMOFILES)" || $(MAKE) $(GMOFILES)
+       @test ! -f $(srcdir)/$(DOMAIN).pot || { \
+         echo "touch stamp-po" && \
+         echo timestamp > stamp-poT && \
+         mv stamp-poT stamp-po; \
+       }
+
+# Note: Target 'all' must not depend on target '$(DOMAIN).pot-update',
+# otherwise packages like GCC can not be built if only parts of the source
+# have been downloaded.
+
+# This target rebuilds $(DOMAIN).pot; it is an expensive operation.
+# Note that $(DOMAIN).pot is not touched if it doesn't need to be changed.
+$(DOMAIN).pot-update: $(POTFILES) $(srcdir)/POTFILES.in remove-potcdate.sed
+       if test -n '$(MSGID_BUGS_ADDRESS)' || test '$(PACKAGE_BUGREPORT)' = '@'PACKAGE_BUGREPORT'@'; then \
+         msgid_bugs_address='$(MSGID_BUGS_ADDRESS)'; \
+       else \
+         msgid_bugs_address='$(PACKAGE_BUGREPORT)'; \
+       fi; \
+       $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \
+         --add-comments=TRANSLATORS: $(XGETTEXT_OPTIONS) \
+         --files-from=$(srcdir)/POTFILES.in \
+         --copyright-holder='$(COPYRIGHT_HOLDER)' \
+         --msgid-bugs-address="$$msgid_bugs_address"
+       test ! -f $(DOMAIN).po || { \
+         if test -f $(srcdir)/$(DOMAIN).pot; then \
+           sed -f remove-potcdate.sed < $(srcdir)/$(DOMAIN).pot > $(DOMAIN).1po && \
+           sed -f remove-potcdate.sed < $(DOMAIN).po > $(DOMAIN).2po && \
+           if cmp $(DOMAIN).1po $(DOMAIN).2po >/dev/null 2>&1; then \
+             rm -f $(DOMAIN).1po $(DOMAIN).2po $(DOMAIN).po; \
+           else \
+             rm -f $(DOMAIN).1po $(DOMAIN).2po $(srcdir)/$(DOMAIN).pot && \
+             mv $(DOMAIN).po $(srcdir)/$(DOMAIN).pot; \
+           fi; \
+         else \
+           mv $(DOMAIN).po $(srcdir)/$(DOMAIN).pot; \
+         fi; \
+       }
+
+# This rule has no dependencies: we don't need to update $(DOMAIN).pot at
+# every "make" invocation, only create it when it is missing.
+# Only "make $(DOMAIN).pot-update" or "make dist" will force an update.
+$(srcdir)/$(DOMAIN).pot:
+       $(MAKE) $(DOMAIN).pot-update
+
+# This target rebuilds a PO file if $(DOMAIN).pot has changed.
+# Note that a PO file is not touched if it doesn't need to be changed.
+$(POFILES): $(srcdir)/$(DOMAIN).pot
+       @lang=`echo $@ | sed -e 's,.*/,,' -e 's/\.po$$//'`; \
+       if test -f "$(srcdir)/$${lang}.po"; then \
+         test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \
+         echo "$${cdcmd}$(MSGMERGE_UPDATE) $${lang}.po $(DOMAIN).pot"; \
+         cd $(srcdir) && $(MSGMERGE_UPDATE) $${lang}.po $(DOMAIN).pot; \
+       else \
+         $(MAKE) $${lang}.po-create; \
+       fi
+
+
+install: install-exec install-data
+install-exec:
+install-data: install-data-@USE_NLS@
+       if test "$(PACKAGE)" = "gettext-tools"; then \
+         $(mkinstalldirs) $(DESTDIR)$(gettextsrcdir); \
+         for file in $(DISTFILES.common) Makevars.template; do \
+           $(INSTALL_DATA) $(srcdir)/$$file \
+                           $(DESTDIR)$(gettextsrcdir)/$$file; \
+         done; \
+         for file in Makevars; do \
+           rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \
+         done; \
+       else \
+         : ; \
+       fi
+install-data-no: all
+install-data-yes: all
+       $(mkinstalldirs) $(DESTDIR)$(datadir)
+       @catalogs='$(CATALOGS)'; \
+       for cat in $$catalogs; do \
+         cat=`basename $$cat`; \
+         lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \
+         dir=$(localedir)/$$lang/LC_MESSAGES; \
+         $(mkinstalldirs) $(DESTDIR)$$dir; \
+         if test -r $$cat; then realcat=$$cat; else realcat=$(srcdir)/$$cat; fi; \
+         $(INSTALL_DATA) $$realcat $(DESTDIR)$$dir/$(DOMAIN).mo; \
+         echo "installing $$realcat as $(DESTDIR)$$dir/$(DOMAIN).mo"; \
+         for lc in '' $(EXTRA_LOCALE_CATEGORIES); do \
+           if test -n "$$lc"; then \
+             if (cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc 2>/dev/null) | grep ' -> ' >/dev/null; then \
+               link=`cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc | sed -e 's/^.* -> //'`; \
+               mv $(DESTDIR)$(localedir)/$$lang/$$lc $(DESTDIR)$(localedir)/$$lang/$$lc.old; \
+               mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \
+               (cd $(DESTDIR)$(localedir)/$$lang/$$lc.old && \
+                for file in *; do \
+                  if test -f $$file; then \
+                    ln -s ../$$link/$$file $(DESTDIR)$(localedir)/$$lang/$$lc/$$file; \
+                  fi; \
+                done); \
+               rm -f $(DESTDIR)$(localedir)/$$lang/$$lc.old; \
+             else \
+               if test -d $(DESTDIR)$(localedir)/$$lang/$$lc; then \
+                 :; \
+               else \
+                 rm -f $(DESTDIR)$(localedir)/$$lang/$$lc; \
+                 mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \
+               fi; \
+             fi; \
+             rm -f $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \
+             ln -s ../LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo 2>/dev/null || \
+             ln $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo 2>/dev/null || \
+             cp -p $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \
+             echo "installing $$realcat link as $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo"; \
+           fi; \
+         done; \
+       done
+
+install-strip: install
+
+installdirs: installdirs-exec installdirs-data
+installdirs-exec:
+installdirs-data: installdirs-data-@USE_NLS@
+       if test "$(PACKAGE)" = "gettext-tools"; then \
+         $(mkinstalldirs) $(DESTDIR)$(gettextsrcdir); \
+       else \
+         : ; \
+       fi
+installdirs-data-no:
+installdirs-data-yes:
+       $(mkinstalldirs) $(DESTDIR)$(datadir)
+       @catalogs='$(CATALOGS)'; \
+       for cat in $$catalogs; do \
+         cat=`basename $$cat`; \
+         lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \
+         dir=$(localedir)/$$lang/LC_MESSAGES; \
+         $(mkinstalldirs) $(DESTDIR)$$dir; \
+         for lc in '' $(EXTRA_LOCALE_CATEGORIES); do \
+           if test -n "$$lc"; then \
+             if (cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc 2>/dev/null) | grep ' -> ' >/dev/null; then \
+               link=`cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc | sed -e 's/^.* -> //'`; \
+               mv $(DESTDIR)$(localedir)/$$lang/$$lc $(DESTDIR)$(localedir)/$$lang/$$lc.old; \
+               mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \
+               (cd $(DESTDIR)$(localedir)/$$lang/$$lc.old && \
+                for file in *; do \
+                  if test -f $$file; then \
+                    ln -s ../$$link/$$file $(DESTDIR)$(localedir)/$$lang/$$lc/$$file; \
+                  fi; \
+                done); \
+               rm -f $(DESTDIR)$(localedir)/$$lang/$$lc.old; \
+             else \
+               if test -d $(DESTDIR)$(localedir)/$$lang/$$lc; then \
+                 :; \
+               else \
+                 rm -f $(DESTDIR)$(localedir)/$$lang/$$lc; \
+                 mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \
+               fi; \
+             fi; \
+           fi; \
+         done; \
+       done
+
+# Define this as empty until I found a useful application.
+installcheck:
+
+uninstall: uninstall-exec uninstall-data
+uninstall-exec:
+uninstall-data: uninstall-data-@USE_NLS@
+       if test "$(PACKAGE)" = "gettext-tools"; then \
+         for file in $(DISTFILES.common) Makevars.template; do \
+           rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \
+         done; \
+       else \
+         : ; \
+       fi
+uninstall-data-no:
+uninstall-data-yes:
+       catalogs='$(CATALOGS)'; \
+       for cat in $$catalogs; do \
+         cat=`basename $$cat`; \
+         lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \
+         for lc in LC_MESSAGES $(EXTRA_LOCALE_CATEGORIES); do \
+           rm -f $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \
+         done; \
+       done
+
+check: all
+
+info dvi ps pdf html tags TAGS ctags CTAGS ID:
+
+mostlyclean:
+       rm -f remove-potcdate.sed
+       rm -f stamp-poT
+       rm -f core core.* $(DOMAIN).po $(DOMAIN).1po $(DOMAIN).2po *.new.po
+       rm -fr *.o
+
+clean: mostlyclean
+
+distclean: clean
+       rm -f Makefile Makefile.in POTFILES *.mo
+
+maintainer-clean: distclean
+       @echo "This command is intended for maintainers to use;"
+       @echo "it deletes files that may require special tools to rebuild."
+       rm -f stamp-po $(GMOFILES)
+
+distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
+dist distdir:
+       $(MAKE) update-po
+       @$(MAKE) dist2
+# This is a separate target because 'update-po' must be executed before.
+dist2: stamp-po $(DISTFILES)
+       dists="$(DISTFILES)"; \
+       if test "$(PACKAGE)" = "gettext-tools"; then \
+         dists="$$dists Makevars.template"; \
+       fi; \
+       if test -f $(srcdir)/$(DOMAIN).pot; then \
+         dists="$$dists $(DOMAIN).pot stamp-po"; \
+       fi; \
+       if test -f $(srcdir)/ChangeLog; then \
+         dists="$$dists ChangeLog"; \
+       fi; \
+       for i in 0 1 2 3 4 5 6 7 8 9; do \
+         if test -f $(srcdir)/ChangeLog.$$i; then \
+           dists="$$dists ChangeLog.$$i"; \
+         fi; \
+       done; \
+       if test -f $(srcdir)/LINGUAS; then dists="$$dists LINGUAS"; fi; \
+       for file in $$dists; do \
+         if test -f $$file; then \
+           cp -p $$file $(distdir) || exit 1; \
+         else \
+           cp -p $(srcdir)/$$file $(distdir) || exit 1; \
+         fi; \
+       done
+
+update-po: Makefile
+       $(MAKE) $(DOMAIN).pot-update
+       test -z "$(UPDATEPOFILES)" || $(MAKE) $(UPDATEPOFILES)
+       $(MAKE) update-gmo
+
+# General rule for creating PO files.
+
+.nop.po-create:
+       @lang=`echo $@ | sed -e 's/\.po-create$$//'`; \
+       echo "File $$lang.po does not exist. If you are a translator, you can create it through 'msginit'." 1>&2; \
+       exit 1
+
+# General rule for updating PO files.
+
+.nop.po-update:
+       @lang=`echo $@ | sed -e 's/\.po-update$$//'`; \
+       if test "$(PACKAGE)" = "gettext-tools"; then PATH=`pwd`/../src:$$PATH; fi; \
+       tmpdir=`pwd`; \
+       echo "$$lang:"; \
+       test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \
+       echo "$${cdcmd}$(MSGMERGE) $$lang.po $(DOMAIN).pot -o $$lang.new.po"; \
+       cd $(srcdir); \
+       if $(MSGMERGE) $$lang.po $(DOMAIN).pot -o $$tmpdir/$$lang.new.po; then \
+         if cmp $$lang.po $$tmpdir/$$lang.new.po >/dev/null 2>&1; then \
+           rm -f $$tmpdir/$$lang.new.po; \
+         else \
+           if mv -f $$tmpdir/$$lang.new.po $$lang.po; then \
+             :; \
+           else \
+             echo "msgmerge for $$lang.po failed: cannot move $$tmpdir/$$lang.new.po to $$lang.po" 1>&2; \
+             exit 1; \
+           fi; \
+         fi; \
+       else \
+         echo "msgmerge for $$lang.po failed!" 1>&2; \
+         rm -f $$tmpdir/$$lang.new.po; \
+       fi
+
+$(DUMMYPOFILES):
+
+update-gmo: Makefile $(GMOFILES)
+       @:
+
+Makefile: Makefile.in.in Makevars $(top_builddir)/config.status @POMAKEFILEDEPS@
+       cd $(top_builddir) \
+         && CONFIG_FILES=$(subdir)/$@.in CONFIG_HEADERS= \
+              $(SHELL) ./config.status
+
+force:
+
+# Tell versions [3.59,3.63) of GNU make not to export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/po/Makevars b/po/Makevars
new file mode 100644 (file)
index 0000000..a632324
--- /dev/null
@@ -0,0 +1,41 @@
+# Makefile variables for PO directory in any package using GNU gettext.
+
+# Usually the message domain is the same as the package name.
+DOMAIN = $(PACKAGE)
+
+# These two variables depend on the location of this directory.
+subdir = po
+top_builddir = ..
+
+# These options get passed to xgettext.
+XGETTEXT_OPTIONS = --keyword=_ --keyword=N_
+
+# This is the copyright holder that gets inserted into the header of the
+# $(DOMAIN).pot file.  Set this to the copyright holder of the surrounding
+# package.  (Note that the msgstr strings, extracted from the package's
+# sources, belong to the copyright holder of the package.)  Translators are
+# expected to transfer the copyright for their translations to this person
+# or entity, or to disclaim their copyright.  The empty string stands for
+# the public domain; in this case the translators are expected to disclaim
+# their copyright.
+COPYRIGHT_HOLDER = AIST
+
+# This is the email address or URL to which the translators shall report
+# bugs in the untranslated strings:
+# - Strings which are not entire sentences, see the maintainer guidelines
+#   in the GNU gettext documentation, section 'Preparing Strings'.
+# - Strings which use unclear terms or require additional context to be
+#   understood.
+# - Strings which make invalid assumptions about notation of date, time or
+#   money.
+# - Pluralisation problems.
+# - Incorrect English spelling.
+# - Incorrect formatting.
+# It can be your email address, or a mailing list address where translators
+# can write to without being subscribed, or the URL of a web page through
+# which the translators can contact you.
+MSGID_BUGS_ADDRESS = m17n-lib-bug@m17n.org
+
+# This is the list of locale categories, beyond LC_MESSAGES, for which the
+# message catalogs shall be used.  It is usually empty.
+EXTRA_LOCALE_CATEGORIES =
diff --git a/po/POTFILES.in b/po/POTFILES.in
new file mode 100644 (file)
index 0000000..3292571
--- /dev/null
@@ -0,0 +1,2 @@
+# List of source files which contain translatable strings.
+src/input.c
diff --git a/po/Rules-quot b/po/Rules-quot
new file mode 100644 (file)
index 0000000..9c2a995
--- /dev/null
@@ -0,0 +1,47 @@
+# Special Makefile rules for English message catalogs with quotation marks.
+
+DISTFILES.common.extra1 = quot.sed boldquot.sed en@quot.header en@boldquot.header insert-header.sin Rules-quot
+
+.SUFFIXES: .insert-header .po-update-en
+
+en@quot.po-create:
+       $(MAKE) en@quot.po-update
+en@boldquot.po-create:
+       $(MAKE) en@boldquot.po-update
+
+en@quot.po-update: en@quot.po-update-en
+en@boldquot.po-update: en@boldquot.po-update-en
+
+.insert-header.po-update-en:
+       @lang=`echo $@ | sed -e 's/\.po-update-en$$//'`; \
+       if test "$(PACKAGE)" = "gettext"; then PATH=`pwd`/../src:$$PATH; GETTEXTLIBDIR=`cd $(top_srcdir)/src && pwd`; export GETTEXTLIBDIR; fi; \
+       tmpdir=`pwd`; \
+       echo "$$lang:"; \
+       ll=`echo $$lang | sed -e 's/@.*//'`; \
+       LC_ALL=C; export LC_ALL; \
+       cd $(srcdir); \
+       if $(MSGINIT) -i $(DOMAIN).pot --no-translator -l $$ll -o - 2>/dev/null | sed -f $$tmpdir/$$lang.insert-header | $(MSGCONV) -t UTF-8 | $(MSGFILTER) sed -f `echo $$lang | sed -e 's/.*@//'`.sed 2>/dev/null > $$tmpdir/$$lang.new.po; then \
+         if cmp $$lang.po $$tmpdir/$$lang.new.po >/dev/null 2>&1; then \
+           rm -f $$tmpdir/$$lang.new.po; \
+         else \
+           if mv -f $$tmpdir/$$lang.new.po $$lang.po; then \
+             :; \
+           else \
+             echo "creation of $$lang.po failed: cannot move $$tmpdir/$$lang.new.po to $$lang.po" 1>&2; \
+             exit 1; \
+           fi; \
+         fi; \
+       else \
+         echo "creation of $$lang.po failed!" 1>&2; \
+         rm -f $$tmpdir/$$lang.new.po; \
+       fi
+
+en@quot.insert-header: insert-header.sin
+       sed -e '/^#/d' -e 's/HEADER/en@quot.header/g' $(srcdir)/insert-header.sin > en@quot.insert-header
+
+en@boldquot.insert-header: insert-header.sin
+       sed -e '/^#/d' -e 's/HEADER/en@boldquot.header/g' $(srcdir)/insert-header.sin > en@boldquot.insert-header
+
+mostlyclean: mostlyclean-quot
+mostlyclean-quot:
+       rm -f *.insert-header
diff --git a/po/boldquot.sed b/po/boldquot.sed
new file mode 100644 (file)
index 0000000..4b937aa
--- /dev/null
@@ -0,0 +1,10 @@
+s/"\([^"]*\)"/“\1”/g
+s/`\([^`']*\)'/‘\1’/g
+s/ '\([^`']*\)' / ‘\1’ /g
+s/ '\([^`']*\)'$/ ‘\1’/g
+s/^'\([^`']*\)' /‘\1’ /g
+s/“”/""/g
+s/“/“\e[1m/g
+s/”/\e[0m”/g
+s/‘/‘\e[1m/g
+s/’/\e[0m’/g
diff --git a/po/en@boldquot.header b/po/en@boldquot.header
new file mode 100644 (file)
index 0000000..fedb6a0
--- /dev/null
@@ -0,0 +1,25 @@
+# All this catalog "translates" are quotation characters.
+# The msgids must be ASCII and therefore cannot contain real quotation
+# characters, only substitutes like grave accent (0x60), apostrophe (0x27)
+# and double quote (0x22). These substitutes look strange; see
+# http://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html
+#
+# This catalog translates grave accent (0x60) and apostrophe (0x27) to
+# left single quotation mark (U+2018) and right single quotation mark (U+2019).
+# It also translates pairs of apostrophe (0x27) to
+# left single quotation mark (U+2018) and right single quotation mark (U+2019)
+# and pairs of quotation mark (0x22) to
+# left double quotation mark (U+201C) and right double quotation mark (U+201D).
+#
+# When output to an UTF-8 terminal, the quotation characters appear perfectly.
+# When output to an ISO-8859-1 terminal, the single quotation marks are
+# transliterated to apostrophes (by iconv in glibc 2.2 or newer) or to
+# grave/acute accent (by libiconv), and the double quotation marks are
+# transliterated to 0x22.
+# When output to an ASCII terminal, the single quotation marks are
+# transliterated to apostrophes, and the double quotation marks are
+# transliterated to 0x22.
+#
+# This catalog furthermore displays the text between the quotation marks in
+# bold face, assuming the VT100/XTerm escape sequences.
+#
diff --git a/po/en@quot.header b/po/en@quot.header
new file mode 100644 (file)
index 0000000..a9647fc
--- /dev/null
@@ -0,0 +1,22 @@
+# All this catalog "translates" are quotation characters.
+# The msgids must be ASCII and therefore cannot contain real quotation
+# characters, only substitutes like grave accent (0x60), apostrophe (0x27)
+# and double quote (0x22). These substitutes look strange; see
+# http://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html
+#
+# This catalog translates grave accent (0x60) and apostrophe (0x27) to
+# left single quotation mark (U+2018) and right single quotation mark (U+2019).
+# It also translates pairs of apostrophe (0x27) to
+# left single quotation mark (U+2018) and right single quotation mark (U+2019)
+# and pairs of quotation mark (0x22) to
+# left double quotation mark (U+201C) and right double quotation mark (U+201D).
+#
+# When output to an UTF-8 terminal, the quotation characters appear perfectly.
+# When output to an ISO-8859-1 terminal, the single quotation marks are
+# transliterated to apostrophes (by iconv in glibc 2.2 or newer) or to
+# grave/acute accent (by libiconv), and the double quotation marks are
+# transliterated to 0x22.
+# When output to an ASCII terminal, the single quotation marks are
+# transliterated to apostrophes, and the double quotation marks are
+# transliterated to 0x22.
+#
diff --git a/po/insert-header.sin b/po/insert-header.sin
new file mode 100644 (file)
index 0000000..b26de01
--- /dev/null
@@ -0,0 +1,23 @@
+# Sed script that inserts the file called HEADER before the header entry.
+#
+# At each occurrence of a line starting with "msgid ", we execute the following
+# commands. At the first occurrence, insert the file. At the following
+# occurrences, do nothing. The distinction between the first and the following
+# occurrences is achieved by looking at the hold space.
+/^msgid /{
+x
+# Test if the hold space is empty.
+s/m/m/
+ta
+# Yes it was empty. First occurrence. Read the file.
+r HEADER
+# Output the file's contents by reading the next line. But don't lose the
+# current line while doing this.
+g
+N
+bb
+:a
+# The hold space was nonempty. Following occurrences. Do nothing.
+x
+:b
+}
diff --git a/po/quot.sed b/po/quot.sed
new file mode 100644 (file)
index 0000000..0122c46
--- /dev/null
@@ -0,0 +1,6 @@
+s/"\([^"]*\)"/“\1”/g
+s/`\([^`']*\)'/‘\1’/g
+s/ '\([^`']*\)' / ‘\1’ /g
+s/ '\([^`']*\)'$/ ‘\1’/g
+s/^'\([^`']*\)' /‘\1’ /g
+s/“”/""/g
diff --git a/po/remove-potcdate.sin b/po/remove-potcdate.sin
new file mode 100644 (file)
index 0000000..2436c49
--- /dev/null
@@ -0,0 +1,19 @@
+# Sed script that remove the POT-Creation-Date line in the header entry
+# from a POT file.
+#
+# The distinction between the first and the following occurrences of the
+# pattern is achieved by looking at the hold space.
+/^"POT-Creation-Date: .*"$/{
+x
+# Test if the hold space is empty.
+s/P/P/
+ta
+# Yes it was empty. First occurrence. Remove the line.
+g
+d
+bb
+:a
+# The hold space was nonempty. Following occurrences. Do nothing.
+x
+:b
+}
diff --git a/src/ChangeLog b/src/ChangeLog
new file mode 100644 (file)
index 0000000..2b502b8
--- /dev/null
@@ -0,0 +1,4888 @@
+2010-04-23  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.6.1 released.
+
+2010-04-23  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (enum GlyphInfoMask): Shift upper masks 1-bit left.
+       (decode_packed_otf_tag): If a glyph has combining information,
+       don't touch it.
+
+2010-04-23  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (ft_drive_otf): Reset 28th bit of g->g.internal for
+       storing OTF feature tag.
+
+2010-04-19  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (run_stages): Update category code of glyphs if
+       category table is changed.
+
+2010-04-05  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (ft_check_cap_otf): Fix conditions to call
+       OTF_check_features.
+
+       * database.c (check_version): Fix previous change.
+
+2010-04-02  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.h (M17NLIB_MINOR_VERSION): Changed to 6.
+       (M17NLIB_PATCH_LEVEL): Changed to 1.
+       (M17NLIB_VERSION_NAME): 1.6.1.
+
+2010-03-30  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.6.0 released.
+
+2010-03-01  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (run_rule): Fix checking of glyph availability.
+
+2010-02-18  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.c (register_device_library): Preprend M17N_MODULE_DIR
+       to the module file name.
+
+       * input.c (load_external_module): Preprend M17N_MODULE_DIR to the
+       module file name.
+
+       * charset.c (load_charset): Check the return value of fgets.
+
+       * Makefile.am: Build modules dynamically loaded with
+       -avoid-version and no -version-info.
+
+2010-01-15  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (run_flt): Set mflt_try_otf to rfont->driver->try_otf.
+       (mdraw__init): Set mflt_enable_new_feature to 1.
+
+       * font-ft.c (ft_try_otf): New function.
+       (mfont__ft_driver): Set ft_try_otf.
+
+       * font.h (struct MFontDriver): New member try_otf.
+
+       * m17n-X.c (xft_driver): Set xft_try_otf.
+       (xft_try_otf): New function.
+
+       * m17n-flt.h: (mflt_enable_new_feature): Extern it.
+       (mflt_try_otf): Extern it.
+
+       * m17n-flt.c (load_category_table): If mflt_enable_new_feature is
+       zero, return NULL for such categories that require the new
+       feature.
+       (parse_otf_command): If mflt_enable_new_feature is zero, return
+       -1.
+       (load_otf_command): Fix previous change.
+       (load_flt): Check the return value of load_category_table.
+       (try_otf): Renamed from run_otf_category.  Call mflt_try_otf
+       instead of font->drive_otf.
+       (run_command): Call try_otf instead of run_otf_category.
+       (m17n_init_flt): Initialize mflt_enable_new_feature to 0,
+       mflt_try_otf to NULL.
+       (mflt_enable_new_feature): New variable.
+       (mflt_try_otf): New variable.
+
+2009-12-10  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (parse_otf_command): Handle ":otf?".
+       (run_otf_category): If not features are specified, reset category
+       codes.
+       (run_command): On copy, don't re-calculate a category code.
+
+2009-12-03  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (run_stages): Reset category code if category-table
+       is changed.
+       (mflt_run): Don't set category code here.
+       (decode_packed_otf_tag): If no feature is applied, re-calculate
+       category code.
+
+2009-12-02  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (mflt_find): If FONT is specified but no flt is
+       found, return NULL.
+       (run_command): Don't set ENCODED and MEASURED of separator.
+
+2009-11-30  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (load_otf_command): Check 4th char against '?'.
+       (load_command): Likewise.
+       (decode_packed_otf_tag): New arg CTX.  If CTX->in == gstring,
+       update CTX->encoded.  Caller changed.
+
+2009-11-30  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (ft_drive_otf): Check if OUT is null or not.
+       (ft_drive_otf): Call OTF_drive_gsub_with_log and
+       OTF_drive_gpos_with_log.  Record the applied feature in
+       g->g.internal.
+
+       * font.c (mfont__get_glyph_id): Encode g->c instead of g->code.
+
+       * internal-flt.h (MAKE_COMBINING_CODE_BY_CLASS)
+       (COMBINING_BY_CLASS_P, COMBINING_CODE_CLASS)
+       (MAKE_PRECOMPUTED_COMBINDING_CODE, COMBINING_PRECOMPUTED_P):
+       Delete externs..
+       (PACK_OTF_TAG): Extern it.
+
+       * draw.c (reorder_combining_chars): Delete it.
+
+       * m17n-flt.h (mflt_font_id): Use type MFLFont.
+       (mflt_iterate_otf_feature): Likewise.
+
+       * m17n-flt.c (enum GlyphInfoMask): New member CategoryCodeMask and
+       CombinedMask.
+       (GET_CATEGORY_CODE, SET_CATEGORY_CODE, GET_COMBINED): New macros.
+       (SET_COMBINING_CODE): Set also CombinedMask.
+       (FontLayoutFeatureTable): Delete it.
+       (FeatureCodeTable): New type.
+       (FontLayoutCategory): Type of feature_table changed.
+       (load_category_table): Adjusted for the change of
+       FontLayoutCategory.
+       (unref_category_table): Likewise.
+       (gen_otf_tag): New member shift.  Caller changed.
+       (FontLayoutContext): New member category.
+       (run_rule): Compare g->c instead of g->code.
+       (decode_packed_otf_tag): New function.
+       (run_otf): Call decode_packed_otf_tag.  Don't reset combining-code
+       here.
+       (run_otf_category): New function.
+       (run_command): Set category-code if necessary.  Call
+       run_otf_category for FontLayoutCmdTypeOTFCategory.
+       (run_stages): Set ctx->category.  Get category from glyph if
+       possible.
+       (mflt_dump_gstring): New function.
+
+2009-11-26  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (enum FontLayoutCmdType): New member
+       FontLayoutCmdTypeOTFCategory.
+       (FontLayoutFeatureTable): New type.
+       (FontLayoutCategory): New members feature_table_size and
+       feature_table.
+       (load_category_table): Handle feature_table.
+       (unref_category_table): Likewise.
+       (load_otf_command): Handle FontLayoutCmdTypeOTFCategory.
+       (load_command): Likewise.
+       (free_flt_command): Likewise.
+
+2009-11-10  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (run_flt): Update category code of each glyph.
+
+2009-11-07  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (ft_drive_otf): Don't accumulate anchor adjustments.
+
+2009-11-05  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (run_otf): Fix updating of g->lbearing, etc.
+
+       * font-ft.c (ft_drive_otf): Use OTF_drive_gpos2 if possible.
+
+2009-10-28  Kenichi Handa  <handa@m17n.org>
+
+       * fontset.c (mdebug_flag): New variable.
+       (mfont__lookup_fontset): Print debug info.
+
+       * m17n-core.c (m17n_init_core): Call SET_DEBUG_FLAG for
+       MDEBUG_FONTSET.
+
+       * internal.h (enum MDebugFlag): Add MDEBUG_FONTSET.
+
+       * language.c (mscript__from_otf_tag): Adjusted for the new format
+       of the database <standard script unicode>.
+
+2009-10-22  Kenichi Handa  <handa@m17n.org>
+
+       * database.c (check_version): Fix the check.
+
+       * input.c (surrounding_pos): New arg *pos.
+       (integer_value): Fix handling of "@+0".
+       (take_action_list): Adjusted for the change of surrounding_pos.
+
+2009-10-05  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.h: (mflt_iterate_otf_feature, mflt_font_id): Extern
+       them.
+
+       * m17n-flt.c (FontLayoutCategory): New typedef.
+       (FontLayoutStage): Type of the member `category' changed.
+       (struct _MFLT): Type of the member `coverage' changed.  New member
+       need_config and font_id.
+       (apply_otf_feature): New function.
+       (load_category_table): New arg FONT.  If FONT is non-NULL, call
+       apply_otf_feature.  Setup category->definition.
+       (ref_category_table): New macro.
+       (unref_category_table): New function.
+       (load_flt): Adjusted for the type change of category.
+       (free_flt_stage): New arg FLT.
+       (list_flt): Adjusted for the type change of category.
+       (run_stages): Adjusted for the type change of category.
+       (configure_category, configure_flt): New function.
+       (m17n_init_flt): Initialize mflt_iterate_otf_feature and
+       mflt_font_id to NULL.
+       (mflt_get): Skip the heading configured FLTs.
+       (mflt_find): Likewise.  If necessary, configure the found flt.
+       (mflt_run): Handle mflt_iterate_otf_feature and mflt_font_id.
+       Adjusted for the type change of category.
+       (mflt_iterate_otf_feature, mflt_font_id): New variable.
+
+       * m17n-X.c (xfont_open): Set rfont->id.
+       (xft_driver): Set xft_iterate_otf_feature.
+       (xft_open): Set rfont->id.
+       (xft_iterate_otf_feature): New function.
+
+       * font.h (struct MRealizedFont): New member id.
+       (struct MFontDriver): New member iterate_otf_feature.
+
+       * font.c (mfont__get_glyph_id): Pay attention to. mfont->source.
+
+       * font-ft.c (ft_open, ft_encapsulate): Set rfont->id.
+       (get_otf): New funcition.
+       (ft_check_otf, ft_drive_otf): Use get_otf.
+       (iterate_callback, ft_iterate_otf_feature): New functions.
+       (mfont__ft_driver): Set ft_iterate_otf_feature.
+
+       * draw.c: Docstring updated.
+       (font_id): New function.
+       (run_flt): Set mflt_font_id and mflt_iterate_otf_feature before
+       calling mflt_run.
+
+2009-10-02  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (load_flt): Check the return value of
+       load_category_table.
+
+2009-09-03  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (run_otf): Clear combining code for glyphs whose
+       positions are adjusted by GPOS table.
+
+2009-08-13  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.5.5 released.
+
+2009-08-13  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.h (M17NLIB_PATCH_LEVEL):  Changed to 5.
+       (M17NLIB_VERSION_NAME): Changed to "1.5.5".
+
+2009-03-03  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (compose_glyph_string): Check if category not Mnil.
+
+2009-03-02  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.5.4 released.
+
+2009-02-25  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.c (report_object_array): For M-text and Plist, print
+       more information.
+
+       * m17n-core.h (M17NLIB_PATCH_LEVEL): Changed to 4.
+       (M17NLIB_VERSION_NAME): Changed to "1.5.4".
+
+       * input.c (get_candidate_list): Free unnecessary objects.
+       (take_action_list): Free plist.
+
+2009-02-04  Kenichi Handa  <handa@m17n.org>
+
+       * coding.c (mcoding__init): Add "Shift_JIS" as an alias of "sjis".
+
+2009-01-16  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.h (Mcased, Msoft_dotted, Mcase_mapping, Mblock):
+       Extern them.
+
+       * character.c (Mcased, Msoft_dotted, Mcase_mapping, Mblock): New
+       variables.
+
+2009-01-14  Kenichi Handa  <handa@m17n.org>
+
+       * coding.c (decode_coding_iso_2022): Check invocation status
+       before updating charset0 and charset1.
+
+       * symbol.c (msymbol__canonicalize): Handle "windows-XXXX".
+
+2008-12-31  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (mflt_run): If g->encoded is set, don't clear
+       g->code.
+
+2008-10-30  Andreas Schwab <schwab@suse.de>  (tiny change)
+
+       * face.c (mface_get_prop): Fix strict aliasing bug.
+       (mface_put_prop): Likewise.
+
+       * m17n-gui.c (mframe): Fix strict aliasing bug.
+
+2008-10-20  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.5.3 released.
+
+2008-10-06  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (mdraw__init): Use TRUE only when
+       FRIBIDI_INTERFACE_VERSION is less than 3.
+
+2008-10-03  Kenichi Handa  <handa@m17n.org>
+
+       * database.c (mdatabase__find_file): Return a copy of filename if
+       it is absolute pathname.
+
+2008-09-25  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (load_macros): Don't parse the action list here.
+       (load_im_info): Parse action lists of all macros.
+
+2008-09-24  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (mflt_find): Setup coverage of "combining" flt.
+
+2008-09-19  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (fully_initialize): Rename "@reload" to "-reload".
+
+2008-09-17  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (run_stages): Fix combining with a variable width
+       font.
+
+2008-08-04  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (fully_initialize): Add more aliaese (e.g. C-M-1
+       vs. C-A-1).
+
+2008-07-22  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (fully_initialize): Fix previous change.
+
+2008-07-19  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (fully_initialize): Fix previous change.
+
+2008-07-14  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (ft_list_family): New arg CHECK_ALIAS.  Callers changed.
+
+2008-07-14  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (fully_initialize): Handle C-M-1, etc.
+
+2008-07-11  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (minput_open_im): Check if the arg NAME is not Mnil.
+
+2008-06-23  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.5.2 released.
+
+2008-06-23  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.h (M17NLIB_MINOR_VERSION): Changed to 5.
+       (M17NLIB_PATCH_LEVEL): Changed to 2.
+       (M17NLIB_VERSION_NAME): Changed "1.5.2".
+
+2008-06-13  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (minput_config_file): Comment fixed for man-page.
+
+2008-06-13  Harshula  <harshula@gmail.com>  (tiny change)
+
+       * Makefile.am (libm17n_gd_la_LIBADD): Add @FREETYPE_LD_FLAGS@.
+
+2008-05-24  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (mdebug_dump_flt): Change return value to (MFLT *).
+
+2008-05-23  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (libm17n_gui_la_LIBADD): Include libm17n-core.la.
+       (libm17n_X_la_LIBADD): Include libm17n-core.la, libm17n.la, and
+       libm17n-flt.la.
+       (libm17n_gd_la_LIBADD): Likewise.
+
+       * input.c (take_action_list): Fix debug info.
+
+2008-05-14  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (run_rule): Check SRC_REGEX at first.
+       (run_stages): Fix index of g_indices.
+
+2008-04-03  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (compose_glyph_string): Don't run flt striding over the
+       cursor position.
+       (get_gstring): Don't use the cached gstring if cursor position is
+       changed.
+
+2008-04-02  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (integer_value): Delete the 3rd arg VALUE.
+       (resolve_expression): Adjust the call of integer_value.
+       (take_action_list): Likewise.
+
+2008-03-06  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (ft_drive_otf): Don't ignore the otf-spec to apply all
+       features.
+
+2008-01-31  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * Version 1.5.1 released.
+
+2008-01-31  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * draw.c (mdraw_glyph_list): Refer to mfont__ft_driver only when
+       HAVE_FREETYPE is defined.
+
+       * font.h (OTF_Tag): Be sure that it is defined in any cases.
+
+2008-01-30  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * font.h (enum MFontOpenTypeTable, MFontCapability): Define them
+       unconditionally.
+
+2008-01-25  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * input.c (parse_action_list): Handle the case "(insert INTEGER)".
+
+2008-01-25  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * input.c (parse_action_list): Check M_candidates.
+       (get_im_info): If key is Mnil, be sure to set im_info->states to a
+       plist.
+
+2008-01-23  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * input.c (integer_value): Fix interpretation of "@-N".
+
+2008-01-17  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * input.c (get_following_char): Fix interpretation of POS.
+       (get_following_char): Fix interpretation of "@+N".
+
+2008-01-15  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * font-ft.c (ft_drive_otf): Don't refer to otf_gstring if HAVE_OTF
+       is not defined.
+
+       * Makefile.am (FLT_SOURCES): Include internal-flt.h.
+
+2008-01-07  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * m17n-flt.c (UPDATE_CLUSTER_RANGE): Don't check if clustering
+       now.
+       (run_rule): Call UPDATE_CLUSTER_RANGE when necessary.
+       (run_command): Check if clustering now before calling
+       UPDATE_CLUSTER_RANGE.
+
+2008-01-06  Kenichi Handa  <handa@m17n.org>
+
+       * font.c (mfont__get_glyph_id): Return -1 if some code is invalid.
+
+       * font-ft.c (ft_drive_otf): Fix checking of negative feature.
+
+       * m17n-X.c (xft_find_metric): Set g->g.measured.
+
+       * m17n-flt.c (Mequal): New variable.
+       (m17n_init_flt): Initialize it.
+       (FontLayoutCmdRule): Merge members supported_glyph and otf_spec
+       into a new member facility.
+       (load_command): Modify parsing of Mfont_facility.
+       (run_rule): Adjuted for the change of FontLayoutCmdRule.
+       (run_otf): Adjusted metrics if a->back is nonzero.
+
+2007-12-28  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * Version 1.5.0 released.
+
+2007-12-13  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * m17n-core.c (m17n_init_core): Handle the lang. env. MDEBUG_FLT.
+
+       * m17n-flt.c (mdebug_flag): Set to MDEBUG_FLT.
+       (run_rule): Check if a font has the specific glyph correctly.
+
+       * internal.h (enum MDebugFlag): Delete MDEBUG_FONT_OTF, change
+       MDEBUG_FONT_FLT to MDEBUG_FLT.
+
+       * font.c (mfont__get_glyph_id): Encode g->g.code (not g->g.c).
+
+       * font-flt.c: Delete it.
+
+2007-12-08  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * m17n-flt.c (run_rule): Fix printing of debug info.  Don't update
+       TO for the rule of SRC_HAS_GLYPH.
+
+       * draw.c (run_flt): Argument changed.
+       (compose_glyph_string): Adjusted for the above change.
+
+2007-12-07  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * plist.c (read_mtext_element): Don't free the malloced buffer.
+
+2007-12-04  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * m17n-core.h (merror_code): Extern it.
+
+       * m17n-misc.h (merror_code): Don't extern it.
+
+       * m17n.h: Handle the case of _M17N_FLT_H_ being defined.
+
+       * m17n-flt.h: Handle the case of _M17N_H_ being defined.
+
+2007-11-22  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * draw.c (compose_glyph_string): Check g->rface->layouter, not
+       g->rface->rfont->layouter.
+
+       * font-ft.c (ft_drive_otf): Fix setting of g->g.from and g->g.to.
+
+       * m17n-flt.c (FontLayoutContext): New member encoded_offset.
+       (run_rule): Use ctx->encoded_offset.
+       (run_command): Likewise.
+       (run_stages): Set ctx->encoded_offset.
+
+2007-11-21  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * m17n-flt.c (enum GlyphInfoMask): Adjusted for the change of
+       bit-size of MFLTGlyph->internal.
+
+2007-11-20  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * draw.c (visual_order): Exclude the last anchor glyph from the
+       iteration.
+
+       * m17n-flt.h (MFLTGlyph): New member <adjusted>.
+
+       * m17n-flt.c (run_otf): Set adjusted flag of glyphs if necessary.
+       (run_stages): Likewise.
+       (load_flt): Unref top after checking plist.
+
+       * m17n-X.c (xft_render): Check adjusted flag of glyphs.
+
+2007-11-12  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * font-ft.c (ft_check_otf): Fix arg to OTF_check_features.
+
+       * m17n-flt.c (Mcombining): New variable.
+       (Mfont_facility): Renamed from Mfont_has.  Referrer changed.
+       (enum FontLayoutCmdRuleSrcType): Delete SRC_EXIST, add
+       SRC_HAS_GLYPH and SRC_OTF_SPEC.
+       (FontLayoutCmdRule): Delete src.exist, add src.supported_glyph and
+       src.otf_spec.
+       (load_command): Adjusted for the above changes.
+       (run_rule): Likewise.
+       (combining_code_from_class): Delete it.
+       (mflt_get): Check flt->name against Mcombining, not Mt.
+
+       * internal-flt.h (Mcombining): Extern it.
+
+       * draw.c (compose_glyph_string): Call run_flt with Mcombining for
+       combining characters.
+
+2007-11-09  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * face.c (mface__realize): Reset measured flag before calling
+       mfont__get_metric.
+
+       * m17n-flt.c (run_stages): Fix handing of off_x and off_y.
+       (setup_combining_coverage): New function.
+       (setup_combining_flt): New function.
+       (mflt_get): If flt is not found, return NULL.  If name if Mt,
+       call setup_combining_flt.
+       (mflt_run): For debugging, print font family name.
+
+       * font-ft.c (ft_render): Fix handling of baseline_offset.
+       (ft_encapsulate): Set metrics in 26.6 fixed pixel.
+       (ft_render): Check pixel_mode to determine anti_alias.
+
+       * m17n-X.c (xfont_find_metric): Delete invalid "continue" line.
+       (xfont_find_metric): Set metrics in 26.6 fixed pixel.
+       (xfont_render): Set baseline_offset in pixel.
+       (xft_render): Fix handling of baseline_offset.
+
+       * draw.c (run_flt): Set font.font.family.
+       (compose_glyph_string): Fix handling of combining characters.
+
+       * fontset.c (try_font_list): Check if the named flt is surely
+       available.
+
+2007-11-07  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * draw.c (analyse_bidi_level): New function.
+       (visual_order): Do reordering using the already decided
+       bidi-level.
+       (compose_glyph_string): Decide bidi-level before calling flt.
+
+       * m17n-flt.c (mflt_run): Fix typo.
+
+       * font-ft.c (ft_drive_otf): Fix indexing gstring->glyphs.
+
+2007-11-06  Kenichi Handa  <handa@ni.aist.go.jp>
+
+       * draw.c (visual_order): Don't rely on the width of glyphs.
+       (run_flt): Fix culculation of g->g.to.
+
+       * m17n-flt.c (run_rule): Don't set error code here.
+       (run_cond): Likewise.
+       (run_otf): Fix culculation of xoff and yoff.
+       (run_command): Don't set error code here.
+       (PREV): New macro.
+       (NEXT): New macro.
+
+       * m17n-X.c (xfont_open): Keep rfont's metrics in 26.6 fixed pixels.
+       (xfont_find_metric): Set glyph's yadv to 0.
+       (xft_find_metric): Likewise.
+
+       * font-ft.c (ft_open): Keep rfont's metrics in 26.6 fixed pixels.
+       (ft_find_metric): Adjust glyph's metrics.
+       (ft_encapsulate): Keep rfont's metrics in 26.6 fixed pixels.
+       (ft_drive_otf): Set mark glyph's xadv to 0.
+
+       * face.c (mface__for_chars): Adjusts the unit of face's ascent and
+       descent.
+
+2007-10-29  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.h (struct _MFLTOtfSpec): Adjusted for the new FLT handling.
+       (mflt_get): Adjusted for the argument change.
+       (mflt_name): Adjusted for the return value change.
+
+       * m17n-flt.c (Mgenerator, Mend): New variables.
+       (flt_min_coverage, flt_max_coverage): New variables.
+       (GCPY): New macro.
+       (GDUP): Use it.
+       (Mfont_has): Renamed from Mexist.  Referrers chagned.
+       (gen_otf_tag): Handle the trailing whitespaces.
+       (otf_count_features, otf_store_features): Fix for negative features.
+       (parse_otf_command): Adjusted for the change of MFLTOtfSpec.
+       (load_otf_command): Likewise.
+       (free_flt_command): Adjusted for the change of MFLTOtfSpec.
+       (load_flt): Argument changed.  Caller changed.
+       (free_flt_list): New function.
+       (run_rule): Adjusted for the change of FontLayoutContext.
+       (mflt_run): Adjusted for the change of FontLayoutContext.
+
+       * m17n-gui.c (m17n_init_win): Call m17n_init_flt.
+       (m17n_fini_win): Call m17n_fini_flt.
+
+       * m17n-gui.h: Include m17n-flt.h.
+
+       * m17n-gd.c: Adusted for the change of MGlyph.
+
+       * m17n-X.c: Adusted for the change of MGlyph.
+       (xft_check_otf, xft_drive_otf): New functions.
+
+       * internal-gui.h (MGlyph): Modified for new FLT handling.
+
+       * fontset.c (try_font_list): Adusted for the change of MGlyph.
+
+       * font-ft.c: Adjusted for the change of MGlyph.
+       (ft_check_cap_otf): Renamed from ft_check_otf.  Callers changed.
+       (get_glyph_metric): Deleted.
+       (ft_check_otf): New function.
+       (ft_drive_otf): New fucntion.
+
+       * font.c: Adjusted for the change of MGlyph.
+       (mfont__init): Don't call mfont__flt_init.
+       (mfont__fini): Don't call mfont__flt_fini.
+       (mfont__get_glyph_id, mfont__get_metrics): New functions.
+
+       * font.h (struct MRealizedFont): New members x_ppem and y_ppem.
+       (MFLTFontForRealized): New struct.
+       (struct MFontDriver): New members check_otf and drive_otf.
+       (mfont__get_glyph_id, mfont__get_metrics): Extern them.
+
+       * face.c: Adjusted for the change of MGlyph.
+
+       * draw.c: Adjusted for the change of MGlyph.
+
+       * m17n.c (m17n_init): Don't call mchar_init.
+
+       * m17n-core.c (m17n_init_core): Call mchar_init.
+
+       * m17n-core.h (mchartable_min_char, mchartable_max_char): Extern them.
+
+       * input.c: Include "m17n.h" instead of "m17n-gui.h".
+
+       * chartab.c (mchartable): Initialize table->min_char to -1.
+       (mchartable_min_char): New function.
+       (mchartable_max_char): New function.
+
+       * Makefile.am (GUI_SOURCES): Delete font-flt.c.
+       (libm17n_gui_la_LIBADD): Add ${top_builddir}/src/libm17n-flt.la.
+
+2007-10-12  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.h (Mcharset): Extern it.
+       Move detabase related declarations from m17n.h.
+
+       * m17n-flt.h: Include m17n-core.h instead of m17n.h.
+       (struct _MFLTOtfFeatures): New struct.
+       (struct _MFLTOtfSpec): Delete gsub, gpos, etc, add gsub_gpos.
+       (struct _MFLTFont): Delete otf, add check_otf.
+       (MCHAR_INVALID_CODE): Define it.
+
+       * plist.c (read_mtext_element): Simplify the code.
+
+       * m17n.h: Move database related declarations to m17n-core.h
+       (Mharset): Don't extern it.
+
+       * m17n.c (m17n_init): Don't call mdatabase__init.
+
+       * m17n-gd.c (read_rgb_txt): Check also /etc/X11/rgb.txt.  Downcase
+       color names.
+
+       * m17n-flt.c: Include m17n-core.h instead of m17n.h.
+       (Mexist): New variable.
+       (enum FontLayoutCmdRuleSrcType): New enum SRC_EXIST.
+       (FontLayoutCmdRule): New member src.exist.
+       (parse_otf_command): Handle gsub_count and gpos_count separately.
+       (load_otf_command): Adjusted for the change of MFLTOtfSpec.
+       (load_command): Handle the command "exist".
+       (free_flt_command): Adjusted for the change of MFLTOtfSpec.
+       (run_rule): Handle the case SRC_EXIST.
+       (run_otf): Adjusted for the change of MFLTOtfSpec.
+       (run_command): Check the range of FROM.
+       (check_otf_spec): Delete it.
+       (m17n_init_flt): Call m17n_init_core instead of m17n_init.
+       Initialize Mexist.
+       (m17n_fini_flt): Call m17n_fini_core instead of m17n_fiini.
+       (mflt_find): Call font->check_otf instead of check_otf_spec.
+       (mflt_run): Keep the metrics in 26.6 fixed point.
+
+       * m17n-core.c (mdatabase__finder, mdatabase__loader): Delete them.
+       (m17n_init_core): Call mdatabase__init.
+
+       * m17n-X.c (device_open): Use mplist_add, not mplist_push.
+
+       * internal.h (mdatabase__finder, mdatabase__loader): Delete externs
+       of them.
+
+       * font-flt.c (Mexist): New variable.
+       (enum FontLayoutCmdRuleSrcType): New enum SRC_EXIST.
+       (FontLayoutCmdRule): New member src.exist.
+       (load_category_table): Use isalnum, not isalpha.
+       (load_command): Check the command "exist".
+       (run_rule): Hande the case SRC_EXIST.
+       (run_command): Check the range of FROM.
+       (mfont__flt_init): Initialize Mexist.
+
+       * draw.c (layout_glyphs): Fix calculation of off_x and off_y.
+
+       * database.h (mdatabase__load_charset_func): Extern it.
+
+       * database.c: Include m17n-core.h instead of m17n.h.
+       (load_chartable): Use mtext__from_data.
+       (load_charset): Moved to charset.c
+       (load_database): Call mdatabase__load_charset_func instead of
+       load_charset.
+       (mdatabase__load_charset_func): New variable.
+       (mdatabase__init): Initialize mdatabase__load_charset_func and
+       Mcharset.  Don't set mdatabase__finder and mdatabase__loader.
+       (mdatabase__save): Use fwrite, not mconv_encode_stream.
+       (Mcharset): Declare it here.
+
+       * charset.c: Include "database.h.".
+       (load_charset): Moved from database.c.
+       (mcharset__init): Initialize mdatabase__load_charset_func, don't
+       initialize Mcharset.
+
+       * character.c (mchar_define_property): Call mdatabase_find directly.
+       (mchar_get_prop): Call mdatabase_add directly.
+       (mchar_put_prop): Call mdatabase_load directly.
+       (mchar_get_prop_table): Likewise.
+
+       * Makefile.am (libm17n_core_la_SOURCES): Add database.[ch].
+       (libm17n_la_SOURCES): Remove database.[ch].
+       (libm17n_flt_la_LIBADD): Delete libm17n.la, add libm17n-core.la.
+
+2007-09-18  Kenichi Handa  <handa@m17n.org>
+
+       * face.c (mface__realize): Try Freetype based font at first.
+
+       * font.c: Include <ctype.h>
+
+2007-09-16  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (load_flt): New arg full.  If full is zero, load only
+       coverage.
+       (run_otf): Call font->get_metrics, not font->get_metric.
+       (run_stages): Likewise.
+       (CHECK_FLT_COVERAGE): New macro.
+       (CHECK_FLT_STAGES): Call load_flt with the second arg 1.
+       (check_otf_spec): New function.
+       (m17n_fini_flt): Unref flt->coverage.
+       (mflt_find): Argument changed.
+       (mflt_name): New function.
+       (mflt_coverage): Use CHECK_FLT_COVERAGE.
+
+       * m17n-flt.h (MFLTFont): Member get_metrics renamed from get_metric.
+       (mflt_find): Prototype adjusted.
+       (mflt_name): Extern it.
+
+2007-09-14  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.h (struct _MFLTGlyph): Change signedness of members.
+
+       * font-flt.c (run_otf): Make debug info printing comaptible with
+       that of m17n-flt.c.
+       (run_command): Likewise.
+       (mfont__flt_run): Likewise.
+
+       * m17n-flt.c (UPDATE_CLUSTER_RANGE): ctx->cluster_begin_idx is
+       invalid only when it's negative.
+       (run_otf): Likewise.
+       (run_command): Likewise.
+       (mflt_run): Initialize ctx.cluster_begin_idx to -1.
+
+2007-09-10  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.h (struct _MFLTGlyph): New member encoded and measured.
+       (struct _MFLTFont): Prototype of get_glyph_id changed.
+
+       * m17n-flt.c (enum GlyphInfoMask): Delete EncodedMask and
+       PositionedMask.
+       (GAPPEND): Delete this macro.
+       (GET_ENCODED, SET_ENCODED, GET_MEASURED, SET_MEASURED): Adjusted
+       for the change of MFLTGlyph.  Caller changed.
+       (run_otf): Simply calls font->get_glyph_id.
+       (run_command): Reset g->encoded and g->measured for direct code.
+       (positioning): Delete this function.
+       (run_stages): Simply calls font->get_glyph_id and font->get_metric.
+
+2007-09-07  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (compose_glyph_string): Improve script detection.
+
+2007-09-06  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.h (mflt_get): Extern it.
+
+       * m17n-flt.c (run_stages): Call positioning only if
+       font->get_metric is non-NULL.
+       (CHECK_FLT_STAGES): Fix typo.
+       (mflt_get): New function.
+
+       * font-flt.c (mfont__flt_run): Improve debug info printing.
+
+2007-09-04  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (MFontLayoutTable): Delete this type.
+       (struct _MFLT): New member mdb and coverage.
+       (list_flt): Set flt->mdb.
+       (load_generator): Argument and return value changed.  Caller
+       changed.
+       (get_font_layout_table): Delete this function.
+       (run_stages): Argument changed.  Caller changed.
+       (CHECK_FLT_STAGES): New macro.
+       (mfont__flt_encode_char): Argument changed.
+       (mflt_find): Likewise.
+       (mflt_coverage): New function.
+       (mflt_run): Argument changed.
+       (mdebug_dump_flt): Likewise.
+
+       * m17n-flt.h (mflt_coverage): Extern it.
+       (mflt_find): Prototype adjusted.
+
+2007-09-03  Kenichi Handa  <handa@m17n.org>
+
+       * internal.h (MTABLE_CALLOC_SAFE, MSTRUCT_CALLOC_SAFE): New macros.
+
+       * database.c (mdatabase__props): New function.
+
+       * database.h (mdatabase__props): Extern it.
+
+       * m17n-flt.h (struct _MFLTGlyphString): Delete user_data, add
+       script and langsys.
+       (struct _MFLTFont): Add suitable_p.
+       (mflt_find): Extern it.
+
+       * m17n-flt.c: Include "database.h".
+       (struct _MFLT): New struct.
+       (list_flt): New function.
+       (load_flt): Don't update flt_list.
+       (get_font_layout_table): Use flt_list.
+       (m17n_init_flt): Don't initialize flt_list.
+       (m17n_fini_flt): Adjusted for the change of flt_list.
+       (mflt_find): New function.
+       (mflt_run): Fix debug printing.
+
+2007-08-23  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (run_otf): Remove #ifdef HAVE_OTF and #endi.
+       (run_stages): Print separator in encoded string as "|".
+
+2007-08-23  Kenichi Handa  <handa@m17n.org>
+
+       * font-flt.c (mfont__flt_run): Don't calculate a glyph metric if
+       the glyph is already handled by OTF.
+
+2007-08-21  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (ft_check_capability): Check cap->script_tag at first.
+
+2007-08-20  Kenichi Handa  <handa@m17n.org>
+
+       * font-flt.c (mfont__flt_run): Get glyph metrics before printing
+       debug information.
+
+2007-08-17  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.h (struct _MFLTGlyphString): Member pointer renamed to
+       user_data.
+       (MFLTOtfSpec): Renamed from MFLT_OTF_Spec.
+       (MFLTFont): Prototype of the member drive_otf adjusted.
+
+       * m17n-flt.c (run_stages): Fix handling of padding.
+
+       * font-ft.c (get_glyph_metric): New function.
+       (DEVICE_DELTA): Return 26.6 fixed point value.
+       (adjust_anchor): Likewise.
+       (mfont__ft_drive_otf): Use get_glyph_metric.
+
+       * font-flt.c (mfont__flt_run): Pay attention to padding on
+       printing debug info.
+
+2007-08-16  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-flt.c (run_stages): Fix typo.
+
+       * font-ft.c (adjust_anchor): Argument changed.  Calculte based on
+       26.6 fixed point.
+       (mfont__ft_drive_otf): Don't call OTF_check_features for GPOS.
+       Adjusted for the argument change of adjust_anchor.  Calculte based
+       on 26.6 fixed point.
+
+2007-08-15  Kenichi Handa  <handa@m17n.org>
+
+       * charset.c (mcharset__load_from_database): Set mdebug_flag
+       instead of mdebug_mask.
+
+       * coding.c (mcoding__load_from_database): Set mdebug_flag instead
+       of mdebug_mask.
+
+       * database.c (load_database): Set mdebug_flag instead of
+       mdebug_mask.
+       (mdatabase__load_for_keys): Likewise.
+
+       * draw.c: Include "internal-flt.h".
+       (dump_combining_code): Don't subtract 128 from combining code
+       off_x/y.
+
+       * font-flt.c: Include "internal-flt.h".  Set mdebug_flag instead
+       of mdebug_mask.
+       (run_rule): Print debug info only when MDEBUG_FLAG is greater than
+       2.
+       (run_cond): Likewise.
+       (run_otf): Likewise.
+       (run_command): Likewise.
+       (mfont__flt_run): Change format of debug info.
+
+       * font-ft.c: Include "internal-flt.h".
+       Set mdebug_flag instead of mdebug_mask.
+       (mfont__ft_drive_otf): Fix arg to OTF_check_features.
+
+       * input.c: Set mdebug_flag instead of mdebug_mask.
+       (shift_state): New MDEBUG_FLAG macro.
+       (preedit_commit): Likewise.
+       (filter): Likewise.
+
+       * internal-flt.h: New file.
+
+       * internal-gui.h (MAKE_COMBINING_CODE, COMBINING_CODE_OFF_Y)
+       (COMBINING_CODE_OFF_X, COMBINING_CODE_BASE_X)
+       (COMBINING_CODE_BASE_Y, COMBINING_CODE_ADD_X)
+       (COMBINING_CODE_ADD_Y, MAKE_COMBINING_CODE_BY_CLASS)
+       (COMBINING_BY_CLASS_P, COMBINING_CODE_CLASS)
+       (MAKE_PRECOMPUTED_COMBINDING_CODE, COMBINING_PRECOMPUTED_P): Move
+       these macros to internal-flt.h.
+
+       * internal.h (M17N_OBJECT_ADD_ARRAY): Adjusted for the change of
+       mdebug__flags.
+       (M17N_OBJECT_REGISTER, M17N_OBJECT_UNREGISTER): Likewise.
+       (enum MDebugMaskBit): Delete this enum.
+       (enum MDebugFlag): New enum.
+       (mdebug__flag): Don't extern it.
+       (mdebug__flags): Extern it.
+       (MDEBUG_FLAG): New macro.
+       (MDEBUG_PRINT0): Use the macro MDEBUG_FLAG.
+       (MDEBUG_DUMP, MDEBUG_PUSH_TIME, MDEBUG_POP_TIME)
+       (MDEBUG_PRINT_TIME): Likewise.
+
+       * m17n-X.c (xfont_open): Set mdebug_flag instead of mdebug_mask.
+       (xfont_list): Likewise.
+
+       * m17n-core.c (mdebug__flag): Delete this variable.
+       (mdebug__flags): New variable.
+       (SET_DEBUG_FLAG): Make it a function.
+       (m17n_init_core): Set mdebug_flag instead of mdebug_mask.
+       (m17n_fini_core): Likewise.
+
+       * m17n-gui.c (m17n_init_win): Set mdebug_flag instead of mdebug_mask.
+       (m17n_fini_win): Likewise.
+
+       * m17n-misc.h (enum MErrorCode): Add MERROR_FLT.
+
+       * m17n.c (m17n_init): Set mdebug_flag instead of mdebug_mask.
+       (m17n_fini): Likewise.
+
+       * symbol.c (msymbol__free_table): Adjusted for the change of
+       mdebug__flags.
+
+       * Makefile.am (BASICBUILDS): Add libm17n-flt.la.
+       (BASICHEADERS): Add m17n-flt.h.
+       (FLT_SOURCES): New variable.
+       (libm17n_flt_la_SOURCES, libm17n_flt_la_LIBADD)
+       (libm17n_flt_la_LDFLAGS): Likewise.
+
+       * m17n-flt.h: New file.
+
+       * m17n-flt.c: New file created by modifying font-flt.c.
+
+2007-07-13  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.4.0 released.
+
+2007-07-12  Kenichi Handa  <handa@m17n.org>
+
+       * input.c: Fix doxygen @ref commands.
+
+2007-07-10  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.h (M17NFunc): Fix typo of Doxygen directive.
+
+2007-07-09  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.h (M17N_BEGIN_HEADER, M17N_END_HEADER): New macros.
+
+       * m17n.h: Include m17n-core.h if not yet done.  Use macros
+       M17N_BEGIN_HEADER and M17N_END_HEADER.
+
+       * m17n-gui.h: Likewise.
+
+       * m17n-misc.h: Likewise.
+
+2007-06-13  Kenichi Handa  <handa@m17n.org>
+
+       * font-flt.c (load_command): Prepend "^" in the regular expression.
+
+2007-06-11  Kenichi Handa  <handa@m17n.org>
+
+       * language.c (mlanguage_name_list): Fix previous change.
+
+       * coding.c (mcoding__load_from_database): Add aliases in
+       coding_definition_list.
+
+2007-06-10  Kenichi Handa  <handa@m17n.org>
+
+       * language.c (mlanguage_name_list): Fix previous change.
+
+2007-06-08  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (update_candidate): Copy candidate_list earlier.
+       (re_init_ic): Provide pseudo initialize state if none.
+
+2007-06-05  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (preedit_insert): Print debug information.
+
+       * database.c (expand_wildcard_database): New function.
+       (mdatabase_list): Fix handling of wildcard database.
+
+       * language.c (load_lang_name): New function.
+       (mlang__fini): Cancel the last two changes.
+       (mlanguage_name_list): New arg script and territories.  Use
+       load_lang_name.
+
+       * m17n.h (mlangauge_name_list): Adjusted.
+
+2007-06-04  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (open_im): Check if the input method has at least one
+       state.
+
+2007-06-01  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (shift_state): Change the format of debug print.
+       (preedit_commit): New arg need_prefix.  Caller changed.
+       (update_candidate): Copy candidate_list.
+       (take_action_list): Likewise.
+       (handle_key): Change the format of debug print.
+
+       * font-flt.c (load_flt): Ignore unknown directives.
+
+2007-05-25  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.c (mdebug__unregister_object): Small optimization.
+
+       * database.c (find_file): Merged into get_database_file.
+       (get_database_file): New arg result.  Caller changed.
+       (mdatabase__check): Fix the logic.
+
+2007-05-24  Kenichi Handa  <handa@m17n.org>
+
+       * database.c (find_database): If unprocessed wildcard database is
+       found, register database filed and recursively call find_database.
+       (free_db_info): Unref db_info->properties.
+       (register_database): New arg properties.  Delete code for
+       initializing mdatabase__list.
+       (register_databases_in_files): Argument changed.  Caller changed.
+       (mdatabase__update): Don't list files by glob here.
+       (mdatabase_list): If unprocessed wildcard database is found,
+       register database filed and recursively call mdatabase_list.
+
+       * database.h (enum MDatabaseStatus): New enum
+       MDB_STATUS_AUTO_WILDCARD.
+
+       * input.c (load_branch): Fix previous change.
+       (update_global_info): If the global database is not found, return -1.
+
+2007-05-23  Kenichi Handa  <handa@m17n.org>
+
+       * database.c (Mversion): New variable.
+       (mdatabase__init): Initialize it.
+       (register_database): New arg properties.  Caller changed.
+       (register_databases_in_files): Don't check version here.
+       (mdatabase__update): Likewise.
+
+       * database.h (MDatabaseInfo): New member properties.
+
+2007-05-21  Kenichi Handa  <handa@m17n.org>
+
+       * language.c: Include <ctype.h>
+       (mlanguage__info): Use strncasecmp (not memcmp).
+       (mlanguage_name): Downcase language name for backward
+       compatibility.
+
+       * input.c (filter): Don't check Mlanguage property of
+       ic->im->langauge.
+
+2007-05-18  Kenichi Handa  <handa@m17n.org>
+
+       * language.c (mlanguage_name): Fix it to handle M-text English
+       name.
+
+       * input.c (config_command): Set NAME before using it.
+       (load_branch): Try to resolve a map name by variables.
+
+2007-05-17  Kenichi Handa  <handa@m17n.org>
+
+       * language.c (mlang__fini): Fix previous change.
+
+2007-05-16  Kenichi Handa  <handa@m17n.org>
+
+       * plist.c (free_plist): Cancel the last change.
+       (write_element): Check if PLIST is nested.
+       (mplist__from_plist): Label a plist as nested if appropriate.
+       (mplist__from_alist): Label a plist as nested.
+       (mplist__conc): Check the value of PL before referring it.  Label
+       a plist as nested if appropriate.
+       (mplist_copy): Label a plist as nested if appropriate.
+       (mplist_put_func): Return Mnil if KEY is a managing key.
+       (mplist_push): Label a plist as nested if appropriate.
+
+       * plist.h (MPLIST_SET_NESTED_P): Return 1 iff plist->control.flag
+       is set as nested.
+
+       * language.c (mlang__fini): Unref each element of langname_list.
+
+2007-05-14  Kenichi Handa  <handa@m17n.org>
+
+       * language.c: Include <string.h> and <locale.h>.
+       (langname_list): New variable.
+       (load_lang_script_list): Exclude invalid list elements.
+       (mlang__init): Initialize langname_list.
+       (mlang__fini): Unref langname_list.
+       (mlanguage__info): Adjusted for the change of English
+       name (symbol->M-text).
+       (mlanguage_name): Label it as obsolete.
+       (mlanguage_name_list): New function.
+
+       * m17n.h (mlanguage_name_list): Extern it.
+
+       * locale.c (make_locale): Fix setting of members of locale.
+
+       * plist.c (free_plist): Unref also nested plist.
+
+2007-05-11  Kenichi Handa  <handa@m17n.org>
+
+       * coding.c (mconv_reset_converter): Set internal->used to 0.
+
+2007-05-08  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (check_description): Force copying the translated text.
+
+2007-05-02  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (minput_save_config): Unref unnecessary plist.  Use
+       free_im_list to free im_config_list.
+
+2007-04-20  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (config_command): Fix previous change again.
+       (config_variable): Likewise.
+       (minput_config_command): Fix for the case of setting back to
+       default.
+       (minput_config_variable): Likewise.
+       (minput_save_config): Include nil as documentation of customized
+       command/variable.
+
+2007-04-05  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (config_command): Fix previous change.
+       (config_variable): Likewise.
+
+       * plist.c (mplist_get_func): Fix for backward compatiblity.
+
+2007-04-04  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (minput_get_command, minput_config_command): Fix example
+       codes.
+
+2007-03-29  Kenichi Handa  <handa@m17n.org>
+
+       These changes are to avoid unsafe casting of a function pointer.
+
+       * face.h (enum MFaceProperty): Delete MFACE_HOOK_FUNC.
+       (struct MFace): New member hook.
+
+       * face.c (serialize_face): Adjusted for the change of MFace.
+       (deserialize_face): Likewise.
+       (mface__init): Likewise.  Use msymbol_put_func.
+       (mface__realize): Adjusted for the change of MFace.  Avoid
+       compiler warning.
+       (mface_get_prop): Adjusted for the change of MFace.
+       (mface_put_prop): Likewise.
+       (mface_get_hook): New function.
+       (mface_put_hook): New function.
+       (mface_update): Adjusted for the change of MFace.
+
+       * input-gui.c (win_callback): Use mplsit_get_func.
+       (minput__win_init): Use mplsit_put_func.
+
+       * input.c (take_action_list): Use mplist_get_func.
+       (init_ic_info): Likewise.
+       (fini_ic_info): Likewise.
+       (minput_callback): Likewise.
+       (minput__init): Use mplist_put_func.
+
+       * language.c (mlang__init): Use msymbol_put_func.
+
+       * m17n-core.h (M17NFunc): New function type.
+       (M17N_FUNC): New macro.
+       (msymbol_put_func, msymbol_get_func): Extern them.
+       (mplist_put_func, mplist_get_func): Extern them.
+
+       * m17n-gui.h (mface_get_hook, mface_put_hook): Extern them.
+
+       * m17n-gui.c (mframe): Add a proper casting.
+
+       * plist.h (struct MPlist): Make the member val a union.
+       (MPLIST_VAL): Adjusted for the above change.
+       (MPLIST_FUNC): New macro.
+       (MPLIST_VAL_FUNC_P, MPLIST_SET_VAL_FUNC_P): New macros.
+
+       * plist.c (mplist_put_func, mplist_get_func): New functions.
+
+       * symbol.c (msymbol__fini): Use MPLIST_VAL.
+       (msymbol_put_func, msymbol_get_func): New functions.
+
+       * textprop.c (mtext_serialize): Use msymbol_get_func.
+       (mtext_deserialize): Likewise.
+
+2007-03-28  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (get_candidate_list): Avoid unnecessary unref.
+
+2007-03-23  Kenichi Handa  <handa@m17n.org>
+
+       * database.c (mdatabase__update): Unref plist at the tail.
+
+2007-03-21  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (update_custom_info): Fix for the case "name == Mnil &&
+       extra != Mnil".
+       (config_command): Fix for the case that configuration is
+       cancelled.
+       (config_variable): Likewise.
+       (minput_config_command): If keyseqlist is an empty list, cancel
+       the customization.
+       (minput_config_variable) If value is an empty list, cancel the
+       customization.
+       (minput_save_config): Handle cancellation of config and customize
+       correctly.
+
+2007-03-15  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (minput_config_variable): Check custom->vars (not
+       custom->cmds).
+
+2007-03-01  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (reload_im_info): Setup cmds, vars, and title of
+       im_info.
+       (check_variable_value): Fix the return value.
+
+       * database.c (mdatabase__check): If necessary, update database and
+       find a new file.
+
+2007-02-28  Kenichi Handa  <handa@m17n.org>
+
+       * database.c (get_dir_info): Set dir_info->status to
+       MDB_STATUS_OUTDATED.
+       (check_version): New function.
+       (register_database): Don't call find_database.
+       (register_databases_in_files): Don't register a database of
+       invalid version.
+       (mdatabase__update): Likewise.  Avoid unnecessary scanning.
+
+       * database.h (enum MDatabaseStatus): New membes MDB_STATUS_UPDATED
+       and MDB_STATUS_OUTDATED.
+
+       * font.h (struct MFont): Types of members type, source, and
+       spacing changed to unsigned.
+
+       * internal-gui.h (struct): Types of members category and type
+       changed to unsigned.
+
+       * internal.h (struct MText): Types of members format and coverage
+       changed to unsigned.
+
+       * m17n-core.h (M17NLIB_PATCH_LEVEL): Changed to 5.
+       (M17NLIB_VERSION_NAME): Changed to "1.3.5".
+
+2007-02-23  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (Mpop): New variable.
+       (fully_initialize): Initialize Mpop.
+       (parse_action_list): Handle Mpop.
+       (take_action_list): Likewise.
+       (handle_key): When a key is unhandled, shift to the initial state
+       only if the current state has no branch action.
+
+2007-02-12  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (get_preceding_char): Unref mt if necessary.
+       (get_following_char): Likewise.
+       (parse_action_list): Fix handling of `insert' action as
+       candidates.
+       (get_candidate_list): Fix for handling (("CANDIDATE1" ...)).
+       (take_action_list): Check invalid candidate list.
+
+2007-02-06  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (integer_value): Check also ic->produced for @-N.
+
+2007-01-26  Kenichi Handa  <handa@m17n.org>
+
+       * database.c (mdatabase__update): Check mdatabase__dir_list from
+       the tail.
+
+       * font-ft.c (STRDUP_LOWER): Don't ignore the tailing spaces.
+
+2007-01-12  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (handle_key): Handle a branch action of the initial
+       state correctly.
+
+2007-01-10  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gd.c (gd_render): Delete superfluous line.
+
+2006-12-26  Kenichi Handa  <handa@m17n.org>
+
+       * m17n.h (minput_callback): Extern it.
+
+       * input.h (minput__callback): Delte extern.
+
+       * input.c (get_surrounding_text): Adjusted for the change of
+       minput__callback to minput_callback.
+       (delete_surrounding_text): Likewise.
+       (minput_create_ic): Likewise.
+       (minput_destroy_ic): Likewise.
+       (minput_filter): Likewise.
+       (minput_set_spot): Likewise.
+       (minput_toggle): Likewise.
+       (minput_reset_ic): Likewise.
+
+       (preedit_commit): Reset ic->candidate_index, ic->candidate_from,
+       and ic->candidate_to to 0.
+       (minput_callback): Renamed from minput__callback.
+
+       * input-gui.c (win_callback): Adjusted for the change of
+       minput__callback to minput_callback.
+
+2006-12-15  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (ft_add_font): Fix typo.
+
+2006-12-06  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.4 released.
+
+2006-11-16  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (parse_action_list): Allow (undo 0).
+       (adjust_markers): New function.
+       (preedit_insert, preedit_delete): Call adjust_markers.
+       (preedit_replace): New function.
+       (update_candidate): Call preedit_replace instead of preedit_insert
+       and preedit_delete.
+       (filter): When ic_info->commit_key_head is nonzero, shift input
+       event keys even if there's no committed text.
+
+2006-11-10  Kenichi Handa  <handa@m17n.org>
+
+       * input.h (MInputContextInfo): New member commit_key_head.
+
+       * input.c (preedit_commit): Update ic_info->commit_key_head.
+       (take_action_list): Reset ic_info->commit_key_head on Mundo.
+       (filter): When committed, shift keys by ic_info->commit_key_head.
+
+2006-10-30  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (preedit_delete): Fix typo.
+       (take_action_list): Print more debugging information.  Allow
+       variable in arg of 'select' and `pushback'.
+
+       * database.c (gen_database_name): Don't put extra space.
+       (load_database): Print debugging information.
+       (register_databases_in_files): New arg headlen.  Callers changed.
+       (mdatabase__load_for_keys): Shorten debugging information.
+       (mdatabase_load): Don't print debugging information here.
+
+2006-10-27  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (marker_code): New arg surrounding.  Callers changed.
+       (surrounding_pos): Check if name[0] == '@'.
+       (integer_value): Fix for the change semantics of `@-N' and `@+N'.
+       (take_action_list): Likewise.
+       (get_preceding_char): If POS is zero, always call
+       get_surrounding_text.
+
+2006-10-19  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (load_variables): Fix setting of `global'.
+
+2006-10-16  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (draw_background): Be sure to set *to_x.
+       (render_glyph_string): If from == to, just return.
+
+2006-10-18  Kenichi Handa  <handa@m17n.org>
+
+       * database.c (get_dir_info): Return NULL if the directory name is
+       too long.
+       (register_databases_in_files): Call register_database with
+       MDB_STATUS_AUTO.
+       (mdatabase__update): Fix logic.  Call register_database with
+       MDB_STATUS_AUTO.
+       (mdatabase_define): Call register_database with
+       MDB_STATUS_EXPLICIT.
+
+       * input.c (delete_surrounding_text): Be sure to set members
+       preceding_text and following_text to NULL.
+       (shift_state): Save variable values in ic_info->vars_saved.
+       (preedit_commit): Don't print debug information here.  Don't
+       change ic_info->keys here.
+       (get_candidate_list): Don't ref plist.
+       (take_action_list): Don't unref return value of
+       get_candidate_list.  For undo, reset ic->produced and recover
+       ic_info->vars.  Be sure to set ic->candidate_list to NULL after
+       unref it.
+       (init_ic_info): Set ic_info->vars_saved.
+       (fini_ic_info): Unref ic_info->vars_saved.
+       (re_init_ic): Be sure to set ic->candidate_list to NULL after
+       unref it.
+       (filter): Be sure to set members preceding_text and following_text
+       to NULL.  Print debug information about produced text.  Delete
+       processed keys from ic_info->keys.
+
+       * input.h (MInputContextInfo): New member vars_saved.
+
+2006-10-16  Kenichi Handa  <handa@m17n.org>
+
+       * database.c (mdatabase__update): Fix the way to get db_info.
+
+2006-10-02  Kenichi Handa  <handa@m17n.org>
+
+       * font.h (struct MFont): New member `multiple_sizes'.  Bit-size of
+       `size' changed to 24.
+
+       * font.c (xlfd_unparse_name): Adjusted for the change of
+       MFont->size.
+       (font_score): Likewise.
+       (mfont__set_spec_from_face): Set spec->multiple_sizes to 0.
+
+       * m17n-X.c (MFontX, _MFontX): Deleted.
+       (SET_SIZE, HAVE_SIZE): Deleted.
+       (free_display_info): Adjusted for the change of
+       disp_info->font_list format.
+       (xfont_registry_list): Likewise.
+       (xfont_open): Likewise.
+       (xfont_list): Likewise.
+       (xfont_encode_char): Ignore size to find a realized font.
+       (MRealizedFontXft): Change the order of members to make it
+       compatible with MRealizedFontFT.
+
+2006-09-27  Kenichi Handa  <handa@m17n.org>
+
+       * font.c (mfont_match_p, mfont_open, mfont_encapsulate)
+       (mfont_close): Add comments.
+
+       * mtext-lbrk.c (mtext_line_break): Add comment.
+
+2006-09-26  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (minput_get_description): Handle description about
+       inclusion-only input methods.
+
+2006-09-21  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (M_gettext): New variable.
+       (fully_initialize): Initialize M_gettext.
+       (check_description): New function.
+       (load_commands): Call check_description.
+       (config_all_commands): Be sure to unref pl.
+       (load_variables): Call check_description.
+       (config_all_variables): Be sure to unref pl.
+       (load_im_info): Call check_description.
+
+       * internal.h [ENABLE_NLS]: Include <libintl.h> and define _.
+
+       * m17n-core.c (m17n_init_core) [ENABLE_NLS]: Call bindtextdoman
+       and bind_textdomain_codeset.
+
+       * Makefile.am (AM_CPPFLAGS): Add -DGETTEXTDIR=...
+
+2006-09-15  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (reload_im_info): Update custom and global info.
+       (init_ic_info): Fix previous change.
+
+2006-09-14  Kenichi Handa  <handa@m17n.org>
+
+       * database.c: Include <libgen.h>.
+       (mdatabase__lock): Make a directory if necessary.
+
+       * input.c (resolve_command): Adjusted for the format change of
+       configured_cmds member.
+       (load_commands, load_variables): Fix for errornous data handling.
+       (config_command, config_variable): New function.
+       (config_all_commands, config_all_variables): Renamed from
+       config_commands and config_variables.  Utilize the above function.
+       (check_variable_value): Argument changed.  Callers changed.
+       (load_im_info): Call config_all_commands and config_all_variables.
+       (init_ic_info): Adjusted for the format change of configured_vars
+       member.
+       (minput__init): Initialize Mcustomized, Mconfigured, and
+       Minherited.
+       (Mcustomized, Mconfigured, Minherited): New variables.
+       (minput_get_command): Be sure to return NULL if an input method
+       use no local command.
+       (minput_get_variable): Be sure to return NULL if an input method
+       use no local variable.
+       (minput_config_command, minput_config_variable)
+       (minput_save_config): Adjusted for the format change of
+       configured_cmds and configured_vars members.
+       
+       * plist.c (write_element): Delete superfluous ':'.
+
+2006-09-13  Kenichi Handa  <handa@m17n.org>
+
+       * m17n.h (Minherited, Mcustomized, Mconfigured): Extern them.
+       (minput_config_file): Extern it.
+
+       * draw.c (Minherited): Declaration moved to input.c.
+       (mdraw__init): Don't initialize Minherited here.
+
+       * database.c (mdatabase__unlock): Be sure to unlink uniq file.
+
+2006-09-07  Kenichi Handa  <handa@m17n.org>
+
+       * textprop.c (mtext_serialize): Call mplist__serialize with the
+       arg pretty 0.
+
+       * plist.h (mplist__serialize): Prototype adjusted.
+       (mplist__assq): Extern it.
+
+       * plist.c: Include <ctype.h>
+       (PUTC, PUTS): New macros.
+       (write_symbol): New function.
+       (write_element): New arg indent.
+       (dump_string, dump_plist_element): Delete them.
+       (mplist__from_string): New arg pretty.
+       (mplist__assq): New function.
+       (mdebug_dump_plist): Use write_element.
+
+       * mtext.c (mtext_cat_char): Allocate more memory.
+       (mdebug_dump_mtext): Don't escal a newline character.
+
+       * m17n.h (minput_get_command, minput_get_variable)
+       (minput_config_command, minput_config_variable)
+       (minput_save_config): Extern them.
+
+       * m17n-core.c: Include <string.h>.
+       (m17n_init_core): If the env. var. MDEBUG_OUTPUT_FILE is "stdout",
+       use the stream stdout instead of a file of that name.
+
+       * m17n-X.c (mwin__parse_event): Fix handling of Shift and Control
+       modifiers.
+
+       * internal.h (MFAILP, MDEBUG_PRINT0): New macros.
+       (MDEBUG_PRINT, MDEBUG_PRINT1, MDEBUG_PRINT2, MDEBUG_PRINT3)
+       (MDEBUG_PRINT4, MDEBUG_PRINT5): Use MDEBUG_PRINT0.
+       (MDEBUG_DUMP): Flush the stream.
+
+       * input.h (struct _MInputMethodInfo): Delete member im.  New
+       members mdb, language, name, extra, cmds, configured_cmds,
+       bc_cmds, vars, configured_vars, bc_vars, description, and tick.
+       (MInputContextInfo): New member tick.
+
+       * input.c: Big change to improve user-side input method
+       customization.  Here, list just public API changes.
+       (minput_get_commands, minput_get_variables)
+       (minput_assign_command_keys, minput_set_variable): Label them
+       obsolete.
+       (minput_get_command, minput_get_variable)
+       (minput_config_command, minput_config_variable)
+       (minput_save_config): New functions.
+       
+       * database.h (PATH_MAX): Define it if not yet defined.
+       (PATH_SEPARATOR): Likewise.
+       (enum MDatabaseStatus): New enum.
+       (struct MDatabaseInfo): Moved from database.c.  New members status,
+       time, lock_file, and uniq_file.
+       (mdatabase__update, mdatabase__file, mdatabase__lock, mdatabase__save)
+       (mdatabase__unlock): Extern them.
+
+       * database.c: Include <time.h>.
+       (MDB_DIR_LEN): Don't include the terminating '\0' in the length.
+       (GEN_PATH): Args changed.  Callers changed.
+       (struct MDatabaseInfo): Moved to database.h.
+       (struct MDatabase, mdb_list): Deleted.
+       (mdatabase__list): New var.
+       (get_database_filename): Deleted.  Callers changed to use
+       get_database_file.
+       (find_file, get_database_file): New files.
+       (get_dir_info): Initialize new members of MDatabaseInfo.
+       (find_database): Arg chagnded.  Callers changed.
+       (free_db_info, register_database, register_databases_in_files):
+       New functions.
+       (update_database_list): Deleted.
+       (mdatabase__init): Initialize mdatabase__list instead of mdb_list.
+       (mdatabase__fini): Finalize mdatabase__list instead of mdb_list.
+       (mdatabase__update): New function.
+       (mdatabase__check): Return value changed.
+       (mdatabase__file, mdatabase__lock, mdatabase__save)
+       (mdatabase__unlock): New functions.
+
+2006-08-30  TAKAHASHI Naoto  <ntakahas@m17n.org>
+
+       * input.c (get_surrounding_text): Return -2 when surrounding text
+       is unavailable.
+       (get_following_char): Likewise.
+       (get_preceding_char): Likewise.
+       (minput__callback): Return 0 if there is a callback function,
+       otherwise -1.
+
+2006-08-17  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (reset_ic): Use shift_state to setup the current state.
+
+2006-08-02  Theppitak Karoonboonyanan  <thep@linux.thai.net>  (tiny change)
+
+       * Makefile.am (libm17n_la_LIBADD, libm17n_gui_la_LIBADD)
+       (libm17n_X_la_LIBADD, libm17n_gd_la_LIBADD, linkcore_LDADD)
+       (linkshell_LDADD, linkgui_LDADD): Use ${top_builddir}.
+
+2006-08-02  Kenichi Handa  <handa@m17n.org>
+
+       * plist.c (mdebug_dump_plist): Fix the 2nd arg to dump_plist_element.
+
+       * mtext.c (mdebug_dump_mtext): If not fullp, dump just text. 
+
+       * font-ft.c (ft_encapsulate): Add code for debugging.
+       (mfont__ft_drive_otf): Be sure to encode character before getting
+       metrics.
+
+2006-07-21  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (mdraw_text_extents): Fix previous typo.
+
+2006-07-19  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (gstring_width): New arg lbearing.
+       (render_glyph_string): Adjusted for the change of gstring_width.
+       (mdraw_text_extents): Fix lbearing of ink and line metrics.
+
+       * m17n-core.h (Mlanguage): Extern it.
+
+       * m17n.h (Mlanguage): Extern deleted. 
+
+       * mtext.c (mtext__init): Initialize Mlanguage.
+       (Mlanguage): Declaration moved from locale.c
+
+       * locale.c (mlocale__init): Don't initialize Mlanguage here.
+       (Mlanguage): Declaration moved to mtext.c.
+
+       * language.c (mlang__init): Don't initialize Mlanguage here.
+
+       * font.c (OTF_tag_name) [! HAVE_OTF]: New function.
+
+2006-07-14  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c: Use FT_BDF_H macro.  Include fontconfig/fcfreetype.h.
+       (MRealizedFontFT): New member face_encapsulated.
+       (free_ft_rfont): Pay attention to ft_rfont->face_encapsulated.
+       (ft_gen_font): New function.
+       (ft_add_font): Use ft_gen_font.
+       (ft_list_script): Store lists in ft_script_list.
+       (ft_check_otf): New arg ft_face.  Caller changed.
+       (ft_check_language): Likewise.
+       (ft_check_script): Likewise.
+       (ft_encapsulate, ft_close): New functions.
+       (mfont__ft_driver): Initialize members encapsulate and close.
+       (mfont__ft_drive_otf): Use OTF_open_ft_face if it is available.
+
+       * font.h (struct MRealizedFont): New member encapsulating.
+       (struct MFontDriver): New members encapsulate and close.
+
+       * font.c (mfont__match_p): If FONT is realized, check capability
+       by font drivers's check_capability method.
+       (mfont_match_p, mfont_open, mfont_encapsulate, mfont_close): New
+       functions.
+
+       * m17n-X.c (xfont_list_family_names): Delete unused var.  Fix
+       declarations of foundry and fam local vars.
+       (xft_driver): Make it static.
+
+       * m17n-gui.h (mfont_match_p, mfont_open, mfont_encapsulate)
+       (mfont_close): Extern them.
+
+       * m17n-gd.c (device_open): Don't specify foundry and family of the
+       default face.
+
+2006-07-11  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.c (m17n_fini_win): Set null_interface.handle to NULL;
+
+2006-07-13  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (fc_build_charset): Return NULL if FcCharSet can't be
+       created.
+       (ft_check_script): Delete unused var.
+       (ft_list_capability): Likewise.
+
+       * font.c (mfont__get_capability): Setup cap->otf.
+       (Motf): Make it global.
+       (mfont_get_prop): Accept Mlanguage, Mscript, and Motf as key arg.
+
+       * font.h (MFontCapability): New member otf.
+
+       * language.c (mlang__fini): Delete unused vars.
+
+       * m17n-gui.h (Motf): Extern it.
+
+       * database.c (update_database_list): Delete unused vars.
+
+2006-07-07  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (DEVICE_DELTA): Fix typo.
+
+2006-07-06  Kenichi Handa  <handa@m17n.org>
+
+       * fontset.c (mfont__lookup_fontset): Don't ignore family and
+       foundry of face.
+
+2006-07-05  TAKAHASHI Naoto  <ntakahas@m17n.org>
+
+       * database.c: Update comments.
+
+2006-07-05  Kenichi Handa  <handa@m17n.org>
+
+       * database.c (PATH_MAX): Define it if not yet defined.
+       (PATH_SEPARATOR, USE_GEN_PATH, GEN_PATH, GEN_PATH_FROM_MT): New
+       macros.
+       (get_database_filename): Use GEN_PATH.
+       (get_dir_info): Don't include the last '/' in directory name.
+       (register_database): New function.
+       (update_database_list): Use register_database.  Search all
+       directories in mdatabase__dir_list for wildcard databases.
+       (mdatabase__init): Check "~/.m17n.d".
+
+2006-07-03  Kenichi Handa  <handa@m17n.org>
+
+       * input-gui.c (win_callback): If is ic->candidate_show zero, don't
+       push reverse property.
+
+       * plist.c (dump_plist_element): Fix previous change.
+
+2006-06-28  Kenichi Handa  <handa@m17n.org>
+
+       * font.c (xlfd_unparse_name): Suppress the heading '-' if not
+       necessary.
+
+       * draw.c (MbidiNSM): New variable.
+       (visual_order) [! HAVE_FRIBIDI]: Clear levels at first.  Pay
+       attention to bidi type NSM.
+       (mdraw__init): Initialize MbibiNSM.
+
+       * language.c (mscript__char_list): Fix finding a char-list element.
+
+       * plist.c (dump_string): Return number of printed characters.
+       (dump_plist_element): Print elements more compactly.
+
+2006-06-23  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (BUILD_LIBS): Don't increment it conditionally.
+       (include_HEADERS): Likewise.
+
+2006-06-23  TAKAHASHI Naoto  <ntakahas@m17n.org>
+
+       * language.c: Update documentation.
+
+2006-06-23  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (struct MFontFT): Delete member lang.
+       (free_ft_info): Don't unref member lang.  Destroy members langset
+       and charset.
+       (fc_parse_pattern): Last argument changed to MFontFT *.  Callers
+       changed.  Set members langset and charset.
+       (fc_init_font_list, fc_list_pattern, fc_build_charset): New
+       functions.
+       (ft_init_font_list, ft_has_char_list_p, ft_list_char_list): New
+       functions.
+       (ft_list_family) [HAVE_FONTCONFIG]: Include FC_CHARSET on objset.
+       (ft_list_family) [! HAVE_FONTCONFIG]: Call ft_init_font_list.
+       (ft_list_language) [HAVE_FONTCONFIG]: Check representative
+       characters at first.  If it fails, try listing by language names.
+       (ft_list_language) [! HAVE_FONTCONFIG]: Call ft_list_char_list.
+       (ft_check_language): Renamed from ft_check_lang.  Adjusted for the
+       change of MFontCapability.
+       (ft_list_capability): Likewise.  Try listing by languages, then by
+       scripts.  Check OTF at last.
+       (ft_check_script): New function.
+       (ft_select): Adjusted for the check of MFontCapability.
+       (ft_list_family_names): New function.
+       (ft_check_capability): If cap->script is not Mnil, call
+       ft_check_script.
+       (mfont__ft_driver): Initialize with ft_list_family_names.
+
+       * font.h (struct MFontDriver): New member list_fmaily_names.
+       (struct): Change member "MSymbol *lang" to "MSymbol language".
+
+       * font.c: Include "language.h".
+       (Motf): New variable.
+       (otf_script_list, load_otf_script_list): Delete it.
+       (find_script_from_otf_tag): Delete it.
+       (merge_capability): New function.
+       (mfont__init): Init Motf.
+       (mfont__fini): Don't unref otf_script_list.
+       (free_font_capability): Check cap->script_tag to determine if
+       OTF-related capability is set.
+       (mfont__get_capability): Call mscript__from_otf_tag.  Adjusted for
+       the change of type MFontCapability.
+       (mfont_put_prop): Call merge_capability for Mlanguage, Mscript,
+       and Motf properties.
+       (mfont_list): Call merge_capability for LANGUAGE arg.
+       (mfont_list_family_names): New function.
+
+       * input-gui.c: Typo in comments fixed.
+
+       * input.c: Typo in comments fixed.
+
+       * language.h (mlanguage__list): Delete it.
+       (mscript__char_list, mscript__otf_tag, mscript__from_otf_tag): New
+       functions.
+
+       * language.c: Include "mtext.h".
+       (M_script_lang_list): Delete it.
+       (language_list, script_list): New variables.
+       (load_lang_script_list, init_language_list, init_script_list): New
+       functions.
+       (mlang__init): Don't load language database here.
+       (mlang__fini): Unref language_list and script_list if not NULL.
+       (mlanguage__list): Delete it.
+       (mlanguage__info, mscript__info, mscript__char_list)
+       (mscript__otf_tag, mscript__from_otf_tag): New functions.
+       (mlanguage_list, mlanguage_code, mlanguage_name, mlanguage_text)
+       (mscript_list, mscript_language_list): New functions.
+
+       * m17n-gui.h (mfont_list_family_names): Extern it.
+
+       * m17n.h (mlanguage_list, mlanguage_code, mlanguage_name)
+       (mlanguage_text, mscript_list, mscript_language_list): Extern
+       them.
+
+2006-06-21  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (xfont_driver): Initialize with
+       xfont_list_family_names.
+       (xfont_list_family_names): New function.
+       (xft_driver): Initialize with NULL for list_family_names member.
+       (device_init): Set list_family_names member of xft_driver to that
+       of mfont__ft_driver.
+
+2006-06-06  Kenichi Handa  <handa@m17n.org>
+
+       * fontset.c (mfont__lookup_fontset): Don't set *num to 1 if it is 0.
+
+2006-03-24  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (ft_open): Improve debug message.
+
+       * fontset.c (mfontset__get_font): Fix for the case that no font in
+       per_script list is available.
+
+2006-02-06  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.3 released.
+
+2006-02-22  Kenichi Handa  <handa@m17n.org>
+
+       * textprop.c: Fix some typos in documentation.
+
+       * plist.c: Fix some typos in documentation.
+
+       * m17n-core.h: Fix some typos in documentation.
+       (M17NLIB_PATCH_LEVEL): Updated to 3.
+       (M17NLIB_VERSION_NAME): Updated to "1.3.3".
+
+       * symbol.c: Fix some typos in documentation.
+
+       * mtext.c: Fix some typos in documentation.
+
+       * input.c: Fix several typos in documentation.
+
+2006-02-06  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.2 released.
+
+2006-02-03  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.h (M17NLIB_PATCH_LEVEL): Updated to 2.
+       (M17NLIB_VERSION_NAME): Updated to "1.3.2".
+
+       * font.c (xlfd_parse_name): Fix handling of the name "nil".
+
+       * draw.c (layout_glyphs): Fix handling left_padding of
+       composition's base.
+
+       * m17n-gd.c (read_rgb_txt): Support HTML 4.0 color names.
+
+2006-02-02  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (include_HEADERS): Add m17n-gui.h and m17n-X.h only
+       if WITH_GUI is true.
+
+2006-01-25  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (resolve_expression): If the value of PLIST is a plist,
+       but the first element is not symbol, return 0.
+
+2006-01-17  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gd.c (gd_render): Use gdImageColorResolveAlpha only if
+       HAVE_GD is 2 or the greater.
+
+2006-01-16  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.1 released.
+
+2006-01-16  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gd.c (gd_render): Use gdImageColorResolveAlpha instead of
+       simulating anti-aliasing.
+
+       * m17n-core.h (M17NLIB_PATCH_LEVEL): Updated to 1.
+       (M17NLIB_VERSION_NAME): Updated to "1.3.1".
+
+2006-01-12  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (get_surrounding_text): Always pop ic->plist.
+       (reset_ic): Don't reset ic->plist.
+
+2006-01-10  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (preedit_commit): For debugging, print only commiting
+       charactes.  Don't set ic->candidate_show to 0.
+       (handle_key): Don't run branch-actions just by shifting to the
+       current state.
+       (reset_ic): Reset state_key_head and key_head of ic_info to 0.
+       Reset vars and plist.
+
+2006-01-07  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (load_branch): Confirm that maps is not NULL.
+
+2006-01-05  Kenichi Handa  <handa@m17n.org>
+
+       * input-gui.c (win_filter): Try to convert arg to key only when
+       arg is not NULL.
+
+       * plist.c (read_integer_element): If '#' and '-' are followed by
+       non-integer-constituent, read them as a part of a symbol.
+       (read_symbol_element): New arg C.
+       (read_element): Adjust args to read_symbol_element.
+
+       * input.c (load_macros): On overwriting a macro, free the old
+       definition.
+       (minput__init): Store Mmap in load_im_info_keys.
+       (minput_get_title_icon): If the input method has no title, be sure
+       to return NULL.
+       (minput_get_description): If the input method has no description,
+       be sure to return NULL.
+       (minput_get_variables): Fix documentation.
+       (handle_key): Pay attention to the case that key is Mnil.
+       (filter): Likewise.  Fix handling of such symbol as S-A.
+
+2005-12-22  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.3.0 released.
+
+2005-12-22  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (ft_list): If the specified font has no property,
+       return all fonts.
+
+2005-12-20  Kenichi Handa  <handa@m17n.org>
+
+       * character.c (mchar_get_prop): Check char_prop_list.
+       (mchar_put_prop, mchar_get_prop_table): Likewise.
+
+2005-12-18  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (minput_get_title_icon): If LANGUAGE is Mt, try also a
+       file name sans language.
+
+2005-12-16  TAKAHASHI Naoto  <ntakahas@m17n.org>
+
+       * input.c: Fix typo in comments.
+
+2005-12-14  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (minput_get_title_icon): Check the default icon for the
+       input method.
+
+2005-12-13  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (Mless_equal, Mgreater_equal): New variables.
+       (parse_expression, resolve_expression, parse_action_list)
+       (take_action_list): Handle the aboves.
+       (filter): Treat key S-X as X.
+       (minput__init): Initialize Mless_equal and Mgreater_equal.
+       (minput_get_title_icon): New function.
+
+       * m17n.h (minput_get_title_icon): Extern it.
+
+       * database.c (get_database_filename): Return a filename instead of
+       file pointer.
+       (load_database): Adjusted for the above change.
+       (mdatabase__load_for_keys): Likewise.
+       (mdatabase__find_file): New function.
+
+       * database.h (mdatabase__find_file): Extern it.
+
+       * font.h (mfont__resize): Delete extern.
+
+       * font.c (mfont__list): Check resize ratio.
+       (mfont__resize): Delete it.
+       (mfont_resize_ratio): Include the code of mfont__resize.
+
+       * font-ft.c (ft_open): Check resize ratio.
+
+       * m17n-X.c (xfont_open): Check resize ratio.
+       (xft_open): Likewise.
+
+2005-12-07  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (take_action_list): If take_action_list return -1,
+       return -1.
+       (handle_key): Likewise.
+
+       * face.c (mface__for_chars): When font is specified and layouter
+       is found for it, if the layouter doesn't support one of a
+       character, use a face sans layouter for it.
+
+2005-12-06  Kenichi Handa  <handa@m17n.org>
+
+       * fontset.c (mfont__lookup_fontset): If only a fallback font is
+       found, don't use it for more than one character.
+
+2005-12-05  Kenichi Handa  <handa@m17n.org>
+
+       * face.c (mface__realize): Set rfont->layouter to Mnil.
+       (mface__for_chars): Fix handling of layouter.
+
+       * character.h (mchar__define_prop): Extern it.
+
+       * database.c (update_database_list): Call mchar__define_prop if
+       necessary.
+
+       * character.c (mchar__init): Don't call mchar_define_property.
+       Instead just initialize property keys.
+       (mchar__fini): Free char_prop_list only if it's not NULL.
+       (mchar__define_prop): New function.
+       (mchar_define_property): Call mchar__define_prop.
+
+       * m17n-core.c (m17n_fini_core): Call mtext__prop_fini at after
+       mplist__fini.
+
+2005-12-02  Kenichi Handa  <handa@m17n.org>
+
+       * language.c (mlang__init): Handle extra chars.
+
+       * m17n-gui.h (mfont_check): Adjust prototype.
+
+       * m17n-X.c (xfont_driver): Specify xfont_check_capability.
+       (xfont_check_capability): New function.
+       (xft_driver): Specify xft_check_capability.
+       (xft_check_capability): New function.
+
+       * font-ft.c (M0_3): Delete it.
+       (M0): New variable.
+       (ft_get_charmaps): Refer to M0.
+       (fc_parse_pattern): Fix previous change.
+       (ft_list_language): Check also extra chars.
+       (ft_check_otf): Define it even if HAVE_OTF is undef.
+       (ft_check_lang): Check the result of FcLangSetHasLang against
+       FcLangDifferentLang.  Check also extra chars.
+       (ft_list_capability): Delete ifdef HAVE_OTF.
+       (ft_select): Likewise.
+       (ft_open): Improve debug information.
+       (ft_check_capability): New function.
+       (mfont__ft_driver): Specify ft_check_capability.
+       (mfont__ft_init): Initialize M0.
+
+       * fontset.c (get_font_from_group): New function.
+       (mfontset__get_font): New function.
+
+       * fontset.h (mfontset__get_font): Extern it.
+
+       * font.c (OTF_tag): Define it if HAVE_OTF is undef.
+       (mfont__fini): Delete ifdef HAVE_OTF.
+       (free_font_capability): Likewise.
+       (mfont__get_capability): Likewise.
+       (mfont__check_capability): New function.
+       (mfont_check): Change the order of arguments.  Use
+       mfontset__get_font.
+
+       * font.h (struct MFontDriver): New member check_capability.
+       (MFontCapability): Delete ifdef HAVE_OTF.
+       (mfont__check_capability): Extern it.
+
+       * face.c (mface__realize): Fix handling of FONT arg.
+       (mface__for_chars): Fix handling of explicitly specified font.
+
+2005-11-25  Kenichi Handa  <handa@m17n.org>
+
+       * font-flt.c (run_command): Print debug info for
+       left/rigth_padding
+
+       * draw.c (layout_glyphs): Fix handling of left/right_padding.
+
+       * face.c (mface__for_chars): Check rfont before accessing the
+       members.
+
+2005-11-21  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (lib_LTLIBRARIES): Define it conditionaly on
+       WITH_GUI.
+
+       * fontset.c (fontset_table): New variable.
+       (free_fontset): Call M17N_OBJECT_UNREGISTER.
+       (mfont__fontset_init): Add fontset_table as an object array.
+       (mfont__realize_fontset): Ref FONTSET.
+       (mfont__free_realized_fontset): Unref REALIZED->fontset.
+       (mfontset): Call M17N_OBJECT_REGISTER.
+       (mfontset_copy): Likewise.
+
+       * input.c (handle_key): For debugging, print information about
+       alias key.
+       (filter): Add an alias for Meta and Alt modifiers.
+       (Mcond, Mplus, Mminus, Mstar, Mslush, Mand, Mor, Mnot): New
+       variables.
+       (minput__init): Initialize them.
+       (parse_expression): New function.
+       (resolve_expression): New function.
+       (parse_action_list): Handle expressions by parse_expression.
+       (take_action_list): Handle expressions by resolve_expression.
+       (parse_nested_list_value): Fix previous change.
+       (resolve_command): Fix handling of the return value of
+       get_nested_list.
+
+2005-11-18  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (ft_check_otf, otf_script_list): Define only when
+       HAVE_OTF is defined.
+       (ft_list_capability): Call ft_check_otf only when HAVE_OTF is
+       defined.
+       (ft_select): Likewise.
+
+       * font.c (mfont_list): Fix for the case that FONT is NULL.
+       (OTF_tag): Delete it.
+       (load_otf_script_list): Define only when HAVE_OTF is defined.
+       (mfont__fini): Unref otf_script_list only when HAVE_OTF is
+       defined.
+
+       * draw.c (truncate_gstring): Be sure to truncate at
+       glapheme-cluster boundary.
+
+2005-11-11  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (delete_surrounding_text): Clear cache if necessary.
+
+2005-11-09  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (compose_glyph_string): Update prev->rface->rfont if the
+       glyph prev is also supported by the current flt.
+
+2005-11-08  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (xft_render): Cancel previous change.
+
+2005-11-07  Kenichi Handa  <handa@m17n.org>
+
+       * input.c: Include <stdlib.h>.
+       (get_surrounding_text, delete_surrounding_text)
+       (get_preceding_char, get_following_char): New functions.
+       (integer_value): New arg surrounding.  If it is nonzero, try to
+       get a surrounding character.  Callers changed.
+       (take_action_list): Check `value' before setting an element.
+       (destroy_ic): Unref ic_info->preceding_text and
+       ic_info->following_text.
+       (minput__init): Initialize Minput_get_surrounding_text and
+       Minput_delete_surrounding_text.
+       (Minput_get_surrounding_text, Minput_delete_surrounding_text): New
+       variables.
+       (filter): Unref ic_info->preceding_text and
+       ic_info->following_text.
+
+       * m17n.h (Minput_get_surrounding_text, Minput_delete_surrounding_text):
+       Extern them.
+
+       * input.h (MInputContextInfo): New members preceding_text and
+       following_text.
+
+2005-11-04  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (parse_nested_list_value): Fix handling of the global
+       definition.
+       (get_nested_list): Get global definitions by load_partial_im_info.
+       (preedit_commit): Set ic->candidates_changed to bitwise or of enum
+       MInputCandidatesChanged.
+       (take_action_list): Likewise.
+       (reset_ic): Likewise.
+       (create_ic): Don't pay special attention to
+       Mcandidates_group_size.
+       (load_partial_im_info): Call mdatabase_find with correct 4th arg.
+       (minput_set_variable): Get a definition of varible by
+       mplist_find_by_value, not mplist_get.
+
+       * m17n.h (enum MInputCandidatesChanged): New enum.
+
+2005-11-01  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (xft_render): Check xft_draw's drawable before changing
+       it.
+       (mwin__destroy_window): If xft_draw's drawable is win, change it
+       to device->drawable before destroying win.
+
+2005-10-31  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (load_im_info): Fix adding of state.
+
+       * m17n-core.c (m17n_fini_core): Fix reporting of module
+       finalization.
+
+       * m17n.c (m17n_fini): Fix reporting of module finalization.
+
+       * m17n-gui.c (m17n_init_win): Fix reporting of module
+       finalization.
+
+2005-10-29  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (get_candidate_list): Fix the timing of referring plist.
+
+2005-10-28  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (load_branch): Ignore an undefined map name.
+       (load_im_info): Set im_info->title from `name' only if it's not
+       Mnil.
+       (shift_state): Always update ic->status.
+       (adjust_candidates): Renamed from adjust_candidate_command.
+       Argument changed.  Caller changed.
+       (get_candidate_list, regularize_action): New functions.
+       (take_action_list): Use them.  On handling Munhandle, don't set
+       ic_info->used to 0.
+       (handle_key): If KEY is not handled by MAP, and MAP has
+       branch_actions, perform them.
+
+       * database.c (mdatabase__fini): Free dir_info->filename;
+
+2005-10-20  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (marker_code): Accept '@@'.
+       (integer_value): Handle '@@'.
+       (parse_action_list): Accept a symbol argument.
+       (take_action_list): Resolve the symbol argument.  Handle the
+       integer argument.
+
+2005-10-18  Kenichi Handa  <handa@m17n.org>
+
+       * input.c: Include "charset.h".
+       (M_candidates, Mcandidates_group_size, Mcandidates_charset): New
+       variables.
+       (MIMState): New member (M17NObject control).
+       (lookup_nested_list, set_nested_list, parse_nested_list_value)
+       (get_nested_list, resolve_variable): New functions.
+       (integer_value): New arg (MPlist **value).  Set it to the plist
+       element containing the value.
+       (resolve_command): New function.
+       (load_translation): New arg (MPlist *map_actions).
+       (load_branch): New args language and name.  If `keylist' is a
+       symbol, resolved that as a command name.
+       (free_map): New arg top.  Free map->map_actions only if top is
+       nonzero.
+       (free_state): New function.
+       (load_state): New arg name.
+       (im_info_list): New variable.
+       (free_im_info, get_im_info_by_tags): New functions.
+       (load_im_info): Arg key changed to plist.  Handle `include'.
+       Return (MInputMethodInfo *).
+       (preedit_commit): Ref ic->candidate_list.
+       (get_select_charset, adjust_candidate_command): New functions.
+       (take_action_list): Handle `include'.  Adjust candidate action
+       properly.  Handle control variables `candidates-charset' and
+       `candidates-group-size'.
+       (open_im): Use get_im_info.
+       (create_ic): Get global variables.
+       (load_partial_im_info): New function.
+       (get_im_info): New function.
+       (check_command_keyseq, check_command_list, check_variable_list):
+       New functions.
+       (minput__init): Don't handle M_database_hook and Mdetail_text.
+       Initialize M_candidates, Mcandidates_group_size,
+       Mcandidates_charset.
+       (parse_variable_list, get_variable_list, parse_command_list)
+       (get_command_list): Delete them.
+       (MDatabaseStatList, imdir_stat_list, input_method_hook): Delete them.
+       (minput__fini): Simply unref command_list and variable_list.
+       (minput_get_description): Adjusted for the new form of description.
+       (minput_get_commands): Use get_nested_list.
+       (minput_assign_command_keys): Likewise.
+       (minput_get_variables, minput_set_variable): Likewise.
+
+       * input.h (MInputMethodInfo): New members im and maps.
+
+       * database.h (M_database_hook): Delete extern.
+       (MDatabaseHookFunc): Delete extern.
+       (mdatabase__check): Extern it.
+
+       * database.c: Include <glob.h>.
+       (MAX_TIME): New macro.
+       (Masterisk): New variable.
+       (get_database_stream): Argument changed to (MDatabaseInfo *).
+       Callers changed.
+       (get_dir_info): Renamed from duplicate_dirname.  Callers changed.
+       (find_database): New function.
+       (update_database_list): New function.
+       (mdatabase__init): Initialize Masterisk.  Setup mdb_list by
+       calling update_database_list.
+       (mdatabase__check): New function.
+       (mdatabase_find): Use update_database and find_database.  Don't
+       handle MDatabaseHookFunc.
+       (mdatabase_list): Call update_database at first.
+       (mdatabase_define): Adjusted for the change of mdb->extra_info.
+       (MDatabaseList): New type.
+
+       * plist.h (mplist_conv, mplist__pop_unref): Extern them.
+
+       * m17n.h (Mdetail_text): Delete extern.
+
+       * m17n-core.h (mplist_conc): Delete extern.
+
+       * plist.c (mplist__conc): Renamed from mplist_conc.  Don't ref
+       tail.
+       (mplist_conc): Renamed to mplist__conc.
+       (mplist__pop_unref): New function.
+
+2005-10-14  Kenichi Handa  <handa@m17n.org>
+
+       * plist.c (read_mtext_element): Ignore the sequence of '\\' and
+       newline.
+       (read_element): If keys is an empty plist, return any element
+       found first.
+       (dump_plist_element): Check if plist is nested.
+       (mplist_conc): Always ref tail.
+       (mplist_set): If key is a managing key, ref val in advance.
+
+       * plist.h (MPLIST_VAL_MANAGED_P): Delete this macro.
+       (MPLIST_NESTED_P, MPLIST_SET_NESTED_P): New macros.
+       (MPLIST_ADD_PLIST, MPLIST_PUSH_PLIST, MPLIST_PUT_PLIST): New
+       macros.
+
+       * fontset.c (free_fontset): Unref fontset_list if necessary.
+       (mfont__fontset_fini): Don't free fontset_list.  Unref
+       default_fontset.
+       (mfont__realize_fontset): Initialize request.
+       (mfontset): Ref default_fontset or fontset only if necessary.
+       (mfontset_copy): Don't ref copy.
+
+       * draw.c (render_glyphs): Check gend->type before checking
+       gend->to.
+
+       * font-ft.c (mfont__ft_fini): Unref ft_default_list.  Set all
+       unrefed plists to NULL.
+
+2005-10-04  Kenichi Handa  <handa@m17n.org>
+
+       * textprop.c (mtext_serialize): Be sure to make mt
+       MTEXT_FORMAT_UTF_8 and NULL terminated.
+
+       * m17n-gui.c (m17n_init_win): Initialize Mcolormap.
+
+       * draw.c (mdraw_glyph_list): Fix settting of glyphs->font->source.
+
+2005-10-03  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (mdraw_glyph_info): Pay attention to the case that FROM
+       is not at the beginning of line.
+
+2005-09-22  Kenichi Handa  <handa@m17n.org>
+
+       * input.c: Include <sys/stat.h> and <unistd.h>.
+       (Minclude, Mcommit, Munhandle): New variables.
+       (minput__init): Initialize them.  Push only Mstate to
+       load_im_info_keys.   Add aliases C-lowercase for C-uppercase.
+       (parse_action_list): Allow integer arg for undo.  Handle Mcommit
+       and Munhandle.
+       (load_input_method): Handle "include" directive.  If no states are
+       loaded, return -1.
+       (shift_state): If state_name is Mt, shift back to the previous
+       state.  Call preedit_commit to commit preedit text.
+       (preedit_commit): New function.
+       (take_action_list): Improve debug printing.  Handle commit and
+       unhandle commands.
+       (handle_key): Check the return value of take_action_list.  Don't
+       take branch_actions just after changing to the root map.
+       (reset_ic): Reset all ic_info members.
+       (filter): When a key is not handled, just move ic_info->keys
+       instead fo calling reset_ic.
+       (load_im_info): If key is not Mstate, push Mmap to
+       load_im_info_keys.
+       (MDatabaseStatList): New type.
+       (imdir_stat_list): New variable.
+       (input_method_hook): Don't cancel the hook.  Check the
+       modification time of directories.
+       (minput__fini): Free imdir_stat_list;
+
+       * input.h (MInputContextInfo): New member prev_state.
+
+       * m17n-core.h (mplist_conc): Extern it.
+
+       * plist.c (mplist_conc): New function.
+
+       * mtext.c (mdebug_dump_mtext): Escape '"' and '\\' by '\\'.
+
+       * font.h (MRealizedFont): New member average_width.
+
+       * font-ft.c (ft_open): Set rface->average_width.
+
+       * font.c (xlfd_unparse_name): Print '*' before registry name.
+
+       * m17n-X.c (MDisplayInfo): New member AVERAGE_WIDTH.
+       (xfont_open): Set rfont->average_width.
+       (xft_open): Likewise.
+       (device_open): Initialize disp_info->AVERAGE_WIDTH.
+
+       * internal-gui.h (struct MFrame): New member average_width.
+
+       * m17n-gui.c (mframe): Fix setting of frame->rfont.
+       (mframe_get_prop): Return the average_width of a font.
+
+       * face.c (mface__realize): Set rface->average_width.
+       (mface__update_frame_face): Set frame->average_width.
+
+       * face.h (MRealizedFace): New member average_width.
+
+2005-09-19  Kenichi Handa  <handa@m17n.org>
+
+       * font.c (xlfd_unparse_name): New arg full_xlfd.
+       (mfont__encode_char): Use shortcut only for X core fonts.
+       (mfont_unparse_name): Call xlfd_unparse_name with full_xlfd arg 1.
+       (mfont_put_prop): Handle `language' property.
+       (mdebug_dump_font): Call xlfd_unparse_name with full_xlfd arg 0.
+       Print file can capability info too.
+
+       * m17n-core.c (mdebug__output): New variable.
+       (SET_DEBUG_FLAG): Unset mask if env_value is '0'.
+       (m17n_init_core): Handle MDEBUG_ALL and MDEBUG_OUTPUT_FILE.
+       (m17n_fini_core): Close mdebug__output if it's not stderr.
+
+       * m17n-X.c (MDisplayInfo): New member MULE_BASELINE_OFFSET.
+       (xfont_open): Handle baseline_offset.
+       (xfont_find_metric): Likewise.
+       (xfont_render): Likewise.
+       (xft_open): Likewise.
+       (xft_render): Likewise.
+
+       * internal.h (MDebugMaskBit): Add MDEBUG_ALL.
+       (mdebug__output): Extern it.
+       (MDEBUG_PRINT, MDEBUG_PRINT1, MDEBUG_PRINT2, MDEBUG_PRINT3)
+       (MDEBUG_PRINT4, MDEBUG_PRINT5): Print to medebug__output.
+       (MDEBUG_DUMP): New macro.
+       (MDEBUG_PRINT_TIME): Print to medebug__output.
+
+       * font.h (MRealizedFont): New member baseline_offset.
+
+       * font-ft.c (ft_get_charmaps): Check if the font support iso8859-1
+       characters.
+       (fc_weight_table): Add FC_WEIGHT_REGULAR.
+       (ft_list_family): Check alias.
+       (ft_list_language): If language is "en", don't try to the second
+       step.
+       (ft_default_list): New variable.
+       (ft_list_default): New function.
+       (ft_select): If family is not specified, try only the default
+       fonts.  Treat the weights normal and medium same.
+       (ft_open): Fix debug message.  If registry is not specified, try
+       unicode-bmp.  Handle _MULE_BASELINE_OFFSET property of BDF fonts.
+       (ft_find_metric): Likewise.
+       (ft_render): Likewise.
+       (ft_list): Fix debug message.  Accept the registring iso8859-1.
+       If family is not specified, try only the default fonts.
+
+       * face.c (mface__realize): Fix logic of opening a font.
+
+2005-09-16  Kenichi Handa  <handa@m17n.org>
+
+       * face.c (mface__realize): 
+
+       * m17n.h (Minput_focus_move, Minput_focus_in, Minput_focus_out):
+       Extern them.
+
+       * input.c (shift_state): Fix the condition of taking init actions.
+       (take_action_list): Fix handling of pushback action.
+       (handle_key): Don't change key while checking its alias.
+       (minput__init): Initialize new variables.
+       (Minput_focus_move, Minput_focus_in, Minput_focus_out): New
+       variables.
+
+2005-09-12  Kenichi Handa  <handa@m17n.org>
+
+       * mtext.c (mtext__uppercase): Add proper open/close parens.
+       (mtext_titlecase): Add proper casting.
+
+       * input.c (parse_action_list): Handle the case that the arg is a
+       key sequence (MText or MPlist).
+       (take_action_list): Likewise.
+       (shift_state): Shorter debug message.
+       (handle_key): Terminate a debug message by "\n".
+       (reset_ic): Don't take initial actions here.
+       (minput_open_im): Print a debug message.
+       (minput_close_im): Likewise.
+       (minput_create_ic): Likewise.
+       (minput_destroy_ic): Likewise.
+
+2005-09-09  TAKAHASHI Naoto  <ntakahas@m17n.org>
+
+       * mtext.c (mtext_lowercase, mtext_titlecase, mtext_uppercase):
+       Change API.
+
+2005-09-07  TAKAHASHI Naoto  <ntakahas@m17n.org>
+       * character.c: Add "cased", "soft-dotted", and "case-mapping" in
+       mchar__init ().
+
+       * character.c: Add Japanese documentation for
+       mchar_get_prop_table ().
+
+2005-09-06  TAKAHASHI Naoto  <ntakahas@m17n.org>
+
+       * mtext.c (tricky_chars, *cased, *soft_dotted, *case_mapping)
+       (MCharTable *combining_class, Mlt, Mtr, Maz, gr03A3, lt0049,
+       (lt004A, lt012E, lt00CC, lt00CD, lt0128, tr0130, tr0049, tr0069):
+       New variables.
+       (init_case_conversion): New function.
+       (CASE_CONV_INIT, REPLACE, DELETE, LOOKUP): New macros.
+       (uppercase_precheck, lowercase_precheck, final_sigma)
+       (after_soft_dotted, more_above, before_dot, after_i)
+       (mtext_uppercase, mtext_titlecase, mtext_lowercase): New functions.
+
+2005-09-05  TAKAHASHI Naoto  <ntakahas@m17n.org>
+
+       * plist.c (read_mtext_element): Fix previous change.
+
+2005-09-05  Kenichi Handa  <handa@m17n.org>
+
+       * plist.c (read_mtext_element): Handle \uXXXX notation.
+
+       * internal.h (MTABLE_MALLOC): Don't use a local variable.
+       (MTABLE_ALLOCA): Change the name of local variable.
+
+       * m17n-gd.c (device_open): Define it even if HAVE_GD nor
+       HAVE_FREETYPE are defined.
+
+       * m17n-X.c: Check HAVE_X11.
+
+       * Makefile.am (X_LD_FLAGS): Use @X11_LD_FLAGS@ instead of
+       directory listing libraries.
+       (noinst_PROGRAMS): Define it only in maintainer mode.
+
+2005-09-02  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.h (mdraw_line_break_option): Extern it.
+
+       * draw.c (truncate_gstring): Use find_glyph_in_gstring to find the
+       end of the first glyph.
+       (GET_LB_TYPE, find_break_backward, find_break_forward): Delete
+       them.
+       (mdraw_line_break_option): New variable.
+       (mdraw_default_line_break): Use mtext_line_break.
+
+       * mtext.h (wordseg_func_table): Don't extern it.
+       (mtext__wseg_fini): Extern it.
+
+       * mtext.c: Don't include word-thai.h.
+       (wordseg_func_table): Delete this variable.
+       (mtext__init): Don't initialize above.  Don't call
+       mtext__word_thai_init.
+       (mtext__fini): Don't free wordseg_func_table.  Call
+       mtext__wseg_fini instead fo mtext__word_thai_fini.
+       (MTextWordsegFunc): Don't typedef it.
+       (mtext__word_segment): Moved to mtext-wseg.c.
+
+       * m17n-core.h (enum MTextLineBreakOption): New enum.
+       (mtext_line_break): Extern it.
+
+       * mtext-wseg.c: New file.
+
+       * mtext-lbrk.c: New file.
+
+       * Makefile.am (libm17n_core_la_SOURCES): Delete word-thai.[ch],
+       add mtext-lbrk.c and mtext-wseg.c.
+
+       * textprop.c (mtext__adjust_plist_for_change): Pay attention for
+       the case that head is NULL.
+
+2005-09-01  Kenichi Handa  <handa@m17n.org>
+
+       * word-thai.c (wordseg_propertize): If the property value is nil,
+       don't make the property no-merge.
+       (thai_wordseg): Don't require *from and *to are set a priori.  Pay
+       attention to the case that they are NULL.
+       (mtext__word_thai_init): Make the name of Mthai_wordseg starts
+       with two spaces.
+
+       * character.c (mchar_get_prop_table): New function.
+
+       * textprop.h (mtext__adjust_plist_for_change): Prototype adjusted.
+
+       * m17n-core.h (mtext_insert, mtext_replace): Extern them.
+       (mchar_get_prop_table): Extern it.
+
+       * textprop.c (prepare_to_modify): New arg deleting.  Callers changed.
+       (mtext__adjust_plist_for_change): Argument changed.  Callers changed.
+
+       * internal.h (enum MTextCoverage): New enum.
+       (MText): New member coverage.
+
+       * mtext.c (FORMAT_COVERAGE): New macro.
+       (insert): Copy mt2->coverage.
+       (mtext__from_data): Initialize mt->coverage.
+       (mtext__adjust_format): Update mt->coverage.
+       (mtext): Initialize mt->coverage.
+       (mtext_set_char): Adjust args to mtext__adjust_plist_for_change.
+       Update mt->coverage if necessary.
+       (mtext_duplicate): Copy mt->coverage.
+       (mtext_insert, mtext_replace): New functions.
+       (mtext_dup): Use mtext_duplicate.
+       (mtext__word_segment): Don't set *from and *to if a word
+       segmentation funcion is not found.
+       (mtext_ins_char): Fix typo.
+
+2005-08-25  Kenichi Handa  <handa@m17n.org>
+
+       * font.h (MFont): New member for_full_width.
+
+       * font.c (compare_font_score): Prefer a font of not
+       for_full_width.
+
+       * m17n-X.c (xfont_registry_list): Set font.for_full_width if the
+       registry charset of a font is one of CJK charsets.
+
+       * font-ft.c (fc_parse_pattern): Set font->for_full_width if a font
+       supports some of CJK.
+
+2005-08-24  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.h (Mascent, Mdescent): Don't extern them.
+
+       * m17n-gui.c (null_device_open): Check Mresolution param and set
+       frame->dpi.
+
+       * m17n-gd.c (device_open): Check Mresolution param and set
+       frame->dpi.
+
+       * m17n-X.c (MWDevice): New member resy.
+       (xfont_open): Set ascent, descent, and max_advance members of
+       rfont.
+       (xft_open): Likewise.
+       (device_open): Compare also screen_num to find a device.  Set
+       device->resy and frame->dpi.
+
+       * internal-gui.h (MFrame): New member dpi.
+
+       * font.h (MRealizedFont): New member max_advance.
+
+       * font.c (xlfd_unparse_name): Handle the case of font->size < 0.
+       (mfont__init): Don't initialize Mascent, Mdescent.
+       (Mascent, Mdescent): Delete these variables.
+       (mfont_get_prop): Fix previous change.  Check Mfont_ascent and
+       Mfont_descent instead of Mascent and Mdescent.
+       (mfont_put_prop): Allow negative size.
+       (mfont_find): Handle the case of spec->size < 0.  Fix previous
+       change.
+       (mfont_list): Handle the case of spec->size < 0.
+       (mfont_check): Likewise.
+
+       * font-ft.c (STRDUP_LOWER): Ignore the tailing spaces.
+       (fc_get_pattern): Handle the case of font->size < 0.
+       (ft_open): Set ascent, descent, and max_advance members of rfont.
+       (ft_find_metric): Improve rounding.
+       (mfont__ft_parse_name): If FC_PIXEL_SIZE is not available, set
+       FC_SIZE.
+
+       * face.c (mface__realize): Handle the case of font->size < 0.
+
+2005-08-22  Kenichi Handa  <handa@m17n.org>
+
+       * coding.c (MConverterStatus): Change the member buf to union.
+       (mconv_buffer_converter): Add const to the arg buf.
+       (mconv_decode_buffer, mconv_rebind_buffer): Likewise.
+       (mconv_decode): Adjusted for the change of MConverterStatus.
+       (mconv_encode_range): Likewise.
+
+       * m17n.h (mconv_buffer_converter): Prototype adjusted.
+       (mconv_decode_buffer, mconv_rebind_buffer): Likewise.
+
+2005-08-20  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.h (mfont_from_name): Prototype adjusted.
+       (Mspacing, Mascent, Mdescent, Mmax_advance): Extern them.
+
+       * m17n-X.c (xfont_open): Set members ascent, descent, and
+       max_advance of rfont.
+       (xft_open): Likewise.
+
+       * font-ft.c (ft_open): Set members ascent, descent, and max_advance
+       of rfont.
+       (mfont__ft_parse_name): Add const to the arg name.
+
+       * font.c (xlfd_parse_name): Add const to the arg name.  Call
+       mfont__set_property instead of mfont_set_spec.  Set font->spacing.
+       (xlfd_unparse_name): Handle spacing.
+       (mfont__init): Initialize new variables.
+       (mfont__id): Handle spacing.
+       (mfont__merge): Likewise.
+       (mfont__set_spec): This function deleted.
+       (mfont__parse_name_into_font): Add const to the arg name.  Fix the
+       condition of calling mfont__ft_parse_name.
+       (Mspacing, Mascent, Mdescent, Mmax_advance): New variables.
+       (mfont_get_prop): Handle properties spacing, ascent, descent,
+       and max-advance.
+       (mfont_find): Return a realized font.
+       (mfont_from_name): Add const to the arg name.
+
+       * font.h (enum MFontProperty): New member MFONT_SPACING.
+       (enum MFontSpacing): New enum.
+       (MFont): New members spacing and max_advance.
+       (mfont__ft_parse_name): Prototype adjusted.
+       (mfont__set_spec): Extern deleted.
+       (mfont__parse_name_into_font): Prototype adjusted.
+
+2005-08-19  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.h (mfont_parse_name): Prototype adjusted.
+
+       * font.c (mfont_list): If FONT is null, use a temporary font.
+       (mfont_parse_name): Add const to the arg name.
+
+2005-08-18  Kenichi Handa  <handa@m17n.org>
+
+       * word-thai.c: Surround code by #ifdef and #endif to escape from
+       doxygen.
+
+       * font-ft.c: Mostly re-written.
+
+       * font-flt.c (FontLayoutCmdOTF): This type deleted.
+       (FontLayoutCmd): Type of the member otf changed..
+       (load_otf_command): Adjusted for the format change of otf command.
+       (load_command): Likewise.
+       (free_flt_command): Unref cmd->body.otf.
+       (run_otf): Ajusted for the type change of otf_cmd.
+       (run_command): Ajusted for the type change of otf_cmd.  On
+       debugging, print ctx->combining_code.
+       (mfont__flt_run): Initialize ctx's members code_offset,
+       combining_code, and left_padding to 0.
+
+       * face.h (struct MRealizedFace): New member font.
+       (mface__realize): Prototype adjusted.
+
+       * face.c (find_realized_face): New arg font.
+       (find_realized_face): Adjusted for the change of MFont.
+       (mface__init): Call M17N_OBJECT_ADD_ARRAY.
+       (mface__fini): Don't call mdebug__report_object.
+       (mface__realize): New arg font.
+       (mface__for_chars): Adjusted for the change of mfont__encode_char.
+       Optimize the latin case.
+       (mface__free_realized): Free rface->font.
+       (mface__update_frame_face): Adjusted for the change of mface__realize.
+       (mface_equal): New function.
+
+       * draw.c (Mcommon): New variable.
+       (visual_order): Args to mfont__encode_char changed.
+       (compose_glyph_string): Handle Mfont text property.
+       (layout_glyphs): Adjusted for the change of MFont.
+       (mdraw__init): Initialize Mcommon.
+       (mdraw_glyph_info): Adjusted for the change of MRealizedFont.
+
+       * font.h (enum MFontType): Members completely changed.
+       (enum MFontProperty): Move MFONT_SIZE to the tail.
+       (enum MFontSource): New enum.
+       (struct MFont): New members type, source, sizes, file, capability,
+       and encoding.
+       (struct MRealizedFont): Type of member font changed. Members
+       score, status, and encoding deleted.
+       (MFontScore): New type.
+       (MFontList): Member changed.
+       (struct MFontDriver): New member has_char.  Types of members
+       changed.
+       (Miso8859_1, Miso10646_1, Municode_bmp, Municode_full)
+       (Mapple_roman): Extern them.
+       (OTF_Tag): Typedefed if not HAVE_OTF.
+       (enum MFontOpenTypeTable): New enum.
+       (MFontCapability): New type.
+       (mfont__ft_drive_otf): Prototype adjusted.
+       (mfont__score): Extern deleted.
+       (mfont__merge): Extern it.
+       (mfont__has_char): Extern it.
+       (mfont__encode_char): Prototype adjusted.
+       (mfont__open): Extern it.
+       (mfont__set_spec): Prototype adjusted.
+       (mfont__get_capability): Extern it.
+
+       * font.c: Include "fontset.h".
+       (M_font_capability, M_font_list, M_font_list_len): New variables.
+       (font_score_priority): Change order of initial elements.
+       (font_score_shift_bits): Fix array size.
+       (common_weight): Add "thin", "semibold", and "heavy".
+       (common_stretch): Add "ultracondensed", "extracondensed",
+       "extraexpanded", and "utltraexpand".
+       (font_weight_regular, font_weight_normal, font_weight_medium): New
+       variables.
+       (gen_font_name): This function deleted.
+       (find_encoding): Set font->encoding.
+       (OTF_tag): New function.
+       (otf_script_list): New variable.
+       (load_otf_script_list): New function.
+       (find_script_from_otf_tag): New function.
+       (xlfd_parse_name): Set font->type and font->source.
+       (mfont__free_realized): Free chains rfonts.
+       (font_score): Renamed from mfont__score.
+       (Miso8859_1, Miso10646_1, Municode_bmp, Municode_full)
+       (Mapple_roman): New variables.
+       (mfont__init): Initilize new variables.  Initalize
+       default_encoding.encoding_name and
+       default_encoding.encoding_charset to Municode_full and
+       mcharset__unicode.  Use SAFE* macros for allocating filepath
+       buffer.
+       (mfont__fini): Free otf_script_list.
+       (mfont__id): New function.
+       (mfont__match_p): Check also capability member of MFont.
+       (mfont__merge): New funciton.
+       (mfont__set_spec_from_face): Set type and source members.
+       (mfont__set_spec_from_plist): Set capability and type members.
+       (mfont__select): Argument changed.
+       (mfont__available): New function.
+       (compare_font_score): New function.
+       (mfont__list): New function.
+       (mfont__open): Return a realized font.
+       (mfont__resize): Adjusted for the change of MFont.
+       (mfont__has_char): New function.
+       (mfont__encode_char): Argument changed.
+       (mfont__set_spec): Argument changed.
+       (free_font_capability): New function.
+       (mfont__get_capability): New function.
+       (MFontfile): New variable.
+       (mfont_get_prop): Adjusted for the change of MFont.
+       (mfont_put_prop): Likewise.
+       (mfont_set_selection_priority): Fix the way of setting
+       font_score_priority[].
+       (mfont_find): Use mfont__list instead of mfont__select.
+       (mfont_resize_ratio): Adjusted for the change of MFont.
+       (mfont_list): Use mfont__list.
+       (mfont_check): New function.
+       (font_score): Make it static.
+
+       * fontset.h (mfont__realize_fontset): Prototype adjusted.
+       (mfont__lookup_fontset): Likewise.
+
+       * fontset.c (struct MFontset): Delete member font_spec_list.
+       (struct MRealizedFontset): Type of member spec changed.  New
+       member request.
+       (load_font_group): Arg spec_list deleted.
+       (load_fontset_contents): Adjusted for the change of fontset_def.
+       (free_fontset): Fix the way of freeing fontset elements.
+       (realize_fontset_elements): Argument changed.
+       (get_per_script): New function.
+       (free_realized_fontset_elements): Fix the way of feeing rfontset
+       elements.
+       (update_fontset_elements): Fix args to realize_fontset_elements.
+       (mfont__realize_fontset): New arg spec.
+       (try_font_list): New function.
+       (try_font_group): New arg request.  Use try_font_list.
+       (mfont__lookup_fontset): New arg ignore_fallback.  Fix arg to
+       try_font_group.
+       (mfontset): Adjusted for the change of MFontset.
+       (mfontset_copy): Likewise.  Don't share plists.
+       (mfontset_modify_entry): Adjusted for the change of MFontset.
+       (mfontset_lookup): Call get_per_script.
+       (mdebug_dump_fontset): Print also the address of fonts.
+
+       * input.c (shift_state): Don't reset ic_info->vars.
+       (take_action_list): Call MDEBUG_PRINT fore calling
+       take_action_list.
+
+       * internal-gui.h (MFontDriver): Don't typedef it here.
+
+       * m17n-X.c: Include <fontconfig/fcfreetype.h> if HAVE_XFT2.
+       (MXFont): This type deleted.
+       (MFontX): New type.
+       (struct _MFontX): New struct.
+       (SET_SIZE, HAVE_SIZE): Adjusted for the change of arg FONTX.
+       (MDisplayInfo): Member base_font_list deleted.
+       (DEFAULT_FONT): Definition changed.
+       (FALLBACK_FONT): This maclr deleted.
+       (free_display_info): Adjusted for the change of MDisplayInfo.
+       (free_device): Argument to mfont__free_realized changed.
+       (xfont_driver): Adjusted for the change of MFontDriver.
+       (xfont_registry_list): Use MFontX instead of MXFont.
+       (MRealizedFontX): Renamed from MXFontInfo.
+       (xfont_select): Return the font found first.
+       (close_xfont): Change MXFontInfo to MRealizedFontX.
+       (xfont_open): Return the realized font.
+       (xfont_find_metric): Get xfont from rfont->fontp.
+       (xfont_has_char): New function.
+       (xfont_encode_char): Adjusted for the argument change.
+       (xfont_render): Get xfont from rfont->fontp.
+       (xfont_list): Adjusted for the argument change.
+       (MRealizedFontXft): Renamed from MXftFontInfo.
+       (xft_driver): Ajusted for the change of MFontDriver.
+       (close_xft): Change MXtfFontInfo to MRealizedFontXft
+       (xft_open_font): Argument changed.
+       (xft_open): Argument changed.  Return the realized font.
+       (xft_find_metric): Get xft_font from rfont->fontp.
+       (xft_has_char, xft_encode_char): New functions.
+       (xft_render): Change MXftFontInfo to MRealizedFontXft.  Open a
+       font if not yet opened.
+       (device_open): Don't set frame->font.
+
+       * m17n-gd.c (gd_font_driver): Adjusted for the change of
+       MFontDriver.
+       (gd_font_open): New function.
+       (gd_render): Don't use the local variable ft_info.
+       (device_init): Adjusted for the change of gd_font_driver.
+
+       * textprop.c (mtext__prop_init): Initialize text_property_table.
+       Call M17N_OBJECT_ADD_ARRAY.
+       (mtext__prop_fini): Don't call mdebug__report_object.
+
+       * plist.c (mplist__init): Initialize plist_table.
+       (mplist__init): Call M17N_OBJECT_ADD_ARRAY.
+       (mplist__fini): Don't call mdebug__report_object.
+
+       * mtext.c (mtext__init): Call M17N_OBJECT_ADD_ARRAY.
+       (mtext__fini): Don't call mdebug__report_object.
+       (MTEXT_FORMAT_UTF_16): Correct type.
+       (mtext_data): New function.
+       (mtext_text): Fix calculation of limit and args to
+       find_char_backward.
+
+       * language.c: Include "plist.h".
+       (M_script_lang_list): New variable.
+       (mlang__init): Read languages and their information from m17n
+       database.
+       (mlanguage__list): New function.
+       (Miso639_1, Miso639_2): New variables.
+
+       * language.h (mlanguage__list): Extern it.
+
+       * database.c (get_database_stream): Use SAFE_* macros for
+       allocating and freeing path.
+       (mdatabase__init): Likewise.
+
+       * symbol.c (msymbol__fini): Don't free symbols here.
+       (msymbol__free_table): New function.
+       (msymbol_is_managing_key): New function.
+
+       * symbol.h (msymbol__free_table): Extern it.
+       (msymbol__list): Extern it.
+
+       * internal.h (MFATAL, USE_SAFE_ALLOCA, SAFE_ALLOCA, SAFE_FREE):
+       New macros.
+       (M17N_OBJECT_UNREF): Change "if ... else ..." structure.
+       (struct _M17NObjectArray): New member name and next.
+       (mdebug__add_object_array): Extern it.
+       (M17N_OBJECT_ADD_ARRAY): New macro.
+       (mdebug__report_object): Don't extern it.
+
+       * m17n-misc.h (enum MErrorCode): New element MERROR_FONT_X.
+
+       * m17n-gui.c (free_frame): Don't free frame->font.
+       (null_device_fini): Fix code for freeing
+       null_device.realized_font_list.
+       (m17n_fini_win): Free interface.
+       (mframe): Cast the return value of dlsym.  Set frame->font here.
+       (mframe_get_prop): Check frame->rface->rfont before accessing the
+       member font.
+
+       * m17n-gui.h (Mfontfile): Extern it.
+       (mfont_check): Extern it.
+       (mface_equal): Extern it.
+
+       * m17n-core.c: Include "symbol.h".
+       (report_header_printed): This variable deleted.
+       (object_array_root): New variable.
+       (report_object_array): New function.
+       (mdebug__report_object): This function deleted.
+       (mdebug__add_object_array): New function.
+       (m17n_init_core): Call mchartable_init () before mtext_init ().
+       (m17n_fini_core): Call report_object_array (if necessary) and
+       msymbol__free_atable at the end.
+
+       * m17n-core.h (msymbol_is_managing_key): Extern it.
+       (mtext_data): Extern it.
+       (MTEXT_FORMAT_UTF_16): Correct type.
+       (M17NLIB_MINOR_VERSION): Changed to 3.
+       (M17NLIB_VERSION_NAME): Changed to "1.3.0".
+
+       * chartab.c (mchartable__init): Initalize chartable_table.count.
+       (mchartable__fini): Use N17N_OBJECT_ADD_ARRAY instead of
+       mdebug__report_object.
+
+2005-05-26  Kenichi Handa  <handa@m17n.org>
+
+       * m17n.h (Miso639_1, Miso639_2): Extern them.
+
+       * symbol.h (msymbol__list): Extern it.
+
+       * symbol.c (msymbol__list): New function.
+
+2005-05-19  Kenichi Handa  <handa@m17n.org>
+
+       * input-gui.c (minput__win_init): Don't change the value of
+       minput_driver.
+
+2005-05-16  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.c (m17n_object): Be sure to initialize all members.
+
+       * font-ft.c (fc_decode_prop): Fix args to msymbol.
+
+2005-05-09  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (mwin__close_device): Fix arg to M17N_OBJECT_UNREF.
+
+2005-04-27  Kenichi Handa  <handa@m17n.org>
+
+       * language.c (mlang__init): Add "an" (Aragonese).
+
+       * word-thai.c: Add support for libthai.
+       (mtext__word_thai_init): Initialize wordseg library conditionaly.
+       (mtext__word_thai_fini): Finalize wordseg library conditionaly.
+
+       * mtext.c: Include "word-thai.h" conditionaly.
+       (mtext__init): Call mtext__word_thai_init conditionaly.
+       (mtext__fini): Call mtext__word_thai_fini conditionaly.
+
+       * Makefile.am (libm17n_core_la_LIBADD): Add THAI_WORDSEG_LD_FLAGS,
+       not WORDCUT_LD_FLAGS.
+
+2005-04-19  Kenichi Handa  <handa@m17n.org>
+
+       * word-thai.c (wordseg_propertize): Always unref the attached
+       property.
+       (thai_wordseg): Don't unref the property.
+
+2005-04-18  Kenichi Handa  <handa@m17n.org>
+
+       * word-thai.c: Include stdlib.h.
+       (wordseg_propertize): Add dummy function for the case that wordcut
+       library doesn't exist.
+       (wordseg_propertize): Fix for old wordcut library.
+
+2005-04-16  Kenichi Handa  <handa@m17n.org>
+
+       * word-thai.c: Include <stdio.h>.
+
+2005-04-15  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c: Include mtext.h.
+       (linebreak_table, M_break_at_space, M_break_at_word)
+       (M_break_at_any, M_kinsoku_bol, M_kinsoku_eol): New variables.
+       (compose_glyph_string): Check POS before getting Mface text
+       property.
+       (truncate_gstring): Give correct TO arg to line_break function.
+       (GET_LB_TYPE): New macro.
+       (find_break_backward, find_break_forward): New functions.
+       (mdraw__init): Initialize the above new variables.
+       (mdraw__fini): Free linebreak_table.
+       (mdraw_default_line_break): Use find_break_backward and
+       find_break_forward.
+
+       * word-thai.c: New file.
+
+       * word-thai.h: New file.
+
+       * mtext.c: Include word-thai.h.
+       (wordseg_func_table): New variable.
+       (mtext__init): Initialize wordseg_func_table and call
+       mtext__word_thai_init.
+       (mtext__fini): Call mtext__word_thai_fini, free
+       wordseg_func_table.
+       (MTextWordsegFunc): New type.
+       (mtext__word_segment): New function.
+
+       * mtext.h (wordseg_func_table): Extern it.
+       (mtext__word_segment): Extern it.
+
+       * m17n.c (m17n_init): Fix typo (== -> =).
+
+       * Makefile.am (libm17n_core_la_SOURCES): Include word-thai.[ch].
+       (libm17n_core_la_LIBADD): Add @WORDCUT_LD_FLAGS@.
+
+       * textprop.h (MTEXTPROP_START, MTEXTPROP_END, MTEXTPROP_KEY)
+       (MTEXTPROP_VAL): New macros.
+
+       * input.c (DLOPEN_SHLIB_EXT): Don't define it.
+
+2005-04-07  Kenichi Handa  <handa@m17n.org>
+
+       * database.c (load_chartable): Fix pursing of symbol name.
+
+2005-03-24  Kenichi Handa  <handa@m17n.org>
+
+       * m17n.c (m17n_init): Fix typo (== -> =).
+
+2005-03-11  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.c (m17n_init_win): Set merror_code to MERROR_NONE at first.
+
+       * m17n.c (m17n_init): Set merror_code to MERROR_NONE at first.
+
+       * m17n-core.c (m17n_init_core): Set merror_code to MERROR_NONE at
+       first.
+
+2005-03-09  handa  <handa@m17n.org>
+
+       * m17n-gui.c (m17n_init_win): Set merror_code to MERROR_NONE before
+       calling m17n_init ().
+
+       * m17n.c (m17n_init): Set merror_code to MERROR_NONE before
+       calling m17n_init_core ().
+
+2005-02-28  Kenichi Handa  <handa@m17n.org>
+
+       * font-flt.c (mfont__flt_run): Add resulting code sequence in
+       debug info.
+
+2005-02-17  Kenichi Handa  <handa@m17n.org>
+
+       * input.c: Include <sys/types.h>, <dirent.h>, and "database.h".
+       (M_description, M_command, M_variable): New variables.
+       (load_im_info_keys): New variables.
+       (load_im_info, check_command_keyseq, get_description_advance)
+       (parse_command_list, get_command_list, parse_variable_list)
+       (get_variable_list, input_method_hook): New functions.
+       (command_list, variable_list): New variables.
+       (minput__init): Put input_method_hook to Minput_method.
+       Initialize M_description, M_command, M_variable, Mdetail_text,
+       load_im_info_keys, command_list, variable_list.
+       (minput__fini): Unref command_list, variable_list, load_im_info_keys.
+       (Mdetail_text): New variable.
+       (minput_get_description, minput_get_commands)
+       (minput_assign_command_keys, minput_get_variables)
+       (minput_set_variable): New functions.
+
+       * m17n.h (Mdetail_text, minput_get_description, minput_get_commands)
+       (minput_assign_command_keys, minput_get_variables)
+       (minput_set_variable): Extern them.
+
+       * plist.c (UNGETC): Just decrement st->p.
+       (read_mtext_element): New arg skip.
+       (read_integer_element): Likewise.
+       (read_symbol_element): Likewise.
+       (read_element): New arg KEYS.
+       (mplist__from_plist): Don't increment ref-count of NULL object.
+       (mplist__from_file): New arg KEYS.
+       (mplist_put): Don't increment ref-count of NULL object.
+       (mplist_add): Likewise.
+       (mplist_push): Likewise.
+       (mplist_set): Likewise.  Call M17N_OBJECT_UNREF unconditionally.
+
+       * plist.h (mplist__from_file): Prototype adjusted.
+
+       * database.c (mdatabase__dir_list): Renamed from mdb_dir_list.
+       (get_database_stream): New function.
+       (load_database): Use get_database_stream.
+       (M_database_hook): New variable
+       (mdatabase__init): Initialize M_database_hook.
+       (mdatabase__load_for_keys): New function.
+       (mdatabase_find, mdatabase_list, mdatabase_define): Check hook
+       function.
+       (mdatabase_define): Free mdb->extra_info if necessary.
+
+       * database.h (mdatabase__dir_list, M_database_hook)
+       (mdatabase__load_for_keys): Extern them.
+       (MDatabaseHookFunc): New type.
+
+       * internal.h (M17N_OBJECT_UNREF): When freed, set OBJECT to NULL.
+
+2004-12-27  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.2.0 released.
+
+2004-12-27  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (minput_filter): Don't reset ic->xxx_changed.
+
+       * mtext.c (mtext_from_data): Fix documentation.
+
+2004-12-25  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.h (M17NLIB_MINOR_VERSION): Update to 2.
+       (M17NLIB_VERSION_NAME): Update to "1.2.".
+
+2004-12-24  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (reset_ic): Set key_unhandled to 0.
+
+2004-12-21  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.h (mfont_from_spec): Delete extern.
+
+       * input-gui.c (win_callback): Handle Minput_reset.
+       (minput__win_init): Register reset_ic as a callback for
+       Minput_reset.
+
+       * input.c (reset_ic): New arg IGNORE which is ignored.  Caller
+       changed.  At first, shift to the initial state.
+       (minput__init): Initialize Minput_reset.  Register reset_ic as a
+       callback for Minput_reset.
+       (Minput_reset): New variable.
+       (minput_filter): Always set ic->xxx_changed to 0.
+       (minput_reset_ic): New function.
+       (integer_value): Fix typo ('>' -> '<') and calculation of length
+       of preedit text.
+
+       * m17n-core.c (merror_code): Change type to `int'.
+
+       * m17n-misc.h (merror_code): Adjust type.
+
+       * m17n.h (Minput_reset, minput_reset_ic): Extern them.
+
+       * m17n-core.h (MTEXT_FORMAT_UTF_16, MTEXT_FORMAT_UTF_32): Adjust types.
+       (mtext_change_prop): Delete extern.
+
+       * mtext.c (MTEXT_FORMAT_UTF_16, MTEXT_FORMAT_UTF_32): Change types
+       to `int'.  Move the documents to m17n-core.h.
+
+2004-12-13  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.h (m17n_object): Rename extern from m17n_object_setup.
+       (MTextProperty): Document it.
+
+2004-12-09  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.h: Fix typo (MTextStatus -> M17NStatus).
+
+2004-12-03  Kenichi Handa  <handa@m17n.org>
+
+       * internal.h (m17n__core_initialized, m17n__shell_initialized,
+       m17n__gui_initialized): New externs.
+
+       * m17n-core.h (enum M17NStatus): New enum.
+       (m17n_status): Extern it.
+
+       * m17n-core.c (core_initialized): Delete this variable.
+       (m17n__core_initialized, m17n__shell_initialized,
+       m17n__gui_initialized): New variables.
+       (m17n_init_core, m17n_fini_core): Check m17n__core_initialized
+       instead of core_initialized.
+       (m17n_status): New function.
+
+       * m17n.c (shell_initialized): Delete this variable.
+       (m17n_init, m17n_fini): Check m17n__shell_initialized instead of
+       shell_initialized.
+
+       * m17n-gui.h (m17n_init_win): Adjust the prototype.
+
+       * m17n-gui.c (win_initialized): Delete this variable.
+       (m17n_init_win, m17n_fini_win): Check m17n__gui_initialized
+       instead of gui_initialized.
+
+2004-11-19  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (reset_ic): Check if ic_info->state is NULL.
+       (filter): If ic_info->state is NULL, return 0.
+       (load_input_method): Don't unref `maps' it it's not created.
+
+2004-11-15  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (find_candidates_group): If INDEX is -1, find the last
+       candidate group.
+       (take_action_list): If the previous of the first candidate is
+       requested, select the last candidate.
+
+2004-11-08  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (device_open): Try at most 32 fonts to find a
+       non-autoscaled font.
+
+       * font.c (xlfd_parse_name): Fix previous change.
+
+2004-11-05  Kenichi Handa  <handa@m17n.org>
+
+       * font.c: (commont_style): Include dummy elements "slanted" and
+       "rslanted" to prefer "o" to "r" if "i" is requested.
+
+       * font-ft.c (ft_to_prop): Fix "oblique" entry.
+
+2004-10-29  Kenichi Handa  <handa@m17n.org>
+
+       * font.c (xlfd_parse_name): If avgwidth is 0, set the size to 0.
+
+       * m17n-X.c (MXFont): Change type of the member `sizes' to int.
+       New members smallest and larger.
+       (SET_SIZE, HAVE_SIZE): Adjusted for the above change.
+       (xfont_registry_list): Likewise.
+       (xfont_select): Likewise.
+       
+
+2004-10-28  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (xfont_registry_list): Include '-' before PIXEL_SIZE in
+       font name comparison.
+       (xfont_select): Fix logic for selecting a larger size font.
+
+2004-10-25  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (take_action_list): Initialize `ret' to 0 for "=", "<",
+       ">" actions.
+
+2004-10-22  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (update_candidate): Renamed from udpate_candidate.
+       (take_action_list): Show more debugging info on arithmetic commands.
+
+       * m17n-X.c (device_open): Fix previous change.
+
+       * draw.c (compose_glyph_string): Don't get face property at the
+       end of M-text.
+
+2004-10-21  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (compose_glyph_string): Fix for the case of category
+       being Mnil.
+
+2004-10-19  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (mdebug_mask): New variable.
+       (shift_state): Print debug information.
+       (take_action_list): Likewise.
+       (handle_key): Likewise.
+
+2004-10-14  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (device_open): Accept Mxft as the value of key Mfont.
+
+2004-10-13  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (device_open): Be sure to register at least one font
+       driver.
+
+       * font-ft.c: Include <freetype/ftbdf.h> conditionally.  Check
+       HAVE_FTBDF_H before calling FT_Get_BDF_Property.
+
+2004-10-12  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (alloc_gstring): Fix previous change.
+
+       * font-ft.c (ft_list_generic): Fix for the case of not
+       HAVE_FONTCONFIG.
+
+       * m17n-X.c (mwin__parse_event): Fix for non-ASCII keys.
+
+       * font.c (mfont_list): If no font is found, return NULL.
+       (load_font_encoding_table): Put entries of nil registry first.
+       (find_encoding): Adjust for the above change.
+
+2004-10-11  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.h (mfont_list): Adjust prototype.
+
+       * m17n-X.c (xfont_list): New arg maxnum.
+
+       * font.h (struct MFontDriver): Change prototype of <list>.
+
+       * font-ft.c (fc_generic_family_list): Delete it.
+       (Mserif, Msans_serif, Mmonospace): Delete them.
+       (M_generic_family_info): New variable.
+       (enum GenericFamilyType): New enum.
+       (struct GenericFamilyInfo): New struct.
+       (generic_family_table): New variable.
+       (set_font_info): New arg style. Don't check 0xA0..0xBF to decide
+       iso8859-1.
+       (add_font_info): Get style here.
+       (ft_list_family): Don't initialize fc_config here.  Don't list
+       generic families.
+       (ft_list_generic): New function.
+       (ft_select): Pay attention to generic familes here.
+       (ft_open): Fix calculation of ascent and descent.
+       (ft_list): Pay attention to generic families.
+       (mfont__ft_init): Initialize M_generic_family_info,
+       generic_family_table, and fc_config..
+       (mfont__ft_fini): Finalize generic_family_table.
+
+       * draw.c (compose_glyph_string): Use more constant font for
+       glyphs.  Adjust for the member change in MGlyph.
+       (layout_glyph_string): Adjust for the member change in MGlyph.
+       (alloc_gstring): Intilize scracth_glyph to avoid
+       compose_glyph_string on it.
+       (get_gstring): Don't call compose_glyph_string on scracth_glyph.
+       (mdraw_coordinates_position): Fix previous change.
+
+       * internal-gui.h (glyph_category): New enum.
+       (MGlyph): Change type of <category> to enum glyph_category.
+
+       * face.c (mface__realize): Delete args langauge and charset.
+       (mface__for_chars): Fix for the case that glyphs have different
+       rfaces.
+       (mface__update_frame_face): Adjust for mface__realize change.
+
+       * face.h (mface__realize): Adjust prototype.
+
+2004-10-05  Kenichi Handa  <handa@m17n.org>
+
+       * language.c (mlang__init): Add Akan.
+
+2004-10-04  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (add_font_info): Add instead of push the element.
+       (ft_list_family): For generic fonts, try all
+       substituted. families.
+
+       * font-flt.c (UPDATE_CLUSTER_RANGE): New macro.
+       (run_rule): Don't update cluster range here.
+       (run_command): Update cluster range on appending a glyph.
+       (run_otf): Update cluster range for glyphs generated by OTF.
+
+2004-10-02  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (device_open): Handle Mfont key in PLIST.
+
+2004-09-30  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (ft_select): Ignore family on calling mfont__score.
+
+2004-09-30  Kenichi Handa  <handa@m17n.org>
+
+       * font.h: Include <fontconfig/fontconfig.h>.
+       (MFTInfo): New member langset.
+       (mfont__encoding_list): Extern it.
+
+       * font.c (mfont__encoding_list): New function.
+       (mdebug_dump_font_list): New function.
+
+       * font-ft.c: Don't include <fontconfig/fontconfig.h> here.
+       (Mserif, Msans_serif, Mmonospace, Mmedium, Mr, Mnull): New
+       variables.
+       (ft_family_list): New variable.
+       (set_font_info): New arg basep.  Callers changed.
+       (fc_list): Check the return value of FcPatternGetString.
+       (add_font_info): New arg plist.  Callers changed. Update
+       ft_family_list.
+       (ft_list_family): New function (merged fc_list and ft_list_all).
+       (ft_select): Use ft_list_family.
+       (ft_list): Likewise.  If FONT is not NULL, check all fonts.  Fix
+       typo (== -> !=).
+       (mfont__ft_init): Initialize above new variables.
+       (mfont__ft_fini): Free ft_family_list.
+       (STRDUP_LOWER): New macro.
+       (set_font_info): Use STRDUP_LOWER.
+       (ft_list_family): Avoid duplicate addition of font path.  Use
+       STRDUP_LOWER.
+       (fc_decode_prop): Fix typo.
+
+       * m17n-X.c (MDisplayInfo): New member all_fonts_scaned.
+       (xfont_registry_list): Change argument disp_info to frame.
+       Callers changed.
+       (xfont_list_all): New function.
+       (xfont_list): If FONT is not NULL, check all fonts.
+
+2004-09-28  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (MXFont, MXFontList): New types.
+       (MDisplayInfo): Delete members font_registry_list,
+       iso8859_1_family_list, iso10646_1_family_list, new members
+       font_list, base_font_list.
+       (free_display_info): Adusted for the change of MDisplayInfo.
+       (xfont_driver): Initialize with xfont_list.
+       (font_compare): New function.
+       (build_font_list): Deleted.
+       (xfont_registry_list): New function.
+       (xfont_select): Use xfont_registry_list.
+       (xfont_list): New function.
+       (device_open): Adusted for the change of MDisplayInfo.
+
+       * font-ft.c (add_font_info): New arg languages.  Callers changed.
+       (fc_list): Get languages from fonts..
+       (ft_list_all): Renamed from ft_list.  Callers changed.
+       (ft_list): New function.
+       (mfont__ft_driver): Initalize with ft_list.
+
+       * font.c (mfont_list): New function.
+
+       * font.h (struct MFontDriver): New member `list'.
+       (MFTInfo): New member languages.
+
+       * m17n-gui.h (mfont_list): Extern it.
+
+2004-09-27  Kenichi Handa  <handa@m17n.org>
+
+       * internal-gui.h (struct MGlyphString): Delete members mt,
+       sub_width, sub_lbrearing, sub_rbearing, and region.
+
+       * draw.c (MSubTextExtents): New type.
+       (layout_glyphs): New arg extents.  Set its members.
+       (layout_glyph_string): Adjusted for the above change.
+       (alloc_gstring): Don't set gstring->mt.
+       (truncate_gstring): Call line_break function with mt instead of
+       gstring->mt.
+
+2004-09-22  Kenichi Handa  <handa@m17n.org>
+
+       * mtext.c (count_utf_16_chars): Count each code of invalid
+       surrogates as one.
+
+2004-09-19  Kenichi Handa  <handa@m17n.org>
+
+       * mtext.c (default_utf_16, default_utf_32): Rename them to
+       MTEXT_FORMAT_UTF_16 and MTEXT_FORMAT_UTF_32 respectively.  Caller
+       changed.
+
+       * m17n-core.h (MTEXT_FORMAT_UTF_16, MTEXT_FORMAT_UTF_32): Extern
+       them.
+
+2004-09-13  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (Mlatin): Don't declare it here.
+       (visual_order): Fix reordering of combining characters.
+       (compose_glyph_string): Fix detection of script.
+       (layout_glyphs): Don't fix reordering of combining characters
+       here.
+       (layout_glyph_string): Pay attention to
+       control->disable_overlapping_adjustment.
+       (truncate_gstring): Include at least on character in a line.
+       (get_gstring): Always scan one full line.
+       (mdraw__init): Don't initialize Mlatin here.
+       (mdraw_text_per_char_extents): Fix iteration.  If a glyph doesn't
+       have a font, use ascent/descent of an ASCII font.  Allow
+       ink_array_return and logical_array_return to be NULL.
+       (mdraw_coordinates_position): Fix iteration.
+
+       * font-ft.c (MFTtoProp): Member completely changed.
+       (ft_to_prop): Adjusted for the above change.
+       (ft_to_prop_size): Likewise.
+       (set_font_info): Adjusted for the change of MFTtoProp.
+       (fc_generic_family_list): New variable.
+       (fc_list): Add special handling of generic font names.
+       (mfont__ft_init): Adjusted for the change of MFTtoProp.
+       Initialize fc_generic_family_list.
+       (mfont__ft_fini): Don't free ft_to_prop.  Free
+       fc_generic_family_list.
+       (FC_vs_M17N_font_prop): New type.
+       (fc_weight_table, fc_slant_table, fc_width_table): New variables.
+       (fc_decode_prop, fc_encode_prop): New functions.
+       (mfont__ft_parse_name): Use fc_decode_prop.
+       (mfont__ft_unparse_name): Use fc_encode_prop.
+
+       * m17n-X.c (MDisplayInfo): Delete member realized_font_list.
+       (MWDevice): Add member realized_font_list.
+       (free_display_info): Don't free disp_info->realized_font_list.
+       (free_device): Free device->realized_fontset_list.
+       (xft_find_metric): Use gstring->frame instead of rfont->frame.
+       (device_open): Don't initialize disp_info->realized_font_list.
+       (device_open): Initialize device->realized_font_list and set it to
+       frame->realized_font_list.
+
+       * fontset.c (try_font_group): New function.
+       (mfont__lookup_fontset): Use try_font_group.
+
+       * font.c (common_weight): Change the order of "regular".
+
+       * face.c (Mlatin): Don't make it static.
+       (mface__realize): Be sure to set work_gstring.frame.
+       (mface__for_chars): Likewise.
+
+       * mtext.c (mdebug_dump_mtext): Fix for the case of mt->format >
+       MTEXT_FORMAT_UTF_8.
+
+       * internal-gui.h (Mlatin): Extern it.
+
+       * m17n-gui.h (MDrawControl): New member
+       disable_overlapping_adjustment.
+
+2004-09-06  Kenichi Handa  <handa@m17n.org>
+
+       * font-flt.c (run_otf): Fix typo ('}'->']').
+
+       * internal-gui.h (MAKE_PRECOMPUTED_COMBINDING_CODE)
+       (COMBINING_PRECOMPUTED_P): New macros.
+
+       * draw.c (layout_glyphs): Handle precomputed combining code.
+
+       * font-ft.c (mfont__ft_drive_otf): Set g->combining_code to a
+       precomupted combining code.
+
+2004-09-03  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (mfont__ft_drive_otf): Use malloc and free for
+       otf_gstring.glyphs.
+
+2004-08-27  Kenichi Handa  <handa@m17n.org>
+
+       * face.c (mface_put_prop): If the new value is the same as the
+       current one, don't increment frame->tick.
+
+2004-08-25  Kenichi Handa  <handa@m17n.org>
+
+       * fontset.c (mfontset): Initialize font_spec_list member.
+       (mfontset_copy): Load fontset if necessary.
+
+       * m17n-gui.h (MDrawGlyphInfo): Change the member name 'this' to
+       'metrics' to for C++.
+
+       * draw.c (mdraw_glyph_info): Adjusted for the member name change
+       (this -> metics).
+
+2004-08-16  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.1.0 released.
+
+2004-08-13  Kenichi Handa  <handa@m17n.org>
+
+       * language.c (mlang__init): Add Dhivehi.
+
+       * m17n-gui.c (Mx, Mfreetype): Delete it.
+       (m17n_init_win): Don't initialize Mx and Mfreetype here.
+
+       * m17n-gui.h (Mfreetype, Mxft): Extern them.
+       (mfont_resize_ratio): Extern it.
+       (MDrawGlyphInfo): New member logical_width;
+       (MDrawGlyph): New type.
+       (mdraw_glyph_list): Prototype adjusted.
+
+       * m17n-X.c (xfont_open): Set type and fontp members.
+       (xft_open): Likewise.
+
+       * internal-gui.h (Mx, Mfreetype): Delete extern.
+
+       * font.h (struct MRealizedFont): New member type and fontp.
+
+       * font.c (mfont__init): Initialize Mx, Mfreetype, and Mxft.
+       (Mx, Mfreetype): Declare here.
+       (Mxft): New variable.
+       (mfont_resize_ratio): New function.
+
+       * font-ft.c (ft_open): Set type and fontp members.
+
+       * draw.c (mdraw_glyph_list): Argument type changed.  Don't set
+       glyph_code member.
+
+2004-08-11  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (ft_find_metric): Call FT_Load_Glyph with
+       FT_LOAD_DEFAULT.
+
+2004-08-06  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (mfont__ft_drive_otf): Fix for the case that no GSUB
+       feature to apply.
+
+       * font-flt.c (run_otf): Print debugging information if necessary.
+
+2004-08-05  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (mfont__ft_drive_otf): Fix sign of g->yoff.  Support
+       positioning_type 5 and 6.  Switch simplified.
+
+2004-08-04  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (mfont__ft_drive_otf): Call OTF_drive_gdef.
+
+2004-08-02  Kenichi Handa  <handa@m17n.org>
+
+       * font.c (mfont__score): If prop is MFONT_FOUNDRY or MFONT_FAMILY,
+       set val to 1 even if it is greater than 1.
+
+       * fontset.c (mfontset_modify_entry): Fix handling of the arg `how'.
+
+2004-07-29  Kenichi Handa  <handa@m17n.org>
+
+       * font-flt.c (run_rule, run_command, mfont__flt_run): Print more
+       debugging information.
+
+       * internal.h (MDEBUG_PRINT5): New macro.
+
+       * draw.c (layout_glyphs): Don't combine a zero width glyph with
+       the previous one if the zero width glyph has left or right
+       padding.
+
+2004-07-26  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (xft_render): Pay attention to members left_padding and
+       right_padding of MGlyph.
+
+       * draw.c (visual_order): Allocate one more elements for arrays as
+       a workaround of fribidi bug.
+       (layout_glyphs): Fix previous change. Check MGlyph->combining_code
+       instead of MGlyph->bidi_sensitive.
+       (layout_glyph_string): Pay attentinon to
+       control->orientation_reversed when padding at the head or tail.
+       Fix adjustment of space glyph width.
+       (get_gstring): If cursor_width or cursor_bidi is changed, don't
+       use a cache.
+
+       * font-ft.c (mfont__ft_drive_otf): Set MGlyph->combining_code
+       instead of MGlyph->bidi_sensitive.
+
+       * internal-gui.h (MGlyph): Delete member bidi_sensitive.
+
+2004-07-26  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (visual_order): Don't treat combined glyphs specially.
+       (layout_glyphs): Don't get metrics glyphs that are already ready.
+       Pay attention to MGlyph->bidi_sensitive.  Combine a glyph of zero
+       width with the previous one. 
+       (draw_background): Fix bar cursor position on a r2l glyph.
+
+       * font-flt.c (FontLayoutCmdOTF): Move back from internal-gui.h.
+       (run_rule): Fix place of updating cluster_begin_pos and
+       cluster_end_pos here.
+       (run_otf): Don't set left_padding.
+
+       * font-ft.c (adjust_anchor): Type of argument `code' changed.
+       Caller changed.
+       (mfont__ft_drive_otf): Renamed back from mfont__ft_drive_gsub.
+       Fix handling of GPOS.
+       (mfont__ft_drive_gpos): Delete this function.
+
+       * font.h (mfont__ft_drive_otf): Renamed back from
+       mfont__ft_drive_gsub.
+       (mfont__ft_drive_gpos): Delete extern.
+
+       * internal-gui.h (FontLayoutCmdOTF): Move back to font-flt.c.
+       (MGlyph): Delete member otf_cmd, add member bidi_sensitive.
+
+2004-07-23  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (layout_glyphs): Call mfont__ft_drive_gpos with glyphs of
+       the same bidi level.
+
+       * font-ft.c (mfont__ft_drive_gpos): Check bidi-level.
+
+2004-07-22  Kenichi Handa  <handa@m17n.org>
+
+       * font-flt.c (load_flt): Treat the symbol Mend as end-of-file.
+
+2004-07-20  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (render_glyphs): Fix checking of g->code validity.
+
+       * face.c (mface__realize): Set g.type.
+
+2004-07-18  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am: Prepend ${top_srcdir} to all *.la in
+       *_LIBADD/*_LDADD.
+
+       * m17n-gui.c (mframe): Print error message give by dlopen to
+       stderr.
+
+2004-07-16  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (compose_glyph_string): Improve the way of deciding a
+       script.  For a character that doesn't have script property, use
+       the last non-latin script.
+
+       * font-ft.c (fc_list): Cancel previous change.
+       (mfont__ft_init): Add more entries in ft_to_prop_name.
+
+2004-07-15  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (mdraw_glyph_list): Add the width of padding glyphs to
+       previous or next character glyphs.
+
+2004-07-14  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (compose_glyph_string): Be sure to set codes for glyphs
+       of type GLYPH_SPACE.
+
+       * fontset.c (mfont__lookup_fontset): If glyph type is
+       GLYPH_SPACE, get codes for SPACE.
+
+       * internal-gui.h (Mfont): Delete extern.
+
+       * m17n-gui.h (Mfont): Delete duplicated extern.
+
+2004-07-13  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (DEVICE_DELTA): New macro.
+       (adjust_anchor): New function.
+       (mfont__ft_drive_gsub): Renamed from mfont__ft_drive_otf.  Drive
+       only GSUB.
+       (mfont__ft_drive_gpos): New function.
+
+       * font-flt.c (FontLayoutCmdOTF): Moved to internal-gui.h.
+       (FontLayoutContext): Delete member `rfont'.
+       (run_otf): Set g->otf_cmd.  Call 
+       (mfont__flt_run): Don't set ctx.rfont.  Call mfont__ft_decode_otf
+       only whne HAVE_OTF is defined.
+
+       * fontset.c: Include "config.h".
+
+       * internal-gui.h (FontLayoutCmdOTF): Moved from font-flt.c.
+       (MGlyph): New member otf_cmd.
+
+       * font.h (mfont__ft_drive_gsub): Changed from mfont__ft_drive_otf.
+       (mfont__ft_drive_gpos): Extern it.
+
+       * face.c: Include "config.h".
+
+       * draw.c (layout_glyphs): Call mfont__ft_drive_gpos.
+
+       * input-gui.c: Include "config.h".
+
+       * plist.c: Include "config.h".
+
+2004-07-06  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.c, m17n-gui.h, m17n-gd.c, m17n-X.h, m17n-X.c,
+       internal-gui.h: Cancel previous changes.
+
+       * m17n-gd.h: Delete it.
+
+       * Makefile.am (libm17n_core_la_LIBADD): New variable.
+       (libm17n_core_la_LDFLAGS): Add -export-dynamic, move
+       @XML2_LD_FLAGS@ to above.
+       (libm17n_la_LIBADD): Add -ldl.
+       (libm17n_la_LDFLAGS): Add -export-dynamic.
+       (X_LD_FLAGS): Fix the order of linking.
+       (libm17n_gui_la_LIBADD): Add ${OPTIONAL_LD_FLAGS}.
+       (libm17n_gui_la_LDFLAGS): Add -export-dynamic, delete above.
+       (libm17n_X_la_LDFLAGS): Add -module.
+       (libm17n_gd_la_SOURCES): Delete m17n-gd.h.
+       (libm17n_gd_la_LIBADD): Add @GD_LD_FLAGS@.
+       (libm17n_gd_la_LDFLAGS): Add -module.
+       (include_HEADERS): Delete m17n-gd.h.
+
+2004-06-30  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.c: Adjusted for the change of struct MDeviceDriver.
+       (MDeviceLibraryInterface): Delete it.
+       (register_device_library): Delete it.
+       (m17n__device_library_list): Renamed from device_library_list.
+
+       * m17n-gui.h (M17N_INIT_X, M17N_INIT_GD): New macros.
+       (m17n_init_win): Adjust prototype.
+
+       * m17n-gd.c: Adjusted for the change of struct MDeviceDriver.
+       (m17n_init_gd): New function. 
+
+       * m17n-gd.h: New file.
+
+       * m17n-X.h: Include <m17n-gui.h>.
+       (m17n_init_X): Extern it.
+       (M17N_INIT): Redefine it.
+
+       * m17n-X.c: Adjusted for the change of struct MDeviceDriver.
+       (m17n_init_X): New function.
+
+       * internal-gui.h (m17n__device_library_list): Extern it.
+       (struct MDeviceDriver): New members initialized, init, and fini.
+
+       * Makefile.am (libm17n_X_la_LIBADD): Add ${X_LD_FLAGS} and
+       @XFT2_LD_FLAGS@.
+       (libm17n_X_la_LIBADD): Delete aboves.
+       (libm17n_gd_la_SOURCES): Add m17n-gd.h.
+       (libm17n_gd_la_LIBADD): Add @GD_LD_FLAGS@.
+       (libm17n_gd_la_LDFLAGS): Delete it.
+       (include_HEADERS): Add m17n-gd.h.
+
+2004-06-25  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (libm17n_X_la_LDFLAGS): Cancel previous change.
+       (libm17n_gd_la_LDFLAGS): Cancel previous change.
+
+       * m17n-gd.c (gd_render): Don't call FT_Get_Char_Index.
+
+       * font-ft.c (fc_list): If FcFontList finds no font, try
+       FcFontMatch.
+
+       * draw.c (compose_glyph_string): Terminate the last loop after
+       doing default combining if necessary.
+
+2004-06-24  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (mdraw_glyph_list): Unref gstring->top at the tail.
+
+       * character.c (mchar_define_property): Add const to an arg.
+
+       * charset.c (mchar_define_charset): Add const to an arg.
+
+       * coding.c (MCodingSystem): Add const to an arg or decoder.
+       (finish_decoding): Add const to an arg.
+       (decode_coding_charset, decode_coding_utf_8)
+       (decode_coding_utf_16, decode_coding_utf_32)
+       (decode_coding_iso_2022, decode_coding_sjis)
+       (mconv_define_coding): Likewise.
+
+       * m17n-X.c (xft_find_metric): Delete unused variable.
+
+       * m17n-core.h (mchar_define_property, mtext_from_data): Adjust
+       prototypes.
+
+       * m17n.h (mchar_define_charset, mconv_define_coding): Adjust
+       prototypes.
+
+       * mtext.c (count_utf_8_chars, count_utf_16_chars)
+       (mtext__from_data, mtext_from_data): Add `const' to an arg.
+
+       * mtext.h (mtext__from_data): Ajust prototype.
+
+2004-06-23  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (compose_glyph_string): Always get glyph codes by
+       mface__for_char.
+       (mdraw_glyph_info): Set info->glyph_code and info->logical_width.
+       (mdraw_glyph_list): New function.
+
+       * font-flt.c (mfont__flt_run): Be sure to call
+       rfont->driver->encode_char.
+
+       * font-ft.c (ft_find_metric): Don't call FT_Get_Char_Index.
+       (ft_encode_char): Delete arg C.
+       (ft_render): Don't call FT_Get_Char_Index.
+
+       * font.c (mfont__encodable_p): Delete it.
+       (mfont__encode_char): Be sure to call rfont->driver->encode_char.
+
+       * font.h (struct MFontDriver): Delete arg C of encode_char.
+       (mfont__encodable_p): Delete extern.
+
+       * m17n-X.c (xfont_encode_char): Delete arg C.
+       (xft_find_metric): Don't cal FT_Get_Char_Index.
+       (xft_render): Likewise.
+
+       * m17n-gui.h (MDrawGlyphInfo): New members glyph_code and
+       logical_width.
+       (mdraw_glyph_list): Extern it.
+
+       * Makefile.am (libm17n_X_la_LDFLAGS): Don't include ${X_LD_FLAGS}.
+
+2004-06-22  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.h (mfontset_lookup): Extern it.
+
+       * m17n-gui.c (m17n_init_win): Delete unnecessary printing.
+
+       * fontset.c (realize_fontset_elements)
+       (free_realized_fontset_elements, update_fontset_elements): New
+       functions.
+       (mfont__realize_fontset): Call realize_fontset_elements.
+       (mfont__free_realized_fontset): Call free_realized_fontset_elements.
+       (mfont__lookup_fontset): If a fontset was modified, update
+       the realized fontset.
+       (mfontset_modify_entry): Increment fontset->tick.
+       (mfontset_lookup): New function.
+
+2004-06-21  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (mfont__ft_parse_name): Cast the arg to FcNameParse.
+
+       * mtext.c (mtext_dup, mtext_cat, mtext_ncat, mtext_cpy)
+       (mtext_ncpy, mtext_duplicate): Pay attention to the case that the
+       length of source text 0.
+
+2004-06-21  Kenichi Handa  <handa@m17n.org>
+
+       * mtext.c (INC_POSITION): Use CHAR_UNITS_BY_HEAD_UTF16.
+       (compare): Pay attention to format other than utf-8.
+       (copy): Delete this function.
+       (count_by_utf_8, count_by_utf_16, insert): New functions.
+       (count_utf_16_chars): Fix handling of a surrogate pair.
+       (find_char_forward, find_char_backward): Likewise.
+       (mtext__from_data): Delete unnecessary check.  Fix number of
+       allocated bytes.
+       (mtext_from_data): Don't count items.
+       (mtext_ref_char): Optimize the code.
+       (mtext_set_char): Pay attention to format other than utf-8.
+       (mtext_cat_char): Likewise.
+       (mtext_dup): Don't call copy, instead do allocation here.
+       (mtext_cat): Call insert instead of copy.
+       (mtext_ncat): Likewise.
+       (mtext_cpy): Delete character at first and call insert instead of
+       copy.
+       (mtext_ncpy): Likewise.
+       (mtext_copy): Likewise.
+       (mtext_duplicate): Call insert instead of copy.
+       (mtext_del): Pay attention to format other than utf-8.
+       (mtext_ins): Simply call insert.
+       (mtext_ins_char): Pay attention to format other than utf-8.
+       (mtext_tok): Call insert instead of copy.
+       (mtext_text): Call UNIT_BYTES.
+
+       * textprop.c (mtext__adjust_plist_for_change): New function.
+
+       * character.h (USHORT_SIZE, UINT_SIZE, UNIT_BYTES): New macros.
+       (CHAR_UNITS_UTF16, CHAR_UNITS): Simplified.
+       (CHAR_UNITS_AT): Fix typo.
+       (CHAR_UNITS_BY_HEAD): Fix typo.
+       (STRING_CHAR_AND_UNITS): Fix typo.
+
+       * internal.h (MTEXT_READ_ONLY_P): New macro. 
+
+       * mtext.h (mtext__replace): Delete the extern.
+       (mtext__adjust_foramt): Adjust prototype.
+
+       * plist.c (mplist_deserialize): Adjust the format of MT to utf-8
+       if possible.  Otherwise make a copy of mmt.
+
+       * coding.c (mconv_decode, mconv_gets): Adjust the format of MT to
+       utf-8.
+
+2004-06-18  Kenichi Handa  <handa@m17n.org>
+
+       * character.h (CHAR_STRING_UTF16): Fix syntax.
+
+2004-06-16  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (libm17n_gd_la_LIBADD): Delete it.
+       (libm17n_X_la_LIBADD): Delete it.
+       (libm17n_gd_la_LDFLAGS): Don't include @GD_LD_FLAGS@.
+
+       * m17n-X.c (device_open): Add parens in `if' condition.
+
+       * mtext.c (INC_POSITION): Handle format other than utf8 and utf16.
+       (DEC_POSITION): Likewise.
+       (compare): Fix case that mt1->format is MTEXT_FORMAT_UTF_8.
+
+2004-06-15  Kenichi Handa  <handa@m17n.org>
+
+       * fontset.c (mfont__lookup_fontset): Fix selection of font groups
+       by language.
+
+       * draw.c (compose_glyph_string): If langauge is specified, call
+       mface__for_chars even if a text is all latin.  Fix condition for
+       setting non_ascii_found.
+
+       * m17n-X.c (xft_find_metric): Fix setting of g->lbrearing.
+
+       * m17n.h (minput_char_to_key): Delete extern.
+
+       * m17n-gui.h (minput_event_to_key): Cancel previous change.
+
+       * m17n-gui.c (null_device_open): Set several members of frame.
+
+2004-06-14  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.h (minput_event_to_key): Delete extern.
+
+       * symbol.h (struct MSymbolStruct): Renamed from MSymbol.
+
+       * m17n-core.h (MSymbol): Defined as "struct MSymbolStruct *".
+
+       * Makefile.am (AM_CPPFLAGS): Refer to @M17NDIR@.
+
+2004-06-08  Kenichi Handa  <handa@m17n.org>
+
+       * character.c (mchar_put_prop): Don't increment the ref-count of
+       record->table.
+
+2004-06-04  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.c (mdebug__register_object): New function.
+       (mdebug__unregister_object): Likewise.
+
+       * internal.h (mdebug__register_object, mdebug__unregister_object):
+       Extern them.
+       (M17N_OBJECT_REGISTER, M17N_OBJECT_UNREGISTER): Call them
+       respectively.
+
+       * charset.c (mcharset__load_from_database): Don't call
+       mconv__register_charset_coding here.
+
+       * coding.c (find_coding): Get a real name from an element of
+       coding_definition_list.
+       (mconv__register_charset_coding): Set the real name at the top of
+       param.
+       (mcoding__load_from_database): Likewise.
+       (mconv_list_codings): Adjusted for the above change.
+
+2004-06-03  Kenichi Handa  <handa@m17n.org>
+
+       * coding.c (find_coding): Find by canonicalized name.  Don't have
+       to modify the element of coding_definition_list by
+       mplist__from_plist.
+       (mconv__define_coding_from_charset): Delete it.
+       (mconv__register_charset_coding): Canonicalize sym.
+       (mcoding__load_from_database): Register plist modified by
+       mplist__from_plist.
+
+       * coding.h (mconv__define_coding_from_charset): Don't extern it.
+
+       * font-ft.c (ft_open): Fix setting of rfont->descent.
+
+2004-06-02  Kenichi Handa  <handa@m17n.org>
+
+       * font.c (enum xlfd_field_idx): Moved from m17n-X.c.
+       (xlfd_parse_name): Merge split_font_name and xfont_parse_name.
+       (xlfd_unparse_name): Renamed from xfont_build_name.
+       (mfont__init): Initialized Mfontconfig.
+       (mfont__free_realized): Unconditionally unref rfont->info.
+       (mfont__select): Free `this' if it's not best.
+       (mfont__open): Don't check frame->realized_font_list.
+       (mfont__parse_name_into_font): New function.
+       (Mfontconfig): New variable.
+       (mfont_from_name): Call mfont_parse_name.
+       (mfont_name): Call mfont_unparse_name.
+       (mdebug_dump_font): Likewise.
+
+       * font.h (struct MFontDriver): Delete members parse_name and
+       build_name.
+       (mfont__ft_parse_name, mfont__ft_unparse_name): Extern them.
+       (mfont__parse_name_into_font): Extern it.
+
+       * font-ft.c: Include "symbol.h".
+       (close_ft): Unconditionally free filename and charmap_list of
+       ft_into.
+       (ft_open): Duplicate base->filename.  Increment ref-count of
+       ft_info->charmap_list.  Free ft_info->charmap_list and
+       ft_info->filename on error.
+       (mfont__ft_parse_name, mfont__ft_unparse_name): New functions.
+
+       * m17n-X.c (xfont_driver): Don't include xfont_parse_name and
+       xfont_build_name.
+       (enum xlfd_field_idx): Moved to font.c.
+       (split_font_name, build_font_name): Likewise.
+       (build_font_list): Call mfont__parse_name_info_font.
+       (xfont_open): Call mfont__unparse_name.  Free name.
+       (xfont_parse_name, xfont_build_name): Moved to font.c
+       (xft_select): Prototype deleted.
+       (device_open): Check HAVE_FREETYPE on using mfont__ft_driver.
+       Call mfont_pase_name.
+
+       * m17n-gui.c (free_frame): Unref frame->font_driver_list.
+       (m17n_fini_win): Add check HAVE_FREETYPE on using null_interface.
+       (mframe): Likewise.
+
+       * m17n-gui.h (mfont_parse_name, mfont_unparse_name, Mfontconfig):
+       Extern them.
+
+       * Makefile.am (linkgui_LDADD): Add libm17n-X.la and libm17n-gd.la.
+
+2004-06-01  Kenichi Handa  <handa@m17n.org>
+
+       * fontset.c (mfontset_modify_entry): Pay attention to the case
+       that fontset->font_spec_list is NULL.
+
+2004-05-31  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.c: Include <dlfcn.h> only when HAVE_DLFCN_H is defined.
+
+       * input.c: Include <dlfcn.h> only when HAVE_DLFCN_H is defined.
+
+       * font.c (mfont__select): Print score the a font for debugging.
+
+       * Makefile.am (libm17n_la_LIBADD): Delete -ldl.
+
+       * coding.c (reset_coding_sjis): Check kanji and kana instead of
+       kanji_sym and kana_sym.
+
+2004-05-28  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (VINFO): New variable.
+       (libm17n_core_la_LDFLAGS, libm17n_la_LDFLAGS)
+       (libm17n_gd_la_LDFLAGS): Include ${VINFO}.
+
+2004-05-27  Kenichi Handa  <handa@m17n.org>
+
+       The following chanages are to make device dependent functions
+       accessible only from MDeviceDriver structure, and to add GD and
+       null device drivers.  Font drivers get also device dependent.
+
+       * m17n.c (m17n_init): Increament shell_initialized.
+       (m17n_fini): Decremented shell_initialized.
+
+       * m17n-misc.h (enum MErrorCode): New element MERROR_GD.
+
+       * m17n-gui.h (Mdevice, Mdisplay, Mscreen, Mdrawable, Mdepth)
+       (Mwidget, Mcolormap, Mx): Extern them.
+
+       * m17n-gui.c: Include <dlfcn.h> and "config.h".
+       (free_frame): Call frame->driver->close instead of
+       mwin__close_device.
+       (DLOPEN_SHLIB_EXT): New macro.
+       (MDeviceLibraryInterface): New type.
+       (device_library_list): New variable.
+       (register_device_library): New function.
+       (null_device): New variable.
+       (null_device_close, null_device_get_prop)
+       (null_device_realize_face, null_device_free_realized_face): New
+       function.
+       (null_driver): New variable.
+       (null_device_init, null_device_fini, null_device_open): New
+       functions.
+       (null_interface): New variable.
+       (Mfreetype, Mdevice): Declare them.
+       (m17n_init_win): Increment win_initialized.  Initialize Mx, Mgd,
+       Mfreetype, Mdevice, Mdisplay, Mscreen, Mdrawable, Mdevice, and
+       Mwin__Close_Device.  Register drivers for Mx and Mgd.
+       (m17n_fini_win): Decremented win_initialized.  Call "fini"
+       function of all opened devices.  Don't call mwin__fini.
+       (Mdisplay, Mscreen, Mdrawable, Mdepth, Mwidget, Mcolormap):
+       Declare them here.
+       (mframe): Handle Mdevice key of PLIST.
+       (mframe_get_prop): Call frame->device->get_prop instead of
+       mwin__device_get_prop.
+
+       * m17n-gd.c: New file.
+
+       * m17n-core.h (M17NLIB_MAJOR_VERSION, M17NLIB_MINOR_VERSION)
+       (M17NLIB_PATCH_LEVEL, M17NLIB_VERSION_NAME): Updated to 1.1.0.
+
+       * m17n-core.c (m17n_init_core): Increate core_initialized.
+       (m17n_fini_core): Decremented core_initialized.
+
+       * m17n-X.h (Mdisplay, Mscreen, Mdrawable, Mdepth, Mwidget)
+       (Mcolormap): Don't extern them here.
+
+       * m17n-X.c (FRAME_DEVICE): New macro.
+       (FRAME_DISPLAY, FRAME_SCREEN, FRAME_CMAP): Use FRAME_DEVICE.
+       (free_display_info): Use MPLIST_DO.
+       (free_device): Free rface->info.
+       (xft_close): Delete it.
+       (device_init): Renamed from mwin__init.
+       (device_fini): Renamed from mwin__fini.
+       (device_open): Renamed from mwin__open_device.
+       (x_driver): New variable.
+       (MXFontInfo): Delete member frame, add member display.
+       (Mdisplay, Mscreen, Mdrawable, Mdepth, Mwidget, Mcolormap, Mxim):
+       Don't declare them here.
+
+       * internal-gui.h (MDeviceType): New enum.
+       (MWDefice): Delete it.
+       (struct MFrame): Change type of device to void *.  New members
+       device_type, driver, font_driver_list.
+       (M_CHECK_WRITABLE, M_CHECK_READABLE): New macros.
+       (MDeviceDriver): New type.
+       (Mx, Mgd, Mfreetype): Extern them.
+       (mwin__XXX): Delete all of them.
+
+       * input-gui.c (win_create_ic): Call frame->driver->XXX instead of
+       mwin__XXX.
+       (win_destroy_ic): Likewise.
+       (adjust_window_and_draw): Likewise.
+       (win_callback): Likewise.
+       (Mxim): Declare it here.
+       (minput_event_to_key): Call M_CHECK_READABLE.
+
+       * fontset.c (mfont__lookup_fontset): Delete local variable
+       font_group.
+
+       * font.h (struct MFontDriver): Delete member close, add members
+       parse_name and build_name.
+       (mfont__driver_list): Delete extern.
+       (mfont__close): Delete extern.
+
+       * font.c (mfont__init): Don't set mfont__driver_list.
+       (mfont__fini): Don't unref mfont__driver_list.
+       (mfont__select): Try font drivers in frame->font_driver_list.  Set
+       driver member of a realized font.
+       (mfont__close): Delete it.
+       (mfont_from_name, mfont_name, mdebug_dump_font): Call driver
+       functions of the default frame.
+
+       * font-ft.c (close_ft): Check ft_info->ft_face and work
+       differently.
+       (add_font_info): Allocate ft_info by M17N_OBJECT.
+       (ft_close): Delete it.
+       (mfont__ft_driver): Don't set ft_close.
+       (ft_select): Increment ref-count of best_font.
+       (ft_open): Decremented ref-count of base.  On error, call
+       FT_Done_Face and free ft_info.
+       (ft_find_metric): Always use XXX_MONO in load_flags.
+       (ft_render): Fix setting of width.  Call
+       frame->driver->draw_points instead of mwin__draw_points.
+       (ft_to_prop): Don't set mfont__driver_list.
+       (mfont__ft_fini): Just unref ft_info.
+
+       * face.c (mface__init): Exchange foreground and background of
+       mface__default.  Call mface_put_prop to set hline of
+       mface_underline,
+       (mface__realize): Call frame->driver->XXX instead of mwin__XXX.
+       (mface__free_realized): Don't call mwin__free_realized_face.
+
+       * draw.c (Mdepth): Don't declare it here.
+       (draw_background): Call frame->driver->XXX instead of mwin__XXX.
+       (render_glyphs, render_glyph_string): Likewise.
+       (mdraw__init): Don't set Mdepth.
+       (mdraw_text, mdraw_image_text, mdraw_text_with_control): Call
+       M_CHECK_WRITABLE.
+       (mdraw_text_per_char_extents): Return 0 on success and -1 on
+       error.
+       (mdraw_text_items): Check FRAME is writable.
+       (mdraw_per_char_extents): Implement body.
+
+       * Makefile.am (lib_LTLIBRARIES): Include libm17n-gui.la and
+       libm17n-gd.la.
+       (OPTIONAL_LD_FLAGS): Include @FONTCONFIG_LD_FLAGS@.
+       (GUI_SOURCES): Delete it.
+       (libm17n_X_la_SOURCES): Don't include ${GUI_SOURCES}.
+       (libm17n_gui_la_SOURCES, libm17n_gui_la_LIBADD)
+       (libm17n_gui_la_LDFLAGS, libm17n_gd_la_SOURCES)
+       (libm17n_gd_la_LIBADD, libm17n_gd_la_LDFLAGS): New targets.
+       (linkgui_LDADD): Set to libm17n-gui.la
+       (linkgui_LDFLAGS): New target.
+       (SRC): Include ${libm17n_gui_la_SOURCES} and
+       ${libm17n_gd_la_SOURCES}.
+
+2004-05-24  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (draw_background): Don't draw background even if
+       rface->face.property[MFACE_BACKGROUND] is not Mnil.
+
+2004-05-22  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (xft_open_font): Fix anti_alias setting.
+
+2004-05-20  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-gui.h (MFaceHookFunc): Change this function type to void.
+
+       * m17n-gui.c: Include "plist.h".
+       (mframe): If PLIST is NULL, initialize it to emply plist.
+
+       * m17n-X.c (build_font_list): Don't set property[MFONT_TYPE].
+       (xft_driver): New variable.
+       (xft_select, close_xft, xft_open_font, xft_open, xft_close)
+       (xft_find_metric, xft_render): New function.
+       (mwin__init): Adjusted for the new mfont__driver_list.
+       (mwin__open_device): Assume arg PARAM is not NULL.  Push a newly
+       generated face to PARAM.
+       (mwin__realize_face): Fix setting of box colors.  Don't call hook
+       function here.
+       (mwin__draw_hline): New function.
+       (mwin__xft_close, mwin__xft_open, mwin__xft_get_metric)
+       (mwin__xft_render): Delete these function.
+
+       * internal-gui.h (struct MFrame): New member tick.
+       (struct MGlyphString): New member tick.
+       (mwin__draw_rect, mwin__draw_empty_boxes): Extern them.
+       (mwin__xft_open, mwin__xft_close, mwin__xft_get_metric)
+       (mwin__xft_render): Delete extern.
+
+       * fontset.c (mfont__lookup_fontset): Make the code simpler.
+       (mfontset): Always increment the reference count of returned
+       object.
+
+       * font-ft.c (mfont__ft_fini): Don't include <otf.h> here.
+       (MFTInfo): Moved to font.h.
+       (ft_iso8859_1_font_list): Delete this variable.
+       (set_font_info): Don't set font->property[MFONT_TYPE].
+       (set_font_info): Don't udpate ft_iso8859_1_font_list.
+       (add_font_info): Change type to void.
+       (fc_list): Change anme from xft_list.  Caller changed.  Include
+       FC_FOUNDRY and FC_PIXEL_SIZE in FcObjectSet.
+       (mfont__ft_driver): Change name from ft_driver.  Caller changed.
+       (ft_select): Check HAVE_FONTCONFIG instead of HAVE_XFT2.
+       (close_ft): Don't call mwin__xft_close.  Unref
+       ft_info->extra_info.
+       (ft_open): Don't setup ft_info->fontname.  Don't call
+       mwin__xft_open.
+       (ft_find_metric): Don't call mwin__xft_get_metric.
+       (ft_encode_char): Call rfont->driver->open instead of ft_open.
+       (ft_render): Don't check HAVE_XFT2.  Don't call mwin__xft_render.
+       (mfont__ft_init): Adjusted for new mfont__driver_list.
+       (mfont__ft_fini): Don't unref ft_iso8859_1_font_list.
+
+       * font.c (mfont__driver_list): Make it MPlist.
+       (mfont__init): Adjust initialization of mfont__driver_list.
+       (mfont__fini): Free mfont__driver_list.
+       (mfont__set_spec_from_face): Don't set spec->property[MFONT_TYPE].
+       (mfont__select): Adjusted for the new mfont__driver_list.
+
+       * font.h (enum MFontProperty): Delete MFONT_TYPE.
+       (mfont__drirver_list): Adjust prototype.
+       (MFTInfo): Move to here from fron.c.  Deleve member fontname.
+
+       * face.h (struct MFace): Delete member realized_face_list, add
+       member frame_list.
+       (struct MRealizedFace): Delete member need_update
+       andnofont_rface, add member non_ascii_list.
+       (mface__update_frame_face): Extern it.
+
+       * face.c (hline_prop_list, box_prop_list, noop_hook): New
+       variables.
+       (get_hline_create, get_box_create): New functions.
+       (find_realized_face): Cancel previous change.  Arg RFONT deleted.
+       Use memcmp.
+       (free_face): Cancep previous change.  Free face->frame_list.
+       (serialize_hline): Do nothing if hline->width is zero.
+       (serialize_box): Do nothing if box->width is zero.
+       (mface__init): Setup all properties of mface__default.
+       (mface__fini): Free hline_prop_list and box_prop_list.
+       (mface__realize): Cancel previous change.  Update
+       face->frame_list.  Setup rface->non_ascii_list.
+       (mface__for_chars): Update rface->non_ascii_list.
+       (mface__free_realized): Free rface->non_ascii_list.
+       (mface__update_frame_face): New function.
+       (mface): Initialize face->frame_list.
+       (mface_copy): Likewise.  Just copy MFACE_HLINE and MFACE_BOX
+       properties.
+       (mface_merge): Likewise.
+       (mface_put_prop): If key is Mhline or Mbox, get value by
+       get_hline_create or get_box_create respectively.
+       (mface_put_prop): Update frame->tick and call
+       mface__update_frame_face if necessary.
+       (mface_update): Do nothing if func is noop_hook.
+
+       * draw.c (render_glyphs): If a font is not found, use
+       mwin__draw_empty_boxes.
+       (alloc_gstring): Initialize gstring->tick.
+       (get_gstring): Check gstring->tick.
+
+2004-05-17  Kenichi Handa  <handa@m17n.org>
+
+       * face.c (find_realized_face): Return value changed.  If RFONT is
+       NULL, avoid unnecessary checking.
+       (free_face): Free face->realized_face_list.
+       (mface__realize): Adjusted for the change of find_realized_face.
+       If it returns a realized face that needs update, free it and
+       realize a new one.  Push a new realized face to
+       frame->realized_face_list instead of appending.
+       (mface__for_chars): Adjusted for the change of find_realized_face.
+       Short cut if the required font is in rface->ascii_rface.
+       (mface_put_prop): Free old value if necessary.  Set need_update
+       member of realized faces to 1.
+
+       * face.h (struct MFace): Delete member tick, add member
+       realized_face_list.
+       (struct MRealizedFace): Delete member tick, add member
+       need_update.
+
+2004-05-13  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (mwin__xft_open): Destroy unnecessary patterns.
+
+2004-05-12  Kenichi Handa  <handa@m17n.org>
+
+       * internal-gui.h (mwin__xft_open): Arguemnt name changed.
+
+       * m17n-X.c (mwin__xft_open): Argument changed to fontname and
+       parse it XftNameParse.
+
+       * font-ft.c (MFTInfo) [HAVE_XFT2]: New member fontname.
+       (all_fonts_scaned): New variable.
+       (set_font_info): FAMILY may be Mnil.
+       (add_font_info): Argument changed.
+       (xft_list): Call add_font_info in it.
+       (ft_list): Likewise.
+       (ft_select): Make it work in the case family is Mnil.
+       (ft_open) [HAVE_XFT2]: Setup ft_info->fontname.
+       (mfont__ft_fini): Set all_fonts_scaned to 0.
+
+       * fontset.c (mfont__lookup_fontset): Don't repeatedly try a font
+       that is failed to open.
+
+2004-05-10  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (mwin__xft_render): Don't use anti-alias if the
+       device's depth is 1 (i.e. monochrome).
+
+       * Makefile.am (OPTIONAL_LD_FLAGS): Change the order of elements
+       to work around the problem of libtool.
+
+       * font-ft.c: Include <freetype/ftbdf.h>.
+       (Municode_bmp, Municode_full, Miso10646_1, Miso8859_1): New
+       variables.
+       (mfont__ft_init): Initialize them.
+       (ft_iso8859_1_font_list): New variable.
+       (set_font_info): Detect a font containing iso8859-1 glyphs and
+       register it in ft_iso8859_1_font_list.  If the font is not
+       scalable, assume it as BDF or PCF font and setup SIZE and RESY
+       properties of the font from its properties.
+       (add_font_list): If the font is not scalable, check if it is BDF
+       or PCF font.  If not, ignore it.
+       (ft_select): If FAMILY is Mnil, return NULL only if the requested
+       registry is not iso8859-1.
+       (ft_select) [not HAVE_XFT2]: If FAMILY is Mnil, select one from
+       ft_iso8859_1_font_list.
+       (ft_find_metric): If the font is not scalable, assume it as BDF
+       or PCF, and get a metric from its properties.
+       (mfont__ft_fini): Free ft_iso8859_1_font_list.
+
+2004-05-07  Kenichi Handa  <handa@redhat.m17n.org>
+
+       * Makefile.am (libm17n_la_LIBADD): Include -ldl.
+       (libm17n_la_LDFLAGS): Delete it.
+       (noinst_PROGRAMS): Renamed from bin_PROGRAMS.
+       (install-binPROGRAMS, uninstall-binPROGRAMS): Delete them.
+
+2004-05-06  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (compose_glyph_string): Fix previous change.
+
+2004-04-30  Kenichi Handa  <handa@m17n.org>
+
+       * font-ft.c (ft_list): Delete unused variable `result'.
+       (ft_render): Fix for the case that bitmap.pitch < bitmap.width.
+
+2004-04-27  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c: Include config.h
+       [HAVE_XFT2]: Include <X11/Xft/Xft.h>.
+       (GCInfo) [HAVE_XFT2]: New member xft_color_fore, xft_color_back.
+       (MWDevice) [HAVE_XFT2]: New member xft_draw.
+       (FRAME_CMAP, FRAME_VISUAL): New macros.
+       (free_device) [HAVE_XFT2]: Destroy device->xft_draw.
+       (xfont_driver): Make it static.
+       (mwin__open_device) [HAVE_XFT2]: Setup device->xft_draw.
+       (mwin__realize_face) [HAVE_XFT2]: Setup info->xft_color_fore and
+       info->xft_color_back.
+       (MXftFontInfo) [HAVE_XFT2]: New type.
+       (mwin__xft_close) [HAVE_XFT2]: New function.
+       (mwin__xft_open) [HAVE_XFT2]: New function.
+       (mwin__xft_get_metric) [HAVE_XFT2]: New function.
+       (mwin__xft_render) [HAVE_XFT2]: New function.
+
+       * internal-gui.h [HAVE_FREETYPE]: Include FT_FREETYPE_H.
+       (mwin__xft_open, mwin__xft_close) [HAVE_FREETYPE]: New externs.
+       (mwin__xft_get_metric, mwin__xft_render) [HAVE_FREETYPE]: New
+       externs.
+
+       * font.h [HAVE_FREETYPE]: Include FT_FREETYPE_H.
+
+       * font-ft.c: Don't include FT_FREETYPE_H here.
+       [HAVE_XFT2]: Include <fontconfig/fontconfig.h>.
+       (fontconfig_initialized, fc_config) [HAVE_XFT2]: New variables.
+       (MFTInfo): New member charmap_index.
+       (MFTInfo) [HAVE_XFT2]: New member xft_info.
+       (check_otf_filename): Renamed from check_filename.  Return value
+       changed.
+       (ft_set_property): This function deleted.
+       (set_font_info): New function.
+       (add_font_list): Argument changed.  Add multiple fonts.
+       (xft_list) [HAVE_XFT2]: New function.
+       (ft_list) [not HAVE_XFT2]: New function.
+       (ft_select): Add code for Xft.
+       (close_ft): Likewise.
+       (ft_open): Likewise.
+       (ft_find_metric): Likewise.
+       (ft_encode_char): Likewise.
+       (ft_render): Likewise.
+
+       * makefile.am (OPTIONAL_LD_FLAGS): Include @XFT2_LD_FLAGS@.
+
+2004-04-26  Kenichi Handa  <handa@m17n.org>
+
+       * textprop.c (mtext_attach_property): Declare the return type as
+       `int'.
+
+2004-04-21  Kenichi Handa  <handa@m17n.org>
+
+       * Makefile.am (OPTIONAL_LD_FLAGS): Include @XFT2_LD_FLAGS@
+
+2004-04-09  Kenichi Handa  <handa@m17n.org>
+
+       * font-flt.c (struct): New members seq_beg, seq_end, seq_from,
+       seq_to.
+       (load_command): Setup above members.
+
+2004-04-05  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (xfont_encode_char): Fix checking of byte1 and byte2.
+
+2004-03-30  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (xfont_encode_char): Return MCHAR_INVALID_CODE if code
+       >= 0x10000.
+
+       * m17n-core.h (M17NLIB_PATCH_LEVEL): Changed to 2.
+       (M17NLIB_VERSION_NAME): Changed to 1.0.2.
+
+2004-03-29  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.0 Patch Level 2 released.
+
+2004-03-29  Kenichi Handa  <handa@m17n.org>
+
+       * charset.c (make_charset): Set charset->fully_loaded and
+       charset->simple correctly.  Don't try to get charset->min_char and
+       charset->max_char for a charset of method subset and superset.
+       Don't load a mapping file here.
+       (mcharset__init): Set unified_max.
+       (mcharset__load_from_database): Free a working plist.
+
+       * coding.c (mcoding__fini): Free all malloced data.
+
+       * input-gui.c (win_create_ic): Set control.as_image for preediting
+       to 0.
+
+       * internal.h (M17N_OBJECT_REGISTER): Check the member `used' (not
+       `count') to initialize the array.
+
+       * locale.c (mlocale_set): Fix the order of M17N_OBJECT_REF and
+       M17N_OBJECT_UNREF.
+
+       * m17n-X.c (xfont_render): If rface->rfont is null, draw a
+       rectangle.
+       (mwin__create_window): Fix bug of setting a background pixel of a
+       new window.
+       (mwin__adjust_window): Clear the window before drawing.
+
+       * m17n-core.c (mdebug__report_object): Free array->objectes if
+       necessary.
+       (m17n_init_core): Don't set report_header_printed to 0 here.
+       Fix debugging information.
+       (m17n_fini_core): Set report_header_printed to 0 here.
+
+       * m17n-core.h (mplist_deserialize): Extern it.
+
+       * m17n-gui.c (m17n_fini_win): Fix debugging information.
+
+       * m17n.c (m17n_fini): Fix debugging information.
+
+       * mtext.c (mtext__adjust_foramt): New function.
+
+       * mtext.h (mtext__adjust_foramt): Extern it.
+
+       * plist.c (mplist_deserialize): Renamed from mplist__deserialize.
+
+       * plist.h (mplist__deserialize): Don't extern it.
+
+       * symbol.c (msymbol__fini): Set freed_symbols to 0.  Set all
+       elements of symbol_table to NULL.  Report about created and freed
+       symbols if MDEBUG_FINI is set.
+
+2004-03-22  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.c (m17n_init_core): Set merror_code to MERROR_NONE.
+
+       * m17n.c (m17n_init): Fix the way of checking merror_code.
+
+       * m17n-gui.c (m17n_init_win): Fix the way of checking merror_code.
+
+2004-03-22  Kenichi Handa  <handa@m17n.org>
+
+       * fontset.c (realize_font_group): Adjust the font size by
+       mfont__resize before selecting a font.
+
+       * font-ft.c (mfont__ft_init): Add oblique and boldoblique.
+
+2004-03-19  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.0 Patch Level 1 released.
+
+2004-03-19  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-core.h (M17NLIB_PATCH_LEVEL): New macro.
+
+       * m17n-core.c (M17NLIB_PATCH_LEVEL): Describe it.
+
+2004-03-19  Kenichi Handa  <handa@m17n.org>
+
+       Re-apply the changes forgotten in the released version.
+
+       * charset.c (mcharset__load_from_database): Call
+       mchar_define_charset.
+
+       * coding.c (encode_unsupporeted_char): Put Mcoding text property.
+       (mconv_encode_range): Put Mcoding text property.
+
+2004-03-18  Kenichi Handa  <handa@m17n.org>
+
+       * draw.c (Mdepth): New variable.
+       (visual_order): Delete unused local var `pos'.
+       (compose_glyph_string): Fix for the case that gstring->glyphs is
+       realloced.  Stop generating glyphs at TO.  Fix handling of
+       control charaters.
+       (layout_glyphs): Get metrics of all glyphs in advance.  Set
+       lbearing and rbearing of base of composition glyph correctly.
+       Handle left-overhang glyphs correctly.
+       (alloc_gstring): New arg frame.  Set gstring->anti_alias.  Caller
+       changed.
+       (dump_combining_code): Change the defualt off_x character to ".".
+       (mdraw__init): Initialize Mdepth.
+
+       * face.c (work_gstring): New variable
+       (mface__init): Initialize work_gstring.
+       (mface__fini): Free work_gstring.glyphs.
+       (mface__realize): Don't handle videomode property here.  Adjusted
+       for the change of mfont__get_metric.
+       (mface__for_chars): Adjusted for the change of mfont__get_metric.
+
+       * face.h (enum face_gc): Moved to m17n-X.c.
+
+       * font.h (struct MFontDriver): Arguments of find_metric changed.
+       (mfont__select): Prototype adjusted.
+       (mfont__get_metric): Likewise.
+       (mfont__ft_drive_otf): Likewise.
+       (mfont__flt_run): Likewise.
+       
+       * font.c (mfont__select): New argument layouter.  If layouter is
+       different in the registered font, make a new copy of realized
+       font.
+       (mfont__get_metric): Argument changed.  Get metrics of multiple
+       glyphs.
+       (mfont_find): Call mfont__select with layouter as Mnil.
+
+       * font-flt.c (FontLayoutContext): New member rfont.
+       (run_otf): Adjusted for the change of mfont__ft_drive_otf.
+       (mfont__flt_run): Argument changed.  Initialize ctx.rfont.
+
+       * font-ft.c (ft_find_metric): Arguments changed.  Get metrics of
+       multiple glyphs.
+       (NUM_POINTS): New macro.
+       (MPointTable): New type.
+       (ft_render): Use mwin__draw_points instead of mwin__draw_bitmap.
+       (mfont__ft_drive_otf): New argument rfont.
+
+       * fontset.c (realize_font_group): Adjusted for the changed of
+       mfont__select.
+       (check_fontset_element): This function deleted.
+
+       * input-gui.c (adjust_window_and_draw): Locate a preedit window
+       off the parent window if the preedit text is zero length.
+
+       * internal-gui.h (struct MFrame): New members foreground,
+       background, videomode, font.
+       (struct MGlyphString): New member anti_alias.
+       (MDrawPoint): New type.
+       (mwin__draw_bitmap): Prototype deleted.
+       (mwin__draw_points): Prototype added.
+
+       * m17n-gui.h (MDrawControl): New member anti_alias.
+
+       * m17n-gui.c (free_frame): Free frame->font.
+       (mframe): Set the fontset of frame->face to the default fontset.
+
+       * m17n-X.c (RGB_GC): New type.
+       (enum gc_index): Renamed from enum face_gc.  Member names changed.
+       (GCInfo): New typel
+       (struct MWDevice): Members foreground and background deleted.  New
+       member scratch_gc, gc_list.
+       (DEFAULT_FONT, FALLBACK_FONT): New macros.
+       (free_device): Free GCs in device->gc_list.
+       (get_rgb_gc): New function.
+       (get_gc): Renamed and argument changed from get_color.
+       (get_gc_for_anti_alias): New function.
+       (xfont_find_metric): Arguments changed.  Get metrics of multiple
+       glyphs.
+       (set_region): Argument changed.  Caller changed.
+       (xfont_render): Allways set a font in gc.
+       (x_error_handler, x_io_error_handler): Define only if
+       X_SET_ERROR_HANDLER is defined.
+       (mwin__open_device): Create device->scratch_gc.  Set members
+       foreground, background, and videomode of frame.  Call
+       XSetErrorHandler and XSetIOErrorHandler only if
+       X_SET_ERROR_HANDLER is defined.
+       (struct gc_list): Deleted.
+       (REGISTER_GC, UNREGISTER_GC): These macros deleted.
+       (mwin__realize_face): Adjusted for the change of the format of
+       rface->info and the charge of set_region.
+       (mwin__free_realized_face, mwin__fill_space, mwin__draw_hline)
+       (mwin__draw_box): Likewise.
+       (mwin__draw_bitmap): This function deleted.
+       (mwin__draw_points): New function.
+       (mwin__verify_region): Adjusted for the change of the format of
+       rface->info and the charge of set_region.
+       (mwin__create_window): Inherit backgound pixel from parent.
+       (mwin__dump_gc): Adjusted for the change of the format of
+       rface->info.
+
+2004-03-16  Kenichi Handa  <handa@m17n.org>
+
+       * m17n-X.c (mwin__parse_event): Fix handling of modifier keys.
+
+       * input.c (M_key_alias): New variable.
+       (handle_key): Try M_key_alias property of a key too.
+       (minput__init): Initialize M_key_alias.  Give that property to
+       symbols in one_char_symbol.  Fix bug of initializing
+       one_char_symbol.
+
+       * draw.c (compose_glyph_string): Don't handle
+       ignore_formatting_char here.  Include formatting characters in the
+       range processed by a FTL.
+       (layout_glyph_string): Handle ignore_formatting_char here.
+
+2004-03-12  Kenichi Handa  <handa@m17n.org>
+
+       * input-gui.c (win_create_ic): Enable bidi in status control.
+
+       * draw.c (visual_order): Avoid re-ordering of combining glyphs only.
+
+2004-03-09  Kenichi Handa  <handa@m17n.org>
+
+       * input.c (load_input_method): If title is not specified, use the
+       input method name as title.
+
+       * m17n-X.c (get_color): Make it static.
+       (xim_create_ic, xim_destroy_ic, x_error_handler)
+       (x_io_error_handler): Likewise.
+
+2004-03-01  Kenichi Handa  <handa@m17n.org>
+
+       * Version 1.0 released.
+
+\f
+Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+  National Institute of Advanced Industrial Science and Technology (AIST)
+  Registration Number H15PRO112
+
+This file is part of the m17n library.
+
+The m17n 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.1 of
+the License, or (at your option) any later version.
+
+The m17n 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 the m17n library; if not, write to the Free
+Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644 (file)
index 0000000..3de7237
--- /dev/null
@@ -0,0 +1,134 @@
+# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010
+#   National Institute of Advanced Industrial Science and Technology (AIST)
+#   Registration Number H15PRO112
+
+# This file is part of the m17n library.
+
+# The m17n 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.1 of
+# the License, or (at your option) any later version.
+
+# The m17n 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 the m17n library; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+VINFO = -version-info @API_VERSION@
+
+BASICBUILDS = libm17n-core.la libm17n.la libm17n-flt.la
+if WITH_GUI
+BUILD_LIBS = $(BASICBUILDS) libm17n-gui.la
+else
+BUILD_LIBS = $(BASICBUILDS)
+endif
+
+lib_LTLIBRARIES = $(BUILD_LIBS)
+
+libm17n_core_la_SOURCES = \
+       character.h character.c \
+       chartab.h chartab.c \
+       database.h database.c \
+       internal.h \
+       plist.h plist.c \
+       m17n-core.h m17n-core.c \
+       m17n-misc.h \
+       mtext.h mtext.c \
+       symbol.h symbol.c \
+       textprop.h textprop.c \
+       mtext-lbrk.c mtext-wseg.c
+
+libm17n_core_la_LIBADD = @XML2_LD_FLAGS@ @THAI_WORDSEG_LD_FLAGS@
+libm17n_core_la_LDFLAGS = -export-dynamic ${VINFO}
+
+libm17n_la_SOURCES = \
+       charset.h charset.c \
+       coding.h coding.c \
+       input.h input.c \
+       language.h language.c \
+       mlocale.h locale.c \
+       m17n.h m17n.c
+libm17n_la_LIBADD = ${top_builddir}/src/libm17n-core.la -ldl
+libm17n_la_LDFLAGS = -export-dynamic ${VINFO}
+
+FLT_SOURCES = \
+       internal-flt.h \
+       m17n-flt.h m17n-flt.c
+
+libm17n_flt_la_SOURCES = ${FLT_SOURCES}
+libm17n_flt_la_LIBADD = ${top_builddir}/src/libm17n-core.la
+libm17n_flt_la_LDFLAGS = -export-dynamic ${VINFO}
+
+GUI_SOURCES = \
+       face.h face.c \
+       font.h font.c font-ft.c \
+       fontset.h fontset.c \
+       draw.c \
+       input-gui.c \
+       internal-gui.h \
+       m17n-gui.h m17n-gui.c
+
+OPTIONAL_LD_FLAGS = \
+       @FREETYPE_LD_FLAGS@ \
+       @FRIBIDI_LD_FLAGS@ \
+       @OTF_LD_FLAGS@ \
+       @FONTCONFIG_LD_FLAGS@
+
+libm17n_gui_la_SOURCES = ${GUI_SOURCES}
+libm17n_gui_la_LIBADD = ${OPTIONAL_LD_FLAGS} ${top_builddir}/src/libm17n-core.la ${top_builddir}/src/libm17n.la ${top_builddir}/src/libm17n-flt.la
+libm17n_gui_la_LDFLAGS = -export-dynamic ${VINFO}
+
+if WITH_GUI
+
+moduledir = ${libdir}/@M17N_MODULE_DIR@
+module_LTLIBRARIES = libm17n-X.la libm17n-gd.la
+X_LD_FLAGS = ${X_PRE_LIBS} ${X_LIBS} @X11_LD_FLAGS@ ${X_EXTRA_LIBS}
+
+libm17n_X_la_SOURCES = m17n-X.h m17n-X.c
+libm17n_X_la_LIBADD = ${X_LD_FLAGS} @XFT2_LD_FLAGS@ ${top_builddir}/src/libm17n-core.la ${top_builddir}/src/libm17n.la ${top_builddir}/src/libm17n-flt.la ${top_builddir}/src/libm17n-gui.la
+libm17n_X_la_LDFLAGS = -avoid-version -module
+
+libm17n_gd_la_SOURCES = m17n-gd.c
+libm17n_gd_la_LIBADD = @GD_LD_FLAGS@ @FREETYPE_LD_FLAGS@ ${top_builddir}/src/libm17n-core.la ${top_builddir}/src/libm17n.la ${top_builddir}/src/libm17n-flt.la ${top_builddir}/src/libm17n-gui.la
+libm17n_gd_la_LDFLAGS = -avoid-version -module
+
+endif
+
+AM_CPPFLAGS = -DM17NDIR=\"@M17NDIR@\" -DM17N_MODULE_DIR=\"${libdir}/@M17N_MODULE_DIR@\" -DGETTEXTDIR=\"@GETTEXTDIR@\"
+
+BASICHEADERS = m17n-core.h m17n.h m17n-misc.h m17n-flt.h
+if WITH_GUI
+include_HEADERS = $(BASICHEADERS) m17n-gui.h m17n-X.h
+else
+include_HEADERS = $(BASICHEADERS)
+endif
+
+SRC =  ${libm17n_core_la_SOURCES} \
+       ${libm17n_la_SOURCES} \
+       ${libm17n_gui_la_SOURCES} \
+       ${libm17n_X_la_SOURCES} \
+       ${libm17n_gd_la_SOURCES}
+
+TAGS: ${SRC}
+       etags ${SRC}
+
+if MAINTAINER_MODE
+noinst_PROGRAMS = linkcore linkshell linkgui
+
+linkcore_SOURCES = linkcore.c
+linkcore_LDADD = ${top_builddir}/src/libm17n-core.la
+linkcore_LDFLAGS = -static
+
+linkshell_SOURCES = linkshell.c
+linkshell_LDADD = ${top_builddir}/src/libm17n.la
+linkshell_LDFLAGS = -static
+
+linkgui_SOURCES = linkgui.c
+linkgui_LDADD = ${top_builddir}/src/libm17n-gui.la
+linkgui_LDFLAGS = -static
+endif
diff --git a/src/Makefile.in b/src/Makefile.in
new file mode 100644 (file)
index 0000000..5d6d9e9
--- /dev/null
@@ -0,0 +1,914 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  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@
+
+# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010
+#   National Institute of Advanced Industrial Science and Technology (AIST)
+#   Registration Number H15PRO112
+
+# This file is part of the m17n library.
+
+# The m17n 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.1 of
+# the License, or (at your option) any later version.
+
+# The m17n 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 the m17n library; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+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@
+@MAINTAINER_MODE_TRUE@noinst_PROGRAMS = linkcore$(EXEEXT) \
+@MAINTAINER_MODE_TRUE@ linkshell$(EXEEXT) linkgui$(EXEEXT)
+subdir = src
+DIST_COMMON = README $(am__include_HEADERS_DIST) $(srcdir)/Makefile.am \
+       $(srcdir)/Makefile.in $(srcdir)/config.h.in ChangeLog
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/codeset.m4 \
+       $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/glibc2.m4 \
+       $(top_srcdir)/m4/glibc21.m4 $(top_srcdir)/m4/iconv.m4 \
+       $(top_srcdir)/m4/intdiv0.m4 $(top_srcdir)/m4/intmax.m4 \
+       $(top_srcdir)/m4/inttypes-pri.m4 $(top_srcdir)/m4/inttypes.m4 \
+       $(top_srcdir)/m4/inttypes_h.m4 $(top_srcdir)/m4/isc-posix.m4 \
+       $(top_srcdir)/m4/lcmessage.m4 $(top_srcdir)/m4/lib-ld.m4 \
+       $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
+       $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/longdouble.m4 \
+       $(top_srcdir)/m4/longlong.m4 $(top_srcdir)/m4/ltoptions.m4 \
+       $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+       $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \
+       $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/printf-posix.m4 \
+       $(top_srcdir)/m4/progtest.m4 $(top_srcdir)/m4/signed.m4 \
+       $(top_srcdir)/m4/size_max.m4 $(top_srcdir)/m4/stdint_h.m4 \
+       $(top_srcdir)/m4/uintmax_t.m4 $(top_srcdir)/m4/ulonglong.m4 \
+       $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/m4/wint_t.m4 \
+       $(top_srcdir)/m4/xsize.m4 $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+       $(ACLOCAL_M4)
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_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 = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(moduledir)" \
+       "$(DESTDIR)$(includedir)"
+LTLIBRARIES = $(lib_LTLIBRARIES) $(module_LTLIBRARIES)
+am__DEPENDENCIES_1 =
+@WITH_GUI_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) \
+@WITH_GUI_TRUE@        $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
+@WITH_GUI_TRUE@libm17n_X_la_DEPENDENCIES = $(am__DEPENDENCIES_2) \
+@WITH_GUI_TRUE@        ${top_builddir}/src/libm17n-core.la \
+@WITH_GUI_TRUE@        ${top_builddir}/src/libm17n.la \
+@WITH_GUI_TRUE@        ${top_builddir}/src/libm17n-flt.la \
+@WITH_GUI_TRUE@        ${top_builddir}/src/libm17n-gui.la
+am__libm17n_X_la_SOURCES_DIST = m17n-X.h m17n-X.c
+@WITH_GUI_TRUE@am_libm17n_X_la_OBJECTS = m17n-X.lo
+libm17n_X_la_OBJECTS = $(am_libm17n_X_la_OBJECTS)
+libm17n_X_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(libm17n_X_la_LDFLAGS) $(LDFLAGS) -o $@
+@WITH_GUI_TRUE@am_libm17n_X_la_rpath = -rpath $(moduledir)
+libm17n_core_la_DEPENDENCIES =
+am_libm17n_core_la_OBJECTS = character.lo chartab.lo database.lo \
+       plist.lo m17n-core.lo mtext.lo symbol.lo textprop.lo \
+       mtext-lbrk.lo mtext-wseg.lo
+libm17n_core_la_OBJECTS = $(am_libm17n_core_la_OBJECTS)
+libm17n_core_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(libm17n_core_la_LDFLAGS) $(LDFLAGS) -o $@
+@WITH_GUI_FALSE@am_libm17n_core_la_rpath = -rpath $(libdir)
+@WITH_GUI_TRUE@am_libm17n_core_la_rpath = -rpath $(libdir)
+libm17n_flt_la_DEPENDENCIES = ${top_builddir}/src/libm17n-core.la
+am__objects_1 = m17n-flt.lo
+am_libm17n_flt_la_OBJECTS = $(am__objects_1)
+libm17n_flt_la_OBJECTS = $(am_libm17n_flt_la_OBJECTS)
+libm17n_flt_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(libm17n_flt_la_LDFLAGS) $(LDFLAGS) -o $@
+@WITH_GUI_FALSE@am_libm17n_flt_la_rpath = -rpath $(libdir)
+@WITH_GUI_TRUE@am_libm17n_flt_la_rpath = -rpath $(libdir)
+@WITH_GUI_TRUE@libm17n_gd_la_DEPENDENCIES =  \
+@WITH_GUI_TRUE@        ${top_builddir}/src/libm17n-core.la \
+@WITH_GUI_TRUE@        ${top_builddir}/src/libm17n.la \
+@WITH_GUI_TRUE@        ${top_builddir}/src/libm17n-flt.la \
+@WITH_GUI_TRUE@        ${top_builddir}/src/libm17n-gui.la
+am__libm17n_gd_la_SOURCES_DIST = m17n-gd.c
+@WITH_GUI_TRUE@am_libm17n_gd_la_OBJECTS = m17n-gd.lo
+libm17n_gd_la_OBJECTS = $(am_libm17n_gd_la_OBJECTS)
+libm17n_gd_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(libm17n_gd_la_LDFLAGS) $(LDFLAGS) -o $@
+@WITH_GUI_TRUE@am_libm17n_gd_la_rpath = -rpath $(moduledir)
+libm17n_gui_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+       ${top_builddir}/src/libm17n-core.la \
+       ${top_builddir}/src/libm17n.la \
+       ${top_builddir}/src/libm17n-flt.la
+am__objects_2 = face.lo font.lo font-ft.lo fontset.lo draw.lo \
+       input-gui.lo m17n-gui.lo
+am_libm17n_gui_la_OBJECTS = $(am__objects_2)
+libm17n_gui_la_OBJECTS = $(am_libm17n_gui_la_OBJECTS)
+libm17n_gui_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(libm17n_gui_la_LDFLAGS) $(LDFLAGS) -o $@
+@WITH_GUI_TRUE@am_libm17n_gui_la_rpath = -rpath $(libdir)
+libm17n_la_DEPENDENCIES = ${top_builddir}/src/libm17n-core.la
+am_libm17n_la_OBJECTS = charset.lo coding.lo input.lo language.lo \
+       locale.lo m17n.lo
+libm17n_la_OBJECTS = $(am_libm17n_la_OBJECTS)
+libm17n_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(libm17n_la_LDFLAGS) $(LDFLAGS) -o $@
+@WITH_GUI_FALSE@am_libm17n_la_rpath = -rpath $(libdir)
+@WITH_GUI_TRUE@am_libm17n_la_rpath = -rpath $(libdir)
+PROGRAMS = $(noinst_PROGRAMS)
+am__linkcore_SOURCES_DIST = linkcore.c
+@MAINTAINER_MODE_TRUE@am_linkcore_OBJECTS = linkcore.$(OBJEXT)
+linkcore_OBJECTS = $(am_linkcore_OBJECTS)
+@MAINTAINER_MODE_TRUE@linkcore_DEPENDENCIES =  \
+@MAINTAINER_MODE_TRUE@ ${top_builddir}/src/libm17n-core.la
+linkcore_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+       --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(linkcore_LDFLAGS) \
+       $(LDFLAGS) -o $@
+am__linkgui_SOURCES_DIST = linkgui.c
+@MAINTAINER_MODE_TRUE@am_linkgui_OBJECTS = linkgui.$(OBJEXT)
+linkgui_OBJECTS = $(am_linkgui_OBJECTS)
+@MAINTAINER_MODE_TRUE@linkgui_DEPENDENCIES =  \
+@MAINTAINER_MODE_TRUE@ ${top_builddir}/src/libm17n-gui.la
+linkgui_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+       --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(linkgui_LDFLAGS) \
+       $(LDFLAGS) -o $@
+am__linkshell_SOURCES_DIST = linkshell.c
+@MAINTAINER_MODE_TRUE@am_linkshell_OBJECTS = linkshell.$(OBJEXT)
+linkshell_OBJECTS = $(am_linkshell_OBJECTS)
+@MAINTAINER_MODE_TRUE@linkshell_DEPENDENCIES =  \
+@MAINTAINER_MODE_TRUE@ ${top_builddir}/src/libm17n.la
+linkshell_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(linkshell_LDFLAGS) $(LDFLAGS) -o $@
+DEFAULT_INCLUDES = -I.@am__isrc@
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+       $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+       --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+       $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+       --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+       $(LDFLAGS) -o $@
+SOURCES = $(libm17n_X_la_SOURCES) $(libm17n_core_la_SOURCES) \
+       $(libm17n_flt_la_SOURCES) $(libm17n_gd_la_SOURCES) \
+       $(libm17n_gui_la_SOURCES) $(libm17n_la_SOURCES) \
+       $(linkcore_SOURCES) $(linkgui_SOURCES) $(linkshell_SOURCES)
+DIST_SOURCES = $(am__libm17n_X_la_SOURCES_DIST) \
+       $(libm17n_core_la_SOURCES) $(libm17n_flt_la_SOURCES) \
+       $(am__libm17n_gd_la_SOURCES_DIST) $(libm17n_gui_la_SOURCES) \
+       $(libm17n_la_SOURCES) $(am__linkcore_SOURCES_DIST) \
+       $(am__linkgui_SOURCES_DIST) $(am__linkshell_SOURCES_DIST)
+am__include_HEADERS_DIST = m17n-core.h m17n.h m17n-misc.h m17n-flt.h \
+       m17n-gui.h m17n-X.h
+HEADERS = $(include_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ALLOCA = @ALLOCA@
+AMTAR = @AMTAR@
+ANTHY_CFLAGS = @ANTHY_CFLAGS@
+ANTHY_LD_FLAGS = @ANTHY_LD_FLAGS@
+ANTHY_LIBS = @ANTHY_LIBS@
+API_VERSION = @API_VERSION@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@
+CATOBJEXT = @CATOBJEXT@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CONFIG_FLAGS = @CONFIG_FLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DATADIRNAME = @DATADIRNAME@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+FONTCONFIG_LD_FLAGS = @FONTCONFIG_LD_FLAGS@
+FREETYPE_LD_FLAGS = @FREETYPE_LD_FLAGS@
+FRIBIDI_LD_FLAGS = @FRIBIDI_LD_FLAGS@
+GD_LD_FLAGS = @GD_LD_FLAGS@
+GENCAT = @GENCAT@
+GETTEXTDIR = @GETTEXTDIR@
+GLIBC2 = @GLIBC2@
+GLIBC21 = @GLIBC21@
+GLIB_2_0_CFLAGS = @GLIB_2_0_CFLAGS@
+GLIB_2_0_LIBS = @GLIB_2_0_LIBS@
+GMSGFMT = @GMSGFMT@
+GREP = @GREP@
+HAVE_ASPRINTF = @HAVE_ASPRINTF@
+HAVE_FREETYPE_CONFIG = @HAVE_FREETYPE_CONFIG@
+HAVE_FRIBIDI_CONFIG = @HAVE_FRIBIDI_CONFIG@
+HAVE_ISPELL = @HAVE_ISPELL@
+HAVE_M17N_DB = @HAVE_M17N_DB@
+HAVE_OTFLIB_CONFIG = @HAVE_OTFLIB_CONFIG@
+HAVE_PKG_CONFIG = @HAVE_PKG_CONFIG@
+HAVE_POSIX_PRINTF = @HAVE_POSIX_PRINTF@
+HAVE_SNPRINTF = @HAVE_SNPRINTF@
+HAVE_WPRINTF = @HAVE_WPRINTF@
+HAVE_XFT_CONFIG = @HAVE_XFT_CONFIG@
+HAVE_XML2_CONFIG = @HAVE_XML2_CONFIG@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+INSTOBJEXT = @INSTOBJEXT@
+INTLBISON = @INTLBISON@
+INTLLIBS = @INTLLIBS@
+INTLOBJS = @INTLOBJS@
+INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@
+INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBICONV = @LIBICONV@
+LIBINTL = @LIBINTL@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTHAI_CFLAGS = @LIBTHAI_CFLAGS@
+LIBTHAI_LIBS = @LIBTHAI_LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBICONV = @LTLIBICONV@
+LTLIBINTL = @LTLIBINTL@
+LTLIBOBJS = @LTLIBOBJS@
+M17NDIR = @M17NDIR@
+M17N_MODULE_DIR = @M17N_MODULE_DIR@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+MKINSTALLDIRS = @MKINSTALLDIRS@
+MSGFMT = @MSGFMT@
+MSGMERGE = @MSGMERGE@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTF_LD_FLAGS = @OTF_LD_FLAGS@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+POSUB = @POSUB@
+POW_LIB = @POW_LIB@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+THAI_WORDSEG_LD_FLAGS = @THAI_WORDSEG_LD_FLAGS@
+USE_INCLUDED_LIBINTL = @USE_INCLUDED_LIBINTL@
+USE_NLS = @USE_NLS@
+VERSION = @VERSION@
+WORDCUT_CFLAGS = @WORDCUT_CFLAGS@
+WORDCUT_LIBS = @WORDCUT_LIBS@
+X11_LD_FLAGS = @X11_LD_FLAGS@
+XAW_LD_FLAGS = @XAW_LD_FLAGS@
+XFT2_LD_FLAGS = @XFT2_LD_FLAGS@
+XGETTEXT = @XGETTEXT@
+XMKMF = @XMKMF@
+XML2_LD_FLAGS = @XML2_LD_FLAGS@
+X_CFLAGS = @X_CFLAGS@
+X_EXTRA_LIBS = @X_EXTRA_LIBS@
+X_LIBS = @X_LIBS@
+X_PRE_LIBS = @X_PRE_LIBS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+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@
+builddir = @builddir@
+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@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+VINFO = -version-info @API_VERSION@
+BASICBUILDS = libm17n-core.la libm17n.la libm17n-flt.la
+@WITH_GUI_FALSE@BUILD_LIBS = $(BASICBUILDS)
+@WITH_GUI_TRUE@BUILD_LIBS = $(BASICBUILDS) libm17n-gui.la
+lib_LTLIBRARIES = $(BUILD_LIBS)
+libm17n_core_la_SOURCES = \
+       character.h character.c \
+       chartab.h chartab.c \
+       database.h database.c \
+       internal.h \
+       plist.h plist.c \
+       m17n-core.h m17n-core.c \
+       m17n-misc.h \
+       mtext.h mtext.c \
+       symbol.h symbol.c \
+       textprop.h textprop.c \
+       mtext-lbrk.c mtext-wseg.c
+
+libm17n_core_la_LIBADD = @XML2_LD_FLAGS@ @THAI_WORDSEG_LD_FLAGS@
+libm17n_core_la_LDFLAGS = -export-dynamic ${VINFO}
+libm17n_la_SOURCES = \
+       charset.h charset.c \
+       coding.h coding.c \
+       input.h input.c \
+       language.h language.c \
+       mlocale.h locale.c \
+       m17n.h m17n.c
+
+libm17n_la_LIBADD = ${top_builddir}/src/libm17n-core.la -ldl
+libm17n_la_LDFLAGS = -export-dynamic ${VINFO}
+FLT_SOURCES = \
+       internal-flt.h \
+       m17n-flt.h m17n-flt.c
+
+libm17n_flt_la_SOURCES = ${FLT_SOURCES}
+libm17n_flt_la_LIBADD = ${top_builddir}/src/libm17n-core.la
+libm17n_flt_la_LDFLAGS = -export-dynamic ${VINFO}
+GUI_SOURCES = \
+       face.h face.c \
+       font.h font.c font-ft.c \
+       fontset.h fontset.c \
+       draw.c \
+       input-gui.c \
+       internal-gui.h \
+       m17n-gui.h m17n-gui.c
+
+OPTIONAL_LD_FLAGS = \
+       @FREETYPE_LD_FLAGS@ \
+       @FRIBIDI_LD_FLAGS@ \
+       @OTF_LD_FLAGS@ \
+       @FONTCONFIG_LD_FLAGS@
+
+libm17n_gui_la_SOURCES = ${GUI_SOURCES}
+libm17n_gui_la_LIBADD = ${OPTIONAL_LD_FLAGS} ${top_builddir}/src/libm17n-core.la ${top_builddir}/src/libm17n.la ${top_builddir}/src/libm17n-flt.la
+libm17n_gui_la_LDFLAGS = -export-dynamic ${VINFO}
+@WITH_GUI_TRUE@moduledir = ${libdir}/@M17N_MODULE_DIR@
+@WITH_GUI_TRUE@module_LTLIBRARIES = libm17n-X.la libm17n-gd.la
+@WITH_GUI_TRUE@X_LD_FLAGS = ${X_PRE_LIBS} ${X_LIBS} @X11_LD_FLAGS@ ${X_EXTRA_LIBS}
+@WITH_GUI_TRUE@libm17n_X_la_SOURCES = m17n-X.h m17n-X.c
+@WITH_GUI_TRUE@libm17n_X_la_LIBADD = ${X_LD_FLAGS} @XFT2_LD_FLAGS@ ${top_builddir}/src/libm17n-core.la ${top_builddir}/src/libm17n.la ${top_builddir}/src/libm17n-flt.la ${top_builddir}/src/libm17n-gui.la
+@WITH_GUI_TRUE@libm17n_X_la_LDFLAGS = -avoid-version -module
+@WITH_GUI_TRUE@libm17n_gd_la_SOURCES = m17n-gd.c
+@WITH_GUI_TRUE@libm17n_gd_la_LIBADD = @GD_LD_FLAGS@ @FREETYPE_LD_FLAGS@ ${top_builddir}/src/libm17n-core.la ${top_builddir}/src/libm17n.la ${top_builddir}/src/libm17n-flt.la ${top_builddir}/src/libm17n-gui.la
+@WITH_GUI_TRUE@libm17n_gd_la_LDFLAGS = -avoid-version -module
+AM_CPPFLAGS = -DM17NDIR=\"@M17NDIR@\" -DM17N_MODULE_DIR=\"${libdir}/@M17N_MODULE_DIR@\" -DGETTEXTDIR=\"@GETTEXTDIR@\"
+BASICHEADERS = m17n-core.h m17n.h m17n-misc.h m17n-flt.h
+@WITH_GUI_FALSE@include_HEADERS = $(BASICHEADERS)
+@WITH_GUI_TRUE@include_HEADERS = $(BASICHEADERS) m17n-gui.h m17n-X.h
+SRC = ${libm17n_core_la_SOURCES} \
+       ${libm17n_la_SOURCES} \
+       ${libm17n_gui_la_SOURCES} \
+       ${libm17n_X_la_SOURCES} \
+       ${libm17n_gd_la_SOURCES}
+
+@MAINTAINER_MODE_TRUE@linkcore_SOURCES = linkcore.c
+@MAINTAINER_MODE_TRUE@linkcore_LDADD = ${top_builddir}/src/libm17n-core.la
+@MAINTAINER_MODE_TRUE@linkcore_LDFLAGS = -static
+@MAINTAINER_MODE_TRUE@linkshell_SOURCES = linkshell.c
+@MAINTAINER_MODE_TRUE@linkshell_LDADD = ${top_builddir}/src/libm17n.la
+@MAINTAINER_MODE_TRUE@linkshell_LDFLAGS = -static
+@MAINTAINER_MODE_TRUE@linkgui_SOURCES = linkgui.c
+@MAINTAINER_MODE_TRUE@linkgui_LDADD = ${top_builddir}/src/libm17n-gui.la
+@MAINTAINER_MODE_TRUE@linkgui_LDFLAGS = -static
+all: config.h
+       $(MAKE) $(AM_MAKEFLAGS) all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+       @for dep in $?; do \
+         case '$(am__configure_deps)' in \
+           *$$dep*) \
+             ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+               && { if test -f $@; then exit 0; else break; fi; }; \
+             exit 1;; \
+         esac; \
+       done; \
+       echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
+       $(am__cd) $(top_srcdir) && \
+         $(AUTOMAKE) --gnu src/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: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+config.h: stamp-h1
+       @if test ! -f $@; then \
+         rm -f stamp-h1; \
+         $(MAKE) $(AM_MAKEFLAGS) stamp-h1; \
+       else :; fi
+
+stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
+       @rm -f stamp-h1
+       cd $(top_builddir) && $(SHELL) ./config.status src/config.h
+$(srcdir)/config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) 
+       ($(am__cd) $(top_srcdir) && $(AUTOHEADER))
+       rm -f stamp-h1
+       touch $@
+
+distclean-hdr:
+       -rm -f config.h stamp-h1
+install-libLTLIBRARIES: $(lib_LTLIBRARIES)
+       @$(NORMAL_INSTALL)
+       test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
+       @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
+       list2=; for p in $$list; do \
+         if test -f $$p; then \
+           list2="$$list2 $$p"; \
+         else :; fi; \
+       done; \
+       test -z "$$list2" || { \
+         echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
+         $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
+       }
+
+uninstall-libLTLIBRARIES:
+       @$(NORMAL_UNINSTALL)
+       @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
+       for p in $$list; do \
+         $(am__strip_dir) \
+         echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \
+         $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \
+       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
+install-moduleLTLIBRARIES: $(module_LTLIBRARIES)
+       @$(NORMAL_INSTALL)
+       test -z "$(moduledir)" || $(MKDIR_P) "$(DESTDIR)$(moduledir)"
+       @list='$(module_LTLIBRARIES)'; test -n "$(moduledir)" || list=; \
+       list2=; for p in $$list; do \
+         if test -f $$p; then \
+           list2="$$list2 $$p"; \
+         else :; fi; \
+       done; \
+       test -z "$$list2" || { \
+         echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(moduledir)'"; \
+         $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(moduledir)"; \
+       }
+
+uninstall-moduleLTLIBRARIES:
+       @$(NORMAL_UNINSTALL)
+       @list='$(module_LTLIBRARIES)'; test -n "$(moduledir)" || list=; \
+       for p in $$list; do \
+         $(am__strip_dir) \
+         echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(moduledir)/$$f'"; \
+         $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(moduledir)/$$f"; \
+       done
+
+clean-moduleLTLIBRARIES:
+       -test -z "$(module_LTLIBRARIES)" || rm -f $(module_LTLIBRARIES)
+       @list='$(module_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
+libm17n-X.la: $(libm17n_X_la_OBJECTS) $(libm17n_X_la_DEPENDENCIES) 
+       $(libm17n_X_la_LINK) $(am_libm17n_X_la_rpath) $(libm17n_X_la_OBJECTS) $(libm17n_X_la_LIBADD) $(LIBS)
+libm17n-core.la: $(libm17n_core_la_OBJECTS) $(libm17n_core_la_DEPENDENCIES) 
+       $(libm17n_core_la_LINK) $(am_libm17n_core_la_rpath) $(libm17n_core_la_OBJECTS) $(libm17n_core_la_LIBADD) $(LIBS)
+libm17n-flt.la: $(libm17n_flt_la_OBJECTS) $(libm17n_flt_la_DEPENDENCIES) 
+       $(libm17n_flt_la_LINK) $(am_libm17n_flt_la_rpath) $(libm17n_flt_la_OBJECTS) $(libm17n_flt_la_LIBADD) $(LIBS)
+libm17n-gd.la: $(libm17n_gd_la_OBJECTS) $(libm17n_gd_la_DEPENDENCIES) 
+       $(libm17n_gd_la_LINK) $(am_libm17n_gd_la_rpath) $(libm17n_gd_la_OBJECTS) $(libm17n_gd_la_LIBADD) $(LIBS)
+libm17n-gui.la: $(libm17n_gui_la_OBJECTS) $(libm17n_gui_la_DEPENDENCIES) 
+       $(libm17n_gui_la_LINK) $(am_libm17n_gui_la_rpath) $(libm17n_gui_la_OBJECTS) $(libm17n_gui_la_LIBADD) $(LIBS)
+libm17n.la: $(libm17n_la_OBJECTS) $(libm17n_la_DEPENDENCIES) 
+       $(libm17n_la_LINK) $(am_libm17n_la_rpath) $(libm17n_la_OBJECTS) $(libm17n_la_LIBADD) $(LIBS)
+
+clean-noinstPROGRAMS:
+       @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
+       echo " rm -f" $$list; \
+       rm -f $$list || exit $$?; \
+       test -n "$(EXEEXT)" || exit 0; \
+       list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+       echo " rm -f" $$list; \
+       rm -f $$list
+linkcore$(EXEEXT): $(linkcore_OBJECTS) $(linkcore_DEPENDENCIES) 
+       @rm -f linkcore$(EXEEXT)
+       $(linkcore_LINK) $(linkcore_OBJECTS) $(linkcore_LDADD) $(LIBS)
+linkgui$(EXEEXT): $(linkgui_OBJECTS) $(linkgui_DEPENDENCIES) 
+       @rm -f linkgui$(EXEEXT)
+       $(linkgui_LINK) $(linkgui_OBJECTS) $(linkgui_LDADD) $(LIBS)
+linkshell$(EXEEXT): $(linkshell_OBJECTS) $(linkshell_DEPENDENCIES) 
+       @rm -f linkshell$(EXEEXT)
+       $(linkshell_LINK) $(linkshell_OBJECTS) $(linkshell_LDADD) $(LIBS)
+
+mostlyclean-compile:
+       -rm -f *.$(OBJEXT)
+
+distclean-compile:
+       -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/character.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/charset.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chartab.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/coding.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/database.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/draw.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/face.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/font-ft.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/font.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fontset.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/input-gui.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/input.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/language.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/linkcore.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/linkgui.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/linkshell.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/locale.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/m17n-X.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/m17n-core.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/m17n-flt.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/m17n-gd.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/m17n-gui.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/m17n.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mtext-lbrk.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mtext-wseg.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mtext.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plist.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/symbol.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/textprop.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@   $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@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@   $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@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@   $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@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
+install-includeHEADERS: $(include_HEADERS)
+       @$(NORMAL_INSTALL)
+       test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)"
+       @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
+       for p in $$list; do \
+         if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+         echo "$$d$$p"; \
+       done | $(am__base_list) | \
+       while read files; do \
+         echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \
+         $(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \
+       done
+
+uninstall-includeHEADERS:
+       @$(NORMAL_UNINSTALL)
+       @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
+       files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+       test -n "$$files" || exit 0; \
+       echo " ( cd '$(DESTDIR)$(includedir)' && rm -f" $$files ")"; \
+       cd "$(DESTDIR)$(includedir)" && rm -f $$files
+
+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; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       mkid -fID $$unique
+tags: TAGS
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
+               $(TAGS_FILES) $(LISP)
+       list='$(SOURCES) $(HEADERS) config.h.in $(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; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       test -z "$(CTAGS_ARGS)$$unique" \
+         || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+            $$unique
+
+GTAGS:
+       here=`$(am__cd) $(top_builddir) && pwd` \
+         && $(am__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)'; \
+         dist_files=`for file in $$list; do echo $$file; done | \
+         sed -e "s|^$$srcdirstrip/||;t" \
+             -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+       case $$dist_files in \
+         */*) $(MKDIR_P) `echo "$$dist_files" | \
+                          sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+                          sort -u` ;; \
+       esac; \
+       for file in $$dist_files; do \
+         if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+         if test -d $$d/$$file; then \
+           dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+           if test -d "$(distdir)/$$file"; then \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+             cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+         else \
+           test -f "$(distdir)/$$file" \
+           || cp -p $$d/$$file "$(distdir)/$$file" \
+           || exit 1; \
+         fi; \
+       done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS) config.h
+installdirs:
+       for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(moduledir)" "$(DESTDIR)$(includedir)"; do \
+         test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+       done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+       @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+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)
+       -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_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-am
+
+clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
+       clean-moduleLTLIBRARIES clean-noinstPROGRAMS mostlyclean-am
+
+distclean: distclean-am
+       -rm -rf ./$(DEPDIR)
+       -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+       distclean-hdr distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-includeHEADERS install-moduleLTLIBRARIES
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-libLTLIBRARIES
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+       -rm -rf ./$(DEPDIR)
+       -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+       mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES \
+       uninstall-moduleLTLIBRARIES
+
+.MAKE: all install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+       clean-libLTLIBRARIES clean-libtool clean-moduleLTLIBRARIES \
+       clean-noinstPROGRAMS ctags distclean distclean-compile \
+       distclean-generic distclean-hdr distclean-libtool \
+       distclean-tags distdir dvi dvi-am html html-am info info-am \
+       install install-am install-data install-data-am install-dvi \
+       install-dvi-am install-exec install-exec-am install-html \
+       install-html-am install-includeHEADERS install-info \
+       install-info-am install-libLTLIBRARIES install-man \
+       install-moduleLTLIBRARIES install-pdf install-pdf-am \
+       install-ps install-ps-am install-strip installcheck \
+       installcheck-am installdirs maintainer-clean \
+       maintainer-clean-generic mostlyclean mostlyclean-compile \
+       mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+       tags uninstall uninstall-am uninstall-includeHEADERS \
+       uninstall-libLTLIBRARIES uninstall-moduleLTLIBRARIES
+
+
+TAGS: ${SRC}
+       etags ${SRC}
+
+# 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/README b/src/README
new file mode 100644 (file)
index 0000000..afc3a7c
--- /dev/null
@@ -0,0 +1,23 @@
+Naming convention.
+
+name-space             internal        external
+==========             ========        ========
+function               mobject__xxx    mobject_xxx
+symbol variable                Mobject__xxx    Mobject_xxx
+other variable         mobject__xxx    mobject_xxx
+constant macro                 MOBJECT_XXX
+other macro                    MOBJECT_XXX
+type                           MObject[Xxx]
+
+A structure is named as MXxxxx and is `typedef'ed with the same name.
+Ex: typedef struct MFace MFace
+
+In comments, a structure member is denoted simply as `<member_name>',
+but a member of a specific structure is denoted as
+`MStruct->member_name'.  If the member itself is a structure (or a
+pointer to a structure) and has a sub-member, the sub-member is
+denoted as:
+       `<member_name.sub_name>'
+       or `<member_name->sub_name>'
+       or `MStruct->member_name.subname'
+       or `MStruct->member_name->subname'
diff --git a/src/character.c b/src/character.c
new file mode 100644 (file)
index 0000000..45ba1fd
--- /dev/null
@@ -0,0 +1,659 @@
+/* character.c -- character module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nCharacter
+    @brief Character objects and API for them.
+
+    The m17n library represents a @e character by a character code (an
+    integer).  The minimum character code is @c 0.  The maximum
+    character code is defined by the macro #MCHAR_MAX.  It is
+    assured that #MCHAR_MAX is not smaller than @c 0x3FFFFF (22
+    bits).
+
+    Characters @c 0 to @c 0x10FFFF are equivalent to the Unicode
+    characters of the same code values.
+
+    A character can have zero or more properties called @e character
+    @e properties.  A character property consists of a @e key and a
+    @e value, where key is a symbol and value is anything that can be
+    cast to <tt>(void *)</tt>.  "The character property that belongs
+    to character C and whose key is K" may be shortened to "the K
+    property of C".  */
+
+/***ja
+    @addtogroup m17nCharacter
+    @brief Ê¸»ú¥ª¥Ö¥¸¥§¥¯¥È¤È¤½¤ì¤Ë´Ø¤¹¤ë API.
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï @e Ê¸»ú ¤òʸ»ú¥³¡¼¥É¡ÊÀ°¿ô¡Ë¤Çɽ¸½¤¹¤ë¡£
+    ºÇ¾®¤Îʸ»ú¥³¡¼¥É¤Ï @c 0 ¤Ç¤¢¤ê¡¢ºÇÂç¤Îʸ»ú¥³¡¼¥É¤Ï¥Þ¥¯¥í #MCHAR_MAX 
+    ¤Ë¤è¤Ã¤ÆÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£#MCHAR_MAX ¤Ï @c 0x3FFFFF¡Ê22¥Ó¥Ã¥È¡Ë
+    °Ê¾å¤Ç¤¢¤ë¤³¤È¤¬Êݾڤµ¤ì¤Æ¤¤¤ë¡£
+
+    @c 0 ¤«¤é @c 0x10FFFF ¤Þ¤Ç¤Îʸ»ú¤Ï¡¢¤½¤ì¤ÈƱ¤¸Ãͤò»ý¤Ä Unicode 
+    ¤Îʸ»ú¤Ë³ä¤êÅö¤Æ¤é¤ì¤Æ¤¤¤ë¡£
+
+    ³Æʸ»ú¤Ï @e Ê¸»ú¥×¥í¥Ñ¥Æ¥£ ¤È¸Æ¤Ö¥×¥í¥Ñ¥Æ¥£¤ò 0 ¸Ä°Ê¾å»ý¤Ä¤³¤È¤¬¤Ç¤­¤ë¡£
+    Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Ï @e ¥­¡¼ ¤È @e ÃÍ ¤«¤é¤Ê¤ë¡£
+    ¥­¡¼¤Ï¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢ÃͤϠ<tt>(void *)</tt> ·¿¤Ë¥­¥ã¥¹¥È¤Ç¤­¤ë¤â¤Î¤Ê¤é²¿¤Ç¤â¤è¤¤¡£ 
+    ¡Öʸ»ú C ¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¥­¡¼¤¬ K ¤Ç¤¢¤ë¤â¤Î¡×¤ò´Êñ¤Ë¡Öʸ»ú C 
+    ¤Î K ¥×¥í¥Ñ¥Æ¥£¡×¤È¸Æ¤Ö¤³¤È¤¬¤¢¤ë¡£  */
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <ctype.h>
+#include <stdio.h>
+
+#include "m17n-core.h"
+#include "m17n-misc.h"
+#include "internal.h"
+
+typedef struct
+{
+  MSymbol type;
+  void *mdb;
+  MCharTable *table;
+} MCharPropRecord;
+
+static MPlist *char_prop_list;
+
+static void
+free_string (int from, int to, void *str, void *arg)
+{
+  free (str);
+}
+
+\f
+/* Internal API */
+
+int
+mchar__init ()
+{
+  Mname = msymbol ("name");
+  Mcategory = msymbol ("category");
+  Mcombining_class = msymbol ("combining-class");
+  Mbidi_category = msymbol ("bidirectional-category");
+  Msimple_case_folding = msymbol ("simple-case-folding");
+  Mcomplicated_case_folding = msymbol ("complicated-case-folding");
+  Mcased = msymbol ("cased");
+  Msoft_dotted = msymbol ("soft-dotted");
+  Mcase_mapping = msymbol ("case-mapping");
+  Mblock = msymbol ("block");
+  Mscript = msymbol ("script");
+
+  return 0;
+}
+
+void
+mchar__fini (void)
+{
+  MPlist *p;
+
+  if (char_prop_list)
+    {
+      for (p = char_prop_list; mplist_key (p) != Mnil; p = mplist_next (p))
+       {
+         MCharPropRecord *record = mplist_value (p);
+
+         if (record->table)
+           {
+             if (record->type == Mstring)
+               mchartable_map (record->table, NULL, free_string, NULL);
+             M17N_OBJECT_UNREF (record->table);
+           }
+         free (record);
+       }
+      M17N_OBJECT_UNREF (char_prop_list);
+    }
+}
+
+void
+mchar__define_prop (MSymbol key, MSymbol type, void *mdb)
+{
+  MCharPropRecord *record;
+
+  if (char_prop_list)
+    record = mplist_get (char_prop_list, key);
+  else
+    char_prop_list = mplist (), record = NULL;
+  if (record)
+    {
+      if (record->table)
+       M17N_OBJECT_UNREF (record->table);
+    }
+  else
+    {
+      MSTRUCT_CALLOC (record, MERROR_CHAR);
+      mplist_put (char_prop_list, key, record);
+    }
+
+  record->type = type;
+  record->mdb = mdb;
+  if (mdb)
+    {
+      record->table = NULL;
+    }
+  else
+    {
+      void *default_value = NULL;
+
+      if (type == Minteger)
+       default_value = (void *) -1;
+      record->table = mchartable (type, default_value);
+    }
+}
+
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+\f
+/* External API */
+
+/*** @addtogroup m17nCharacter
+     @{ */
+/*=*/
+
+#ifdef FOR_DOXYGEN
+/***en
+    @brief Maximum character code.
+
+    The macro #MCHAR_MAX gives the maximum character code.  */
+
+/***ja
+    @brief Ê¸»ú¥³¡¼¥É¤ÎºÇÂçÃÍ.
+
+    ¥Þ¥¯¥í #MCHAR_MAX ¤Ïʸ»ú¥³¡¼¥É¤ÎºÇÂçÃͤòɽ¤¹¡£  */
+
+#define MCHAR_MAX
+/*=*/
+#endif /* FOR_DOXYGEN */
+
+/***en
+    @name Variables: Keys of character properties
+
+    These symbols are used as keys of character properties.  */
+
+/***ja
+    @ingroup m17nCharacter
+    @name ÊÑ¿ô: Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼
+
+    ¤³¤ì¤é¤Î¥·¥ó¥Ü¥ë¤Ïʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£*/
+
+/*=*/
+/*** @{ */
+
+/***en
+    @brief Key for script.
+
+    The symbol #Mscript has the name <tt>"script"</tt> and is used as the key
+    of a character property.  The value of such a property is a symbol
+    representing the script to which the character belongs.
+
+    Each symbol that represents a script has one of the names listed in
+    the <em>Unicode Technical Report #24</em>.  */
+
+/***ja
+    @brief ¥¹¥¯¥ê¥×¥È¤òɽ¤ï¤¹¥­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Mscript ¤Ï <tt>"script"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
+    ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢¤³¤Îʸ»ú¤Î°¤¹¤ë¥¹¥¯¥ê¥×¥È¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    ¥¹¥¯¥ê¥×¥È¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Î̾Á°¤Ï¡¢<em>Unicode Technical Report
+    #24</em> ¤Ë¥ê¥¹¥È¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£  */
+
+MSymbol Mscript;
+
+/*=*/
+
+/***en
+    @brief Key for character name.
+
+    The symbol #Mname has the name <tt>"name"</tt> and is used as
+    the key of a character property.  The value of such a property is a
+    C-string representing the name of the character.  */
+
+/***ja
+    @brief Ì¾Á°¤òɽ¤ï¤¹¥­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Mname ¤Ï <tt>"name"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
+    ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϤ½¤Îʸ»ú¤Î̾Á°¤òɽ¤ï¤¹ C ¤Îʸ»úÎó¤Ç¤¢¤ë¡£  */
+
+MSymbol Mname;
+
+/*=*/
+
+/***en
+    @brief Key for general category.
+
+    The symbol #Mcategory has the name <tt>"category"</tt> and is
+    used as the key of a character property.  The value of such a
+    property is a symbol representing the <em>general category</em> of
+    the character.
+
+    Each symbol that represents a general category has one of the
+    names listed as abbreviations for <em>General Category</em> in
+    Unicode.  */
+
+/***ja
+    @brief °ìÈÌ¥«¥Æ¥´¥ê¤òɽ¤ï¤¹¥­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Mcategory ¤Ï <tt>"category"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
+    ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë <em>°ìÈÌ¥«¥Æ¥´¥ê</em> ¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    °ìÈÌ¥«¥Æ¥´¥ê¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Î̾Á°¤Ï¡¢<em>General Category</em> 
+    ¤Î¾Êά·Á¤È¤·¤Æ Unicode ¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤Ç¤¢¤ë¡£  */
+
+MSymbol Mcategory;
+
+/*=*/
+
+/***en
+    @brief Key for canonical combining class.
+
+    The symbol #Mcombining_class has the name
+    <tt>"combining-class"</tt> and is used as the key of a character
+    property.  The value of such a property is an integer that
+    represents the <em>canonical combining class</em> of the character.
+
+    The meaning of each integer that represents a canonical combining
+    class is identical to the one defined in Unicode.  */
+
+/***ja
+    @brief É¸½à·ë¹ç¥¯¥é¥¹¤òɽ¤ï¤¹¥­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Mcombining_class ¤Ï <tt>"combining-class"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
+    ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë @e É¸½à·ë¹ç¥¯¥é¥¹ ¤òɽ¤ï¤¹À°¿ô¤Ç¤¢¤ë¡£
+
+    É¸½à·ë¹ç¥¯¥é¥¹¤òɽ¤ï¤¹À°¿ô¤Î°ÕÌ£¤Ï¡¢Unicode 
+    ¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤ÈƱ¤¸¤Ç¤¢¤ë¡£  */
+
+MSymbol Mcombining_class;
+/*=*/
+
+/***en
+    @brief Key for bidi category.
+
+    The symbol #Mbidi_category has the name <tt>"bidi-category"</tt>
+    and is used as the key of a character property.  The value of such
+    a property is a symbol that represents the <em>bidirectional
+    category</em> of the character.
+
+    Each symbol that represents a bidirectional category has one of
+    the names listed as types of <em>Bidirectional Category</em> in
+    Unicode.  */
+
+/***ja
+    @brief ÁÐÊý¸þ¥«¥Æ¥´¥ê¤òɽ¤ï¤¹¥­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Mbidi_category ¤Ï <tt>"bidi-category"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
+    ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë @e ÁÐÊý¸þ¥«¥Æ¥´¥ê ¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    ÁÐÊý¸þ¥«¥Æ¥´¥ê¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Î̾Á°¤Ï¡¢<em>Bidirectional
+    Category</em> ¤Î·¿¤È¤·¤Æ Unicode ¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤Ç¤¢¤ë¡£  */
+
+MSymbol Mbidi_category;
+/*=*/
+
+/***en
+    @brief Key for corresponding single lowercase character.
+
+    The symbol #Msimple_case_folding has the name
+    <tt>"simple-case-folding"</tt> and is used as the key of a
+    character property.  The value of such a property is the
+    corresponding single lowercase character that is used when
+    comparing M-texts ignoring cases.
+
+    If a character requires a complicated comparison (i.e. cannot be
+    compared by simply mapping to another single character), the value
+    of such a property is @c 0xFFFF.  In this case, the character has
+    another property whose key is #Mcomplicated_case_folding.  */
+
+/***ja
+    @brief Âбþ¤¹¤ë¾®Ê¸»ú°ìʸ»ú¤òɽ¤ï¤¹¥­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Msimple_case_folding ¤Ï <tt>"simple-case-folding"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
+    ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë¾®Ê¸»ú°ìʸ»ú¤Ç¤¢¤ê¡¢Âçʸ»ú¡¿¾®Ê¸»ú¤Î¶èÊ̤ò̵»ë¤·¤¿Ê¸»úÎóÈæ³Ó¤ÎºÝ¤Ë»È¤ï¤ì¤ë¡£
+
+    Ê£»¨¤ÊÈæ³ÓÊýË¡¤òɬÍפȤ¹¤ëʸ»ú¤Ç¤¢¤Ã¤¿¾ì¹ç
+    ¡ÊÊ̤ΰìʸ»ú¤ÈÂбþÉÕ¤±¤ë¤³¤È¤Ë¤è¤Ã¤ÆÈæ³Ó¤Ç¤­¤Ê¤¤¾ì¹ç¡Ë¡¢¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϠ
+    @c 0xFFFF ¤Ë¤Ê¤ë¡£¤³¤Î¾ì¹ç¤½¤Îʸ»ú¤Ï¡¢#Mcomplicated_case_folding
+    ¤È¤¤¤¦¥­¡¼¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¡£  */
+
+MSymbol Msimple_case_folding;
+/*=*/
+
+/***en
+    @brief Key for corresponding multiple lowercase characters.
+
+    The symbol #Mcomplicated_case_folding has the name
+    <tt>"complicated-case-folding"</tt> and is used as the key of a
+    character property.  The value of such a property is the
+    corresponding M-text that contains a sequence of lowercase
+    characters to be used for comparing M-texts ignoring case.  */
+
+/***ja
+    @brief Âбþ¤¹¤ë¾®Ê¸»ú¤ÎÎó¤òɽ¤ï¤¹¥­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Mcomplicated_case_folding ¤Ï 
+    <tt>"complicated-case-folding"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
+    ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë¾®Ê¸»úÎ󤫤é¤Ê¤ë M-text ¤Ç¤¢¤ê¡¢Âçʸ»ú¡¿¾®Ê¸»ú¤Î¶èÊ̤ò̵»ë¤·¤¿Ê¸»úÎóÈæ³Ó¤ÎºÝ¤Ë»È
+    ¤ï¤ì¤ë¡£
+      */
+
+MSymbol Mcomplicated_case_folding;
+/*=*/
+
+/***en
+    @brief Key for values used in case operation.
+
+    The symbol #Mcased has the name <tt>"cased"</tt> and is used as
+    the key of charater property.  The value of such a property is an
+    integer value 1, 2, or 3 representing "cased", "case-ignorable",
+    and both of them respective.  See the Unicode Standard 5.0
+    (Section 3.13 Default Case Algorithm) for the detail.
+ */
+
+/***ja
+    @brief Case ½èÍý¤ËÍѤ¤¤é¤ì¤ëÃͤΥ­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Mcased ¤Ï¡¢<tt>"cased"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ
+    ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤÏÀ°¿ôÃÍ 1, 2, 3 ¤Î¤¤¤º
+    ¤ì¤«¤Ç¤¢¤ê¡¢¤½¤ì¤¾¤ì "cased", "case-ignorable", ¤½¤ÎξÊý¤ò°ÕÌ£¤¹¤ë¡£
+    ¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¡¢the Unicode Standard 5.0 (Section 3.13 Default
+    Case Algorithm) »²¾È¡£
+ */
+MSymbol Mcased;
+
+/*=*/
+/***en
+    @brief Key for values used in case operation.
+
+    The symbol #Msoft_dotted has the name <tt>"soft-dotted"</tt> and
+    is used as the key of charater property.  The value of such a
+    property is #Mt if a character has "Soft_Dotted" property, and
+    #Mnil otherwise.  See the Unicode Standard 5.0 (Section 3.13
+    Default Case Algorithm) for the detail.  */
+
+/***ja
+    @brief Case ½èÍý¤ËÍѤ¤¤é¤ì¤ëÃͤΥ­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Msoft_dotted ¤Ï¡¢<tt>"soft-dotted"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
+    Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Ê¸»ú¤¬
+    "Soft_Dotted"¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¾ì¹ç¤Ë¤Ï #Mt, ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð #Mnil ¤Ç
+    ¤¢¤ë¡£ ¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¡¢the Unicode Standard 5.0 (Section 3.13
+    Default Case Algorithm) »²¾È¡£
+ */
+MSymbol Msoft_dotted;
+
+/*=*/
+/***en 
+    @brief Key for values used in case operation.
+
+    The symbol #Mcase_mapping has the name <tt>"case-mapping"</tt> and
+    is used as the key of charater property.  The value of such a
+    property is a plist of three M-Texts; lower, title, and upper of
+    the corresponding character.  See the Unicode Standard 5.0
+    (Section 5.18 Case Mappings) for the detail.  */
+
+/***ja
+    @brief Case ½èÍý¤ËÍѤ¤¤é¤ì¤ëÃͤΥ­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Mcase_mapping ¤Ï¡¢<tt>"case-mapping"</tt> ¤È¤¤¤¦Ì¾Á°¤ò¤â
+    ¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢£³¤Ä
+    ¤Î M-text¡¢¤¹¤Ê¤ï¤Á¤½¤Îʸ»ú¤Î lower, title, ¤È upper¤«¤é¤Ê¤ë plist
+    ¤Ç¤¢¤ë¡£ ¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¡¢the Unicode Standard 5.0 (Section 3.13
+    Default Case Algorithm) »²¾È¡£
+*/
+MSymbol Mcase_mapping;
+
+/*=*/
+/***en 
+    @brief Key for script block name.
+
+    The symbol #Mblock the name <tt>"block"</tt> and is used as the
+    key of charater property.  The value of such a property is a
+    symbol representing a script block of the corresponding
+    character.  */
+/***ja
+    @brief ¥¹¥¯¥ê¥×¥È¥Ö¥í¥Ã¥¯Ì¾¤òɽ¤¹¥­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Mblock ¤Ï¡¢<tt>"block"</tt> ¤È¤¤¤¦Ì¾Á°¤ò¤â¤Á¡¢Ê¸»ú¥×¥í¥Ñ
+    ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢¤½¤Îʸ»ú¤Î¥¹¥¯¥ê¥×
+    ¥È¥Ö¥í¥Ã¥¯Ì¾¤òɽ¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£*/
+MSymbol Mblock;
+
+/*** @} */
+/*=*/
+
+/***en
+    @brief Define a character property.
+
+    The mchar_define_property () function searches the m17n database
+    for a data whose tags are \<#Mchar_table, $TYPE, $SYM \>.
+    Here, $SYM is a symbol whose name is $NAME.  $TYPE must be
+    #Mstring, #Mtext, #Msymbol, #Minteger, or #Mplist.
+
+    @return
+    If the operation was successful, mchar_define_property () returns
+    $SYM.  Otherwise it returns #Mnil.  */
+
+/***ja
+    @brief Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤òÄêµÁ¤¹¤ë.
+
+    ´Ø¿ô mchar_define_property () ¤Ï¡¢ \<#Mchar_table, $TYPE, $SYM \>
+    ¤È¤¤¤¦¥¿¥°¤ò»ý¤Ã¤¿¥Ç¡¼¥¿¥Ù¡¼¥¹¤ò m17n ¸À¸ì¾ðÊó¥Ù¡¼¥¹¤«¤éõ¤¹¡£  
+    ¤³¤³¤Ç $SYM ¤Ï $NAME ¤È¤¤¤¦Ì¾Á°¤Î¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£$TYPE ¤Ï#Mstring,
+    #Mtext, #Msymbol, #Minteger, #Mplist ¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
+
+    @return
+    ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð mchar_define_property () ¤Ï$SYM ¤òÊÖ¤¹¡£
+    ¼ºÇÔ¤·¤¿¾ì¹ç¤Ï #Mnil ¤òÊÖ¤¹¡£  */
+
+/***
+    @errors
+    @c MERROR_DB
+
+    @seealso
+    mchar_get_prop (), mchar_put_prop ()  */
+
+MSymbol
+mchar_define_property (const char *name, MSymbol type)
+{
+  MSymbol key = msymbol (name);
+  void *mdb;
+
+  mdb = mdatabase_find (Mchar_table, type, key, Mnil);
+  if (! mdb)
+    return Mnil;
+  mchar__define_prop (key, type, mdb);
+  return key;
+}
+
+/*=*/
+
+/***en
+    @brief Get the value of a character property.
+
+    The mchar_get_prop () function searches character $C for the
+    character property whose key is $KEY.
+
+    @return
+    If the operation was successful, mchar_get_prop () returns the
+    value of the character property.  Otherwise it returns @c
+    NULL.  */
+
+/***ja
+    @brief Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë.
+
+    ´Ø¿ô mchar_get_prop () ¤Ï¡¢Ê¸»ú $C ¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¥­¡¼¤¬ 
+    $KEY ¤Ç¤¢¤ë¤â¤Î¤òõ¤¹¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mchar_get_prop () ¤Ï¸«¤Ä¤«¤Ã¤¿¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£
+    ¼ºÇÔ¤·¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mchar_get_prop} @endlatexonly
+*/
+/***
+    @errors
+    @c MERROR_SYMBOL, @c MERROR_DB
+
+    @seealso
+    mchar_define_property (), mchar_put_prop ()  */
+
+void *
+mchar_get_prop (int c, MSymbol key)
+{
+  MCharPropRecord *record;
+
+  if (! char_prop_list)
+    return NULL;
+  record = mplist_get (char_prop_list, key);
+  if (! record)
+    return NULL;
+  if (record->mdb)
+    {
+      record->table = mdatabase_load (record->mdb);
+      if (! record->table)
+       MERROR (MERROR_DB, NULL);
+      record->mdb = NULL;
+    }
+  return mchartable_lookup (record->table, c);
+}
+
+/*=*/
+
+/***en
+    @brief Set the value of a character property.
+
+    The mchar_put_prop () function searches character $C for the
+    character property whose key is $KEY and assigns $VAL to the value
+    of the found property.
+
+    @return
+    If the operation was successful, mchar_put_prop () returns 0.
+    Otherwise, it returns -1.  */
+/***ja
+    @brief Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÀßÄꤹ¤ë.
+
+    ´Ø¿ô mchar_put_prop () ¤Ï¡¢Ê¸»ú $C ¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¥­¡¼¤¬ $KEY 
+    ¤Ç¤¢¤ë¤â¤Î¤òõ¤·¡¢¤½¤ÎÃͤȤ·¤Æ $VAL ¤òÀßÄꤹ¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mchar_put_prop () ¤Ï0¤òÊÖ¤¹¡£¼ºÇÔ¤·¤¿¾ì¹ç¤Ï-1¤òÊÖ¤¹¡£  */
+/***
+    @errors
+    @c MERROR_SYMBOL, @c MERROR_DB
+
+    @seealso
+    mchar_define_property (), mchar_get_prop ()   */
+
+int
+mchar_put_prop (int c, MSymbol key, void *val)
+{
+  MCharPropRecord *record;
+
+  if (! char_prop_list)
+    MERROR (MERROR_CHAR, -1);
+  record = mplist_get (char_prop_list, key);
+  if (! record)
+    return -1;
+  if (record->mdb)
+    {
+      record->table = mdatabase_load (record->mdb);
+      if (! record->table)
+       MERROR (MERROR_DB, -1);
+      record->mdb = NULL;
+    }
+  return mchartable_set (record->table, c, val);
+}
+
+/*=*/
+
+/***en
+    @brief Get the char-table for a character property.
+
+    The mchar_get_prop_table () function returns a char-table that
+    contains the character property whose key is $KEY.  If $TYPE is
+    not NULL, this function stores the type of the property in the
+    place pointed by $TYPE.  See mchar_define_property () for types of
+    character property.
+
+    @return
+    If $KEY is a valid character property key, this function returns a
+    char-table.  Otherwise NULL is retuned.  */
+
+/***ja
+    @brief Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Îʸ»ú¥Æ¡¼¥Ö¥ë¤òÆÀ¤ë.
+
+    ´Ø¿ô mchar_get_prop_table () ¤Ï¡¢¥­¡¼¤¬ $KEY ¤Ç¤¢¤ëʸ»ú¥×¥í¥Ñ¥Æ¥£
+    ¤ò´Þ¤àʸ»ú¥Æ¡¼¥Ö¥ë¤òÊÖ¤¹¡£¤â¤· $TYPE ¤¬ NULL ¤Ç¤Ê¤±¤ì¤Ð¡¢ $TYPE ¤Ç
+    »Ø¤µ¤ì¤ë¾ì½ê¤Ë¤½¤Îʸ»ú¤Î¥×¥í¥Ñ¥Æ¥£¤ò³ÊǼ¤¹¤ë¡£Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¼ïÎà
+    ¤Ë´Ø¤·¤Æ¤Ï mchar_define_property () ¤ò¸«¤è¡£
+
+    @return
+    ¤â¤· $KEY ¤¬ÀµÅö¤Êʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤Ç¤¢¤ì¤Ð¡¢Ê¸»ú¥Æ¡¼¥Ö¥ë¤¬ÊÖ¤µ
+    ¤ì¤ë¡£¤½¤¦¤Ç¤Ê¤¤¾ì¹ç¤Ï NULL ¤¬ÊÖ¤µ¤ì¤ë¡£  */
+
+MCharTable *
+mchar_get_prop_table (MSymbol key, MSymbol *type)
+{
+  MCharPropRecord *record;
+
+  if (! char_prop_list)
+    return NULL;
+  record = mplist_get (char_prop_list, key);
+  if (! record)
+    return NULL;
+  if (record->mdb)
+    {
+      record->table = mdatabase_load (record->mdb);
+      if (! record->table)
+       MERROR (MERROR_DB, NULL);
+      record->mdb = NULL;
+    }
+  if (type)
+    *type = record->type;
+  return record->table;
+}
+
+/*** @} */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/character.h b/src/character.h
new file mode 100644 (file)
index 0000000..a3bc37e
--- /dev/null
@@ -0,0 +1,290 @@
+/* character.h -- header file for the character module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_CHARACTER_H_
+#define _M17N_CHARACTER_H_
+
+/*  UTF-8 format
+
+        0-7F           0xxxxxxx
+       80-7FF          110xxxxx 10xxxxxx
+       800-FFFF                1110xxxx 10xxxxxx 10xxxxxx
+     10000-1FFFFF      11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+    200000-3FFFFFF     111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 
+   4000000-7FFFFFFF    1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+
+   Unicode range:
+     0-10FFFF  0 - 11110uuu 10uuxxxx 10xxxxxx 10xxxxxx (uuuuu <= 0x10)
+
+*/
+
+#define MAX_UTF8_CHAR_BYTES 6
+#define MAX_UNICODE_CHAR_BYTES 4
+
+#define USHORT_SIZE (sizeof (unsigned short))
+#define UINT_SIZE (sizeof (unsigned int))
+
+/* Return how many bytes one unit (char, short, or int) in FORMAT
+   occupies.  */
+
+#define UNIT_BYTES(format)                             \
+  ((format) <= MTEXT_FORMAT_UTF_8 ? 1                  \
+   : (format) <= MTEXT_FORMAT_UTF_16BE ? USHORT_SIZE   \
+   : UINT_SIZE)
+
+/* Return how many units (char, short, or int) C will occupy in
+   MText->data.  If C is not in the supported range, return 0.  */
+
+#define CHAR_UNITS_ASCII(c) ((c) < 0x80)
+
+#define CHAR_UNITS_UTF8(c)     \
+  ((c) < 0x80 ? 1              \
+   : (c) < 0x800 ? 2           \
+   : (c) < 0x10000 ? 3         \
+   : (c) < 0x200000 ? 4                \
+   : (c) < 0x4000000 ? 5       \
+   : 6)
+
+#define CHAR_UNITS_UTF16(c) ((c) < 0x110000 ? (2 - ((c) < 0x10000)) : 0)
+
+#define CHAR_UNITS_UTF32(c) 1
+
+#define CHAR_UNITS(c, format)                                  \
+  ((format) <= MTEXT_FORMAT_UTF_8 ? CHAR_UNITS_UTF8 (c)                \
+   : (format) <= MTEXT_FORMAT_UTF_16BE ? CHAR_UNITS_UTF16 (c)  \
+   : CHAR_UNITS_UTF32 (c))
+
+#define CHAR_BYTES CHAR_UNITS_UTF8
+
+#define CHAR_UNITS_AT_UTF8(p)  \
+  (!(*(p) & 0x80) ? 1          \
+   : !(*(p) & 0x20) ? 2                \
+   : !(*(p) & 0x10) ? 3                \
+   : !(*(p) & 0x08) ? 4                \
+   : !(*(p) & 0x04) ? 5                \
+   : !(*(p) & 0x02) ? 6                \
+   : 0)
+
+#define CHAR_UNITS_AT_UTF16(p)                 \
+  (2 - (*(unsigned short *) (p) < 0xD800       \
+       || *(unsigned short *) (p) >= 0xDC00))
+
+#define CHAR_UNITS_AT(mt, p)                                           \
+  ((mt)->format <= MTEXT_FORMAT_UTF_8 ? CHAR_UNITS_AT_UTF8 (p)         \
+   : (mt)->format <= MTEXT_FORMAT_UTF_16BE ? CHAR_UNITS_AT_UTF16 (p)   \
+   : 1)
+
+#define CHAR_BYTES_AT CHAR_UNITS_AT_UTF8
+
+#define CHAR_UNITS_BY_HEAD_UTF8(c)     \
+  (!((c) & 0x80) ? 1                   \
+   : !((c) & 0x20) ? 2                 \
+   : !((c) & 0x10) ? 3                 \
+   : !((c) & 0x08) ? 4                 \
+   : !((c) & 0x04) ? 5                 \
+   : !((c) & 0x02) ? 6                 \
+   : 0)
+
+#define CHAR_UNITS_BY_HEAD_UTF16(c)    \
+  (2 - ((unsigned short) (c) < 0xD800 || (unsigned short) (c) >= 0xDC00))
+
+#define CHAR_UNITS_BY_HEAD(c, format)                                  \
+  ((format) <= MTEXT_FORMAT_UTF_8 ? CHAR_UNITS_BY_HEAD_UTF8 (c)        \
+   : (format) <= MTEXT_FORMAT_UTF_16BE ? CHAR_UNITS_BY_HEAD_UTF16 (c)  \
+   : 1)
+
+#define CHAR_BYTES_BY_HEAD CHAR_UNITS_BY_HEAD_UTF8
+
+#define STRING_CHAR_UTF8(p)                            \
+  (!((p)[0] & 0x80) ? (p)[0]                           \
+   : !((p)[0] & 0x20) ? ((((p)[0] & 0x1F) << 6)                \
+                        | ((p)[1] & 0x3F))             \
+   : !((p)[0] & 0x10) ? ((((p)[0] & 0x0F) << 12)       \
+                        | (((p)[1] & 0x3F) << 6)       \
+                        | ((p)[2] & 0x3F))             \
+   : !((p)[0] & 0x08) ? ((((p)[0] & 0x07) << 18)       \
+                        | (((p)[1] & 0x3F) << 12)      \
+                        | (((p)[2] & 0x3F) << 6)       \
+                        | ((p)[3] & 0x3F))             \
+   : !((p)[0] & 0x04) ? ((((p)[0] & 0x03) << 24)       \
+                        | (((p)[1] & 0x3F) << 18)      \
+                        | (((p)[2] & 0x3F) << 12)      \
+                        | (((p)[3] & 0x3F) << 6)       \
+                        | ((p)[4] & 0x3F))             \
+   : ((((p)[0] & 0x01) << 30)                          \
+      | (((p)[1] & 0x3F) << 24)                                \
+      | (((p)[2] & 0x3F) << 18)                                \
+      | (((p)[3] & 0x3F) << 12)                                \
+      | (((p)[4] & 0x3F) << 6)                         \
+      | ((p)[5] & 0x3F)))
+
+#define STRING_CHAR_UTF16(p)                                              \
+  (((unsigned short) (p)[0] < 0xD800 || (unsigned short) (p)[0] >= 0xDC00) \
+   ? (p)[0]                                                               \
+   : ((((p)[0] - 0xD800) << 10) + ((p)[1] - 0xDC00) + 0x10000))
+
+
+#define STRING_CHAR STRING_CHAR_UTF8
+
+
+#define STRING_CHAR_ADVANCE_UTF8(p)                    \
+  (!(*(p) & 0x80) ? *(p)++                             \
+   : !(*(p) & 0x20) ? (((*(p)++ & 0x1F) << 6)          \
+                      | (*(p)++ & 0x3F))               \
+   : !(*(p) & 0x10) ? (((*(p)++ & 0x0F) << 12)         \
+                      | ((*(p)++ & 0x3F) << 6)         \
+                      | (*(p)++ & 0x3F))               \
+   : !(*(p) & 0x08) ? (((*(p)++ & 0x07) << 18)         \
+                      | ((*(p)++ & 0x3F) << 12)        \
+                      | ((*(p)++ & 0x3F) << 6)         \
+                      | (*(p)++ & 0x3F))               \
+   : !(*(p) & 0x04) ? (((*(p)++ & 0x03) << 24)         \
+                      | ((*(p)++ & 0x3F) << 18)        \
+                      | ((*(p)++ & 0x3F) << 12)        \
+                      | ((*(p)++ & 0x3F) << 6)         \
+                      | (*(p)++ & 0x3F))               \
+   : (((*(p)++ & 0x01) << 30)                          \
+      | ((*(p)++ & 0x3F) << 24)                                \
+      | ((*(p)++ & 0x3F) << 18)                                \
+      | ((*(p)++ & 0x3F) << 12)                                \
+      | ((*(p)++ & 0x3F) << 6)                         \
+      | (*(p)++ & 0x3F)))
+
+#define STRING_CHAR_ADVANCE_UTF16(p)                                      \
+  (((unsigned short) (p)[0] < 0xD800 || (unsigned short) (p)[0] >= 0xDC00) \
+   ? *(p)++                                                               \
+   : (((*(p)++ - 0xD800) << 10) + (*(p)++ - 0xDC00) + 0x10000))
+
+#define STRING_CHAR_ADVANCE STRING_CHAR_ADVANCE_UTF8
+
+#define STRING_CHAR_AND_UNITS_UTF8(p, bytes)           \
+  (!((p)[0] & 0x80) ? ((bytes) = 1, (p)[0])            \
+   : !((p)[0] & 0x20) ? ((bytes) = 2,                  \
+                        ((((p)[0] & 0x1F) << 6)        \
+                         | ((p)[1] & 0x3F)))           \
+   : !((p)[0] & 0x10) ? ((bytes) = 3,                  \
+                        ((((p)[0] & 0x0F) << 12)       \
+                         | (((p)[1] & 0x3F) << 6)      \
+                         | ((p)[2] & 0x3F)))           \
+   : !((p)[0] & 0x08) ? ((bytes) = 4,                  \
+                        ((((p)[0] & 0x07) << 18)       \
+                         | (((p)[1] & 0x3F) << 12)     \
+                         | (((p)[2] & 0x3F) << 6)      \
+                         | ((p)[3] & 0x3F)))           \
+   : !((p)[0] & 0x04) ? ((bytes) = 5,                  \
+                        ((((p)[0] & 0x03) << 24)       \
+                         | (((p)[1] & 0x3F) << 18)     \
+                         | (((p)[2] & 0x3F) << 12)     \
+                         | (((p)[3] & 0x3F) << 6)      \
+                         | ((p)[4] & 0x3F)))           \
+   : ((bytes) = 6,                                     \
+      ((((p)[0] & 0x01) << 30)                         \
+       | (((p)[1] & 0x3F) << 24)                       \
+       | (((p)[2] & 0x3F) << 18)                       \
+       | (((p)[3] & 0x3F) << 12)                       \
+       | (((p)[4] & 0x3F) << 6)                                \
+       | ((p)[5] & 0x3F))))
+
+#define STRING_CHAR_AND_UNITS_UTF16(p, units)                             \
+  (((unsigned short) (p)[0] < 0xD800 || (unsigned short) (p)[0] >= 0xDC00) \
+   ? ((units) = 1, (p)[0])                                                \
+   : ((units) = 2,                                                        \
+      (((p)[0] - 0xD800) << 10) + ((p)[1] - 0xDC00) + 0x10000))
+
+#define STRING_CHAR_AND_UNITS(p, units, format)        \
+  ((format) <= MTEXT_FORMAT_UTF_8              \
+   ? STRING_CHAR_AND_UNITS_UTF8 (p, units)     \
+   : (format) <= MTEXT_FORMAT_UTF_16BE         \
+   ? STRING_CHAR_AND_UNITS_UTF16 (p, units)    \
+   : ((units) = 1, ((unsigned) (p))[0]))
+
+
+#define STRING_CHAR_AND_BYTES STRING_CHAR_AND_UNITS_UTF8
+
+#define CHAR_STRING_UTF8(c, p)                                         \
+  ((c) < 0x80                                                          \
+   ? ((p)[0] = (c), 1)                                                 \
+   : (c) < 0x800 ? ((p)[0] = (0xC0 | ((c) >> 6)),                      \
+                   (p)[1] = (0x80 | ((c) & 0x3F)),                     \
+                   2)                                                  \
+   : (c) < 0x10000 ? ((p)[0] = (0xE0 | ((c) >> 12)),                   \
+                     (p)[1] = (0x80 | (((c) >> 6) & 0x3F)),            \
+                     (p)[2] = (0x80 | ((c) & 0x3F)),                   \
+                     3)                                                \
+   : (c) < 0x200000 ? ((p)[0] = (0xF0 | ((c) >> 18)),                  \
+                      (p)[1] = (0x80 | (((c) >> 12) & 0x3F)),          \
+                      (p)[2] = (0x80 | (((c) >> 6) & 0x3F)),           \
+                      (p)[3] = (0x80 | ((c) & 0x3F)),                  \
+                      4)                                               \
+   : (c) < 0x4000000 ? ((p)[0] = 0xF8,                                 \
+                       (p)[1] = (0x80 | ((c) >> 18)),                  \
+                       (p)[2] = (0x80 | (((c) >> 12) & 0x3F)),         \
+                       (p)[3] = (0x80 | (((c) >> 6) & 0x3F)),          \
+                       (p)[4] = (0x80 | ((c) & 0x3F)),                 \
+                       5)                                              \
+   : ((p)[0] = (0xFC | ((c) >> 30)),                                   \
+      (p)[1] = (0x80 | (((c) >> 24) & 0x3F)),                          \
+      (p)[2] = (0x80 | (((c) >> 18) & 0x3F)),                          \
+      (p)[3] = (0x80 | (((c) >> 12) & 0x3F)),                          \
+      (p)[4] = (0x80 | (((c) >> 6) & 0x3F)),                           \
+      (p)[5] = (0x80 | ((c) & 0x3F)),                                  \
+      6))
+
+#define CHAR_STRING_UTF16(c, p)                        \
+  ((c) < 0x10000 ? (p)[0] = (c), 1                     \
+   : (p[0] = (((c) - 0x10000) >> 10) + 0xD800,         \
+      p[1] = (((c) - 0x10000) & 0x3FF) + 0xDC00,       \
+      2))
+
+#define CHAR_STRING CHAR_STRING_UTF8
+
+#define CHAR_HEAD_P_UTF8(p)    \
+  ((*(p) & 0xC0) != 0x80)
+
+#define CHAR_HEAD_P_UTF16(p)           \
+  (*(unsigned short *) (p) < 0xDC00    \
+   || *(unsigned short *) (p) >= 0xE000)
+
+#define CHAR_HEAD_P CHAR_HEAD_P_UTF8
+
+/** Locale-safe version of tolower ().  It works only for an ASCII
+    character.  */
+#define TOLOWER(c)  (((c) >= 'A' && (c) <= 'Z') ? (c) + 32 : (c))
+
+/** Locale-safe version of toupper ().  It works only for an ASCII
+    character.  */
+#define TOUPPER(c)  (((c) >= 'a' && (c) <= 'z') ? (c) - 32 : (c))
+
+/** Locale-safe version of isupper ().  It works only for an ASCII
+    character.  */
+#define ISUPPER(c) ((c) >= 'A' && (c) <= 'Z')
+
+/** Locale-safe version of isalnum ().  It works only for an ASCII
+    character.  */
+#define ISALNUM(c)                     \
+  (((c) >= 'A' && (c) <= 'Z')          \
+   || ((c) >= 'a' && (c) <= 'z')       \
+   || ((c) >= '0' && (c) <= '9'))
+
+extern void mchar__define_prop (MSymbol key, MSymbol type, void *mdb);
+
+#endif /* not _M17N_CHARACTER_H_ */
diff --git a/src/charset.c b/src/charset.c
new file mode 100644 (file)
index 0000000..cd9012d
--- /dev/null
@@ -0,0 +1,1549 @@
+/* charset.c -- charset module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+/***en
+    @addtogroup m17nCharset
+    @brief Charset objects and API for them.
+
+    The m17n library uses @e charset objects to represent a coded
+    character sets (CCS).  The m17n library supports many predefined
+    coded character sets.  Moreover, application programs can add
+    other charsets.  A character can belong to multiple charsets.
+
+    The m17n library distinguishes the following three concepts:
+
+    @li A @e code-point is a number assigned by the CCS to each
+    character.  Code-points may or may not be continuous.  The type
+    @c unsigned is used to represent a code-point.  An invalid
+    code-point is represented by the macro @c MCHAR_INVALID_CODE.
+
+    @li A @e character @e index is the canonical index of a character
+    in a CCS.  The character that has the character index N occupies
+    the Nth position when all the characters in the current CCS are
+    sorted by their code-points.  Character indices in a CCS are
+    continuous and start with 0.
+
+    @li A @e character @e code is the internal representation in the
+    m17n library of a character.  A character code is a signed integer
+    of 21 bits or longer.
+
+    Each charset object defines how characters are converted between
+    code-points and character codes.  To @e encode means converting
+    code-points to character codes and to @e decode means converting
+    character codes to code-points.  */
+
+/***ja
+    @addtogroup m17nCharset
+    @brief Ê¸»ú¥»¥Ã¥È¥ª¥Ö¥¸¥§¥¯¥È¤È¤½¤ì¤Ë´Ø¤¹¤ë API.
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï¡¢Éä¹æ²½Ê¸»ú½¸¹ç (CCS) ¤ò @e Ê¸»ú¥»¥Ã¥È 
+    ¤È¸Æ¤Ö¥ª¥Ö¥¸¥§¥¯¥È¤Çɽ¸½¤¹¤ë¡£
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï¿¤¯¤ÎÉä¹æ²½Ê¸»ú½¸¹ç¤ò¤¢¤é¤«¤¸¤á¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¤·¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤¬Æȼ«¤Ëʸ»ú¥»¥Ã¥È¤òÄɲ乤뤳¤È¤â²Äǽ¤Ç¤¢¤ë¡£
+    °ì¤Ä¤Îʸ»ú¤ÏÊ£¿ô¤Îʸ»ú¥»¥Ã¥È¤Ë°¤·¤Æ¤â¤è¤¤¡£
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï¡¢°Ê²¼¤Î³µÇ°¤ò¶èÊ̤·¤Æ¤¤¤ë:
+
+    @li @e ¥³¡¼¥É¥Ý¥¤¥ó¥È ¤È¤Ï¡¢CCS ¤¬¤½¤ÎÃæ¤Î¸Ä¡¹¤Îʸ»ú¤ËÂФ·¤ÆÄêµÁ¤¹¤ë¿ôÃͤǤ¢¤ë¡£
+    ¥³¡¼¥É¥Ý¥¤¥ó¥È¤ÏϢ³¤·¤Æ¤¤¤ë¤È¤Ï¸Â¤é¤Ê¤¤¡£¥³¡¼¥É¥Ý¥¤¥ó¥È¤Ï
+    @c unsigned ·¿¤Ë¤è¤Ã¤Æɽ¤µ¤ì¤ë¡£Ìµ¸ú¤Ê¥³¡¼¥É¥Ý¥¤¥ó¥È¤Ï¥Þ¥¯¥í
+    @c MCHAR_INVALID_CODE ¤Çɽ¤µ¤ì¤ë¡£
+
+    @li @e Ê¸»ú¥¤¥ó¥Ç¥Ã¥¯¥¹ ¤È¤Ï¡¢CCS Æâ¤Ç³Æʸ»ú¤Ë³ä¤êÅö¤Æ¤é¤ì¤ëÀµµ¬²½¤µ¤ì¤¿¥¤¥ó¥Ç¥Ã¥¯¥¹¤Ç¤¢¤ë¡£
+    Ê¸»ú¥¤¥ó¥Ç¥Ã¥¯¥¹¤¬ N ¤Îʸ»ú¤Ï¡¢CCS Ãæ¤ÎÁ´Ê¸»ú¤ò¥³¡¼¥É¥Ý¥¤¥ó¥È½ç¤Ëʤ٤¿¤È¤­¤Ë N ÈÖÌܤ˸½¤ï¤ì¤ë¡£
+    CCS Ãæ¤Îʸ»ú¥¤¥ó¥Ç¥Ã¥¯¥¹¤ÏϢ³¤·¤Æ¤ª¤ê¡¢0 ¤«¤é»Ï¤Þ¤ë¡£
+
+    @li @e Ê¸»ú¥³¡¼¥É ¤È¤Ï¡¢m17n ¥é¥¤¥Ö¥é¥êÆâ¤Ë¤ª¤±¤ëʸ»ú¤ÎÆâÉôɽ¸½¤Ç¤¢¤ê¡¢21 ¥Ó¥Ã¥È°Ê¾å¤ÎŤµ¤ò»ý¤ÄÉä¹çÉÕ¤­À°¿ô¤Ç¤¢¤ë¡£
+
+    ³Æʸ»ú¥»¥Ã¥È¥ª¥Ö¥¸¥§¥¯¥È¤Ï¡¢¤½¤Îʸ»ú¥»¥Ã¥È¤Ë°¤¹¤ëʸ»ú¤Î¥³¡¼¥É¥Ý¥¤¥ó¥È¤Èʸ»ú¥³¡¼¥É¤È¤Î´Ö¤ÎÊÑ´¹¤òµ¬Äꤹ¤ë¡£
+    ¥³¡¼¥É¥Ý¥¤¥ó¥È¤«¤éʸ»ú¥³¡¼¥É¤Ø¤ÎÊÑ´¹¤ò @e ¥Ç¥³¡¼¥É
+    ¤È¸Æ¤Ó¡¢Ê¸»ú¥³¡¼¥É¤«¤é¥³¡¼¥É¥Ý¥¤¥ó¥È¤Ø¤ÎÊÑ´¹¤ò @e ¥¨¥ó¥³¡¼¥É ¤È¸Æ¤Ö¡£  */
+
+
+/*=*/
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+#include "m17n.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "symbol.h"
+#include "database.h"
+#include "chartab.h"
+#include "plist.h"
+#include "charset.h"
+#include "coding.h"
+
+static int unified_max;
+
+/** List of all charsets ever defined.  */
+
+struct MCharsetList
+{
+  int size, inc, used;
+  MCharset **charsets;
+};
+
+static struct MCharsetList charset_list;
+
+static MPlist *charset_definition_list;
+
+/** Make a charset object from the template of MCharset structure
+    CHARSET, and return a pointer to the new charset object.
+    CHARSET->code_range[4N + 2] and CHARSET->code_range[4N + 3] are
+    not yet set.  */
+
+static MCharset *
+make_charset (MCharset *charset)
+{
+  unsigned min_code, max_code;
+  int i, n;
+  int *range = charset->code_range;
+
+  if (charset->dimension < 1 || charset->dimension > 4)
+    MERROR (MERROR_CHARSET, NULL);
+  if ((charset->final_byte > 0 && charset->final_byte < '0')
+      || charset->final_byte > 127)
+    MERROR (MERROR_CHARSET, NULL);
+
+  for (i = 0, n = 1; i < 4; i++)
+    {
+      if (range[i * 4] > range[i * 4 + 1])
+       MERROR (MERROR_CHARSET, NULL);
+      range[i * 4 + 2] = range[i * 4 + 1] - range[i * 4] + 1;
+      n *= range[i * 4 + 2];
+      range[i * 4 + 3] = n;
+    }
+
+  min_code = range[0] | (range[4] << 8) | (range[8] << 16) | (range[12] << 24);
+  if (charset->min_code == 0)
+    charset->min_code = min_code;
+  else if (charset->min_code < min_code)
+    MERROR (MERROR_CHARSET, NULL);
+  max_code = range[1] | (range[5] << 8) | (range[9] << 16) | (range[13] << 24);
+  if (charset->max_code == 0)  
+    charset->max_code = max_code;
+  else if (charset->max_code > max_code)
+    MERROR (MERROR_CHARSET, NULL);
+
+  charset->code_range_min_code = min_code;
+  charset->fully_loaded = 0;
+  charset->simple = 0;
+
+  if (charset->method == Msubset)
+    {
+      MCharset *parent;
+
+      if (charset->nparents != 1)
+       MERROR (MERROR_CHARSET, NULL);
+      parent = charset->parents[0];
+      if (parent->method == Msuperset
+         || charset->min_code - charset->subset_offset < parent->min_code
+         || charset->max_code - charset->subset_offset > parent->max_code)
+       MERROR (MERROR_CHARSET, NULL);
+    }
+  else if (charset->method == Msuperset)
+    {
+      if (charset->nparents < 2)
+       MERROR (MERROR_CHARSET, NULL);
+      for (i = 0; i < charset->nparents; i++)
+       if (charset->min_code > charset->parents[i]->min_code
+           || charset->max_code < charset->parents[i]->max_code)
+         MERROR (MERROR_CHARSET, NULL);
+    }
+  else
+    {
+      charset->no_code_gap
+       = (charset->dimension == 1
+          || (range[2] == 256
+              && (charset->dimension == 2
+                  || (range[6] == 256
+                      && (charset->dimension == 3
+                          || range[10] == 256)))));
+
+      if (! charset->no_code_gap)
+       {
+         int j;
+
+         memset (charset->code_range_mask, 0,
+                 sizeof charset->code_range_mask);
+         for (i = 0; i < 4; i++)
+           for (j = range[i * 4]; j <= range[i * 4 + 1]; j++)
+             charset->code_range_mask[j] |= (1 << i);
+       }
+
+      if (charset->method == Moffset)
+       {
+         charset->max_char = charset->min_char + range[15] - 1;
+         if (charset->min_char < 0
+             || charset->max_char < 0 || charset->max_char > unified_max)
+           MERROR (MERROR_CHARSET, NULL);
+         charset->simple = charset->no_code_gap;
+         charset->fully_loaded = 1;
+       }
+      else if (charset->method == Munify)
+       {
+         /* The magic number 12 below is to align to the SUB_BITS_2
+            (defined in chartab.c) boundary in a char-table.  */
+         unified_max -= ((range[15] >> 12) + 1) << 12;
+         charset->unified_max = unified_max;
+       }
+      else if (charset->method != Mmap)
+       MERROR (MERROR_CHARSET, NULL);
+    }
+
+  MLIST_APPEND1 (&charset_list, charsets, charset, MERROR_CHARSET);
+
+  if (charset->final_byte > 0)
+    {
+      MLIST_APPEND1 (&mcharset__iso_2022_table, charsets, charset,
+                    MERROR_CHARSET);
+      if (charset->revision <= 0)
+       {
+         int chars = range[2];
+
+         if (chars == 128)     /* ASCII case */
+           chars = 94;
+         else if (chars == 256) /* ISO-8859-X case */
+           chars = 96;
+         MCHARSET_ISO_2022 (charset->dimension, chars, charset->final_byte)
+           = charset;
+       }
+    }
+
+  return charset;
+}
+
+static int
+load_charset_fully (MCharset *charset)
+{
+  if (charset->method == Msubset)
+    {
+      MCharset *parent = charset->parents[0];
+
+      if (! parent->fully_loaded
+         && load_charset_fully (parent) < 0)
+       MERROR (MERROR_CHARSET, -1);
+      if (parent->method == Moffset)
+       {
+         unsigned code;
+
+         code = charset->min_code - charset->subset_offset;
+         charset->min_char = DECODE_CHAR (parent, code);
+         code = charset->max_code - charset->subset_offset;
+         charset->max_char = DECODE_CHAR (parent, code);
+       }
+      else
+       {
+         unsigned min_code = charset->min_code - charset->subset_offset;
+         unsigned max_code = charset->max_code - charset->subset_offset;
+         int min_char = DECODE_CHAR (parent, min_code);
+         int max_char = min_char;
+         
+         for (++min_code; min_code <= max_code; min_code++)
+           {
+             int c = DECODE_CHAR (parent, min_code);
+
+             if (c >= 0)
+               {
+                 if (c < min_char)
+                   min_char = c;
+                 else if (c > max_char)
+                   max_char = c;
+               }
+           }
+         charset->min_char = min_char;
+         charset->max_char = max_char;
+       }
+    }
+  else if (charset->method == Msuperset)
+    {
+      int min_char = 0, max_char = 0;
+      int i;
+
+      for (i = 0; i < charset->nparents; i++)
+       {
+         MCharset *parent = charset->parents[i];
+
+         if (! parent->fully_loaded
+             && load_charset_fully (parent) < 0)
+           MERROR (MERROR_CHARSET, -1);
+         if (i == 0)
+           min_char = parent->min_char, max_char = parent->max_char;
+         else if (parent->min_char < min_char)
+           min_char = parent->min_char;
+         else if (parent->max_char > max_char)
+           max_char = parent->max_char;
+       }
+      charset->min_char = min_char;
+      charset->max_char = max_char;
+    }
+  else                                 /* charset->method is Mmap or Munify */
+    {
+      MDatabase *mdb = mdatabase_find (Mcharset, charset->name, Mnil, Mnil);
+      MPlist *plist;
+
+      if (! mdb || ! (plist = mdatabase_load (mdb)))
+       MERROR (MERROR_CHARSET, -1);
+      charset->decoder = mplist_value (plist);
+      charset->encoder = mplist_value (mplist_next (plist));
+      M17N_OBJECT_UNREF (plist);
+      mchartable_range (charset->encoder,
+                       &charset->min_char, &charset->max_char);
+      if (charset->method == Mmap)
+       charset->simple = charset->no_code_gap;
+      else
+       charset->max_char = charset->unified_max + 1 + charset->code_range[15];
+    }
+
+  charset->fully_loaded = 1;
+  return 0;
+}
+
+/** Load a data of type @c charset from the file FD.  */
+
+static void *
+load_charset (FILE *fp, MSymbol charset_name)
+{
+  MCharset *charset = MCHARSET (charset_name);
+  int *decoder;
+  MCharTable *encoder;
+  int size;
+  int i, c;
+  int found = 0;
+  MPlist *plist;
+
+  if (! charset)
+    MERROR (MERROR_DB, NULL);
+  size = (charset->code_range[15]
+         - (charset->min_code - charset->code_range_min_code));
+  MTABLE_MALLOC (decoder, size, MERROR_DB);
+  for (i = 0; i < size; i++)
+    decoder[i] = -1;
+  encoder = mchartable (Minteger, (void *) MCHAR_INVALID_CODE);
+
+  while ((c = getc (fp)) != EOF)
+    {
+      unsigned code1, code2, c1, c2;
+      int idx1, idx2;
+      char buf[256];
+
+      ungetc (c, fp);
+      if (! fgets (buf, 256, fp))
+       break;
+      if (c != '#')
+       {
+         if (sscanf (buf, "0x%x-0x%x 0x%x", &code1, &code2, &c1) == 3)
+           {
+             idx1 = CODE_POINT_TO_INDEX (charset, code1);
+             if (idx1 >= size)
+               continue;
+             idx2 = CODE_POINT_TO_INDEX (charset, code2);
+             if (idx2 >= size)
+               idx2 = size - 1;
+             c2 = c1 + (idx2 - idx1);
+           }
+         else if (sscanf (buf, "0x%x 0x%x", &code1, &c1) == 2)
+           {
+             idx1 = idx2 = CODE_POINT_TO_INDEX (charset, code1);
+             if (idx1 >= size)
+               continue;
+             c2 = c1;
+           }
+         else
+           continue;
+         if (idx1 >= 0 && idx2 >= 0)
+           {
+             decoder[idx1] = c1;
+             mchartable_set (encoder, c1, (void *) code1);
+             for (idx1++, c1++; idx1 <= idx2; idx1++, c1++)
+               {
+                 code1 = INDEX_TO_CODE_POINT (charset, idx1);
+                 decoder[idx1] = c1;
+                 mchartable_set (encoder, c1, (void *) code1);
+               }
+             found++;
+           }
+       }
+    }
+
+  if (! found)
+    {
+      free (decoder);
+      M17N_OBJECT_UNREF (encoder);
+      return NULL;
+    }
+  plist = mplist ();
+  mplist_add (plist, Mt, decoder);
+  mplist_add (plist, Mt, encoder);
+  return plist;
+}
+
+\f
+/* Internal API */
+
+MPlist *mcharset__cache;
+
+/* Predefined charsets.  */
+MCharset *mcharset__ascii;
+MCharset *mcharset__binary;
+MCharset *mcharset__m17n;
+MCharset *mcharset__unicode;
+
+MCharsetISO2022Table mcharset__iso_2022_table;
+
+/** Initialize charset handler.  */
+
+int
+mcharset__init ()
+{
+  MPlist *param, *pl;
+
+  unified_max = MCHAR_MAX;
+
+  mdatabase__load_charset_func = load_charset;
+  mcharset__cache = mplist ();
+  mplist_set (mcharset__cache, Mt, NULL);
+
+  MLIST_INIT1 (&charset_list, charsets, 128);
+  MLIST_INIT1 (&mcharset__iso_2022_table, charsets, 128);
+  charset_definition_list = mplist ();
+
+  memset (mcharset__iso_2022_table.classified, 0,
+         sizeof (mcharset__iso_2022_table.classified));
+
+  Mmethod = msymbol ("method");
+  Moffset = msymbol ("offset");
+  Mmap = msymbol ("map");
+  Munify = msymbol ("unify");
+  Msubset = msymbol ("subset");
+  Msuperset = msymbol ("superset");
+
+  Mdimension = msymbol ("dimension");
+  Mmin_range = msymbol ("min-range");
+  Mmax_range = msymbol ("max-range");
+  Mmin_code = msymbol ("min-code");
+  Mmax_code = msymbol ("max-code");
+  Mascii_compatible = msymbol ("ascii-compatible");
+  Mfinal_byte = msymbol ("final-byte");
+  Mrevision = msymbol ("revision");
+  Mmin_char = msymbol ("min-char");
+  Mmapfile = msymbol_as_managing_key ("mapfile");
+  Mparents = msymbol_as_managing_key ("parents");
+  Msubset_offset = msymbol ("subset-offset");
+  Mdefine_coding = msymbol ("define-coding");
+  Maliases = msymbol_as_managing_key ("aliases");
+
+  param = mplist ();
+  pl = param;
+  /* Setup predefined charsets.  */
+  pl = mplist_add (pl, Mmethod, Moffset);
+  pl = mplist_add (pl, Mmin_range, (void *) 0);
+  pl = mplist_add (pl, Mmax_range, (void *) 0x7F);
+  pl = mplist_add (pl, Mascii_compatible, Mt);
+  pl = mplist_add (pl, Mfinal_byte, (void *) 'B');
+  pl = mplist_add (pl, Mmin_char, (void *) 0);
+  Mcharset_ascii = mchar_define_charset ("ascii", param);
+
+  mplist_put (param, Mmax_range, (void *) 0xFF);
+  mplist_put (param, Mfinal_byte, NULL);
+  Mcharset_iso_8859_1 = mchar_define_charset ("iso-8859-1", param);
+
+  mplist_put (param, Mmax_range, (void *) 0x10FFFF);
+  Mcharset_unicode = mchar_define_charset ("unicode", param);
+
+  mplist_put (param, Mmax_range, (void *) MCHAR_MAX);
+  Mcharset_m17n = mchar_define_charset ("m17n", param);
+
+  mplist_put (param, Mmax_range, (void *) 0xFF);
+  Mcharset_binary = mchar_define_charset ("binary", param);
+
+  M17N_OBJECT_UNREF (param);
+
+  mcharset__ascii = MCHARSET (Mcharset_ascii);
+  mcharset__binary = MCHARSET (Mcharset_binary);
+  mcharset__m17n = MCHARSET (Mcharset_m17n);
+  mcharset__unicode = MCHARSET (Mcharset_unicode);
+
+  return 0;
+}
+
+void
+mcharset__fini (void)
+{
+  int i;
+  MPlist *plist;
+
+  for (i = 0; i < charset_list.used; i++)
+    {
+      MCharset *charset = charset_list.charsets[i];
+
+      if (charset->decoder)
+       free (charset->decoder);
+      if (charset->encoder)
+       M17N_OBJECT_UNREF (charset->encoder);
+      free (charset);
+    }
+  M17N_OBJECT_UNREF (mcharset__cache);
+  MLIST_FREE1 (&charset_list, charsets);
+  MLIST_FREE1 (&mcharset__iso_2022_table, charsets);
+  MPLIST_DO (plist, charset_definition_list)
+    M17N_OBJECT_UNREF (MPLIST_VAL (plist));
+  M17N_OBJECT_UNREF (charset_definition_list);
+}
+
+
+MCharset *
+mcharset__find (MSymbol name)
+{
+  MCharset *charset;
+
+  charset = msymbol_get (name, Mcharset);
+  if (! charset)
+    {
+      MPlist *param = mplist_get (charset_definition_list, name);
+
+      MPLIST_KEY (mcharset__cache) = Mt;
+      if (! param)
+       return NULL;
+      param = mplist__from_plist (param);
+      mchar_define_charset (MSYMBOL_NAME (name), param);
+      charset = msymbol_get (name, Mcharset);
+      M17N_OBJECT_UNREF (param);
+    }
+  MPLIST_KEY (mcharset__cache) = name;
+  MPLIST_VAL (mcharset__cache) = charset;
+  return charset;
+}
+
+
+/** Return the character corresponding to code-point CODE in CHARSET.
+    If CODE is invalid for CHARSET, return -1.  */
+
+int
+mcharset__decode_char (MCharset *charset, unsigned code)
+{
+  int idx;
+
+  if (code < 128 && charset->ascii_compatible)
+    return (int) code;
+  if (code < charset->min_code || code > charset->max_code)
+    return -1;
+
+  if (! charset->fully_loaded
+      && load_charset_fully (charset) < 0)
+    MERROR (MERROR_CHARSET, -1);
+
+  if (charset->method == Msubset)
+    {
+      MCharset *parent = charset->parents[0];
+
+      code -= charset->subset_offset;
+      return DECODE_CHAR (parent, code);
+    }
+
+  if (charset->method == Msuperset)
+    {
+      int i;
+
+      for (i = 0; i < charset->nparents; i++)
+       {
+         MCharset *parent = charset->parents[i];
+         int c = DECODE_CHAR (parent, code);
+
+         if (c >= 0)
+           return c;
+       }
+      return -1;
+    }
+
+  idx = CODE_POINT_TO_INDEX (charset, code);
+  if (idx < 0)
+    return -1;
+
+  if (charset->method == Mmap)
+    return charset->decoder[idx];
+
+  if (charset->method == Munify)
+    {
+      int c = charset->decoder[idx];
+
+      if (c < 0)
+       c = charset->unified_max + 1 + idx;
+      return c;
+    }
+
+  /* Now charset->method should be Moffset.  */
+  return (charset->min_char + idx);
+}
+
+
+/** Return the code point of character C in CHARSET.  If CHARSET does not
+    contain C, return MCHAR_INVALID_CODE.  */
+
+unsigned
+mcharset__encode_char (MCharset *charset, int c)
+{
+  if (! charset->fully_loaded
+      && load_charset_fully (charset) < 0)
+    MERROR (MERROR_CHARSET, MCHAR_INVALID_CODE);
+
+  if (charset->method == Msubset)
+    {
+      MCharset *parent = charset->parents[0];
+      unsigned code = ENCODE_CHAR (parent, c);
+
+      if (code == MCHAR_INVALID_CODE)
+       return code;
+      code += charset->subset_offset;
+      if (code >= charset->min_code && code <= charset->max_code)
+       return code;
+      return MCHAR_INVALID_CODE;
+    }
+
+  if (charset->method == Msuperset)
+    {
+      int i;
+
+      for (i = 0; i < charset->nparents; i++)
+       {
+         MCharset *parent = charset->parents[i];
+         unsigned code = ENCODE_CHAR (parent, c);
+
+         if (code != MCHAR_INVALID_CODE)
+           return code;
+       }
+      return MCHAR_INVALID_CODE;
+    }
+
+  if (c < charset->min_char || c > charset->max_char)
+    return MCHAR_INVALID_CODE;
+
+  if (charset->method == Mmap)
+    return (unsigned) mchartable_lookup (charset->encoder, c);
+
+  if (charset->method == Munify)
+    {
+      if (c > charset->unified_max)
+       {
+         c -= charset->unified_max - 1;
+         return INDEX_TO_CODE_POINT (charset, c);
+       }
+      return (unsigned) mchartable_lookup (charset->encoder, c);
+    }
+
+  /* Now charset->method should be Moffset */
+  c -= charset->min_char;
+  return INDEX_TO_CODE_POINT (charset, c);
+}
+
+int
+mcharset__load_from_database ()
+{
+  MDatabase *mdb = mdatabase_find (msymbol ("charset-list"), Mnil, Mnil, Mnil);
+  MPlist *def_list, *plist;
+  MPlist *definitions = charset_definition_list;
+  int mdebug_flag = MDEBUG_CHARSET;
+
+  if (! mdb)
+    return 0;
+  MDEBUG_PUSH_TIME ();
+  def_list = (MPlist *) mdatabase_load (mdb);
+  MDEBUG_PRINT_TIME ("CHARSET", (stderr, " to load data."));
+  MDEBUG_POP_TIME ();
+  if (! def_list)
+    return -1;
+
+  MDEBUG_PUSH_TIME ();
+  MPLIST_DO (plist, def_list)
+    {
+      MPlist *pl, *p;
+      MSymbol name;
+
+      if (! MPLIST_PLIST_P (plist))
+       MERROR (MERROR_CHARSET, -1);
+      pl = MPLIST_PLIST (plist);
+      if (! MPLIST_SYMBOL_P (pl))
+       MERROR (MERROR_CHARSET, -1);
+      name = MPLIST_SYMBOL (pl);
+      pl = MPLIST_NEXT (pl);
+      definitions = mplist_add (definitions, name, pl);
+      M17N_OBJECT_REF (pl);
+      p = mplist__from_plist (pl);
+      mchar_define_charset (MSYMBOL_NAME (name), p);
+      M17N_OBJECT_UNREF (p);
+    }
+
+  M17N_OBJECT_UNREF (def_list);
+  MDEBUG_PRINT_TIME ("CHARSET", (stderr, " to parse the loaded data."));
+  MDEBUG_POP_TIME ();
+  return 0;
+}
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+/* External API */
+
+/*** @addtogroup m17nCharset */
+/*** @{ */
+/*=*/
+
+#ifdef FOR_DOXYGEN
+/***en
+    @brief Invalid code-point.
+
+    The macro #MCHAR_INVALID_CODE gives the invalid code-point.  */
+
+/***ja
+    @brief Ìµ¸ú¤Ê¥³¡¼¥É¥Ý¥¤¥ó¥È.
+
+    ¥Þ¥¯¥í #MCHAR_INVALID_CODE ¤Ï̵¸ú¤Ê¥³¡¼¥É¥Ý¥¤¥ó¥È¤ò¼¨¤¹¡£  */
+
+#define MCHAR_INVALID_CODE
+#endif
+
+/*=*/
+
+/***en
+    @name Variables: Symbols representing a charset.
+
+    Each of the following symbols represents a predefined charset.  */
+
+/***ja
+    @name ÊÑ¿ô: Ê¸»ú¥»¥Ã¥È¤òɽ¸½¤¹¤ëÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë.
+
+    °Ê²¼¤Î³Æ¥·¥ó¥Ü¥ë¤Ï¡¢ÄêµÁºÑ¤ßʸ»ú¥»¥Ã¥È¤òɽ¸½¤¹¤ë¡£  */
+/*=*/
+/*** @{ */
+/*=*/
+/***en
+    @brief Symbol representing the charset ASCII.
+
+    The symbol #Mcharset_ascii has name <tt>"ascii"</tt> and represents
+    the charset ISO 646, USA Version X3.4-1968 (ISO-IR-6).  */
+/***ja
+    @brief ASCII Ê¸»ú¥»¥Ã¥È¤òɽ¸½¤¹¤ë¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcharset_ascii ¤Ï <tt>"ascii"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢ 
+    ISO 646, USA Version X3.4-1968 (ISO-IR-6) Ê¸»ú¥»¥Ã¥È¤òɽ¸½¤¹¤ë¡£
+     */
+
+MSymbol Mcharset_ascii;
+
+/*=*/
+/***en
+    @brief Symbol representing the charset ISO/IEC 8859/1.
+
+    The symbol #Mcharset_iso_8859_1 has name <tt>"iso-8859-1"</tt>
+    and represents the charset ISO/IEC 8859-1:1998.  */
+/***ja
+    @brief ISO/IEC 8859-1:1998 Ê¸»ú¥»¥Ã¥È¤òɽ¸½¤¹¤ë¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcharset_iso_8859_1 ¤Ï <tt>"iso-8859-1"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢ISO/IEC 8859-1:1998 Ê¸»ú¥»¥Ã¥È¤òɽ¸½¤¹¤ë¡£
+    */
+
+MSymbol Mcharset_iso_8859_1;
+
+/***en
+    @brief Symbol representing the charset Unicode.
+
+    The symbol #Mcharset_unicode has name <tt>"unicode"</tt> and
+    represents the charset Unicode.  */
+/***ja
+    @brief Unicode Ê¸»ú¥»¥Ã¥È¤òɽ¸½¤¹¤ë¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcharset_unicode ¤Ï <tt>"unicode"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Unicode Ê¸»ú¥»¥Ã¥È¤òɽ¸½¤¹¤ë¡£ */
+
+MSymbol Mcharset_unicode;
+
+/*=*/
+/***en
+    @brief Symbol representing the largest charset.
+
+    The symbol #Mcharset_m17n has name <tt>"m17n"</tt> and
+    represents the charset that contains all characters supported by
+    the m17n library.  */ 
+/***ja
+    @brief Á´Ê¸»ú¤ò´Þ¤àʸ»ú¥»¥Ã¥È¤òɽ¸½¤¹¤ë¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcharset_m17n ¤Ï <tt>"m17n"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
+    m17n ¥é¥¤¥Ö¥é¥ê¤¬°·¤¦Á´¤Æ¤Îʸ»ú¤ò´Þ¤àʸ»ú¥»¥Ã¥È¤òɽ¸½¤¹¤ë¡£ */
+
+MSymbol Mcharset_m17n;
+
+/*=*/
+/***en
+    @brief Symbol representing the charset for ill-decoded characters.
+
+    The symbol #Mcharset_binary has name <tt>"binary"</tt> and
+    represents the fake charset which the decoding functions put to an
+    M-text as a text property when they encounter an invalid byte
+    (sequence).  
+
+    See @ref m17nConv for more details.  */
+
+/***ja
+    @brief Àµ¤·¤¯¥Ç¥³¡¼¥É¤Ç¤­¤Ê¤¤Ê¸»ú¤Îʸ»ú¥»¥Ã¥È¤òɽ¸½¤¹¤ë¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcharset_binary ¤Ï <tt>"binary"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢µ¶¤Î (fake) Ê¸»ú¥»¥Ã¥È¤òɽ¸½¤¹¤ë¡£
+    ¥Ç¥³¡¼¥É´Ø¿ô¤Ï¡¢M-text ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤È¤·¤Æ¡¢Ìµ¸ú¤Ê¥Ð¥¤¥È¡Ê¥·¡¼¥¯¥¨¥ó¥¹¡Ë¤ËÁø¶ø¤·¤¿°ÌÃÖ¤òÉղ乤롣
+
+     ¾ÜºÙ¤Ï @ref m17nConv »²¾È¤Î¤³¤È¡£ */
+
+MSymbol Mcharset_binary;
+
+/*=*/
+/*** @} */
+/*=*/
+
+/***en
+    @name Variables: Parameter keys for mchar_define_charset ().
+
+    These are the predefined symbols to use as parameter keys for the
+    function mchar_define_charset () (which see).  */
+
+/***ja
+    @name ÊÑ¿ô: mchar_define_charset ÍѤΥѥé¥á¡¼¥¿¡¦¥­¡¼
+
+    ¤³¤ì¤é¤Ï¡¢´Ø¿ô mchar_define_charset () ÍѤΥѥé¥á¡¼¥¿¡¦¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£ 
+    ¾Ü¤·¤¯¤Ï¤³¤Î´Ø¿ô¤Î²òÀâ¤ò»²¾È¤Î¤³¤È¡£*/
+/*** @{ */
+/*=*/
+
+MSymbol Mmethod;
+MSymbol Mdimension;
+MSymbol Mmin_range;
+MSymbol Mmax_range;
+MSymbol Mmin_code;
+MSymbol Mmax_code;
+MSymbol Mascii_compatible;
+MSymbol Mfinal_byte;
+MSymbol Mrevision;
+MSymbol Mmin_char;
+MSymbol Mmapfile;
+MSymbol Mparents;
+MSymbol Msubset_offset;
+MSymbol Mdefine_coding;
+MSymbol Maliases;
+/*=*/
+/*** @} */
+/*=*/
+
+/***en
+    @name Variables: Symbols representing charset methods.
+
+    These are the predefined symbols that can be a value of the
+    @b Mmethod parameter of a charset used in an argument to the
+    mchar_define_charset () function.
+
+    A method specifies how code-points and character codes are
+    converted.  See the documentation of the mchar_define_charset ()
+    function for the details.  */
+
+/***ja
+    @name ÊÑ¿ô: Ê¸»ú¥»¥Ã¥È¤Î¥á¥½¥Ã¥É»ØÄê¤Ë»È¤ï¤ì¤ë¥·¥ó¥Ü¥ë
+
+    ¤³¤ì¤é¤Ï¡¢Ê¸»ú¥»¥Ã¥È¤Î @e ¥á¥½¥Ã¥É ¤ò»ØÄꤹ¤ë¤¿¤á¤ÎÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢Ê¸»ú¥»¥Ã¥È¤Î
+    @b Mmethod ¥Ñ¥é¥á¡¼¥¿¤ÎÃͤȤʤ뤳¤È¤¬¤Ç¤­¤ë¡£
+    ¤³¤ÎÃͤϴؿô mchar_define_charset () ¤Î°ú¿ô¤È¤·¤Æ»È¤ï¤ì¤ë¡£
+
+    ¥á¥½¥Ã¥É¤È¤Ï¡¢¥³¡¼¥É¥Ý¥¤¥ó¥È¤Èʸ»ú¥³¡¼¥É¤òÁê¸ßÊÑ´¹¤¹¤ëºÝ¤ÎÊý¼°¤Î¤³¤È¤Ç¤¢¤ë¡£
+    ¾Ü¤·¤¯¤Ï´Ø¿ô mchar_define_charset () ¤Î²òÀâ¤ò»²¾È¤Î¤³¤È¡£  */
+/*** @{ */
+/*=*/
+/***en
+    @brief Symbol for the offset type method of charset.
+
+    The symbol #Moffset has the name <tt>"offset"</tt> and, when used
+    as a value of @b Mmethod parameter of a charset, it means that the
+    conversion of code-points and character codes of the charset is
+    done by this calculation:
+
+@verbatim
+CHARACTER-CODE = CODE-POINT - MIN-CODE + MIN-CHAR
+@endverbatim
+
+    where, MIN-CODE is a value of @b Mmin_code parameter of the charset,
+    and MIN-CHAR is a value of @b Mmin_char parameter.  */
+
+/***ja
+    @brief ¥ª¥Õ¥»¥Ã¥È·¿¤Î¥á¥½¥Ã¥É¤ò¼¨¤¹¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Moffset ¤Ï <tt>"offset"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥»¥Ã¥È¤Î
+    @b Mmethod ¥Ñ¥é¥á¡¼¥¿¤ÎÃͤȤ·¤ÆÍѤ¤¤é¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢¥³¡¼¥É¥Ý¥¤¥ó¥È¤Èʸ»ú¥»¥Ã¥È¤Îʸ»ú¥³¡¼¥É¤Î´Ö¤ÎÊÑ´¹¤¬°Ê²¼¤Î¼°¤Ë½¾¤Ã¤Æ¹Ô¤ï¤ì¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
+
+@verbatim
+ʸ»ú¥³¡¼¥É = ¥³¡¼¥É¥Ý¥¤¥ó¥È - MIN-CODE + MIN-CHAR
+@endverbatim
+
+    ¤³¤³¤Ç¡¢MIN-CODE ¤Ïʸ»ú¥»¥Ã¥È¤Î @b Mmin_code ¥Ñ¥é¥á¡¼¥¿¤ÎÃͤǤ¢¤ê¡¢MIN-CHAR ¤Ï
+    @b Mmin_char ¥Ñ¥é¥á¡¼¥¿¤ÎÃͤǤ¢¤ë¡£ */
+
+MSymbol Moffset;
+/*=*/
+
+/***en @brief Symbol for the map type method of charset.
+
+    The symbol #Mmap has the name <tt>"map"</tt> and, when used as a
+    value of @b Mmethod parameter of a charset, it means that the
+    conversion of code-points and character codes of the charset is
+    done by map looking up.  The map must be given by @b Mmapfile
+    parameter.  */
+
+/***ja @brief ¥Þ¥Ã¥×·¿¤Î¥á¥½¥Ã¥É¤ò¼¨¤¹¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mmap ¤Ï <tt>"map"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥»¥Ã¥È¤Î 
+    @b Mmethod ¥Ñ¥é¥á¡¼¥¿¤ÎÃͤȤ·¤ÆÍѤ¤¤é¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢¥³¡¼¥É¥Ý¥¤¥ó¥È¤Èʸ»ú¥»¥Ã¥È¤Îʸ»ú¥³¡¼¥É¤Î´Ö¤ÎÊÑ´¹¤¬¥Þ¥Ã¥×¤ò»²¾È¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¹Ô¤ï¤ì¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
+    ¥Þ¥Ã¥×¤Ï @b Mmapfile ¥Ñ¥é¥á¡¼¥¿¤È¤·¤ÆÍ¿¤¨¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£ */
+
+MSymbol Mmap;
+/*=*/
+
+/***en @brief Symbol for the unify type method of charset.
+
+    The symbol #Munify has the name <tt>"unify"</tt> and, when used as
+    a value of @b Mmethod parameter of a charset, it means that the
+    conversion of code-points and character codes of the charset is
+    done by map looking up and offsetting.  The map must be given by
+    @b Mmapfile parameter.  For this kind of charset, a unique
+    continuous character code space for all characters is assigned.
+
+    If the map has an entry for a code-point, the conversion is done
+    by looking up the map.  Otherwise, the conversion is done by this
+    calculation:
+
+@verbatim
+CHARACTER-CODE = CODE-POINT - MIN-CODE + LOWEST-CHAR-CODE
+@endverbatim
+
+    where, MIN-CODE is a value of @b Mmin_code parameter of the charset,
+    and LOWEST-CHAR-CODE is the lowest character code of the assigned
+    code space.  */
+
+/***ja @brief ¥æ¥Ë¥Õ¥¡¥¤·¿¤Î¥á¥½¥Ã¥É¤ò¼¨¤¹¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Munify ¤Ï <tt>"unify"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥»¥Ã¥È¤Î 
+    @b Mmethod ¥Ñ¥é¥á¡¼¥¿¤ÎÃͤȤ·¤ÆÍѤ¤¤é¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢¥³¡¼¥É¥Ý¥¤¥ó¥È¤Èʸ»ú¥»¥Ã¥È¤Îʸ»ú¥³¡¼¥É¤Î´Ö¤ÎÊÑ´¹¤¬¡¢¥Þ¥Ã¥×¤Î»²¾È¤È¥ª¥Õ¥»¥Ã¥È¤ÎÁȤ߹ç¤ï¤»¤Ë¤è¤Ã¤Æ¹Ô¤ï¤ì¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
+    ¥Þ¥Ã¥×¤Ï @b Mmapfile ¥Ñ¥é¥á¡¼¥¿¤È¤·¤ÆÍ¿¤¨¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
+    ¤³¤Î¼ï¤Î³Æʸ»ú¥»¥Ã¥È¤Ë¤Ï¡¢Á´Ê¸»ú¤ËÂФ·¤ÆϢ³¤¹¤ë¥³¡¼¥É¥¹¥Ú¡¼¥¹¤¬¤½¤ì¤¾¤ì³ä¤êÅö¤Æ¤é¤ì¤ë¡£
+
+    ¥³¡¼¥É¥Ý¥¤¥ó¥È¤¬¥Þ¥Ã¥×¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ì¤Ð¡¢ÊÑ´¹¤Ï¥Þ¥Ã¥×»²¾È¤Ë¤è¤Ã¤Æ¹Ô¤ï¤ì¤ë¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢°Ê²¼¤Î¼°¤Ë½¾¤¦¡£
+
+@verbatim
+CHARACTER-CODE = CODE-POINT - MIN-CODE + LOWEST-CHAR-CODE
+@endverbatim
+    
+    ¤³¤³¤Ç¡¢MIN-CODE ¤Ïʸ»ú¥»¥Ã¥È¤Î @b Mmin_code ¥Ñ¥é¥á¡¼¥¿¤ÎÃͤǤ¢¤ê¡¢
+    LOWEST-CHAR-CODE ¤Ï³ä¤êÅö¤Æ¤é¤ì¤¿¥³¡¼¥É¥¹¥Ú¡¼¥¹¤ÎºÇ¤â¾®¤µ¤¤Ê¸»ú¥³¡¼¥É¤Ç¤¢¤ë¡£
+    */
+
+MSymbol Munify;
+/*=*/
+
+/***en
+    @brief Symbol for the subset type method of charset.
+
+    The symbol #Msubset has the name <tt>"subset"</tt> and, when used
+    as a value of @b Mmethod parameter of a charset, it means that the
+    charset is a subset of a parent charset.  The parent charset must
+    be given by @b Mparents parameter.  The conversion of code-points
+    and character codes of the charset is done conceptually by this
+    calculation:
+
+@verbatim
+CHARACTER-CODE = PARENT-CODE (CODE-POINT) + SUBSET-OFFSET
+@endverbatim
+
+    where, PARENT-CODE is a pseudo function that returns a character
+    code of CODE-POINT in the parent charset, and SUBSET-OFFSET is a
+    value given by @b Msubset_offset parameter.  */
+
+/***ja @brief ¥µ¥Ö¥»¥Ã¥È·¿¤Î¥á¥½¥Ã¥É¤ò¼¨¤¹¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Msubset ¤Ï <tt>"subset"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥»¥Ã¥È¤Î
+    @b Mmethod ¥Ñ¥é¥á¡¼¥¿¤ÎÃͤȤ·¤ÆÍѤ¤¤é¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢¤³¤Îʸ»ú¥»¥Ã¥È¤¬Ê̤Îʸ»ú¥»¥Ã¥È¡Ê¿Æʸ»ú¥»¥Ã¥È¡Ë¤ÎÉôʬ½¸¹ç¤Ç¤¢¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
+    ¿Æʸ»ú¥»¥Ã¥È¤Ï @b Mparents ¥Ñ¥é¥á¡¼¥¿¤Ë¤è¤Ã¤ÆÍ¿¤¨¤é¤ì¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+    ¥³¡¼¥É¥Ý¥¤¥ó¥È¤Èʸ»ú¥»¥Ã¥È¤Îʸ»ú¥³¡¼¥É¤Î´Ö¤ÎÊÑ´¹¤Ï¡¢³µÇ°Åª¤Ë¤Ï°Ê²¼¤Î¼°¤Ë½¾¤¦¡£
+
+@verbatim
+CHARACTER-CODE = PARENT-CODE (CODE-POINT) + SUBSET-OFFSET
+@endverbatim
+
+    ¤³¤³¤Ç PARENT-CODE ¤Ï CODE-POINT 
+    ¤Î¿Æʸ»ú¥»¥Ã¥ÈÃæ¤Ç¤Îʸ»ú¥³¡¼¥É¤òÊÖ¤¹µ¼´Ø¿ô¤Ç¤¢¤ê¡¢SUBSET-OFFSET ¤Ï 
+    @b Msubset_offset ¥Ñ¥é¥á¡¼¥¿¤ÇÍ¿¤¨¤é¤ì¤ëÃͤǤ¢¤ë¡£
+    */
+
+MSymbol Msubset;
+/*=*/
+
+/***en
+    @brief Symbol for the superset type method of charset.
+
+    The symbol #Msuperset has the name <tt>"superset"</tt> and, when
+    used as a value of @b Mmethod parameter of a charset, it means that
+    the charset is a superset of parent charsets.  The parent charsets
+    must be given by @b Mparents parameter.  */
+
+/***ja
+    @brief ¥¹¡¼¥Ñ¡¼¥»¥Ã¥È·¿¤Î¥á¥½¥Ã¥É¤ò¼¨¤¹¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Msuperset ¤Ï <tt>"superset"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥»¥Ã¥È¤Î
+    @b Mmethod ¥Ñ¥é¥á¡¼¥¿¤ÎÃͤȤ·¤ÆÍѤ¤¤é¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢¤³¤Îʸ»ú¥»¥Ã¥È¤¬Ê̤Îʸ»ú¥»¥Ã¥È¡Ê¿Æʸ»ú¥»¥Ã¥È¡Ë¤Î¾å°Ì½¸¹ç¤Ç¤¢¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
+    ¿Æʸ»ú¥»¥Ã¥È¤Ï @b Mparents ¥Ñ¥é¥á¡¼¥¿¤Ë¤è¤Ã¤ÆÍ¿¤¨¤é¤ì¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+    */
+
+MSymbol Msuperset;
+/*=*/
+/*** @}  */ 
+
+/***en
+    @brief Define a charset.
+
+    The mchar_define_charset () function defines a new charset and
+    makes it accessible via a symbol whose name is $NAME.  $PLIST
+    specifies parameters of the charset as below:
+
+    <ul>
+
+    <li> Key is @b Mmethod, value is a symbol.
+
+    The value specifies the method for decoding/encoding code-points
+    in the charset.  It must be #Moffset, #Mmap (default), #Munify,
+    #Msubset, or #Msuperset.
+
+    <li> Key is @b Mdimension, value is an integer
+
+    The value specifies the dimension of code-points of the charset.
+    It must be 1 (default), 2, 3, or 4.
+
+    <li> Key is @b Mmin_range, value is an unsigned integer
+
+    The value specifies the minimum range of a code-point, which means
+    that the Nth byte of the value is the minimum Nth byte of
+    code-points of the charset.   The default value is 0.
+
+    <li> Key is @b Mmax_range, value is an unsigned integer
+
+    The value specifies the maximum range of a code-point, which means
+    that the Nth byte of the value is the maximum Nth byte of
+    code-points of the charset.  The default value is 0xFF, 0xFFFF,
+    0xFFFFFF, or 0xFFFFFFFF if the dimension is 1, 2, 3, or 4
+    respectively.
+
+    <li> Key is @b Mmin_code, value is an unsigned integer
+
+    The value specifies the minimum code-point of
+    the charset.  The default value is the minimum range.
+
+    <li> Key is @b Mmax_code, value is an unsigned integer
+
+    The value specifies the maximum code-point of
+    the charset.  The default value is the maximum range.
+
+    <li> Key is @b Mascii_compatible, value is a symbol
+
+    The value specifies whether the charset is ASCII compatible or
+    not.  If the value is #Mnil (default), it is not ASCII
+    compatible, else compatible.
+
+    <li> Key is @b Mfinal_byte, value is an integer
+
+    The value specifies the @e final @e byte of the charset registered
+    in The International Registry.  It must be 0 (default) or 32..127.
+    The value 0 means that the charset is not in the registry.
+
+    <li> Key is @b Mrevision, value is an integer
+
+    The value specifies the @e revision @e number of the charset
+    registered in The International Registry.  It must be 0..127.  If
+    the charset is not in The International Registry, the value is
+    ignored.  The value 0 means that the charset has no revision
+    number.
+
+    <li> Key is @b Mmin_char, value is an integer
+
+    The value specifies the minimum character code of the charset.
+    The default value is 0.
+
+    <li> Key is @b Mmapfile, value is an M-text
+
+    If the method is #Mmap or #Munify, a data that contains
+    mapping information is added to the m17n database by calling
+    the function mdatabase_define () with the value as an argument $EXTRA_INFO,
+    i.e. the value is used as a file name of the data.
+
+    Otherwise, this parameter is ignored.
+
+    <li> Key is @b Mparents, value is a plist
+
+    If the method is #Msubset, the value must is a plist of length
+    1, and the value of the plist must be a symbol representing a
+    parent charset.
+
+    If the method is #Msuperset, the value must be a plist of length
+    less than 9, and the values of the plist must be symbols
+    representing subset charsets.
+
+    Otherwise, this parameter is ignored.
+
+    <li> Key is @b Mdefine_coding, value is a symbol
+
+    If the dimension of the charset is 1, the value specifies whether
+    or not to define a coding system of the same name whose type is
+    #Mcharset.  A coding system is defined if the value is not #Mnil.
+
+    Otherwise, this parameter is ignored.
+
+    </ul>
+
+    @return
+    If the operation was successful, mchar_define_charset () returns a
+    symbol whose name is $NAME.  Otherwise it returns #Mnil and
+    assigns an error code to the external variable #merror_code.  */
+
+/***ja
+    @brief Ê¸»ú¥»¥Ã¥È¤òÄêµÁ¤¹¤ë.
+
+    ´Ø¿ô mchar_define_charset () ¤Ï¿·¤·¤¤Ê¸»ú¥»¥Ã¥È¤òÄêµÁ¤·¡¢¤½¤ì¤ò 
+    $NAME ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë·Ðͳ¤Ç¥¢¥¯¥»¥¹¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë¡£
+    $PLIST ¤ÏÄêµÁ¤µ¤ì¤ëʸ»ú¥»¥Ã¥È¤Î¥Ñ¥é¥á¡¼¥¿¤ò°Ê²¼¤Î¤è¤¦¤Ë»ØÄꤹ¤ë¡£
+
+    <ul>
+
+    <li> ¥­¡¼¤¬ @b Mmethod ¤ÇÃͤ¬¥·¥ó¥Ü¥ë¤Î»þ
+
+    Ãͤϡ¢#Moffset, #Mmap (¥Ç¥Õ¥©¥ë¥ÈÃÍ), #Munify, #Msubset,
+    #Msuperset ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ê¡¢Ê¸»ú¥»¥Ã¥È¤Î¥³¡¼¥É¥Ý¥¤¥ó¥È¤ò¥Ç¥³¡¼¥É¡¿¥¨¥ó¥³¡¼¥É¤¹¤ëºÝ¤Î¥á¥½¥Ã¥É¤ò»ØÄꤹ¤ë¡£
+
+    <li> ¥­¡¼¤¬ @b Mdimension ¤ÇÃͤ¬À°¿ôÃͤλþ
+
+    Ãͤϡ¢1 (¥Ç¥Õ¥©¥ë¥ÈÃÍ), 2, 3, 4 
+    ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ê¡¢Ê¸»ú¥»¥Ã¥È¤Î¥³¡¼¥É¥Ý¥¤¥ó¥È¤Î¼¡¸µ¤Ç¤¢¤ë¡£
+
+    <li> ¥­¡¼¤¬ @b Mmin_range ¤ÇÃͤ¬ÈóÉéÀ°¿ôÃͤλþ
+
+    Ãͤϥ³¡¼¥É¥Ý¥¤¥ó¥È¤ÎºÇ¾®¤ÎÃͤǤ¢¤ë¡£¤¹¤Ê¤ï¤Á¡¢¤³¤ÎÃͤΠN 
+    ÈÖÌܤΥХ¤¥È¤Ï¤³¤Îʸ»ú¥»¥Ã¥È¤Î¥³¡¼¥É¥Ý¥¤¥ó¥È¤Î N ÈÖÌܤΥХ¤¥È¤ÎºÇ¾®¤Î¤â¤Î¤È¤Ê¤ë¡£
+    ¥Ç¥Õ¥©¥ë¥ÈÃͤϠ0 ¡£
+
+    <li> ¥­¡¼¤¬ @b Mmax_range ¤ÇÃͤ¬ÈóÉéÀ°¿ôÃͤλþ
+
+    Ãͤϥ³¡¼¥É¥Ý¥¤¥ó¥È¤ÎºÇÂç¤ÎÃͤǤ¢¤ë¡£¤¹¤Ê¤ï¤Á¡¢¤³¤ÎÃͤΠN 
+    ÈÖÌܤΥХ¤¥È¤Ï¤³¤Îʸ»ú¥»¥Ã¥È¤Î¥³¡¼¥É¥Ý¥¤¥ó¥È¤Î N ÈÖÌܤΥХ¤¥È¤ÎºÇÂç¤Î¤â¤Î¤È¤Ê¤ë¡£
+    ¥Ç¥Õ¥©¥ë¥ÈÃͤϡ¢¥³¡¼¥É¥Ý¥¤¥ó¥È¤Î¼¡¸µ¤¬ 1, 2, 3, 4 ¤Î»þ¡¢¤½¤ì¤¾¤ì
+    0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF ¡£
+
+    <li> ¥­¡¼¤¬ @b Mmin_code ¤ÇÃͤ¬ÈóÉéÀ°¿ôÃͤλþ
+
+    ÃͤϤ³¤Îʸ»ú¥»¥Ã¥È¤ÎºÇ¾®¤Î¥³¡¼¥É¥Ý¥¤¥ó¥È¤Ç¤¢¤ë¡£¥Ç¥Õ¥©¥ë¥ÈÃͤϠ
+    @b Mmin_range ¤ÎÃÍ¡£
+
+    <li> ¥­¡¼¤¬ @b Mmax_code ¤ÇÃͤ¬ÈóÉéÀ°¿ôÃͤλþ
+
+    ÃͤϤ³¤Îʸ»ú¥»¥Ã¥È¤ÎºÇÂç¤Î¥³¡¼¥É¥Ý¥¤¥ó¥È¤Ç¤¢¤ë¡£¥Ç¥Õ¥©¥ë¥ÈÃͤϠ
+    @b Mmax_range ¤ÎÃÍ¡£
+
+    <li> ¥­¡¼¤¬  @b Mascii_compatible ¤ÇÃͤ¬¥·¥ó¥Ü¥ë¤Î»þ
+
+    ÃͤϤ³¤Îʸ»ú¥»¥Ã¥È¤¬ ASCII ¸ß´¹¤Ç¤¢¤ë¤«¤É¤¦¤«¤ò¼¨¤¹¡£¥Ç¥Õ¥©¥ë¥ÈÃͤÎ
+    #Mnil ¤Ç¤¢¤ì¤Ð¸ß´¹¤Ç¤Ï¤Ê¤¯¡¢¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï¸ß´¹¤Ç¤¢¤ë¡£
+
+    <li> ¥­¡¼¤¬  @b Mfinal_byte ¤ÇÃͤ¬À°¿ôÃͤλþ
+
+    ÃͤϤ³¤Îʸ»ú¥»¥Ã¥È¤Î The International Registry ¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë 
+    @e ½ªÃ¼¥Ð¥¤¥È ¤Ç¤¢¤ê¡¢0 (¥Ç¥Õ¥©¥ë¥ÈÃÍ) ¤Ç¤¢¤ë¤« 32..127 ¤Ç¤¢¤ë¡£0 
+    ¤ÏÅÐÏ¿¤µ¤ì¤Æ¤¤¤Ê¤¤¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
+
+    <li> ¥­¡¼¤¬  @b Mrevision ¤ÇÃͤ¬À°¿ôÃͤλþ
+
+    ÃͤϠThe International Registry ¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë @e revision @e
+    number ¤Ç¤¢¤ê¡¢0..127 ¤Ç¤¢¤ë¡£
+    Ê¸»ú¥»¥Ã¥È¤¬ÅÐÏ¿¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï¤³¤ÎÃͤÏ̵»ë¤µ¤ì¤ë¡£
+    0 ¤Ï revision number ¤¬Â¸ºß¤·¤Ê¤¤¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
+
+    <li> ¥­¡¼¤¬  @b Mmin_char ¤ÇÃͤ¬À°¿ôÃͤλþ
+
+    ÃͤϤ³¤Îʸ»ú¥»¥Ã¥È¤ÎºÇ¾®¤Îʸ»ú¥³¡¼¥É¤Ç¤¢¤ë¡£¥Ç¥Õ¥©¥ë¥ÈÃͤϠ0 ¡£
+
+    <li> ¥­¡¼¤¬ @b Mmapfile ¤ÇÃͤ¬ M-text ¤Î»þ
+
+    ¥á¥½¥Ã¥É¤¬ #Mmap ¤« #Munify ¤Î»þ¡¢´Ø¿ô mdatabase_define () 
+    ¤ò¤³¤ÎÃͤò°ú¿ô $EXTRA_INFO ¤È¤·¤Æ¸Æ¤Ö¤³¤È¤Ë¤è¤Ã¤Æ¡¢¥Þ¥Ã¥Ô¥ó¥°¤Ë´Ø¤¹¤ë¥Ç¡¼¥¿¤¬
+    m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤ËÄɲ䵤ì¤ë¡£
+    ¤¹¤Ê¤ï¤Á¡¢¤³¤ÎÃͤϥǡ¼¥¿¥Õ¥¡¥¤¥ë¤Î̾Á°¤Ç¤¢¤ë¡£
+
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢¤³¤Î¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
+
+    <li> ¥­¡¼¤¬ @b Mparents ¤ÇÃͤ¬ plist ¤Î»þ
+
+    ¥á¥½¥Ã¥É¤¬ #Msubset ¤Ê¤é¤Ð¡¢ÃͤÏŤµ 1 ¤Î plist 
+    ¤Ç¤¢¤ê¡¢¤½¤ÎÃͤϤ³¤Îʸ»ú¥»¥Ã¥È¤Î¾å°Ì½¸¹ç¤È¤Ê¤ëʸ»ú¥»¥Ã¥È¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    ¥á¥½¥Ã¥É¤¬ #Msuperset ¤Ê¤é¤Ð¡¢ÃͤÏŤµ 8 °Ê²¼¤Î plist 
+    ¤Ç¤¢¤ê¡¢¤½¤ì¤é¤ÎÃͤϤ³¤Îʸ»ú¥»¥Ã¥È¤Î²¼°Ì½¸¹ç¤Ç¤¢¤ëʸ»ú¥»¥Ã¥È¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢¤³¤Î¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
+
+    <li> ¥­¡¼¤¬  @b Mdefine_coding ¤ÇÃͤ¬¥·¥ó¥Ü¥ë¤Î»þ
+
+    Ê¸»ú¥»¥Ã¥È¤Î¼¡¸µ¤¬ 1 ¤Ê¤é¤Ð¡¢Ãͤ¬ #Mnil °Ê³°¤Î¾ì¹ç¤Ë #Mcharset ·¿
+    ¤ÇƱ¤¸Ì¾Á°¤ò»ý¤Ä¥³¡¼¥É·Ï¤òÄêµÁ¤¹¤ë¡£
+
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢¤³¤Î¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
+
+    </ul>
+
+    @return 
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mchar_define_charset() ¤Ï $NAME 
+    ¤È¤¤¤¦Ì¾Á°¤Î¥·¥ó¥Ü¥ë¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð #Mnil ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô 
+    #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£*/
+
+/***
+    @errors
+    @c MERROR_CHARSET  */
+
+MSymbol
+mchar_define_charset (const char *name, MPlist *plist)
+{
+  MSymbol sym = msymbol (name);
+  MCharset *charset;
+  int i;
+  unsigned min_range, max_range;
+  MPlist *pl;
+  MText *mapfile = (MText *) mplist_get (plist, Mmapfile);
+
+  MSTRUCT_CALLOC (charset, MERROR_CHARSET);
+  charset->name = sym;
+  charset->method = (MSymbol) mplist_get (plist, Mmethod);
+  if (! charset->method)
+    {
+      if (mapfile)
+       charset->method = Mmap;
+      else
+       charset->method = Moffset;
+    }
+  if (charset->method == Mmap || charset->method == Munify)
+    {
+      if (! mapfile)
+       MERROR (MERROR_CHARSET, Mnil);
+      mdatabase_define (Mcharset, sym, Mnil, Mnil, NULL, mapfile->data);
+    }
+  if (! (charset->dimension = (int) mplist_get (plist, Mdimension)))
+    charset->dimension = 1;
+
+  min_range = (unsigned) mplist_get (plist, Mmin_range);
+  if ((pl = mplist_find_by_key (plist, Mmax_range)))
+    {
+      max_range = (unsigned) MPLIST_VAL (pl);
+      if (max_range >= 0x1000000)
+       charset->dimension = 4;
+      else if (max_range >= 0x10000 && charset->dimension < 3)
+       charset->dimension = 3;
+      else if (max_range >= 0x100 && charset->dimension < 2)
+       charset->dimension = 2;
+    }
+  else if (charset->dimension == 1)
+    max_range = 0xFF;
+  else if (charset->dimension == 2)
+    max_range = 0xFFFF;
+  else if (charset->dimension == 3)
+    max_range = 0xFFFFFF;
+  else
+    max_range = 0xFFFFFFFF;
+
+  memset (charset->code_range, 0, sizeof charset->code_range);
+  for (i = 0; i < charset->dimension; i++, min_range >>= 8, max_range >>= 8)
+    {
+      charset->code_range[i * 4] = min_range & 0xFF;
+      charset->code_range[i * 4 + 1] = max_range & 0xFF;
+    }
+  if ((charset->min_code = (int) mplist_get (plist, Mmin_code)) < min_range)
+    charset->min_code = min_range;
+  if ((charset->max_code = (int) mplist_get (plist, Mmax_code)) > max_range)
+    charset->max_code = max_range;
+  charset->ascii_compatible
+    = (MSymbol) mplist_get (plist, Mascii_compatible) != Mnil;
+  charset->final_byte = (int) mplist_get (plist, Mfinal_byte);
+  charset->revision = (int) mplist_get (plist, Mrevision);
+  charset->min_char = (int) mplist_get (plist, Mmin_char);
+  pl = (MPlist *) mplist_get (plist, Mparents);
+  charset->nparents = pl ? mplist_length (pl) : 0;
+  if (charset->nparents > 8)
+    charset->nparents = 8;
+  for (i = 0; i < charset->nparents; i++, pl = MPLIST_NEXT (pl))
+    {
+      MSymbol parent_name;
+
+      if (MPLIST_KEY (pl) != Msymbol)
+       MERROR (MERROR_CHARSET, Mnil);
+      parent_name = MPLIST_SYMBOL (pl);
+      if (! (charset->parents[i] = MCHARSET (parent_name)))
+       MERROR (MERROR_CHARSET, Mnil);
+    }
+
+  charset->subset_offset = (int) mplist_get (plist, Msubset_offset);
+
+  msymbol_put (sym, Mcharset, charset);
+  charset = make_charset (charset);
+  if (! charset)
+    return Mnil;
+  msymbol_put (msymbol__canonicalize (sym), Mcharset, charset);
+
+  for (pl = (MPlist *) mplist_get (plist, Maliases);
+       pl && MPLIST_KEY (pl) == Msymbol;
+       pl = MPLIST_NEXT (pl))
+    {
+      MSymbol alias = MPLIST_SYMBOL (pl);
+
+      msymbol_put (alias, Mcharset, charset);
+      msymbol_put (msymbol__canonicalize (alias), Mcharset, charset);
+    }
+
+  if (mplist_get (plist, Mdefine_coding)
+      && charset->dimension == 1
+      && charset->code_range[0] == 0 && charset->code_range[1] == 255)
+    mconv__register_charset_coding (sym);
+  return (sym);
+}
+
+/*=*/
+
+/***en
+    @brief Resolve charset name.
+
+    The mchar_resolve_charset () function returns $SYMBOL if it
+    represents a charset.  Otherwise, canonicalize $SYMBOL as to a
+    charset name, and if the canonicalized name represents a charset,
+    return it.  Otherwise, return #Mnil.  */
+
+/***ja
+    @brief Ê¸»ú¥»¥Ã¥È̾¤ò²ò·è¤¹¤ë.
+
+    ´Ø¿ô mchar_resolve_charset () ¤Ï $SYMBOL 
+    ¤¬Ê¸»ú¥»¥Ã¥È¤ò¼¨¤·¤Æ¤¤¤ì¤Ð¤½¤ì¤òÊÖ¤¹¡£
+
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢$SYMBOL ¤òʸ»ú¥»¥Ã¥È̾¤È¤·¤ÆÀµµ¬²½¤·¡¢¤½¤ì¤¬Ê¸»ú¥»¥Ã¥È¤ò¼¨¤·¤Æ¤¤¤Æ¤¤¤ì¤ÐÀµµ¬²½¤·¤¿¤â¤Î¤òÊÖ¤¹¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢#Mnil ¤òÊÖ¤¹¡£ */
+
+MSymbol
+mchar_resolve_charset (MSymbol symbol)
+{
+  MCharset *charset = (MCharset *) msymbol_get (symbol, Mcharset);
+
+  if (! charset)
+    {
+      symbol = msymbol__canonicalize (symbol);
+      charset = (MCharset *) msymbol_get (symbol, Mcharset);
+    }
+
+  return (charset ? charset->name : Mnil);
+}
+
+/*=*/
+
+/***en
+    @brief List symbols representing charsets.
+
+    The mchar_list_charsets () function makes an array of symbols
+    representing a charset, stores the pointer to the array in a place
+    pointed to by $SYMBOLS, and returns the length of the array.  */
+
+/***ja
+    @brief Ê¸»ú¥»¥Ã¥È¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤òÎóµó¤¹¤ë.
+
+    ´Ø¿ô mchar_list_charsets () 
+    ¤Ï¡¢Ê¸»ú¥»¥Ã¥È¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤òʤ٤¿ÇÛÎó¤òºî¤ê¡¢$SYMBOLS 
+    ¤Ç¥Ý¥¤¥ó¥È¤µ¤ì¤¿¾ì½ê¤Ë¤³¤ÎÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÃÖ¤­¡¢ÇÛÎó¤ÎŤµ¤òÊÖ¤¹¡£ */
+
+int
+mchar_list_charset (MSymbol **symbols)
+{
+  int i;
+
+  MTABLE_MALLOC ((*symbols), charset_list.used, MERROR_CHARSET);
+  for (i = 0; i < charset_list.used; i++)
+    (*symbols)[i] = charset_list.charsets[i]->name;
+  return i;
+}
+
+/*=*/
+
+/***en
+    @brief Decode a code-point.
+
+    The mchar_decode () function decodes code-point $CODE in the
+    charset represented by the symbol $CHARSET_NAME to get a character
+    code.
+
+    @return
+    If decoding was successful, mchar_decode () returns the decoded
+    character code.  Otherwise it returns -1.  */
+
+/***ja
+    @brief ¥³¡¼¥É¥Ý¥¤¥ó¥È¤ò¥Ç¥³¡¼¥É¤¹¤ë.
+
+    ´Ø¿ô mchar_decode () ¤Ï¡¢¥·¥ó¥Ü¥ë $CHARSET_NAME ¤Ç¼¨¤µ¤ì¤ëʸ»ú¥»¥Ã¥ÈÆâ¤Î
+    $CODE ¤È¤¤¤¦¥³¡¼¥É¥Ý¥¤¥ó¥È¤ò¥Ç¥³¡¼¥É¤·¤Æʸ»ú¥³¡¼¥É¤òÆÀ¤ë¡£
+
+    @return
+    ¥Ç¥³¡¼¥É¤¬À®¸ù¤¹¤ì¤Ð¡¢mchar_decode () ¤Ï¥Ç¥³¡¼¥É¤µ¤ì¤¿Ê¸»ú¥³¡¼¥É¤òÊÖ¤¹¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤¹¡£  */
+
+/***
+    @seealso
+    mchar_encode ()  */
+
+int
+mchar_decode (MSymbol charset_name, unsigned code)
+{
+  MCharset *charset = MCHARSET (charset_name);
+
+  if (! charset)
+    return MCHAR_INVALID_CODE;
+  return DECODE_CHAR (charset, code);
+}
+
+/*=*/
+
+/***en
+    @brief Encode a character code.
+
+    The mchar_encode () function encodes character code $C to get a
+    code-point in the charset represented by the symbol $CHARSET_NAME.
+
+    @return
+    If encoding was successful, mchar_encode () returns the encoded
+    code-point.  Otherwise it returns #MCHAR_INVALID_CODE.  */
+
+/***ja
+    @brief Ê¸»ú¥³¡¼¥É¤ò¥¨¥ó¥³¡¼¥É¤¹¤ë.
+
+    ´Ø¿ô mchar_encode () ¤Ï¡¢Ê¸»ú¥³¡¼¥É $C ¤ò¥¨¥ó¥³¡¼¥É¤·¤Æ¥·¥ó¥Ü¥ë
+    $CHARSET_NAME ¤Ç¼¨¤µ¤ì¤ëʸ»ú¥»¥Ã¥ÈÆâ¤Ë¤ª¤±¤ë¥³¡¼¥É¥Ý¥¤¥ó¥È¤òÆÀ¤ë¡£
+
+    @return
+    ¥¨¥ó¥³¡¼¥É¤¬À®¸ù¤¹¤ì¤Ð¡¢mchar_encode () ¤Ï¥¨¥ó¡¼¥É¤µ¤ì¤¿¥³¡¼¥É¥Ý¥¤¥ó¥È¤òÊÖ¤¹¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð #MCHAR_INVALID_CODE ¤òÊÖ¤¹¡£  */
+
+/***
+    @seealso
+    mchar_decode ()  */
+
+unsigned
+mchar_encode (MSymbol charset_name, int c)
+{
+  MCharset *charset = MCHARSET (charset_name);
+
+  if (! charset)
+    return MCHAR_INVALID_CODE;
+  return ENCODE_CHAR (charset, c);
+}
+
+/*=*/
+
+/***en
+    @brief Call a function for all the characters in a specified charset.
+
+    The mcharset_map_chars () function calls $FUNC for all the
+    characters in the charset named $CHARSET_NAME.  A call is done for
+    a chunk of consecutive characters rather than character by
+    character.
+
+    $FUNC receives three arguments: $FROM, $TO, and $ARG.  $FROM and
+    $TO specify the range of character codes in $CHARSET.  $ARG is the
+    same as $FUNC_ARG.
+
+    @return
+    If the operation was successful, mcharset_map_chars () returns 0.
+    Otherwise, it returns -1 and assigns an error code to the external
+    variable #merror_code.  */
+
+/***ja
+    @brief »ØÄꤷ¤¿Ê¸»ú¥»¥Ã¥È¤Î¤¹¤Ù¤Æ¤Îʸ»ú¤ËÂФ·¤Æ´Ø¿ô¤ò¸Æ¤Ö.
+
+    ´Ø¿ô mcharset_map_chars () ¤Ï $CHARSET_NAME 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Äʸ»ú¥»¥Ã¥ÈÃæ¤Î¤¹¤Ù¤Æ¤Îʸ»ú¤ËÂФ·¤Æ $FUNC ¤ò¸Æ¤Ö¡£
+    ¸Æ¤Ó½Ð¤·¤Ï°ìʸ»úËè¤Ç¤Ï¤Ê¤¯¡¢Ï¢Â³¤·¤¿Ê¸»ú¤Î¤Þ¤È¤Þ¤êñ°Ì¤Ç¹Ô¤Ê¤ï¤ì¤ë¡£
+
+    ´Ø¿ô $FUNC ¤Ë¤Ï$FROM, $TO, $ARG ¤Î£³°ú¿ô¤¬ÅϤµ¤ì¤ë¡£$FROM ¤È $TO 
+    ¤Ï $CHARSET Ãæ¤Îʸ»ú¥³¡¼¥É¤ÎÈϰϤò»ØÄꤹ¤ë¡£$ARG ¤Ï $FUNC_ARG 
+    ¤ÈƱ¤¸¤Ç¤¢¤ë¡£
+
+    @return
+    ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð mcharset_map_chars () ¤Ï 0 ¤òÊÖ¤¹¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/*** 
+    @errors
+    @c MERROR_CHARSET */
+
+int
+mchar_map_charset (MSymbol charset_name,
+                  void (*func) (int from, int to, void *arg),
+                  void *func_arg)
+{
+  MCharset *charset;
+
+  charset = MCHARSET (charset_name);
+  if (! charset)
+    MERROR (MERROR_CHARSET, -1);
+
+  if (charset->encoder)
+    {
+      int c = charset->min_char;
+      int next_c;
+
+      if ((int) mchartable__lookup (charset->encoder, c, &next_c, 1) < 0)
+       c = next_c;
+      while (c <= charset->max_char)
+       {
+         if ((int) mchartable__lookup (charset->encoder, c, &next_c, 1) >= 0)
+           (*func) (c, next_c - 1, func_arg);    
+         c = next_c;
+       }
+    }
+  else
+    (*func) (charset->min_char, charset->max_char, func_arg);
+  return 0;
+}
+
+/*=*/
+
+/*** @} */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/charset.h b/src/charset.h
new file mode 100644 (file)
index 0000000..ddf3fa1
--- /dev/null
@@ -0,0 +1,253 @@
+/* charset.h -- header file for the charset module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_CHARSET_H_
+#define _M17N_CHARSET_H_
+
+/** @file charset.h
+    @brief Header for charset handlers.
+*/
+
+enum mcharset_method
+  {
+    MCHARSET_METHOD_OFFSET,
+    MCHARSET_METHOD_MAP,
+    MCHARSET_METHOD_DEFERRED,
+    MCHARSET_METHOD_SUBSET,
+    MCHARSET_METHOD_SUPERSET,
+    MCHARSET_METHOD_MAX
+  };
+
+/** Structure for charset.  */
+
+typedef struct MCharset MCharset;
+
+struct MCharset
+{
+  /** The value is always 0 because all charsets are static.  */
+  unsigned ref_count;
+
+  /** Symbol indicating the name of the charset.  */
+  MSymbol name;
+
+  /** Number of dimensions of the charset.  It must be 1, 2, 3, or
+      4.  */
+  int dimension;
+
+  /** Byte code range of each dimension.  <code_range>[4N] is a
+      minimum byte code of the (N+1)th dimension, <code_range>[4N+1]
+      is a maximum byte code of the (N+1)th dimension,
+      <code_range>[4N+2] is (<code_range>[4N+1] - <code_range>[4N] +
+      1), <code_range>[4N+3] is a number of characters contained in the
+      first to (N+1)th dimensions.  We get "char-index" of a
+      "code-point" from this information.  */
+  int code_range[16];
+
+  /** The minimum code-point calculated from <code_range>.  It may be
+      smaller than <min_code>.  */
+  int code_range_min_code;
+
+  /** Nonzero means there is no gap in code points of the charset.  If
+      <dimension> is 1, <no_code_gap> is always 1.  Otherwise,
+      <no_code_gap> is 1 iff <code_range>[4N] is zero and
+      <code_range>[4N+1] is 256 for N = 0..<dimension>-2.  If
+      <no_code_gap> is nonzero, "char-index" is "code-point" -
+      <min_code>.  */
+  int no_code_gap;
+
+  /** If the byte code B is valid in the (N+1)th dimension,
+      (<code_range_mask>[B] & (1 << N)) is 1.  Otherwise,
+      (<code_range_mask>[B] & (1 << N)) is 0.  */
+  unsigned char code_range_mask[256];
+
+  /** Minimum and maximum code-point of the charset.  */
+  unsigned min_code, max_code;
+
+  /** Nonzero means the charset encodes ASCII characters as is.  */
+  int ascii_compatible;
+
+  /** Minimum and maximum character of the charset.  If
+      <ascii_compatible> is nonzero, <min_char> is actually the
+      minimum non-ASCII character of the charset.  */
+  int min_char, max_char;
+
+  /** ISO 2022 final byte of the charset.  It must be in the range
+      48..127, or -1.  The value -1 means that the charset is not
+      encodable by ISO 2022 based coding systems.  */
+  int final_byte;
+
+  /** ISO 2022 revision number of the charset, or -1.  The value -1
+      means that the charset has no revision number.  Used only when
+      <final_byte> is not -1.  */
+  int revision;
+
+  /** Specify how to encode/decode code-point of the charset.  It must
+      be Moffset, Mmap, Munify, Msubset, or Msuperset.  */
+  MSymbol method;
+
+  /** Array of integers to decode a code-point of the charset.  It is
+      indexed by a "char-index" of the code-point, and the
+      corresponding element is a character of the charset, or -1 if
+      the code point is not valid in the charset.  Used only when
+      <method> is Mmap or Munify.  */
+  int *decoder;
+
+  /** Char-table to encode a character of the charset.  It is indexed
+      by a character code, and the corresponding element is a code
+      point of the character in the charset, or
+      MCHAR_INVALID_CODE if the character is not included in the
+      charset.  Used only when <method> is Mmap or Munify.  */
+  MCharTable *encoder;
+
+  int unified_max;
+
+  /** Array of pointers to parent charsets.  Used only when <method>
+      is Msubset or Msuperset.  Atmost 8 parents are supported.  */
+  MCharset *parents[8];
+
+  /* Number of parent charsets.  */
+  int nparents;
+
+  unsigned subset_min_code, subset_max_code;
+  int subset_offset;
+
+  int simple;
+
+  /** If the charset is fully loaded (i.e. all the above member are
+      set to correct values), the value is 1.  Otherwise, the value is
+      0.  */
+  int fully_loaded;
+};
+
+extern MPlist *mcharset__cache;
+
+/** Return a charset associated with the symbol CHARSET_SYM.  */
+
+#define MCHARSET(charset_sym)                                  \
+  (((charset_sym) == MPLIST_KEY (mcharset__cache)              \
+    || (MPLIST_KEY (mcharset__cache) = (charset_sym),          \
+       MPLIST_VAL (mcharset__cache)                            \
+       = (MCharset *) msymbol_get ((charset_sym), Mcharset)))  \
+   ? MPLIST_VAL (mcharset__cache)                              \
+   : mcharset__find (charset_sym))
+
+
+/** Return index of a character whose code-point in CHARSET is CODE.
+    If CODE is not valid, return -1.  */
+
+#define CODE_POINT_TO_INDEX(charset, code)                             \
+  ((charset)->no_code_gap                                              \
+   ? (code) - (charset)->min_code                                      \
+   : (((charset)->code_range_mask[(code) >> 24] & 0x8)                 \
+      && ((charset)->code_range_mask[((code) >> 16) & 0xFF] & 0x4)     \
+      && ((charset)->code_range_mask[((code) >> 8) & 0xFF] & 0x2)      \
+      && ((charset)->code_range_mask[(code) & 0xFF] & 0x1))            \
+   ? (((((code) >> 24) - (charset)->code_range[12])                    \
+       * (charset)->code_range[11])                                    \
+      + (((((code) >> 16) & 0xFF) - (charset)->code_range[8])          \
+        * (charset)->code_range[7])                                    \
+      + (((((code) >> 8) & 0xFF) - (charset)->code_range[4])           \
+        * (charset)->code_range[3])                                    \
+      + (((code) & 0xFF) - (charset)->code_range[0])                   \
+      - ((charset)->min_code - (charset)->code_range_min_code))                \
+   : -1)
+
+
+/* Return code-point of a character whose index is IDX.  
+   The validness of IDX is not checked.  IDX may be modified.  */
+
+#define INDEX_TO_CODE_POINT(charset, idx)                                   \
+  ((charset)->no_code_gap                                                   \
+   ? (idx) + (charset)->min_code                                            \
+   : (idx += (charset)->min_code - (charset)->code_range_min_code,          \
+      (((charset)->code_range[0] + (idx) % (charset)->code_range[2])        \
+       | (((charset)->code_range[4]                                         \
+          + ((idx) / (charset)->code_range[3] % (charset)->code_range[6]))  \
+         << 8)                                                              \
+       | (((charset)->code_range[8]                                         \
+          + ((idx) / (charset)->code_range[7] % (charset)->code_range[10])) \
+         << 16)                                                             \
+       | (((charset)->code_range[12] + ((idx) / (charset)->code_range[11]))  \
+         << 24))))
+
+
+/** Return a character whose code-point in CHARSET is CODE.  If CODE
+    is invalid, return -1.  */
+
+#define DECODE_CHAR(charset, code)                                     \
+  (((code) < 128 && (charset)->ascii_compatible)                       \
+   ? (int) (code)                                                      \
+   : ((code) < (charset)->min_code || (code) > (charset)->max_code)    \
+   ? -1                                                                        \
+   : ! (charset)->simple                                               \
+   ? mcharset__decode_char ((charset), (code))                         \
+   : (charset)->method == Moffset                                      \
+   ? (code) - (charset)->min_code + (charset)->min_char                        \
+   : (charset)->decoder[(code) - (charset)->min_code])
+
+
+/** Return a code-point in CHARSET for character C.  If CHARSET
+    does not contain C, return MCHAR_INVALID_CODE.  */
+
+#define ENCODE_CHAR(charset, c)                                        \
+  (! (charset)->simple                                         \
+   ? mcharset__encode_char ((charset), (c))                    \
+   : ((c) < (charset)->min_char || (c) > (charset)->max_char)  \
+   ? MCHAR_INVALID_CODE                                                \
+   : (charset)->method == Moffset                              \
+   ? (c) - (charset)->min_char + (charset)->min_code           \
+   : (unsigned) mchartable_lookup ((charset)->encoder, (c)))
+
+
+extern MCharset *mcharset__ascii;
+extern MCharset *mcharset__binary;
+extern MCharset *mcharset__m17n;
+extern MCharset *mcharset__unicode;
+
+#define ISO_MAX_DIMENSION 3
+#define ISO_MAX_CHARS 2
+#define ISO_MAX_FINAL 0x80     /* only 0x30..0xFF are used */
+
+typedef struct
+{
+  /* Table of ISO-2022 charsets.  */
+  int size, inc, used;
+  MCharset **charsets;
+
+  /** A 3-dimensional table indexed by "dimension", "chars", and
+      "final byte" of an ISO-2022 charset to get the correponding
+      charset.  A charset that has a revision number is not stored in
+      this table.  */
+  MCharset *classified[ISO_MAX_DIMENSION][ISO_MAX_CHARS][ISO_MAX_FINAL];
+} MCharsetISO2022Table;
+
+extern MCharsetISO2022Table mcharset__iso_2022_table;
+
+#define MCHARSET_ISO_2022(dim, chars, final) \
+  mcharset__iso_2022_table.classified[(dim) - 1][(chars) == 96][(final)]
+
+extern MCharset *mcharset__find (MSymbol name);
+extern int mcharset__decode_char (MCharset *charset, unsigned code);
+extern unsigned mcharset__encode_char (MCharset *charset, int c);
+extern int mcharset__load_from_database ();
+
+#endif /* _M17N_CHARSET_H_ */
diff --git a/src/chartab.c b/src/chartab.c
new file mode 100644 (file)
index 0000000..947b575
--- /dev/null
@@ -0,0 +1,1010 @@
+/* chartab.h -- character table module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nChartable
+    @brief Chartable objects and API for them.
+
+    The m17n library supports enormous number of characters.  Thus, if
+    attributes of each character are to be stored in a simple array,
+    such an array would be impractically big.  The attributes usually
+    used, however, are often assigned only to a range of characters.
+    Even when all characters have attributes, characters of
+    consecutive character code tend to have the same attribute values.
+
+    The m17n library utilizes this tendency to store characters and
+    their attribute values efficiently in an object called @e
+    Chartable.  Although a chartable object is not a simple array,
+    application programs can handle a chartable as if it is an array.
+    Attribute values of a character can be obtained by accessing a
+    Chartable for the attribute with the character code of the
+    specified character.
+
+    A chartable is a managed object.  */
+
+/***ja
+    @addtogroup m17nChartable Ê¸»ú¥Æ¡¼¥Ö¥ë
+
+    @brief Ê¸»ú¥Æ¡¼¥Ö¥ë¤È¤½¤ì¤Ë´Ø¤¹¤ë API.
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤¬°·¤¦Ê¸»ú¤Î¶õ´Ö¤Ï¹­Âç¤Ç¤¢¤ë¤¿¤á¡¢Ê¸»úËè¤Î¾ðÊó¤òñ½ã¤ÊÇÛÎó¤Ë³ÊǼ¤·¤è¤¦¤È¤¹¤ë¤È¡¢¤½¤ÎÇÛÎó¤ÏµðÂç¤Ë¤Ê¤ê¤¹¤®¡¢Èó¼ÂÍÑŪ¤Ç¤¢¤ë¡£
+    ¤·¤«¤·Ä̾ïɬÍפȤʤëʸ»ú¤Ë¤Ä¤¤¤Æ¤Î¾ðÊó¤Ï¡¢¤¢¤ëÆÃÄê¤ÎÈϰϤÎʸ»ú¤Ë¤Î¤ßÉÕ¤¤¤Æ¤¤¤ë¤³¤È¤¬Â¿¤¤¡£
+    Á´Ê¸»ú¤Ë´Ø¤·¤Æ¾ðÊ󤬤¢¤ë¾ì¹ç¤Ë¤â¡¢Ï¢Â³¤·¤¿Ê¸»ú¥³¡¼¥É¤ò»ý¤Äʸ»ú¤ÏƱ¤¸¾ðÊó¤ò»ý¤Ä¤³¤È¤¬Â¿¤¤¡£
+
+    ¤³¤Î¤è¤¦¤Ê·¹¸þ¤òÍøÍѤ·¤Æʸ»ú¤È¤½¤ÎÉղþðÊó¤ò¸úΨŪ¤Ë³ÊǼ¤¹¤ë¤¿¤á¤Ë¡¢
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï @e Ê¸»ú¥Æ¡¼¥Ö¥ë (chartable) ¤È¸Æ¤Ö¥ª¥Ö¥¸¥§¥¯¥È¤òÍѤ¤¤ë¡£
+    Ê¸»ú¥Æ¡¼¥Ö¥ë¤ÏÇÛÎó¤Ç¤Ï¤Ê¤¤¤¬¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ïʸ»ú¥Æ¡¼¥Ö¥ë¤òÇÛÎó¤Î°ì¼ï¤È¤·¤Æ°·¤¦¤³¤È¤¬¤Ç¤­¤ë¡£
+    ¤¢¤ëʸ»ú¤Ë¤Ä¤¤¤Æ¤ÎÆÃÄê¤Î¾ðÊó¤Ï¡¢¤½¤Î¾ðÊó¤ò»ý¤Äʸ»ú¥Æ¡¼¥Ö¥ë¤ò¤½¤Îʸ»ú¤Î¥³¡¼¥É¤Ç°ú¤¯¤³¤È
+    ¤ÇÆÀ¤é¤ì¤ë¡£  
+
+    Ê¸»ú¥Æ¡¼¥Ö¥ë¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë¡£ */
+
+/*=*/
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <ctype.h>
+#include <stdio.h>
+
+#include "m17n.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "symbol.h"
+
+static M17NObjectArray chartable_table;
+
+/*** Maximum depth of char-table.  */
+#define CHAR_TAB_MAX_DEPTH 3
+
+/** @name Define: Number of characters covered by char-table of each level.
+    @{ */
+
+/** BITs for number of characters covered by char-table of each
+    level.  */
+#if MCHAR_MAX < 0x400000
+
+#define SUB_BITS_0     22      /* i.e. 0x400000 chars */
+#define SUB_BITS_1     16      /* i.e. 0x10000 chars */
+#define SUB_BITS_2     12      /* i.e. 0x1000 chars */
+#define SUB_BITS_3     7       /* i.e. 0x80 chars */
+
+#else  /* MCHAR_MAX >= 0x400000 */
+
+#define SUB_BITS_0     31
+#define SUB_BITS_1     24
+#define SUB_BITS_2     16
+#define SUB_BITS_3     8
+#endif
+
+/** @} */
+
+/** How many characters a char-table covers at each level.  */
+static const int chartab_chars[] =
+  { (1 << SUB_BITS_0),
+    (1 << SUB_BITS_1),
+    (1 << SUB_BITS_2),
+    (1 << SUB_BITS_3) };
+
+/** How many slots a char-table has at each level.  */
+static const int chartab_slots[] =
+  { (1 << (SUB_BITS_0 - SUB_BITS_1)),
+    (1 << (SUB_BITS_1 - SUB_BITS_2)),
+    (1 << (SUB_BITS_2 - SUB_BITS_3)),
+    (1 << SUB_BITS_3) };
+
+/** Mask bits to obtain the valid bits from a character code for looking
+    up a char-table of each level.  */
+static const int chartab_mask[] =
+  { (int) ((((unsigned) 1) << SUB_BITS_0) - 1),
+    (1 << SUB_BITS_1) - 1,
+    (1 << SUB_BITS_2) - 1,
+    (1 << SUB_BITS_3) - 1 };
+
+/** Bit-shifting counts to obtain a valid index from a character code
+    for looking up a char-table of each level.  */
+static const int chartab_shift[] =
+  { SUB_BITS_1, SUB_BITS_2, SUB_BITS_3, 0 };
+
+
+/** Index for looking up character C in a char-table at DEPTH.  */
+#define SUB_IDX(depth, c)      \
+  (((c) & chartab_mask[depth]) >> chartab_shift[depth])
+
+
+/** Structure of sub char-table.  */
+typedef struct MSubCharTable MSubCharTable;
+
+struct MSubCharTable
+{
+#if SUB_BITS_0 > 24
+
+  /* The depth of the table; 0, 1, 2, or 3. */
+  int depth;
+
+  /* The minimum character covered by the table.  */
+  int min_char;
+
+#else  /* SUB_BITS_0 <= 24 */
+
+  /* The value is ((<depth> << 24) | <min_char>).  */
+  int depth_min_char;
+
+#endif /* SUB_BITS_0 <= 24 */
+
+  /** The default value of characters covered by the table.  */
+  void *default_value;
+
+  /** For a table of bottom level, array of values.  For a non-bottom
+     table, array of sub char-tables.  It may be NULL if all
+     characters covered by the table has <default_value>.  */
+  union {
+    void **values;
+    MSubCharTable *tables;
+  } contents;
+};
+
+#if SUB_BITS_0 > 24
+#define TABLE_DEPTH(table) ((table)->depth)
+#define TABLE_MIN_CHAR(table) ((table)->min_char)
+#define SET_DEPTH_MIN_CHAR(table, DEPTH, MIN_CHAR) \
+  ((table)->depth = (DEPTH), (table)->min_char = (MIN_CHAR))
+#else  /* SUB_BITS_0 <= 24 */
+#define TABLE_DEPTH(table) ((table)->depth_min_char >> 24)
+#define TABLE_MIN_CHAR(table) ((table)->depth_min_char & 0xFFFFFF)
+#define SET_DEPTH_MIN_CHAR(table, DEPTH, MIN_CHAR) \
+  ((table)->depth_min_char = ((DEPTH) << 24) | (MIN_CHAR))
+#endif  /* SUB_BITS_0 <= 24 */
+
+/** Structure of char-table.  */
+
+struct MCharTable
+{
+  /** Common header for a managed object.  */
+  M17NObject control;
+
+  /** Key of the table.  */
+  MSymbol key;
+
+  /** The minimum and maximum characters covered by the table.  */
+  int min_char, max_char;
+
+  MSubCharTable subtable;
+};
+
+
+\f
+
+/* Local functions.  */
+
+/** Allocate and initialize an array of sub-tables for sub char-table
+    TABLE.  It is assumed that TABLE_DEPTH (TABLE) <
+    CHAR_TAB_MAX_DEPTH.*/
+
+static void
+make_sub_tables (MSubCharTable *table, int managedp)
+{
+  int depth = TABLE_DEPTH (table);
+  int min_char = TABLE_MIN_CHAR (table);
+  int slots = chartab_slots[depth];
+  int chars = chartab_chars[depth + 1];
+  MSubCharTable *tables;
+  int i;
+
+  MTABLE_MALLOC (tables, slots, MERROR_CHARTABLE);
+
+  for (i = 0; i < slots; i++, min_char += chars)
+    {
+      SET_DEPTH_MIN_CHAR (tables + i, depth + 1, min_char);
+      tables[i].default_value = table->default_value;
+      tables[i].contents.tables = NULL;
+    }
+  if (managedp && table->default_value)
+    M17N_OBJECT_REF_NTIMES (tables->default_value, slots);
+  table->contents.tables = tables;
+}
+
+
+/** Allocate and initialize an array of values for sub char-table
+    TABLE.  It is assumed that TABLE_DEPTH (TABLE) ==
+    CHAR_TAB_MAX_DEPTH.  */
+
+static void
+make_sub_values (MSubCharTable *table, int managedp)
+{
+  int slots = chartab_slots[CHAR_TAB_MAX_DEPTH];
+  void **values;
+  int i;
+
+  MTABLE_MALLOC (values, slots, MERROR_CHARTABLE);
+
+  for (i = 0; i < slots; i++)
+    values[i] = table->default_value;
+  if (managedp && table->default_value)
+    M17N_OBJECT_REF_NTIMES (table->default_value, slots);
+  table->contents.values = values;
+}
+
+
+/** Free contents of sub char-table TABLE and the default value of
+    TABLE.  Free also the sub-tables recursively.  */
+
+static void
+free_sub_tables (MSubCharTable *table, int managedp)
+{
+  int depth = TABLE_DEPTH (table);
+  int slots = chartab_slots[depth];
+
+  if (table->contents.tables)
+    {
+      if (depth < CHAR_TAB_MAX_DEPTH)
+       {
+         while (slots--)
+           free_sub_tables (table->contents.tables + slots, managedp);
+         free (table->contents.tables);
+       }
+      else
+       {
+         if (managedp)
+           while (slots--)
+             {
+               if (table->contents.values[slots])
+                 M17N_OBJECT_UNREF (table->contents.values[slots]);
+             }
+         free (table->contents.values);
+       }
+      table->contents.tables = NULL;
+    }
+  if (managedp && table->default_value)
+    M17N_OBJECT_UNREF (table->default_value);
+}
+
+
+/** In sub char-table TABLE, set value VAL for characters of the range
+    FROM and TO. */
+
+static void
+set_chartable_range (MSubCharTable *table, int from, int to, void *val,
+                    int managedp)
+{
+  int depth = TABLE_DEPTH (table);
+  int min_char = TABLE_MIN_CHAR (table);
+  int max_char = min_char + (chartab_chars[depth] - 1);
+  int i;
+
+  if (max_char < 0 || max_char > MCHAR_MAX)
+    max_char = MCHAR_MAX;
+
+  if (from < min_char)
+    from = min_char;
+  if (to > max_char)
+    to = max_char;
+
+  if (from == min_char && to == max_char)
+    {
+      free_sub_tables (table, managedp);
+      if (managedp && val)
+       M17N_OBJECT_REF (val);
+      table->default_value = val;
+      return;
+    }
+
+  if (depth < CHAR_TAB_MAX_DEPTH)
+    {
+      if (! table->contents.tables)
+       make_sub_tables (table, managedp);
+      i = SUB_IDX (depth, from);
+      table = table->contents.tables + i;
+      while (i < chartab_slots[depth] && TABLE_MIN_CHAR (table) <= to)
+       {
+         set_chartable_range (table, from, to, val, managedp);
+         table++, i++;
+       }
+    }
+  else
+    {
+      int idx_from = SUB_IDX (depth, from);
+      int idx_to = SUB_IDX (depth, to);
+
+      if (! table->contents.values)
+       make_sub_values (table, managedp);
+      for (i = idx_from; i <= idx_to; i++)
+       {
+         if (managedp && table->contents.values[i])
+           M17N_OBJECT_UNREF (table->contents.values[i]);
+         table->contents.values[i] = val;
+       }
+      if (managedp && val)
+       M17N_OBJECT_REF_NTIMES (val, (idx_to - idx_from + 1));
+    }
+}
+
+
+/** Lookup the sub char-table TABLE for the character C.  If NEXT_C is
+    not NULL, set *NEXT_C to the next interesting character to lookup
+    for.  If DEFAULT_P is zero, the next interesting character is what
+    possibly has the different value than C.  Otherwise, the next
+    interesting character is what possibly has the default value (if C
+    has a value deferent from the default value) or has a value
+    different from the default value (if C has the default value).  */
+
+static void *
+lookup_chartable (MSubCharTable *table, int c, int *next_c, int default_p)
+{
+  int depth = TABLE_DEPTH (table);
+  void *val;
+  void *default_value = table->default_value;
+  int idx;
+
+  while (1)
+    {
+      if (! table->contents.tables)
+       {
+         if (next_c)
+           *next_c = TABLE_MIN_CHAR (table) + chartab_chars[depth];
+         return table->default_value;
+       }
+      if (depth == CHAR_TAB_MAX_DEPTH)
+       break;
+      table = table->contents.tables + SUB_IDX (depth, c);
+      depth++;
+    }
+
+  idx = SUB_IDX (depth, c);
+  val = table->contents.values[idx];
+
+  if (next_c)
+    {
+      int max_char = TABLE_MIN_CHAR (table) + (chartab_chars[depth] - 1);
+
+      if (max_char < 0 || max_char > MCHAR_MAX)
+       max_char = MCHAR_MAX;
+      if (default_p && val != default_value)
+       {
+         do { c++, idx++; }
+         while (c >= 0 && c <= max_char
+                && table->contents.values[idx] != default_value);
+       }
+      else
+       {
+         do { c++, idx++; }
+         while (c >= 0 && c <= max_char
+                && table->contents.values[idx] == val);
+       }
+      *next_c = c;
+    }
+  return val;
+}
+
+/** Call FUNC for characters in sub char-table TABLE.  Ignore such
+    characters that has a value IGNORE.  FUNC is called with four
+    arguments; FROM, TO, VAL, and ARG (same as FUNC_ARG).  If
+    DEFAULT_P is zero, FROM and TO are range of characters that has
+    the same value VAL.  Otherwise, FROM and TO are range of
+    characters that has the different value than the default value of
+    TABLE.  */
+
+static void
+map_chartable (MSubCharTable *table, void *ignore, int default_p,
+               void (*func) (int, int, void *, void *),
+               void *func_arg)
+{
+  void *current;
+  int from = 0;
+  int c, next_c;
+
+  current = lookup_chartable (table, 0, &next_c, default_p);
+  c = next_c;
+  while (c >= 0 && c <= MCHAR_MAX)
+    {
+      void *next = lookup_chartable (table, c, &next_c, default_p);
+
+      if (current != next)
+       {
+         if (current != ignore)
+           (*func) (from, c - 1, current, func_arg);
+         current = next;
+         from = c;
+       }
+      c = next_c;
+    }
+  if (from <= MCHAR_MAX && current != ignore)
+    (*func) (from, MCHAR_MAX, current, func_arg);
+}
+
+
+/* Return the smallest character whose value is not DEFAULT_VALUE in
+   TABLE.  If all characters in TABLE have DEFAULT_VALUE, return
+   -1.  */
+
+static int
+chartab_min_non_default_char (MSubCharTable *table, void *default_value)
+{
+  int depth = TABLE_DEPTH (table);
+  int slots;
+  int i, c;
+
+  if (!table->contents.tables)
+    return (default_value == table->default_value
+           ? -1 : TABLE_MIN_CHAR (table));
+
+  slots = chartab_slots[depth];
+
+  if (depth == CHAR_TAB_MAX_DEPTH)
+    {
+      for (i = 0; i < slots; i++)
+       if (table->contents.values[i] != default_value)
+         return (TABLE_MIN_CHAR (table) + i);
+    }
+  else
+    {
+      for (i = 0; i < slots; i++)
+       if ((c = chartab_min_non_default_char (table->contents.tables + i,
+                                              default_value))
+           >= 0)
+         return c;
+    }
+  return -1;
+}
+
+
+/* Return the largest character whose value is not DEFAULT_VALUE in
+   TABLE.  If all characters in TABLE have DEFAULT_VALUE, return
+   -1.  */
+
+static int
+chartab_max_non_default_char (MSubCharTable *table, void *default_value)
+{
+  int depth = TABLE_DEPTH (table);
+  int slots;
+  int i, c;
+
+  if (!table->contents.tables)
+    return (default_value == table->default_value
+           ? -1 : TABLE_MIN_CHAR (table) + chartab_chars[depth] - 1);
+
+  slots = chartab_slots[depth];
+
+  if (depth == CHAR_TAB_MAX_DEPTH)
+    {
+      for (i = slots - 1; i >= 0; i--)
+       if (table->contents.values[i] != default_value)
+         return (TABLE_MIN_CHAR (table) + i);
+    }
+  else
+    {
+      for (i = slots - 1; i >= 0; i--)
+       if ((c = chartab_max_non_default_char (table->contents.tables + i,
+                                              default_value))
+           >= 0)
+         return c;
+    }
+  return -1;
+}
+
+static void
+free_chartable (void *object)
+{
+  MCharTable *table = (MCharTable *) object;
+  int managedp = table->key != Mnil && table->key->managing_key;
+
+  if (table->subtable.contents.tables)
+    {
+      int i;
+
+      for (i = 0; i < chartab_slots[0]; i++)
+       free_sub_tables (table->subtable.contents.tables + i, managedp);
+      free (table->subtable.contents.tables);
+      if (managedp && table->subtable.default_value)
+       M17N_OBJECT_UNREF (table->subtable.default_value);
+    }
+  M17N_OBJECT_UNREGISTER (chartable_table, table);
+  free (object);
+}
+
+#include <stdio.h>
+
+/* Support function of mdebug_dump_chartab.  */
+
+static void
+dump_sub_chartab (MSubCharTable *table, void *default_value,
+                 MSymbol key, int indent)
+{
+  int depth = TABLE_DEPTH (table);
+  int min_char = TABLE_MIN_CHAR (table);
+  int max_char = min_char + (chartab_chars[depth] - 1);
+  char *prefix = (char *) alloca (indent + 1);
+  int i;
+
+  if (max_char < 0 || max_char > MCHAR_MAX)
+    max_char = MCHAR_MAX;
+
+  memset (prefix, 32, indent);
+  prefix[indent] = 0;
+
+  if (! table->contents.tables && table->default_value == default_value)
+    return;
+  fprintf (stderr, "\n%s(sub%d (U+%04X U+%04X) ",
+          prefix, depth, min_char, max_char);
+  if (key == Msymbol)
+    {
+      if (table->default_value)
+       fprintf (stderr, "(default %s)",
+                ((MSymbol) table->default_value)->name);
+      else
+       fprintf (stderr, "(default nil)");
+    }
+  else
+    fprintf (stderr, "(default #x%X)", (unsigned) table->default_value);
+
+  default_value = table->default_value;
+  if (table->contents.tables)
+    {
+      if (depth < CHAR_TAB_MAX_DEPTH)
+       for (i = 0; i < chartab_slots[depth]; i++)
+         dump_sub_chartab (table->contents.tables + i, default_value,
+                           key, indent  + 2);
+      else
+       for (i = 0; i < chartab_slots[depth]; i++, min_char++)
+         {
+           void **val = table->contents.values + i;
+
+           if (val == default_value)
+             continue;
+           default_value = *val;
+           fprintf (stderr, "\n%s  (U+%04X", prefix, min_char);
+           while (i + 1 < chartab_slots[depth]
+                  && val[1] == default_value)
+             i++, val++, min_char++;
+           fprintf (stderr, "-U+%04X ", min_char);
+           if (key == Msymbol)
+             {
+               if (default_value)
+                 fprintf (stderr, "%s)", ((MSymbol) default_value)->name);
+               else
+                 fprintf (stderr, "nil)");
+             }
+           else
+             fprintf (stderr, " #xx%X)", (unsigned) default_value);
+         }
+    }
+  fprintf (stderr, ")");
+}
+
+\f
+/* Internal API */
+
+int
+mchartable__init ()
+{
+  M17N_OBJECT_ADD_ARRAY (chartable_table, "Chartable");
+  return 0;
+}
+
+void
+mchartable__fini ()
+{
+}
+
+void *
+mchartable__lookup (MCharTable *table, int c, int *next_c, int default_p)
+{
+  return lookup_chartable (&table->subtable, c, next_c, default_p);
+}
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+/* External API */
+
+/*** @addtogroup m17nChartable */
+/*** @{ */
+/*=*/
+
+/***en
+    @brief Symbol whose name is "char-table".
+
+    The symbol @c Mchar_table has the name <tt>"char-table"</tt>.  */
+
+/***ja
+    @brief "char-table" ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë @c Mchar_table ¤Ï̾Á° <tt>"char-table"</tt> ¤ò»ý¤Ä¡£
+    */
+
+MSymbol Mchar_table;
+
+/*=*/
+
+/***en
+    @brief Create a new chartable.
+
+    The mchartable () function creates a new chartable object with
+    symbol $KEY and the default value $DEFAULT_VALUE.  If $KEY is a
+    managing key, the elements of the table (including the default
+    value) are managed objects or NULL.
+
+    @return
+    If the operation was successful, mchartable () returns a pointer
+    to the created chartable.  Otherwise it returns @c NULL and
+    assigns an error code to the external variable #merror_code.  */
+
+/***ja
+    @brief ¿·¤·¤¤Ê¸»ú¥Æ¡¼¥Ö¥ë¤òºî¤ë.
+
+    ´Ø¿ô mchartable () ¤Ï¥­¡¼¤¬ $KEY ¤ÇÍ×ÁǤΥǥե©¥ë¥ÈÃͤ¬ 
+    $DEFAULT_VALUE ¤Ç¤¢¤ë¿·¤·¤¤Ê¸»ú¥Æ¡¼¥Ö¥ë¤òºî¤ë¡£¤â¤· $KEY 
+    ¤¬´ÉÍý¥­¡¼¤Ç¤¢¤ì¤Ð¡¢¤³¤Î¥Æ¡¼¥Ö¥ë¤ÎÍ×ÁǤϡʥǥե©¥ë¥ÈÃͤò´Þ¤á¤Æ¡Ë´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤« 
+    NULL ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mchartable () ¤ÏºîÀ®¤µ¤ì¤¿Ê¸»ú¥Æ¡¼¥Ö¥ë¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
+    ¼ºÇÔ¤·¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+MCharTable *
+mchartable (MSymbol key, void *default_value)
+{
+  MCharTable *table;
+
+  M17N_OBJECT (table, free_chartable, MERROR_CHARTABLE);
+  M17N_OBJECT_REGISTER (chartable_table, table);
+  table->key = key;
+  table->min_char = -1;
+  table->max_char = -1;
+  SET_DEPTH_MIN_CHAR (&table->subtable, 0, 0);
+  table->subtable.default_value = default_value;
+  if (key != Mnil && key->managing_key && default_value)
+    M17N_OBJECT_REF (default_value);
+  table->subtable.contents.tables = NULL;
+  return table;
+}
+
+/*=*/
+
+/***en
+    @brief Return the minimum character whose value is set in a chartabe.
+
+    The mchartable_min_char () function return the minimum character
+    whose value is set in chartable $TABLE.  No character is set its
+    value, the function returns -1.
+ */
+
+int
+mchartable_min_char (MCharTable *table)
+{
+  return table->min_char;
+}
+
+/*=*/
+
+/***en
+    @brief Return the maximum character whose value is set in a chartabe.
+
+    The mchartable_max_char () function return the maximum character
+    whose value is set in chartable $TABLE.  No character is set its
+    value, the function returns -1.
+ */
+
+int
+mchartable_max_char (MCharTable *table)
+{
+  return table->max_char;
+}
+
+/*=*/
+
+/***en
+    @brief Return the assigned value of a character in a chartable.
+
+    The mchartable_lookup () function returns the value assigned to
+    character $C in chartable $TABLE.  If no value has been set for $C
+    explicitly, the default value of $TABLE is returned.  If $C is not
+    a valid character, mchartable_lookup () returns @c NULL and
+    assigns an error code to the external variable #merror_code.  */
+
+/***ja
+    @brief Ê¸»ú¥Æ¡¼¥Ö¥ëÃæ¤Çʸ»ú¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿ÃͤòÊÖ¤¹.
+
+    ´Ø¿ô mchartable_lookup () ¤Ïʸ»ú¥Æ¡¼¥Ö¥ë $TABLE Ãæ¤Çʸ»ú $C 
+    ¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿ÃͤòÊÖ¤¹¡£$C ¤ËÂФ¹¤ëÌÀ¼¨Åª¤ÊÃͤ¬¤Ê¤±¤ì¤Ð¡¢$TABLE 
+    ¤Î¥Ç¥Õ¥©¥ë¥ÈÃͤòÊÖ¤¹¡£$C ¤¬ÂÅÅö¤Êʸ»ú¤Ç¤Ê¤±¤ì¤Ð¡¢mchartable_lookup () ¤Ï 
+    @c NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_CHAR
+
+    @seealso
+    mchartable_set ()  */
+
+void *
+mchartable_lookup (MCharTable *table, int c)
+{
+  M_CHECK_CHAR (c, NULL);
+
+  if (c < table->min_char || c > table->max_char)
+    return table->subtable.default_value;
+  return lookup_chartable (&table->subtable, c, NULL, 0);
+}
+
+/*=*/
+
+/***en
+    @brief Assign a value to a character in a chartable.
+
+    The mchartable_set () function sets the value of character $C in
+    chartable $TABLE to $VAL.
+
+    @return
+    If the operation was successful, mchartable_set () returns 0.
+    Otherwise it returns -1 and assigns an error code to the external
+    variable #merror_code.  */
+
+/***ja
+    @brief Ê¸»ú¥Æ¡¼¥Ö¥ëÃæ¤Ç¤Îʸ»ú¤ÎÃͤòÀßÄꤹ¤ë.
+
+    ´Ø¿ô mchartable_set () ¤Ï¡¢Ê¸»ú¥Æ¡¼¥Ö¥ë $TABLE Ãæ¤Îʸ»ú $C 
+    ¤ËÃÍ $VAL ¤ò³ä¤êÅö¤Æ¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mchartable_set () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_CHAR
+
+    @seealso
+    mchartable_lookup (), mchartable_set_range ()  */
+
+
+int
+mchartable_set (MCharTable *table, int c, void *val)
+{
+  int managedp = table->key != Mnil && table->key->managing_key;
+  MSubCharTable *sub = &table->subtable;
+  int i;
+
+  M_CHECK_CHAR (c, -1);
+
+  if (table->max_char < 0)
+    table->min_char = table->max_char = c;
+  else
+    {
+      if (c < table->min_char)
+       table->min_char = c;
+      else if (c > table->max_char)
+       table->max_char = c;
+    }
+
+  for (i = 0; i < CHAR_TAB_MAX_DEPTH; i++)
+    {
+      if (! sub->contents.tables)
+       {
+         if (sub->default_value == val)
+           return 0;
+         make_sub_tables (sub, managedp);
+       }
+      sub = sub->contents.tables + SUB_IDX (i, c);
+    }
+  if (! sub->contents.values)
+    {
+      if (sub->default_value == val)
+       return 0;
+      make_sub_values (sub, managedp);
+    }
+  sub->contents.values[SUB_IDX (3, c)] = val;
+  if (managedp && val)
+    M17N_OBJECT_REF (val);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Assign a value to the characters in the specified range.
+
+    The mchartable_set_range () function assigns value $VAL to the
+    characters from $FROM to $TO (both inclusive) in chartable $TABLE.
+
+    @return
+    If the operation was successful, mchartable_set_range () returns
+    0.  Otherwise it returns -1 and assigns an error code to the
+    external variable #merror_code.  If $FROM is greater than $TO,
+    mchartable_set_range () returns immediately without an error.  */
+
+/***ja
+    @brief »ØÄêÈϰϤÎʸ»ú¤ËÃͤòÀßÄꤹ¤ë.
+
+    ´Ø¿ô mchartable_set_range () ¤Ï¡¢Ê¸»ú¥Æ¡¼¥Ö¥ë $TABLE Ãæ¤Î $FROM 
+    ¤«¤é $TO ¤Þ¤Ç¡Êξü¤ò´Þ¤à¡Ë¤Îʸ»ú¤Ë¡¢ÃͤȤ·¤Æ $VAL ¤òÀßÄꤹ¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mchartable_set_range () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð 
+    -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£$FROM ¤¬ 
+    $TO ¤è¤êÂ礭¤¤¤È¤­¤Ë¤Ï¡¢ mchartable_set_range () 
+    ¤Ï²¿¤â¤»¤º¡¢¥¨¥é¡¼¤âµ¯¤³¤µ¤Ê¤¤¡£  */
+
+/***
+    @errors
+    @c MERROR_CHAR
+
+    @seealso
+    mchartable_set ()  */
+
+int
+mchartable_set_range (MCharTable *table, int from, int to, void *val)
+{
+  int managedp = table->key != Mnil && table->key->managing_key;
+
+  M_CHECK_CHAR (from, -1);
+  M_CHECK_CHAR (to, -1);
+
+  if (from > to)
+    return 0;
+
+  if (table->max_char < 0)
+    table->min_char = from, table->max_char = to;
+  else{
+    if (from < table->min_char)
+      table->min_char = from;
+    if (to > table->max_char)
+      table->max_char = to;
+  }
+  set_chartable_range (&table->subtable, from, to, val, managedp);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Search for characters that have non-default value.
+
+    The mchartable_range () function searches chartable $TABLE for the
+    first and the last character codes that do not have the default
+    value of $TABLE, and set $FROM and $TO to them, respectively.  If
+    all characters have the default value, both $FROM and $TO are set
+    to -1.  */
+
+/***ja
+    @brief Ãͤ¬¥Ç¥Õ¥©¥ë¥È¤È°Û¤Ê¤ëʸ»ú¤òõ¤¹.
+
+    ´Ø¿ô mchartable_range () ¤Ïʸ»ú¥Æ¡¼¥Ö¥ë $TABLE Ãæ¤Ç¡¢$TABLE 
+    ¤Î¥Ç¥Õ¥©¥ë¥ÈÃͰʳ°¤ÎÃͤò»ý¤ÄºÇ½é¤ÈºÇ¸å¤Îʸ»ú¤òõ¤·¡¢¤½¤ì¤¾¤ì¤ò $FROM 
+    ¤È $TO ¤ËÀßÄꤹ¤ë¡£¤¹¤Ù¤Æ¤Îʸ»ú¤¬ÃͤȤ·¤Æ¥Ç¥Õ¥©¥ë¥ÈÃͤò¤È¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï
+    $FROM ¤È $TO ¤ò -1¤ËÀßÄꤹ¤ë¡£  */
+
+void
+mchartable_range (MCharTable *table, int *from, int *to)
+{
+  *from = chartab_min_non_default_char (&table->subtable,
+                                       table->subtable.default_value);
+  if (*from == -1)
+    *to = -1;
+  else
+    *to = chartab_max_non_default_char (&table->subtable,
+                                       table->subtable.default_value);
+}
+
+/*=*/
+
+/***en
+    @brief Call a function for characters in a chartable.
+
+    The mchartable_map () function calls function $FUNC for characters
+    in chartable $TABLE.  No function call occurs for characters that
+    have value $IGNORE in $TABLE.  Comparison of $IGNORE and character
+    value is done with the operator @c ==.  Be careful when you use
+    string literals or pointers.
+
+    Instead of calling $FUNC for each character, mchartable_map ()
+    tries to optimize the number of function calls, i.e. it makes a
+    single function call for a chunk of characters when those
+    consecutive characters have the same value.
+
+    No matter how long the character chunk is, $FUNC is called with
+    four arguments; $FROM, $TO, $VAL, and $ARG.  $FROM and $TO (both
+    inclusive) defines the range of characters that have value $VAL.
+    $ARG is the same as $FUNC_ARG.
+
+    @return
+    This function always returns 0.  */
+
+/***ja
+    @brief Ê¸»ú¥Æ¡¼¥Ö¥ëÃæ¤Îʸ»ú¤ËÂФ·¤Æ»ØÄê¤Î´Ø¿ô¤ò¸Æ¤Ö.
+
+    ´Ø¿ô mchartable_map () ¤Ï¡¢Ê¸»ú¥Æ¡¼¥Ö¥ë $TABLE Ãæ¤Îʸ»ú¤ËÂФ·¤Æ´Ø¿ô
+    $FUNC ¤ò¸Æ¤Ö¡£¤¿¤À¤·$TABLE Ãæ¤Ç¤âÃͤ¬ $IGNORE 
+    ¤Ç¤¢¤ëʸ»ú¤Ë¤Ä¤¤¤Æ¤Ï´Ø¿ô¸Æ¤Ó½Ð¤·¤ò¹Ô¤Ê¤ï¤Ê¤¤¡£$IGNORE ¤Èʸ»ú¤ÎÃͤÎÈæ³Ó¤Ï 
+    @c == ¤Ç¹Ô¤Ê¤¦¤Î¤Ç¡¢Ê¸»úÎó¥ê¥Æ¥é¥ë¤ä¥Ý¥¤¥ó¥¿¤ò»È¤¦ºÝ¤Ë¤ÏÃí°Õ¤òÍפ¹¤ë¡£
+
+    mchartable_map () ¤Ï¡¢°ìʸ»ú¤´¤È¤Ë $FUNC 
+    ¤ò¸Æ¤Ö¤Î¤Ç¤Ï¤Ê¤¯¡¢´Ø¿ô¸Æ¤Ó½Ð¤·¤Î²ó¿ô¤òºÇŬ²½¤·¤è¤¦¤È¤¹¤ë¡£
+    ¤¹¤Ê¤ï¤Á¡¢Ï¢Â³¤·¤¿Ê¸»ú¤¬Æ±¤¸Ãͤò»ý¤Ã¤Æ¤¤¤¿¾ì¹ç¤Ë¤Ï¡¢¤½¤Îʸ»ú¤Î¤Þ¤È¤Þ¤êÁ´ÂΤˤĤ¤¤Æ°ìÅ٤δؿô¸Æ¤Ó½Ð
+    ¤·¤·¤«¹Ô¤Ê¤ï¤Ê¤¤¡£
+
+    Ê¸»ú¤Î¤Þ¤È¤Þ¤ê¤ÎÂ礭¤µ¤Ë¤«¤«¤ï¤é¤º¡¢$FUNC ¤Ï $FROM, $TO, $VAL, $ARG 
+    ¤Î£´°ú¿ô¤Ç¸Æ¤Ð¤ì¤ë¡£$FROM ¤È $TO ¡Êξü¤ò´Þ¤à¡Ë¤Ï $VAL 
+    ¤òÃͤȤ·¤Æ»ý¤Äʸ»ú¤ÎÈϰϤò¼¨¤·¡¢$ARG ¤Ï $FUNC_ARG ¤½¤Î¤â¤Î¤Ç¤¢¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¾ï¤Ë0¤òÊÖ¤¹¡£  */
+
+int
+mchartable_map (MCharTable *table, void *ignore,
+               void (*func) (int, int, void *, void *),
+               void *func_arg)
+{
+  map_chartable (&table->subtable, ignore, 0, func, func_arg);
+  return 0;
+}
+
+/*=*/
+
+/*** @} */
+
+/*** @addtogroup m17nDebug */
+/*=*/
+/*** @{  */
+
+/***en
+    @brief Dump a chartable.
+
+    The mdebug_dump_chartab () function prints a chartable $TABLE in a
+    human readable way to the stderr.  $INDENT specifies how many
+    columns to indent the lines but the first one.
+
+    @return
+    This function returns $TABLE.  */
+
+/***ja
+    @brief Ê¸»ú¥Æ¡¼¥Ö¥ë¤ò¥À¥ó¥×¤¹¤ë.
+
+    ´Ø¿ô mdebug_dump_chartab () ¤Ïʸ»ú¥Æ¡¼¥Ö¥ë $TABLE ¤ò stderr 
+    ¤Ë¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç°õºþ¤¹¤ë¡£$INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï $TABLE ¤òÊÖ¤¹¡£  */
+
+MCharTable *
+mdebug_dump_chartab (MCharTable *table, int indent)
+{
+  fprintf (stderr, "(chartab (U+%04X U+%04X)",
+          table->min_char, table->max_char);
+  dump_sub_chartab (&table->subtable, table->subtable.default_value,
+                   table->key, indent + 2);
+  fprintf (stderr, ")");
+  return table;
+}
+
+/*** @} */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/chartab.h b/src/chartab.h
new file mode 100644 (file)
index 0000000..9738393
--- /dev/null
@@ -0,0 +1,30 @@
+/* chartab.h -- header file for the character table module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_CHARTAB_H_
+#define _M17N_CHARTAB_H_
+
+extern void *mchartable__lookup (MCharTable *table, int c,
+                                int *next_c, int default_p);
+
+#endif /* not _M17N_CHARTAB_H_ */
+
diff --git a/src/coding.c b/src/coding.c
new file mode 100644 (file)
index 0000000..179ad69
--- /dev/null
@@ -0,0 +1,5078 @@
+/* coding.c -- code conversion module.
+   Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nConv
+    @brief Coding system objects and API for them.
+
+    The m17n library represents a character encoding scheme (CES) of
+    coded character sets (CCS) as an object called @e coding @e
+    system.  Application programs can add original coding systems.
+
+    To @e encode means converting code-points to character codes and
+    to @e decode means converting character codes back to code-points.
+
+    Application programs can decode a byte sequence with a specified
+    coding system into an M-text, and inversely, can encode an M-text
+    into a byte sequence.  */
+
+/***ja
+    @addtogroup m17nConv
+    @brief ¥³¡¼¥É·Ï¥ª¥Ö¥¸¥§¥¯¥È¤È¤½¤ì¤Ë´Ø¤¹¤ë API.
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï¡¢Éä¹æ²½Ê¸»ú½¸¹ç (coded character set; CCS) 
+    ¤Îʸ»úÉä¹ç²½Êý¼° (character encoding scheme; CES) ¤ò @e ¥³¡¼¥É·Ï 
+    ¤È¸Æ¤Ö¥ª¥Ö¥¸¥§¥¯¥È¤Çɽ¸½¤¹¤ë¡£
+    ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤ÏÆȼ«¤Ë¥³¡¼¥É·Ï¤òÄɲ乤뤳¤È¤â¤Ç¤­¤ë¡£
+
+    ¥³¡¼¥É¥Ý¥¤¥ó¥È¤«¤éʸ»ú¥³¡¼¥É¤Ø¤ÎÊÑ´¹¤ò @e ¥¨¥ó¥³¡¼¥É 
+    ¤È¸Æ¤Ó¡¢Ê¸»ú¥³¡¼¥É¤«¤é¥³¡¼¥É¥Ý¥¤¥ó¥È¤Ø¤ÎÊÑ´¹¤ò @e ¥Ç¥³¡¼¥É ¤È¸Æ¤Ö¡£
+
+    ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï¡¢»ØÄꤵ¤ì¤¿¥³¡¼¥É·Ï¤Ç¥Ð¥¤¥ÈÎó¤ò¥Ç¥³¡¼¥É¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ
+    M-text ¤òÆÀ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£¤Þ¤¿µÕ¤Ë¡¢»ØÄꤵ¤ì¤¿¥³¡¼¥É·Ï¤Ç M-text 
+    ¤ò¥¨¥ó¥³¡¼¥É¤·¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¥Ð¥¤¥ÈÎó¤òÆÀ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£  */
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "m17n.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "plist.h"
+#include "character.h"
+#include "charset.h"
+#include "coding.h"
+#include "mtext.h"
+#include "symbol.h"
+#include "mlocale.h"
+
+#define NUM_SUPPORTED_CHARSETS 32
+
+/** Structure for coding system object.  */
+
+typedef struct
+{
+  /** Name of the coding system.  */
+  MSymbol name;
+
+  /** Type of the coding system.  */
+  MSymbol type;
+
+  /* Number of supported charsets.  */
+  int ncharsets;
+
+  /** Array of supported charsets.  */
+  MCharset *charsets[NUM_SUPPORTED_CHARSETS];
+
+  /** If non-NULL, function to call at the time of creating and
+      reseting a converter.  */
+  int (*resetter) (MConverter *converter);
+
+  int (*decoder) (const unsigned char *str, int str_bytes, MText *mt,
+                 MConverter *converter);
+
+  int (*encoder) (MText *mt, int from, int to,
+                 unsigned char *str, int str_bytes,
+                 MConverter *converter);
+
+  /** If non-zero, the coding system decode/encode ASCII characters as
+      is.  */
+  int ascii_compatible;
+
+  /** Pointer to extra information given when the coding system is
+      defined.  The meaning depends on <type>.  */
+  void *extra_info;
+
+  /** Pointer to information referred on conversion.  The meaning
+      depends on <type>.  The value NULL means that the coding system
+      is not yet setup.  */
+  void *extra_spec;
+
+  int ready;
+} MCodingSystem;
+
+struct MCodingList
+{
+  int size, inc, used;
+  MCodingSystem **codings;
+};
+
+static struct MCodingList coding_list;
+
+static MPlist *coding_definition_list;
+
+typedef struct {
+  /**en
+     Pointer to a structure of a coding system.  */
+  /**ja
+     ¥³¡¼¥É·Ï¤òɽ¤ï¤¹¥Ç¡¼¥¿¹½Â¤¤Ø¤Î¥Ý¥¤¥ó¥¿ */
+  MCodingSystem *coding;
+
+  /**en
+     Buffer for carryover bytes generated while decoding. */
+  /**ja
+     ¥Ç¥³¡¼¥ÉÃæ¤Î¥­¥ã¥ê¥£¥ª¡¼¥Ð¡¼¥Ð¥¤¥ÈÍѥХåե¡ */
+  unsigned char carryover[256];
+
+  /**en
+     Number of carryover bytes. */
+  /**ja
+     ¥­¥ã¥ê¥£¥ª¡¼¥Ð¡¼¥Ð¥¤¥È¿ô */
+  int carryover_bytes;
+
+  /**en
+     Beginning of the byte sequence bound to this converter. */
+  /**ja
+     ¤³¤Î¥³¥ó¥Ð¡¼¥¿¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤¿¥Ð¥¤¥ÈÎó¤ÎÀèƬ°ÌÃÖ */
+  union {
+    const unsigned char *in;
+    unsigned char *out;
+  } buf;
+
+  /**en
+     Size of buf. */
+  /**ja
+     buf ¤ÎÂ礭¤µ */
+  int bufsize;
+
+  /**en
+     Number of bytes already consumed in buf. */
+  /**ja
+     buf Æâ¤Ç¤¹¤Ç¤Ë¾ÃÈñ¤µ¤ì¤¿¥Ð¥¤¥È¿ô */
+  int used;
+
+  /**en
+     Stream bound to this converter. */
+  /**ja
+     ¤³¤Î¥³¥ó¥Ð¡¼¥¿¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤¿¥¹¥È¥ê¡¼¥à */
+  FILE *fp;
+
+  /**en
+     Which of above two is in use. */
+  /**ja
+     ¾åµ­2¼Ô¤Î¤¤¤º¤ì¤¬»È¤ï¤ì¤Æ¤¤¤ë¤« */
+  int binding;
+
+  /**en
+     Buffer for unget. */
+  /**ja
+     Unget ÍѥХåե¡ */
+  MText *unread;
+
+  /*en
+    Working area. */
+  /*ja
+    ºî¶ÈÎΰè */
+  MText *work_mt;
+
+  int seekable;
+} MConverterStatus;
+
+
+\f
+/* Local macros and functions.  */
+
+/** At first, set SRC_BASE to SRC.  Then check if we have already
+    produced AT_MOST chars.  If so, set SRC_END to SRC, and jump to
+    source_end.  Otherwise, get one more byte C from SRC.  In that
+    case, if SRC == SRC_END, jump to the label source_end.  */
+
+#define ONE_MORE_BASE_BYTE(c)          \
+  do {                                 \
+    src_base = src;                    \
+    if (nchars == at_most)             \
+      {                                        \
+       src_end = src;                  \
+       goto source_end;                \
+      }                                        \
+    if (src == src_stop)               \
+      {                                        \
+       if (src == src_end)             \
+         goto source_end;              \
+       src_base = src = source;        \
+       if (src == src_end)             \
+         goto source_end;              \
+       src_stop = src_end;             \
+      }                                        \
+    (c) = *src++;                      \
+  } while (0)
+
+
+/** Get one more byte C from SRC.  If SRC == SRC_END, jump to the
+   label source_end.  */
+
+#define ONE_MORE_BYTE(c)       \
+  do {                         \
+    if (src == src_stop)       \
+      {                                \
+       if (src == src_end)     \
+         goto source_end;      \
+       src = source;           \
+       if (src == src_end)     \
+         goto source_end;      \
+       src_stop = src_end;     \
+      }                                \
+    (c) = *src++;              \
+  } while (0)
+
+
+#define REWIND_SRC_TO_BASE()                                           \
+  do {                                                                 \
+    if (src_base < source || src_base >= src_end)                      \
+      src_stop = internal->carryover + internal->carryover_bytes;      \
+    src = src_base;                                                    \
+  } while (0)
+
+
+/** Push back byte C to SRC.  */
+
+#define UNGET_ONE_BYTE(c)              \
+  do {                                 \
+    if (src > source)                  \
+      src--;                           \
+    else                               \
+      {                                        \
+       internal->carryover[0] = c;     \
+       internal->carryover_bytes = 1;  \
+       src = internal->carryover;      \
+       src_stop = src + 1;             \
+      }                                        \
+  } while  (0);
+
+
+/** Store multibyte representation of character C at DST and increment
+    DST to the next of the produced bytes.  DST must be a pointer to
+    data area of M-text MT.  If the produced bytes are going to exceed
+    DST_END, enlarge the data area of MT.  */
+
+#define EMIT_CHAR(c)                                           \
+  do {                                                         \
+    int bytes = CHAR_BYTES (c);                                        \
+    int len;                                                   \
+                                                               \
+    if (dst + bytes + 1 > dst_end)                             \
+      {                                                                \
+       len = dst - mt->data;                                   \
+       bytes = mt->allocated + bytes + (src_stop - src);       \
+       mtext__enlarge (mt, bytes);                             \
+       dst = mt->data + len;                                   \
+       dst_end = mt->data + mt->allocated;                     \
+      }                                                                \
+    dst += CHAR_STRING (c, dst);                               \
+    nchars++;                                                  \
+  } while (0)
+
+
+/* Check if there is enough room to produce LEN bytes at DST.  If not,
+   go to the label insufficient_destination.  */
+
+#define CHECK_DST(len)                 \
+  do {                                 \
+    if (dst + (len) > dst_end)         \
+      goto insufficient_destination;   \
+  } while (0)
+
+
+/** Take NUM_CHARS characters (NUM_BYTES bytes) already stored at
+    (MT->data + MT->nbytes) into MT, and put charset property on
+    them with CHARSET->name.  */
+
+#define TAKEIN_CHARS(mt, num_chars, num_bytes, charset)                        \
+  do {                                                                 \
+    int chars = (num_chars);                                           \
+                                                                       \
+    if (chars > 0)                                                     \
+      {                                                                        \
+       mtext__takein ((mt), chars, (num_bytes));                       \
+       if (charset)                                                    \
+         mtext_put_prop ((mt), (mt)->nchars - chars, (mt)->nchars,     \
+                         Mcharset, (void *) ((charset)->name));        \
+      }                                                                        \
+  } while (0)
+
+
+#define SET_SRC(mt, format, from, to)                                  \
+  do {                                                                 \
+    if (format <= MTEXT_FORMAT_UTF_8)                                  \
+      {                                                                        \
+       src = mt->data + POS_CHAR_TO_BYTE (mt, from);                   \
+       src_end = mt->data + POS_CHAR_TO_BYTE (mt, to);                 \
+      }                                                                        \
+    else if (format <= MTEXT_FORMAT_UTF_16BE)                          \
+      {                                                                        \
+       src                                                             \
+         = mt->data + (sizeof (short)) * POS_CHAR_TO_BYTE (mt, from);  \
+       src_end                                                         \
+         = mt->data + (sizeof (short)) * POS_CHAR_TO_BYTE (mt, to);    \
+      }                                                                        \
+    else                                                               \
+      {                                                                        \
+       src = mt->data + (sizeof (int)) * from;                         \
+       src_end = mt->data + (sizeof (int)) * to;                       \
+      }                                                                        \
+  } while (0)
+
+
+#define ONE_MORE_CHAR(c, bytes, format)                                \
+  do {                                                         \
+    if (src == src_end)                                                \
+      goto finish;                                             \
+    if (format <= MTEXT_FORMAT_UTF_8)                          \
+      c = STRING_CHAR_AND_BYTES (src, bytes);                  \
+    else if (format <= MTEXT_FORMAT_UTF_16BE)                  \
+      {                                                                \
+       c = mtext_ref_char (mt, from++);                        \
+       bytes = (sizeof (short)) * CHAR_UNITS_UTF16 (c);        \
+      }                                                                \
+    else                                                       \
+      {                                                                \
+       c = ((unsigned *) (mt->data))[from++];                  \
+       bytes = sizeof (int);                                   \
+      }                                                                \
+  } while (0)
+
+
+static int
+encode_unsupporeted_char (int c, unsigned char *dst, unsigned char *dst_end,
+                         MText *mt, int pos)
+{
+  int len;
+  char *format;
+
+  len = c < 0x10000 ? 8 : 10;
+  if (dst + len > dst_end)
+    return 0;
+
+  mtext_put_prop (mt, pos, pos + 1, Mcoding, Mnil);
+  format = (c < 0xD800 ? "<U+%04X>"
+           : c < 0xE000 ? "<M+%04X>"
+           : c < 0x10000 ? "<U+%04X>"
+           : c < 0x110000 ? "<U+%06X>"
+           : "<M+%06X>");
+  sprintf ((char *) dst, format, c);
+  return len;
+}
+
+
+
+/** Finish decoding of bytes at SOURCE (ending at SRC_END) into NCHARS
+    characters by CONVERTER into M-text MT.  SRC is a pointer to the
+    not-yet processed bytes.  ERROR is 1 iff an invalid byte was
+    found.  */
+
+static int
+finish_decoding (MText *mt, MConverter *converter, int nchars,
+                const unsigned char *source, const unsigned char *src_end,
+                const unsigned char *src,
+                int error)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+
+  if (src == src_end)
+    internal->carryover_bytes = 0;
+  else if (error
+          || (converter->last_block
+              && ! converter->lenient))
+    converter->result = MCONVERSION_RESULT_INVALID_BYTE;
+  else if (! converter->last_block)
+    {
+      unsigned char *dst = internal->carryover;
+
+      if (src < source || src > src_end)
+       {
+         dst += internal->carryover_bytes;
+         src = source;
+       }
+      while (src < src_end)
+       *dst++ = *src++;
+      internal->carryover_bytes = dst - internal->carryover;
+      converter->result = MCONVERSION_RESULT_INSUFFICIENT_SRC;
+    }
+  else
+    {
+      unsigned char *dst = mt->data + mt->nbytes;
+      unsigned char *dst_end = mt->data + mt->allocated;
+      const unsigned char *src_stop = src_end;
+      int c;
+      int last_nchars = nchars;
+
+      if (src < source || src > src_end)
+       src_stop = internal->carryover + internal->carryover_bytes;
+      while (1)
+       {
+         if (converter->at_most && nchars == converter->at_most)
+           break;
+         if (src == src_stop)
+           {
+             if (src == src_end)
+               break;
+             src = source;
+             if (src == src_end)
+               break;
+             src_stop = src_end;
+           }
+         c = *src++;
+         EMIT_CHAR (c);
+       }
+      TAKEIN_CHARS (mt, nchars - last_nchars, dst - (mt->data + mt->nbytes),
+                   mcharset__binary);
+      internal->carryover_bytes = 0;
+    }
+
+  converter->nchars += nchars;
+  converter->nbytes += ((src < source || src > src_end) ? 0 : src - source);
+  return (converter->result == MCONVERSION_RESULT_INVALID_BYTE ? -1 : 0);
+}
+
+
+\f
+/* Staffs for coding-systems of type MCODING_TYPE_CHARSET.  */
+
+static int
+setup_coding_charset (MCodingSystem *coding)
+{
+  int ncharsets = coding->ncharsets;
+  unsigned *code_charset_table;
+
+  if (ncharsets > 1)
+    {
+      /* At first, reorder charset list by dimensions (a charset of
+        smaller dimension comes first).  As the number of charsets is
+        usually very small (at most 32), we do a simple sort.  */
+      MCharset **charsets;
+      int idx = 0;
+      int i, j;
+
+      MTABLE_ALLOCA (charsets, NUM_SUPPORTED_CHARSETS, MERROR_CODING);
+      memcpy (charsets, coding->charsets,
+             sizeof (MCharset *) * NUM_SUPPORTED_CHARSETS);
+      for (i = 0; i < 4; i++)
+       for (j = 0; j < ncharsets; j++)
+         if (charsets[j]->dimension == i)
+           coding->charsets[idx++] = charsets[j];
+    }
+
+  MTABLE_CALLOC (code_charset_table, 256, MERROR_CODING);
+  while (ncharsets--)
+    {
+      int dim = coding->charsets[ncharsets]->dimension;
+      int from = coding->charsets[ncharsets]->code_range[(dim - 1) * 4];
+      int to = coding->charsets[ncharsets]->code_range[(dim - 1) * 4 + 1];
+
+      if (coding->charsets[ncharsets]->ascii_compatible)
+       coding->ascii_compatible = 1;
+      while (from <= to)
+       code_charset_table[from++] |= 1 << ncharsets;
+    }
+
+  coding->extra_spec = (void *) code_charset_table;
+  return 0;
+}
+
+static int
+reset_coding_charset (MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  MCodingSystem *coding = internal->coding;
+
+  if (! coding->ready
+      && setup_coding_charset (coding) < 0)
+    return -1;
+  coding->ready = 1;
+  return 0;
+}
+
+static int
+decode_coding_charset (const unsigned char *source, int src_bytes, MText *mt,
+                      MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  MCodingSystem *coding = internal->coding;
+  const unsigned char *src = internal->carryover;
+  const unsigned char *src_stop = src + internal->carryover_bytes;
+  const unsigned char *src_end = source + src_bytes;
+  const unsigned char *src_base;
+  unsigned char *dst = mt->data + mt->nbytes;
+  unsigned char *dst_end = mt->data + mt->allocated;
+  int nchars = 0;
+  int last_nchars = 0;
+  int at_most = converter->at_most > 0 ? converter->at_most : -1;
+
+  unsigned *code_charset_table = (unsigned *) coding->extra_spec;
+  MCharset **charsets = coding->charsets;
+  MCharset *charset = mcharset__ascii;
+  int error = 0;
+
+  while (1)
+    {
+      MCharset *this_charset = NULL;
+      int c;
+      unsigned mask;
+
+      ONE_MORE_BASE_BYTE (c);
+      mask = code_charset_table[c];
+      if (mask)
+       {
+         int idx = 0;
+         unsigned code = c;
+         int nbytes = 1;
+         int dim;
+         
+         while (mask)
+           {
+             while (! (mask & 1)) mask >>= 1, idx++;
+             this_charset = charsets[idx];
+             dim = this_charset->dimension;
+             while (nbytes < dim)
+               {
+                 ONE_MORE_BYTE (c);
+                 code = (code << 8) | c;
+                 nbytes++;
+               }
+             c = DECODE_CHAR (this_charset, code);
+             if (c >= 0)
+               goto emit_char;
+             mask >>= 1, idx++;
+           }
+       }
+
+      if (! converter->lenient)
+       break;
+      REWIND_SRC_TO_BASE ();
+      c = *src++;
+      this_charset = mcharset__binary;
+
+    emit_char:
+      if (this_charset != mcharset__ascii
+         && this_charset != charset)
+       {
+         TAKEIN_CHARS (mt, nchars - last_nchars, 
+                       dst - (mt->data + mt->nbytes), charset);
+         charset = this_charset;
+         last_nchars = nchars;
+       }
+      EMIT_CHAR (c);
+    }
+  /* We reach here because of an invalid byte.  */
+  error = 1;
+
+ source_end:
+  TAKEIN_CHARS (mt, nchars - last_nchars,
+               dst - (mt->data + mt->nbytes), charset);
+  return finish_decoding (mt, converter, nchars,
+                         source, src_end, src_base, error);
+}
+
+static int
+encode_coding_charset (MText *mt, int from, int to,
+                      unsigned char *destination, int dst_bytes,
+                      MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  MCodingSystem *coding = internal->coding;
+  unsigned char *src, *src_end;
+  unsigned char *dst = destination;
+  unsigned char *dst_end = dst + dst_bytes;
+  int nchars = 0;
+  int ncharsets = coding->ncharsets;
+  MCharset **charsets = coding->charsets;
+  int ascii_compatible = coding->ascii_compatible;
+  enum MTextFormat format = mt->format;
+
+  SET_SRC (mt, format, from, to);
+  while (1)
+    {
+      int c, bytes;
+
+      ONE_MORE_CHAR (c, bytes, format);
+
+      if (c < 0x80 && ascii_compatible)
+       {
+         CHECK_DST (1);
+         *dst++ = c;
+       }
+      else
+       {
+         unsigned code;
+         MCharset *charset = NULL;
+         int i = 0;
+
+         while (1)
+           {
+             charset = charsets[i];
+             code = ENCODE_CHAR (charset, c);
+             if (code != MCHAR_INVALID_CODE)
+               break;
+             if (++i == ncharsets)
+               goto unsupported_char;
+           }
+
+         CHECK_DST (charset->dimension);
+         if (charset->dimension == 1)
+           {
+             *dst++ = code;
+           }
+         else if (charset->dimension == 2)
+           {
+             *dst++ = code >> 8;
+             *dst++ = code & 0xFF;
+           }
+         else if (charset->dimension == 3)
+           {
+             *dst++ = code >> 16;
+             *dst++ = (code >> 8) & 0xFF;
+             *dst++ = code & 0xFF;
+           }
+         else
+           {
+             *dst++ = code >> 24;
+             *dst++ = (code >> 16) & 0xFF;
+             *dst++ = (code >> 8) & 0xFF;
+             *dst++ = code & 0xFF;
+           }
+       }
+      src += bytes;
+      nchars++;
+      continue;
+
+    unsupported_char:
+      {
+       int len;
+
+       if (! converter->lenient)
+         break;
+       len = encode_unsupporeted_char (c, dst, dst_end, mt, from + nchars);
+       if (len == 0)
+         goto insufficient_destination;
+       dst += len;
+       src += bytes;
+       nchars++;
+      }
+    }
+  /* We reach here because of an unsupported char.  */
+  converter->result = MCONVERSION_RESULT_INVALID_CHAR;
+  goto finish;
+
+ insufficient_destination:
+  converter->result = MCONVERSION_RESULT_INSUFFICIENT_DST;
+
+ finish:
+  converter->nchars += nchars;
+  converter->nbytes += dst - destination;
+  return (converter->result == MCONVERSION_RESULT_INVALID_CHAR ? -1 : 0);
+}
+
+\f
+/* Staffs for coding-systems of type MCODING_TYPE_UTF (8).  */
+
+#define UTF8_CHARSET(p)                                        \
+  (! ((p)[0] & 0x80) ? (mcharset__unicode)                     \
+   : CHAR_HEAD_P ((p) + 1) ? (mcharset__binary)                        \
+   : ! ((p)[0] & 0x20) ? (mcharset__unicode)                   \
+   : CHAR_HEAD_P ((p) + 2) ? (mcharset__binary)                        \
+   : ! ((p)[0] & 0x10) ? (mcharset__unicode)                   \
+   : CHAR_HEAD_P ((p) + 3) ? (mcharset__binary)                        \
+   : ! ((p)[0] & 0x08) ? ((((((p)[0] & 0x07) << 2)             \
+                           & (((p)[1] & 0x30) >> 4)) <= 0x10)  \
+                         ? (mcharset__unicode)                 \
+                         : (mcharset__m17n))                   \
+   : CHAR_HEAD_P ((p) + 4) ? (mcharset__binary)                        \
+   : ! ((p)[0] & 0x04) ? (mcharset__m17n)                      \
+   : CHAR_HEAD_P ((p) + 5) ? (mcharset__binary)                        \
+   : ! ((p)[0] & 0x02) ? (mcharset__m17n)                      \
+   : (mcharset__binary))
+
+
+static int
+decode_coding_utf_8 (const unsigned char *source, int src_bytes, MText *mt,
+                    MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  MCodingSystem *coding = internal->coding;
+  const unsigned char *src = internal->carryover;
+  const unsigned char *src_stop = src + internal->carryover_bytes;
+  const unsigned char *src_end = source + src_bytes;
+  const unsigned char *src_base;
+  unsigned char *dst = mt->data + mt->nbytes;
+  unsigned char *dst_end = mt->data + mt->allocated;
+  int nchars = 0;
+  int last_nchars = 0;
+  int at_most = converter->at_most > 0 ? converter->at_most : -1;
+  int error = 0;
+  int full = converter->lenient || (coding->charsets[0] == mcharset__m17n);
+  MCharset *charset = NULL;
+
+  while (1)
+    {
+      int c, c1, bytes;
+      MCharset *this_charset = NULL;
+
+      ONE_MORE_BASE_BYTE (c);
+
+      if (!(c & 0x80))
+       bytes = 1;
+      else if (!(c & 0x40))
+       goto invalid_byte;
+      else if (!(c & 0x20))
+       bytes = 2, c &= 0x1F;
+      else if (!(c & 0x10))
+       bytes = 3, c &= 0x0F;
+      else if (!(c & 0x08))
+       bytes = 4, c &= 0x07;
+      else if (!(c & 0x04))
+       bytes = 5, c &= 0x03;
+      else if (!(c & 0x02))
+       bytes = 6, c &= 0x01;
+      else
+       goto invalid_byte;
+
+      while (bytes-- > 1)
+       {
+         ONE_MORE_BYTE (c1);
+         if ((c1 & 0xC0) != 0x80)
+           goto invalid_byte;
+         c = (c << 6) | (c1 & 0x3F);
+       }
+
+      if (full
+         || c < 0xD800 || (c >= 0xE000 && c < 0x110000))
+       goto emit_char;
+
+    invalid_byte:
+      if (! converter->lenient)
+       break;
+      REWIND_SRC_TO_BASE ();
+      c = *src++;
+      this_charset = mcharset__binary;
+
+    emit_char:
+      if (this_charset != charset)
+       {
+         TAKEIN_CHARS (mt, nchars - last_nchars, 
+                       dst - (mt->data + mt->nbytes), charset);
+         charset = this_charset;
+         last_nchars = nchars;
+       }
+      EMIT_CHAR (c);
+    }
+  /* We reach here because of an invalid byte.  */
+  error = 1;
+
+ source_end:
+  TAKEIN_CHARS (mt, nchars - last_nchars,
+               dst - (mt->data + mt->nbytes), charset);
+  return finish_decoding (mt, converter, nchars,
+                         source, src_end, src_base, error);
+}
+
+static int
+encode_coding_utf_8 (MText *mt, int from, int to,
+                    unsigned char *destination, int dst_bytes,
+                    MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  MCodingSystem *coding = internal->coding;
+  unsigned char *src, *src_end;
+  unsigned char *dst = destination;
+  unsigned char *dst_end = dst + dst_bytes;
+  int nchars = 0;
+  enum MTextFormat format = mt->format;
+
+  SET_SRC (mt, format, from, to);
+
+  if (format <= MTEXT_FORMAT_UTF_8
+      && (converter->lenient
+         || coding->charsets[0] == mcharset__m17n))
+    {
+      if (dst_bytes < src_end - src)
+       {
+         int byte_pos = (src + dst_bytes) - mt->data;
+
+         to = POS_BYTE_TO_CHAR (mt, byte_pos);
+         byte_pos = POS_CHAR_TO_BYTE (mt, to);
+         src_end = mt->data + byte_pos;
+         converter->result = MCONVERSION_RESULT_INSUFFICIENT_DST;
+       }
+      memcpy (destination, src, src_end - src);
+      nchars = to - from;
+      dst += src_end - src;
+      goto finish;
+    }
+
+  while (1)
+    {
+      int c, bytes;
+
+      ONE_MORE_CHAR (c, bytes, format);
+
+      if ((c >= 0xD800 && c < 0xE000) || c >= 0x110000)
+       break;
+      CHECK_DST (bytes);
+      dst += CHAR_STRING (c, dst);
+      src += bytes;
+      nchars++;
+    }
+  /* We reach here because of an unsupported char.  */
+  converter->result = MCONVERSION_RESULT_INVALID_CHAR;
+  goto finish;
+
+ insufficient_destination:
+  converter->result = MCONVERSION_RESULT_INSUFFICIENT_DST;
+
+ finish:
+  converter->nchars += nchars;
+  converter->nbytes += dst - destination;
+  return (converter->result == MCONVERSION_RESULT_INVALID_CHAR ? -1 : 0);
+}
+
+\f
+/* Staffs for coding-systems of type MCODING_TYPE_UTF (16 & 32).  */
+
+enum utf_bom
+  {
+    UTF_BOM_MAYBE,
+    UTF_BOM_NO,
+    UTF_BOM_YES,
+    UTF_BOM_MAX
+  };
+
+enum utf_endian
+  {
+    UTF_BIG_ENDIAN,
+    UTF_LITTLE_ENDIAN,
+    UTF_ENDIAN_MAX
+  };
+
+struct utf_status
+{
+  int surrogate;
+  enum utf_bom bom;
+  enum utf_endian endian;
+};
+
+static int
+setup_coding_utf (MCodingSystem *coding)
+{
+  MCodingInfoUTF *info = (MCodingInfoUTF *) (coding->extra_info);
+  MCodingInfoUTF *spec;
+
+  if (info->code_unit_bits == 8)
+    coding->ascii_compatible = 1;
+  else if (info->code_unit_bits == 16
+          || info->code_unit_bits == 32)
+    {
+      if (info->bom < 0 || info->bom > 2
+         || info->endian < 0 || info->endian > 1)
+       MERROR (MERROR_CODING, -1);
+    }
+  else
+    return -1;
+
+  MSTRUCT_CALLOC (spec, MERROR_CODING);
+  *spec = *info;
+  coding->extra_spec = (void *) (spec);
+  return 0;
+}
+
+static int
+reset_coding_utf (MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  MCodingSystem *coding = internal->coding;
+  struct utf_status *status = (struct utf_status *) &(converter->status);
+
+  if (! coding->ready
+      && setup_coding_utf (coding) < 0)
+    return -1;
+  coding->ready = 1;
+
+  status->surrogate = 0;
+  status->bom = ((MCodingInfoUTF *) (coding->extra_spec))->bom;
+  status->endian = ((MCodingInfoUTF *) (coding->extra_spec))->endian;
+  return 0;
+}
+
+static int
+decode_coding_utf_16 (const unsigned char *source, int src_bytes, MText *mt,
+                     MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  const unsigned char *src = internal->carryover;
+  const unsigned char *src_stop = src + internal->carryover_bytes;
+  const unsigned char *src_end = source + src_bytes;
+  const unsigned char *src_base;
+  unsigned char *dst = mt->data + mt->nbytes;
+  unsigned char *dst_end = mt->data + mt->allocated;
+  int nchars = 0;
+  int last_nchars = 0;
+  int at_most = converter->at_most > 0 ? converter->at_most : -1;
+  struct utf_status *status = (struct utf_status *) &(converter->status);
+  unsigned char b1, b2;
+  MCharset *charset = NULL;
+  int error = 0;
+
+  if (status->bom != UTF_BOM_NO)
+    {
+      int c;
+
+      ONE_MORE_BASE_BYTE (b1);
+      ONE_MORE_BYTE (b2);
+      c = (b1 << 8) | b2;
+      if (c == 0xFEFF)
+       status->endian = UTF_BIG_ENDIAN;
+      else if (c == 0xFFFE)
+       status->endian = UTF_LITTLE_ENDIAN;
+      else if (status->bom == UTF_BOM_MAYBE
+              || converter->lenient)
+       {
+         status->endian = UTF_BIG_ENDIAN;
+         REWIND_SRC_TO_BASE ();
+       }
+      else
+       {
+         error = 1;
+         goto source_end;
+       }
+      status->bom = UTF_BOM_NO;
+    }
+
+  while (1)
+    {
+      int c, c1;
+      MCharset *this_charset = NULL;
+
+      ONE_MORE_BASE_BYTE (b1);
+      ONE_MORE_BYTE (b2);
+      if (status->endian == UTF_BIG_ENDIAN)
+       c = ((b1 << 8) | b2);
+      else
+       c = ((b2 << 8) | b1);
+      if (c < 0xD800 || c >= 0xE000)
+       goto emit_char;
+      else if (c < 0xDC00)
+       {
+         ONE_MORE_BYTE (b1);
+         ONE_MORE_BYTE (b2);
+         if (status->endian == UTF_BIG_ENDIAN)
+           c1 = ((b1 << 8) | b2);
+         else
+           c1 = ((b2 << 8) | b1);
+         if (c1 < 0xDC00 || c1 >= 0xE000)
+           goto invalid_byte;
+         c = 0x10000 + ((c - 0xD800) << 10) + (c1 - 0xDC00);
+         goto emit_char;
+       }
+
+    invalid_byte:
+      if (! converter->lenient)
+       break;
+      REWIND_SRC_TO_BASE ();
+      ONE_MORE_BYTE (b1);
+      ONE_MORE_BYTE (b2);
+      if (status->endian == UTF_BIG_ENDIAN)
+       c = ((b1 << 8) | b2);
+      else
+       c = ((b2 << 8) | b1);
+      this_charset = mcharset__binary;
+
+    emit_char:
+      if (this_charset != charset)
+       {
+         TAKEIN_CHARS (mt, nchars - last_nchars, 
+                       dst - (mt->data + mt->nbytes), charset);
+         charset = this_charset;
+         last_nchars = nchars;
+       }
+      EMIT_CHAR (c);
+    }
+  /* We reach here because of an invalid byte.  */
+  error = 1;
+
+ source_end:
+  TAKEIN_CHARS (mt, nchars - last_nchars,
+               dst - (mt->data + mt->nbytes), charset);
+  return finish_decoding (mt, converter, nchars,
+                         source, src_end, src_base, error);
+}
+
+
+static int
+decode_coding_utf_32 (const unsigned char *source, int src_bytes, MText *mt,
+                     MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  const unsigned char *src = internal->carryover;
+  const unsigned char *src_stop = src + internal->carryover_bytes;
+  const unsigned char *src_end = source + src_bytes;
+  const unsigned char *src_base;
+  unsigned char *dst = mt->data + mt->nbytes;
+  unsigned char *dst_end = mt->data + mt->allocated;
+  int nchars = 0;
+  int last_nchars = 0;
+  int at_most = converter->at_most > 0 ? converter->at_most : -1;
+  struct utf_status *status = (struct utf_status *) &(converter->status);
+  unsigned char b1, b2, b3, b4;
+  MCharset *charset = NULL;
+  int error = 0;
+
+  if (status->bom != UTF_BOM_NO)
+    {
+      unsigned c;
+
+      ONE_MORE_BASE_BYTE (b1);
+      ONE_MORE_BYTE (b2);
+      ONE_MORE_BYTE (b3);
+      ONE_MORE_BYTE (b4);
+      c = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
+      if (c == 0x0000FEFF)
+       status->endian = UTF_BIG_ENDIAN;
+      else if (c == 0xFFFE0000)
+       status->endian = UTF_LITTLE_ENDIAN;
+      else if (status->bom == UTF_BOM_MAYBE
+              || converter->lenient)
+       {
+         status->endian = UTF_BIG_ENDIAN;
+         REWIND_SRC_TO_BASE ();
+       }
+      else
+       {
+         error = 1;
+         goto source_end;
+       }
+      status->bom = UTF_BOM_NO;
+    }
+
+  while (1)
+    {
+      unsigned c;
+      MCharset *this_charset = NULL;
+
+      ONE_MORE_BASE_BYTE (b1);
+      ONE_MORE_BYTE (b2);
+      ONE_MORE_BYTE (b3);
+      ONE_MORE_BYTE (b4);
+      if (status->endian == UTF_BIG_ENDIAN)
+       c = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
+      else
+       c = (b4 << 24) | (b3 << 16) | (b2 << 8) | b1;
+      if (c < 0xD800 || (c >= 0xE000 && c < 0x110000))
+       goto emit_char;
+
+      if (! converter->lenient)
+       break;
+      REWIND_SRC_TO_BASE ();
+      ONE_MORE_BYTE (c);
+      this_charset = mcharset__binary;
+
+    emit_char:
+      if (this_charset != charset)
+       {
+         TAKEIN_CHARS (mt, nchars - last_nchars, 
+                       dst - (mt->data + mt->nbytes), charset);
+         charset = this_charset;
+         last_nchars = nchars;
+       }
+      EMIT_CHAR (c);
+    }
+  /* We reach here because of an invalid byte.  */
+  error = 1;
+
+ source_end:
+  TAKEIN_CHARS (mt, nchars - last_nchars,
+               dst - (mt->data + mt->nbytes), charset);
+  return finish_decoding (mt, converter, nchars,
+                         source, src_end, src_base, error);
+}
+
+
+static int
+encode_coding_utf_16 (MText *mt, int from, int to,
+                     unsigned char *destination, int dst_bytes,
+                     MConverter *converter)
+{
+  unsigned char *src, *src_end;
+  unsigned char *dst = destination;
+  unsigned char *dst_end = dst + dst_bytes;
+  int nchars = 0;
+  struct utf_status *status = (struct utf_status *) &(converter->status);
+  int big_endian = status->endian == UTF_BIG_ENDIAN;
+  enum MTextFormat format = mt->format;
+
+  SET_SRC (mt, format, from, to);
+
+  if (status->bom != UTF_BOM_NO)
+    {
+      CHECK_DST (2);
+      if (big_endian)
+       *dst++ = 0xFE, *dst++ = 0xFF;
+      else
+       *dst++ = 0xFF, *dst++ = 0xFE;
+      status->bom = UTF_BOM_NO;
+    }
+
+  while (1)
+    {
+      int c, bytes;
+
+      ONE_MORE_CHAR (c, bytes, format);
+
+      if (c < 0xD800 || (c >= 0xE000 && c < 0x10000))
+       {
+         CHECK_DST (2);
+         if (big_endian)
+           *dst++ = c >> 8, *dst++ = c & 0xFF;
+         else
+           *dst++ = c & 0xFF, *dst++ = c >> 8;
+       }
+      else if (c >= 0x10000 && c < 0x110000)
+       {
+         int c1, c2;
+
+         CHECK_DST (4);
+         c -= 0x10000;
+         c1 = (c >> 10) + 0xD800;
+         c2 = (c & 0x3FF) + 0xDC00;
+         if (big_endian)
+           *dst++ = c1 >> 8, *dst++ = c1 & 0xFF,
+             *dst++ = c2 >> 8, *dst++ = c2 & 0xFF;
+         else
+           *dst++ = c1 & 0xFF, *dst++ = c1 >> 8,
+             *dst++ = c2 & 0xFF, *dst++ = c2 >> 8;
+       }
+      else
+       {
+         unsigned char buf[11];
+         int len, i;
+
+         if (! converter->lenient)
+           break;
+         len = encode_unsupporeted_char (c, buf, buf + (dst_end - dst),
+                                         mt, from + nchars);
+         if (len == 0)
+           goto insufficient_destination;
+         if (big_endian)
+           for (i = 0; i < len; i++)
+             *dst++ = 0, *dst++ = buf[i];
+         else
+           for (i = 0; i < len; i++)
+             *dst++ = buf[i], *dst++ = 0;
+       }
+      src += bytes;
+      nchars++;
+    }
+  /* We reach here because of an unsupported char.  */
+  converter->result = MCONVERSION_RESULT_INVALID_CHAR;
+  goto finish;
+
+ insufficient_destination:
+  converter->result = MCONVERSION_RESULT_INSUFFICIENT_DST;
+
+ finish:
+  converter->nchars += nchars;
+  converter->nbytes += dst - destination;
+  return (converter->result == MCONVERSION_RESULT_INVALID_CHAR ? -1 : 0);
+}
+
+static int
+encode_coding_utf_32 (MText *mt, int from, int to,
+                     unsigned char *destination, int dst_bytes,
+                     MConverter *converter)
+{
+  unsigned char *src, *src_end;
+  unsigned char *dst = destination;
+  unsigned char *dst_end = dst + dst_bytes;
+  int nchars = 0;
+  struct utf_status *status = (struct utf_status *) &(converter->status);
+  int big_endian = status->endian == UTF_BIG_ENDIAN;
+  enum MTextFormat format = mt->format;
+
+  SET_SRC (mt, format, from, to);
+
+  if (status->bom != UTF_BOM_NO)
+    {
+      CHECK_DST (4);
+      if (big_endian)
+       *dst++ = 0x00, *dst++ = 0x00, *dst++ = 0xFE, *dst++ = 0xFF;
+      else
+       *dst++ = 0xFF, *dst++ = 0xFE, *dst++ = 0x00, *dst++ = 0x00;
+      status->bom = UTF_BOM_NO;
+    }
+
+  while (1)
+    {
+      int c, bytes;
+
+      ONE_MORE_CHAR (c, bytes, format);
+
+      if (c < 0xD800 || (c >= 0xE000 && c < 0x110000))
+       {
+         CHECK_DST (4);
+         if (big_endian)
+           *dst++ = 0x00, *dst++ = c >> 16,
+             *dst++ = (c >> 8) & 0xFF, *dst++ = c & 0xFF;
+         else
+           *dst++ = c & 0xFF, *dst++ = (c >> 8) & 0xFF,
+             *dst++ = c >> 16, *dst++ = 0x00;
+       }
+      else
+       {
+         unsigned char buf[11];
+         int len, i;
+
+         if (! converter->lenient)
+           break;
+         len = encode_unsupporeted_char (c, buf, buf + (dst_end - dst),
+                                         mt, from + nchars);
+         if (len == 0)
+           goto insufficient_destination;
+         if (big_endian)
+           for (i = 0; i < len; i++)
+             *dst++ = 0, *dst++ = buf[i];
+         else
+           for (i = 0; i < len; i++)
+             *dst++ = buf[i], *dst++ = 0;
+       }
+      src += bytes;
+      nchars++;
+    }
+  /* We reach here because of an unsupported char.  */
+  converter->result = MCONVERSION_RESULT_INVALID_CHAR;
+  goto finish;
+
+ insufficient_destination:
+  converter->result = MCONVERSION_RESULT_INSUFFICIENT_DST;
+
+ finish:
+  converter->nchars += nchars;
+  converter->nbytes += dst - destination;
+  return (converter->result == MCONVERSION_RESULT_INVALID_CHAR ? -1 : 0);
+}
+
+\f
+/* Staffs for coding-systems of type MCODING_TYPE_ISO_2022.  */
+
+#define ISO_CODE_STX   0x02            /* start text */
+#define ISO_CODE_SO    0x0E            /* shift-out */
+#define ISO_CODE_SI    0x0F            /* shift-in */
+#define ISO_CODE_SS2_7 0x19            /* single-shift-2 for 7-bit code */
+#define ISO_CODE_ESC   0x1B            /* escape */
+#define ISO_CODE_SS2   0x8E            /* single-shift-2 */
+#define ISO_CODE_SS3   0x8F            /* single-shift-3 */
+
+/** Structure pointed by MCodingSystem.extra_spec.  */
+
+struct iso_2022_spec
+{
+  unsigned flags;
+
+  /** Initial graphic registers (0..3) invoked to each graphic
+      plane left and right. */
+  int initial_invocation[2];
+
+  /** Initially designated charsets for each graphic register.  */
+  MCharset *initial_designation[4];
+
+  int n_designations;
+  char *designations;
+
+  int use_esc;
+};
+
+struct iso_2022_status
+{
+  int invocation[2];
+  MCharset *designation[4];
+  unsigned single_shifting : 1;
+  unsigned bol : 1;
+  unsigned r2l : 1;
+  unsigned utf8_shifting : 1;
+  MCharset *non_standard_charset;
+  int non_standard_charset_bytes;
+  int non_standard_encoding;
+};
+
+enum iso_2022_code_class {
+  ISO_control_0,               /* Control codes in the range
+                                  0x00..0x1F and 0x7F, except for the
+                                  following 4 codes.  */
+  ISO_shift_out,               /* ISO_CODE_SO (0x0E) */
+  ISO_shift_in,                        /* ISO_CODE_SI (0x0F) */
+  ISO_single_shift_2_7,                /* ISO_CODE_SS2_7 (0x19) */
+  ISO_escape,                  /* ISO_CODE_SO (0x1B) */
+  ISO_control_1,               /* Control codes in the range
+                                  0x80..0x9F, except for the
+                                  following 3 codes.  */
+  ISO_single_shift_2,          /* ISO_CODE_SS2 (0x8E) */
+  ISO_single_shift_3,          /* ISO_CODE_SS3 (0x8F) */
+  ISO_control_sequence_introducer, /* ISO_CODE_CSI (0x9B) */
+  ISO_0x20_or_0x7F,          /* Codes of the values 0x20 or 0x7F.  */
+  ISO_graphic_plane_0,  /* Graphic codes in the range 0x21..0x7E.  */
+  ISO_0xA0_or_0xFF,          /* Codes of the values 0xA0 or 0xFF.  */
+  ISO_graphic_plane_1   /* Graphic codes in the range 0xA1..0xFE.  */
+} iso_2022_code_class[256];
+
+
+#define MCODING_ISO_DESIGNATION_MASK   \
+  (MCODING_ISO_DESIGNATION_G0          \
+   | MCODING_ISO_DESIGNATION_G1                \
+   | MCODING_ISO_DESIGNATION_CTEXT     \
+   | MCODING_ISO_DESIGNATION_CTEXT_EXT)
+
+static int
+setup_coding_iso_2022 (MCodingSystem *coding)
+{
+  MCodingInfoISO2022 *info = (MCodingInfoISO2022 *) (coding->extra_info);
+  int ncharsets = coding->ncharsets;
+  struct iso_2022_spec *spec;
+  int designation_policy = info->flags & MCODING_ISO_DESIGNATION_MASK;
+  int i;
+
+  coding->ascii_compatible = 0;
+
+  MSTRUCT_CALLOC (spec, MERROR_CODING);
+
+  spec->flags = info->flags;
+  spec->initial_invocation[0] = info->initial_invocation[0];
+  spec->initial_invocation[1] = info->initial_invocation[1];
+  for (i = 0; i < 4; i++)
+    spec->initial_designation[i] = NULL;
+  if (designation_policy)
+    {
+      spec->n_designations = ncharsets;
+      if (spec->flags & MCODING_ISO_FULL_SUPPORT)
+       spec->n_designations += mcharset__iso_2022_table.used;
+      MTABLE_CALLOC (spec->designations, spec->n_designations, MERROR_CODING);
+      for (i = 0; i < spec->n_designations; i++)
+       spec->designations[i] = -1;
+    }
+  else
+    {
+      if (spec->flags & MCODING_ISO_FULL_SUPPORT)
+       MERROR (MERROR_CODING, -1);
+      spec->designations = NULL;
+    }
+
+  for (i = 0; i < ncharsets; i++)
+    {
+      int reg = info->designations[i];
+
+      if (reg != -5
+         && coding->charsets[i]->final_byte > 0
+         && (reg < -4 || reg > 3))
+       MERROR (MERROR_CODING, -1);
+      if (reg >= 0)
+       {
+         if (spec->initial_designation[reg])
+           MERROR (MERROR_CODING, -1);
+         spec->initial_designation[reg] = coding->charsets[i];
+       }
+      else if (reg >= -4)
+       {
+         if (! designation_policy
+             && ! (spec->flags & MCODING_ISO_EUC_TW_SHIFT))
+           MERROR (MERROR_CODING, -1);
+         reg += 4;
+       }
+
+      if (designation_policy)
+       spec->designations[i] = reg;
+      if (coding->charsets[i] == mcharset__ascii)
+       coding->ascii_compatible = 1;
+    }
+
+  if (coding->ascii_compatible
+      && (spec->flags & (MCODING_ISO_DESIGNATION_G0
+                        | MCODING_ISO_DESIGNATION_CTEXT
+                        | MCODING_ISO_DESIGNATION_CTEXT_EXT
+                        | MCODING_ISO_LOCKING_SHIFT)))
+    coding->ascii_compatible = 0;
+
+  if (spec->flags & MCODING_ISO_FULL_SUPPORT)
+    for (i = 0; i < mcharset__iso_2022_table.used; i++)
+      {
+       MCharset *charset = mcharset__iso_2022_table.charsets[i];
+
+       spec->designations[ncharsets + i]
+         = ((designation_policy == MCODING_ISO_DESIGNATION_CTEXT
+             || designation_policy == MCODING_ISO_DESIGNATION_CTEXT_EXT)
+            ? (charset->code_range[0] == 32
+               || charset->code_range[1] == 255)
+            : designation_policy == MCODING_ISO_DESIGNATION_G1);
+      }
+
+  spec->use_esc = ((spec->flags & MCODING_ISO_DESIGNATION_MASK)
+                  || ((spec->flags & MCODING_ISO_LOCKING_SHIFT)
+                      && (spec->initial_designation[2]
+                          || spec->initial_designation[3]))
+                  || (! (spec->flags & MCODING_ISO_EIGHT_BIT)
+                      && (spec->flags & MCODING_ISO_SINGLE_SHIFT))
+                  || (spec->flags & MCODING_ISO_ISO6429));
+
+  coding->extra_spec = (void *) spec;
+
+  return 0;
+}
+
+static int
+reset_coding_iso_2022 (MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  MCodingSystem *coding = internal->coding;
+  struct iso_2022_status *status
+    = (struct iso_2022_status *) &(converter->status);
+  struct iso_2022_spec *spec;
+  int i;
+
+  if (! coding->ready
+      && setup_coding_iso_2022 (coding) < 0)
+    return -1;
+  coding->ready = 1;
+
+  spec = (struct iso_2022_spec *) coding->extra_spec;
+  status->invocation[0] = spec->initial_invocation[0];
+  status->invocation[1] = spec->initial_invocation[1];
+  for (i = 0; i < 4; i++)
+    status->designation[i] = spec->initial_designation[i];
+  status->single_shifting = 0;
+  status->bol = 1;
+  status->r2l = 0;
+
+  return 0;
+}
+
+#define ISO2022_DECODE_DESIGNATION(reg, dim, chars, final, rev)                  \
+  do {                                                                   \
+    MCharset *charset;                                                   \
+                                                                         \
+    if ((final) < '0' || (final) >= 128)                                 \
+      goto invalid_byte;                                                 \
+    if (rev < 0)                                                         \
+      {                                                                          \
+       charset = MCHARSET_ISO_2022 ((dim), (chars), (final));            \
+       if (! (spec->flags & MCODING_ISO_FULL_SUPPORT))                   \
+         {                                                               \
+           int i;                                                        \
+                                                                         \
+           for (i = 0; i < coding->ncharsets; i++)                       \
+             if (charset == coding->charsets[i])                         \
+               break;                                                    \
+           if (i == coding->ncharsets)                                   \
+             goto invalid_byte;                                          \
+         }                                                               \
+      }                                                                          \
+    else                                                                 \
+      {                                                                          \
+       int i;                                                            \
+                                                                         \
+       for (i = 0; i < mcharset__iso_2022_table.used; i++)               \
+         {                                                               \
+           charset = mcharset__iso_2022_table.charsets[i];               \
+           if (charset->revision == (rev)                                \
+               && charset->dimension == (dim)                            \
+               && charset->final_byte == (final)                         \
+               && (charset->code_range[1] == (chars)                     \
+                   || ((chars) == 96 && charset->code_range[1] == 255))) \
+             break;                                                      \
+         }                                                               \
+       if (i == mcharset__iso_2022_table.used)                           \
+         goto invalid_byte;                                              \
+      }                                                                          \
+    status->designation[reg] = charset;                                          \
+  } while (0)
+
+
+static MCharset *
+find_ctext_non_standard_charset (char *charset_name)
+{
+  MCharset *charset;
+
+  if (! strcmp (charset_name, "koi8-r"))
+    charset = MCHARSET (msymbol ("koi8-r"));
+  else if  (! strcmp (charset_name, "big5-0"))
+    charset = MCHARSET (msymbol ("big5"));    
+  else
+    charset = NULL;
+  return charset;
+}
+
+static int
+decode_coding_iso_2022 (const unsigned char *source, int src_bytes, MText *mt,
+                      MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  MCodingSystem *coding = internal->coding;
+  const unsigned char *src = internal->carryover;
+  const unsigned char *src_stop = src + internal->carryover_bytes;
+  const unsigned char *src_end = source + src_bytes;
+  const unsigned char *src_base;
+  unsigned char *dst = mt->data + mt->nbytes;
+  unsigned char *dst_end = mt->data + mt->allocated;
+  int nchars = 0;
+  int last_nchars = 0;
+  int at_most = converter->at_most > 0 ? converter->at_most : -1;
+  struct iso_2022_spec *spec = (struct iso_2022_spec *) coding->extra_spec;
+  struct iso_2022_status *status
+    = (struct iso_2022_status *) &(converter->status);
+  MCharset *charset0, *charset1, *charset;
+  int error = 0;
+  MCharset *cns_charsets[15];
+
+  charset0 = (status->invocation[0] >= 0
+             ? status->designation[status->invocation[0]] : NULL);
+  charset1 = (status->invocation[1] >= 0
+             ? status->designation[status->invocation[1]] : NULL);
+  charset = mcharset__ascii;
+
+  if (spec->flags & MCODING_ISO_EUC_TW_SHIFT)
+    {
+      int i;
+
+      memset (cns_charsets, 0, sizeof (cns_charsets));
+      for (i = 0; i < coding->ncharsets; i++)
+       if (coding->charsets[i]->dimension == 2
+           && coding->charsets[i]->code_range[1] == 126)
+         {
+           int final = coding->charsets[i]->final_byte;
+
+           if (final >= 'G' && final <= 'M')
+             cns_charsets[final - 'G'] = coding->charsets[i];
+           else if (final < 0)
+             cns_charsets[14] = coding->charsets[i];
+         }
+    }
+
+  while (1)
+    {
+      MCharset *this_charset = NULL;
+      int c1, c2, c3;
+
+      ONE_MORE_BASE_BYTE (c1);
+
+      if (status->utf8_shifting)
+       {
+         int buf[6];
+         int bytes = CHAR_BYTES_BY_HEAD (c1);
+         int i;
+         
+         buf[0] = c1;
+         for (i = 1; i < bytes; i++)
+           {
+             ONE_MORE_BYTE (c1);
+             buf[i] = c1;
+           }
+         this_charset = UTF8_CHARSET (buf);
+         c1 = STRING_CHAR_UTF8 (buf);
+         goto emit_char;
+       }
+
+      if (status->non_standard_encoding > 0)
+       {
+         int i;
+
+         this_charset = status->non_standard_charset;
+         for (i = 1; i < status->non_standard_charset_bytes; i++)
+           {
+             ONE_MORE_BYTE (c2);
+             c1 = (c1 << 8) | c2;
+           }
+         c1 = DECODE_CHAR (this_charset, c1);
+         goto emit_char;
+       }
+
+      switch (iso_2022_code_class[c1])
+       {
+       case ISO_graphic_plane_0:
+         this_charset = charset0;
+         break;
+
+       case ISO_0x20_or_0x7F:
+         if (! charset0
+             || (charset0->code_range[0] != 32
+                 && charset0->code_range[1] != 255))
+           /* This is SPACE or DEL.  */
+           this_charset = mcharset__ascii;
+         else
+           /* This is a graphic character of plane 0.  */        
+           this_charset = charset0;
+         break;
+
+       case ISO_graphic_plane_1:
+         if (!charset1)
+           goto invalid_byte;
+         this_charset = charset1;
+         break;
+
+       case ISO_0xA0_or_0xFF:
+         if (! charset1
+             || charset1->code_range[0] == 33
+             || ! (spec->flags & MCODING_ISO_EIGHT_BIT))
+           goto invalid_byte;
+         /* This is a graphic character of plane 1. */
+         if (! charset1)
+           goto invalid_byte;
+         this_charset = charset1;
+         break;
+
+       case ISO_control_0:
+         this_charset = mcharset__ascii;
+         break;
+
+       case ISO_control_1:
+         goto invalid_byte;
+
+       case ISO_shift_out:
+         if ((spec->flags & MCODING_ISO_LOCKING_SHIFT)
+             &&  status->designation[1])
+           {
+             status->invocation[0] = 1;
+             charset0 = status->designation[1];
+             continue;
+           }
+         this_charset = mcharset__ascii;
+         break;
+
+       case ISO_shift_in:
+         if (spec->flags & MCODING_ISO_LOCKING_SHIFT)
+           {
+             status->invocation[0] = 0;
+             charset0 = status->designation[0];
+             continue;
+           }
+         this_charset = mcharset__ascii;
+         break;
+
+       case ISO_single_shift_2_7:
+         if (! (spec->flags & MCODING_ISO_SINGLE_SHIFT_7))
+           {
+             this_charset = mcharset__ascii;
+             break;
+           }
+         c1 = 'N';
+         goto label_escape_sequence;
+
+       case ISO_single_shift_2:
+         if (spec->flags & MCODING_ISO_EUC_TW_SHIFT)
+           {
+             ONE_MORE_BYTE (c1);
+             if (c1 < 0xA1 || (c1 > 0xA7 && c1 < 0xAF) || c1 > 0xAF
+                 || ! cns_charsets[c1 - 0xA1])
+               goto invalid_byte;
+             status->designation[2] = cns_charsets[c1 - 0xA1];
+           }
+         else if (! (spec->flags & MCODING_ISO_SINGLE_SHIFT))
+           goto invalid_byte;
+         /* SS2 is handled as an escape sequence of ESC 'N' */
+         c1 = 'N';
+         goto label_escape_sequence;
+
+       case ISO_single_shift_3:
+         if (! (spec->flags & MCODING_ISO_SINGLE_SHIFT))
+           goto invalid_byte;
+         /* SS2 is handled as an escape sequence of ESC 'O' */
+         c1 = 'O';
+         goto label_escape_sequence;
+
+       case ISO_control_sequence_introducer:
+         /* CSI is handled as an escape sequence of ESC '[' ...  */
+         c1 = '[';
+         goto label_escape_sequence;
+
+       case ISO_escape:
+         if (! spec->use_esc)
+           {
+             this_charset = mcharset__ascii;
+             break;
+           }
+         ONE_MORE_BYTE (c1);
+       label_escape_sequence:
+         /* Escape sequences handled here are invocation,
+            designation, and direction specification.  */
+         switch (c1)
+           {
+           case '&':        /* revision of following character set */
+             if (! (spec->flags & MCODING_ISO_DESIGNATION_MASK))
+               goto unused_escape_sequence;
+             ONE_MORE_BYTE (c1);
+             if (c1 < '@' || c1 > '~')
+               goto invalid_byte;
+             ONE_MORE_BYTE (c1);
+             if (c1 != ISO_CODE_ESC)
+               goto invalid_byte;
+             ONE_MORE_BYTE (c1);
+             goto label_escape_sequence;
+
+           case '$':        /* designation of 2-byte character set */
+             if (! (spec->flags & MCODING_ISO_DESIGNATION_MASK))
+               goto unused_escape_sequence;
+             ONE_MORE_BYTE (c1);
+             if (c1 >= '@' && c1 <= 'B')
+               { /* designation of JISX0208.1978, GB2312.1980, or
+                    JISX0208.1980 */
+                 ISO2022_DECODE_DESIGNATION (0, 2, 94, c1, -1);
+               }
+             else if (c1 >= 0x28 && c1 <= 0x2B)
+               { /* designation of (dimension 2, chars 94) character set */
+                 ONE_MORE_BYTE (c2);
+                 ISO2022_DECODE_DESIGNATION (c1 - 0x28, 2, 94, c2, -1);
+               }
+             else if (c1 >= 0x2C && c1 <= 0x2F)
+               { /* designation of (dimension 2, chars 96) character set */
+                 ONE_MORE_BYTE (c2);
+                 ISO2022_DECODE_DESIGNATION (c1 - 0x2C, 2, 96, c2, -1);
+               }
+             else
+               goto invalid_byte;
+             /* We must update these variables now.  */
+             if (status->invocation[0] >= 0)
+               charset0 = status->designation[status->invocation[0]];
+             if (status->invocation[1] >= 0)
+               charset1 = status->designation[status->invocation[1]];
+             continue;
+
+           case 'n':           /* invocation of locking-shift-2 */
+             if (! (spec->flags & MCODING_ISO_LOCKING_SHIFT)
+                 || ! status->designation[2])
+               goto invalid_byte;
+             status->invocation[0] = 2;
+             charset0 = status->designation[2];
+             continue;
+
+           case 'o':           /* invocation of locking-shift-3 */
+             if (! (spec->flags & MCODING_ISO_LOCKING_SHIFT)
+                 || ! status->designation[3])
+               goto invalid_byte;
+             status->invocation[0] = 3;
+             charset0 = status->designation[3];
+             continue;
+
+           case 'N':           /* invocation of single-shift-2 */
+             if (! ((spec->flags & MCODING_ISO_SINGLE_SHIFT)
+                    || (spec->flags & MCODING_ISO_EUC_TW_SHIFT))
+                 || ! status->designation[2])
+               goto invalid_byte;
+             this_charset = status->designation[2];
+             ONE_MORE_BYTE (c1);
+             if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0))
+               goto invalid_byte;
+             break;
+
+           case 'O':           /* invocation of single-shift-3 */
+             if (! (spec->flags & MCODING_ISO_SINGLE_SHIFT)
+                 || ! status->designation[3])
+               goto invalid_byte;
+             this_charset = status->designation[3];
+             ONE_MORE_BYTE (c1);
+             if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0))
+               goto invalid_byte;
+             break;
+
+           case '[':           /* specification of direction */
+             if (! (spec->flags & MCODING_ISO_ISO6429))
+               goto invalid_byte;
+             /* For the moment, nested direction is not supported.
+                So, (coding->mode & CODING_MODE_DIRECTION) zero means
+                left-to-right, and nonzero means right-to-left.  */
+             ONE_MORE_BYTE (c1);
+             switch (c1)
+               {
+               case ']':       /* end of the current direction */
+               case '0':       /* end of the current direction */
+                 status->r2l = 0;
+                 break;
+
+               case '1':       /* start of left-to-right direction */
+                 ONE_MORE_BYTE (c1);
+                 if (c1 != ']')
+                   goto invalid_byte;
+                 status->r2l = 0;
+                 break;
+
+               case '2':       /* start of right-to-left direction */
+                 ONE_MORE_BYTE (c1);
+                 if (c1 != ']')
+                   goto invalid_byte;
+                 status->r2l = 1;
+                 break;
+
+               default:
+                 goto invalid_byte;
+               }
+             continue;
+
+           case '%':
+             {
+               char charset_name[16];
+               int bytes;
+               int i;
+
+               if (! spec->flags & MCODING_ISO_DESIGNATION_CTEXT_EXT)
+                 goto invalid_byte;
+               /* Compound-text uses these escape sequences:
+
+               ESC % G  -- utf-8 bytes -- ESC % @
+               ESC % / 1 M L -- charset name -- STX -- bytes --
+               ESC % / 2 M L -- charset name -- STX -- bytes --
+               ESC % / 3 M L -- charset name -- STX -- bytes --
+               ESC % / 4 M L -- charset name -- STX -- bytes --
+
+               It also uses this sequence but that is not yet
+               supported here.
+
+               ESC % / 0 M L -- charset name -- STX -- bytes -- */
+
+               ONE_MORE_BYTE (c1);
+               if (c1 == 'G')
+                 {
+                   status->utf8_shifting = 1;
+                   continue;
+                 }
+               if (c1 == '@')
+                 {
+                   if (! status->utf8_shifting)
+                     goto invalid_byte;
+                   status->utf8_shifting = 0;
+                   continue;
+                 }
+               if (c1 != '/')
+                 goto invalid_byte;
+               ONE_MORE_BYTE (c1);
+               if (c1 < '1' || c1 > '4')
+                 goto invalid_byte;
+               status->non_standard_charset_bytes = c1 - '0';
+               ONE_MORE_BYTE (c1);
+               ONE_MORE_BYTE (c2);
+               if (c1 < 128 || c2 < 128)
+                 goto invalid_byte;
+               bytes = (c1 - 128) * 128 + (c2 - 128);
+               for (i = 0; i < 16; i++)
+                 {
+                   ONE_MORE_BYTE (c1);
+                   if (c1 == ISO_CODE_STX)
+                     break;
+                   charset_name[i] = TOLOWER (c1);
+                 }
+               if (i == 16)
+                 goto invalid_byte;
+               charset_name[i++] = '\0';
+               this_charset = find_ctext_non_standard_charset (charset_name);
+               if (! this_charset)
+                 goto invalid_byte;
+               status->non_standard_charset = this_charset;
+               status->non_standard_encoding = bytes - i;
+               continue;
+             }
+
+           default:
+             if (! (spec->flags & MCODING_ISO_DESIGNATION_MASK))
+               goto unused_escape_sequence;
+             if (c1 >= 0x28 && c1 <= 0x2B)
+               { /* designation of (dimension 1, chars 94) charset */
+                 ONE_MORE_BYTE (c2);
+                 ISO2022_DECODE_DESIGNATION (c1 - 0x28, 1, 94, c2, -1);
+               }
+             else if (c1 >= 0x2C && c1 <= 0x2F)
+               { /* designation of (dimension 1, chars 96) charset */
+                 ONE_MORE_BYTE (c2);
+                 ISO2022_DECODE_DESIGNATION (c1 - 0x2C, 1, 96, c2, -1);
+               }
+             else
+               goto invalid_byte;
+             /* We must update these variables now.  */
+             if (status->invocation[0] >= 0)
+               charset0 = status->designation[status->invocation[0]];
+             if (status->invocation[1] >= 0)
+               charset1 = status->designation[status->invocation[1]];
+             continue;
+
+           unused_escape_sequence:
+             UNGET_ONE_BYTE (c1);
+             c1 = ISO_CODE_ESC;
+             this_charset = mcharset__ascii;
+           }
+       }
+
+      if (this_charset->dimension == 1)
+       {
+         if (this_charset->code_range[1] <= 128)
+           c1 &= 0x7F;
+       }
+      else if (this_charset->dimension == 2)
+       {
+         ONE_MORE_BYTE (c2);
+         c1 = ((c1 & 0x7F) << 8) | (c2 & 0x7F);
+       }
+      else                     /* i.e.  (dimension == 3) */
+       {
+         ONE_MORE_BYTE (c2);
+         ONE_MORE_BYTE (c3);
+         c1 = ((c1 & 0x7F) << 16) | ((c2 & 0x7F) << 8) | (c3 & 0x7F);
+       }
+      c1 = DECODE_CHAR (this_charset, c1);
+      goto emit_char;
+
+    invalid_byte:
+      if (! converter->lenient)
+       break;
+      REWIND_SRC_TO_BASE ();
+      c1 = *src++;
+      this_charset = mcharset__binary;
+
+    emit_char:
+      if (this_charset != mcharset__ascii
+         && this_charset != charset)
+       {
+         TAKEIN_CHARS (mt, nchars - last_nchars,
+                       dst - (mt->data + mt->nbytes), charset);
+         charset = this_charset;
+         last_nchars = nchars;
+       }
+      EMIT_CHAR (c1);
+      if (status->non_standard_encoding > 0)
+       status->non_standard_encoding -= status->non_standard_charset_bytes;
+    }
+  /* We reach here because of an invalid byte.  */
+  error = 1;
+
+
+
+ source_end:
+  TAKEIN_CHARS (mt, nchars - last_nchars,
+               dst - (mt->data + mt->nbytes), charset);
+  return finish_decoding (mt, converter, nchars,
+                         source, src_end, src_base, error);
+
+}
+
+/* Produce codes (escape sequence) for designating CHARSET to graphic
+   register REG at DST, and increment DST.  If CHARSET->final-char is
+   '@', 'A', or 'B' and SHORT_FORM is nonzero, produce designation
+   sequence of short-form.  Update STATUS->designation.  */
+
+#define ISO2022_ENCODE_DESIGNATION(reg, charset, spec, status)            \
+  do {                                                                    \
+    char *intermediate_char_94 = "()*+";                                  \
+    char *intermediate_char_96 = ",-./";                                  \
+                                                                          \
+    if (dst + 4 > dst_end)                                                \
+      goto memory_shortage;                                               \
+    *dst++ = ISO_CODE_ESC;                                                \
+    if (charset->dimension == 1)                                          \
+      {                                                                           \
+       if (charset->code_range[0] != 32                                   \
+           && charset->code_range[1] != 255)                              \
+         *dst++ = (unsigned char) (intermediate_char_94[reg]);            \
+       else                                                               \
+         *dst++ = (unsigned char) (intermediate_char_96[reg]);            \
+      }                                                                           \
+    else                                                                  \
+      {                                                                           \
+       *dst++ = '$';                                                      \
+       if (charset->code_range[0] != 32                                   \
+           && charset->code_range[1] != 255)                              \
+         {                                                                \
+           if (spec->flags & MCODING_ISO_LONG_FORM                        \
+               || reg != 0                                                \
+               || charset->final_byte < '@' || charset->final_byte > 'B') \
+             *dst++ = (unsigned char) (intermediate_char_94[reg]);        \
+         }                                                                \
+       else                                                               \
+         *dst++ = (unsigned char) (intermediate_char_96[reg]);            \
+      }                                                                           \
+    *dst++ = charset->final_byte;                                         \
+                                                                          \
+    status->designation[reg] = charset;                                           \
+  } while (0)
+
+
+/* The following two macros produce codes (control character or escape
+   sequence) for ISO-2022 single-shift functions (single-shift-2 and
+   single-shift-3).  */
+
+#define ISO2022_ENCODE_SINGLE_SHIFT_2(spec, status)    \
+  do {                                                 \
+    if (dst + 2 > dst_end)                             \
+      goto memory_shortage;                            \
+    if (! (spec->flags & MCODING_ISO_EIGHT_BIT))       \
+      *dst++ = ISO_CODE_ESC, *dst++ = 'N';             \
+    else                                               \
+      *dst++ = ISO_CODE_SS2;                           \
+    status->single_shifting = 1;                       \
+  } while (0)
+
+
+#define ISO2022_ENCODE_SINGLE_SHIFT_3(spec, status)    \
+  do {                                                 \
+    if (dst + 2 > dst_end)                             \
+      goto memory_shortage;                            \
+    if (! (spec->flags & MCODING_ISO_EIGHT_BIT))       \
+      *dst++ = ISO_CODE_ESC, *dst++ = 'O';             \
+    else                                               \
+      *dst++ = ISO_CODE_SS3;                           \
+    status->single_shifting = 1;                       \
+  } while (0)
+
+
+/* The following four macros produce codes (control character or
+   escape sequence) for ISO-2022 locking-shift functions (shift-in,
+   shift-out, locking-shift-2, and locking-shift-3).  */
+
+#define ISO2022_ENCODE_SHIFT_IN(status)                \
+  do {                                         \
+    if (dst + 1 > dst_end)                     \
+      goto memory_shortage;                    \
+    *dst++ = ISO_CODE_SI;                      \
+    status->invocation[0] = 0;                 \
+  } while (0)
+
+
+#define ISO2022_ENCODE_SHIFT_OUT(status)       \
+  do {                                         \
+    if (dst + 1 > dst_end)                     \
+      goto memory_shortage;                    \
+    *dst++ = ISO_CODE_SO;                      \
+    status->invocation[0] = 1;                 \
+  } while (0)
+
+
+#define ISO2022_ENCODE_LOCKING_SHIFT_2(status) \
+  do {                                         \
+    if (dst + 2 > dst_end)                     \
+      goto memory_shortage;                    \
+    *dst++ = ISO_CODE_ESC, *dst++ = 'n';       \
+    status->invocation[0] = 2;                 \
+  } while (0)
+
+
+#define ISO2022_ENCODE_LOCKING_SHIFT_3(status) \
+  do {                                         \
+    if (dst + 2 > dst_end)                     \
+      goto memory_shortage;                    \
+    *dst++ = ISO_CODE_ESC, *dst++ = 'o';       \
+    status->invocation[0] = 3;                 \
+  } while (0)
+
+#define ISO2022_ENCODE_UTF8_SHIFT_START(len)   \
+  do {                                         \
+    CHECK_DST (3 + len);                       \
+    *dst++ = ISO_CODE_ESC;                     \
+    *dst++ = '%';                              \
+    *dst++ = 'G';                              \
+    status->utf8_shifting = 1;                 \
+  } while (0)
+
+
+#define ISO2022_ENCODE_UTF8_SHIFT_END()        \
+  do {                                 \
+    CHECK_DST (3);                     \
+    *dst++ = ISO_CODE_ESC;             \
+    *dst++ = '%';                      \
+    *dst++ = '@';                      \
+    status->utf8_shifting = 0;         \
+  } while (0)
+
+
+#define ISO2022_ENCODE_NON_STANDARD(name, len)                 \
+  do {                                                         \
+    CHECK_DST (6 + len + 1 + non_standard_charset_bytes);      \
+    non_standard_begin = dst;                                  \
+    *dst++ = ISO_CODE_ESC;                                     \
+    *dst++ = '%';                                              \
+    *dst++ = '/';                                              \
+    *dst++ = '0' + non_standard_charset_bytes;                 \
+    *dst++ = 0, *dst++ = 0;    /* filled later */              \
+    memcpy (dst, name, len);                                   \
+    dst += len;                                                        \
+    *dst++ = ISO_CODE_STX;                                     \
+    non_standard_bytes = len + 1;                              \
+  } while (0)
+
+
+static char *
+find_ctext_non_standard_name (MCharset *charset, int *bytes)
+{
+  char *name = msymbol_name (charset->name);
+
+  if (! strcmp (name, "koi8-r"))
+    *bytes = 1;
+  else if (! strcmp (name, "big5"))
+    name = "big5-0", *bytes = 2;
+  else
+    return NULL;
+  return name;
+}
+
+/* Designate CHARSET to a graphic register specified in
+   SPEC->designation.  If the register is not yet invoked to graphic
+   left not right, invoke it to graphic left.  DSTP points to a
+   variable containing a memory address where the output must go.
+   DST_END is the limit of that memory.
+
+   Return 0 if it succeeds.  Return -1 otherwise, which means that the
+   memory area is too short.  By side effect, update the variable that
+   DSTP points to.  */
+
+static int
+iso_2022_designate_invoke_charset (MCodingSystem *coding,
+                                  MCharset *charset,
+                                  struct iso_2022_spec *spec,
+                                  struct iso_2022_status *status,
+                                  unsigned char **dstp,
+                                  unsigned char *dst_end)
+{
+  int i;
+  unsigned char *dst = *dstp;
+
+  for (i = 0; i < 4; i++)
+    if (charset == status->designation[i])
+      break;
+
+  if (i >= 4)
+    {
+      /* CHARSET is not yet designated to any graphic registers.  */
+      for (i = 0; i < coding->ncharsets; i++)
+       if (charset == coding->charsets[i])
+         break;
+      if (i == coding->ncharsets)
+       {
+         for (i = 0; i < mcharset__iso_2022_table.used; i++)
+           if (charset == mcharset__iso_2022_table.charsets[i])
+             break;
+         i += coding->ncharsets;
+       }
+      i = spec->designations[i];
+      ISO2022_ENCODE_DESIGNATION (i, charset, spec, status);
+    }
+
+  if (status->invocation[0] != i
+      && status->invocation[1] != i)
+    {
+      /* Graphic register I is not yet invoked.  */
+      switch (i)
+       {
+       case 0:                 /* graphic register 0 */
+         ISO2022_ENCODE_SHIFT_IN (status);
+         break;
+
+       case 1:                 /* graphic register 1 */
+         ISO2022_ENCODE_SHIFT_OUT (status);
+         break;
+
+       case 2:                 /* graphic register 2 */
+         if (spec->flags & MCODING_ISO_SINGLE_SHIFT)
+           ISO2022_ENCODE_SINGLE_SHIFT_2 (spec, status);
+         else
+           ISO2022_ENCODE_LOCKING_SHIFT_2 (status);
+         break;
+
+       case 3:                 /* graphic register 3 */
+         if (spec->flags & MCODING_ISO_SINGLE_SHIFT)
+           ISO2022_ENCODE_SINGLE_SHIFT_3 (spec, status);
+         else
+           ISO2022_ENCODE_LOCKING_SHIFT_3 (status);
+         break;
+       }
+    }
+  *dstp = dst;
+  return 0;
+
+ memory_shortage:
+  *dstp = dst;
+  return -1;
+}
+
+
+/* Reset the invocation/designation status to the initial one.  SPEC
+   and STATUS contain information about the current and initial
+   invocation /designation status respectively.  DSTP points to a
+   variable containing a memory address where the output must go.
+   DST_END is the limit of that memory.
+
+   Return 0 if it succeeds.  Return -1 otherwise, which means that the
+   memory area is too short.  By side effect, update the variable that
+   DSTP points to.  */
+
+static int
+iso_2022_reset_invocation_designation (struct iso_2022_spec *spec,
+                                      struct iso_2022_status *status,
+                                      unsigned char **dstp,
+                                      unsigned char *dst_end)
+{
+  unsigned char *dst = *dstp;
+  int i;
+
+  /* Reset the invocation status of GL.  We have not yet supported GR
+     invocation.  */
+  if (status->invocation[0] != spec->initial_invocation[0]
+       && spec->initial_invocation[0] >= 0)
+    {
+      if (spec->initial_invocation[0] == 0)
+       ISO2022_ENCODE_SHIFT_IN (status);
+      else if (spec->initial_invocation[0] == 1)
+       ISO2022_ENCODE_SHIFT_OUT (status);
+      else if (spec->initial_invocation[0] == 2)
+       ISO2022_ENCODE_LOCKING_SHIFT_2 (status);
+      else                     /* i.e. spec->initial_invocation[0] == 3 */
+       ISO2022_ENCODE_LOCKING_SHIFT_3 (status);
+    }
+
+  /* Reset the designation status of G0..G3.  */
+  for (i = 0; i < 4; i++)
+    if (status->designation[i] != spec->initial_designation[i]
+       && spec->initial_designation[i])
+      {
+       MCharset *charset = spec->initial_designation[i];
+       
+       ISO2022_ENCODE_DESIGNATION (i, charset, spec, status);
+      }
+
+  *dstp = dst;
+  return 0;
+
+ memory_shortage:
+  *dstp = dst;
+  return -1;
+}
+
+
+static int
+encode_coding_iso_2022 (MText *mt, int from, int to,
+                      unsigned char *destination, int dst_bytes,
+                      MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  MCodingSystem *coding = internal->coding;
+  unsigned char *src, *src_end;
+  unsigned char *dst = destination;
+  unsigned char *dst_end = dst + dst_bytes;
+  int nchars = 0;
+  unsigned char *dst_base;
+  struct iso_2022_spec *spec = (struct iso_2022_spec *) coding->extra_spec;
+  int full_support = spec->flags & MCODING_ISO_FULL_SUPPORT;
+  struct iso_2022_status *status
+    = (struct iso_2022_status *) &(converter->status);
+  MCharset *primary, *charset0, *charset1;
+  int next_primary_change;
+  int ncharsets = coding->ncharsets;
+  MCharset **charsets = coding->charsets;
+  MCharset *cns_charsets[15];
+  int ascii_compatible = coding->ascii_compatible;
+  MCharset *non_standard_charset = NULL;
+  int non_standard_charset_bytes = 0;
+  int non_standard_bytes = 0;
+  unsigned char *non_standard_begin = NULL;
+  enum MTextFormat format = mt->format;
+
+  SET_SRC (mt, format, from, to);
+
+  if (spec->flags & MCODING_ISO_EUC_TW_SHIFT)
+    {
+      int i;
+
+      memset (cns_charsets, 0, sizeof (cns_charsets));
+      for (i = 0; i < ncharsets; i++)
+       if (charsets[i]->dimension == 2)
+         {
+           int final = charsets[i]->final_byte;
+
+           if (final >= 'G' && final <= 'M')
+             cns_charsets[final - 'G'] = charsets[i];
+           else if (final < 0)
+             cns_charsets[14] = charsets[i];
+         }
+    }
+
+  next_primary_change = from;
+  primary = NULL;
+  charset0 = status->designation[status->invocation[0]];
+  charset1 = (status->invocation[1] < 0 ? NULL
+             : status->designation[status->invocation[1]]);
+
+  while (1)
+    {
+      int bytes, c;
+
+      dst_base = dst;
+      ONE_MORE_CHAR (c, bytes, format);
+
+      if (c < 128 && ascii_compatible)
+       {
+         if (status->utf8_shifting)
+           ISO2022_ENCODE_UTF8_SHIFT_END ();
+         CHECK_DST (1);
+         *dst++ = c;
+       }
+      else if (c <= 32 || c == 127)
+       {
+         if (status->utf8_shifting)
+           ISO2022_ENCODE_UTF8_SHIFT_END ();
+         if (spec->flags & MCODING_ISO_RESET_AT_CNTL
+             || (c == '\n' && spec->flags & MCODING_ISO_RESET_AT_EOL))
+           {
+             if (iso_2022_reset_invocation_designation (spec, status,
+                                                        &dst, dst_end) < 0)
+               goto insufficient_destination;
+             charset0 = status->designation[status->invocation[0]];
+             charset1 = (status->invocation[1] < 0 ? NULL
+                         : status->designation[status->invocation[1]]);
+           }
+         CHECK_DST (1);
+         *dst++ = c;
+       }
+      else
+       {
+         unsigned code = MCHAR_INVALID_CODE;
+         MCharset *charset = NULL;
+         int gr_mask;
+         int pos = from + nchars;
+
+         if (pos >= next_primary_change)
+           {
+             MSymbol primary_charset
+               = (MSymbol) mtext_get_prop (mt, pos, Mcharset);
+             primary = MCHARSET (primary_charset);
+             if (primary && primary != mcharset__binary)
+               {
+                 if (primary->final_byte <= 0)
+                   primary = NULL;
+                 else if (! full_support)
+                   {
+                     int i;
+
+                     for (i = 0; i < ncharsets; i++)
+                       if (primary == charsets[i])
+                         break;
+                     if (i == ncharsets)
+                       primary = NULL;
+                   }
+               }
+
+             mtext_prop_range (mt, Mcharset, pos,
+                               NULL, &next_primary_change, 0);
+           }
+
+         if (primary && primary != mcharset__binary)
+           {
+             code = ENCODE_CHAR (primary, c);
+             if (code != MCHAR_INVALID_CODE)
+               charset = primary;
+           }
+         if (! charset)
+           {
+             if (c <= 32 || c == 127)
+               {
+                 code = c;
+                 charset = mcharset__ascii;
+               }
+             else 
+               {
+                 int i;
+
+                 for (i = 0; i < ncharsets; i++)
+                   {
+                     charset = charsets[i];
+                     code = ENCODE_CHAR (charset, c);
+                     if (code != MCHAR_INVALID_CODE)
+                       break;
+                   }
+                 if (i == ncharsets)
+                   {
+                     if (spec->flags & MCODING_ISO_FULL_SUPPORT)
+                       {
+                         for (i = 0; i < mcharset__iso_2022_table.used; i++)
+                           {
+                             charset = mcharset__iso_2022_table.charsets[i];
+                             code = ENCODE_CHAR (charset, c);
+                             if (code != MCHAR_INVALID_CODE)
+                               break;
+                           }
+                         if (i == mcharset__iso_2022_table.used)
+                           {
+                             if (spec->flags & MCODING_ISO_DESIGNATION_CTEXT_EXT)
+                               goto unsupported_char;
+                             converter->result = MCONVERSION_RESULT_INVALID_CHAR;
+                             goto finish;
+                           }
+                       }
+                     else
+                       goto unsupported_char;
+                   }
+               }
+           }
+
+         if (charset
+             && (charset->final_byte >= 0
+                 || spec->flags & MCODING_ISO_EUC_TW_SHIFT))
+           {
+             if (code >= 0x80 && code < 0xA0)
+               goto unsupported_char;
+             code &= 0x7F7F7F7F;
+             if (status->utf8_shifting)
+               ISO2022_ENCODE_UTF8_SHIFT_END ();
+             if (charset == charset0)
+               gr_mask = 0;
+             else if (charset == charset1)
+               gr_mask = 0x80;
+             else
+               {
+                 unsigned char *p = NULL;
+
+                 if (spec->flags & MCODING_ISO_EUC_TW_SHIFT)
+                   {
+                     int i;
+
+                     if (cns_charsets[0] == charset)
+                       {
+                         CHECK_DST (2);
+                       }
+                     else
+                       {
+                         for (i = 1; i < 15; i++)
+                           if (cns_charsets[i] == charset)
+                             break;
+                         CHECK_DST (4);
+                         *dst++ = ISO_CODE_SS2;
+                         *dst++ = 0xA1 + i;
+                       }
+                     status->single_shifting = 1;
+                     p = dst;
+                   }
+                 else
+                   {
+                     if (iso_2022_designate_invoke_charset
+                         (coding, charset, spec, status, &dst, dst_end) < 0)
+                       goto insufficient_destination;
+                     charset0 = status->designation[status->invocation[0]];
+                     charset1 = (status->invocation[1] < 0 ? NULL
+                                 : status->designation[status->invocation[1]]);
+                   }
+                 if (status->single_shifting)
+                   gr_mask
+                     = (spec->flags & MCODING_ISO_EIGHT_BIT) ? 0x80 : 0;
+                 else if (charset == charset0)
+                   gr_mask = 0;
+                 else
+                   gr_mask = 0x80;
+               }
+             if (charset->dimension == 1)
+               {
+                 CHECK_DST (1);
+                 *dst++ = code | gr_mask;
+               }
+             else if (charset->dimension == 2)
+               {
+                 CHECK_DST (2);
+                 *dst++ = (code >> 8) | gr_mask;
+                 *dst++ = (code & 0xFF) | gr_mask;
+               }
+             else
+               {
+                 CHECK_DST (3);
+                 *dst++ = (code >> 16) | gr_mask;
+                 *dst++ = ((code >> 8) & 0xFF) | gr_mask;
+                 *dst++ = (code & 0xFF) | gr_mask;
+               }
+             status->single_shifting = 0;
+           }
+         else if (charset && spec->flags & MCODING_ISO_DESIGNATION_CTEXT_EXT)
+           {
+             if (charset != non_standard_charset)
+               {
+                 char *name = (find_ctext_non_standard_name
+                               (charset, &non_standard_charset_bytes));
+
+                 if (name)
+                   {
+                     int len = strlen (name);
+                     
+                     ISO2022_ENCODE_NON_STANDARD (name, len);
+                     non_standard_charset = charset;
+                   }
+                 else
+                   non_standard_charset = NULL;
+               }
+
+             if (non_standard_charset)
+               {
+                 if (dst + non_standard_charset_bytes > dst_end)
+                   goto insufficient_destination;
+                 non_standard_bytes += non_standard_charset_bytes;
+                 non_standard_begin[4] = (non_standard_bytes / 128) | 0x80;
+                 non_standard_begin[5] = (non_standard_bytes % 128) | 0x80;
+                 if (non_standard_charset_bytes == 1)
+                   *dst++ = code;
+                 else if (non_standard_charset_bytes == 2)
+                   *dst++ = code >> 8, *dst++ = code & 0xFF;
+                 else if (non_standard_charset_bytes == 3)
+                   *dst++ = code >> 16, *dst++ = (code >> 8) & 0xFF,
+                     *dst++ = code & 0xFF;
+                 else          /* i.e non_standard_charset_bytes == 3 */
+                   *dst++ = code >> 24, *dst++ = (code >> 16) & 0xFF,
+                     *dst++ = (code >> 8) & 0xFF, *dst++ = code & 0xFF;
+               }
+             else
+               {
+                 int len = CHAR_BYTES (c);
+
+                 if (c >= 0x110000)
+                   goto unsupported_char;
+                 if (! status->utf8_shifting)
+                   ISO2022_ENCODE_UTF8_SHIFT_START (len);
+                 else
+                   CHECK_DST (len);
+                 CHAR_STRING (c, dst);
+               }
+           }
+         else
+           goto unsupported_char;
+       }
+      src += bytes;
+      nchars++;
+      continue;
+
+    unsupported_char:
+      {
+       int len;
+
+       if (iso_2022_designate_invoke_charset (coding, mcharset__ascii,
+                                              spec, status,
+                                              &dst, dst_end) < 0)
+         goto insufficient_destination;
+       if (! converter->lenient)
+         break;
+       len = encode_unsupporeted_char (c, dst, dst_end, mt, from + nchars);
+       if (len == 0)
+         goto insufficient_destination;
+       dst += len;
+       src += bytes;
+       nchars++;
+      }
+    }
+  /* We reach here because of an unsupported char.  */
+  converter->result = MCONVERSION_RESULT_INVALID_CHAR;
+  goto finish;
+
+ insufficient_destination:
+  dst = dst_base;
+  converter->result = MCONVERSION_RESULT_INSUFFICIENT_DST;
+
+ finish:
+  if (converter->result == MCONVERSION_RESULT_SUCCESS
+      && converter->last_block)
+    {
+      if (status->utf8_shifting)
+       {
+         ISO2022_ENCODE_UTF8_SHIFT_END ();
+         dst_base = dst;
+       }
+      if (spec->flags & MCODING_ISO_RESET_AT_EOL
+         && charset0 != spec->initial_designation[0])
+       {
+         if (iso_2022_reset_invocation_designation (spec, status,
+                                                    &dst, dst_end) < 0)
+           goto insufficient_destination;
+       }
+    }
+  converter->nchars += nchars;
+  converter->nbytes += dst - destination;
+  return (converter->result == MCONVERSION_RESULT_INVALID_CHAR ? -1 : 0);
+}
+
+\f
+/* Staffs for coding-systems of type MCODING_TYPE_MISC.  */
+
+/* For SJIS handling... */
+
+#define SJIS_TO_JIS(s1, s2)                            \
+  (s2 >= 0x9F                                          \
+   ? (((s1 * 2 - (s1 >= 0xE0 ? 0x160 : 0xE0)) << 8)    \
+      | (s2 - 0x7E))                                   \
+   : (((s1 * 2 - ((s1 >= 0xE0) ? 0x161 : 0xE1)) << 8)  \
+      | (s2 - ((s2 >= 0x7F) ? 0x20 : 0x1F))))
+
+#define JIS_TO_SJIS(c1, c2)                            \
+  ((c1 & 1)                                            \
+   ? (((c1 / 2 + ((c1 < 0x5F) ? 0x71 : 0xB1)) << 8)    \
+      | (c2 + ((c2 >= 0x60) ? 0x20 : 0x1F)))           \
+   : (((c1 / 2 + ((c1 < 0x5F) ? 0x70 : 0xB0)) << 8)    \
+      | (c2 + 0x7E)))
+
+
+static int
+reset_coding_sjis (MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  MCodingSystem *coding = internal->coding;
+
+  if (! coding->ready)
+    {
+      MSymbol kanji_sym = msymbol ("jisx0208.1983");
+      MCharset *kanji = MCHARSET (kanji_sym);
+      MSymbol kana_sym = msymbol ("jisx0201-kana");
+      MCharset *kana = MCHARSET (kana_sym);
+
+      if (! kanji || ! kana)
+       return -1;
+      coding->ncharsets = 3;
+      coding->charsets[1] = kanji;
+      coding->charsets[2] = kana;
+    }
+  coding->ready = 1;
+  return 0;
+}
+
+static int
+decode_coding_sjis (const unsigned char *source, int src_bytes, MText *mt,
+                   MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  MCodingSystem *coding = internal->coding;
+  const unsigned char *src = internal->carryover;
+  const unsigned char *src_stop = src + internal->carryover_bytes;
+  const unsigned char *src_end = source + src_bytes;
+  const unsigned char *src_base;
+  unsigned char *dst = mt->data + mt->nbytes;
+  unsigned char *dst_end = mt->data + mt->allocated - MAX_UTF8_CHAR_BYTES;
+  int nchars = 0;
+  int last_nchars = 0;
+  int at_most = converter->at_most > 0 ? converter->at_most : -1;
+
+  MCharset *charset_roman = coding->charsets[0];
+  MCharset *charset_kanji = coding->charsets[1];
+  MCharset *charset_kana = coding->charsets[2];
+  MCharset *charset = mcharset__ascii;
+  int error = 0;
+
+  while (1)
+    {
+      MCharset *this_charset;
+      int c, c1, c2;
+
+      ONE_MORE_BASE_BYTE (c1);
+
+      c2 = -1;
+      if (c1 < 0x80)
+       {
+         this_charset = ((c1 <= 0x20 || c1 == 0x7F)
+                         ? mcharset__ascii
+                         : charset_roman);
+       }
+      else if ((c1 >= 0x81 && c1 <= 0x9F) || (c1 >= 0xE0 && c1 <= 0xEF))
+       {
+         ONE_MORE_BYTE (c2);
+         if ((c2 >= 0x40 && c2 <= 0x7F) || (c2 >= 80 && c2 <= 0xFC))
+           {
+             this_charset = charset_kanji;
+             c1 = SJIS_TO_JIS (c1, c2);
+           }
+         else
+           goto invalid_byte;
+       }
+      else if (c1 >= 0xA1 && c1 <= 0xDF)
+       {
+         this_charset = charset_kana;
+         c1 &= 0x7F;
+       }
+      else
+       goto invalid_byte;
+
+      c = DECODE_CHAR (this_charset, c1);
+      if (c >= 0)
+       goto emit_char;
+
+    invalid_byte:
+      if (! converter->lenient)
+       break;
+      REWIND_SRC_TO_BASE ();
+      c = *src++;
+      this_charset = mcharset__binary;
+
+    emit_char:
+      if (this_charset != mcharset__ascii
+         && this_charset != charset)
+       {
+         TAKEIN_CHARS (mt, nchars - last_nchars, 
+                       dst - (mt->data + mt->nbytes), charset);
+         charset = this_charset;
+         last_nchars = nchars;
+       }
+      EMIT_CHAR (c);
+    }
+  /* We reach here because of an invalid byte.  */
+  error = 1;
+
+ source_end:
+  TAKEIN_CHARS (mt, nchars - last_nchars,
+               dst - (mt->data + mt->nbytes), charset);
+  return finish_decoding (mt, converter, nchars,
+                         source, src_end, src_base, error);
+}
+
+static int
+encode_coding_sjis (MText *mt, int from, int to,
+                   unsigned char *destination, int dst_bytes,
+                   MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  MCodingSystem *coding = internal->coding;
+  unsigned char *src, *src_end;
+  unsigned char *dst = destination;
+  unsigned char *dst_end = dst + dst_bytes;
+  int nchars = 0;
+  MCharset *charset_roman = coding->charsets[0];
+  MCharset *charset_kanji = coding->charsets[1];
+  MCharset *charset_kana = coding->charsets[2];
+  enum MTextFormat format = mt->format;
+
+  SET_SRC (mt, format, from, to);
+
+  while (1)
+    {
+      int c, bytes, len;
+      unsigned code;
+
+      ONE_MORE_CHAR (c, bytes, format);
+
+      if (c <= 0x20 || c == 0x7F)
+       {
+         CHECK_DST (1);
+         *dst++ = c;
+       }
+      else
+       {
+         if ((code = ENCODE_CHAR (charset_roman, c)) != MCHAR_INVALID_CODE)
+           {
+             CHECK_DST (1);
+             *dst++ = c;
+           }
+         else if ((code = ENCODE_CHAR (charset_kanji, c))
+                  != MCHAR_INVALID_CODE)
+           {
+             int c1 = code >> 8, c2 = code & 0xFF;
+             code = JIS_TO_SJIS (c1, c2);
+             CHECK_DST (2);
+             *dst++ = code >> 8;
+             *dst++ = code & 0xFF;
+           }
+         else if ((code = ENCODE_CHAR (charset_kana, c))
+                  != MCHAR_INVALID_CODE)
+           {
+             CHECK_DST (1);
+             *dst++ = code | 0x80;
+           }
+         else
+           {
+             if (! converter->lenient)
+               break;
+             len = encode_unsupporeted_char (c, dst, dst_end,
+                                             mt, from + nchars);
+             if (len == 0)
+               goto insufficient_destination;
+             dst += len;
+           }
+       }
+      src += bytes;
+      nchars++;
+    }
+  /* We reach here because of an unsupported char.  */
+  converter->result = MCONVERSION_RESULT_INVALID_CHAR;
+  goto finish;
+
+ insufficient_destination:
+  converter->result = MCONVERSION_RESULT_INSUFFICIENT_DST;
+
+ finish:
+  converter->nchars += nchars;
+  converter->nbytes += dst - destination;
+  return (converter->result == MCONVERSION_RESULT_INVALID_CHAR ? -1 : 0);
+}
+
+
+static MCodingSystem *
+find_coding (MSymbol name)
+{
+  MCodingSystem *coding = (MCodingSystem *) msymbol_get (name, Mcoding);
+
+  if (! coding)
+    {
+      MPlist *plist, *pl;
+      MSymbol sym = msymbol__canonicalize (name);
+
+      plist = mplist_find_by_key (coding_definition_list, sym);
+      if (! plist)
+       return NULL;
+      pl = MPLIST_PLIST (plist);
+      name = MPLIST_VAL (pl);
+      mconv_define_coding (MSYMBOL_NAME (name), MPLIST_NEXT (pl),
+                          NULL, NULL, NULL, NULL);
+      coding = (MCodingSystem *) msymbol_get (name, Mcoding);
+      plist = mplist_pop (plist);
+      M17N_OBJECT_UNREF (plist);
+    }
+  return coding;
+}
+
+#define BINDING_NONE 0
+#define BINDING_BUFFER 1
+#define BINDING_STREAM 2
+
+#define CONVERT_WORKSIZE 0x10000
+
+\f
+/* Internal API */
+
+int
+mcoding__init (void)
+{
+  int i;
+  MPlist *param, *charsets, *pl;
+
+  MLIST_INIT1 (&coding_list, codings, 128);
+  coding_definition_list = mplist ();
+
+  /* ISO-2022 specific initialize routine.  */
+  for (i = 0; i < 0x20; i++)
+    iso_2022_code_class[i] = ISO_control_0;
+  for (i = 0x21; i < 0x7F; i++)
+    iso_2022_code_class[i] = ISO_graphic_plane_0;
+  for (i = 0x80; i < 0xA0; i++)
+    iso_2022_code_class[i] = ISO_control_1;
+  for (i = 0xA1; i < 0xFF; i++)
+    iso_2022_code_class[i] = ISO_graphic_plane_1;
+  iso_2022_code_class[0x20] = iso_2022_code_class[0x7F] = ISO_0x20_or_0x7F;
+  iso_2022_code_class[0xA0] = iso_2022_code_class[0xFF] = ISO_0xA0_or_0xFF;
+  iso_2022_code_class[0x0E] = ISO_shift_out;
+  iso_2022_code_class[0x0F] = ISO_shift_in;
+  iso_2022_code_class[0x19] = ISO_single_shift_2_7;
+  iso_2022_code_class[0x1B] = ISO_escape;
+  iso_2022_code_class[0x8E] = ISO_single_shift_2;
+  iso_2022_code_class[0x8F] = ISO_single_shift_3;
+  iso_2022_code_class[0x9B] = ISO_control_sequence_introducer;
+
+  Mcoding = msymbol ("coding");
+
+  Mutf = msymbol ("utf");
+  Miso_2022 = msymbol ("iso-2022");
+
+  Mreset_at_eol = msymbol ("reset-at-eol");
+  Mreset_at_cntl = msymbol ("reset-at-cntl");
+  Meight_bit = msymbol ("eight-bit");
+  Mlong_form = msymbol ("long-form");
+  Mdesignation_g0 = msymbol ("designation-g0");
+  Mdesignation_g1 = msymbol ("designation-g1");
+  Mdesignation_ctext = msymbol ("designation-ctext");
+  Mdesignation_ctext_ext = msymbol ("designation-ctext-ext");
+  Mlocking_shift = msymbol ("locking-shift");
+  Msingle_shift = msymbol ("single-shift");
+  Msingle_shift_7 = msymbol ("single-shift-7");
+  Meuc_tw_shift = msymbol ("euc-tw-shift");
+  Miso_6429 = msymbol ("iso-6429");
+  Mrevision_number = msymbol ("revision-number");
+  Mfull_support = msymbol ("full-support");
+  Mmaybe = msymbol ("maybe");
+
+  Mtype = msymbol ("type");
+  Mcharsets = msymbol_as_managing_key ("charsets");
+  Mflags = msymbol_as_managing_key ("flags");
+  Mdesignation = msymbol_as_managing_key ("designation");
+  Minvocation = msymbol_as_managing_key ("invocation");
+  Mcode_unit = msymbol ("code-unit");
+  Mbom = msymbol ("bom");
+  Mlittle_endian = msymbol ("little-endian");
+
+  param = mplist ();
+  charsets = mplist ();
+  pl = param;
+  /* Setup predefined codings.  */
+  mplist_set (charsets, Msymbol, Mcharset_ascii);
+  pl = mplist_add (pl, Mtype, Mcharset);
+  pl = mplist_add (pl, Mcharsets, charsets);
+  Mcoding_us_ascii = mconv_define_coding ("us-ascii", param,
+                                         NULL, NULL, NULL, NULL);
+
+  {
+    MSymbol alias = msymbol ("ANSI_X3.4-1968");
+    MCodingSystem *coding
+      = (MCodingSystem *) msymbol_get (Mcoding_us_ascii, Mcoding);
+
+    msymbol_put (alias, Mcoding, coding);
+    alias = msymbol__canonicalize (alias);
+    msymbol_put (alias, Mcoding, coding);
+  }
+
+  mplist_set (charsets, Msymbol, Mcharset_iso_8859_1);
+  Mcoding_iso_8859_1 = mconv_define_coding ("iso-8859-1", param,
+                                           NULL, NULL, NULL, NULL);
+
+  mplist_set (charsets, Msymbol, Mcharset_m17n);
+  mplist_put (param, Mtype, Mutf);
+  mplist_put (param, Mcode_unit, (void *) 8);
+  Mcoding_utf_8_full = mconv_define_coding ("utf-8-full", param,
+                                           NULL, NULL, NULL, NULL);
+
+  mplist_set (charsets, Msymbol, Mcharset_unicode);
+  Mcoding_utf_8 = mconv_define_coding ("utf-8", param,
+                                      NULL, NULL, NULL, NULL);
+
+  mplist_put (param, Mcode_unit, (void *) 16);
+  mplist_put (param, Mbom, Mmaybe);
+#ifndef WORDS_BIGENDIAN
+  mplist_put (param, Mlittle_endian, Mt);
+#endif
+  Mcoding_utf_16 = mconv_define_coding ("utf-16", param,
+                                       NULL, NULL, NULL, NULL);
+
+  mplist_put (param, Mcode_unit, (void *) 32);
+  Mcoding_utf_32 = mconv_define_coding ("utf-32", param,
+                                       NULL, NULL, NULL, NULL);
+
+  mplist_put (param, Mcode_unit, (void *) 16);
+  mplist_put (param, Mbom, Mnil);
+  mplist_put (param, Mlittle_endian, Mnil);
+  Mcoding_utf_16be = mconv_define_coding ("utf-16be", param,
+                                         NULL, NULL, NULL, NULL);
+
+  mplist_put (param, Mcode_unit, (void *) 32);
+  Mcoding_utf_32be = mconv_define_coding ("utf-32be", param,
+                                         NULL, NULL, NULL, NULL);
+
+  mplist_put (param, Mcode_unit, (void *) 16);
+  mplist_put (param, Mlittle_endian, Mt);
+  Mcoding_utf_16le = mconv_define_coding ("utf-16le", param,
+                                         NULL, NULL, NULL, NULL);
+
+  mplist_put (param, Mcode_unit, (void *) 32);
+  Mcoding_utf_32le = mconv_define_coding ("utf-32le", param,
+                                         NULL, NULL, NULL, NULL);
+
+  mplist_put (param, Mtype, Mnil);
+  pl = mplist ();
+  mplist_add (pl, Msymbol, msymbol ("Shift_JIS"));
+  mplist_put (param, Maliases, pl);
+  mplist_set (charsets, Msymbol, Mcharset_ascii);
+  Mcoding_sjis = mconv_define_coding ("sjis", param,
+                                     reset_coding_sjis,
+                                     decode_coding_sjis,
+                                     encode_coding_sjis, NULL);
+
+  M17N_OBJECT_UNREF (charsets);
+  M17N_OBJECT_UNREF (param);
+  M17N_OBJECT_UNREF (pl);
+
+  return 0;
+}
+
+void
+mcoding__fini (void)
+{
+  int i;
+  MPlist *plist;
+
+  for (i = 0; i < coding_list.used; i++)
+    {
+      MCodingSystem *coding = coding_list.codings[i];
+
+      if (coding->extra_info)
+       free (coding->extra_info);
+      if (coding->extra_spec)
+       {
+         if (coding->type == Miso_2022)
+           free (((struct iso_2022_spec *) coding->extra_spec)->designations);
+         free (coding->extra_spec);
+       }
+      free (coding);
+    }
+  MLIST_FREE1 (&coding_list, codings);
+  MPLIST_DO (plist, coding_definition_list)
+    M17N_OBJECT_UNREF (MPLIST_VAL (plist));
+  M17N_OBJECT_UNREF (coding_definition_list);
+}
+
+void
+mconv__register_charset_coding (MSymbol sym)
+{
+  MSymbol name = msymbol__canonicalize (sym);
+
+  if (! mplist_find_by_key (coding_definition_list, name))
+    {
+      MPlist *param = mplist (), *charsets = mplist ();
+
+      mplist_set (charsets, Msymbol, sym);
+      mplist_add (param, Msymbol, sym);
+      mplist_add (param, Mtype, Mcharset);
+      mplist_add (param, Mcharsets, charsets);
+      mplist_put (coding_definition_list, name, param);
+      M17N_OBJECT_UNREF (charsets);
+    }
+}
+
+
+int
+mcoding__load_from_database ()
+{
+  MDatabase *mdb = mdatabase_find (msymbol ("coding-list"), Mnil, Mnil, Mnil);
+  MPlist *def_list, *plist;
+  MPlist *definitions = coding_definition_list;
+  int mdebug_flag = MDEBUG_CODING;
+
+  if (! mdb)
+    return 0;
+  MDEBUG_PUSH_TIME ();
+  def_list = (MPlist *) mdatabase_load (mdb);
+  MDEBUG_PRINT_TIME ("CODING", (stderr, " to load the data."));
+  MDEBUG_POP_TIME ();
+  if (! def_list)
+    return -1;
+
+  MDEBUG_PUSH_TIME ();
+  MPLIST_DO (plist, def_list)
+    {
+      MPlist *pl, *aliases;
+      MSymbol name, canonicalized;
+
+      if (! MPLIST_PLIST_P (plist))
+       MERROR (MERROR_CHARSET, -1);
+      pl = MPLIST_PLIST (plist);
+      if (! MPLIST_SYMBOL_P (pl))
+       MERROR (MERROR_CHARSET, -1);
+      name = MPLIST_SYMBOL (pl);
+      canonicalized = msymbol__canonicalize (name);
+      pl = mplist__from_plist (MPLIST_NEXT (pl));
+      mplist_push (pl, Msymbol, name);
+      definitions = mplist_add (definitions, canonicalized, pl);
+      aliases = mplist_get (pl, Maliases);
+      if (aliases)
+       MPLIST_DO (aliases, aliases)
+         if (MPLIST_SYMBOL_P (aliases))
+           {
+             name = MPLIST_SYMBOL (aliases);
+             canonicalized = msymbol__canonicalize (name);
+             definitions = mplist_add (definitions, canonicalized, pl);
+             M17N_OBJECT_REF (pl);
+           }
+    }
+
+  M17N_OBJECT_UNREF (def_list);
+  MDEBUG_PRINT_TIME ("CODING", (stderr, " to parse the loaded data."));
+  MDEBUG_POP_TIME ();
+  return 0;
+}
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+\f
+/* External API */
+
+/*** @addtogroup m17nConv */
+/*** @{ */
+/*=*/
+
+/***en @name Variables: Symbols representing coding systems */
+/***ja @name ÊÑ¿ô: ÄêµÁºÑ¤ß¥³¡¼¥É·Ï¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥·¥ó¥Ü¥ë */
+/*** @{ */
+/*=*/
+
+/***en
+    @brief Symbol for the coding system US-ASCII.
+
+    The symbol #Mcoding_us_ascii has name <tt>"us-ascii"</tt> and
+    represents a coding system for the CES US-ASCII.  */
+
+/***ja
+    @brief US-ASCII ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcoding_us_ascii ¤Ï <tt>"us-ascii"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
+    CES US-ASCII ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£
+    */
+MSymbol Mcoding_us_ascii;
+/*=*/
+
+/***en
+    @brief Symbol for the coding system ISO-8859-1.
+
+    The symbol #Mcoding_iso_8859_1 has name <tt>"iso-8859-1"</tt> and
+    represents a coding system for the CES ISO-8859-1.  */
+
+/***ja
+    @brief ISO-8859-1 ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcoding_iso_8859_1 ¤Ï <tt>"iso-8859-1"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢CES ISO-8859-1 ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£  */
+
+MSymbol Mcoding_iso_8859_1;
+/*=*/
+
+/***en
+    @brief Symbol for the coding system UTF-8.
+
+    The symbol #Mcoding_utf_8 has name <tt>"utf-8"</tt> and represents
+    a coding system for the CES UTF-8.  */
+
+/***ja
+    @brief UTF-8 ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcoding_utf_8 ¤Ï <tt>"utf-8"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢CES
+    UTF-8 ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£
+     */
+
+MSymbol Mcoding_utf_8;
+/*=*/
+
+/***en
+    @brief Symbol for the coding system UTF-8-FULL.
+
+    The symbol #Mcoding_utf_8_full has name <tt>"utf-8-full"</tt> and
+    represents a coding system that is a extension of UTF-8.  This
+    coding system uses the same encoding algorithm as UTF-8 but is not
+    limited to the Unicode characters.  It can encode all characters
+    supported by the m17n library.  */
+
+/***ja
+    @brief UTF-8-FULL ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcoding_utf_8_full ¤Ï <tt>"utf-8-full"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢<tt>"UTF-8"</tt> ¤Î³ÈÄ¥¤Ç¤¢¤ë¥³¡¼¥É·Ï¤ò¼¨¤¹¡£
+    ¤³¤Î¥³¡¼¥É·Ï¤Ï UTF-8 ¤ÈƱ¤¸¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¥¢¥ë¥´¥ê¥º¥à¤òÍѤ¤¤ë¤¬¡¢ÂоݤÏ
+    Unicode Ê¸»ú¤Ë¤Ï¸ÂÄꤵ¤ì¤Ê¤¤¡£
+    ¤Þ¤¿m17n ¥é¥¤¥Ö¥é¥ê¤¬°·¤¦Á´¤Æ¤Îʸ»ú¤ò¥¨¥ó¥³¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
+    */
+
+MSymbol Mcoding_utf_8_full;
+/*=*/
+
+/***en
+    @brief Symbol for the coding system UTF-16.
+
+    The symbol #Mcoding_utf_16 has name <tt>"utf-16"</tt> and
+    represents a coding system for the CES UTF-16 (RFC 2279).  */
+/***ja
+    @brief UTF-16 ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcoding_utf_16 ¤Ï <tt>"utf-16"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
+    CES UTF-16 (RFC 2279) ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£
+     */
+
+MSymbol Mcoding_utf_16;
+/*=*/
+
+/***en
+    @brief Symbol for the coding system UTF-16BE.
+
+    The symbol #Mcoding_utf_16be has name <tt>"utf-16be"</tt> and
+    represents a coding system for the CES UTF-16BE (RFC 2279).  */
+
+/***ja
+    @brief UTF-16BE ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcoding_utf_16be ¤Ï <tt>"utf-16be"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
+    CES UTF-16BE (RFC 2279) ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£     */
+
+MSymbol Mcoding_utf_16be;
+/*=*/
+
+/***en
+    @brief Symbol for the coding system UTF-16LE.
+
+    The symbol #Mcoding_utf_16le has name <tt>"utf-16le"</tt> and
+    represents a coding system for the CES UTF-16LE (RFC 2279).  */
+
+/***ja
+    @brief UTF-16LE ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcoding_utf_16le ¤Ï <tt>"utf-16le"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
+    CES UTF-16LE (RFC 2279) ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£     */
+
+MSymbol Mcoding_utf_16le;
+/*=*/
+
+/***en
+    @brief Symbol for the coding system UTF-32.
+
+    The symbol #Mcoding_utf_32 has name <tt>"utf-32"</tt> and
+    represents a coding system for the CES UTF-32 (RFC 2279).  */
+
+/***ja
+    @brief UTF-32 ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcoding_utf_32 ¤Ï <tt>"utf-32"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
+    CES UTF-32 (RFC 2279) ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£     */
+
+MSymbol Mcoding_utf_32;
+/*=*/
+
+/***en
+    @brief Symbol for the coding system UTF-32BE.
+
+    The symbol #Mcoding_utf_32be has name <tt>"utf-32be"</tt> and
+    represents a coding system for the CES UTF-32BE (RFC 2279).  */
+/***ja
+    @brief UTF-32BE ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcoding_utf_32be ¤Ï <tt>"utf-32be"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
+    CES UTF-32BE (RFC 2279) ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£     */
+
+MSymbol Mcoding_utf_32be;
+/*=*/
+
+/***en
+    @brief Symbol for the coding system UTF-32LE.
+
+    The symbol #Mcoding_utf_32le has name <tt>"utf-32le"</tt> and
+    represents a coding system for the CES UTF-32LE (RFC 2279).  */
+/***ja
+    @brief UTF-32LE ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcoding_utf_32le ¤Ï <tt>"utf-32le"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
+    CES UTF-32LE (RFC 2279) ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£     */
+
+MSymbol Mcoding_utf_32le;
+/*=*/
+
+/***en
+    @brief Symbol for the coding system SJIS.
+
+    The symbol #Mcoding_sjis has name <tt>"sjis"</tt> and represents a coding
+    system for the CES Shift-JIS.  */ 
+/***ja
+    @brief SJIS ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mcoding_sjis has ¤Ï <tt>"sjis"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
+    CES Shift-JISÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£  */ 
+
+MSymbol Mcoding_sjis;
+/*** @} */ 
+/*=*/
+
+/***en
+    @name Variables: Parameter keys for mconv_define_coding ().  */
+/***ja
+    @name ÊÑ¿ô:  mconv_define_coding () Íѥѥé¥á¡¼¥¿¥­¡¼  */
+/*** @{ */
+/*=*/
+
+/***en
+    Parameter key for mconv_define_coding () (which see). */ 
+/***ja
+    mconv_define_coding () Íѥѥé¥á¡¼¥¿¥­¡¼ (¾ÜºÙ¤Ï mconv_define_coding ()»²¾È). */ 
+MSymbol Mtype;
+MSymbol Mcharsets;
+MSymbol Mflags;
+MSymbol Mdesignation;
+MSymbol Minvocation;
+MSymbol Mcode_unit;
+MSymbol Mbom;
+MSymbol Mlittle_endian;
+/*** @} */
+/*=*/
+
+/***en
+    @name Variables: Symbols representing coding system types.  */
+/***ja
+    @name ÊÑ¿ô¡§ ¥³¡¼¥É·Ï¤Î¥¿¥¤¥×¤ò¼¨¤¹¥·¥ó¥Ü¥ë.  */
+/*** @{ */
+/*=*/
+
+/***en
+    Symbol that can be a value of the #Mtype parameter of a coding
+    system used in an argument to the mconv_define_coding () function
+    (which see).  */
+/***ja 
+    ´Ø¿ô mconv_define_coding () ¤Î°ú¿ô¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¥³¡¼¥É·Ï¤Î¥Ñ¥é¥á¡¼¥¿
+    #Mtype ¤ÎÃͤȤʤêÆÀ¤ë¥·¥ó¥Ü¥ë¡£(¾ÜºÙ¤Ï 
+    mconv_define_coding ()»²¾È)¡£  */
+MSymbol Mutf;
+/*=*/
+MSymbol Miso_2022;
+/*=*/
+/*** @} */
+/*=*/
+
+/***en
+    @name Variables: Symbols appearing in the value of Mflags parameter.  */
+/***ja
+    @name ÊÑ¿ô¡§ ¥Ñ¥é¥á¡¼¥¿ Mflags ¤ÎÃͤȤʤêÆÀ¤ë¥·¥ó¥Ü¥ë.  */
+/*** @{ */
+/***en
+    Symbols that can be a value of the @b Mflags parameter of a coding
+    system used in an argument to the mconv_define_coding () function
+    (which see).  */
+/***ja 
+    ´Ø¿ô mconv_define_coding () ¤Î°ú¿ô¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¥³¡¼¥É·Ï¤Î¥Ñ¥é¥á¡¼¥¿
+    @b Mflags ¤ÎÃͤȤʤêÆÀ¤ë¥·¥ó¥Ü¥ë¡£(¾ÜºÙ¤Ï 
+    mconv_define_coding ()»²¾È)¡£  */
+MSymbol Mreset_at_eol;
+MSymbol Mreset_at_cntl;
+MSymbol Meight_bit;
+MSymbol Mlong_form;
+MSymbol Mdesignation_g0;
+MSymbol Mdesignation_g1;
+MSymbol Mdesignation_ctext;
+MSymbol Mdesignation_ctext_ext;
+MSymbol Mlocking_shift;
+MSymbol Msingle_shift;
+MSymbol Msingle_shift_7;
+MSymbol Meuc_tw_shift;
+MSymbol Miso_6429;
+MSymbol Mrevision_number;
+MSymbol Mfull_support;
+/*** @} */
+/*=*/
+
+/***en
+    @name Variables: Others
+
+    Remaining variables.  */
+/***ja @name ÊÑ¿ô: ¤½¤Î¾ 
+
+    ¤Û¤«¤ÎÊÑ¿ô¡£ */
+/*** @{ */
+/*=*/
+/***en
+    @brief Symbol whose name is "maybe".
+
+    The variable #Mmaybe is a symbol of name <tt>"maybe"</tt>.  It is
+    used a value of @b Mbom parameter of the function
+    mconv_define_coding () (which see).  */
+/***ja
+    @brief "maybe"¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë.
+
+    ÊÑ¿ô #Mmaybe ¤Ï <tt>"maybe"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¡£¤³¤ì¤Ï´Ø¿ô 
+    mconv_define_coding () ¥Ñ¥é¥á¡¼¥¿ @b Mbom ¤ÎÃͤȤ·¤ÆÍѤ¤¤é¤ì¤ë¡£
+    (¾ÜºÙ¤Ï mconv_define_coding () »²¾È)¡£ */
+
+MSymbol Mmaybe;
+/*=*/
+
+/***en
+    @brief The symbol @c Mcoding.
+
+    Any decoded M-text has a text property whose key is the predefined
+    symbol @c Mcoding.  The name of @c Mcoding is
+    <tt>"coding"</tt>.  */
+
+/***ja
+    @brief ¥·¥ó¥Ü¥ë @c Mcoding.
+
+    ¥Ç¥³¡¼¥É¤µ¤ì¤¿ M-text ¤Ï¤¹¤Ù¤Æ¡¢¥­¡¼¤¬ÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë @c Mcoding 
+    ¤Ç¤¢¤ë¤è¤¦¤Ê¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¡£¥·¥ó¥Ü¥ë @c Mcoding ¤Ï 
+    <tt>"coding"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¡£  */
+
+MSymbol Mcoding;
+/*=*/
+/*** @} */ 
+/*=*/
+
+/***en
+    @brief Define a coding system.
+
+    The mconv_define_coding () function defines a new coding system
+    and makes it accessible via a symbol whose name is $NAME.  $PLIST
+    specifies parameters of the coding system as below:
+
+    <ul>
+
+    <li> Key is @c Mtype, value is a symbol
+
+    The value specifies the type of the coding system.  It must be
+    @b Mcharset, @b Mutf, @b Miso_2022, or @b Mnil.
+
+    If the type is @b Mcharset, $EXTRA_INFO is ignored.
+
+    If the type is @b Mutf, $EXTRA_INFO must be a pointer to
+    #MCodingInfoUTF.
+
+    If the type is @b Miso_2022, $EXTRA_INFO must be a pointer to
+    #MCodingInfoISO2022.
+
+    If the type is #Mnil, the argument $RESETTER, $DECODER, and
+    $ENCODER must be supplied.  $EXTRA_INFO is ignored.  Otherwise,
+    they can be @c NULL and the m17n library provides proper defaults.
+
+    <li> Key is @b Mcharsets, value is a plist
+
+    The value specifies a list charsets supported by the coding
+    system.  The keys of the plist must be #Msymbol, and the values
+    must be symbols representing charsets.
+
+    <li> Key is @b Mflags, value is a plist
+
+    If the type is @b Miso_2022, the values specifies flags to control
+    the ISO 2022 interpreter.  The keys of the plist must e #Msymbol,
+    and values must be one of the following.
+
+    <ul>
+
+    <li> @b Mreset_at_eol
+
+    If this flag exists, designation and invocation status is reset to
+    the initial state at the end of line.
+
+    <li> @b Mreset_at_cntl
+
+    If this flag exists, designation and invocation status is reset to
+    the initial state at a control character.
+
+    <li> @b Meight_bit
+
+    If this flag exists, the graphic plane right is used.
+
+    <li> @b Mlong_form
+
+    If this flag exists, the over-long escape sequences (ESC '$' '('
+    \<final_byte\>) are used for designating the CCS JISX0208.1978,
+    GB2312, and JISX0208.
+
+    <li> @b Mdesignation_g0
+
+    If this flag and @b Mfull_support exists, designates charsets not
+    listed in the charset list to the graphic register G0.
+
+    <li> @b Mdesignation_g1
+
+    If this flag and @b Mfull_support exists, designates charsets not
+    listed in the charset list to the graphic register G1.
+
+    <li> @b Mdesignation_ctext
+
+    If this flag and @b Mfull_support exists, designates charsets not
+    listed in the charset list to a graphic register G0 or G1 based on
+    the criteria of the Compound Text.
+
+    <li> @b Mdesignation_ctext_ext
+
+    If this flag and @b Mfull_support exists, designates charsets not
+    listed in the charset list to a graphic register G0 or G1, or use
+    extended segment for such charsets based on the criteria of the
+    Compound Text.
+
+    <li> @b Mlocking_shift
+
+    If this flag exists, use locking shift.
+
+    <li> @b Msingle_shift
+
+    If this flag exists, use single shift.
+
+    <li> @b Msingle_shift_7
+
+    If this flag exists, use 7-bit single shift code (0x19).
+
+    <li> @b Meuc_tw_shift
+
+    If this flag exists, use a special shifting according to EUC-TW.
+
+    <li> @b Miso_6429
+
+    This flag is currently ignored.
+
+    <li> @b Mrevision_number
+
+    If this flag exists, use a revision number escape sequence to
+    designate a charset that has a revision number.
+
+    <li> @b Mfull_support
+
+    If this flag exists, support all charsets registered in the
+    International Registry.
+
+    </ul>
+
+    <li> Key is @b Mdesignation, value is a plist
+
+    If the type is @b Miso_2022, the value specifies how to designate
+    each supported characters.  The keys of the plist must be 
+    #Minteger, and the values must be numbers indicating a graphic
+    registers.  The Nth element value is for the Nth charset of the
+    charset list.  The value 0..3 means that it is assumed that a
+    charset is already designated to the graphic register 0..3.  The
+    negative value G (-4..-1) means that a charset is not designated
+    to any register at first, and if necessary, is designated to the
+    (G+4) graphic register.
+
+    <li> Key is @b Minvocation, value is a plist
+
+    If the type is @b Miso_2022, the value specifies how to invocate
+    each graphic registers.  The plist length must be one or two.  The
+    keys of the plist must be #Minteger, and the values must be
+    numbers indicating a graphic register.  The value of the first
+    element specifies which graphic register is invocated to the
+    graphic plane left.  If the length is one, no graphic register is
+    invocated to the graphic plane right.  Otherwise, the value of the
+    second element specifies which graphic register is invocated to
+    the graphic plane right.
+
+    <li> Key is @b Mcode_unit, value is an integer
+
+    If the type is @b Mutf, the value specifies the bit length of a
+    code-unit.  It must be 8, 16, or 32.
+
+    <li> Key is @b Mbom, value is a symbol
+
+    If the type is @b Mutf and the code-unit bit length is 16 or 32,
+    it specifies whether or not to use BOM (Byte Order Mark).  If the
+    value is #Mnil (default), BOM is not used, else if the value is
+    #Mmaybe, the existence of BOM is detected at decoding time, else
+    BOM is used.
+
+    <li> Key is @b Mlittle_endian, value is a symbol
+
+    If the type is @b Mutf and the code-unit bit length is 16 or 32,
+    it specifies whether or not the encoding is little endian.  If the
+    value is #Mnil (default), it is big endian, else it is little
+    endian.
+
+    </ul>
+
+    $RESETTER is a pointer to a function that resets a converter for
+    the coding system to the initial status.  The pointed function is
+    called with one argument, a pointer to a converter object.
+
+    $DECODER is a pointer to a function that decodes a byte sequence
+    according to the coding system.  The pointed function is called
+    with four arguments:
+
+       @li A pointer to the byte sequence to decode.
+       @li The number of bytes to decode.
+       @li A pointer to an M-text to which the decoded characters are appended.
+       @li A pointer to a converter object.
+
+    $DECODER must return 0 if it succeeds.  Otherwise it must return -1.
+
+    $ENCODER is a pointer to a function that encodes an M-text
+    according to the coding system.  The pointed function is called
+    with six arguments:
+
+       @li A pointer to the M-text to encode.
+       @li The starting position of the encoding.
+       @li The ending position of the encoding.
+       @li A pointer to a memory area where the produced bytes are stored.
+       @li The size of the memory area.
+       @li A pointer to a converter object.
+
+    $ENCODER must return 0 if it succeeds.  Otherwise it must return -1.
+
+    $EXTRA_INFO is a pointer to a data structure that contains extra
+    information about the coding system.  The type of the data
+    structure depends on $TYPE.
+
+    @return  
+
+    If the operation was successful, mconv_define_coding () returns a
+    symbol whose name is $NAME.  If an error is detected, it returns
+    #Mnil and assigns an error code to the external variable #merror_code.  */
+
+/***ja
+    @brief ¥³¡¼¥É·Ï¤òÄêµÁ¤¹¤ë.
+
+    ´Ø¿ô mconv_define_coding () ¤Ï¡¢¿·¤·¤¤¥³¡¼¥É·Ï¤òÄêµÁ¤·¡¢¤½¤ì¤ò 
+    $NAME ¤È¤¤¤¦Ì¾Á°¤Î¥·¥ó¥Ü¥ë·Ðͳ¤Ç¥¢¥¯¥»¥¹¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë¡£ $PLIST 
+    ¤Ç¤ÏÄêµÁ¤¹¤ë¥³¡¼¥É·Ï¤Î¥Ñ¥é¥á¡¼¥¿¤ò°Ê²¼¤Î¤è¤¦¤Ë»ØÄꤹ¤ë¡£
+
+    <ul>
+
+    <li> ¥­¡¼¤¬ @c Mtype ¤ÇÃͤ¬¥·¥ó¥Ü¥ë¤Î»þ
+
+    Ãͤϥ³¡¼¥É·Ï¤Î¥¿¥¤¥×¤òɽ¤·¡¢@b Mcharset, @b Mutf, @b Miso_2022, #Mnil 
+    ¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    ¥¿¥¤¥×¤¬ @b Mcharset ¤Ê¤é¤Ð $EXTRA_INFO ¤Ï̵»ë¤µ¤ì¤ë¡£
+
+    ¥¿¥¤¥×¤¬ @b Mutf ¤Ê¤é¤Ð $EXTRA_INFO ¤Ï #MCodingInfoUTF 
+    ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    ¥¿¥¤¥×¤¬ @b Miso_2022¤Ê¤é¤Ð $EXTRA_INFO ¤Ï #MCodingInfoISO2022 
+    ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    ¥¿¥¤¥×¤¬ #Mnil ¤Ê¤é¤Ð¡¢°ú¿ô $RESETTER, $DECODER, $ENCODER 
+    ¤òÍ¿¤¨¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£$EXTRA_INFO ¤Ï̵»ë¤µ¤ì¤ë¡£
+    ¤½¤ì°Ê³°¤Î¾ì¹ç¤Ë¤Ï¤³¤ì¤é¤Ï @c NULL ¤Ç¤è¤¯¡¢
+    m17n ¥é¥¤¥Ö¥é¥ê¤¬Å¬Àڤʥǥե©¥ë¥ÈÃͤòÍ¿¤¨¤ë¡£
+
+    <li> ¥­¡¼¤¬ @b Mcharsets ¤ÇÃͤ¬ plist ¤Î»þ
+
+    ÃͤϤ³¤Î¥³¡¼¥É·Ï¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤ëʸ»ú¥»¥Ã¥È¤Î¥ê¥¹¥È¤Ç¤¢¤ë¡£plist¤Î¥­¡¼¤Ï
+    #Msymbol¡¢ÃͤÏʸ»ú¥»¥Ã¥È¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    <li> ¥­¡¼¤¬ @b Mflags Ãͤ¬ plist ¤Î»þ
+
+    ¥¿¥¤¥×¤¬ @b Miso_2022 ¤Ê¤é¤Ð¡¢¤³¤ÎÃͤÏ, ISO 2022 
+    ¥¤¥ó¥¿¥×¥ê¥¿ÍѤÎÀ©¸æ¥Õ¥é¥Ã¥°¤ò¼¨¤¹¡£plist ¤Î¥­¡¼¤Ï #Msymbol 
+    ¤Ç¤¢¤ê¡¢Ãͤϰʲ¼¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£
+
+    <ul>
+
+    <li> @b Mreset_at_eol
+
+    ¤³¤Î¥Õ¥é¥°¤¬¤¢¤ì¤Ð¡¢¿Þ·Áʸ»ú½¸¹ç¤Î»Ø¼¨¤ä¸Æ½Ð¤Ï¹ÔËö¤Ç¥ê¥»¥Ã¥È¤µ¤ì¤ÆÅö½é¤Î¾õÂÖ¤ËÌá¤ë¡£
+
+    <li> @b Mreset_at_cntl
+
+    ¤³¤Î¥Õ¥é¥°¤¬¤¢¤ì¤Ð¡¢¿Þ·Áʸ»ú½¸¹ç¤Î»Ø¼¨¤ä¸Æ½Ð¤ÏÀ©¸æʸ»ú¤Ë½Ð²ñ¤Ã¤¿»þÅÀ¤Ç¥ê¥»¥Ã¥È¤µ¤ì¤ÆÅö½é¤Î¾õÂÖ¤ËÌá¤ë¡£
+
+    <li> @b Meight_bit
+
+    ¤³¤Î¥Õ¥é¥°¤¬¤¢¤ì¤Ð¡¢¿Þ·Áʸ»ú½¸¹ç¤Î±¦È¾Ì̤¬ÍѤ¤¤é¤ì¤ë¡£
+
+    <li> @b Mlong_form
+
+    ¤³¤Î¥Õ¥é¥°¤¬¤¢¤ì¤Ð¡¢Ê¸»ú½¸¹ç JISX0208.1978, GB2312, JISX0208 
+    ¤ò»Ø¼¨¤¹¤ëºÝ¤Ë over-long ¥¨¥¹¥±¡¼¥×¥·¡¼¥±¥ó¥¹ (ESC '$' '('
+    \<final_byte\>) ¤¬ÍѤ¤¤é¤ì¤ë¡£
+
+    <li> @b Mdesignation_g0
+
+    ¤³¤Î¥Õ¥é¥°¤È @b Mfull_support ¤¬¤¢¤ì¤Ð¡¢Ê¸»ú¥»¥Ã¥È¥ê¥¹¥È¤Ë¸½¤ï¤ì¤Ê¤¤Ê¸»ú¥»¥Ã¥È¤ò
+    G0 ½¸¹ç¤Ë»Ø¼¨¤¹¤ë¡£
+
+    <li> @b Mdesignation_g1
+
+    ¤³¤Î¥Õ¥é¥°¤È @b Mfull_support ¤¬¤¢¤ì¤Ð¡¢Ê¸»ú¥»¥Ã¥È¥ê¥¹¥È¤Ë¸½¤ï¤ì¤Ê¤¤Ê¸»ú¥»¥Ã¥È¤ò
+    G1 ½¸¹ç¤Ë»Ø¼¨¤¹¤ë¡£
+
+    <li> @b Mdesignation_ctext
+
+    ¤³¤Î¥Õ¥é¥°¤È @b Mfull_support ¤¬¤¢¤ì¤Ð¡¢Ê¸»ú¥»¥Ã¥È¥ê¥¹¥È¤Ë¸½¤ï¤ì¤Ê¤¤Ê¸»ú¥»¥Ã¥È¤ò
+    G0 ½¸¹ç¤Þ¤¿¤Ï G1 ½¸¹ç¤Ë¡¢¥³¥ó¥Ñ¥¦¥ó¥É¥Æ¥­¥¹¥È¤Î´ð½à¤Ë¤½¤Ã¤Æ»Ø¼¨¤¹¤ë¡£
+
+    <li> @b Mdesignation_ctext_ext
+
+    ¤³¤Î¥Õ¥é¥°¤È @b Mfull_support ¤¬¤¢¤ì¤Ð¡¢Ê¸»ú¥»¥Ã¥È¥ê¥¹¥È¤Ë¸½¤ï¤ì¤Ê¤¤Ê¸»ú¥»¥Ã¥È¤ò
+    G0 ½¸¹ç¤Þ¤¿¤Ï G1 ½¸¹ç¤Ë¡¢¤¢¤ë¤¤¤Ï³ÈÄ¥¥»¥°¥á¥ó¥È¤Ë¥³¥ó¥Ñ¥¦¥ó¥É¥Æ¥­¥¹¥È¤Î´ð½à¤Ë¤½¤Ã¤Æ»Ø¼¨¤¹¤ë¡£
+
+    <li> @b Mlocking_shift
+
+    ¤³¤Î¥Õ¥é¥°¤¬¤¢¤ì¤Ð¡¢¥í¥Ã¥­¥ó¥°¥·¥Õ¥È¤òÍѤ¤¤ë¡£
+
+    <li> @b Msingle_shift
+
+    ¤³¤Î¥Õ¥é¥°¤¬¤¢¤ì¤Ð¡¢¥·¥ó¥°¥ë¥·¥Õ¥È¤òÍѤ¤¤ë¡£
+
+    <li> @b Msingle_shift_7
+
+    ¤³¤Î¥Õ¥é¥°¤¬¤¢¤ì¤Ð¡¢7-bit ¥·¥ó¥°¥ë¥·¥Õ¥È¥³¡¼¥É (0x19) ¤òÍѤ¤¤ë¡£   
+    
+    <li> @b Meuc_tw_shift
+
+    ¤³¤Î¥Õ¥é¥°¤¬¤¢¤ì¤Ð¡¢EUC-TW ¤Ë±è¤Ã¤¿ÆÃÊ̤ʥ·¥Õ¥È¤òÍѤ¤¤ë¡£
+
+    <li> @b Miso_6429
+
+    ¸½»þÅÀ¤Ç¤ÏÍѤ¤¤é¤ì¤Æ¤¤¤Ê¤¤¡£
+
+    <li> @b Mrevision_number
+
+    ¤³¤Î¥Õ¥é¥°¤¬¤¢¤ì¤Ð¡¢revision number ¤ò»ý¤Äʸ»ú¥»¥Ã¥È¤ò»Ø¼¨¤¹¤ëºÝ¤Ë 
+    revision number ¥¨¥¹¥±¡¼¥×¥·¡¼¥¯¥¨¥ó¥¹¤òÍѤ¤¤ë¡£
+
+    <li> @b Mfull_support
+
+    ¤³¤Î¥Õ¥é¥°¤¬¤¢¤ì¤Ð¡¢the International Registry 
+    ¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤ëÁ´Ê¸»ú¥»¥Ã¥È¤ò¥µ¥Ý¡¼¥È¤¹¤ë¡£
+
+    </ul>
+
+    <li> ¥­¡¼¤¬ @b Mdesignation ¤ÇÃͤ¬ plist ¤Î»þ
+
+    ¥¿¥¤¥×¤¬ @b Miso_2022 ¤Ê¤é¤Ð¡¢ÃͤϳÆʸ»ú¤ò¤É¤Î¤è¤¦¤Ë»Ø¼¨¤¹¤ë¤«¤ò¼¨¤¹¡£
+    plist ¤Î¥­¡¼¤Ï #Minteger¡¢ÃͤϽ¸¹ç¡Êgraphic register¡Ë
+    ¤ò¼¨¤¹¿ô»ú¤Ç¤¢¤ë¡£NÈÖÌܤÎÍ×ÁǤÎÃͤϡ¢Ê¸»ú¥»¥Ã¥È¥ê¥¹¥È¤Î N 
+    ÈÖÌܤÎʸ»ú¥»¥Ã¥È¤ËÂбþ¤¹¤ë¡£Ãͤ¬ 0..3 ¤Ç¤¢¤ì¤Ð¡¢Ê¸»ú¥»¥Ã¥È¤¬¤¹¤Ç¤Ë 
+    G0..G3 ¤Ë»Ø¼¨ ¤µ¤ì¤Æ¤¤¤ë¡£
+
+    Ãͤ¬Éé(-4..-1) ¤Ç¤¢¤ì¤Ð¡¢½é´ü¾õÂ֤ǤÏʸ»ú¥»¥Ã¥È¤¬¤É¤³¤Ë¤â»Ø¼¨¤µ¤ì¤Æ¤¤¤Ê¤¤¤³¤È¡¢É¬ÍפʺݤˤÏ
+    G0..G3 ¤Î¤½¤ì¤¾¤ì¤Ë»Ø¼¨¤¹¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
+
+    <li> ¥­¡¼¤¬ @b Minvocation ¤ÇÃͤ¬ plist ¤Î»þ
+
+    ¥¿¥¤¥×¤¬ @b Miso_2022 ¤Ê¤é¤Ð¡¢Ãͤϳƽ¸¹ç¤ò¤É¤Î¤è¤¦¤Ë¸Æ¤Ó½Ð¤¹¤«¤ò¼¨¤¹¡£
+    plist ¤ÎŤµ¤Ï 1 ¤Ê¤¤¤· 2 ¤Ç¤¢¤ë¡£plist ¤Î¥­¡¼¤Ï 
+    #Minteger¡¢ÃͤϽ¸¹ç¡Êgraphic register)¤ò¼¨¤¹¿ô»ú¤Ç¤¢¤ë¡£
+    ºÇ½é¤ÎÍ×ÁǤÎÃͤ¬¿Þ·Áʸ»ú½¸¹çº¸È¾Ì̤˸ƤӽФµ¤ì¤ë½¸¹ç¤ò¼¨¤¹¡£
+    plist ¤ÎŤµ¤¬ 1 ¤Ê¤é¤Ð¡¢±¦È¾Ì̤ˤϲ¿¤â¸Æ¤Ó½Ð¤µ¤ì¤Ê¤¤¡£
+    ¤½¤¦¤Ç¤±¤ì¤Ð¡¢£²¤Ä¤á¤ÎÍ×ÁǤÎÃͤ¬¿Þ·Áʸ»ú½¸¹ç±¦È¾Ì̤˸ƤӽФµ¤ì¤ë½¸¹ç¤ò¼¨¤¹¡£
+
+    <li> ¥­¡¼¤¬ @b Mcode_unit ¤ÇÃͤ¬À°¿ôÃͤλþ
+
+    ¥¿¥¤¥×¤¬ @b Mutf ¤Ê¤é¤Ð¡¢Ãͤϥ³¡¼¥É¥æ¥Ë¥Ã¥È¤Î¥Ó¥Ã¥ÈŤǤ¢¤ê¡¢8, 16,
+    32 ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£
+
+    <li> ¥­¡¼¤¬ @b Mbom ¤ÇÃͤ¬¥·¥ó¥Ü¥ë¤Î»þ
+
+    ¥¿¥¤¥×¤¬ @b Mutf ¤Ç¥³¡¼¥É¥æ¥Ë¥Ã¥È¤Î¥Ó¥Ã¥ÈŤ¬ 16 ¤« 32¤Ê¤é¤Ð¡¢ÃͤÏ
+    BOM (Byte Order Mark) ¤ò»ÈÍѤ¹¤ë¤«¤É¤¦¤«¤ò¼¨¤¹¡£Ãͤ¬¥Ç¥Õ¥©¥ë¥ÈÃͤΠ
+    #Mnil ¤Ê¤é¤Ð¡¢»ÈÍѤ·¤Ê¤¤¡£Ãͤ¬ #Mmaybe ¤Ê¤é¤Ð¥Ç¥³¡¼¥É»þ¤Ë BOM 
+    ¤¬¤¢¤ë¤«¤É¤¦¤«¤òÄ´¤Ù¤ë¡£¤½¤ì°Ê³°¤Ê¤é¤Ð»ÈÍѤ¹¤ë¡£
+
+    <li> ¥­¡¼¤¬ @b Mlittle_endian ¤ÇÃͤ¬¥·¥ó¥Ü¥ë¤Î»þ 
+
+    ¥¿¥¤¥×¤¬ @b Mutf ¤Ç¥³¡¼¥É¥æ¥Ë¥Ã¥È¤Î¥Ó¥Ã¥ÈŤ¬ 16 ¤« 32
+    ¤Ê¤é¤Ð¡¢Ãͤϥ¨¥ó¥³¡¼¥É¤¬ little endian ¤«¤É¤¦¤«¤ò¼¨¤¹¡£Ãͤ¬¥Ç¥Õ¥©¥ë¥ÈÃͤÎ
+    #Mnil ¤Ê¤é¤Ð big endian ¤Ç¤¢¤ê¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð little endian ¤Ç¤¢¤ë¡£
+
+    </ul>
+
+    $RESETTER 
+    ¤Ï¤³¤Î¥³¡¼¥É·ÏÍѤΥ³¥ó¥Ð¡¼¥¿¤ò½é´ü¾õÂ֤˥ꥻ¥Ã¥È¤¹¤ë´Ø¿ô¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    ¤³¤Î´Ø¿ô¤Ï¥³¥ó¥Ð¡¼¥¿¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤È¤¤¤¦£±°ú¿ô¤ò¤È¤ë¡£
+
+    $DECODER ¤Ï¥Ð¥¤¥ÈÎó¤ò¤³¤Î¥³¡¼¥É·Ï¤Ë½¾¤Ã¤Æ¥Ç¥³¡¼¥É¤¹¤ë´Ø¿ô¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    ¤³¤Î´Ø¿ô¤Ï°Ê²¼¤Î£´°ú¿ô¤ò¤È¤ë¡£
+
+       @li ¥Ç¥³¡¼¥É¤¹¤ë¥Ð¥¤¥ÈÎó¤Ø¤Î¥Ý¥¤¥ó¥¿
+       @li ¥Ç¥³¡¼¥É¤¹¤Ù¤­¥Ð¥¤¥È¿ô
+       @li ¥Ç¥³¡¼¥É·ë²Ì¤Îʸ»ú¤òÉղ乤ë M-text ¤Ø¤Î¥Ý¥¤¥ó¥¿
+       @li ¥³¥ó¥Ð¡¼¥¿¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿
+
+    $DECODER ¤ÏÀ®¸ù¤·¤¿¤È¤­¤Ë¤Ï 0 ¤ò¡¢¼ºÇÔ¤·¤¿¤È¤­¤Ë¤Ï -1 
+    ¤òÊÖ¤µ¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    $ENCODER ¤Ï M-text ¤ò¤³¤Î¥³¡¼¥É·Ï¤Ë½¾¤Ã¤Æ¥¨¥ó¥³¡¼¥É¤¹¤ë´Ø¿ô¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    ¤³¤Î´Ø¿ô¤Ï°Ê²¼¤Î£¶°ú¿ô¤ò¤È¤ë¡£
+
+        @li ¥¨¥ó¥³¡¼¥É¤¹¤ëM-text ¤Ø¤Î¥Ý¥¤¥ó¥¿
+        @li M-text ¤Î¥¨¥ó¥³¡¼¥É³«»Ï°ÌÃÖ
+        @li M-text ¤Î¥¨¥ó¥³¡¼¥É½ªÎ»°ÌÃÖ
+        @li À¸À®¤·¤¿¥Ð¥¤¥È¤òÊÝ»ý¤¹¤ë¥á¥â¥êÎΰè¤Ø¤Î¥Ý¥¤¥ó¥¿
+        @li ¥á¥â¥êÎΰè¤Î¥µ¥¤¥º
+       @li ¥³¥ó¥Ð¡¼¥¿¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿
+
+    $ENCODER ¤ÏÀ®¸ù¤·¤¿¤È¤­¤Ë¤Ï 0 ¤ò¡¢¼ºÇÔ¤·¤¿¤È¤­¤Ë¤Ï -1 
+    ¤òÊÖ¤µ¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    $EXTRA_INFO ¤Ï¥³¡¼¥Ç¥£¥°¥·¥¹¥Æ¥à¤Ë´Ø¤¹¤ëÄɲþðÊó¤ò´Þ¤à¥Ç¡¼¥¿¹½Â¤¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    ¤³¤Î¥Ç¡¼¥¿¹½Â¤¤Î·¿ $TYPE ¤Ë°Í¸¤¹¤ë¡£
+
+    @return  
+
+    ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð mconv_define_coding () ¤Ï $NAME 
+    ¤È¤¤¤¦Ì¾Á°¤Î¥·¥ó¥Ü¥ë¤òÊÖ¤¹¡£ ¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï #Mnil
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+      */
+
+/***
+    @errors
+    @c MERROR_CODING  */
+
+MSymbol
+mconv_define_coding (const char *name, MPlist *plist,
+                    int (*resetter) (MConverter *),
+                    int (*decoder) (const unsigned char *, int, MText *,
+                                    MConverter *),
+                    int (*encoder) (MText *, int, int,
+                                    unsigned char *, int,
+                                    MConverter *),
+                    void *extra_info)
+{
+  MSymbol sym = msymbol (name);
+  int i;
+  MCodingSystem *coding;
+  MPlist *pl;
+
+  MSTRUCT_MALLOC (coding, MERROR_CODING);
+  coding->name = sym;
+  if ((coding->type = (MSymbol) mplist_get (plist, Mtype)) == Mnil)
+    coding->type = Mcharset;
+  pl = (MPlist *) mplist_get (plist, Mcharsets);
+  if (! pl)
+    MERROR (MERROR_CODING, Mnil);
+  coding->ncharsets = mplist_length (pl);
+  if (coding->ncharsets > NUM_SUPPORTED_CHARSETS)
+    coding->ncharsets = NUM_SUPPORTED_CHARSETS;
+  for (i = 0; i < coding->ncharsets; i++, pl = MPLIST_NEXT (pl))
+    {
+      MSymbol charset_name;
+
+      if (MPLIST_KEY (pl) != Msymbol)
+       MERROR (MERROR_CODING, Mnil);
+      charset_name = MPLIST_SYMBOL (pl);
+      if (! (coding->charsets[i] = MCHARSET (charset_name)))
+       MERROR (MERROR_CODING, Mnil);
+    }
+
+  coding->resetter = resetter;
+  coding->decoder = decoder;
+  coding->encoder = encoder;
+  coding->ascii_compatible = 0;
+  coding->extra_info = extra_info;
+  coding->extra_spec = NULL;
+  coding->ready = 0;
+
+  if (coding->type == Mcharset)
+    {
+      if (! coding->resetter)
+       coding->resetter = reset_coding_charset;
+      if (! coding->decoder)
+       coding->decoder = decode_coding_charset;
+      if (! coding->encoder)
+       coding->encoder = encode_coding_charset;
+    }
+  else if (coding->type == Mutf)
+    {
+      MCodingInfoUTF *info = malloc (sizeof (MCodingInfoUTF));
+      MSymbol val;
+
+      if (! coding->resetter)
+       coding->resetter = reset_coding_utf;
+
+      info->code_unit_bits = (int) mplist_get (plist, Mcode_unit);
+      if (info->code_unit_bits == 8)
+       {
+         if (! coding->decoder)
+           coding->decoder = decode_coding_utf_8;
+         if (! coding->encoder)
+           coding->encoder = encode_coding_utf_8;
+       }
+      else if (info->code_unit_bits == 16)
+       {
+         if (! coding->decoder)
+           coding->decoder = decode_coding_utf_16;
+         if (! coding->encoder)
+           coding->encoder = encode_coding_utf_16;
+       }
+      else if (info->code_unit_bits == 32)
+       {
+         if (! coding->decoder)
+           coding->decoder = decode_coding_utf_32;
+         if (! coding->encoder)
+           coding->encoder = encode_coding_utf_32;
+       }
+      else
+       MERROR (MERROR_CODING, Mnil);
+      val = (MSymbol) mplist_get (plist, Mbom);
+      if (val == Mnil)
+       info->bom = 1;
+      else if (val == Mmaybe)
+       info->bom = 0;
+      else
+       info->bom = 2;
+
+      info->endian = (mplist_get (plist, Mlittle_endian) ? 1 : 0);
+      coding->extra_info = info;
+    }
+  else if (coding->type == Miso_2022)
+    {
+      MCodingInfoISO2022 *info = malloc (sizeof (MCodingInfoISO2022));
+
+      if (! coding->resetter)
+       coding->resetter = reset_coding_iso_2022;
+      if (! coding->decoder)
+       coding->decoder = decode_coding_iso_2022;
+      if (! coding->encoder)
+       coding->encoder = encode_coding_iso_2022;
+
+      info->initial_invocation[0] = 0;
+      info->initial_invocation[1] = -1;
+      pl = (MPlist *) mplist_get (plist, Minvocation);
+      if (pl)
+       {
+         if (MPLIST_KEY (pl) != Minteger)
+           MERROR (MERROR_CODING, Mnil);
+         info->initial_invocation[0] = MPLIST_INTEGER (pl);
+         if (! MPLIST_TAIL_P (pl))
+           {
+             pl = MPLIST_NEXT (pl);
+             if (MPLIST_KEY (pl) != Minteger)
+               MERROR (MERROR_CODING, Mnil);
+             info->initial_invocation[1] = MPLIST_INTEGER (pl);
+           }
+       }
+      memset (info->designations, 0, sizeof (info->designations));
+      for (i = 0, pl = (MPlist *) mplist_get (plist, Mdesignation);
+          i < 32 && pl && MPLIST_KEY (pl) == Minteger;
+          i++, pl = MPLIST_NEXT (pl))
+       info->designations[i] = MPLIST_INTEGER (pl);
+
+      info->flags = 0;
+      MPLIST_DO (pl, (MPlist *) mplist_get (plist, Mflags))
+       {
+         MSymbol val;
+
+         if (MPLIST_KEY (pl) != Msymbol)
+           MERROR (MERROR_CODING, Mnil);
+         val = MPLIST_SYMBOL (pl);
+         if (val == Mreset_at_eol)
+           info->flags |= MCODING_ISO_RESET_AT_EOL;
+         else if (val == Mreset_at_cntl)
+           info->flags |= MCODING_ISO_RESET_AT_CNTL;
+         else if (val == Meight_bit)
+           info->flags |= MCODING_ISO_EIGHT_BIT;
+         else if (val == Mlong_form)
+           info->flags |= MCODING_ISO_LOCKING_SHIFT;
+         else if (val == Mdesignation_g0)
+           info->flags |= MCODING_ISO_DESIGNATION_G0;
+         else if (val == Mdesignation_g1)
+           info->flags |= MCODING_ISO_DESIGNATION_G1;
+         else if (val == Mdesignation_ctext)
+           info->flags |= MCODING_ISO_DESIGNATION_CTEXT;
+         else if (val == Mdesignation_ctext_ext)
+           info->flags |= MCODING_ISO_DESIGNATION_CTEXT_EXT;
+         else if (val == Mlocking_shift)
+           info->flags |= MCODING_ISO_LOCKING_SHIFT;
+         else if (val == Msingle_shift)
+           info->flags |= MCODING_ISO_SINGLE_SHIFT;
+         else if (val == Msingle_shift_7)
+           info->flags |= MCODING_ISO_SINGLE_SHIFT_7;
+         else if (val == Meuc_tw_shift)
+           info->flags |= MCODING_ISO_EUC_TW_SHIFT;
+         else if (val == Miso_6429)
+           info->flags |= MCODING_ISO_ISO6429;
+         else if (val == Mrevision_number)
+           info->flags |= MCODING_ISO_REVISION_NUMBER;
+         else if (val == Mfull_support)
+           info->flags |= MCODING_ISO_FULL_SUPPORT;
+       }
+
+      coding->extra_info = info;
+    }
+  else
+    {
+      if (! coding->decoder || ! coding->encoder)
+       MERROR (MERROR_CODING, Mnil);
+      if (! coding->resetter)
+       coding->ready = 1;
+    }
+
+  msymbol_put (sym, Mcoding, coding);
+  msymbol_put (msymbol__canonicalize (sym), Mcoding, coding);
+  plist = (MPlist *) mplist_get (plist, Maliases);
+  if (plist)
+    {
+      MPLIST_DO (pl, plist)
+       {
+         MSymbol alias;
+
+         if (MPLIST_KEY (pl) != Msymbol)
+           continue;
+         alias = MPLIST_SYMBOL (pl);
+         msymbol_put (alias, Mcoding, coding);
+         msymbol_put (msymbol__canonicalize (alias), Mcoding, coding);
+       }
+    }
+
+  MLIST_APPEND1 (&coding_list, codings, coding, MERROR_CODING);
+
+  return sym;
+}
+
+/*=*/
+
+/***en
+    @brief Resolve coding system name.
+
+    The mconv_resolve_coding () function returns $SYMBOL if it
+    represents a coding system.  Otherwise, canonicalize $SYMBOL as to
+    a coding system name, and if the canonicalized name represents a
+    coding system, return it.  Otherwise, return #Mnil.  */
+/***ja
+    @brief ¥³¡¼¥É·Ï¤Î̾Á°¤ò²ò·è¤¹¤ë.
+
+    ´Ø¿ô mconv_resolve_coding () ¤Ï $SYMBOL ¤¬¥³¡¼¥É·Ï¤ò¼¨¤·¤Æ¤¤¤ì¤Ð¤½¤ì¤òÊÖ¤¹¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¥³¡¼¥É·Ï¤Î̾Á°¤È¤·¤Æ $SYMBOL 
+    ¤òÀµµ¬²½¤·¡¢¤½¤ì¤¬¥³¡¼¥É·Ï¤òɽ¤·¤Æ¤¤¤ì¤ÐÀµµ¬²½¤·¤¿ $SYMBOL ¤òÊÖ¤¹¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð#Mnil ¤òÊÖ¤¹¡£  */
+
+
+
+MSymbol
+mconv_resolve_coding (MSymbol symbol)
+{
+  MCodingSystem *coding = find_coding (symbol);
+
+  if (! coding)
+    {
+      symbol = msymbol__canonicalize (symbol);
+      coding = find_coding (symbol);
+    }
+  return (coding ? coding->name : Mnil);
+}
+
+/*=*/
+
+
+/***en
+    @brief List symbols representing coding systems.
+
+    The mconv_list_codings () function makes an array of symbols
+    representing a coding system, stores the pointer to the array in a
+    place pointed to by $SYMBOLS, and returns the length of the array.  */
+/***ja
+    @brief ¥³¡¼¥É·Ï¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤òÎóµó¤¹¤ë.
+
+    ´Ø¿ô mchar_list_codings () ¤Ï¡¢¥³¡¼¥É·Ï¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤òʤ٤¿ÇÛÎó¤òºî¤ê¡¢
+    $SYMBOLS ¤Ç¥Ý¥¤¥ó¥È¤µ¤ì¤¿¾ì½ê¤Ë¤³¤ÎÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÃÖ¤­¡¢ÇÛÎó¤ÎŤµ¤òÊÖ¤¹¡£ */
+
+int
+mconv_list_codings (MSymbol **symbols)
+{
+  int i = coding_list.used + mplist_length (coding_definition_list);
+  int j;
+  MPlist *plist;
+
+  MTABLE_MALLOC ((*symbols), i, MERROR_CODING);
+  i = 0;
+  MPLIST_DO (plist, coding_definition_list)
+    {
+      MPlist *pl = MPLIST_VAL (plist);
+      (*symbols)[i++] = MPLIST_SYMBOL (pl);
+    }
+  for (j = 0; j < coding_list.used; j++)
+    if (! mplist_find_by_key (coding_definition_list, 
+                             coding_list.codings[j]->name))
+      (*symbols)[i++] = coding_list.codings[j]->name;
+  return i;
+}
+
+/*=*/
+
+/***en
+    @brief Create a code converter bound to a buffer.
+
+    The mconv_buffer_converter () function creates a pointer to a code
+    converter for coding system $NAME.  The code converter is bound
+    to buffer area of $N bytes pointed to by $BUF.  Subsequent
+    decodings and encodings are done to/from this buffer area.
+
+    $NAME can be #Mnil.  In this case, a coding system associated
+    with the current locale (LC_CTYPE) is used.
+
+    @return
+    If the operation was successful, mconv_buffer_converter () returns
+    the created code converter.  Otherwise it returns @c NULL and
+    assigns an error code to the external variable #merror_code.  */
+
+/***ja
+    @brief ¥Ð¥Ã¥Õ¥¡¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤¿¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤òºî¤ë.
+
+    ´Ø¿ô mconv_buffer_converter () ¤Ï¡¢¥³¡¼¥É·Ï $NAME 
+    ÍѤΥ³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤òºî¤ë¡£¤³¤Î¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤Ï¡¢$BUF ¤Ç¼¨¤µ¤ì¤ëÂ礭¤µ $N 
+    ¥Ð¥¤¥È¤Î¥Ð¥Ã¥Õ¥¡Îΰè¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤ë¡£
+    ¤³¤ì°Ê¹ß¤Î¥Ç¥³¡¼¥É¤ª¤è¤Ó¥¨¥ó¥³¡¼¥É¤Ï¡¢¤³¤Î¥Ð¥Ã¥Õ¥¡Îΰè¤ËÂФ·¤Æ¹Ô¤Ê¤ï¤ì¤ë¡£
+
+    $NAME ¤Ï #Mnil ¤Ç¤¢¤Ã¤Æ¤â¤è¤¤¡£¤³¤Î¾ì¹ç¤Ï¸½ºß¤Î¥í¥±¡¼¥ë 
+    (LC_CTYPE) ¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥³¡¼¥É·Ï¤¬»È¤ï¤ì¤ë¡£
+
+    @return
+    ¤â¤·½èÍý¤¬À®¸ù¤¹¤ì¤Ð mconv_buffer_converter () ¤Ï ºîÀ®¤·¤¿¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤òÊÖ¤¹¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code 
+    ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mconverter} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_SYMBOL, @c MERROR_CODING
+
+    @seealso 
+    mconv_stream_converter ()  */
+
+MConverter *
+mconv_buffer_converter (MSymbol name, const unsigned char *buf, int n)
+{
+  MCodingSystem *coding;
+  MConverter *converter;
+  MConverterStatus *internal;
+
+  if (name == Mnil)
+    name = mlocale_get_prop (mlocale__ctype, Mcoding);
+  coding = find_coding (name);
+  if (! coding)
+    MERROR (MERROR_CODING, NULL);
+  MSTRUCT_CALLOC (converter, MERROR_CODING);
+  MSTRUCT_CALLOC (internal, MERROR_CODING);
+  converter->internal_info = internal;
+  internal->coding = coding;
+  if (coding->resetter
+      && (*coding->resetter) (converter) < 0)
+    {
+      free (internal);
+      free (converter);
+      MERROR (MERROR_CODING, NULL);
+    }
+
+  internal->unread = mtext ();
+  internal->work_mt = mtext ();
+  mtext__enlarge (internal->work_mt, MAX_UTF8_CHAR_BYTES);
+  internal->buf.in = buf;
+  internal->used = 0;
+  internal->bufsize = n;
+  internal->binding = BINDING_BUFFER;
+
+  return converter;
+}
+
+/*=*/
+
+/***en
+    @brief Create a code converter bound to a stream.
+
+    The mconv_stream_converter () function creates a pointer to a code
+    converter for coding system $NAME.  The code converter is bound
+    to stream $FP.  Subsequent decodings and encodings are done
+    to/from this stream.
+
+    $NAME can be #Mnil.  In this case, a coding system associated
+    with the current locale (LC_CTYPE) is used.
+
+    @return 
+    If the operation was successful, mconv_stream_converter ()
+    returns the created code converter.  Otherwise it returns @c NULL
+    and assigns an error code to the external variable 
+    #merror_code.  */
+
+/***ja
+    @brief ¥¹¥È¥ê¡¼¥à¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤¿¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤òºî¤ë.
+
+    ´Ø¿ô mconv_stream_converter () ¤Ï¡¢¥³¡¼¥É·Ï $NAME 
+    ÍѤΥ³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤òºî¤ë¡£¤³¤Î¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤Ï¡¢¥¹¥È¥ê¡¼¥à $FP 
+    ¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤ë¡£
+    ¤³¤ì°Ê¹ß¤Î¥Ç¥³¡¼¥É¤ª¤è¤Ó¥¨¥ó¥³¡¼¥É¤Ï¡¢¤³¤Î¥¹¥È¥ê¡¼¥à¤ËÂФ·¤Æ¹Ô¤Ê¤ï¤ì¤ë¡£
+
+    $NAME ¤Ï #Mnil ¤Ç¤¢¤Ã¤Æ¤â¤è¤¤¡£¤³¤Î¾ì¹ç¤Ï¸½ºß¤Î¥í¥±¡¼¥ë 
+    (LC_CTYPE) ¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥³¡¼¥É·Ï¤¬»È¤ï¤ì¤ë¡£
+
+    @return 
+    ¤â¤·½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_stream_converter () 
+    ¤ÏºîÀ®¤·¤¿¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL 
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mconverter} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_SYMBOL, @c MERROR_CODING
+
+    @seealso
+    mconv_buffer_converter ()  */
+
+MConverter *
+mconv_stream_converter (MSymbol name, FILE *fp)
+{
+  MCodingSystem *coding;
+  MConverter *converter;
+  MConverterStatus *internal;
+
+  if (name == Mnil)
+    name = mlocale_get_prop (mlocale__ctype, Mcoding);
+  coding = find_coding (name);
+  if (! coding)
+    MERROR (MERROR_CODING, NULL);
+  MSTRUCT_CALLOC (converter, MERROR_CODING);
+  MSTRUCT_CALLOC (internal, MERROR_CODING);
+  converter->internal_info = internal;
+  internal->coding = coding;
+  if (coding->resetter
+      && (*coding->resetter) (converter) < 0)
+    {
+      free (internal);
+      free (converter);
+      MERROR (MERROR_CODING, NULL);
+    }
+
+  if (fseek (fp, 0, SEEK_CUR) < 0)
+    {
+      if (errno == EBADF)
+       {
+         free (internal);
+         free (converter);
+         return NULL;
+       }
+      internal->seekable = 0;
+    }
+  else
+    internal->seekable = 1;
+  internal->unread = mtext ();
+  internal->work_mt = mtext ();
+  mtext__enlarge (internal->work_mt, MAX_UTF8_CHAR_BYTES);
+  internal->fp = fp;
+  internal->binding = BINDING_STREAM;
+
+  return converter;
+}
+
+/*=*/
+
+/***en
+    @brief Reset a code converter.
+
+    The mconv_reset_converter () function resets code converter
+    $CONVERTER to the initial state.
+
+    @return
+    If $CONVERTER->coding has its own reseter function,
+    mconv_reset_converter () returns the result of that function
+    applied to $CONVERTER.  Otherwise it returns 0.  */
+
+/***ja
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ò¥ê¥»¥Ã¥È¤¹¤ë.
+
+    ´Ø¿ô mconv_reset_converter () ¤Ï¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ $CONVERTER 
+    ¤ò½é´ü¾õÂÖ¤ËÌ᤹¡£
+
+    @return
+    ¤â¤· $CONVERTER->coding ¤Ë¥ê¥»¥Ã¥ÈÍѤδؿô¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤Ê¤é¤Ð¡¢
+    mconv_reset_converter () ¤Ï¤½¤Î´Ø¿ô¤Ë $CONVERTER 
+    ¤òŬÍѤ·¤¿·ë²Ì¤òÊÖ¤·¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð0¤òÊÖ¤¹¡£  */
+
+int
+mconv_reset_converter (MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+
+  converter->nchars = converter->nbytes = 0;
+  converter->result = MCONVERSION_RESULT_SUCCESS;
+  internal->carryover_bytes = 0;
+  internal->used = 0;
+  mtext_reset (internal->unread);
+  if (internal->coding->resetter)
+    return (*internal->coding->resetter) (converter);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Free a code converter.
+
+    The mconv_free_converter () function frees the code converter
+    $CONVERTER.  */
+
+/***ja
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ò²òÊü¤¹¤ë.
+
+    ´Ø¿ô mconv_free_converter () ¤Ï¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ $CONVERTER 
+    ¤ò²òÊü¤¹¤ë¡£  */
+
+void
+mconv_free_converter (MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+
+  M17N_OBJECT_UNREF (internal->work_mt);
+  M17N_OBJECT_UNREF (internal->unread);
+  free (internal);
+  free (converter);
+}
+
+/*=*/
+
+/***en
+    @brief Bind a buffer to a code converter.
+
+    The mconv_rebind_buffer () function binds buffer area of $N bytes
+    pointed to by $BUF to code converter $CONVERTER.  Subsequent
+    decodings and encodings are done to/from this newly bound buffer
+    area.
+
+    @return
+    This function always returns $CONVERTER.  */
+
+/***ja
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤Ë¥Ð¥Ã¥Õ¥¡Îΰè¤ò·ë¤ÓÉÕ¤±¤ë.
+
+    ´Ø¿ô mconv_rebind_buffer () ¤Ï¡¢$BUF ¤Ë¤è¤Ã¤Æ»Ø¤µ¤ì¤¿Â礭¤µ $N 
+    ¥Ð¥¤¥È¤Î¥Ð¥Ã¥Õ¥¡Îΰè¤ò¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ $CONVERTER ¤Ë·ë¤ÓÉÕ¤±¤ë¡£
+    ¤³¤ì°Ê¹ß¤Î¥Ç¥³¡¼¥É¤ª¤è¤Ó¥¨¥ó¥³¡¼¥É¤Ï¡¢¤³¤Î¿·¤¿¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤¿¥Ð¥Ã¥Õ¥¡Îΰè¤ËÂФ·¤Æ¹Ô¤Ê¤ï¤ì¤ë¤è¤¦¤Ë¤Ê¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¾ï¤Ë $CONVERTER ¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mconv_rebind_buffer} @endlatexonly  */
+
+/***
+    @seealso
+    mconv_rebind_stream () */
+
+MConverter *
+mconv_rebind_buffer (MConverter *converter, const unsigned char *buf, int n)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+
+  internal->buf.in = buf;
+  internal->used = 0;
+  internal->bufsize = n;
+  internal->binding = BINDING_BUFFER;
+  return converter;
+}
+
+/*=*/
+
+/***en
+    @brief Bind a stream to a code converter.
+
+    The mconv_rebind_stream () function binds stream $FP to code
+    converter $CONVERTER.  Following decodings and encodings are done
+    to/from this newly bound stream.
+
+    @return
+    This function always returns $CONVERTER.  */
+
+/***ja
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤Ë¥¹¥È¥ê¡¼¥à¤ò·ë¤ÓÉÕ¤±¤ë.
+
+    ´Ø¿ô mconv_rebind_stream () ¤Ï¡¢¥¹¥È¥ê¡¼¥à $FP ¤ò¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ 
+    $CONVERTER ¤Ë·ë¤ÓÉÕ¤±¤ë¡£
+    ¤³¤ì°Ê¹ß¤Î¥Ç¥³¡¼¥É¤ª¤è¤Ó¥¨¥ó¥³¡¼¥É¤Ï¡¢¤³¤Î¿·¤¿¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤¿¥¹¥È¥ê¡¼¥à¤ËÂФ·¤Æ¹Ô¤Ê¤ï¤ì¤ë¤è¤¦¤Ë¤Ê¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¾ï¤Ë $CONVERTER ¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mconv_rebind_stream} @endlatexonly  */
+
+/***
+    @seealso
+    mconv_rebind_buffer () */
+
+MConverter *
+mconv_rebind_stream (MConverter *converter, FILE *fp)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+
+  if (fseek (fp, 0, SEEK_CUR) < 0)
+    {
+      if (errno == EBADF)
+       return NULL;
+      internal->seekable = 0;
+    }
+  else
+    internal->seekable = 1;
+  internal->fp = fp;
+  internal->binding = BINDING_STREAM;
+  return converter;
+}
+
+/*=*/
+
+/***en
+    @brief Decode a byte sequence into an M-text.
+
+    The mconv_decode () function decodes a byte sequence and appends
+    the result at the end of M-text $MT.  The source byte sequence is
+    taken from either the buffer area or the stream that is currently
+    bound to $CONVERTER.
+
+    @return
+    If the operation was successful, mconv_decode () returns updated
+    $MT.  Otherwise it returns @c NULL and assigns an error code to
+    the external variable #merror_code.  */
+
+/***ja
+    @brief ¥Ð¥¤¥ÈÎó¤ò M-text ¤Ë¥Ç¥³¡¼¥É¤¹¤ë.
+
+    ´Ø¿ô mconv_decode () ¤Ï¡¢¥Ð¥¤¥ÈÎó¤ò¥Ç¥³¡¼¥É¤·¤Æ¤½¤Î·ë²Ì¤ò M-text
+    $MT ¤ÎËöÈø¤ËÄɲ乤롣¥Ç¥³¡¼¥É¸µ¤Î¥Ð¥¤¥ÈÎó¤Ï¡¢$CONVERTER 
+    ¤Ë¸½ºß·ë¤ÓÉÕ¤±¤é¤ì¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼¥à¤«¤é¼è¤é¤ì¤ë¡£
+
+    @return
+    ¤â¤·½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_decode () ¤Ï¹¹¿·¤µ¤ì¤¿ $MT ¤òÊÖ¤¹¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code 
+    ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_IO, @c MERROR_CODING
+
+    @seealso
+    mconv_rebind_buffer (), mconv_rebind_stream (),
+    mconv_encode (), mconv_encode_range (),
+    mconv_decode_buffer (), mconv_decode_stream ()  */
+
+MText *
+mconv_decode (MConverter *converter, MText *mt)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  int at_most = converter->at_most > 0 ? converter->at_most : -1;
+  int n;
+
+  M_CHECK_READONLY (mt, NULL);
+
+  if (mt->format != MTEXT_FORMAT_UTF_8)
+    mtext__adjust_format (mt, MTEXT_FORMAT_UTF_8);
+
+  if (! mt->data)
+    mtext__enlarge (mt, MAX_UTF8_CHAR_BYTES);
+
+  converter->nchars = converter->nbytes = 0;
+  converter->result = MCONVERSION_RESULT_SUCCESS;
+
+  n = mtext_nchars (internal->unread);
+  if (n > 0)
+    {
+      int limit = n;
+      int i;
+
+      if (at_most > 0 && at_most < limit)
+       limit = at_most;
+
+      for (i = 0, n -= 1; i < limit; i++, converter->nchars++, n--)
+       mtext_cat_char (mt, mtext_ref_char (internal->unread, n));
+      mtext_del (internal->unread, n + 1, internal->unread->nchars);
+      if (at_most > 0)
+       {
+         if (at_most == limit)
+           return mt;
+         converter->at_most -= converter->nchars;
+       }
+    }
+
+  if (internal->binding == BINDING_BUFFER)
+    {
+      (*internal->coding->decoder) (internal->buf.in + internal->used,
+                                   internal->bufsize - internal->used,
+                                   mt, converter);
+      internal->used += converter->nbytes;
+    }  
+  else if (internal->binding == BINDING_STREAM)
+    {
+      unsigned char work[CONVERT_WORKSIZE];
+      int last_block = converter->last_block;
+      int use_fread = at_most < 0 && internal->seekable;
+
+      converter->last_block = 0;
+      while (1)
+       {
+         int nbytes, prev_nbytes;
+
+         if (feof (internal->fp))
+           nbytes = 0;
+         else if (use_fread)
+           nbytes = fread (work, sizeof (unsigned char), CONVERT_WORKSIZE,
+                           internal->fp);
+         else
+           {
+             int c = getc (internal->fp);
+
+             if (c != EOF)
+               work[0] = c, nbytes = 1;
+             else
+               nbytes = 0;
+           }
+
+         if (ferror (internal->fp))
+           {
+             converter->result = MCONVERSION_RESULT_IO_ERROR;
+             break;
+           }
+
+         if (nbytes == 0)
+           converter->last_block = last_block;
+         prev_nbytes = converter->nbytes;
+         (*internal->coding->decoder) (work, nbytes, mt, converter);
+         if (converter->nbytes - prev_nbytes < nbytes)
+           {
+             if (use_fread)
+               fseek (internal->fp, converter->nbytes - prev_nbytes - nbytes,
+                      SEEK_CUR);
+             else
+               ungetc (work[0], internal->fp);
+             break;
+           }
+         if (nbytes == 0
+             || (converter->at_most > 0
+                 && converter->nchars == converter->at_most))
+           break;
+       }
+      converter->last_block = last_block;
+    }
+  else                         /* internal->binding == BINDING_NONE */
+    MERROR (MERROR_CODING, NULL);
+
+  converter->at_most = at_most;
+  return ((converter->result == MCONVERSION_RESULT_SUCCESS
+          || converter->result == MCONVERSION_RESULT_INSUFFICIENT_SRC)
+         ? mt : NULL);
+}
+
+/*=*/
+
+/***en
+    @brief Decode a buffer area based on a coding system.
+
+    The mconv_decode_buffer () function decodes $N bytes of the buffer
+    area pointed to by $BUF based on the coding system $NAME.  A
+    temporary code converter for decoding is automatically created
+    and freed.
+
+    @return 
+    If the operation was successful, mconv_decode_buffer ()
+    returns the resulting M-text.  Otherwise it returns @c NULL and
+    assigns an error code to the external variable #merror_code.  */
+
+/***ja
+    @brief ¥³¡¼¥É·Ï¤Ë´ð¤Å¤¤¤Æ¥Ð¥Ã¥Õ¥¡Îΰè¤ò¥Ç¥³¡¼¥É¤¹¤ë.
+
+    ´Ø¿ô mconv_decode_buffer () ¤Ï¡¢$BUF ¤Ë¤è¤Ã¤Æ»Ø¤µ¤ì¤¿ $N 
+    ¥Ð¥¤¥È¤Î¥Ð¥Ã¥Õ¥¡Îΰè¤ò¡¢¥³¡¼¥É·Ï $NAME ¤Ë´ð¤Å¤¤¤Æ¥Ç¥³¡¼¥É¤¹¤ë¡£
+    ¥Ç¥³¡¼¥É¤ËɬÍפʥ³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ÎºîÀ®¤È²òÊü¤Ï¼«Æ°Åª¤Ë¹Ô¤Ê¤ï¤ì¤ë¡£
+
+    @return
+    ¤â¤·½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_decode_buffer () ¤ÏÆÀ¤é¤ì¤¿ M-text ¤òÊÖ¤¹¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code 
+    ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_IO, @c MERROR_CODING
+
+    @seealso
+    mconv_decode (), mconv_decode_stream ()  */
+
+MText *
+mconv_decode_buffer (MSymbol name, const unsigned char *buf, int n)
+{
+  MConverter *converter = mconv_buffer_converter (name, buf, n);
+  MText *mt;
+
+  if (! converter)
+    return NULL;
+  mt = mtext ();
+  if (! mconv_decode (converter, mt))
+    {
+      M17N_OBJECT_UNREF (mt);
+      mt = NULL;
+    }
+  mconv_free_converter (converter);
+  return mt;
+}
+
+/*=*/
+
+/***en
+    @brief Decode a stream input based on a coding system.
+
+    The mconv_decode_stream () function decodes the entire byte
+    sequence read in from stream $FP based on the coding system $NAME.
+    A code converter for decoding is automatically created and freed.
+
+    @return
+    If the operation was successful, mconv_decode_stream () returns
+    the resulting M-text.  Otherwise it returns @c NULL and assigns an
+    error code to the external variable #merror_code.  */
+
+/***ja
+    @brief ¥³¡¼¥É·Ï¤Ë´ð¤Å¤¤¤Æ¥¹¥È¥ê¡¼¥àÆþÎϤò¥Ç¥³¡¼¥É¤¹¤ë.
+
+    ´Ø¿ô mconv_decode_stream () ¤Ï¡¢¥¹¥È¥ê¡¼¥à $FP 
+    ¤«¤éÆɤ߹þ¤Þ¤ì¤ë¥Ð¥¤¥ÈÎóÁ´ÂΤò¡¢¥³¡¼¥É·Ï $NAME 
+    ¤Ë´ð¤Å¤¤¤Æ¥Ç¥³¡¼¥É¤¹¤ë¡£¥Ç¥³¡¼¥É¤ËɬÍפʥ³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ÎºîÀ®¤È²òÊü¤Ï¼«Æ°Åª¤Ë¹Ô¤Ê¤ï¤ì¤ë¡£
+
+    @return
+    ¤â¤·½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_decode_stream () ¤ÏÆÀ¤é¤ì¤¿ M-text 
+    ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code 
+    ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_IO, @c MERROR_CODING
+
+    @seealso
+    mconv_decode (), mconv_decode_buffer ()  */
+
+MText *
+mconv_decode_stream (MSymbol name, FILE *fp)
+{
+  MConverter *converter = mconv_stream_converter (name, fp);
+  MText *mt;
+
+  if (! converter)
+    return NULL;
+  mt = mtext ();
+  if (! mconv_decode (converter, mt))
+    {
+      M17N_OBJECT_UNREF (mt);
+      mt = NULL;
+    }
+  mconv_free_converter (converter);
+  return mt;
+}
+
+/*=*/
+
+/***en @brief Encode an M-text into a byte sequence.
+
+    The mconv_encode () function encodes M-text $MT and writes the
+    resulting byte sequence into the buffer area or the stream that is
+    currently bound to code converter $CONVERTER.
+
+    @return
+    If the operation was successful, mconv_encode () returns the
+    number of written bytes.  Otherwise it returns -1 and assigns an
+    error code to the external variable #merror_code.  */
+
+/***ja
+    @brief M-text ¤ò¥Ð¥¤¥ÈÎó¤Ë¥¨¥ó¥³¡¼¥É¤¹¤ë.
+
+    ´Ø¿ô mconv_encode () ¤Ï¡¢M-text $MT ¤ò¥¨¥ó¥³¡¼¥É¤·¤Æ¡¢¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿
+    $CONVERTER ¤Ë¸½ºß·ë¤ÓÉÕ¤±¤é¤ì¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼¥à¤ËÆÀ¤é¤ì¤¿¥Ð¥¤¥ÈÎó¤ò½ñ¤­¹þ¤à¡£
+
+    @return
+    ¤â¤·½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_encode () ¤Ï½ñ¤­¹þ¤Þ¤ì¤¿¥Ð¥¤¥È¿ô¤òÊÖ¤¹¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code 
+    ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_IO, @c MERROR_CODING
+
+    @seealso
+    mconv_rebind_buffer (), mconv_rebind_stream(),
+    mconv_decode (), mconv_encode_range ()  */
+
+int
+mconv_encode (MConverter *converter, MText *mt)
+{
+  return mconv_encode_range (converter, mt, 0, mtext_nchars (mt));
+}
+
+/*=*/
+
+/***en
+    @brief Encode a part of an M-text.
+
+    The mconv_encode_range () function encodes the text between $FROM
+    (inclusive) and $TO (exclusive) in M-text $MT and writes the
+    resulting byte sequence into the buffer area or the stream that is
+    currently bound to code converter $CONVERTER.
+
+    @return
+    If the operation was successful, mconv_encode_range () returns the
+    number of written bytes. Otherwise it returns -1 and assigns an
+    error code to the external variable #merror_code.  */
+
+/***ja
+    @brief M-text ¤Î°ìÉô¤ò¥Ð¥¤¥ÈÎó¤Ë¥¨¥ó¥³¡¼¥É¤¹¤ë.
+
+    ´Ø¿ô mconv_encode_range () ¤Ï¡¢M-text $MT ¤Î $FROM 
+    ¡Ê$FROM ¼«ÂΤâ´Þ¤à¡Ë¤«¤é $TO ¡Ê$TO¼«ÂΤϴޤޤʤ¤¡Ë
+    ¤Þ¤Ç¤ÎÈϰϤΥƥ­¥¹¥È¤ò¥¨¥ó¥³¡¼¥É¤·¤Æ¡¢¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿
+    $CONVERTER ¤Ë¸½ºß·ë¤ÓÉÕ¤±¤é¤ì¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼¥à¤ËÆÀ¤é¤ì¤¿¥Ð¥¤¥ÈÎó¤ò½ñ¤­¹þ¤à¡£
+
+    @return
+    ¤â¤·½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_encode_range () 
+    ¤Ï½ñ¤­¹þ¤Þ¤ì¤¿¥Ð¥¤¥È¿ô¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_RANGE, @c MERROR_IO, @c MERROR_CODING
+
+    @seealso
+    mconv_rebind_buffer (), mconv_rebind_stream(),
+    mconv_decode (), mconv_encode ()  */
+
+int
+mconv_encode_range (MConverter *converter, MText *mt, int from, int to)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+
+  M_CHECK_POS_X (mt, from, -1);
+  M_CHECK_POS_X (mt, to, -1);
+  if (to < from)
+    to = from;
+
+  if (converter->at_most > 0 && from + converter->at_most < to)
+    to = from + converter->at_most;
+
+  converter->nchars = converter->nbytes = 0;
+  converter->result = MCONVERSION_RESULT_SUCCESS;
+
+  mtext_put_prop (mt, from, to, Mcoding, internal->coding->name);
+  if (internal->binding == BINDING_BUFFER)
+    {
+      (*internal->coding->encoder) (mt, from, to,
+                                   internal->buf.out + internal->used,
+                                   internal->bufsize - internal->used,
+                                   converter);
+      internal->used += converter->nbytes;
+    }
+  else if (internal->binding == BINDING_STREAM)
+    {
+      unsigned char work[CONVERT_WORKSIZE];
+
+      while (from < to)
+       {
+         int written = 0;
+         int prev_nbytes = converter->nbytes;
+         int this_nbytes;
+
+         (*internal->coding->encoder) (mt, from, to, work,
+                                       CONVERT_WORKSIZE, converter);
+         this_nbytes = converter->nbytes - prev_nbytes;
+         while (written < this_nbytes)
+           {
+             int wrtn = fwrite (work + written, sizeof (unsigned char),
+                                this_nbytes - written, internal->fp);
+
+             if (ferror (internal->fp))
+               break;
+             written += wrtn;
+           }
+         if (written < this_nbytes)
+           {
+             converter->result = MCONVERSION_RESULT_IO_ERROR;
+             break;
+           }
+         from += converter->nchars;
+       }
+    }
+  else                                 /* fail safe */
+    MERROR (MERROR_CODING, -1);
+
+  return ((converter->result == MCONVERSION_RESULT_SUCCESS
+          || converter->result == MCONVERSION_RESULT_INSUFFICIENT_DST)
+         ? converter->nbytes : -1);
+}
+
+/*=*/
+
+/***en
+    @brief Encode an M-text into a buffer area.
+
+    The mconv_encode_buffer () function encodes M-text $MT based on
+    coding system $NAME and writes the resulting byte sequence into the
+    buffer area pointed to by $BUF.  At most $N bytes are written.  A
+    temporary code converter for encoding is automatically created
+    and freed.
+
+    @return
+    If the operation was successful, mconv_encode_buffer () returns
+    the number of written bytes.  Otherwise it returns -1 and assigns
+    an error code to the external variable #merror_code.  */
+
+/***ja
+    @brief M-text ¤ò¥¨¥ó¥³¡¼¥É¤·¤Æ¥Ð¥Ã¥Õ¥¡Îΰè¤Ë½ñ¤­¹þ¤à.
+
+    ´Ø¿ô mconv_encode_buffer () ¤ÏM-text $MT ¤ò¥³¡¼¥É·Ï $NAME 
+    ¤Ë´ð¤Å¤¤¤Æ¥¨¥ó¥³¡¼¥É¤·¡¢ÆÀ¤é¤ì¤¿¥Ð¥¤¥ÈÎó¤ò $BUF ¤Î»Ø¤¹¥Ð¥Ã¥Õ¥¡Îΰè¤Ë½ñ¤­¹þ¤à¡£
+    $N ¤Ï½ñ¤­¹þ¤àºÇÂç¥Ð¥¤¥È¿ô¤Ç¤¢¤ë¡£
+    ¥¨¥ó¥³¡¼¥É¤ËɬÍפʥ³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ÎºîÀ®¤È²òÊü¤Ï¼«Æ°Åª¤Ë¹Ô¤Ê¤ï¤ì¤ë¡£
+
+    @return
+    ¤â¤·½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_encode_buffer () ¤Ï½ñ¤­¹þ¤Þ¤ì¤¿¥Ð¥¤¥È¿ô¤òÊÖ¤¹¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð-1¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_IO, @c MERROR_CODING
+
+    @seealso
+    mconv_encode (), mconv_encode_stream ()  */
+
+int
+mconv_encode_buffer (MSymbol name, MText *mt, unsigned char *buf, int n)
+{
+  MConverter *converter = mconv_buffer_converter (name, buf, n);
+  int ret;
+
+  if (! converter)
+    return -1;
+  ret = mconv_encode (converter, mt);
+  mconv_free_converter (converter);
+  return ret;
+}
+
+/*=*/
+
+/***en
+    @brief Encode an M-text to write to a stream.
+
+    The mconv_encode_stream () function encodes M-text $MT based on
+    coding system $NAME and writes the resulting byte sequence to
+    stream $FP.  A temporary code converter for encoding is
+    automatically created and freed.
+
+    @return
+    If the operation was successful, mconv_encode_stream () returns
+    the number of written bytes.  Otherwise it returns -1 and assigns
+    an error code to the external variable #merror_code.  */
+
+/***ja
+    @brief M-text ¤ò¥¨¥ó¥³¡¼¥É¤·¤Æ¥¹¥È¥ê¡¼¥à¤Ë½ñ¤­¹þ¤à.
+
+    ´Ø¿ô mconv_encode_stream () ¤ÏM-text $MT ¤ò¥³¡¼¥É·Ï $NAME 
+    ¤Ë´ð¤Å¤¤¤Æ¥¨¥ó¥³¡¼¥É¤·¡¢ÆÀ¤é¤ì¤¿¥Ð¥¤¥ÈÎó¤ò¥¹¥È¥ê¡¼¥à $FP 
+    ¤Ë½ñ¤­½Ð¤¹¡£¥¨¥ó¥³¡¼¥É¤ËɬÍפʥ³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ÎºîÀ®¤È²òÊü¤Ï¼«Æ°Åª¤Ë¹Ô¤Ê¤ï¤ì¤ë¡£
+
+    @return
+    ¤â¤·½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_encode_stream () 
+    ¤Ï½ñ¤­¹þ¤Þ¤ì¤¿¥Ð¥¤¥È¿ô¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_IO, @c MERROR_CODING
+
+    @seealso
+    mconv_encode (), mconv_encode_buffer (), mconv_encode_file ()  */
+
+int
+mconv_encode_stream (MSymbol name, MText *mt, FILE *fp)
+{
+  MConverter *converter = mconv_stream_converter (name, fp);
+  int ret;
+
+  if (! converter)
+    return -1;
+  ret = mconv_encode (converter, mt);
+  mconv_free_converter (converter);
+  return ret;
+}
+
+/*=*/
+
+/***en
+    @brief Read a character via a code converter.
+
+    The mconv_getc () function reads one character from the buffer
+    area or the stream that is currently bound to code converter
+    $CONVERTER.  The decoder of $CONVERTER is used to decode the byte
+    sequence.  The internal status of $CONVERTER is updated
+    appropriately.
+
+    @return
+    If the operation was successful, mconv_getc () returns the
+    character read in.  If the input source reaches EOF, it returns @c
+    EOF without changing the external variable #merror_code.  If an
+    error is detected, it returns @c EOF and assigns an error code to
+    #merror_code.  */
+
+/***ja
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿·Ðͳ¤Ç°ìʸ»ú¤òÆɤߤ³¤à.
+
+    ´Ø¿ô mconv_getc () ¤Ï¡¢¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ $CONVERTER 
+    ¤Ë¸½ºß·ë¤ÓÉÕ¤±¤é¤ì¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼¥à¤«¤éʸ»ú¤ò°ì¤ÄÆɤ߹þ¤à¡£
+    ¥Ð¥¤¥ÈÎó¤Î¥Ç¥³¡¼¥É¤Ë¤Ï $CONVERTER ¤Î¥Ç¥³¡¼¥À¤¬ÍѤ¤¤é¤ì¤ë¡£
+    $CONVERTER ¤ÎÆâÉô¾õÂÖ¤ÏɬÍפ˱þ¤¸¤Æ¹¹¿·¤µ¤ì¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_getc () ¤ÏÆɤ߹þ¤Þ¤ì¤¿Ê¸»ú¤òÊÖ¤¹¡£ÆþÎϸ»¤¬ 
+    EOF ¤Ë㤷¤¿¾ì¹ç¤Ï¡¢³°ÉôÊÑ¿ô #merror_code ¤òÊѤ¨¤º¤Ë @c EOF 
+    ¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï @c EOF ¤òÊÖ¤·¡¢#merror_code 
+    ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_CODING
+
+    @seealso
+    mconv_ungetc (), mconv_putc (), mconv_gets ()  */
+
+int
+mconv_getc (MConverter *converter)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+  int at_most = converter->at_most;
+
+  mtext_reset (internal->work_mt);
+  converter->at_most = 1;
+  mconv_decode (converter, internal->work_mt);
+  converter->at_most = at_most;
+  return (converter->nchars == 1
+         ? STRING_CHAR (internal->work_mt->data)
+         : EOF);
+}
+
+/*=*/
+
+/***en
+    @brief Push a character back to a code converter.
+
+    The mconv_ungetc () function pushes character $C back to code
+    converter $CONVERTER.  Any number of characters can be pushed
+    back.  The lastly pushed back character is firstly read by the
+    subsequent mconv_getc () call.  The characters pushed back are
+    registered only in $CONVERTER; they are not written to the input
+    source.  The internal status of $CONVERTER is updated
+    appropriately.
+
+    @return
+    If the operation was successful, mconv_ungetc () returns $C.
+    Otherwise it returns @c EOF and assigns an error code to the
+    external variable #merror_code.  */
+
+/***ja
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤Ë°ìʸ»úÌ᤹.
+
+    ´Ø¿ô mconv_ungetc () ¤Ï¡¢¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ $CONVERTER ¤Ëʸ»ú $C 
+    ¤ò²¡¤·Ì᤹¡£Ìᤵ¤ì¤ëʸ»ú¿ô¤ËÀ©¸Â¤Ï¤Ê¤¤¡£¤³¤Î¸å¤Ç mconv_getc () 
+    ¤ò¸Æ¤Ó½Ð¤·¤¿ºÝ¤Ë¤Ï¡¢ºÇ¸å¤ËÌᤵ¤ì¤¿Ê¸»ú¤¬ºÇ½é¤ËÆɤޤì¤ë¡£Ìᤵ¤ì¤¿Ê¸»ú¤Ï 
+    $CONVERTER ¤ÎÆâÉô¤ËÃߤ¨¤é¤ì¤ë¤À¤±¤Ç¤¢¤ê¡¢¼ÂºÝ¤ËÆþÎϸ»¤Ë½ñ¤­¹þ¤Þ¤ì¤ë¤ï¤±¤Ç¤Ï¤Ê¤¤¡£
+    $CONVERTER ¤ÎÆâÉô¾õÂÖ¤ÏɬÍפ˱þ¤¸¤Æ¹¹¿·¤µ¤ì¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_ungetc () ¤Ï $C ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c
+    EOF ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_CODING, @c MERROR_CHAR
+
+    @seealso
+    mconv_getc (), mconv_putc (), mconv_gets ()  */
+
+int
+mconv_ungetc (MConverter *converter, int c)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+
+  M_CHECK_CHAR (c, EOF);
+
+  converter->result = MCONVERSION_RESULT_SUCCESS;
+  mtext_cat_char (internal->unread, c);
+  return c;
+}
+
+/*=*/
+
+/***en
+    @brief Write a character via a code converter.
+
+    The mconv_putc () function writes character $C to the buffer area
+    or the stream that is currently bound to code converter
+    $CONVERTER.  The encoder of $CONVERTER is used to encode the
+    character.  The number of bytes actually written is set to the @c
+    nbytes member of $CONVERTER.  The internal status of $CONVERTER
+    is updated appropriately.
+
+    @return
+    If the operation was successful, mconv_putc () returns $C.
+    If an error is detected, it returns @c EOF and assigns
+    an error code to the external variable #merror_code.  */
+
+/***ja
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ò·Ðͳ¤·¤Æ°ìʸ»ú½ñ¤­½Ð¤¹.
+
+    ´Ø¿ô mconv_putc () ¤Ï¡¢¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ $CONVERTER 
+    ¤Ë¸½ºß·ë¤ÓÉÕ¤±¤é¤ì¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼¥à¤Ëʸ»ú $C 
+    ¤ò½ñ¤­½Ð¤¹¡£Ê¸»ú¤Î¥¨¥ó¥³¡¼¥É¤Ë¤Ï $CONVERTER 
+    ¤Î¥¨¥ó¥³¡¼¥À¤¬ÍѤ¤¤é¤ì¤ë¡£¼ÂºÝ¤Ë½ñ¤­½Ð¤µ¤ì¤¿¥Ð¥¤¥È¿ô¤Ï¡¢$CONVERTER ¤Î¥á¥ó¥Ð¡¼
+    @c nbytes ¤Ë¥»¥Ã¥È¤µ¤ì¤ë¡£$CONVERTER ¤ÎÆâÉô¾õÂÖ¤ÏɬÍפ˱þ¤¸¤Æ¹¹¿·¤µ¤ì¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_putc () ¤Ï $C ¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï
+    @c EOF ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_CODING, @c MERROR_IO, @c MERROR_CHAR
+
+    @seealso
+    mconv_getc (), mconv_ungetc (), mconv_gets ()  */
+
+int
+mconv_putc (MConverter *converter, int c)
+{
+  MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
+
+  M_CHECK_CHAR (c, EOF);
+  mtext_reset (internal->work_mt);
+  mtext_cat_char (internal->work_mt, c);
+  if (mconv_encode_range (converter, internal->work_mt, 0, 1) < 0)
+    return EOF;
+  return c;
+}
+
+/*=*/
+
+/***en
+    @brief Read a line using a code converter.
+
+    The mconv_gets () function reads one line from the buffer area or
+    the stream that is currently bound to code converter $CONVERTER.
+    The decoder of $CONVERTER is used for decoding.  The decoded
+    character sequence is appended at the end of M-text $MT.  The
+    final newline character in the original byte sequence is not
+    appended.  The internal status of $CONVERTER is updated
+    appropriately.
+
+    @return
+    If the operation was successful, mconv_gets () returns the
+    modified $MT.  If it encounters EOF without reading a single
+    character, it returns $MT without changing it.  If an error is
+    detected, it returns @c NULL and assigns an error code to 
+    #merror_code.  */
+
+/***ja
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ò»È¤Ã¤Æ°ì¹ÔÆɤ߹þ¤à.
+
+    ´Ø¿ô mconv_gets () ¤Ï¡¢¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ $CONVERTER 
+    ¤Ë¸½ºß·ë¤ÓÉÕ¤±¤é¤ì¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼¥à¤«¤é 1 ¹Ô¤òÆɤ߹þ¤à¡£
+    ¥Ð¥¤¥ÈÎó¤Î¥Ç¥³¡¼¥É¤Ë¤Ï $CONVERTER 
+    ¤Î¥Ç¥³¡¼¥À¤¬ÍѤ¤¤é¤ì¤ë¡£¥Ç¥³¡¼¥É¤µ¤ì¤¿Ê¸»úÎó¤Ï M-text $MT 
+    ¤ÎËöÈø¤ËÄɲ䵤ì¤ë¡£¸µ¤Î¥Ð¥¤¥ÈÎó¤Î½ªÃ¼²þ¹Ôʸ»ú¤ÏÄɲ䵤ì¤Ê¤¤¡£
+    $CONVERTER ¤ÎÆâÉô¾õÂÖ¤ÏɬÍפ˱þ¤¸¤Æ¹¹¿·¤µ¤ì¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_gets () ¤ÏÊѹ¹¤µ¤ì¤¿ $MT
+    ¤òÊÖ¤¹¡£¤â¤·1ʸ»ú¤âÆɤޤº¤Ë EOF ¤ËÁø¶ø¤·¤¿¾ì¹ç¤Ï¡¢$MT 
+    ¤òÊѹ¹¤»¤º¤Ë¤½¤Î¤Þ¤ÞÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤·¡¢
+    #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_CODING
+
+    @seealso
+    mconv_getc (), mconv_ungetc (), mconv_putc ()  */
+
+MText *
+mconv_gets (MConverter *converter, MText *mt)
+{
+  int c;
+
+  M_CHECK_READONLY (mt, NULL);
+  if (mt->format != MTEXT_FORMAT_UTF_8)
+    mtext__adjust_format (mt, MTEXT_FORMAT_UTF_8);
+
+  while (1)
+    {
+      c = mconv_getc (converter);
+      if (c == EOF || c == '\n')
+       break;
+      mtext_cat_char (mt, c);
+    }
+  if (c == EOF && converter->result != MCONVERSION_RESULT_SUCCESS)
+    /* mconv_getc () sets #merror_code */
+    return NULL;
+  return mt;
+}
+
+/*=*/
+
+/*** @} */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/coding.h b/src/coding.h
new file mode 100644 (file)
index 0000000..cb7e07a
--- /dev/null
@@ -0,0 +1,30 @@
+/* coding.h -- header file for the code conversion module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_CODING_H_
+#define _M17N_CODING_H_
+
+extern void mconv__register_charset_coding (MSymbol name);
+
+extern int mcoding__load_from_database ();
+
+#endif /* _M17N_CODING_H_ */
diff --git a/src/config.h.in b/src/config.h.in
new file mode 100644 (file)
index 0000000..ce5a5d5
--- /dev/null
@@ -0,0 +1,455 @@
+/* src/config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Define if building universal (internal helper macro) */
+#undef AC_APPLE_UNIVERSAL_BUILD
+
+/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
+   systems. This function is required for `alloca.c' support on those systems.
+   */
+#undef CRAY_STACKSEG_END
+
+/* Define to 1 if using `alloca.c'. */
+#undef C_ALLOCA
+
+/* Define to loadable module extention */
+#undef DLOPEN_SHLIB_EXT
+
+/* Define to 1 if translation of program messages to the user's native
+   language is requested. */
+#undef ENABLE_NLS
+
+/* Define to 1 if you have `alloca', as a function or macro. */
+#undef HAVE_ALLOCA
+
+/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
+   */
+#undef HAVE_ALLOCA_H
+
+/* Define to 1 if you have Anthy library and header file */
+#undef HAVE_ANTHY
+
+/* Define to 1 if you have the <argz.h> header file. */
+#undef HAVE_ARGZ_H
+
+/* Define to 1 if you have the `asprintf' function. */
+#undef HAVE_ASPRINTF
+
+/* Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the
+   CoreFoundation framework. */
+#undef HAVE_CFLOCALECOPYCURRENT
+
+/* Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in
+   the CoreFoundation framework. */
+#undef HAVE_CFPREFERENCESCOPYAPPVALUE
+
+/* Define if the GNU dcgettext() function is already present or preinstalled.
+   */
+#undef HAVE_DCGETTEXT
+
+/* Define to 1 if you have the declaration of `feof_unlocked', and to 0 if you
+   don't. */
+#undef HAVE_DECL_FEOF_UNLOCKED
+
+/* Define to 1 if you have the declaration of `fgets_unlocked', and to 0 if
+   you don't. */
+#undef HAVE_DECL_FGETS_UNLOCKED
+
+/* Define to 1 if you have the declaration of `getc_unlocked', and to 0 if you
+   don't. */
+#undef HAVE_DECL_GETC_UNLOCKED
+
+/* Define to 1 if you have the declaration of `_snprintf', and to 0 if you
+   don't. */
+#undef HAVE_DECL__SNPRINTF
+
+/* Define to 1 if you have the declaration of `_snwprintf', and to 0 if you
+   don't. */
+#undef HAVE_DECL__SNWPRINTF
+
+/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
+   */
+#undef HAVE_DIRENT_H
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#undef HAVE_DLFCN_H
+
+/* Define to 1 if you have the function dlopen. */
+#undef HAVE_DLOPEN
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#undef HAVE_FCNTL_H
+
+/* Define to 1 if you have fontconfig library and header file. */
+#undef HAVE_FONTCONFIG
+
+/* Define to 1 if you have FreeType library and header file. */
+#undef HAVE_FREETYPE
+
+/* Define to 1 if you have Fribidi library and header file. */
+#undef HAVE_FRIBIDI
+
+/* Define to 1 if you have freetype/ftbdf.h. */
+#undef HAVE_FTBDF_H
+
+/* Define to 1 if you have the `fwprintf' function. */
+#undef HAVE_FWPRINTF
+
+/* Define to 1 or 2 if you have gd library and header file. */
+#undef HAVE_GD
+
+/* Define to 1 if you have the `getcwd' function. */
+#undef HAVE_GETCWD
+
+/* Define to 1 if you have the `getegid' function. */
+#undef HAVE_GETEGID
+
+/* Define to 1 if you have the `geteuid' function. */
+#undef HAVE_GETEUID
+
+/* Define to 1 if you have the `getgid' function. */
+#undef HAVE_GETGID
+
+/* Define to 1 if you have the `getpagesize' function. */
+#undef HAVE_GETPAGESIZE
+
+/* Define if the GNU gettext() function is already present or preinstalled. */
+#undef HAVE_GETTEXT
+
+/* Define to 1 if you have the `gettimeofday' function. */
+#undef HAVE_GETTIMEOFDAY
+
+/* Define to 1 if you have the `getuid' function. */
+#undef HAVE_GETUID
+
+/* Define if you have the iconv() function. */
+#undef HAVE_ICONV
+
+/* Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>. */
+#undef HAVE_INTMAX_T
+
+/* Define if <inttypes.h> exists and doesn't clash with <sys/types.h>. */
+#undef HAVE_INTTYPES_H
+
+/* Define if <inttypes.h> exists, doesn't clash with <sys/types.h>, and
+   declares uintmax_t. */
+#undef HAVE_INTTYPES_H_WITH_UINTMAX
+
+/* Define if ispell is available. */
+#undef HAVE_ISPELL
+
+/* Define if you have <langinfo.h> and nl_langinfo(CODESET). */
+#undef HAVE_LANGINFO_CODESET
+
+/* Define to 1 if you have the <langinfo.h> header file. */
+#undef HAVE_LANGINFO_H
+
+/* Define if your <locale.h> file defines LC_MESSAGES. */
+#undef HAVE_LC_MESSAGES
+
+/* Define if you have libthai */
+#undef HAVE_LIBTHAI
+
+/* Define to 1 if you have the <limits.h> header file. */
+#undef HAVE_LIMITS_H
+
+/* Define to 1 if you have the <locale.h> header file. */
+#undef HAVE_LOCALE_H
+
+/* Define if you have the 'long double' type. */
+#undef HAVE_LONG_DOUBLE
+
+/* Define if you have the 'long long' type. */
+#undef HAVE_LONG_LONG
+
+/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
+   to 0 otherwise. */
+#undef HAVE_MALLOC
+
+/* Define to 1 if you have the <malloc.h> header file. */
+#undef HAVE_MALLOC_H
+
+/* Define to 1 if you have the `memmove' function. */
+#undef HAVE_MEMMOVE
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the `mempcpy' function. */
+#undef HAVE_MEMPCPY
+
+/* Define to 1 if you have the `memset' function. */
+#undef HAVE_MEMSET
+
+/* Define to 1 if you have a working `mmap' system call. */
+#undef HAVE_MMAP
+
+/* Define to 1 if you have the `munmap' function. */
+#undef HAVE_MUNMAP
+
+/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
+#undef HAVE_NDIR_H
+
+/* Define to 1 if you have the `nl_langinfo' function. */
+#undef HAVE_NL_LANGINFO
+
+/* Define to 1 if you have the <nl_types.h> header file. */
+#undef HAVE_NL_TYPES_H
+
+/* Define to 1 if you have OTF library and header file. */
+#undef HAVE_OTF
+
+/* Define to 1 if the OTF library has OTF_drive_gpos2(). */
+#undef HAVE_OTF_DRIVE_GPOS2
+
+/* Define if your printf() function supports format strings with positions. */
+#undef HAVE_POSIX_PRINTF
+
+/* Define to 1 if you have the `putenv' function. */
+#undef HAVE_PUTENV
+
+/* Define to 1 if your system has a GNU libc compatible `realloc' function,
+   and to 0 otherwise. */
+#undef HAVE_REALLOC
+
+/* Define to 1 if you have the `regcomp' function. */
+#undef HAVE_REGCOMP
+
+/* Define to 1 if you have the `setenv' function. */
+#undef HAVE_SETENV
+
+/* Define to 1 if you have the `setlocale' function. */
+#undef HAVE_SETLOCALE
+
+/* Define to 1 if you have the `snprintf' function. */
+#undef HAVE_SNPRINTF
+
+/* Define to 1 if `stat' has the bug that it succeeds when given the
+   zero-length file name argument. */
+#undef HAVE_STAT_EMPTY_STRING_BUG
+
+/* Define to 1 if you have the <stddef.h> header file. */
+#undef HAVE_STDDEF_H
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define if <stdint.h> exists, doesn't clash with <sys/types.h>, and declares
+   uintmax_t. */
+#undef HAVE_STDINT_H_WITH_UINTMAX
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the `stpcpy' function. */
+#undef HAVE_STPCPY
+
+/* Define to 1 if you have the `strcasecmp' function. */
+#undef HAVE_STRCASECMP
+
+/* Define to 1 if you have the `strchr' function. */
+#undef HAVE_STRCHR
+
+/* Define to 1 if you have the `strcoll' function and it is properly defined.
+   */
+#undef HAVE_STRCOLL
+
+/* Define to 1 if you have the `strdup' function. */
+#undef HAVE_STRDUP
+
+/* Define to 1 if you have the `strftime' function. */
+#undef HAVE_STRFTIME
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the `strtoul' function. */
+#undef HAVE_STRTOUL
+
+/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
+   */
+#undef HAVE_SYS_DIR_H
+
+/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
+   */
+#undef HAVE_SYS_NDIR_H
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#undef HAVE_SYS_PARAM_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#undef HAVE_SYS_TIME_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define if you have some Thai word-segmentation library */
+#undef HAVE_THAI_WORDSEG
+
+/* Define to 1 if you have the `tsearch' function. */
+#undef HAVE_TSEARCH
+
+/* Define if you have the 'uintmax_t' type in <stdint.h> or <inttypes.h>. */
+#undef HAVE_UINTMAX_T
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define if you have the 'unsigned long long' type. */
+#undef HAVE_UNSIGNED_LONG_LONG
+
+/* Define if you have the 'wchar_t' type. */
+#undef HAVE_WCHAR_T
+
+/* Define to 1 if you have the `wcslen' function. */
+#undef HAVE_WCSLEN
+
+/* Define if you have the 'wint_t' type. */
+#undef HAVE_WINT_T
+
+/* Define if you have the wordcut library and header file */
+#undef HAVE_WORDCUT
+
+/* Define if you have the old version of wordcut library */
+#undef HAVE_WORDCUT_OLD
+
+/* Define to 1 if you have X11. */
+#undef HAVE_X11
+
+/* Define to 1 if you have the Xaw header files. */
+#undef HAVE_X11_XAW_COMMAND_H
+
+/* Define to 1 if you have Xft2 library and header file. */
+#undef HAVE_XFT2
+
+/* Define to 1 if you have libxml2 library and header file */
+#undef HAVE_XML2
+
+/* Define to 1 if you have the `__argz_count' function. */
+#undef HAVE___ARGZ_COUNT
+
+/* Define to 1 if you have the `__argz_next' function. */
+#undef HAVE___ARGZ_NEXT
+
+/* Define to 1 if you have the `__argz_stringify' function. */
+#undef HAVE___ARGZ_STRINGIFY
+
+/* Define to 1 if you have the `__fsetlocking' function. */
+#undef HAVE___FSETLOCKING
+
+/* Define as const if the declaration of iconv() needs const. */
+#undef ICONV_CONST
+
+/* Define if integer division by zero raises signal SIGFPE. */
+#undef INTDIV0_RAISES_SIGFPE
+
+/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
+   slash. */
+#undef LSTAT_FOLLOWS_SLASHED_SYMLINK
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+   */
+#undef LT_OBJDIR
+
+/* Name of package */
+#undef PACKAGE
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the home page for this package. */
+#undef PACKAGE_URL
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Define if <inttypes.h> exists and defines unusable PRI* macros. */
+#undef PRI_MACROS_BROKEN
+
+/* Define as the maximum value of type 'size_t', if the system doesn't define
+   it. */
+#undef SIZE_MAX
+
+/* If using the C implementation of alloca, define if you know the
+   direction of stack growth for your system; otherwise it will be
+   automatically deduced at runtime.
+       STACK_DIRECTION > 0 => grows toward higher addresses
+       STACK_DIRECTION < 0 => grows toward lower addresses
+       STACK_DIRECTION = 0 => direction of growth unknown */
+#undef STACK_DIRECTION
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#undef TIME_WITH_SYS_TIME
+
+/* Define to 1 if your <sys/time.h> declares `struct tm'. */
+#undef TM_IN_SYS_TIME
+
+/* Version number of package */
+#undef VERSION
+
+/* Define tdict file name */
+#undef WORDCUT_TDICT
+
+/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+   significant byte first (like Motorola and SPARC, unlike Intel). */
+#if defined AC_APPLE_UNIVERSAL_BUILD
+# if defined __BIG_ENDIAN__
+#  define WORDS_BIGENDIAN 1
+# endif
+#else
+# ifndef WORDS_BIGENDIAN
+#  undef WORDS_BIGENDIAN
+# endif
+#endif
+
+/* Define to 1 if the X Window System is missing or not being used. */
+#undef X_DISPLAY_MISSING
+
+/* Define to empty if `const' does not conform to ANSI C. */
+#undef const
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+   calls it, or to nothing if 'inline' is not supported under any name.  */
+#ifndef __cplusplus
+#undef inline
+#endif
+
+/* Define to rpl_malloc if the replacement function should be used. */
+#undef malloc
+
+/* Define to `long int' if <sys/types.h> does not define. */
+#undef off_t
+
+/* Define as the type of the result of subtracting two pointers, if the system
+   doesn't define it. */
+#undef ptrdiff_t
+
+/* Define to rpl_realloc if the replacement function should be used. */
+#undef realloc
+
+/* Define to empty if the C compiler doesn't support this keyword. */
+#undef signed
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+#undef size_t
+
+/* Define to unsigned long or unsigned long long if <stdint.h> and
+   <inttypes.h> don't define. */
+#undef uintmax_t
diff --git a/src/database.c b/src/database.c
new file mode 100644 (file)
index 0000000..a31a2c1
--- /dev/null
@@ -0,0 +1,1539 @@
+/* database.c -- database module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nDatabase
+    @brief The m17n database and API for it.
+
+    The m17n library acquires various kinds of information
+    from data in the <i> m17n database</i> on demand.  Application
+    programs can also add/load their original data to/from the m17n
+    database by setting the variable #mdatabase_dir to an
+    application-specific directory and storing data in it.  Users can
+    overwrite those data by storing preferable data in the directory
+    specified by the environment variable "M17NDIR", or if it is not
+    set, in the directory "~/.m17n.d".
+
+    The m17n database contains multiple heterogeneous data, and each
+    data is identified by four tags; TAG0, TAG1, TAG2, TAG3.  Each tag
+    must be a symbol.
+
+    TAG0 specifies the type of data stored in the database as below.
+
+    @li
+    If TAG0 is #Mchar_table, the data is of the @e chartable @e
+    type and provides information about each character.  In this case,
+    TAG1 specifies the type of the information and must be #Msymbol,
+    #Minteger, #Mstring, #Mtext, or #Mplist.  TAG2 and TAG3 can be any
+    symbols.
+
+    @li
+    If TAG0 is #Mcharset, the data is of the @e charset @e type
+    and provides a decode/encode mapping table for a charset.  In this
+    case, TAG1 must be a symbol representing a charset.  TAG2 and TAG3
+    can be any symbols.
+
+    @li 
+    If TAG0 is neither #Mchar_table nor #Mcharset, the data is of
+    the @e plist @e type.  See the documentation of the 
+    mdatabase_load () function for the details.  
+    In this case, TAG1, TAG2, and TAG3 can be any symbols.
+
+    The notation \<TAG0, TAG1, TAG2, TAG3\> means a data with those
+    tags.
+
+    Application programs first calls the mdatabase_find () function to
+    get a pointer to an object of the type #MDatabase.  That object
+    holds information about the specified data.  When it is
+    successfully returned, the mdatabase_load () function loads the
+    data.  The implementation of the structure #MDatabase is
+    concealed from application programs.
+*/
+
+/***ja
+    @addtogroup m17nDatabase
+    @brief m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë¤È¤½¤ì¤Ë´Ø¤¹¤ë API.
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤ÏɬÍפ˱þ¤¸¤ÆưŪ¤Ë @e m17n @e ¥Ç¡¼¥¿¥Ù¡¼¥¹ 
+    ¤«¤é¾ðÊó¤ò¼èÆÀ¤¹¤ë¡£¤Þ¤¿¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤â¡¢Æȼ«¤Î¥Ç¡¼¥¿¤ò 
+    m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤ËÄɲä·¡¢¤½¤ì¤òưŪ¤Ë¼èÆÀ¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
+    ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤¬Æȼ«¤Î¥Ç¡¼¥¿¤òÄɲᦼèÆÀ¤¹¤ë¤Ë¤Ï¡¢ÊÑ¿ô 
+    #mdatabase_dir ¤Ë¤½¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¸ÇÍ­¤Î¥Ç¥£¥ì¥¯¥È¥ê¤ò¥»¥Ã¥È¤·¡¢
+    ¤½¤ÎÃæ¤Ë¥Ç¡¼¥¿¤ò³ÊǼ¤¹¤ë¡£¥æ¡¼¥¶¤¬¤½¤Î¥Ç¡¼¥¿¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥È¤·¤¿¤¤
+    ¤È¤­¤Ï¡¢´Ä¶­ÊÑ¿ô "M17NDIR" ¤Ç»ØÄꤵ¤ì¤ë¥Ç¥£¥ì¥¯¥È¥ê¡Ê»ØÄꤵ¤ì¤Æ¤¤¤Ê
+    ¤¤¤È¤­¤Ï "~/.m17n.d" ¤È¤¤¤¦¥Ç¥£¥ì¥¯¥È¥ê¡Ë¤ËÊ̤Υǡ¼¥¿¤òÃÖ¤¯¡£
+
+    m17n 
+    ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë¤ÏÊ£¿ô¤Î¿Íͤʥǡ¼¥¿¤¬´Þ¤Þ¤ì¤Æ¤ª¤ê¡¢³Æ¥Ç¡¼¥¿¤Ï
+    TAG0, TAG1, TAG2, TAG3¡Ê¤¹¤Ù¤Æ¥·¥ó¥Ü¥ë¡Ë¤Î£´¤Ä¤Î¥¿¥°¤Ë¤è¤Ã¤Æ¼±Ê̤µ¤ì¤ë¡£
+
+    TAG0 ¤Ë¤è¤Ã¤Æ¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹Æâ¤Î¥Ç¡¼¥¿¤Î¥¿¥¤¥×¤Ï¼¡¤Î¤è¤¦¤Ë»ØÄꤵ¤ì¤ë¡£
+
+    @li 
+    TAG0 ¤¬ #Mchar_table ¤Ç¤¢¤ë¥Ç¡¼¥¿¤Ï @e chartable¥¿¥¤¥× 
+    ¤È¸Æ¤Ð¤ì¡¢³Æʸ»ú¤Ë´Ø¤¹¤ë¾ðÊó¤òÄ󶡤¹¤ë¡£¤³¤Î¾ì¹ç
+    TAG1 ¤Ï¾ðÊó¤Î¼ïÎà¤ò»ØÄꤹ¤ë¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢#Msymbol, #Minteger, #Mstring,
+    #Mtext, #Mplist ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£TAG2 ¤È TAG3 ¤ÏǤ°Õ¤Î¥·¥ó¥Ü¥ë¤Ç¤è¤¤¡£
+
+    @li 
+    TAG0 ¤¬ #Mcharset ¤Ç¤¢¤ë¥Ç¡¼¥¿¤Ï @e charset¥¿¥¤¥× 
+    ¤È¸Æ¤Ð¤ì¡¢Ê¸»ú¥»¥Ã¥ÈÍѤΥǥ³¡¼¥É¡¿¥¨¥ó¥³¡¼¥É¥Þ¥Ã¥×¤òÄ󶡤¹¤ë¡£¤³¤Î¾ì¹ç TAG1
+    ¤Ïʸ»ú¥»¥Ã¥È¤Î¥·¥ó¥Ü¥ë¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£TAG2 ¤È TAG3
+    ¤ÏǤ°Õ¤Î¥·¥ó¥Ü¥ë¤Ç¤è¤¤¡£
+
+    @li
+    TAG0 ¤¬ #Mchar_table ¤Ç¤â #Mcharset ¤Ç¤â¤Ê¤¤¾ì¹ç¡¢¤½¤Î¥Ç¡¼¥¿¤Ï @e
+    plist¥¿¥¤¥× ¤Ç¤¢¤ë¡£¾ÜºÙ¤Ë´Ø¤·¤Æ¤Ï´Ø¿ô mdatabase_load () 
+    ¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£¤³¤Î¾ì¹ç TAG1¡¢TAG2¡¢TAG3 ¤ÏǤ°Õ¤Î¥·¥ó¥Ü¥ë¤Ç¤è¤¤¡£
+
+    ÆÃÄê¤Î¥¿¥°¤ò»ý¤Ä¥Ç¡¼¥¿¥Ù¡¼¥¹¤ò \<TAG0, TAG1, TAG2, TAG3\> 
+    ¤È¤¤¤¦·Á¼°¤Çɽ¤¹¡£
+
+    ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï¡¢¤Þ¤º´Ø¿ô mdatabase_find () 
+    ¤ò»È¤Ã¤Æ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë´Ø¤¹¤ë¾ðÊó¤òÊÝ»ý¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¡Ê#MDatabase
+    ·¿¡Ë¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÆÀ¤ë¡£¤½¤ì¤ËÀ®¸ù¤·¤¿¤é¡¢ mdatabase_load () 
+    ¤Ë¤è¤Ã¤Æ¼ÂºÝ¤Ë¥Ç¡¼¥¿¥Ù¡¼¥¹¤ò¥í¡¼¥É¤¹¤ë¡£¹½Â¤ÂΠ#MDatabase 
+    ¼«¿È¤¬¤É¤¦¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¤«¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤Ï¸«¤¨¤Ê¤¤¡£
+
+    @latexonly \IPAlabel{database} @endlatexonly
+*/
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <limits.h>
+#include <glob.h>
+#include <time.h>
+#include <libgen.h>
+
+#include "m17n-core.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "mtext.h"
+#include "character.h"
+#include "database.h"
+#include "plist.h"
+
+/** The file containing a list of databases.  */
+#define MDB_DIR "mdb.dir"
+/** Length of MDB_DIR.  */
+#define MDB_DIR_LEN 7
+
+#define MAX_TIME(TIME1, TIME2) ((TIME1) >= (TIME2) ? (TIME1) : (TIME2))
+
+#define GEN_PATH(path, dir, dir_len, file, file_len)   \
+  (dir_len + file_len > PATH_MAX ? 0                   \
+   : (memcpy (path, dir, dir_len),                     \
+      memcpy (path + dir_len, file, file_len),         \
+      path[dir_len + file_len] = '\0', 1))
+
+static MSymbol Masterisk;
+static MSymbol Mversion;
+
+/** Structure for a data in the m17n database.  */
+
+struct MDatabase
+{
+  /** Tags to identify the data.  <tag>[0] specifies the type of
+      database.  If it is #Mchar_table, the type is @e chartable, if
+      it is #Mcharset, the type is @e charset, otherwise the type is
+      @e plist.  */
+  MSymbol tag[4];
+
+  void *(*loader) (MSymbol *tags, void *extra_info);
+
+  /** The meaning of the value is dependent on <loader>.  If <loader>
+      is load_database (), the value is a string of the file name that
+      contains the data.  */
+  void *extra_info;
+};
+
+static MPlist *mdatabase__list;
+
+static int
+read_number (char *buf, int *i)
+{
+  int idx = *i;
+  int c = buf[idx++];
+  int n;
+
+  if (!c)
+    return -1;
+
+  while (c && isspace (c)) c = buf[idx++];
+
+  if (c == '0')
+    {
+      if (buf[idx] == 'x')
+       {
+         for (idx++, c = 0; (n = hex_mnemonic[(unsigned) buf[idx]]) < 16;
+              idx++)
+           c  = (c << 4) | n;
+         *i = idx;
+         return c;
+       }
+      c = 0;
+    }
+  else if (c == '\'')
+    {
+      c = buf[idx++];
+      if (c == '\\')
+       {
+         c = buf[idx++];
+         n = escape_mnemonic[c];
+         if (n != 255)
+           c = n;
+       }
+      while (buf[idx] && buf[idx++] != '\'');
+      *i = idx;
+      return c;
+    }
+  else if (hex_mnemonic[c] < 10)
+    c -= '0';
+  else
+    return -1;
+
+  while ((n = hex_mnemonic[(unsigned) buf[idx]]) < 10)
+    c = (c * 10) + n, idx++;
+  *i = idx;
+  return c;
+}
+
+
+/** Load a data of type @c chartable from the file FD, and return the
+    newly created chartable.  */
+
+static void *
+load_chartable (FILE *fp, MSymbol type)
+{
+  int c, from, to;
+  char buf[1024];
+  void *val;
+  MCharTable *table;
+
+  if (! fp)
+    MERROR (MERROR_DB, NULL);
+
+  table = mchartable (type, (type == Msymbol ? (void *) Mnil
+                            : type == Minteger ? (void *) -1
+                            : NULL));
+
+  while (! feof (fp))
+    {
+      int i, len;
+
+      for (len = 0; len < 1023 && (c = getc (fp)) != EOF && c != '\n'; len++)
+       buf[len] = c;
+      buf[len] = '\0';   
+      if (hex_mnemonic[(unsigned) buf[0]] >= 10)
+       /* skip comment/invalid line */
+       continue;
+      i = 0;
+      from = read_number (buf, &i);
+      if (buf[i] == '-')
+       i++, to = read_number (buf, &i);
+      else
+       to = from;
+      if (from < 0 || to < from)
+       continue;
+
+      while (buf[i] && isspace ((unsigned) buf[i])) i++;
+      c = buf[i];
+      if (!c)
+       continue;
+
+      if (type == Mstring)
+       {
+         /* VAL is a C-string.  */
+         if (! (val = strdup (buf + i)))
+           MEMORY_FULL (MERROR_DB);
+       }
+      else if (type == Minteger)
+       {
+         /* VAL is an integer.  */
+         int positive = 1;
+         int n;
+
+         if (c == '-')
+           i++, positive = -1;
+         n = read_number (buf, &i);
+         if (n < 0)
+           goto label_error;
+         val = (void *) (n * positive);
+       }
+      else if (type == Mtext)
+       {
+         /* VAL is an M-text.  */
+         MText *mt;
+         if (c == '"')
+           mt = mtext__from_data (buf + i, len - i - 1, MTEXT_FORMAT_UTF_8, 1);
+         else
+           {
+             mt = mtext ();
+             while ((c = read_number (buf, &i)) >= 0)
+               mt = mtext_cat_char (mt, c);
+           }
+         val = (void *) mt;
+       }
+      else if (type == Msymbol)
+       {
+         char *p = buf + i;
+
+         while (*p && ! isspace (*p)) 
+           {
+             if (*p == '\\' && p[1] != '\0')
+               {
+                 memmove (p, p + 1, buf + len - (p + 1));
+                 len--;
+               }
+             p++;
+           }
+         *p = '\0';
+         if (! strcmp (buf + i, "nil"))
+           val = (void *) Mnil;
+         else
+           val = (void *) msymbol (buf + i);
+       }
+      else if (type == Mplist)
+       {
+         val = (void *) mplist__from_string ((unsigned char *) buf + i,
+                                             strlen (buf + i));
+       }
+      else
+       val = NULL;
+
+      if (from == to)
+       mchartable_set (table, from, val);
+      else
+       mchartable_set_range (table, from, to, val);
+    }
+  return table;
+
+ label_error:
+  M17N_OBJECT_UNREF (table);
+  MERROR (MERROR_DB, NULL);
+}
+
+
+static char *
+gen_database_name (char *buf, MSymbol *tags)
+{
+  int i;
+
+  strcpy (buf, msymbol_name (tags[0]));
+  for (i = 1; i < 4; i++)
+    {
+      strcat (buf, ",");
+      strcat (buf, msymbol_name (tags[i]));
+    }
+  return buf;
+}
+
+/* Return the absolute file name for DB_INFO->filename or NULL if no
+   absolute file name was found.  If BUF is non-NULL, store the result
+   of `stat' call in it.  In that case, set *RESULT to the return
+   value of `stat'.  */
+
+char *
+get_database_file (MDatabaseInfo *db_info, struct stat *buf, int *result)
+{
+  if (db_info->absolute_filename)
+    {
+      if (buf)
+       *result = stat (db_info->absolute_filename, buf);
+    }
+  else
+    {
+      struct stat stat_buf;
+      struct stat *statbuf = buf ? buf : &stat_buf;
+      int res;
+      MPlist *plist;
+      char path[PATH_MAX + 1];
+
+      MPLIST_DO (plist, mdatabase__dir_list)
+       {
+         MDatabaseInfo *dir_info = MPLIST_VAL (plist);
+
+         if (dir_info->status != MDB_STATUS_DISABLED
+             && GEN_PATH (path, dir_info->filename, dir_info->len,
+                          db_info->filename, db_info->len)
+             && (res = stat (path, statbuf)) == 0)
+           {
+             db_info->absolute_filename = strdup (path);
+             if (result)
+               *result = res;
+             break;
+           }
+       }
+    }
+
+  return db_info->absolute_filename;
+}
+
+static void *
+load_database (MSymbol *tags, void *extra_info)
+{
+  MDatabaseInfo *db_info = extra_info;
+  void *value;
+  char *filename = get_database_file (db_info, NULL, NULL);
+  FILE *fp;
+  int mdebug_flag = MDEBUG_DATABASE;
+  char buf[256];
+
+  MDEBUG_PRINT1 (" [DB] <%s>", gen_database_name (buf, tags));
+  if (! filename || ! (fp = fopen (filename, "r")))
+    {
+      if (filename)
+       MDEBUG_PRINT1 (" open fail: %s\n", filename);
+      else
+       MDEBUG_PRINT1 (" not found: %s\n", db_info->filename);
+      MERROR (MERROR_DB, NULL);
+    }
+
+  MDEBUG_PRINT1 (" from %s\n", filename);
+
+  if (tags[0] == Mchar_table)
+    value = load_chartable (fp, tags[1]);
+  else if (tags[0] == Mcharset)
+    {
+      if (! mdatabase__load_charset_func)
+       MERROR (MERROR_DB, NULL);
+      value = (*mdatabase__load_charset_func) (fp, tags[1]);
+    }
+  else
+    value = mplist__from_file (fp, NULL);
+  fclose (fp);
+
+  if (! value)
+    MERROR (MERROR_DB, NULL);
+  db_info->time = time (NULL);
+  return value;
+}
+
+
+/** Return a newly allocated MDatabaseInfo for DIRNAME.  */
+
+static MDatabaseInfo *
+get_dir_info (char *dirname)
+{
+  MDatabaseInfo *dir_info;
+
+  MSTRUCT_CALLOC (dir_info, MERROR_DB);
+  if (dirname)
+    {
+      int len = strlen (dirname);
+
+      if (len + MDB_DIR_LEN < PATH_MAX)
+       {
+         MTABLE_MALLOC (dir_info->filename, len + 2, MERROR_DB);
+         memcpy (dir_info->filename, dirname, len + 1);
+         /* Append PATH_SEPARATOR if DIRNAME doesn't end with it.  */
+         if (dir_info->filename[len - 1] != PATH_SEPARATOR)
+           {
+             dir_info->filename[len] = PATH_SEPARATOR;
+             dir_info->filename[++len] = '\0';
+           }
+         dir_info->len = len;
+         dir_info->status = MDB_STATUS_OUTDATED;
+       }
+      else
+       dir_info->status = MDB_STATUS_DISABLED; 
+    }
+  else
+    dir_info->status = MDB_STATUS_DISABLED;
+  return dir_info;
+}
+
+static void register_databases_in_files (MSymbol tags[4],
+                                        char *filename, int len);
+
+static MDatabase *
+find_database (MSymbol tags[4])
+{
+  MPlist *plist;
+  int i;
+  MDatabase *mdb;
+  
+  if (! mdatabase__list)
+    return NULL;
+  for (i = 0, plist = mdatabase__list; i < 4; i++)
+    {
+      MPlist *pl = mplist__assq (plist, tags[i]);
+      MPlist *p;
+
+      if ((p = mplist__assq (plist, Masterisk)))
+       {
+         MDatabaseInfo *db_info;
+         int j;
+
+         p = MPLIST_PLIST (p);
+         for (j = i + 1; j < 4; j++)
+           p = MPLIST_PLIST (MPLIST_NEXT (p));
+         mdb = MPLIST_VAL (MPLIST_NEXT (p));
+         db_info = mdb->extra_info;
+         if (db_info->status != MDB_STATUS_DISABLED)
+           {
+             register_databases_in_files (mdb->tag,
+                                          db_info->filename, db_info->len);
+             db_info->status = MDB_STATUS_DISABLED;
+             return find_database (tags);
+           }
+       }
+      if (! pl)
+       return NULL;
+      plist = MPLIST_PLIST (pl);
+      plist = MPLIST_NEXT (plist);
+    }
+  mdb = MPLIST_VAL (plist);
+  return mdb;
+}
+
+static void
+free_db_info (MDatabaseInfo *db_info)
+{
+  free (db_info->filename);
+  if (db_info->absolute_filename
+      && db_info->filename != db_info->absolute_filename)
+    free (db_info->absolute_filename);
+  M17N_OBJECT_UNREF (db_info->properties);
+  free (db_info);
+}
+
+static int
+check_version (MText *version)
+{
+  char *verstr = (char *) MTEXT_DATA (version);
+  char *endp = verstr + mtext_nbytes (version);
+  int ver[3];
+  int i;
+
+  ver[0] = ver[1] = ver[2] = 0;
+  for (i = 0; verstr < endp; verstr++)
+    {
+      if (*verstr == '.')
+       {
+         i++;
+         if (i == 3)
+           break;
+         continue;
+       }
+      if (! isdigit (*verstr))
+       break;
+      ver[i] = ver[i] * 10 + (*verstr - '0');
+    }
+  return (ver[0] < M17NLIB_MAJOR_VERSION
+         || (ver[0] == M17NLIB_MAJOR_VERSION
+             && (ver[1] < M17NLIB_MINOR_VERSION
+                 || (ver[1] == M17NLIB_MINOR_VERSION
+                     && ver[2] <= M17NLIB_PATCH_LEVEL))));
+}
+
+static MDatabase *
+register_database (MSymbol tags[4],
+                  void *(*loader) (MSymbol *, void *),
+                  void *extra_info, enum MDatabaseStatus status,
+                  MPlist *properties)
+{
+  MDatabase *mdb;
+  MDatabaseInfo *db_info;
+  int i;
+  MPlist *plist;
+
+  if (properties)
+    {
+      MPLIST_DO (plist, properties)
+       if (MPLIST_PLIST_P (plist))
+         {
+           MPlist *p = MPLIST_PLIST (plist);
+
+           if (MPLIST_SYMBOL_P (p)
+               && MPLIST_SYMBOL (p) == Mversion
+               && MPLIST_MTEXT_P (MPLIST_NEXT (p)))
+             {
+               if (check_version (MPLIST_MTEXT (MPLIST_NEXT (p))))
+                 break;
+               return NULL;
+             }
+         }
+    }
+
+  for (i = 0, plist = mdatabase__list; i < 4; i++)
+    {
+      MPlist *pl = mplist__assq (plist, tags[i]);
+
+      if (pl)
+       pl = MPLIST_PLIST (pl);
+      else
+       {
+         pl = mplist ();
+         mplist_add (pl, Msymbol, tags[i]);
+         mplist_push (plist, Mplist, pl);
+         M17N_OBJECT_UNREF (pl);
+       }
+      plist = MPLIST_NEXT (pl);
+    }
+
+  if (MPLIST_TAIL_P (plist))
+    {
+      MSTRUCT_MALLOC (mdb, MERROR_DB);
+      for (i = 0; i < 4; i++)
+       mdb->tag[i] = tags[i];
+      mdb->loader = loader;
+      if (loader == load_database)
+       {
+         MSTRUCT_CALLOC (db_info, MERROR_DB);
+         mdb->extra_info = db_info;
+       }
+      else
+       {
+         db_info = NULL;
+         mdb->extra_info = extra_info;
+       }
+      mplist_push (plist, Mt, mdb);
+    }
+  else
+    {
+      mdb = MPLIST_VAL (plist);
+      if (loader == load_database)
+       db_info = mdb->extra_info;
+      else
+       db_info = NULL;
+    }
+
+  if (db_info)
+    {
+      db_info->status = status;
+      if (! db_info->filename
+         || strcmp (db_info->filename, (char *) extra_info) != 0)
+       {
+         if (db_info->filename)
+           free (db_info->filename);
+         if (db_info->absolute_filename
+             && db_info->filename != db_info->absolute_filename)
+           free (db_info->absolute_filename);
+         db_info->filename = strdup ((char *) extra_info);
+         db_info->len = strlen ((char *) extra_info);
+         db_info->time = 0;
+       }
+      if (db_info->filename[0] == PATH_SEPARATOR)
+       db_info->absolute_filename = db_info->filename;
+      else
+       db_info->absolute_filename = NULL;
+      M17N_OBJECT_UNREF (db_info->properties);
+      if (properties)
+       {
+         db_info->properties = properties;
+         M17N_OBJECT_REF (properties);
+       }
+    }
+
+  if (mdb->tag[0] == Mchar_table
+      && mdb->tag[2] != Mnil
+      && (mdb->tag[1] == Mstring || mdb->tag[1] == Mtext
+         || mdb->tag[1] == Msymbol || mdb->tag[1] == Minteger
+         || mdb->tag[1] == Mplist))
+    mchar__define_prop (mdb->tag[2], mdb->tag[1], mdb);
+  return mdb;
+}
+
+static void
+register_databases_in_files (MSymbol tags[4], char *filename, int len)
+{
+  int i, j;
+  MPlist *load_key = mplist ();
+  FILE *fp;
+  MPlist *plist, *pl;
+
+  MPLIST_DO (plist, mdatabase__dir_list)
+    {
+      glob_t globbuf;
+      int headlen;
+
+      if (filename[0] == PATH_SEPARATOR)
+       {
+         if (glob (filename, GLOB_NOSORT, NULL, &globbuf))
+           break;
+         headlen = 0;
+       }
+      else
+       {
+         MDatabaseInfo *d_info = MPLIST_VAL (plist);
+         char path[PATH_MAX + 1];
+
+         if (d_info->status == MDB_STATUS_DISABLED)
+           continue;
+         if (! GEN_PATH (path, d_info->filename, d_info->len, filename, len))
+           continue;
+         if (glob (path, GLOB_NOSORT, NULL, &globbuf))
+           continue;
+         headlen = d_info->len;
+       }
+
+      for (i = 0; i < globbuf.gl_pathc; i++)
+       {
+         if (! (fp = fopen (globbuf.gl_pathv[i], "r")))
+           continue;
+         pl = mplist__from_file (fp, load_key);
+         fclose (fp);
+         if (! pl)
+           continue;
+         if (MPLIST_PLIST_P (pl))
+           {
+             MPlist *p;
+             MSymbol tags2[4];
+
+             for (j = 0, p = MPLIST_PLIST (pl); j < 4 && MPLIST_SYMBOL_P (p);
+                  j++, p = MPLIST_NEXT (p))
+               tags2[j] = MPLIST_SYMBOL (p);
+             for (; j < 4; j++)
+               tags2[j] = Mnil;
+             for (j = 0; j < 4; j++)
+               if (tags[j] != Masterisk && tags[j] != tags2[j])
+                 break;
+             if (j == 4)
+               register_database (tags2, load_database,
+                                  globbuf.gl_pathv[i] + headlen,
+                                  MDB_STATUS_AUTO, p);
+           }
+         M17N_OBJECT_UNREF (pl);
+       }
+      globfree (&globbuf);
+      if (filename[0] == PATH_SEPARATOR)
+       break;
+    }
+  M17N_OBJECT_UNREF (load_key);
+}
+
+static int
+expand_wildcard_database (MPlist *plist)
+{
+  MDatabase *mdb;
+  MDatabaseInfo *db_info;
+
+  plist = MPLIST_NEXT (plist);
+  while (MPLIST_PLIST_P (plist))
+    {
+      plist = MPLIST_PLIST (plist);
+      plist = MPLIST_NEXT (plist);
+    }
+  mdb = MPLIST_VAL (plist);
+  if (mdb->loader == load_database
+      && (db_info = mdb->extra_info)
+      && db_info->status != MDB_STATUS_DISABLED)
+    {
+      register_databases_in_files (mdb->tag, db_info->filename, db_info->len);
+      db_info->status = MDB_STATUS_DISABLED;
+      return 1;
+    }
+  return 0;
+}
+
+\f
+/* Internal API */
+
+/** List of database directories.  */ 
+MPlist *mdatabase__dir_list;
+
+void *(*mdatabase__load_charset_func) (FILE *fp, MSymbol charset_name);
+
+int
+mdatabase__init ()
+{
+  MDatabaseInfo *dir_info;
+  char *path;
+
+  mdatabase__load_charset_func = NULL;
+
+  Mchar_table = msymbol ("char-table");
+  Mcharset = msymbol ("charset");
+  Masterisk = msymbol ("*");
+  Mversion = msymbol ("version");
+
+  mdatabase__dir_list = mplist ();
+  /** The macro M17NDIR specifies a directory where the system-wide
+    MDB_DIR file exists.  */
+  mplist_set (mdatabase__dir_list, Mt, get_dir_info (M17NDIR));
+
+  /* The variable mdatabase_dir specifies a directory where an
+     application program specific MDB_DIR file exists.  */
+  if (mdatabase_dir && strlen (mdatabase_dir) > 0)
+    mplist_push (mdatabase__dir_list, Mt, get_dir_info (mdatabase_dir));
+
+  /* The environment variable M17NDIR specifies a directory where a
+     user specific MDB_DIR file exists.  */
+  path = getenv ("M17NDIR");
+  if (path && strlen (path) > 0)
+    mplist_push (mdatabase__dir_list, Mt, get_dir_info (path));
+  else
+    {
+      /* If the env var M17NDIR is not set, check "~/.m17n.d".  */
+      char *home = getenv ("HOME");
+      int len;
+
+      if (home
+         && (len = strlen (home))
+         && (path = alloca (len + 9)))
+       {
+         strcpy (path, home);
+         if (path[len - 1] != PATH_SEPARATOR)
+           path[len++] = PATH_SEPARATOR;
+         strcpy (path + len, ".m17n.d");
+         dir_info = get_dir_info (path);
+         mplist_push (mdatabase__dir_list, Mt, dir_info);
+       }
+      else
+       mplist_push (mdatabase__dir_list, Mt, get_dir_info (NULL));
+    }
+
+  mdatabase__list = mplist ();
+  mdatabase__update ();
+  return 0;
+}
+
+void
+mdatabase__fini (void)
+{
+  MPlist *plist, *p0, *p1, *p2, *p3;
+
+  MPLIST_DO (plist, mdatabase__dir_list)
+    free_db_info (MPLIST_VAL (plist));
+  M17N_OBJECT_UNREF (mdatabase__dir_list);
+
+  /* MDATABASE_LIST ::= ((TAG0 (TAG1 (TAG2 (TAG3 t:MDB) ...) ...) ...) ...) */
+  MPLIST_DO (plist, mdatabase__list)
+    {
+      p0 = MPLIST_PLIST (plist);
+      /* P0 ::= (TAG0 (TAG1 (TAG2 (TAG3 t:MDB) ...) ...) ...) */
+      MPLIST_DO (p0, MPLIST_NEXT (p0))
+       {
+         p1 = MPLIST_PLIST (p0);
+         /* P1 ::= (TAG1 (TAG2 (TAG3 t:MDB) ...) ...) */
+         MPLIST_DO (p1, MPLIST_NEXT (p1))
+           {
+             p2 = MPLIST_PLIST (p1);
+             /* P2 ::= (TAG2 (TAG3 t:MDB) ...) */
+             MPLIST_DO (p2, MPLIST_NEXT (p2))
+               {
+                 MDatabase *mdb;
+
+                 p3 = MPLIST_PLIST (p2); /* P3 ::= (TAG3 t:MDB) */
+                 p3 = MPLIST_NEXT (p3);
+                 mdb = MPLIST_VAL (p3);
+                 if (mdb->loader == load_database)
+                   free_db_info (mdb->extra_info);
+                 free (mdb);
+               }
+           }
+       }
+    }
+  M17N_OBJECT_UNREF (mdatabase__list);
+}
+
+void
+mdatabase__update (void)
+{
+  MPlist *plist, *p0, *p1, *p2, *p3;
+  char path[PATH_MAX + 1];
+  MDatabaseInfo *dir_info;
+  struct stat statbuf;
+  int rescan = 0;
+
+  /* Update elements of mdatabase__dir_list.  */
+  MPLIST_DO (plist, mdatabase__dir_list)
+    {
+      dir_info = MPLIST_VAL (plist);
+      if (dir_info->filename)
+       {
+         if (stat (dir_info->filename, &statbuf) == 0
+             && (statbuf.st_mode & S_IFDIR))
+           {
+             if (dir_info->time < statbuf.st_mtime)
+               {
+                 rescan = 1;
+                 dir_info->time = statbuf.st_mtime;
+               }
+             if (GEN_PATH (path, dir_info->filename, dir_info->len,
+                           MDB_DIR, MDB_DIR_LEN)
+                 && stat (path, &statbuf) >= 0
+                 && dir_info->time < statbuf.st_mtime)
+               {
+                 rescan = 1;
+                 dir_info->time = statbuf.st_mtime;
+               }
+             dir_info->status = MDB_STATUS_UPDATED;
+           }
+         else
+           {
+             if (dir_info->status != MDB_STATUS_DISABLED)
+               {
+                 rescan = 1;
+                 dir_info->time = 0;
+                 dir_info->status = MDB_STATUS_DISABLED;
+               }
+           }
+       }
+    }
+
+  if (! rescan)
+    return;
+
+  /* At first, mark all databases defined automatically from mdb.dir
+     file(s) as "disabled".  */
+  MPLIST_DO (plist, mdatabase__list)
+    {
+      p0 = MPLIST_PLIST (plist);
+      /* P0 ::= (TAG0 (TAG1 (TAG2 (TAG3 MDB) ...) ...) ...) */
+      MPLIST_DO (p0, MPLIST_NEXT (p0))
+       {
+         p1 = MPLIST_PLIST (p0);
+         MPLIST_DO (p1, MPLIST_NEXT (p1))
+           {
+             p2 = MPLIST_PLIST (p1);
+             MPLIST_DO (p2, MPLIST_NEXT (p2))
+               {
+                 MDatabase *mdb;
+                 MDatabaseInfo *db_info;
+
+                 p3 = MPLIST_PLIST (p2);
+                 p3 = MPLIST_NEXT (p3);
+                 mdb = MPLIST_VAL (p3);
+                 db_info = mdb->extra_info;
+                 if (db_info->status == MDB_STATUS_AUTO)
+                   db_info->status = MDB_STATUS_DISABLED;
+               }
+           }
+       }
+    }
+
+  plist = mplist (); 
+  MPLIST_DO (p0, mdatabase__dir_list)
+    mplist_push (plist, MPLIST_KEY (p0), MPLIST_VAL (p0));
+
+  while (! MPLIST_TAIL_P (plist))
+    {
+      MDatabaseInfo *dir_info = mplist_pop (plist);
+      MPlist *pl, *p;
+      int i;
+      FILE *fp;
+
+      if (dir_info->status == MDB_STATUS_DISABLED)
+       continue;
+      if (! GEN_PATH (path, dir_info->filename, dir_info->len,
+                     MDB_DIR, MDB_DIR_LEN))
+       continue;
+      if (! (fp = fopen (path, "r")))
+       continue;
+      pl = mplist__from_file (fp, NULL);
+      fclose (fp);
+      if (! pl)
+       continue;
+      MPLIST_DO (p, pl)
+       {
+         MSymbol tags[4];
+         MPlist *p1;
+         MText *mt;
+         int nbytes;
+         int with_wildcard = 0;
+
+         if (! MPLIST_PLIST_P (p))
+           continue;
+         for (i = 0, p1 = MPLIST_PLIST (p); i < 4 && MPLIST_SYMBOL_P (p1);
+              i++, p1 = MPLIST_NEXT (p1))
+           with_wildcard |= ((tags[i] = MPLIST_SYMBOL (p1)) == Masterisk);
+         if (i == 0
+             || tags[0] == Masterisk
+             || ! MPLIST_MTEXT_P (p1))
+           continue;
+         for (; i < 4; i++)
+           tags[i] = with_wildcard ? Masterisk : Mnil;
+         mt = MPLIST_MTEXT (p1);
+         nbytes = mtext_nbytes (mt);
+         if (nbytes > PATH_MAX)
+           continue;
+         memcpy (path, MTEXT_DATA (mt), nbytes);
+         path[nbytes] = '\0';
+         if (with_wildcard)
+           register_database (tags, load_database, path,
+                              MDB_STATUS_AUTO_WILDCARD, NULL);
+         else
+           register_database (tags, load_database, path,
+                              MDB_STATUS_AUTO, p1);
+       }
+      M17N_OBJECT_UNREF (pl);
+    }
+  M17N_OBJECT_UNREF (plist);
+}
+
+MPlist *
+mdatabase__load_for_keys (MDatabase *mdb, MPlist *keys)
+{
+  int mdebug_flag = MDEBUG_DATABASE;
+  MDatabaseInfo *db_info;
+  char *filename;
+  FILE *fp;
+  MPlist *plist;
+  char name[256];
+
+  if (mdb->loader != load_database
+      || mdb->tag[0] == Mchar_table
+      || mdb->tag[0] == Mcharset)
+    MERROR (MERROR_DB, NULL);
+  MDEBUG_PRINT1 (" [DB]  <%s>.\n",
+                gen_database_name (name, mdb->tag));
+  db_info = mdb->extra_info;
+  filename = get_database_file (db_info, NULL, NULL);
+  if (! filename || ! (fp = fopen (filename, "r")))
+    MERROR (MERROR_DB, NULL);
+  plist = mplist__from_file (fp, keys);
+  fclose (fp);
+  return plist;
+}
+
+
+/* Check if the database MDB should be reloaded or not.  It returns:
+
+       1: The database has not been updated since it was loaded last
+       time.
+
+       0: The database has never been loaded or has been updated
+       since it was loaded last time.
+
+       -1: The database is not loadable at the moment.  */
+
+int
+mdatabase__check (MDatabase *mdb)
+{
+  MDatabaseInfo *db_info = (MDatabaseInfo *) mdb->extra_info;
+  struct stat buf;
+  int result;
+
+  if (db_info->absolute_filename != db_info->filename
+      || db_info->status == MDB_STATUS_AUTO)
+    mdatabase__update ();
+
+  if (! get_database_file (db_info, &buf, &result)
+      || result < 0)
+    return -1;
+  if (db_info->time < buf.st_mtime)
+    return 0;
+  return 1;
+}
+
+/* Search directories in mdatabase__dir_list for file FILENAME.  If
+   the file exist, return the absolute pathname.  If FILENAME is
+   already absolute, return a copy of it.  */
+
+char *
+mdatabase__find_file (char *filename)
+{
+  struct stat buf;
+  int result;
+  MDatabaseInfo db_info;
+
+  if (filename[0] == PATH_SEPARATOR)
+    return (stat (filename, &buf) == 0 ? strdup (filename) : NULL);
+  db_info.filename = filename;
+  db_info.len = strlen (filename);
+  db_info.time = 0;
+  db_info.absolute_filename = NULL;
+  if (! get_database_file (&db_info, &buf, &result)
+      || result < 0)
+    return NULL;
+  return db_info.absolute_filename;
+}
+
+char *
+mdatabase__file (MDatabase *mdb)
+{
+  MDatabaseInfo *db_info;
+
+  if (mdb->loader != load_database)
+    return NULL;
+  db_info = mdb->extra_info;
+  return get_database_file (db_info, NULL, NULL);
+}
+
+int
+mdatabase__lock (MDatabase *mdb)
+{
+  MDatabaseInfo *db_info;
+  struct stat buf;
+  FILE *fp;
+  int len;
+  char *file;
+
+  if (mdb->loader != load_database)
+    return -1;
+  db_info = mdb->extra_info;
+  if (db_info->lock_file)
+    return -1;
+  file = get_database_file (db_info, NULL, NULL);
+  if (! file)
+    return -1;
+  len = strlen (file);
+  db_info->uniq_file = malloc (len + 35);
+  if (! db_info->uniq_file)
+    return -1;
+  db_info->lock_file = malloc (len + 5);
+  if (! db_info->lock_file)
+    {
+      free (db_info->uniq_file);
+      return -1;
+    }
+  sprintf (db_info->uniq_file, "%s.%X.%X", db_info->absolute_filename,
+          (unsigned) time (NULL), (unsigned) getpid ());
+  sprintf (db_info->lock_file, "%s.LCK", db_info->absolute_filename);
+
+  fp = fopen (db_info->uniq_file, "w");
+  if (! fp)
+    {
+      char *str = strdup (db_info->uniq_file);
+      char *dir = dirname (str);
+      
+      if (stat (dir, &buf) == 0
+         || mkdir (dir, 0777) < 0
+         || ! (fp = fopen (db_info->uniq_file, "w")))
+       {
+         free (db_info->uniq_file);
+         free (db_info->lock_file);
+         db_info->lock_file = NULL;
+         free (str);
+         return -1;
+       }
+      free (str);
+    }
+  fclose (fp);
+  if (link (db_info->uniq_file, db_info->lock_file) < 0
+      && (stat (db_info->uniq_file, &buf) < 0
+         || buf.st_nlink != 2))
+    {
+      unlink (db_info->uniq_file);
+      unlink (db_info->lock_file);
+      free (db_info->uniq_file);
+      free (db_info->lock_file);
+      db_info->lock_file = NULL;
+      return 0;
+    }
+  return 1;
+}
+
+int
+mdatabase__save (MDatabase *mdb, MPlist *data)
+{
+  MDatabaseInfo *db_info;
+  FILE *fp;
+  char *file;
+  MText *mt;
+  int ret;
+
+  if (mdb->loader != load_database)
+    return -1;
+  db_info = mdb->extra_info;
+  if (! db_info->lock_file)
+    return -1;
+  file = get_database_file (db_info, NULL, NULL);
+  if (! file)
+    return -1;
+  mt = mtext ();
+  if (mplist__serialize (mt, data, 1) < 0)
+    {
+      M17N_OBJECT_UNREF (mt);
+      return -1;
+    }
+  fp = fopen (db_info->uniq_file, "w");
+  if (! fp)
+    {
+      M17N_OBJECT_UNREF (mt);
+      return -1;
+    }
+  if (mt->format > MTEXT_FORMAT_UTF_8)
+    mtext__adjust_format (mt, MTEXT_FORMAT_UTF_8);
+  fwrite (MTEXT_DATA (mt), 1, mtext_nchars (mt), fp);
+  fclose (fp);
+  M17N_OBJECT_UNREF (mt);
+  if ((ret = rename (db_info->uniq_file, file)) < 0)
+    unlink (db_info->uniq_file);
+  free (db_info->uniq_file);
+  db_info->uniq_file = NULL;
+  return ret;
+}
+
+int
+mdatabase__unlock (MDatabase *mdb)
+{
+  MDatabaseInfo *db_info;
+
+  if (mdb->loader != load_database)
+    return -1;
+  db_info = mdb->extra_info;
+  if (! db_info->lock_file)
+    return -1;
+  unlink (db_info->lock_file);
+  free (db_info->lock_file);
+  db_info->lock_file = NULL;
+  if (db_info->uniq_file)
+    {
+      unlink (db_info->uniq_file);
+      free (db_info->uniq_file);
+    }
+  return 0;
+}
+
+MPlist *
+mdatabase__props (MDatabase *mdb)
+{
+  MDatabaseInfo *db_info;
+
+  if (mdb->loader != load_database)
+    return NULL;
+  db_info = mdb->extra_info;
+  return db_info->properties;
+}
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+/* External API */
+
+/*** @addtogroup m17nCharset */
+/*** @{ */
+/*=*/
+/***en
+    @brief The symbol @c Mcharset.
+
+    Any decoded M-text has a text property whose key is the predefined
+    symbol @c Mcharset.  The name of @c Mcharset is
+    <tt>"charset"</tt>.  */
+
+/***ja
+    @brief ¥·¥ó¥Ü¥ë @c Mcharset.
+
+    ¥Ç¥³¡¼¥É¤µ¤ì¤¿ M-text ¤Ï¡¢¥­¡¼¤¬ @c Mcharset
+    ¤Ç¤¢¤ë¤è¤¦¤Ê¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¡£
+    ¥·¥ó¥Ü¥ë @c Mcharset ¤Ï <tt>"charset"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¡£  */
+
+MSymbol Mcharset;
+/*=*/
+/*** @} */
+/*=*/
+
+/*** @addtogroup m17nDatabase */
+/*** @{ */
+
+/*=*/
+/***en
+    @brief Directory for application specific data.
+
+    If an application program wants to provide a data specific to the
+    program or a data overriding what supplied by the m17n database,
+    it must set this variable to a name of directory that contains the
+    data files before it calls the macro M17N_INIT ().  The directory
+    may contain a file "mdb.dir" which contains a list of data
+    definitions in the format described in @ref mdbDir "mdbDir(5)".
+
+    The default value is NULL.  */
+/***ja
+    @brief ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¸ÇÍ­¤Î¥Ç¡¼¥¿Íѥǥ£¥ì¥¯¥È¥ê.
+
+    ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤¬¡¢¤½¤Î¥×¥í¥°¥é¥à¸ÇÍ­¤Î¥Ç¡¼¥¿¤ä m17n 
+    ¥Ç¡¼¥¿¥Ù¡¼¥¹¤ò¾å½ñ¤­¤¹¤ë¥Ç¡¼¥¿¤òÄ󶡤¹¤ë¾ì¹ç¤Ë¤Ï¡¢¥Þ¥¯¥í M17N_INIT () 
+    ¤ò¸Æ¤ÖÁ°¤Ë¤³¤ÎÊÑ¿ô¤ò¥Ç¡¼¥¿¥Õ¥¡¥¤¥ë¤ò´Þ¤à¥Ç¥£¥ì¥¯¥È¥ê̾¤Ë¥»¥Ã¥È¤·¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¥Ç¥£¥ì¥¯¥È¥ê¤Ë¤Ï
+    "mdb.dir" ¥Õ¥¡¥¤¥ë¤ò¤ª¤¯¤³¤È¤¬¤Ç¤­¤ë¡£¤½¤Î"mdb.dir"¥Õ¥¡¥¤¥ë¤Ë¤Ï¡¢ 
+    @ref mdbDir "mdbDir(5)" ¤ÇÀâÌÀ¤µ¤ì¤Æ¤¤¤ë¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç¥Ç¡¼¥¿ÄêµÁ¤Î¥ê¥¹¥È¤òµ­½Ò¤¹¤ë¡£
+
+    ¥Ç¥Õ¥©¥ë¥È¤ÎÃͤϠNULL ¤Ç¤¢¤ë¡£  */
+
+char *mdatabase_dir;
+
+/*=*/
+/***en
+    @brief Look for a data in the database.
+
+    The mdatabase_find () function searches the m17n database for a
+    data who has tags $TAG0 through $TAG3, and returns a pointer to
+    the data.  If such a data is not found, it returns @c NULL.  */
+
+/***ja
+    @brief ¥Ç¡¼¥¿¥Ù¡¼¥¹Ãæ¤Î¥Ç¡¼¥¿¤òõ¤¹.
+
+    ´Ø¿ô mdatabase_find () ¤Ï¡¢ m17n ¸À¸ì¾ðÊó¥Ù¡¼¥¹Ãæ¤Ç $TAG0 ¤«¤é 
+    $TAG3 ¤Þ¤Ç¤Î¥¿¥°¤ò»ý¤Ä¥Ç¡¼¥¿¤òõ¤·¡¢¤½¤ì¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¤½¤Î¤è¤¦¤Ê¥Ç¡¼¥¿¤¬¤Ê¤±¤ì¤Ð
+    @c NULL ¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mdatabase_find} @endlatexonly  */
+
+MDatabase *
+mdatabase_find (MSymbol tag0, MSymbol tag1, MSymbol tag2, MSymbol tag3)
+{
+  MSymbol tags[4];
+
+  mdatabase__update ();
+  tags[0] = tag0, tags[1] = tag1, tags[2] = tag2, tags[3] = tag3;
+  return find_database (tags);
+}
+
+/*=*/
+/***en
+    @brief Return a data list of the m17n database.
+
+    The mdatabase_list () function searches the m17n database for data
+    who have tags $TAG0 through $TAG3, and returns their list by a
+    plist.  The value #Mnil in $TAGn means a wild card that matches
+    any tag.  Each element of the plist has key #Mt and value a
+    pointer to type #MDatabase.  */
+/***ja
+    @brief m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥Ç¡¼¥¿¥ê¥¹¥È¤òÊÖ¤¹.
+
+    ´Ø¿ô mdatabase_list () ¤Ï m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹Ã椫¤é $TAG0 ¤«¤é$TAG3 
+    ¤Þ¤Ç¤Î¥¿¥°¤ò»ý¤Ä¥Ç¡¼¥¿¤òõ¤·¡¢¤½¤Î¥ê¥¹¥È¤òplist ¤È¤·¤ÆÊÖ¤¹¡£ $TAGn ¤¬ #Mnil
+    ¤Ç¤¢¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢Ç¤°Õ¤Î¥¿¥°¤Ë¥Þ¥Ã¥Á¤¹¤ë¥ï¥¤¥ë¥É¥«¡¼¥É¤È¤·¤Æ¼è¤ê°·¤ï¤ì¤ë¡£ÊÖ¤µ¤ì¤ë
+    plist ¤Î³ÆÍ×ÁǤϥ­¡¼ ¤È¤·¤Æ #Mt ¤ò¡¢ÃͤȤ·¤Æ #MDatabase ·¿¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò»ý¤Ä¡£  */
+
+MPlist *
+mdatabase_list (MSymbol tag0, MSymbol tag1, MSymbol tag2, MSymbol tag3)
+{
+  MPlist *plist = mplist (), *pl = plist;
+  MPlist *p, *p0, *p1, *p2, *p3;
+
+  mdatabase__update ();
+
+  MPLIST_DO (p, mdatabase__list)
+    {
+      p0 = MPLIST_PLIST (p);
+      /* P0 ::= (TAG0 (TAG1 (TAG2 (TAG3 MDB) ...) ...) ...) */
+      if (MPLIST_SYMBOL (p0) == Masterisk
+         || (tag0 != Mnil && MPLIST_SYMBOL (p0) != tag0))
+       continue;
+      MPLIST_DO (p0, MPLIST_NEXT (p0))
+       {
+         p1 = MPLIST_PLIST (p0);
+         if (MPLIST_SYMBOL (p1) == Masterisk)
+           {
+             if (expand_wildcard_database (p1))
+               {
+                 M17N_OBJECT_UNREF (plist);
+                 return mdatabase_list (tag0, tag1, tag2, tag3);
+               }
+             continue;
+           }
+         if (tag1 != Mnil && MPLIST_SYMBOL (p1) != tag1)
+           continue;
+         MPLIST_DO (p1, MPLIST_NEXT (p1))
+           {
+             p2 = MPLIST_PLIST (p1);
+             if (MPLIST_SYMBOL (p2) == Masterisk)
+               {
+                 if (expand_wildcard_database (p2))
+                   {
+                     M17N_OBJECT_UNREF (plist);
+                     return mdatabase_list (tag0, tag1, tag2, tag3);
+                   }
+                 continue;
+               }
+             if (tag2 != Mnil && MPLIST_SYMBOL (p2) != tag2)
+               continue;
+             MPLIST_DO (p2, MPLIST_NEXT (p2))
+               {
+                 p3 = MPLIST_PLIST (p2);
+                 if (MPLIST_SYMBOL (p3) == Masterisk)
+                   {
+                     if (expand_wildcard_database (p3))
+                       {
+                         M17N_OBJECT_UNREF (plist);
+                         return mdatabase_list (tag0, tag1, tag2, tag3);
+                       }
+                     continue;
+                   }
+                 if (tag3 != Mnil && MPLIST_SYMBOL (p3) != tag3)
+                   continue;
+                 p3 = MPLIST_NEXT (p3);
+                 pl = mplist_add (pl, Mt, MPLIST_VAL (p3));
+               }
+           }
+       }
+    }
+  if (MPLIST_TAIL_P (plist))
+    M17N_OBJECT_UNREF (plist);
+  return plist;
+}
+
+/*=*/
+/***en
+    @brief Define a data of the m17n database.
+
+    The mdatabase_define () function defines a data that has tags
+    $TAG0 through $TAG3 and additional information $EXTRA_INFO.
+
+    $LOADER is a pointer to a function that loads the data from the
+    database.  This function is called from the mdatabase_load ()
+    function with the two arguments $TAGS and $EXTRA_INFO.  Here,
+    $TAGS is the array of $TAG0 through $TAG3.
+
+    If $LOADER is @c NULL, the default loader of the m17n library is
+    used.  In this case, $EXTRA_INFO must be a string specifying a
+    filename that contains the data.
+
+    @return
+    If the operation was successful, mdatabase_define () returns a
+    pointer to the defined data, which can be used as an argument to
+    mdatabase_load ().  Otherwise, it returns @c NULL.  */
+
+/***ja
+    @brief m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥Ç¡¼¥¿¤òÄêµÁ¤¹¤ë.
+
+    ´Ø¿ô mdatabase_define () ¤Ï $TAG0 ¤«¤é $TAG3 ¤Þ¤Ç¤Î¥¿¥°¤ª¤è¤ÓÉղþðÊó 
+    $EXTRA_INFO ¤ò»ý¤Ä¥Ç¡¼¥¿¤òÄêµÁ¤¹¤ë¡£
+
+    $LOADER ¤Ï¤½¤Î¥Ç¡¼¥¿¤Î¥í¡¼¥É¤ËÍѤ¤¤é¤ì¤ë´Ø¿ô¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£¤³¤Î´Ø¿ô¤Ï
+    mdatabase_load () ¤«¤é $TAGS ¤È $EXTRA_INFO ¤È¤¤¤¦Æó¤Ä¤Î°ú¿ôÉÕ¤­¤Ç¸Æ¤Ó½Ð¤µ¤ì¤ë¡£¤³¤³¤Ç 
+    $TAGS ¤Ï $TAG0 ¤«¤é $TAG3 ¤Þ¤Ç¤ÎÇÛÎó¤Ç¤¢¤ë¡£
+
+    ¤â¤· $LOADER ¤¬ @c NULL ¤Ê¤é¡¢m17n ¥é¥¤¥Ö¥é¥êɸ½à¤Î¥í¡¼¥À¤¬»È¤ï¤ì¤ë¡£¤³¤Î¾ì¹ç¤Ë¤Ï
+    $EXTRA_INFO ¤Ï¥Ç¡¼¥¿¤ò´Þ¤à¥Õ¥¡¥¤¥ë̾¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    @return
+    ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð mdatabase_define () 
+    ¤ÏÄêµÁ¤µ¤ì¤¿¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¤³¤Î¥Ý¥¤¥ó¥¿¤Ï´Ø¿ô mdatabase_load () 
+    ¤Î°ú¿ô¤È¤·¤ÆÍѤ¤¤ë¤³¤È¤¬¤Ç¤­¤ë¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mdatabase_define} @endlatexonly  */
+
+/***
+    @seealso
+    mdatabase_load (),  mdatabase_define ()  */
+
+MDatabase *
+mdatabase_define (MSymbol tag0, MSymbol tag1, MSymbol tag2, MSymbol tag3,
+                 void *(*loader) (MSymbol *, void *),
+                 void *extra_info)
+{
+  MDatabase *mdb;
+  MSymbol tags[4];
+
+  tags[0] = tag0, tags[1] = tag1, tags[2] = tag2, tags[3] = tag3;
+  if (! loader)
+    loader = load_database;
+  mdb = register_database (tags, loader, extra_info, MDB_STATUS_EXPLICIT, NULL);
+  return mdb;
+}
+
+/*=*/
+/***en
+    @brief Load a data from the database.
+
+    The mdatabase_load () function loads a data specified in $MDB and
+    returns the contents.  The type of contents depends on the type of
+    the data.
+
+    If the data is of the @e plist @e type, this function returns a
+    pointer to @e plist.
+
+    If the database is of the @e chartable @e type, it returns a
+    chartable.  The default value of the chartable is set according to
+    the second tag of the data as below:
+
+    @li If the tag is #Msymbol, the default value is #Mnil.
+    @li If the tag is #Minteger, the default value is -1.
+    @li Otherwise, the default value is @c NULL.
+
+    If the data is of the @e charset @e type, it returns a plist of length 2
+    (keys are both #Mt).  The value of the first element is an array
+    of integers that maps code points to the corresponding character
+    codes.  The value of the second element is a chartable of integers
+    that does the reverse mapping.  The charset must be defined in
+    advance.  */
+
+
+/***ja
+    @brief ¥Ç¡¼¥¿¥Ù¡¼¥¹¤«¤é¥Ç¡¼¥¿¤ò¥í¡¼¥É¤¹¤ë.
+
+    ´Ø¿ô mdatabase_load () ¤Ï $MDB 
+    ¤¬»Ø¤¹¥Ç¡¼¥¿¤ò¥í¡¼¥É¤·¡¢¤½¤ÎÃæ¿È¤òÊÖ¤¹¡£ÊÖ¤µ¤ì¤ë¤â¤Î¤Ï¥Ç¡¼¥¿¤Î¥¿¥¤¥×¤Ë¤è¤Ã¤Æ°Û¤Ê¤ë¡£
+
+    ¥Ç¡¼¥¿¤¬ @e plist¥¿¥¤¥× ¤Ê¤é¤Ð¡¢ @e plist ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
+
+    ¥Ç¡¼¥¿¤¬ @e chartable¥¿¥¤¥× ¤Ê¤é¤Ðʸ»ú¥Æ¡¼¥Ö¥ë¤òÊÖ¤¹¡£
+    Ê¸»ú¥Æ¡¼¥Ö¥ë¤Î¥Ç¥Õ¥©¥ë¥ÈÃͤϡ¢¥Ç¡¼¥¿¤ÎÂè2¥¿¥°¤Ë¤è¤Ã¤Æ°Ê²¼¤Î¤è¤¦¤Ë·è¤Þ¤ë¡£
+
+    @li ¥¿¥°¤¬ #Msymbol ¤Ê¤é¡¢¥Ç¥Õ¥©¥ë¥ÈÃͤϠ#Mnil
+    @li ¥¿¥°¤¬ #Minteger ¤Ê¤é¡¢¥Ç¥Õ¥©¥ë¥ÈÃͤϠ-1
+    @li ¤½¤ì°Ê³°¤Ê¤é¡¢¥Ç¥Õ¥©¥ë¥ÈÃͤϠ@c NULL
+
+    ¥Ç¡¼¥¿¤¬ @e charset¥¿¥¤¥× ¤Ê¤é¤ÐŤµ 2 ¤Î plist ¤òÊÖ¤¹¡Ê¥­¡¼¤Ï¶¦¤Ë#Mt ¡Ë¡£
+    ºÇ½é¤ÎÍ×ÁǤÎÃͤϥ³¡¼¥É¥Ý¥¤¥ó¥È¤òÂбþ¤¹¤ëʸ»ú¥³¡¼¥É¤Ë¥Þ¥Ã¥×¤¹¤ëÀ°¿ô¤ÎÇÛÎó¤Ç¤¢¤ë¡£
+    £²ÈÖÌܤÎÍ×ÁǤÎÃͤϵդΥޥåפò¤¹¤ëʸ»ú¥Æ¡¼¥Ö¥ë¤Ç¤¢¤ë¡£
+    ¤³¤Îʸ»ú¥»¥Ã¥È¤Ïͽ¤áÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
+
+    @latexonly \IPAlabel{mdatabase_load} @endlatexonly
+  */
+
+/***
+    @seealso
+    mdatabase_load (),  mdatabase_define ()  */
+
+void *
+mdatabase_load (MDatabase *mdb)
+{
+  return (*mdb->loader) (mdb->tag, mdb->extra_info);
+}
+
+/*=*/
+/***en
+    @brief Get tags of a data.
+
+    The mdatabase_tag () function returns an array of tags (symbols)
+    that identify the data in $MDB.  The length of the array is
+    four.  */
+
+/***ja
+    @brief ¥Ç¡¼¥¿¤Î¥¿¥°¤òÆÀ¤ë.
+
+    ´Ø¿ô mdatabase_tag () ¤Ï¡¢¥Ç¡¼¥¿ $MDB ¤Î¥¿¥°¡Ê¥·¥ó¥Ü¥ë¡Ë¤ÎÇÛÎó¤òÊÖ¤¹¡£ÇÛÎó¤ÎŤµ¤Ï
+    4 ¤Ç¤¢¤ë¡£
+
+    @latexonly \IPAlabel{mdatabase_tag} @endlatexonly  */
+
+MSymbol *
+mdatabase_tag (MDatabase *mdb)
+{
+  return mdb->tag;
+}
+
+/*** @} */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/database.h b/src/database.h
new file mode 100644 (file)
index 0000000..28397c0
--- /dev/null
@@ -0,0 +1,95 @@
+/* database.h -- header file for the database module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_DATABASE_H_
+#define _M17N_DATABASE_H_
+
+#ifndef M17NDIR
+#define M17NDIR "/usr/local/share/m17n"
+#endif
+
+#ifndef PATH_MAX
+#define PATH_MAX 1024
+#endif
+
+#ifndef PATH_SEPARATOR
+#define PATH_SEPARATOR '/'
+#endif
+
+enum MDatabaseStatus
+  {
+    /* The database was defined automatically (from mdb.dir file(s))
+       with no wildcard tag.  */
+    MDB_STATUS_AUTO,
+    /* The database was defined automatically (from mdb.dir file(s)).
+       with a wildcard tag.  */
+    MDB_STATUS_AUTO_WILDCARD,
+    /* The database was defined explicitely (by mdatabase_define ()). */
+    MDB_STATUS_EXPLICIT,
+    /* The databse is currently disabled. (usually because it is
+       deleted from mdb.dir file(s)).  */
+    MDB_STATUS_DISABLED,
+    MDB_STATUS_UPDATED,
+    MDB_STATUS_OUTDATED
+  };
+
+typedef struct
+{
+  /* Name of the file containing the database.  */
+  char *filename;
+  /* Length of FILENAME.  */
+  int len;
+  /* Absolute path of filename.  */
+  char *absolute_filename;
+  /* The current status of the database.  */
+  enum MDatabaseStatus status;
+  /* When the database was loaded last.  0 if it has never been
+     loaded.  */
+  time_t time;
+  char *lock_file, *uniq_file;
+
+  MPlist *properties;
+} MDatabaseInfo;
+
+extern MPlist *mdatabase__dir_list;
+
+extern void mdatabase__update (void);
+
+extern MPlist *mdatabase__load_for_keys (MDatabase *mdb, MPlist *keys);
+
+extern int mdatabase__check (MDatabase *mdb);
+
+extern char *mdatabase__find_file (char *filename);
+
+extern char *mdatabase__file (MDatabase *mdb);
+
+extern int mdatabase__lock (MDatabase *mdb);
+
+extern int mdatabase__save (MDatabase *mdb, MPlist *data);
+
+extern int mdatabase__unlock (MDatabase *mdb);
+
+extern MPlist *mdatabase__props (MDatabase *mdb);
+
+extern void *(*mdatabase__load_charset_func) (FILE *fp, MSymbol charset_name);
+
+#endif /* not _M17N_DATABASE_H_ */
diff --git a/src/draw.c b/src/draw.c
new file mode 100644 (file)
index 0000000..0e58c15
--- /dev/null
@@ -0,0 +1,2953 @@
+/* draw.c -- drawing module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nDraw
+    @brief Drawing M-texts on a window.
+
+    The m17n GUI API provides functions to draw M-texts.
+
+    The fonts used for drawing are selected automatically based on the
+    fontset and the properties of a face.  A face also specifies the
+    appearance of M-texts, i.e. font size, color, underline, etc.
+
+    The drawing format of M-texts can be controlled in a variety of
+    ways, which provides powerful 2-dimensional layout
+    facility.  */
+
+/***ja
+    @addtogroup m17nDraw
+    @brief M-text ¤ò¥¦¥£¥ó¥É¥¦¤ËÉÁ²è¤¹¤ë.
+
+    m17n-gui API ¤Ë¤Ï¡¢M-text ¤òɽ¼¨¤¹¤ë¤¿¤á¤Î´Ø¿ô¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤ë¡£
+
+    É½¼¨¤ËÍѤ¤¤é¤ì¤ë¥Õ¥©¥ó¥È¤Ï¡¢¥Õ¥©¥ó¥È¥»¥Ã¥È¤È face 
+    ¤Î¥×¥í¥Ñ¥Æ¥£¤Ë´ð¤Å¤¤¤Æ¼«Æ°Åª¤Ë·èÄꤵ¤ì¤ë¡£¤Þ¤¿¡¢¥Õ¥©¥ó¥È¤Î¥µ¥¤¥º¤ä¿§¤ä²¼Àþ¤Ê¤É¤Î¸«±É¤¨¤â
+    face ¤Ë¤è¤Ã¤Æ·è¤Þ¤ë¡£
+
+    M-text ¤ÎÉÁ²è¥Õ¥©¡¼¥Þ¥Ã¥È¤Ï¿ÍͤÊÊýË¡¤ÇÀ©¸æ¤Ç¤­¤ë¤Î¤Ç¡¢¶¯ÎϤÊÆ󼡸µ¥ì¥¤¥¢¥¦¥Èµ¡Ç½¤¬¼Â¸½¤Ç¤­¤ë¡£
+    */
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <sys/types.h>
+
+#include "config.h"
+#include "m17n-gui.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "symbol.h"
+#include "mtext.h"
+#include "textprop.h"
+#include "internal-gui.h"
+#include "internal-flt.h"
+#include "face.h"
+#include "font.h"
+
+#ifdef HAVE_FRIBIDI
+#include <fribidi/fribidi.h>
+#endif /* HAVE_FRIBIDI */
+
+#define MAX(x, y) ((x) > (y) ? (x) : (y))
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
+
+static MSymbol M_glyph_string;
+
+/* Special scripts */
+static MSymbol Mcommon;
+/* Special categories */
+static MSymbol McatCc, McatCf;
+
+static MCharTable *linebreak_table;
+static MSymbol M_break_at_space, M_break_at_word, M_break_at_any;
+static MSymbol M_kinsoku_bol, M_kinsoku_eol;
+
+\f
+/* Glyph-string composer.  */
+
+static MSymbol MbidiR;
+static MSymbol MbidiAL;
+static MSymbol MbidiRLE;
+static MSymbol MbidiRLO;
+static MSymbol MbidiBN;
+static MSymbol MbidiS;
+static MSymbol MbidiNSM;
+
+static int
+analyse_bidi_level (MGlyphString *gstring)
+{
+  int len = gstring->used - 2;
+  int bidi_sensitive = gstring->control.orientation_reversed;
+  int max_level;
+  MGlyph *g;
+  int i;
+#ifdef HAVE_FRIBIDI
+  FriBidiCharType base = bidi_sensitive ? FRIBIDI_TYPE_RTL : FRIBIDI_TYPE_LTR;
+  FriBidiChar *logical = alloca (sizeof (FriBidiChar) * len);
+  FriBidiLevel *levels;
+  FriBidiStrIndex *indices;
+#else  /* not HAVE_FRIBIDI */
+  int *logical = alloca (sizeof (int) * len);
+  char *levels = alloca (len);
+
+  memset (levels, 0, sizeof (int) * len);
+#endif /* not HAVE_FRIBIDI */
+
+  for (g = MGLYPH (1), i = 0; g->type != GLYPH_ANCHOR; g++, i++)
+    {
+      if (! bidi_sensitive
+#ifndef HAVE_FRIBIDI
+         || 1
+#endif /* not HAVE_FRIBIDI */
+         )
+       {
+         MSymbol bidi = (MSymbol) mchar_get_prop (g->g.c, Mbidi_category);
+
+         if (bidi == MbidiR || bidi == MbidiAL
+             || bidi == MbidiRLE || bidi == MbidiRLO)
+           {
+             bidi_sensitive = 1;
+#ifndef HAVE_FRIBIDI
+             levels[i] = 1;
+#endif /* not HAVE_FRIBIDI */
+           }
+#ifndef HAVE_FRIBIDI
+         else if (bidi == MbidiNSM && i > 0 && levels[i - 1])
+           levels[i] = 1;          
+#endif /* not HAVE_FRIBIDI */
+       }
+      logical[i] = g->g.c;
+    }
+
+  if (! bidi_sensitive)
+    return 0;
+
+#ifdef HAVE_FRIBIDI
+  levels = alloca (sizeof (FriBidiLevel) * (len + 1));
+  indices = alloca (sizeof (FriBidiStrIndex) * (len + 1));
+
+  fribidi_log2vis (logical, len, &base, NULL, NULL, indices, levels);
+#endif /* not HAVE_FRIBIDI */
+
+  MGLYPH (0)->bidi_level = 0;
+  max_level = 0;
+  for (g = MGLYPH (1), i = 0; i < len; g++, i++)
+    {
+      g->bidi_level = levels[i];
+      if (max_level < g->bidi_level)
+       max_level = g->bidi_level;
+    }
+  MGLYPH (i)->bidi_level = 0;
+  return max_level;
+}
+
+static void
+visual_order (MGlyphString *gstring)
+{
+  MGlyph *glyphs = alloca (sizeof (MGlyph) * gstring->used);
+  int i, j, gidx;
+
+  memcpy (glyphs, gstring->glyphs, sizeof (MGlyph) * gstring->used);
+
+  for (i = gidx = 0; i < gstring->used - 1; gidx++)
+    {
+      int level = glyphs[i].bidi_level;
+      
+      gstring->glyphs[gidx] = glyphs[i];
+      glyphs[i].rface = NULL;
+
+      if (level % 2)
+       {
+         int prev_level = glyphs[i - 1].bidi_level;
+
+         if (prev_level == level)
+           i--;
+         else if (prev_level > level)
+           {
+             for (; glyphs[i - 1].bidi_level > level; i--);
+             if (glyphs[i].bidi_level % 2)
+               for (level = glyphs[i].bidi_level;
+                    glyphs[i + 1].bidi_level == level; i++);
+           }
+         else
+           for (i++; ! glyphs[i].rface; i++);
+       }
+      else
+       {
+         int next_level = glyphs[i + 1].bidi_level;
+
+         if (next_level == level)
+           i++;
+         else if (next_level > level)
+           {
+             for (; glyphs[i + 1].bidi_level > level; i++);
+             if ((glyphs[i].bidi_level % 2) == 0)
+               for (level = glyphs[i].bidi_level;
+                    glyphs[i - 1].bidi_level == level; i--);
+           }
+         else
+           {
+             int save = i + 1;
+
+             for (i--; glyphs[i].bidi_level >= level; i--);
+             if (! glyphs[i].rface)
+               for (i = save; ! glyphs[i].rface; i++);
+           }
+       }
+    }
+  for (i = 1; i < gstring->used - 1; i++)
+    {
+      MGlyph *g = gstring->glyphs + i;
+
+      for (j = i; g->g.from == gstring->glyphs[j + 1].g.from; j++);
+      if (j > i)
+       {
+         memcpy (glyphs + i, gstring->glyphs + i,
+                 sizeof (MGlyph) * (j - i + 1));
+         for (; i <= j; i++)
+           g[j - i] = glyphs[i];
+         i--;
+       }
+    }
+}
+
+static MSymbol
+font_id (MFLTFont *font)
+{
+  return ((MFLTFontForRealized *) font)->rfont->id;
+}
+
+static int
+run_flt (MGlyphString *gstring, int from, int to, MRealizedFace *rface)
+{
+  MRealizedFont *rfont = rface->rfont;
+  MSymbol layouter = rface->layouter;
+  MFLTGlyphString flt_gstr;
+  MFLTFontForRealized font;
+  MFLT *flt;
+  int from_pos = MGLYPH (from)->g.from;
+  int len = to - from;
+  int catcode;
+  int i;
+
+  flt = mflt_get (layouter);
+  flt_gstr.glyph_size = sizeof (MGlyph);
+  flt_gstr.glyphs = (MFLTGlyph *) (gstring->glyphs);
+  flt_gstr.used = gstring->used;
+  flt_gstr.allocated = gstring->size;
+  flt_gstr.r2l = 0;
+  font.font.family = mfont_get_prop (rfont->font, Mfamily);
+  font.font.x_ppem = rfont->x_ppem;
+  font.font.y_ppem = rfont->y_ppem;
+  font.font.get_glyph_id = mfont__get_glyph_id;
+  font.font.get_metrics = mfont__get_metrics;
+  font.font.check_otf = rfont->driver->check_otf;
+  font.font.drive_otf = rfont->driver->drive_otf;
+  font.font.internal = NULL;
+  font.rfont = rfont;
+  mflt_font_id = font_id;
+  mflt_iterate_otf_feature = rfont->driver->iterate_otf_feature;
+  mflt_try_otf = rfont->driver->try_otf;
+  for (i = 0; i < 3; i++)
+    {
+      to = mflt_run (&flt_gstr, from, to, &font.font, flt);
+      if (to != -2)
+       break;
+      APPEND_GLYPH (gstring, *MGLYPH (0));
+      APPEND_GLYPH (gstring, *MGLYPH (0));
+      gstring->used -= 2;
+    }
+  if (from + len != to)
+    gstring->used += to - (from + len);
+  for (i = from, catcode = -1; i < to; i++)
+    {
+      MGlyph *g = MGLYPH (i);
+
+      g->g.from += from_pos - from;
+      g->g.to += from_pos - from + 1;
+      g->g.xadv >>= 6;
+      g->g.yadv >>= 6;
+      g->g.ascent >>= 6;
+      g->g.descent >>= 6;
+      g->g.lbearing >>= 6;
+      g->g.rbearing >>= 6;
+      g->g.xoff >>= 6;
+      g->g.yoff >>= 6;
+      g->rface = rface;
+      if (catcode < 0 || g->g.from != g[-1].g.from)
+       {
+         MSymbol category = mchar_get_prop (g->g.c, Mcategory);
+
+         catcode = (category == McatCf
+                    ? GLYPH_CATEGORY_FORMATTER
+                    : category != Mnil && MSYMBOL_NAME (category)[0] == 'M'
+                    ? GLYPH_CATEGORY_MODIFIER
+                    : GLYPH_CATEGORY_NORMAL);
+       }
+      g->category = catcode;
+    }
+  return to;
+}
+
+/** Scan M-text MT from FROM to TO, and compose glyphs in GSTRING for
+    displaying them on FRAME.
+
+    This function fills these members:
+      pos, to, c, code, rface, bidi_level, categories, type, combining_code
+    The other members are filled by layout_glyph_string.  */
+
+static void
+compose_glyph_string (MFrame *frame, MText *mt, int from, int to,
+                     MGlyphString *gstring)
+{
+  MRealizedFace *default_rface = frame->rface;
+  int stop, face_change, language_change, charset_change, font_change;
+  MGlyph g_tmp, *g, *last_g;
+  int pos;
+  MSymbol language = Mnil, script = Mnil, charset = Mnil;
+  MSymbol non_latin_script = Mnil;
+  MRealizedFace *rface = default_rface;
+  MRealizedFont *rfont;
+  int size = gstring->control.fixed_width;
+  int max_bidi_level = 0;
+  int i;
+
+  MLIST_RESET (gstring);
+  gstring->from = from;
+
+  /* At first generate glyphs with <pos>, <to>, <c>, <type>,
+     <category> and <rface> members.*/
+  INIT_GLYPH (g_tmp);
+
+  /** Put anchor glyphs at the head and tail.  */
+  g_tmp.type = GLYPH_ANCHOR;
+  g_tmp.g.from = g_tmp.g.to = from;
+  APPEND_GLYPH (gstring, g_tmp);
+  stop = face_change = font_change = pos = from;
+  while (1)
+    {
+      int c;
+      MSymbol category;
+
+      if (pos == stop)
+       {
+         if (pos == to)
+           break;
+         if (pos < mtext_nchars (mt))
+           {
+             MFont *font = rface->font;
+             MFace *faces[64];
+             int num;
+
+             if (pos == font_change)
+               {
+                 font = mtext_get_prop (mt, pos, Mfont);
+                 mtext_prop_range (mt, Mfont, pos, NULL, &font_change, 0);
+                 if (font_change == mtext_nchars (mt))
+                   font_change++;
+               }
+             if (pos == face_change)
+               {
+                 num = mtext_get_prop_values (mt, pos, Mface,
+                                              (void **) faces, 64);
+                 mtext_prop_range (mt, Mface, pos, NULL, &face_change, 1);
+                 if (face_change == mtext_nchars (mt))
+                   face_change++;
+               }
+             else
+               {
+                 faces[0] = &rface->face;
+                 num = 1;
+               }
+             rface = mface__realize (frame, faces, num, size, font);
+           }
+         else
+           rface = default_rface;
+         stop = to;
+         if (stop > font_change)
+           stop = font_change;         
+         if (stop > face_change)
+           stop = face_change;         
+       }
+
+      if (pos < mtext_nchars (mt))
+       c = mtext_ref_char (mt, pos);
+      else
+       c = '\n';
+      g_tmp.type
+       = (c == ' ' || c == '\n' || c == '\t') ? GLYPH_SPACE : GLYPH_CHAR;
+      g_tmp.g.c = c;
+      g_tmp.g.from = pos++;
+      g_tmp.g.to = pos;
+      g_tmp.rface = rface;
+      category = mchar_get_prop (c, Mcategory);
+      if (category == McatCf)
+       g_tmp.category = GLYPH_CATEGORY_FORMATTER;
+      else if (category != Mnil && MSYMBOL_NAME (category)[0] == 'M')
+       g_tmp.category = GLYPH_CATEGORY_MODIFIER;
+      else
+       g_tmp.category = GLYPH_CATEGORY_NORMAL;
+      
+      if ((c <= ' ' || c == 127) && g_tmp.type == GLYPH_CHAR)
+       {
+         MGlyph ctrl[2];
+
+         ctrl[0] = ctrl[1] = g_tmp;
+         ctrl[0].g.c = '^';
+         ctrl[1].g.c = c < ' ' ? c + 0x40 : '?';
+         APPEND_GLYPH (gstring, ctrl[0]);
+         APPEND_GLYPH (gstring, ctrl[1]);
+       }
+      else
+       APPEND_GLYPH (gstring, g_tmp);
+      if (c == '\n' && gstring->control.two_dimensional)
+       break;
+    }
+  /* Append an anchor glyph.  */
+  INIT_GLYPH (g_tmp);
+  g_tmp.type = GLYPH_ANCHOR;
+  g_tmp.g.from = g_tmp.g.to = pos;
+  APPEND_GLYPH (gstring, g_tmp);
+  gstring->to = pos;
+
+  if (gstring->control.enable_bidi)
+    max_bidi_level = analyse_bidi_level (gstring);
+
+  /* The next loop is to change each <rface> member for non-ASCII
+     characters if necessary.  */
+  stop = charset_change = language_change = from;
+  rfont = default_rface->rfont;
+  for (last_g = g = MGLYPH (1); g->type != GLYPH_ANCHOR; g++)
+    {
+      int c = g->g.c;
+      MSymbol this_script;
+
+      if (c < 0x100)
+       /* Short cut for the obvious case.  */
+       this_script = Mlatin;
+      else
+       {
+         this_script = (MSymbol) mchar_get_prop (c, Mscript);
+         if (this_script == Minherited || this_script == Mcommon)
+           {
+             if (g > MGLYPH (1))
+               {
+                 MSymbol category = mchar_get_prop (g[-1].g.c, Mcategory);
+
+                 if (category != Mnil && MSYMBOL_NAME (category)[0] != 'Z')
+                   this_script = script;
+               }
+           }
+         if (this_script == Mcommon && non_latin_script)
+           this_script = non_latin_script;
+         if (this_script == Mcommon)
+           {
+             /* Search forward for a character that explicitly
+                specifies a non-latin script.  */
+             MSymbol sym;
+             MGlyph *g1;
+
+             for (g1 = g + 1; g1->type != GLYPH_ANCHOR; g1++)
+               if (g1->g.c >= 0x100
+                   && (sym = mchar_get_prop (g1->g.c, Mscript)) != Mcommon
+                   && sym != Minherited)
+                 {
+                   this_script = sym;
+                   break;
+                 }
+           }
+       }
+
+      pos = g->g.from;
+      if (pos == stop || script != this_script || g->rface->rfont != rfont)
+       {
+         while (last_g < g)
+           last_g = mface__for_chars (script, language, charset,
+                                      last_g, g, size);
+         script = this_script;
+         if (script != Mnil && script != Mlatin)
+           non_latin_script = script;
+         rfont = g->rface->ascii_rface->rfont;
+         if (pos == stop)
+           {
+             if (pos < mtext_nchars (mt) && pos == language_change)
+               {
+                 language = (MSymbol) mtext_get_prop (mt, pos, Mlanguage);
+                 mtext_prop_range (mt, Mlanguage, pos, NULL,
+                                   &language_change, 0);
+               }
+             if (pos < mtext_nchars (mt) && pos == charset_change)
+               {
+                 charset = (MSymbol) mtext_get_prop (mt, pos, Mcharset);
+                 mtext_prop_range (mt, Mcharset, pos, NULL,
+                                   &charset_change, 0);
+               }
+             stop = to;
+             if (stop > language_change)
+               stop = language_change;
+             if (stop > charset_change)
+               stop = charset_change;
+           }
+       }
+    }
+  while (last_g < g)
+    last_g = mface__for_chars (script, language, charset, last_g, g, size);
+
+  /* The next loop is to run FLT or perform the default combining if
+     necessary.  */
+  for (i = 1, g = MGLYPH (1); g->type != GLYPH_ANCHOR;)
+    {
+      MGlyph *this = g;
+
+      if (this->type == GLYPH_CHAR && this->rface->rfont)
+       {
+         int start = i++;
+
+         if (this->rface->layouter != Mnil)
+           {
+             MGlyph *prev = MGLYPH (start - 1);
+
+             while (prev->type == GLYPH_CHAR
+                    && prev->category == GLYPH_CATEGORY_FORMATTER
+                    && (mfont__encode_char (NULL, (MFont *) this->rface->rfont,
+                                            NULL, prev->g.c)
+                        != MCHAR_INVALID_CODE))
+               {
+                 prev->rface->rfont = this->rface->rfont;
+                 start--, prev--;
+               }
+
+             for (g++;
+                  (g->type == GLYPH_CHAR
+                   && g->g.from != gstring->control.cursor_pos
+                   && g->rface->layouter == this->rface->layouter
+                   && (g->rface->rfont == this->rface->rfont
+                       || (g->category == GLYPH_CATEGORY_FORMATTER
+                           && (mfont__encode_char (NULL,
+                                                   (MFont *) this->rface->rfont,
+                                                   NULL, g->g.c)
+                               != MCHAR_INVALID_CODE))));
+                  i++, g++)
+               g->rface->rfont = this->rface->rfont;
+             i = run_flt (gstring, start, i, this->rface);
+           }
+         else
+           {
+             g++;
+             while (g->type == GLYPH_CHAR
+                    && g->g.c >= 0x100
+                    && g->category == GLYPH_CATEGORY_MODIFIER
+                    && g->rface->rfont
+                    && g->rface->layouter == Mnil)
+               i++, g++;
+             if (start + 1 < i)
+               {
+                 this->rface->layouter = Mcombining;
+                 run_flt (gstring, start, i, this->rface);
+               }
+             else
+               mfont__get_metric (gstring, start, i);
+           }
+         g = MGLYPH (i);
+       }
+      else
+       i++, g++;
+    }
+
+  /* At last, reorder glyphs visually if necessary.  */
+  if (max_bidi_level > 0)
+    visual_order (gstring);
+}
+
+typedef struct {
+  int width, lbearing, rbearing;
+} MSubTextExtents;
+
+static void
+layout_glyphs (MFrame *frame, MGlyphString *gstring, int from, int to,
+              MSubTextExtents *extents)
+{
+  int g_physical_ascent, g_physical_descent;
+  MGlyph *g = MGLYPH (from);
+  MGlyph *last_g = MGLYPH (to);
+
+  g_physical_ascent = gstring->physical_ascent;
+  g_physical_descent = gstring->physical_descent;
+  extents->width = extents->lbearing = extents->rbearing = 0;
+
+  for (g = MGLYPH (from); g < last_g; g++)
+    {
+      g_physical_ascent = MAX (g_physical_ascent, g->g.ascent);
+      g_physical_descent = MAX (g_physical_descent, g->g.descent);
+      extents->lbearing = MIN (extents->lbearing,
+                              extents->width + g->g.lbearing);
+      extents->rbearing = MAX (extents->rbearing,
+                              extents->width + g->g.rbearing);
+      extents->width += g->g.xadv;
+    }
+
+  gstring->physical_ascent = g_physical_ascent;
+  gstring->physical_descent = g_physical_descent;
+}
+
+
+/** Decide the layout of glyphs in GSTRING.  Space glyphs are handled
+    by this function directly.  Character glyphs are handled by
+    layouter functions registered in font drivers.
+
+    This function fill-in all the remaining members of glyphs.  */
+
+static void
+layout_glyph_string (MFrame *frame, MGlyphString *gstring)
+{
+  /* Default width of TAB.  */
+  int tab_width = frame->space_width * (gstring->control.tab_width
+                                       ? gstring->control.tab_width : 8);
+  int tab_found = 0;
+  MGlyph *g;
+  MGlyph pad;
+  MDrawControl *control = &(gstring->control);
+  int width;
+  MFaceBoxProp *box;
+  int box_line_height = 0;
+  int ignore_formatting_char = control->ignore_formatting_char;
+
+  gstring->ascent = gstring->descent = 0;
+  gstring->physical_ascent = gstring->physical_descent = 0;
+  gstring->width = gstring->lbearing = gstring->rbearing = 0;
+
+  g = MGLYPH (1);
+  box = NULL;
+  while (g->type != GLYPH_ANCHOR)
+    {
+      if (box != g->rface->box)
+       {
+         int gidx = GLYPH_INDEX (g);
+
+         if (box)
+           {
+             /* Insert the right side of the box.  That glyph belongs
+                to the previous grapheme cluster.  */
+             MGlyph box_glyph = g[-1];
+
+             box_glyph.type = GLYPH_BOX;
+             box_glyph.g.xadv
+               = (control->fixed_width
+                  ? frame->space_width
+                  : box->inner_hmargin + box->width + box->outer_hmargin);
+             box_glyph.g.lbearing = 0;
+             box_glyph.g.rbearing = box_glyph.g.xadv;
+             box_glyph.g.xoff = 0;
+             box_glyph.right_padding = 1;
+             gstring->width += box_glyph.g.xadv;
+             gstring->rbearing += box_glyph.g.xadv;
+             INSERT_GLYPH (gstring, gidx, box_glyph);
+             gidx++;
+             g = MGLYPH (gidx);
+           }
+         box = g->rface->box;
+         if (box)
+           {
+             /* Insert the left side of the box.  That glyph belongs
+                to the following grapheme cluster.  */
+             MGlyph box_glyph = *g;
+             int box_height = (box->width
+                               + box->inner_vmargin + box->outer_vmargin);
+
+             if (box_line_height < box_height)
+               box_line_height = box_height;
+             box_glyph.type = GLYPH_BOX;
+             box_glyph.g.xadv
+               = (control->fixed_width
+                  ? frame->space_width
+                  : box->inner_hmargin + box->width + box->outer_hmargin);
+             box_glyph.g.lbearing = 0;
+             box_glyph.g.rbearing = box_glyph.g.xadv;
+             box_glyph.g.xoff = 0;
+             box_glyph.left_padding = 1;
+             gstring->width += box_glyph.g.xadv;
+             gstring->rbearing += box_glyph.g.xadv;
+             INSERT_GLYPH (gstring, gidx, box_glyph);
+             gidx++;
+             g = MGLYPH (gidx);
+           }
+       }
+
+      if (g->category == GLYPH_CATEGORY_FORMATTER && ignore_formatting_char)
+       g->type = GLYPH_SPACE;
+
+      if (g->type == GLYPH_CHAR)
+       {
+         MRealizedFace *rface = g->rface;
+         MRealizedFont *rfont = rface->rfont;
+         MGlyph *fromg = g;
+         int from = GLYPH_INDEX (g);
+
+         for (g++; g->type == GLYPH_CHAR; g++)
+           if (! rfont != ! g->rface->rfont
+               || box != g->rface->box
+               || ((fromg->g.code == MCHAR_INVALID_CODE)
+                   != (g->g.code == MCHAR_INVALID_CODE))
+               || (g->category == GLYPH_CATEGORY_FORMATTER
+                   && ignore_formatting_char))
+             break;
+         if (rfont && fromg->g.code != MCHAR_INVALID_CODE)
+           {
+             int extra_width;
+             int to = GLYPH_INDEX (g);
+             MSubTextExtents extents;
+
+             layout_glyphs (frame, gstring, from, to, &extents);
+             extra_width = - extents.lbearing;
+             if (extra_width > 0
+                 && ! control->disable_overlapping_adjustment
+                 && (! control->orientation_reversed
+                     ? ((to > 1 || control->align_head)
+                        && g->type != GLYPH_ANCHOR)
+                     : (((g->type && GLYPH_ANCHOR) || control->align_head)
+                        && to > 1)))
+               {
+                 g = MGLYPH (from);
+                 pad = *g;
+                 pad.type = GLYPH_PAD;
+                 pad.g.xoff = 0;
+                 pad.g.lbearing = 0;
+                 pad.g.xadv = pad.g.rbearing = extra_width;
+                 pad.left_padding = 1;
+                 INSERT_GLYPH (gstring, from, pad);
+                 to++;
+                 extents.lbearing = 0;
+                 extents.width += extra_width;
+                 extents.rbearing += extra_width;
+
+                 g = MGLYPH (from - 1);
+                 if (g->type == GLYPH_SPACE)
+                   {
+                     /* The pad just inserted is absorbed (maybe
+                        partially) by the previous space while
+                        keeping at least some space width.  For the
+                        moment, we use the arbitrary width 2-pixel.
+                        Perhaps, it should be decided by the current
+                        face, or a default value of the current
+                        frame, which is, however, not yet
+                        implemented.  */
+                     if (extra_width + 2 < g->g.xadv)
+                       {
+                         g->g.xadv -= extra_width;
+                       }
+                     else
+                       {
+                         extra_width = g->g.xadv - 2;
+                         g->g.xadv = 2;
+                       }
+                     gstring->width -= extra_width;
+                     gstring->rbearing -= extra_width;
+                   }
+               }
+
+             g = MGLYPH (to);
+             extra_width = extents.rbearing - extents.width;
+             if (extra_width > 0
+                 && ! control->disable_overlapping_adjustment
+                 && (GLYPH_INDEX (g) < gstring->used - 1
+                     || (control->orientation_reversed && control->align_head)))
+               {
+                 if (g->type == GLYPH_SPACE && box == g->rface->box)
+                   {
+                     pad = g[-1];
+                     pad.type = GLYPH_PAD;
+                     pad.g.xoff = 0;
+                     pad.g.lbearing = 0;
+                     pad.g.xadv = pad.g.rbearing = extra_width;
+                     INSERT_GLYPH (gstring, to, pad);
+                     to++;
+                     g = MGLYPH (to);
+                   }
+                 else
+                   g[-1].g.xadv += extra_width;
+                 extents.width += extra_width;
+               }
+
+             if (gstring->lbearing > gstring->width + extents.lbearing)
+               gstring->lbearing = gstring->width + extents.lbearing;
+             if (gstring->rbearing < gstring->width + extents.rbearing)
+               gstring->rbearing = gstring->width + extents.rbearing;
+             gstring->width += extents.width;
+             if (gstring->ascent < rface->ascent)
+               gstring->ascent = rface->ascent;
+             if (gstring->descent < rface->descent)
+               gstring->descent = rface->descent;
+           }
+         else
+           {
+             for (; fromg < g; fromg++)
+               {
+                 if ((fromg->g.c >= 0x200B && fromg->g.c <= 0x200F)
+                     || (fromg->g.c >= 0x202A && fromg->g.c <= 0x202E))
+                   fromg->g.xadv = fromg->g.rbearing = 1;
+                 else
+                   fromg->g.xadv = fromg->g.rbearing = rface->space_width;
+                 fromg->g.xoff = fromg->g.lbearing = 0;
+                 fromg->g.ascent = fromg->g.descent = 0;
+                 gstring->width += fromg->g.xadv;
+                 gstring->rbearing += fromg->g.xadv;
+               }
+             if (gstring->ascent < frame->rface->ascent)
+               gstring->ascent = frame->rface->ascent;
+             if (gstring->descent < frame->descent)
+               gstring->descent = frame->rface->descent;
+           }
+       }
+      else if (g->type == GLYPH_SPACE)
+       {
+         if (g->g.c == ' ')
+           g->g.xadv = g->rface->space_width;
+         else if (g->g.c == '\n')
+           {
+             g->g.xadv = control->cursor_width;
+             if (g->g.xadv)
+               {
+                 if (control->cursor_bidi)
+                   g->g.xadv = 3;
+                 else if (g->g.xadv < 0)
+                   g->g.xadv = g->rface->space_width;
+               }
+           }
+         else if (g->g.c == '\t')
+           {
+             g->g.xadv = tab_width - ((gstring->indent + gstring->width)
+                                      % tab_width);
+             tab_found = 1;
+           }
+         else
+           g->g.xadv = 1;
+         if (g[-1].type == GLYPH_PAD)
+           {
+             /* This space glyph absorbs (maybe partially) the
+                previous padding glyph.  */
+             g->g.xadv -= g[-1].g.xadv;
+             if (g->g.xadv < 1)
+               /* But, keep at least some space width.  For the
+                  moment, we use the arbitrary width 2-pixel.  */
+               g->g.xadv = 2;
+           }
+         g->g.rbearing = g->g.xadv;
+         gstring->width += g->g.xadv;
+         gstring->rbearing += g->g.xadv;
+         if (g->rface->rfont)
+           {
+             if (gstring->ascent < g->rface->ascent)
+               gstring->ascent = g->rface->ascent;
+             if (gstring->descent < g->rface->descent)
+               gstring->descent = g->rface->descent;
+           }
+         g++;
+       }
+      else
+       {
+         gstring->width += g->g.xadv;
+         gstring->rbearing += g->g.xadv;
+         g++;
+       }
+    }
+
+  if (box)
+    {
+      /* Insert the right side of the box.  */
+      int gidx = GLYPH_INDEX (g);
+      MGlyph box_glyph = g[-1];
+
+      box_glyph.type = GLYPH_BOX;
+      box_glyph.g.xadv
+       = (control->fixed_width
+          ? frame->space_width
+          : box->inner_hmargin + box->width + box->outer_hmargin);
+      box_glyph.g.lbearing = 0;
+      box_glyph.g.rbearing = box_glyph.g.xadv;
+      box_glyph.g.xoff = 0;
+      box_glyph.right_padding = 1;
+      gstring->width += box_glyph.g.xadv;
+      gstring->rbearing += box_glyph.g.xadv;
+      INSERT_GLYPH (gstring, gidx, box_glyph);
+    }
+
+  gstring->text_ascent = gstring->ascent;
+  gstring->text_descent = gstring->descent;
+  if (gstring->text_ascent < gstring->physical_ascent)
+    gstring->text_ascent = gstring->physical_ascent;
+  if (gstring->text_descent < gstring->physical_descent)
+    gstring->text_descent = gstring->physical_descent;
+  gstring->line_ascent = gstring->text_ascent;
+  gstring->line_descent = gstring->text_descent;
+  if (box_line_height > 0)
+    {
+      gstring->line_ascent += box_line_height;
+      gstring->physical_ascent = gstring->line_ascent;
+      gstring->line_descent += box_line_height;
+      gstring->physical_descent = gstring->line_descent;
+    }
+
+  if (gstring->line_ascent < control->min_line_ascent)
+    gstring->line_ascent = control->min_line_ascent;
+  else if (control->max_line_ascent
+          && control->max_line_ascent > control->min_line_ascent
+          && gstring->line_ascent > control->max_line_ascent)
+    gstring->line_ascent = control->max_line_ascent;
+
+  if (gstring->line_descent < control->min_line_descent)
+    gstring->line_descent = control->min_line_descent;
+  else if (control->max_line_descent
+          && control->max_line_descent > control->min_line_descent
+          && gstring->line_descent > control->max_line_descent)
+    gstring->line_descent = control->max_line_descent;
+  gstring->height = gstring->line_ascent + gstring->line_descent;
+
+  if (control->orientation_reversed
+      && tab_found)
+    {
+      /* We must adjust TAB width for RTL orientation.  */
+      width = gstring->indent;
+
+      for (g = MGLYPH (gstring->used - 2); g->type != GLYPH_ANCHOR; g--)
+       {
+         if (g->type == GLYPH_CHAR && g->g.c == '\t')
+           {
+             int this_width = tab_width - (width % tab_width);
+
+             if (g[1].type == GLYPH_PAD)
+               this_width -= g[1].g.xadv;
+             if (g[-1].type == GLYPH_PAD)
+               this_width -= g[-1].g.xadv;             
+             if (this_width < 2)
+               this_width = 2;
+             gstring->width += this_width - g->g.xadv;
+             gstring->rbearing += this_width - g->g.xadv;
+             g->g.xadv = this_width;
+             width += this_width;
+           }
+         else
+           width += g->g.xadv;
+       }
+    }
+}
+
+
+static MDrawRegion
+draw_background (MFrame *frame, MDrawWindow win, int x, int y,
+                MGlyphString *gstring, int from, int to,
+                int *from_idx, int *to_idx, int *to_x)
+{
+  MGlyph *g = MGLYPH (1);
+  MDrawRegion region = (MDrawRegion) NULL;
+  MDrawControl *control = &gstring->control;
+  int cursor_pos = -1;
+  int prev_pos = -1;
+  int cursor_bidi = control->cursor_bidi;
+
+  if (control->with_cursor && control->cursor_width)
+    {
+      if (gstring->from <= control->cursor_pos
+         && gstring->to > control->cursor_pos)
+       cursor_pos = control->cursor_pos;
+      if (cursor_pos >= 0
+         && cursor_bidi
+         && gstring->from <= control->cursor_pos - 1
+         && gstring->to > control->cursor_pos - 1)
+       prev_pos = control->cursor_pos - 1;
+    }
+
+  *from_idx = *to_idx = 0;
+  *to_x = x;
+  while (g->type != GLYPH_ANCHOR)
+    {
+      if (g->g.from >= from && g->g.from < to)
+       {
+         MGlyph *fromg = g, *cursor = NULL;
+         MRealizedFace *rface = g->rface;
+         int width = 0;
+         int cursor_width = 0;
+         int cursor_x;
+
+         if (! *from_idx)
+           *from_idx = GLYPH_INDEX (g);
+         while (g->g.from >= from && g->g.from < to
+                && g->rface == rface)
+           {
+             g->enabled = 1;
+             if (g->type != GLYPH_BOX
+                 && g->g.from <= cursor_pos && g->g.to > cursor_pos)
+               {
+                 if (! cursor)
+                   cursor = g, cursor_x = x + width;
+                 cursor_width += g->g.xadv;
+               }
+             width += g++->g.xadv;
+           }
+         if (width > 0
+             && (control->as_image
+                 || rface->face.property[MFACE_VIDEOMODE] == Mreverse))
+           {
+             int this_x = x, this_width = width;
+
+             if (fromg->type == GLYPH_BOX)
+               this_x += fromg->g.xadv, this_width -= fromg->g.xadv;
+             if (g[-1].type == GLYPH_BOX)
+               this_width -= g[-1].g.xadv;
+             (frame->driver->fill_space)
+               (frame, win, rface, 0,
+                this_x, y - gstring->text_ascent, this_width,
+                gstring->text_ascent + gstring->text_descent,
+                control->clip_region);
+           }
+         if (cursor)
+           {
+             MDrawMetric rect;
+           
+             rect.x = cursor_x;
+             rect.y = y - gstring->text_ascent;
+             rect.height = gstring->text_ascent + gstring->text_descent;
+             if (! cursor_bidi)
+               {
+                 rect.width = ((control->cursor_width > 0
+                                && control->cursor_width < cursor_width)
+                               ? control->cursor_width : cursor_width);
+               }
+             else
+               rect.width = 1;
+             if (cursor->bidi_level % 2)
+               rect.x += cursor_width - rect.width;
+             (*frame->driver->fill_space)
+               (frame, win, rface, 1, rect.x, rect.y, rect.width, rect.height,
+                control->clip_region);
+             if (! region)
+               region = (*frame->driver->region_from_rect) (&rect);
+             else
+               (*frame->driver->region_add_rect) (region, &rect);
+             if (cursor_bidi)
+               {
+                 if (cursor->bidi_level % 2)
+                   rect.x -= 3;
+                 rect.height = 2;
+                 rect.width = cursor_width < 4 ? cursor_width : 4;
+                 (*frame->driver->fill_space)
+                   (frame, win, rface, 1,
+                    rect.x, rect.y, rect.width, rect.height,
+                    control->clip_region);
+                 (*frame->driver->region_add_rect) (region, &rect);
+               }
+           }
+
+         if (prev_pos >= 0)
+           {
+             int temp_width = 0;
+
+             cursor_width = 0;
+             cursor = NULL;
+             while (fromg < g)
+               {
+                 if (fromg->type != GLYPH_BOX
+                     && fromg->g.from <= prev_pos && fromg->g.to > prev_pos)
+                   {
+                     if (! cursor)
+                       cursor = fromg, cursor_x = x + temp_width;
+                     cursor_width += fromg->g.xadv;
+                   }
+                 temp_width += fromg++->g.xadv;
+               }
+             if (cursor)
+               {
+                 MDrawMetric rect;
+
+                 rect.x = cursor_x;
+                 if (! (cursor->bidi_level % 2))
+                   rect.x += cursor_width - 1;
+                 rect.y = y - gstring->text_ascent;
+                 rect.height = gstring->text_ascent + gstring->text_descent;
+                 rect.width = 1;
+                 (*frame->driver->fill_space)
+                   (frame, win, rface, 1,
+                    rect.x, rect.y, rect.width, rect.height,
+                    control->clip_region);
+                 if (! region)
+                   region = (*frame->driver->region_from_rect) (&rect);
+                 else
+                   (*frame->driver->region_add_rect) (region, &rect);
+                 rect.y += rect.height - 2;
+                 rect.height = 2;
+                 rect.width = cursor_width < 4 ? cursor_width : 4;
+                 if (! (cursor->bidi_level % 2))
+                   rect.x -= rect.width - 1;
+                 (*frame->driver->fill_space) (frame, win, rface, 1,
+                                   rect.x, rect.y, rect.width, rect.height,
+                                   control->clip_region);
+                 (*frame->driver->region_add_rect) (region, &rect);
+               }
+           }
+         x += width;
+         *to_idx = GLYPH_INDEX (g);
+         *to_x = x;
+       }
+      else
+       g++->enabled = 0;
+    }
+  return region;
+}
+
+static void
+render_glyphs (MFrame *frame, MDrawWindow win, int x, int y, int width,
+              MGlyphString *gstring, int from_idx, int to_idx,
+              int reverse, MDrawRegion region)
+{
+  MGlyph *g = MGLYPH (from_idx), *gend = MGLYPH (to_idx);
+
+  if (region)
+    {
+      MDrawMetric rect;
+
+      (*frame->driver->region_to_rect) (region, &rect);
+      if (rect.x > x)
+       {
+         while (g != gend && x + g->g.rbearing <= rect.x)
+           {
+             x += g->g.xadv;
+             width -= g++->g.xadv;
+             while (! g->enabled && g != gend)
+               g++;
+           }
+       }
+      rect.x += rect.width;
+      if (rect.x < x + width)
+       {
+         while (g != gend
+                && (x + width - gend[-1].g.xadv + gend[-1].g.lbearing >= rect.x))
+           {
+             width -= (--gend)->g.xadv;
+             while (! gend->enabled && g != gend)
+               gend--;
+           }
+         if (g != gend)
+           while (gend->type != GLYPH_ANCHOR && gend[-1].g.to == gend->g.to)
+             gend++;
+       }
+    }
+
+  while (g != gend)
+    {
+      if (g->enabled)
+       {
+         MRealizedFace *rface = g->rface;
+         int width = g->g.xadv;
+         MGlyph *from_g = g++;
+
+         /* Handle the glyphs of the same type/face at once.  */
+         while (g != gend
+                && g->type == from_g->type
+                && g->rface == rface
+                && ((g->g.code == MCHAR_INVALID_CODE)
+                    == (from_g->g.code == MCHAR_INVALID_CODE))
+                && g->enabled)
+           width += g++->g.xadv;
+
+         if (from_g->type == GLYPH_CHAR)
+           {
+             if (rface->rfont && from_g->g.code != MCHAR_INVALID_CODE)
+               (rface->rfont->driver->render) (win, x, y, gstring, from_g, g,
+                                               reverse, region);
+             else
+               (*frame->driver->draw_empty_boxes) (win, x, y, gstring, from_g, g,
+                                       reverse, region);
+           }
+         else if (from_g->type == GLYPH_BOX)
+           {
+             /* Draw the left or right side of a box.  If
+                from_g->lbearing is nonzero, this is the left side,
+                else this is the right side.  */
+             (*frame->driver->draw_box) (frame, win, gstring, from_g, x, y, 0, region);
+           }
+
+         if (from_g->type != GLYPH_BOX)
+           {
+             if (rface->hline)
+               (*frame->driver->draw_hline) (frame, win, gstring, rface, reverse,
+                                 x, y, width, region);
+             if (rface->box
+                 && ! reverse)
+               /* Draw the top and bottom side of a box.  */
+               (*frame->driver->draw_box) (frame, win, gstring, from_g,
+                                  x, y, width, region);
+           }
+         x += width;
+       }
+      else
+       g++;
+    }
+}
+
+
+static int
+find_overlapping_glyphs (MGlyphString *gstring, int *left, int *right,
+                        int *from_x, int *to_x)
+{
+  MGlyph *g;
+  int left_idx = *left, right_idx = *right;
+  int left_x, right_x, x;
+
+  for (g = MGLYPH (*left) - 1, x = 0; g->type != GLYPH_ANCHOR; g--)
+    {
+      x -= g->g.xadv;
+      if (x + g->g.rbearing > 0)
+       {
+         while (g[-1].g.from == g->g.from && g[-1].type != GLYPH_ANCHOR)
+           x -= (--g)->g.xadv;
+         left_idx = GLYPH_INDEX (g);
+         left_x = x;
+       }
+    }
+
+  for (g = MGLYPH (*right), x = 0; g->type != GLYPH_ANCHOR; g++)
+    {
+      x += g->g.xadv;
+      if (x - g->g.xadv + g->g.lbearing < 0)
+       {
+         while (g->g.from == g[1].g.from && g[1].type != GLYPH_ANCHOR)
+           x += (++g)->g.xadv;
+         right_idx = GLYPH_INDEX (g) + 1;
+         right_x = x;
+       }
+    }
+
+  if (*left == left_idx && *right == right_idx)
+    return 0;
+
+  if (*left != left_idx)
+    {
+      for (g = MGLYPH (*left) - 1; GLYPH_INDEX (g) >= left_idx; g--)
+       g->enabled = 1;
+      *left = left_idx;
+      *from_x += left_x;
+    }
+  if (*right != right_idx)
+    {
+      for (g = MGLYPH (*right); GLYPH_INDEX (g) < right_idx; g++)
+       g->enabled = 1;
+      *right = right_idx;
+      *to_x += right_x;
+    }
+  return 1;
+}
+
+
+static int
+gstring_width (MGlyphString *gstring, int from, int to,
+              int *lbearing, int *rbearing)
+{
+  MGlyph *g;
+  int width;
+
+  if (from <= gstring->from && to >= gstring->to)
+    {
+      if (lbearing)
+       *lbearing = gstring->lbearing;
+      if (rbearing)
+       *rbearing = gstring->rbearing;
+      return gstring->width;
+    }
+
+  if (lbearing)
+    *lbearing = 0;
+  if (rbearing)
+    *rbearing = 0;
+  for (g = MGLYPH (1), width = 0; g->type != GLYPH_ANCHOR; g++)
+    if (g->g.from >= from && g->g.from < to)
+      {
+       if (lbearing && width + g->g.lbearing < *lbearing)
+         *lbearing = width + g->g.lbearing;
+       if (rbearing && width + g->g.rbearing > *rbearing)
+         *rbearing = width + g->g.rbearing;
+       width += g->g.xadv;
+      }
+  return width;
+}
+
+
+static void
+render_glyph_string (MFrame *frame, MDrawWindow win, int x, int y,
+                    MGlyphString *gstring, int from, int to)
+{
+  MDrawControl *control = &gstring->control;
+  MDrawMetric rect;
+  MDrawRegion clip_region, cursor_region;
+  int from_idx, to_idx;
+  int to_x;
+
+  if (from == to)
+    return;
+  if (control->orientation_reversed)
+    x -= gstring->indent + gstring_width (gstring, from, to, NULL, NULL);
+  else
+    x += gstring->indent;
+
+  /* At first, draw all glyphs without cursor.  */
+  cursor_region = draw_background (frame, win, x, y, gstring, from, to,
+                                  &from_idx, &to_idx, &to_x);
+
+  if (control->partial_update)
+    {
+      rect.x = x;
+      rect.width = to_x - x;
+      if (find_overlapping_glyphs (gstring, &from_idx, &to_idx, &x, &to_x))
+       {
+         rect.y = y - gstring->line_ascent;
+         rect.height = gstring->height;
+         clip_region = (*frame->driver->region_from_rect) (&rect);
+         if (control->clip_region)
+           (*frame->driver->intersect_region) (clip_region, control->clip_region);
+       }
+      else
+       clip_region = control->clip_region;
+    }
+  else
+    clip_region = control->clip_region;
+
+  render_glyphs (frame, win, x, y, to_x - x, gstring, from_idx, to_idx,
+                0, clip_region);
+  if (cursor_region)
+    {
+      if (clip_region)
+       (*frame->driver->intersect_region) (cursor_region, clip_region);
+      render_glyphs (frame, win, x, y, to_x - x, gstring, from_idx, to_idx,
+                    1, cursor_region);
+    }
+  if (clip_region != control->clip_region)
+    (*frame->driver->free_region) (clip_region);
+  if (cursor_region)
+    (*frame->driver->free_region) (cursor_region);
+  return;
+}
+
+static int gstring_num;
+
+static void
+free_gstring (void *object)
+{
+  MGlyphString *gstring = (MGlyphString *) object;
+
+  if (gstring->next)
+    free_gstring (gstring->next);
+  if (gstring->size > 0)
+    free (gstring->glyphs);
+  free (gstring);
+  gstring_num--;
+}
+
+
+static MGlyphString scratch_gstring;
+
+static MGlyphString *
+alloc_gstring (MFrame *frame, MText *mt, int pos, MDrawControl *control,
+              int line, int y)
+{
+  MGlyphString *gstring;
+
+  if (pos == mt->nchars)
+    {
+      MGlyph *g;
+
+      gstring = &scratch_gstring;
+      if (gstring->size == 0)
+       {
+         MGlyph g_tmp;
+
+         INIT_GLYPH (g_tmp);
+         g_tmp.type = GLYPH_ANCHOR;
+         APPEND_GLYPH (gstring, g_tmp);
+         APPEND_GLYPH (gstring, g_tmp);
+         APPEND_GLYPH (gstring, g_tmp);
+         gstring->glyphs[1].type = GLYPH_SPACE;
+         gstring->glyphs[1].g.c = '\n';
+         gstring->glyphs[1].g.code = '\n';
+       }
+      gstring->from = pos;
+      g = MGLYPH (0);
+      g->rface = frame->rface;
+      g->g.from = g->g.to = pos;
+      g++;
+      g->rface = frame->rface;
+      g->g.from = pos++, g->g.to = pos;
+      g++;
+      g->rface = frame->rface;
+      g->g.from = g->g.to = pos;
+      gstring->to = pos;
+    }
+  else
+    {
+      M17N_OBJECT (gstring, free_gstring, MERROR_DRAW);
+      MLIST_INIT1 (gstring, glyphs, 128);
+      gstring_num++;
+    }
+
+  gstring->frame = frame;
+  gstring->tick = frame->tick;
+  gstring->top = gstring;
+  gstring->control = *control;
+  gstring->indent = gstring->width_limit = 0;
+  if (control->format)
+    (*control->format) (line, y, &(gstring->indent), &(gstring->width_limit));
+  else
+    gstring->width_limit = control->max_line_width;
+  gstring->anti_alias = control->anti_alias;
+  return gstring;
+}
+
+static MGlyph *find_glyph_in_gstring (MGlyphString *gstring, int pos,
+                                     int forwardp);
+
+/* Truncate the line width of GSTRING to GSTRING->width_limit.  */
+
+static void
+truncate_gstring (MFrame *frame, MText *mt, MGlyphString *gstring)
+{
+  int width;
+  int i;
+  int *pos_width;
+  MGlyph *g;
+  int pos;
+
+  /* Setup the array POS_WIDTH so that POS_WIDTH[I - GSTRING->from] is
+     a width of glyphs for the character at I of MT.  If I is not a
+     beginning of a grapheme cluster, the corresponding element is
+     0.  */
+  MTABLE_ALLOCA (pos_width, gstring->to - gstring->from, MERROR_DRAW);
+  memset (pos_width, 0, sizeof (int) * (gstring->to - gstring->from));
+  for (g = MGLYPH (1); g->type != GLYPH_ANCHOR; g++)
+    pos_width[g->g.from - gstring->from] += g->g.xadv;
+  for (i = 0, width = 0; i < gstring->to - gstring->from; i++)
+    {
+      if (pos_width[i] > 0)
+       {
+         if (width + pos_width[i] > gstring->width_limit)
+           break;
+       }
+      width += pos_width[i];
+    }
+
+  pos = gstring->from + i;
+  if (gstring->control.line_break)
+    {
+      pos = (*gstring->control.line_break) (mt, gstring->from + i,
+                                           gstring->from, gstring->from + i,
+                                           0, 0);
+      if (pos <= gstring->from)
+       {
+         g = find_glyph_in_gstring (gstring, gstring->from, 1);
+         pos = g->g.to;
+       }
+      else if (pos >= gstring->to)
+       pos = gstring->to;
+    }
+  else if (i == 0)
+    {
+      g = find_glyph_in_gstring (gstring, gstring->from, 1);
+      pos = g->g.to;
+    }
+  if (pos < gstring->to)
+    {
+      compose_glyph_string (frame, mt, gstring->from, pos, gstring);
+      layout_glyph_string (frame, gstring);
+    }
+}
+
+
+/* Return a gstring that covers a character at POS.  */
+
+static MGlyphString *
+get_gstring (MFrame *frame, MText *mt, int pos, int to, MDrawControl *control)
+{
+  MGlyphString *gstring = NULL;
+
+  if (pos < mtext_nchars (mt))
+    {
+      MTextProperty *prop = mtext_get_property (mt, pos, M_glyph_string);
+
+      if (prop
+         && ((prop->start != 0
+              && mtext_ref_char (mt, prop->start - 1) != '\n')
+             || (prop->end < mtext_nchars (mt)
+                 && mtext_ref_char (mt, prop->end - 1) != '\n')))
+       {
+         mtext_detach_property (prop);
+         prop = NULL;
+       }
+      if (prop)
+       {
+         gstring = prop->val;
+         if (gstring->frame != frame
+             || gstring->tick != frame->tick
+             || memcmp (control, &gstring->control,
+                        (char *) (&control->with_cursor)
+                        - (char *) (control))
+             || control->cursor_pos != gstring->control.cursor_pos
+             || control->cursor_width != gstring->control.cursor_width
+             || control->cursor_bidi != gstring->control.cursor_bidi)
+           {
+             mtext_detach_property (prop);
+             gstring = NULL;
+           }
+       }
+    }
+  else if (! control->cursor_width)
+    return NULL;
+
+  if (gstring)
+    {
+      MGlyphString *gst;
+      int offset;
+
+      offset = mtext_character (mt, pos, 0, '\n');
+      if (offset < 0)
+       offset = 0;
+      else
+       offset++;
+      offset -= gstring->from;
+      if (offset)
+       for (gst = gstring; gst; gst = gst->next)
+         {
+           int i;
+
+           gst->from += offset;
+           gst->to += offset;
+           for (i = 0; i < gst->used; i++)
+             {
+               gst->glyphs[i].g.from += offset;
+               gst->glyphs[i].g.to += offset;
+             }
+         }
+      M17N_OBJECT_REF (gstring);
+    }
+  else
+    {
+      int beg, end;
+      int line = 0, y = 0;
+
+      if (pos < mtext_nchars (mt))
+       {
+         beg = mtext_character (mt, pos, 0, '\n');
+         if (beg < 0)
+           beg = 0;
+         else
+           beg++;
+       }
+      else
+       beg = pos;
+      end = mtext_nchars (mt) + (control->cursor_width != 0);
+      gstring = alloc_gstring (frame, mt, beg, control, line, y);
+      if (beg < mtext_nchars (mt))
+       compose_glyph_string (frame, mt, beg, end, gstring);
+      layout_glyph_string (frame, gstring);
+      end = gstring->to;
+      if (gstring->width_limit
+         && gstring->width > gstring->width_limit)
+       {
+         MGlyphString *gst = gstring;
+
+         truncate_gstring (frame, mt, gst);
+         while (gst->to < end)
+           {
+             line++, y += gst->height;
+             gst->next = alloc_gstring (frame, mt, gst->from, control,
+                                        line, y);
+             gst->next->top = gstring;
+             compose_glyph_string (frame, mt, gst->to, end, gst->next);
+             gst = gst->next;
+             layout_glyph_string (frame, gst);
+             if (gst->width <= gst->width_limit)
+               break;
+             truncate_gstring (frame, mt, gst);
+           }
+       }
+
+      if (! control->disable_caching && pos < mtext_nchars (mt))
+       {
+         MTextProperty *prop = mtext_property (M_glyph_string, gstring,
+                                               MTEXTPROP_VOLATILE_STRONG);
+
+         if (end > mtext_nchars (mt))
+           end = mtext_nchars (mt);
+         mtext_attach_property (mt, beg, end, prop);
+         M17N_OBJECT_UNREF (prop);
+       }
+    }
+
+  while (gstring->to <= pos)
+    {
+      if (! gstring->next)
+       mdebug_hook ();
+      gstring = gstring->next;
+    }
+  gstring->control = *control;
+
+  return gstring;
+}
+
+
+static MDrawControl control_noop;
+
+#define ASSURE_CONTROL(control)        \
+  if (! control)               \
+    control = &control_noop;   \
+  else
+
+
+static int
+draw_text (MFrame *frame, MDrawWindow win, int x, int y,
+          MText *mt, int from, int to,
+          MDrawControl *control)
+{
+  MGlyphString *gstring;
+
+  M_CHECK_POS_X (mt, from, -1);
+  ASSURE_CONTROL (control);
+  if (to > mtext_nchars (mt) + (control->cursor_width != 0))
+    to = mtext_nchars (mt) + (control->cursor_width != 0);
+  else if (to < from)
+    to = from;
+
+  gstring = get_gstring (frame, mt, from, to, control);
+  if (! gstring)
+    MERROR (MERROR_DRAW, -1);
+  render_glyph_string (frame, win, x, y, gstring, from, to);
+  from = gstring->to;
+  while (from < to)
+    {
+      y += gstring->line_descent;
+      M17N_OBJECT_UNREF (gstring->top);
+      gstring = get_gstring (frame, mt, from, to, control);
+      y += gstring->line_ascent;
+      render_glyph_string (frame, win, x, y, gstring, from, to);
+      from = gstring->to;
+    }
+  M17N_OBJECT_UNREF (gstring->top);
+
+  return 0;
+}
+
+
+static MGlyph *
+find_glyph_in_gstring (MGlyphString *gstring, int pos, int forwardp)
+{
+  MGlyph *g;
+
+  if (forwardp)
+    {
+      for (g = MGLYPH (1); g->type != GLYPH_ANCHOR; g++)
+       if (g->g.from <= pos && g->g.to > pos)
+         break;
+    }
+  else
+    {
+      for (g = MGLYPH (gstring->used - 2); g->type != GLYPH_ANCHOR; g--)
+       if (g->g.from <= pos && g->g.to > pos)
+         break;
+    }
+  return g;
+}
+
+\f
+/* for debugging... */
+char work[16];
+
+void
+dump_gstring (MGlyphString *gstring, int indent, int type)
+{
+  char *prefix = (char *) alloca (indent + 1);
+  MGlyph *g, *first_g, *last_g;
+
+  memset (prefix, 32, indent);
+  prefix[indent] = 0;
+
+  fprintf (stderr, "(glyph-string");
+
+  if (type == 0)
+    {
+      first_g = MGLYPH (0);
+      last_g = first_g + gstring->used;
+    }
+  else
+    {
+      first_g = (MGlyph *) ((MFLTGlyphString *) gstring)->glyphs;
+      last_g = first_g + ((MFLTGlyphString *) gstring)->used;
+    }
+
+  for (g = first_g; g < last_g; g++)
+    {
+      fprintf (stderr,
+              "\n%s  (%02d %s pos:%d-%d c:%04X code:%04X face:%x w:%02d bidi:%d",
+              prefix,
+              g - first_g,
+              (g->type == GLYPH_SPACE ? "SPC": g->type == GLYPH_PAD ? "PAD"
+               : g->type == GLYPH_ANCHOR ? "ANC"
+               : g->type == GLYPH_BOX ? "BOX" : "CHR"),
+              g->g.from, g->g.to, g->g.c, g->g.code, (unsigned) g->rface,
+              g->g.xadv, g->bidi_level);
+      if (g->g.xoff || g->g.yoff)
+       fprintf (stderr, " off:%d,%d", g->g.xoff, g->g.yoff);
+      fprintf (stderr, ")");
+    }
+  fprintf (stderr, ")");
+}
+\f
+
+/* m17n-X internal APIs */
+
+int
+mdraw__init ()
+{
+  M_glyph_string = msymbol_as_managing_key ("  glyph-string");
+
+  memset (&scratch_gstring, 0, sizeof (scratch_gstring));
+  MLIST_INIT1 (&scratch_gstring, glyphs, 3);
+
+  Mcommon = msymbol ("common");
+
+  McatCc = msymbol ("Cc");
+  McatCf = msymbol ("Cf");
+
+  MbidiR = msymbol ("R");
+  MbidiAL = msymbol ("AL");
+  MbidiRLE = msymbol ("RLE");
+  MbidiRLO = msymbol ("RLO");
+  MbidiBN = msymbol ("BN");
+  MbidiS = msymbol ("S");
+  MbidiNSM = msymbol ("NSM");
+#ifdef HAVE_FRIBIDI
+#if FRIBIDI_INTERFACE_VERSION < 3
+  fribidi_set_mirroring (TRUE);
+#else
+  fribidi_set_mirroring (1);
+#endif
+#endif
+
+  M_break_at_space = msymbol ("bs");
+  M_break_at_word = msymbol ("bw");
+  M_break_at_any = msymbol ("ba");
+  M_kinsoku_bol = msymbol ("kb");
+  M_kinsoku_eol = msymbol ("ke");
+
+  mflt_enable_new_feature = 1;
+
+  return 0;
+}
+
+void
+mdraw__fini ()
+{
+  MLIST_FREE1 (&scratch_gstring, glyphs);
+  M17N_OBJECT_UNREF (linebreak_table);
+  linebreak_table = NULL;
+}
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+/* External API */
+/*** @addtogroup m17nDraw */
+/*** @{ */
+
+/*=*/
+/***en
+    @brief Draw an M-text on a window.
+
+    The mdraw_text () function draws the text between $FROM and $TO of
+    M-text $MT on window $WIN of frame $FRAME at coordinate ($X, $Y).
+
+    The appearance of the text (size, style, color, etc) is specified
+    by the value of the text property whose key is @c Mface.  If the
+    M-text or a part of the M-text does not have such a text property,
+    the default face of $FRAME is used.
+
+    The font used to draw a character in the M-text is selected from
+    the value of the fontset property of a face by the following
+    algorithm:
+
+    <ol>
+
+    <li> Search the text properties given to the character for the one
+        whose key is @c Mcharset; its value should be either a symbol
+        specifying a charset or #Mnil.  If the value is #Mnil,
+        proceed to the next step.
+
+        Otherwise, search the mapping table of the fontset for the
+        charset.  If no entry is found proceed to the next step.  
+
+         If an entry is found, use one of the fonts in the entry that
+        has a glyph for the character and that matches best with the
+        face properties.  If no such font exists, proceed to the next
+        step.
+
+    <li> Get the character property "script" of the character.  If it is
+        inherited, get the script property from the previous
+        characters.  If there is no previous character, or none of
+        them has the script property other than inherited, proceed to
+        the next step.
+
+        Search the text properties given to the character for the one
+         whose key is @c Mlanguage; its value should be either a
+         symbol specifying a language or @c Mnil.
+
+        Search the mapping table of the fontset for the combination
+        of the script and language.  If no entry is found, proceed to
+        the next step.  
+
+         If an entry is found, use one of the fonts in the entry that
+        has a glyph for the character and that matches best with the
+        face properties.  If no such font exists, proceed to the next
+        step.
+
+    <li> Search the fall-back table of the fontset for a font that has
+        a glyph of the character.  If such a font is found, use that
+        font.
+
+    </ol>
+
+    If no font is found by the algorithm above, this function draws an
+    empty box for the character.
+
+    This function draws only the glyph foreground.  To specify the
+    background color, use mdraw_image_text () or
+    mdraw_text_with_control ().
+
+    This function is the counterpart of <tt>XDrawString ()</tt>,
+    <tt>XmbDrawString ()</tt>, and <tt>XwcDrawString ()</tt> functions
+    in the X Window System.
+
+    @return
+    If the operation was successful, mdraw_text () returns 0.  If an
+    error is detected, it returns -1 and assigns an error code to the
+    external variable #merror_code.  */
+/***ja
+    @brief ¥¦¥£¥ó¥É¥¦¤Ë M-text ¤òÉÁ²è¤¹¤ë.
+
+    ´Ø¿ô mdraw_text () ¤Ï¡¢¥Õ¥ì¡¼¥à $FRAME ¤Î¥¦¥£¥ó¥É¥¦ $WIN ¤ÎºÂɸ 
+    ($X, $Y) ¤Ë¡¢M-text $MT ¤Î $FROM ¤«¤é $TO ¤Þ¤Ç¤Î¥Æ¥­¥¹¥È¤òÉÁ²è¤¹¤ë¡£
+
+    ¥Æ¥­¥¹¥È¤Î¸«±É¤¨¡Ê¥Õ¥©¥ó¥È¡¢¥¹¥¿¥¤¥ë¡¢¿§¤Ê¤É¡Ë¤Ï¡¢¥­¡¼¤¬ @c Mface 
+    ¤Ç¤¢¤ë¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ÎÃͤˤè¤Ã¤Æ·è¤Þ¤ë¡£M-text 
+    ¤Î°ìÉô¤¢¤ë¤¤¤ÏÁ´Éô¤Ë¤½¤Î¤è¤¦¤Ê¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤¬ÉÕ¤¤¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢$FRAME 
+    ¤Î¥Ç¥Õ¥©¥ë¥È¥Õ¥§¡¼¥¹¤òÂå¤ï¤ê¤ËÍѤ¤¤ë¡£
+
+    M-text ¤Î³Æʸ»ú¤òɽ¼¨¤¹¤ë¥Õ¥©¥ó¥È¤Ï¡¢¥Õ¥§¡¼¥¹¤Î fontset 
+    ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤΤ¦¤Á¤«¤é¡¢°Ê²¼¤Î¥¢¥ë¥´¥ê¥º¥à¤ÇÁª¤Ð¤ì¤ë¡£
+
+    <ol>
+
+    <li> ¤½¤Îʸ»ú¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¡¢¥­¡¼¤¬ @c Mcharset
+         ¤Ç¤¢¤ë¤â¤Î¤ÎÃͤòÄ´¤Ù¤ë¡£¤³¤ÎÃͤÏʸ»ú¥»¥Ã¥È¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤« #Mnil 
+         ¤Î¤É¤Á¤é¤«¤Ç¤¢¤ë¡£#Mnil ¤Ê¤é¤Ð¡¢¼¡¤Î¥¹¥Æ¥Ã¥×¤Ë¿Ê¤à¡£
+        ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢fontset 
+        ¤Î¥Þ¥Ã¥Ô¥ó¥°¥Æ¡¼¥Ö¥ë¤Ë¤½¤Îʸ»ú¥»¥Ã¥ÈÍѤΥե©¥ó¥È¤¬¤¢¤ë¤«¤É¤¦¤«¤òÄ´¤Ù¤ë¡£
+        Ìµ¤±¤ì¤Ð¡¢¼¡¤Î¥¹¥Æ¥Ã¥×¤Ë¿Ê¤à¡£
+         
+         ¤½¤Îʸ»ú¥»¥Ã¥ÈÍѤΥե©¥ó¥È¤¬¤ß¤Ä¤«¤ì¤Ð¡¢¤½¤ì¤é¤Î¤¦¤Á¸½ºß¤Îʸ»úÍѤΥ°¥ê¥Õ¤ò»ý¤Á¡¢¥Õ¥§¡¼¥¹¤Î³Æ¥×¥í¥Ñ¥Æ¥£¤ËºÇ¤â¤è¤¯¹çÃפ¹¤ë¤â¤Î¤ò»È¤¦¡£
+        ¤½¤Î¤è¤¦¤Ê¥Õ¥©¥ó¥È¤¬Ìµ¤±¤ì¤Ð¼¡¤Î¥¹¥Æ¥Ã¥×¤Ë¿Ê¤à¡£
+
+    <li> ¤½¤Îʸ»ú¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£ "script" ¡Ê¥¹¥¯¥ê¥×¥È¡Ë¤òÄ´¤Ù¤ë¡£
+         ¤½¤Î¥×¥í¥Ñ¥Æ¥£¤¬·Ñ¾µ¤µ¤ì¤Æ¤¤¤ë¤Ê¤é¤Ð¤½¤ì°ÊÁ°¤Îʸ»ú¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£ "script" 
+        ¤òÄ´¤Ù¤ë¡£Á°¤Îʸ»ú¤¬¤Ê¤«¤Ã¤¿¤ê¡¢¤½¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ã¤Æ¤¤¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢¼¡¤Î¥¹¥Æ¥Ã¥×¤Ë¿Ê¤à¡£
+
+         ¤½¤Îʸ»ú¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¡¢¥­¡¼¤¬ @c Mlanguage ¤Ç¤¢¤ë¤â¤Î¤ÎÃͤòÄ´¤Ù¤ë¡£
+        ¤³¤ÎÃͤϸÀ¸ì¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤« @c Mnil ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£
+
+        ¤½¤Î¸À¸ì¤È¥¹¥¯¥ê¥×¥È¤ÎÁȤ߹ç¤ï¤»¤¬ fontset
+        ¤Î¥Þ¥Ã¥Ô¥ó¥°¥Æ¡¼¥Ö¥ë¤Ë¤¢¤ë¤«¤É¤¦¤«¤òÄ´¤Ù¤ë¡£¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð¼¡¤Î¥¹¥Æ¥Ã¥×¤Ë¿Ê¤à¡£
+
+        ¸«¤Ä¤«¤Ã¤¿¤Ð¤¢¤¤¤Ë¤Ï¡¢¤½¤ì¤é¤Î¥Õ¥©¥ó¥È¤Î¤¦¤Á¸½ºß¤Îʸ»úÍѤΥ°¥ê¥Õ¤ò»ý¤Á¡¢¥Õ¥§¡¼¥¹¤Î³Æ¥×¥í¥Ñ¥Æ¥£¤ËºÇ¤â¤è¤¯¹çÃפ·¤Æ¤¤¤ë¤â¤Î¤ò»È¤¦¡£
+        ¤½¤Î¤è¤¦¤Ê¥Õ¥©¥ó¥È¤¬Ìµ¤±¤ì¤Ð¼¡¤Î¥¹¥Æ¥Ã¥×¤Ë¿Ê¤à¡£
+
+    <li> ¤½¤Îʸ»ú¤Î¥°¥ê¥Õ¤ò»ý¤Ä¥Õ¥©¥ó¥È¤ò¡¢¥Õ¥©¥ó¥È¥»¥Ã¥È¤Î fall-back 
+         ¥Æ¡¼¥Ö¥ë¤«¤éõ¤¹¡£¥Õ¥©¥ó¥È¤¬¸«¤Ä¤«¤ì¤Ð¤½¤ì¤ò»È¤¦¡£
+
+    </ol>
+
+    °Ê¾å¤Î¥¢¥ë¥´¥ê¥º¥à¤Ç¥Õ¥©¥ó¥È¤¬¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ï¤½¤Îʸ»ú¤È¤·¤Æ¶õ¤Î»Í³Ñ·Á¤òɽ¼¨¤¹¤ë¡£
+
+    ¤³¤Î´Ø¿ô¤¬ÉÁ²è¤¹¤ë¤Î¤Ï¥°¥ê¥Õ¤ÎÁ°·Ê¤À¤±¤Ç¤¢¤ë¡£ÇØ·Ê¿§¤ò»ØÄꤹ¤ë¤Ë¤Ï¡¢´Ø¿ô
+    mdraw_image_text () ¤«´Ø¿ô mdraw_text_with_control () ¤ò»È¤¦¤³¤È¡£
+
+    ¤³¤Î´Ø¿ô¤Ï¡¢X ¥¦¥£¥ó¥É¥¦¤Ë¤ª¤±¤ë´Ø¿ô <tt>XDrawString ()</tt>,
+    <tt>XmbDrawString ()</tt>, <tt>XwcDrawString ()</tt> ¤ËÁêÅö¤¹¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤·¤¿¾ì¹ç¡¢mdraw_text () ¤Ï 0 ÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï
+    -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mdraw_text} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE
+
+    @seealso
+    mdraw_image_text ()  */
+
+int
+mdraw_text (MFrame *frame, MDrawWindow win, int x, int y,
+           MText *mt, int from, int to)
+{
+  MDrawControl control;
+
+  M_CHECK_WRITABLE (frame, MERROR_DRAW, -1);
+  memset (&control, 0, sizeof control);
+  control.as_image = 0;
+  return draw_text (frame, win, x, y, mt, from, to, &control);
+}
+
+/*=*/
+
+
+/***en
+    @brief Draw an M-text on a window as an image.
+
+    The mdraw_image_text () function draws the text between $FROM and
+    $TO of M-text $MT as image on window $WIN of frame $FRAME at
+    coordinate ($X, $Y).
+
+    The way to draw a text is the same as in mdraw_text () except that
+    this function also draws the background with the color specified
+    by faces.
+
+    This function is the counterpart of <tt>XDrawImageString ()</tt>,
+    <tt>XmbDrawImageString ()</tt>, and <tt>XwcDrawImageString ()</tt>
+    functions in the X Window System.
+
+    @return
+    If the operation was successful, mdraw_image_text () returns 0.
+    If an error is detected, it returns -1 and assigns an error code
+    to the external variable #merror_code.  */
+
+/***ja
+    @brief ¥Ç¥£¥¹¥×¥ì¥¤¤ËM-text ¤ò²èÁü¤È¤·¤ÆÉÁ¤¯.
+  
+    ´Ø¿ô mdraw_image_text () ¤Ï¡¢¥Õ¥ì¡¼¥à $FRAME ¤Î¥¦¥£¥ó¥É¥¦ $WIN 
+    ¤ÎºÂɸ ($X, $Y) ¤Ë¡¢M-text $MT ¤Î $FROM ¤«¤é $TO 
+    ¤Þ¤Ç¤Î¥Æ¥­¥¹¥È¤ò²èÁü¤È¤·¤ÆÉÁ¤¯¡£
+
+    ¥Æ¥­¥¹¥È¤ÎÉÁ²èÊýË¡¤Ï mdraw_text ()
+    ¤È¤Û¤ÜƱ¤¸¤Ç¤¢¤ë¤¬¡¢¤³¤Î´Ø¿ô¤Ç¤Ï¥Õ¥§¡¼¥¹¤Ç»ØÄꤵ¤ì¤¿¿§¤ÇÇطʤâÉÁ¤¯ÅÀ¤¬°Û¤Ê¤Ã¤Æ¤¤¤ë¡£
+
+    ¤³¤Î´Ø¿ô¤Ï¡¢X ¥¦¥£¥ó¥É¥¦¤Ë¤ª¤±¤ë <tt>XDrawImageString ()</tt>,
+    <tt>XmbDrawImageString ()</tt>, <tt>XwcDrawImageString ()</tt> 
+    ¤ËÁêÅö¤¹¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤·¤¿¾ì¹ç¡¢mdraw_image_text () ¤Ï 0 
+    ¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mdraw_image_text} @endlatexonly   */
+
+/***
+    @errors
+    @c MERROR_RANGE
+
+    @seealso
+    mdraw_text ()  */
+
+int
+mdraw_image_text (MFrame *frame, MDrawWindow win, int x, int y,
+                 MText *mt, int from, int to)
+{
+  MDrawControl control;
+
+  M_CHECK_WRITABLE (frame, MERROR_DRAW, -1);
+  memset (&control, 0, sizeof control);
+  control.as_image = 1;
+  return draw_text (frame, win, x, y, mt, from, to, &control);
+}
+
+/*=*/
+
+/***en
+    @brief Draw an M-text on a window with fine control.
+
+    The mdraw_text_with_control () function draws the text between
+    $FROM and $TO of M-text $MT on windows $WIN of frame $FRAME at
+    coordinate ($X, $Y).
+
+    The way to draw a text is the same as in mdraw_text () except that
+    this function also follows what specified in the drawing control
+    object $CONTROL.
+
+    For instance, if \<two_dimensional\> of $CONTROL is nonzero, this
+    function draw an M-text 2-dimensionally, i.e., newlines in M-text
+    breaks lines and the following characters are drawn in the next
+    line.  See the documentation of the structure @ MDrawControl for
+    more detail.  */
+
+/***ja
+    @brief ¥Ç¥£¥¹¥×¥ì¥¤¤ËM-text ¤ò¾ÜºÙ¤ÊÀ©¸æ¤Ä¤­¤ÇÉÁ¤¯.
+
+    ´Ø¿ô mdraw_text_with_control () ¤Ï¡¢¥Õ¥ì¡¼¥à $FRAME ¤Î¥¦¥£¥ó¥É¥¦ 
+    $WIN ¤ÎºÂɸ ($X, $Y) ¤Ë¡¢M-text $MT ¤Î $FROM ¤«¤é $TO ¤Þ¤Ç¤Î¥Æ¥­¥¹
+    ¥È¤òÉÁ¤¯¡£
+
+    ¥Æ¥­¥¹¥È¤ÎÉÁ²èÊýË¡¤Ï mdraw_text () ¤È¤Û¤ÜƱ¤¸¤Ç¤¢¤ë¤¬¡¢¤³¤Î´Ø¿ô¤ÏÉÁ²èÀ©¸æÍѤΥª¥Ö¥¸¥§¥¯¥È
+    $CONTROL ¤Î»Ø¼¨¤Ë¤â½¾¤¦ÅÀ¤¬°Û¤Ê¤Ã¤Æ¤¤¤ë¡£
+
+    ¤¿¤È¤¨¤Ð $CONTROL ¤Î \<two_dimensional\> ¤¬¥¼¥í¤Ç¤Ê¤±¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ï 
+    M-text ¤ò2¼¡¸µÅª¤ËÉÁ¤¯¡£¤¹¤Ê¤ï¤Á M-text Ãæ¤Î²þ¹Ô¤Ç¹Ô¤ò²þ¤á¡¢Â³¤¯Ê¸»ú¤Ï¼¡¤Î¹Ô¤ËÉÁ¤¯¡£¾ÜºÙ¤Ï¹½Â¤ÂÎ
+    @ MDrawControl ¤ÎÀâÌÀ¤ò»²¾È¤¹¤ë¤³¤È¡£*/
+
+int
+mdraw_text_with_control (MFrame *frame, MDrawWindow win, int x, int y,
+                        MText *mt, int from, int to, MDrawControl *control)
+{
+  M_CHECK_WRITABLE (frame, MERROR_DRAW, -1);
+  return draw_text (frame, win, x, y, mt, from, to, control);
+}
+
+/*=*/
+
+/***en
+    @brief Compute text pixel width.
+
+    The mdraw_text_extents () function computes the width of text
+    between $FROM and $TO of M-text $MT when it is drawn on a window
+    of frame $FRAME using the mdraw_text_with_control () function with
+    the drawing control object $CONTROL.
+
+    If $OVERALL_INK_RETURN is not @c NULL, this function also computes
+    the bounding box of character ink of the M-text, and stores the
+    results in the members of the structure pointed to by
+    $OVERALL_INK_RETURN.  If the M-text has a face specifying a
+    surrounding box, the box is included in the bounding box.
+
+    If $OVERALL_LOGICAL_RETURN is not @c NULL, this function also
+    computes the bounding box that provides minimum spacing to other
+    graphical features (such as surrounding box) for the M-text, and
+    stores the results in the members of the structure pointed to by
+    $OVERALL_LOGICAL_RETURN.
+
+    If $OVERALL_LINE_RETURN is not @c NULL, this function also
+    computes the bounding box that provides minimum spacing to the
+    other M-text drawn, and stores the results in the members of the
+    structure pointed to by $OVERALL_LINE_RETURN.  This is a union of
+    $OVERALL_INK_RETURN and $OVERALL_LOGICAL_RETURN if the members
+    min_line_ascent, min_line_descent, max_line_ascent, and
+    max_line_descent of $CONTROL are all zero.
+
+    @return
+    This function returns the width of the text to be drawn in the
+    unit of pixels.  If $CONTROL->two_dimensional is nonzero and the
+    text is drawn in multiple physical lines, it returns the width of
+    the widest line.  If an error occurs, it returns -1 and assigns an
+    error code to the external variable #merror_code.  */
+
+
+/***ja 
+    @brief ¥Æ¥­¥¹¥È¤ÎÉý¡Ê¥Ô¥¯¥»¥ëñ°Ì¡Ë¤ò·×»»¤¹¤ë.
+
+    ´Ø¿ô mdraw_text_extents () ¤Ï¡¢´Ø¿ô mdraw_text_with_control () 
+    ¤¬ÉÁ²èÀ©¸æ¥ª¥Ö¥¸¥§¥¯¥È $CONTROL ¤òÍѤ¤¤Æ M-text $MT ¤Î $FROM ¤«¤é $TO 
+    ¤Þ¤Ç¤ò¥Õ¥ì¡¼¥à $FRAME ¤Ëɽ¼¨¤¹¤ëºÝ¤ËɬÍפȤʤëÉý¤òÊÖ¤¹¡£
+
+    $OVERALL_INK_RETURN ¤¬ @c NULL ¤Ç¤Ê¤±¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ï M-text 
+    ¤Îʸ»ú¤Î¥¤¥ó¥¯¤Î¥Ð¥¦¥ó¥Ç¥£¥ó¥°¥Ü¥Ã¥¯¥¹¤â·×»»¤·¡¢$OVERALL_INK_RETURN 
+    ¤¬»Ø¤¹¹½Â¤ÂΤΥá¥ó¥Ð¤Ë¤½¤Î·ë²Ì¤òÀßÄꤹ¤ë¡£M-text ¤Ë°Ï¤ßÏÈ (surrounding box)
+    ¤ò»ØÄꤹ¤ë¥Õ¥§¡¼¥¹¤¬¤¢¤ì¤Ð¡¢¤½¤ì¤â¥Ð¥¦¥ó¥Ç¥£¥ó¥°¥Ü¥Ã¥¯¥¹¤Ë´Þ¤à¡£
+
+    $OVERALL_LOGICAL_RETURN ¤¬ @c NULL ¤Ç¤Ê¤±¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ï M-text 
+    ¤È¾¤Î graphical feature ¡Ê°Ï¤ßÏȤʤɡË
+    ¤È¤Î´Ö¤ÎºÇ¾®¤Î¥¹¥Ú¡¼¥¹¤ò¼¨¤¹¥Ð¥¦¥ó¥Ç¥£¥ó¥°¥Ü¥Ã¥¯¥¹¤â·×»»¤·¡¢$OVERALL_LOGICAL_RETURN
+    ¤¬»Ø¤¹¹½Â¤ÂΤΥá¥ó¥Ð¤Ë¤½¤Î·ë²Ì¤òÀßÄꤹ¤ë¡£
+
+    $OVERALL_LINE_RETURN ¤¬ @c NULL ¤Ç¤Ê¤±¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ï¾¤Î M-text 
+    ¤È¤Î´Ö¤ÎºÇ¾®¤Î¥¹¥Ú¡¼¥¹¤ò¼¨¤¹¥Ð¥¦¥ó¥Ç¥£¥ó¥°¥Ü¥Ã¥¯¥¹¤â·×»»¤·¡¢
+    $OVERALL_LINE_RETURN ¤¬»Ø¤¹¹½Â¤ÂΤΥá¥ó¥Ð¤Ë¤½¤Î·ë²Ì¤òÀßÄꤹ¤ë¡£¥ª¥Ö¥¸¥§¥¯¥È
+    $CONTROL ¤Î¥á¥ó¥Ð min_line_ascent, min_line_descent,
+    max_line_ascent, max_line_descent ¤¬¤¹¤Ù¤Æ0¤Î»þ¤Ë¤Ï¡¢¤³¤ÎÃͤϠ
+    $OVERALL_INK_RETURN ¤È$OVERALL_LOGICAL_RETURN ¤ÎϤȤʤ롣
+
+    @return 
+    ¤³¤Î´Ø¿ô¤Ïɽ¼¨¤ËɬÍפʥƥ­¥¹¥È¤ÎÉý¤ò¥Ô¥¯¥»¥ëñ°Ì¤ÇÊÖ¤¹¡£$CONTROL->two_dimensional
+    ¤¬0¤Ç¤Ê¤¯¡¢¥Æ¥­¥¹¥È¤¬Ê£¿ô¤Î¹Ô¤ËÅϤäÆÉÁ¤«¤ì¤ë¾ì¹ç¤Ë¤Ï¡¢ºÇÂç¤ÎÉý¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬À¸¤¸¤¿¾ì¹ç¤Ï
+    -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mdraw_text_extents} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE  */
+
+int
+mdraw_text_extents (MFrame *frame,
+                   MText *mt, int from, int to, MDrawControl *control,
+                   MDrawMetric *overall_ink_return,
+                   MDrawMetric *overall_logical_return,
+                   MDrawMetric *overall_line_return)
+{
+  MGlyphString *gstring;
+  int y = 0;
+  int width, lbearing, rbearing;
+
+  ASSURE_CONTROL (control);
+  M_CHECK_POS_X (mt, from, -1);
+  if (to > mtext_nchars (mt) + (control->cursor_width != 0))
+    to = mtext_nchars (mt) + (control->cursor_width != 0);
+  else if (to < from)
+    to = from;
+
+  gstring = get_gstring (frame, mt, from, to, control);
+  if (! gstring)
+    MERROR (MERROR_DRAW, -1);
+  width = gstring_width (gstring, from, to, &lbearing, &rbearing);
+  if (overall_ink_return)
+    overall_ink_return->y = - gstring->physical_ascent;
+  if (overall_logical_return)
+    overall_logical_return->y = - gstring->ascent;
+  if (overall_line_return)
+    overall_line_return->y = - gstring->line_ascent;
+
+  for (from = gstring->to; from < to; from = gstring->to)
+    {
+      int this_width, this_lbearing, this_rbearing;
+
+      y += gstring->line_descent;
+      M17N_OBJECT_UNREF (gstring->top);
+      gstring = get_gstring (frame, mt, from, to, control);
+      this_width = gstring_width (gstring, from, to,
+                                 &this_lbearing, &this_rbearing);
+      y += gstring->line_ascent;
+      if (width < this_width)
+       width = this_width;
+      if (rbearing < this_rbearing)
+       rbearing = this_rbearing;
+      if (lbearing > this_lbearing)
+       lbearing = this_lbearing;
+    }
+  if (overall_ink_return)
+    {
+      overall_ink_return->x = lbearing;
+      overall_ink_return->width = rbearing - lbearing;
+      overall_ink_return->height
+       = y + gstring->physical_descent - overall_ink_return->y;
+    }
+  if (overall_logical_return)
+    {
+      overall_logical_return->x = 0;
+      overall_logical_return->width = width;
+      overall_logical_return->height
+       = y + gstring->descent - overall_logical_return->y;
+    }
+  if (overall_line_return)
+    {
+      overall_line_return->x = lbearing;
+      overall_line_return->width = MAX (width, rbearing - lbearing);
+      overall_line_return->height
+       = y + gstring->line_descent - overall_line_return->y;
+    }
+
+  M17N_OBJECT_UNREF (gstring->top);
+  return width;
+}
+
+/*=*/
+
+/***en
+    @brief Compute the text dimensions of each character of M-text.
+
+    The mdraw_text_per_char_extents () function computes the drawn
+    metric of each character between $FROM and $TO of M-text $MT
+    assuming that they are drawn on a window of frame $FRAME using the
+    mdraw_text_with_control () function with the drawing control
+    object $CONTROL.
+
+    $ARRAY_SIZE specifies the size of $INK_ARRAY_RETURN and
+    $LOGICAL_ARRAY_RETURN.  Each successive element of
+    $INK_ARRAY_RETURN and $LOGICAL_ARRAY_RETURN are set to the drawn
+    ink and logical metrics of successive characters respectively,
+    relative to the drawing origin of the M-text.  The number of
+    elements of $INK_ARRAY_RETURN and $LOGICAL_ARRAY_RETURN that have
+    been set is returned to $NUM_CHARS_RETURN.
+
+    If $ARRAY_SIZE is too small to return all metrics, the function
+    returns -1 and store the requested size in $NUM_CHARS_RETURN.
+    Otherwise, it returns zero.
+
+    If pointer $OVERALL_INK_RETURN and $OVERALL_LOGICAL_RETURN are not
+    @c NULL, this function also computes the metrics of the overall
+    text and stores the results in the members of the structure
+    pointed to by $OVERALL_INK_RETURN and $OVERALL_LOGICAL_RETURN.
+
+    If $CONTROL->two_dimensional is nonzero, this function computes
+    only the metrics of characters in the first line.  */
+/***ja
+    @brief  M-text ¤Î³Æʸ»ú¤Îɽ¼¨ÈϰϤò·×»»¤¹¤ë.
+
+    ´Ø¿ô mdraw_text_per_char_extents () ¤Ï¡¢´Ø¿ô mdraw_text_with_control ()
+    ¤¬ÉÁ²èÀ©¸æ¥ª¥Ö¥¸¥§¥¯¥È $CONTROL ¤òÍѤ¤¤Æ M-text $MT ¤Î $FROM ¤«¤é $TO 
+    ¤Þ¤Ç¤ò¥Õ¥ì¡¼¥à $FRAME ¤Ëɽ¼¨¤¹¤ëºÝ¤Î³Æʸ»ú¤Î¥µ¥¤¥º¤ò·×»»¤¹¤ë¡£
+
+    $ARRAY_SIZE ¤Ë¤è¤Ã¤Æ $INK_ARRAY_RETURN ¤È$LOGICAL_ARRAY_RETURN 
+    ¤Î¥µ¥¤¥º¤ò»ØÄꤹ¤ë¡£$INK_ARRAY_RETURN ¤È$LOGICAL_ARRAY_RETURN 
+    ¤Î³ÆÍ×ÁǤϡ¢¤½¤ì¤¾¤ìʸ»ú¤ÎÉÁ²è¥¤¥ó¥¯¤ÈÏÀÍý¥µ¥¤¥º¡ÊM-text 
+    ¤Îɽ¼¨¸¶ÅÀ¤«¤é¤ÎÁêÂаÌÃ͡ˤˤè¤Ã¤Æ½ç¤ËËä¤á¤é¤ì¤ë¡£ÀßÄꤵ¤ì¤¿ $INK_ARRAY_RETURN ¤È 
+    $LOGICAL_ARRAY_RETURN ¤ÎÍ×ÁǤοô¤Ï¡¢$NUM_CHARS_RETURN ¤ËÌᤵ¤ì¤ë¡£
+   
+    $ARRAY_SIZE ¤¬¤¹¤Ù¤Æ¤ÎÀ£Ë¡¤òÌ᤻¤Ê¤¤¤Û¤É¾®¤µ¤¤¾ì¹ç¤Ë¤Ï¡¢´Ø¿ô¤Ï -1 
+    ¤òÊÖ¤·¡¢É¬ÍפÊÂ礭¤µ¤ò $NUM_CHARS_RETURN ¤ËÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð 0 
+    ¤òÊÖ¤¹¡£
+
+    ¥Ý¥¤¥ó¥¿ $OVERALL_INK_RETURN ¤È $OVERALL_LOGICAL_RETURN ¤¬@c NULL 
+    ¤Ç¤Ê¤±¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ï¥Æ¥­¥¹¥ÈÁ´ÂΤΥµ¥¤¥º¤â·×»»¤·¡¢·ë²Ì¤ò
+    $OVERALL_INK_RETURN ¤È $OVERALL_LOGICAL_RETURN ¤Ç»Ø¤µ¤ì¤ë¹½Â¤¤Î¥á¥ó¥Ð¤ËÊݸ¤¹¤ë¡£
+
+    $CONTROL->two_dimensional ¤¬0¤Ç¤Ê¤±¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤ÏºÇ½é¤Î¹Ô¤Îʸ»ú¤Î¥µ¥¤¥º¤À¤±¤ò·×»»¤¹¤ë¡£ */
+
+int
+mdraw_text_per_char_extents (MFrame *frame,
+                            MText *mt, int from, int to,
+                            MDrawControl *control,
+                            MDrawMetric *ink_array_return,
+                            MDrawMetric *logical_array_return,
+                            int array_size,
+                            int *num_chars_return,
+                            MDrawMetric *overall_ink_return,
+                            MDrawMetric *overall_logical_return)
+{
+  MGlyphString *gstring;
+  MGlyph *g;
+  int x;
+
+  ASSURE_CONTROL (control);
+  *num_chars_return = to - from;
+  if (array_size < *num_chars_return)
+    MERROR (MERROR_DRAW, -1);
+  if (overall_logical_return)
+    memset (overall_logical_return, 0, sizeof (MDrawMetric));
+  if (overall_ink_return)
+    memset (overall_ink_return, 0, sizeof (MDrawMetric));
+
+  M_CHECK_RANGE (mt, from, to, -1, 0);
+  gstring = get_gstring (frame, mt, from, to, control);
+  if (! gstring)
+    {
+      *num_chars_return = 0;
+      return 0;
+    }
+
+  for (g = MGLYPH (1), x = 0; g->type != GLYPH_ANCHOR; g++)
+    if (g->g.from >= from && g->g.from < to)
+      {
+       int start = g->g.from;
+       int end = g->g.to;
+       int width = g->g.xadv;
+       int lbearing = g->g.lbearing;
+       int rbearing = g->g.rbearing;
+       int ascent = g->g.ascent;
+       int descent = g->g.descent;
+       int logical_ascent;
+       int logical_descent;
+
+       if (g->rface->rfont)
+         {
+           logical_ascent = g->rface->rfont->ascent;
+           logical_descent = g->rface->rfont->descent;
+         }
+       else
+         {
+           logical_ascent = g->rface->ascent;
+           logical_descent = g->rface->descent;
+         }
+       for (g++; g->type != GLYPH_ANCHOR && g->g.from == start; g++)
+         {
+           if (lbearing < width + g->g.lbearing)
+             lbearing = width + g->g.lbearing;
+           if (rbearing < width + g->g.rbearing)
+             rbearing = width + g->g.rbearing;
+           width += g->g.xadv;
+           if (ascent < g->g.ascent)
+             ascent = g->g.ascent;
+           if (descent < g->g.descent)
+             descent = g->g.descent;
+         }
+
+       if (end > to)
+         end = to;
+       while (start < end)
+         {
+           if (ink_array_return)
+             {
+               ink_array_return[start - from].x = x + lbearing;
+               ink_array_return[start - from].y = - ascent;
+               ink_array_return[start - from].width = rbearing - lbearing;
+               ink_array_return[start - from].height = ascent + descent;
+             }
+           if (logical_array_return)
+             {
+               logical_array_return[start - from].x = x;
+               logical_array_return[start - from].y = - logical_descent;
+               logical_array_return[start - from].height
+                 = logical_ascent + logical_descent;
+               logical_array_return[start - from].width = width;
+             }
+           start++;
+         }
+       x += width;
+       g--;
+      }
+
+  if (overall_ink_return)
+    {
+      overall_ink_return->y = - gstring->line_ascent;
+      overall_ink_return->x = gstring->lbearing;
+      overall_ink_return->width = x - gstring->lbearing;
+      overall_ink_return->height = gstring->height;
+    }
+  if (overall_logical_return)
+    {
+      overall_logical_return->y = - gstring->ascent;
+      overall_logical_return->x = 0;
+      overall_logical_return->width = x;
+      overall_logical_return->height = gstring->ascent + gstring->descent;
+    }
+
+  M17N_OBJECT_UNREF (gstring->top);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Return the character position nearest to the coordinates.
+
+    The mdraw_coordinates_position () function checks which character
+    is to be drawn at coordinate ($X, $Y) when the text between $FROM
+    and $TO of M-text $MT is drawn at the coordinate (0, 0) using the
+    mdraw_text_with_control () function with the drawing control
+    object $CONTROL.  Here, the character position means the number of
+    characters that precede the character in question in $MT, that is,
+    the character position of the first character is 0.
+
+    $FRAME is used only to get the default face information.
+
+    @return
+    If the glyph image of a character covers coordinate ($X, $Y),
+    mdraw_coordinates_position () returns the character position of
+    that character.\n\n
+    If $Y is less than the minimum Y-coordinate of the drawn area, it
+    returns $FROM.\n\n
+    If $Y is greater than the maximum Y-coordinate of the drawn area,
+    it returns $TO.\n\n
+    If $Y fits in with the drawn area but $X is less than the minimum
+    X-coordinate, it returns the character position of the first
+    character drawn on the line $Y.\n\n
+    If $Y fits in with the drawn area but $X is greater than the
+    maximum X-coordinate, it returns the character position of the
+    last character drawn on the line $Y.  */
+
+/***ja
+    @brief »ØÄꤷ¤¿ºÂɸ¤ËºÇ¤â¶á¤¤Ê¸»ú¤Îʸ»ú°ÌÃÖ¤òÆÀ¤ë.
+
+    ´Ø¿ô mdraw_coordinates_position () ¤Ï¡¢´Ø¿ô 
+    mdraw_text_with_control () ¤¬ÉÁ²èÀ©¸æ¥ª¥Ö¥¸¥§¥¯¥È $CONTROL ¤òÍѤ¤¤Æ¡¢
+    M-text $MT ¤Î $FROM ¤«¤é $TO ¤Þ¤Ç¤òºÂɸ (0, 0) 
+    ¤òµ¯ÅÀ¤È¤·¤ÆÉÁ²è¤¹¤ëºÝ¤Ë¡¢ºÂɸ ($X, $Y) 
+    ¤ËÉÁ²è¤µ¤ì¤ëʸ»ú¤Îʸ»ú°ÌÃÖ¤òÊÖ¤¹¡£¤³¤³¤Çʸ»ú°ÌÃ֤Ȥϡ¢Åö³º
+    M-text Ãæ¤Ë¤ª¤¤¤Æ¤½¤Îʸ»ú¤¬ºÇ½é¤«¤é²¿ÈÖÌܤ«¤ò¼¨¤¹À°¿ô¤Ç¤¢¤ë¡£¤¿¤À¤·ºÇ½é¤Îʸ»ú¤Îʸ»ú°ÌÃÖ¤Ï0¤È¤¹¤ë¡£
+
+    $FRAME ¤Ï¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹¤Î¾ðÊó¤òÆÀ¤ë¤¿¤á¤À¤±¤ËÍѤ¤¤é¤ì¤ë¡£
+
+    @return
+    ºÂɸ ($X, $Y) ¤¬¤¢¤ëʸ»ú¤Î¥°¥ê¥Õ¤Çʤ¤ï¤ì¤ë¾ì¹ç¡¢ ´Ø¿ô 
+    mdraw_coordinates_position () ¤Ï¤½¤Îʸ»ú¤Îʸ»ú°ÌÃÖ¤òÊÖ¤¹¡£\n\n
+    ¤â¤· $Y ¤¬ÉÁ²èÎΰè¤ÎºÇ¾®YºÂɸ¤è¤ê¤â¾®¤µ¤¤¤Ê¤é¤Ð $FROM ¤òÊÖ¤¹¡£\n\n
+    ¤â¤· $Y ¤¬ÉÁ²èÎΰè¤ÎºÇÂçYºÂɸ¤è¤ê¤âÂ礭¤¤¤Ê¤é¤Ð $TO ¤òÊÖ¤¹¡£\n\n
+    ¤â¤· $Y ¤¬ÉÁ²èÎΰè¤Ë¾è¤Ã¤Æ¤¤¤Æ¤«¤Ä $X ¤¬ÉÁ²èÎΰè¤ÎºÇ¾®XºÂɸ¤è¤ê¤â
+    ¾®¤µ¤¤¾ì¹ç¤Ï¡¢Ä¾Àþ y = $Y ¾å¤ËÉÁ²è¤µ¤ì¤ëºÇ½é¤Îʸ»ú¤Îʸ»ú°ÌÃÖ¤òÊÖ¤¹¡£\n\n
+    ¤â¤· $Y ¤¬ÉÁ²èÎΰè¤Ë¾è¤Ã¤Æ¤¤¤Æ¤«¤Ä $X ¤¬ÉÁ²èÎΰè¤ÎºÇÂçXºÂɸ¤è¤ê¤â
+    Â礭¤¤¾ì¹ç¤Ï¡¢Ä¾Àþ y = $Y ¾å¤ËÉÁ²è¤µ¤ì¤ëºÇ¸å¤Îʸ»ú¤Îʸ»ú°ÌÃÖ¤òÊÖ¤¹¡£ */
+
+int
+mdraw_coordinates_position (MFrame *frame, MText *mt, int from, int to,
+                           int x_offset, int y_offset, MDrawControl *control)
+{
+  MGlyphString *gstring;
+  int y = 0;
+  int width;
+  MGlyph *g;
+
+  M_CHECK_POS_X (mt, from, -1);
+  if (to > mtext_nchars (mt) + (control->cursor_width != 0))
+    to = mtext_nchars (mt) + (control->cursor_width != 0);
+  else if (to < from)
+    to = from;
+
+  if (from == to)
+    return from;
+  ASSURE_CONTROL (control);
+  gstring = get_gstring (frame, mt, from, to, control);
+  while (y + gstring->line_descent <= y_offset
+        && gstring->to < to)
+    {
+      from = gstring->to;
+      y += gstring->line_descent;
+      M17N_OBJECT_UNREF (gstring->top);
+      gstring = get_gstring (frame, mt, from, to, control);
+      y += gstring->line_ascent;
+    }
+
+  /* Accumulate width of glyphs in WIDTH until it exceeds X. */
+  if (! control->orientation_reversed)
+    {
+      width = gstring->indent;
+      for (g = MGLYPH (1); g->type != GLYPH_ANCHOR; g++)
+       if (g->g.from >= from && g->g.from < to)
+         {
+           width += g->g.xadv;
+           if (width > x_offset)
+             break;
+         }
+    }
+  else
+    {
+      width = - gstring->indent;
+      for (g = MGLYPH (gstring->used - 2); g->type != GLYPH_ANCHOR; g--)
+       if (g->g.from >= from && g->g.from < to)
+         {
+           width -= g->g.xadv;
+           if (width < x_offset)
+             break;
+         }
+    }
+  if (g->type == GLYPH_ANCHOR
+      && control->two_dimensional
+      && g[-1].g.c == '\n')
+    g--;
+  from = g->g.from;
+  M17N_OBJECT_UNREF (gstring->top);
+
+  return from;
+}
+
+/*=*/
+
+/***en
+    @brief Compute information about a glyph.
+
+    The mdraw_glyph_info () function computes information about a
+    glyph that covers a character at position $POS of the M-text $MT
+    assuming that the text is drawn from the character at $FROM of $MT
+    on a window of frame $FRAME using the mdraw_text_with_control ()
+    function with the drawing control object $CONTROL.
+
+    The information is stored in the members of $INFO.  */
+/***ja
+    @brief ¥°¥ê¥Õ¤Ë´Ø¤¹¤ë¾ðÊó¤ò·×»»¤¹¤ë.
+
+    ´Ø¿ô mdraw_glyph_info () ¤Ï¡¢´Ø¿ô mdraw_text_with_control () 
+    ¤¬ÉÁ ²èÀ©¸æ¥ª¥Ö¥¸¥§¥¯¥È $CONTROL ¤òÍѤ¤¤ÆM-text $MT ¤Î $FROM ¤«¤é $TO 
+    ¤Þ¤Ç¤ò¥Õ¥ì¡¼¥à $FRAME ¤ËÉÁ²è¤·¤¿¾ì¹ç¡¢M-text ¤Îʸ»ú°ÌÃÖ $POS 
+    ¤Îʸ»ú¤òʤ¤¦¥°¥ê¥Õ¤Ë´Ø¤¹¤ë¾ðÊó¤ò·×»»¤¹¤ë¡£
+
+    ¾ðÊó¤Ï$INFO ¤Î¥á¥ó¥Ð¤ËÊÝ»ý¤µ¤ì¤ë¡£  */
+
+/***
+    @seealso
+    MDrawGlyphInfo
+*/
+
+int
+mdraw_glyph_info (MFrame *frame, MText *mt, int from, int pos,
+                 MDrawControl *control, MDrawGlyphInfo *info)
+{
+  MGlyphString *gstring;
+  MGlyph *g;
+  int y = 0;
+
+  M_CHECK_RANGE_X (mt, from, pos, -1);
+
+  ASSURE_CONTROL (control);
+  gstring = get_gstring (frame, mt, from, pos + 1, control);
+  if (! gstring)
+    MERROR (MERROR_DRAW, -1);
+  while (gstring->to <= pos)
+    {
+      y += gstring->line_descent;
+      M17N_OBJECT_UNREF (gstring->top);
+      gstring = get_gstring (frame, mt, gstring->to, pos + 1, control);
+      y += gstring->line_ascent;
+    }
+  info->line_from = gstring->from;
+  if (info->line_from < from)
+    info->line_from = from;
+  info->line_to = gstring->to;
+
+  info->y = y;
+  if (! control->orientation_reversed)
+    {
+      info->x = gstring->indent;
+      for (g = MGLYPH (1); g->g.from > pos || g->g.to <= pos; g++)
+       info->x += g->g.xadv;
+    }
+  else
+    {
+      info->x = - gstring->indent;
+      for (g = MGLYPH (gstring->used - 2); g->g.from > pos || g->g.to <= pos; g--)
+       info->x -= g->g.xadv;
+      while (g[-1].g.to == g->g.to)
+       g--;
+    }
+  info->from = g->g.from;
+  info->to = g->g.to;
+  info->metrics.x = g->g.lbearing;
+  info->metrics.y = - gstring->line_ascent;
+  info->metrics.height = gstring->height;
+  info->metrics.width = - g->g.lbearing + g->g.xadv;
+  if (g->rface->rfont)
+    info->font = (MFont *) g->rface->rfont;
+  else
+    info->font = NULL;
+  /* info->logical_width is calculated later.  */
+
+  if (info->from > info->line_from)
+    {
+      /* The logically previous glyph is on this line.  */
+      MGlyph *g_tmp = find_glyph_in_gstring (gstring, info->from - 1, 1);
+
+      info->prev_from = g_tmp->g.from;
+    }
+  else if (info->line_from > 0
+          && gstring->from > 0)
+    {
+      /* The logically previous glyph is on the previous line.  */
+      MGlyphString *gst = get_gstring (frame, mt, gstring->from - 1,
+                                      gstring->from, control);
+      MGlyph *g_tmp = find_glyph_in_gstring (gst, info->from - 1, 1);
+
+      info->prev_from = g_tmp->g.from;
+      M17N_OBJECT_UNREF (gst->top);
+    }
+  else
+    info->prev_from = -1;
+
+  if (GLYPH_INDEX (g) > 1)
+    info->left_from = g[-1].g.from, info->left_to = g[-1].g.to;
+  else if (! control->orientation_reversed)
+    {
+      if (info->line_from > 0)
+       {
+         MGlyph *g_tmp;
+         MGlyphString *gst;
+         int p = gstring->from - 1;
+
+         gst = get_gstring (frame, mt, p, gstring->from, control);
+         g_tmp = gst->glyphs + (gst->used - 2);
+         info->left_from = g_tmp->g.from, info->left_to = g_tmp->g.to;
+         M17N_OBJECT_UNREF (gst->top);
+       }
+      else
+       info->left_from = info->left_to = -1;
+    }
+  else
+    {
+      if (gstring->to + (control->cursor_width == 0) <= mtext_nchars (mt))
+       {
+         MGlyph *g_tmp;
+         MGlyphString *gst;
+         int p = gstring->to;
+
+         gst = get_gstring (frame, mt, p, p + 1, control);
+         g_tmp = gst->glyphs + (gst->used - 2);
+         info->left_from = g_tmp->g.from, info->left_to = g_tmp->g.to;
+         M17N_OBJECT_UNREF (gst->top);
+       }
+      else
+       info->left_from = info->left_to = -1;
+    }
+
+  if (info->to < gstring->to)
+    {
+      /* The logically next glyph is on this line.   */
+      MGlyph *g_tmp = find_glyph_in_gstring (gstring, info->to, 0);
+
+      info->next_to = g_tmp->g.to;
+    }
+  else if (info->to + (control->cursor_width == 0) <= mtext_nchars (mt))
+    {
+      /* The logically next glyph is on the next line.   */
+      int p = info->to;
+      MGlyphString *gst = get_gstring (frame, mt, p, p + 1, control);
+      MGlyph *g_tmp = find_glyph_in_gstring (gst, p, 0);
+
+      info->next_to = g_tmp->g.to;
+      M17N_OBJECT_UNREF (gst->top);
+    }
+  else
+    info->next_to = -1;
+
+  for (info->logical_width = (g++)->g.xadv;
+       g->g.from == pos && g->type != GLYPH_ANCHOR;
+       info->metrics.width += g->g.xadv, info->logical_width += (g++)->g.xadv);
+  info->metrics.width += g[-1].g.rbearing - g[-1].g.xadv;
+
+  if (g->type != GLYPH_ANCHOR)
+    info->right_from = g->g.from, info->right_to = g->g.to;
+  else if (! control->orientation_reversed)
+    {
+      if (gstring->to + (control->cursor_width == 0) <= mtext_nchars (mt))
+       {
+         pos = gstring->to;
+         M17N_OBJECT_UNREF (gstring->top);
+         gstring = get_gstring (frame, mt, pos, pos + 1, control);
+         g = MGLYPH (1);
+         info->right_from = g->g.from, info->right_to = g->g.to;
+       }
+      else
+       info->right_from = info->right_to = -1;
+    }
+  else
+    {
+      if (info->line_from > 0)
+       {
+         pos = gstring->from - 1;
+         M17N_OBJECT_UNREF (gstring->top);
+         gstring = get_gstring (frame, mt, pos, pos + 1, control);
+         g = MGLYPH (1);
+         info->right_from = g->g.from, info->right_to = g->g.to;
+       }
+      else
+       info->right_from = info->right_to = -1;
+    }
+
+  M17N_OBJECT_UNREF (gstring->top);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Compute information about glyph sequence.
+
+    The mdraw_glyph_list () function computes information about glyphs
+    corresponding to the text between $FROM and $TO of M-text $MT when
+    it is drawn on a window of frame $FRAME using the
+    mdraw_text_with_control () function with the drawing control
+    object $CONTROL.  $GLYPHS is an array of objects to store the
+    information, and $ARRAY_SIZE is the array size.
+
+    If $ARRAY_SIZE is large enough to cover all glyphs, it stores the
+    number of actually filled elements in the place pointed by
+    $NUM_GLYPHS_RETURN, and returns 0.
+
+    Otherwise, it stores the required array size in the place pointed
+    by $NUM_GLYPHS_RETURN, and returns -1.  */
+
+/***ja
+    @brief ¥°¥ê¥ÕÎó¤Ë´Ø¤¹¤ë¾ðÊó¤ò·×»»¤¹¤ë.
+
+    ´Ø¿ô mdraw_glyph_list () ¤Ï¡¢´Ø¿ô mdraw_text_with_control () 
+    ¤¬ÉÁ²èÀ©¸æ¥ª¥Ö¥¸¥§¥¯¥È $CONTROL ¤òÍѤ¤¤ÆM-text $MT ¤Î $FROM ¤«¤é $TO
+    ¤Þ¤Ç¤ò¥Õ¥ì¡¼¥à $FRAME ¤ËÉÁ²è¤·¤¿¾ì¹ç¤Î¡¢³Æ¥°¥ê¥Õ¤Î¾ðÊó¤ò $GLYPHS 
+    ¤¬»Ø¤¹ÇÛÎó¤Ë³ÊǼ¤¹¤ë¡£ $ARRAY_SIZE ¤Ï¤½¤ÎÇÛÎó¤Î¥µ¥¤¥º¤Ç¤¢¤ë¡£
+
+    ¤â¤· $ARRAY_SIZE ¤¬¤¹¤Ù¤Æ¤Î¥°¥ê¥Õ¤Ë¤Ä¤¤¤Æ¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë¤Î¤Ë½½Ê¬¤Ç¤¢¤ì¤Ð¡¢
+    $NUM_GLYPHS_RETURN ¤¬»Ø¤¹¾ì½ê¤Ë¼ÂºÝ¤ËËä¤á¤¿Í×ÁǤοô¤òÀßÄꤷ 0 ¤òÊÖ¤¹¡£
+
+    
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢$NUM_GLYPHS_RETURN ¤¬»Ø¤¹¾ì½ê¤ËɬÍפÊÇÛÎó¤Î¥µ¥¤¥º¤òÀßÄꤷ¡¢
+    -1 ¤òÊÖ¤¹¡£
+    */
+
+/***
+    @seealso
+    MDrawGlyph
+*/
+
+int
+mdraw_glyph_list (MFrame *frame, MText *mt, int from, int to,
+                 MDrawControl *control, MDrawGlyph *glyphs,
+                 int array_size, int *num_glyphs_return)
+{
+  MGlyphString *gstring;
+  MGlyph *g;
+  int n;
+  int pad_width = 0;
+
+  ASSURE_CONTROL (control);
+  *num_glyphs_return = 0;
+  M_CHECK_RANGE (mt, from, to, -1, 0);
+  gstring = get_gstring (frame, mt, from, to, control);
+  if (! gstring)
+    return -1;
+  for (g = MGLYPH (1), n = 0; g->type != GLYPH_ANCHOR; g++)
+    {
+      if (g->type == GLYPH_BOX
+         || g->g.from < from || g->g.from >= to)
+       continue;
+      if (g->type == GLYPH_PAD)
+       {
+         if (g->left_padding)
+           pad_width = g->g.xadv;
+         else if (n > 0)
+           {
+             pad_width = 0;
+             glyphs[-1].x_advance += g->g.xadv;
+           }
+         continue;
+       }
+      if (n < array_size)
+       {
+         glyphs->from = g->g.from;
+         glyphs->to = g->g.to;
+         glyphs->glyph_code = g->g.code;
+         glyphs->x_off = g->g.xoff + pad_width;
+         glyphs->y_off = g->g.yoff;
+         glyphs->lbearing = g->g.lbearing;
+         glyphs->rbearing = g->g.rbearing;
+         glyphs->ascent = g->g.ascent;
+         glyphs->descent = g->g.descent;
+         glyphs->x_advance = g->g.xadv + pad_width;
+         glyphs->y_advance = 0;
+         if (g->rface->rfont)
+           {
+             glyphs->font = (MFont *) g->rface->rfont;
+#ifdef HAVE_FREETYPE
+             glyphs->font_type
+               = (glyphs->font->source == MFONT_SOURCE_X ? Mx
+                  : g->rface->rfont->driver == &mfont__ft_driver ? Mfreetype
+                  : Mxft);
+#else  /* not HAVE_FREETYPE */
+             glyphs->font_type = Mx;
+#endif /* not HAVE_FREETYPE */
+             glyphs->fontp = g->rface->rfont->fontp;
+           }
+         else
+           {
+             glyphs->font = NULL;
+             glyphs->font_type = Mnil;
+             glyphs->fontp = NULL;
+           }
+         pad_width = 0;
+         glyphs++;
+       }
+      n++;
+    }
+  M17N_OBJECT_UNREF (gstring->top);
+
+  *num_glyphs_return = n;
+  return (n <= array_size ? 0 : -1);
+}
+
+/*=*/
+
+/***en
+    @brief Draw one or more textitems.
+
+    The mdraw_text_items () function draws one or more M-texts on
+    window $WIN of frame $FRAME at coordinate ($X, $Y).  $ITEMS is an array
+    of the textitems to be drawn and $NITEMS is the number of
+    textitems in the array.  */
+
+/***ja
+    @brief textitem ¤òɽ¼¨¤¹¤ë.
+
+    ´Ø¿ô mdraw_text_items () ¤Ï¡¢°ì¸Ä°Ê¾å¤Î¥Æ¥­¥¹¥È¥¢¥¤¥Æ¥à¤ò¡¢¥Õ¥ì¡¼¥à
+    $FRAME ¤Î¥¦¥£¥ó¥É¥¦ $WIN ¤ÎºÂɸ ($X, $Y) ¤Ëɽ¼¨¤¹¤ë¡£$ITEMS 
+    ¤Ïɽ¼¨¤¹¤Ù¤­¥Æ¥­¥¹¥È¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤Ç¤¢¤ê¡¢$NITEMS ¤Ï¤½¤Î¸Ä¿ô¤Ç¤¢¤ë¡£
+
+    @latexonly \IPAlabel{mdraw_text_items} @endlatexonly  */
+
+/***
+    @seealso
+    MTextItem, mdraw_text ().  */
+
+void
+mdraw_text_items (MFrame *frame, MDrawWindow win, int x, int y,
+                 MDrawTextItem *items, int nitems)
+{
+  if (! (frame->device_type & MDEVICE_SUPPORT_OUTPUT))
+    return;
+  while (nitems-- > 0)
+    {
+      if (items->face)
+       mtext_push_prop (items->mt, 0, mtext_nchars (items->mt), Mface,
+                        items->face);
+      mdraw_text_with_control (frame, win, x, y,
+                              items->mt, 0, mtext_nchars (items->mt),
+                              items->control);
+      x += mdraw_text_extents (frame, items->mt, 0, mtext_nchars (items->mt),
+                              items->control, NULL, NULL, NULL);
+      x += items->delta;
+      if (items->face)
+       mtext_pop_prop (items->mt, 0, mtext_nchars (items->mt), Mface);
+    }
+}
+
+/*=*/
+/***en
+    @brief Option of line breaking for drawing text.
+
+    The variable #mdraw_line_break_option specifies line breaking
+    options by logical-or of the members of #MTextLineBreakOption.  It
+    controls the line breaking algorithm of the function
+    mdraw_default_line_break ().  */
+    
+int mdraw_line_break_option;
+
+/*=*/
+/***en 
+    @brief Calculate a line breaking position.
+
+    The function mdraw_default_line_break () calculates a line
+    breaking position based on the line number $LINE and the
+    coordinate $Y, when a line is too long to fit within the width
+    limit.  $POS is the position of the character next to the last one
+    that fits within the limit.  $FROM is the position of the first
+    character of the line, and $TO is the position of the last
+    character displayed on the line if there were not width limit.
+    $LINE and $Y are reset to 0 when a line is broken by a newline
+    character, and incremented each time when a long line is broken
+    because of the width limit.
+
+    @return 
+    This function returns a character position to break the
+    line.
+*/
+
+/***ja 
+      @brief ²þ¹Ô°ÌÃÖ¤ò·×»»¤¹¤ë.
+
+      ´Ø¿ô mdraw_default_line_break () ¤Ï¡¢¹Ô¤¬ºÇÂçÉýÃæ¤Ë¼ý¤Þ¤é¤Ê¤¤¾ì¹ç¤Î²þ¹Ô°ÌÃÖ¤ò¡¢¹ÔÈÖ¹æ
+      $LINE ¤ÈºÂɸ $Y ¤Ë´ð¤Å¤¤¤Æ·×»»¤¹¤ë¡£
+      $POS ¤ÏºÇÂçÉý¤Ë¼ý¤Þ¤ëºÇ¸å¤Îʸ»ú¤Î¼¡¤Îʸ»ú¤Î°ÌÃ֤Ǥ¢¤ë¡£
+      $FROM ¤Ï¤½¤Î¹Ô¤ÎºÇ½é¤Îʸ»ú¤Î°ÌÃÖ¡¢$TO 
+      ¤ÏºÇÂçÉý¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¤½¤Î¹Ô¤Ëɽ¼¨¤µ¤ì¤ëºÇ¸å¤Îʸ»ú¤Î°ÌÃ֤Ǥ¢¤ë¡£
+      $LINE ¤È $Y ¤Ï²þ¹Ôʸ»ú¤Ë¤è¤Ã¤Æ¹Ô¤¬²þ¤Þ¤Ã¤¿ºÝ¤Ë¤Ï 0
+      ¤Ë¥ê¥»¥Ã¥È¤µ¤ì¡¢ºÇÂçÉý¤Ë¤è¤Ã¤Æ¹Ô¤¬²þ¤Þ¤Ã¤¿¾ì¹ç¤Ë¤Ï 1 ¤Å¤ÄÁý¤ä¤µ¤ì¤ë¡£
+
+      @return 
+      ¤³¤Î´Ø¿ô¤Ï²þ¹Ô¤¹¤ëʸ»ú°ÌÃÖ¤òÊÖ¤¹¡£
+*/
+
+int
+mdraw_default_line_break (MText *mt, int pos,
+                         int from, int to, int line, int y)
+{
+  int p, after;
+
+  p = mtext_line_break (mt, pos, mdraw_line_break_option, &after);
+  if (p < from)
+    p = from;
+  else if (p >= to)
+    p = to;
+  return p;
+}
+
+/*=*/
+
+/***en
+    @brief Obtain per character dimension information.
+
+    The mdraw_per_char_extents () function computes the text dimension
+    of each character in M-text $MT.  The faces given as text
+    properties in $MT and the default face of frame $FRAME determine
+    the fonts to draw the text.  Each successive element in
+    $ARRAY_RETURN is set to the drawn metrics of successive
+    characters, which is relative to the origin of the drawing, and a
+    rectangle for each character in $MT.  The number of elements of
+    $ARRAY_RETURN must be equal to or greater than the number of
+    characters in $MT.
+
+    If pointer $OVERALL_RETURN is not @c NULL, this function also
+    computes the extents of the overall text and stores the results in
+    the members of the structure pointed to by $OVERALL_RETURN.  */
+
+/***ja
+    @brief M-text ¤Îʸ»úËè¤Îɽ¼¨ÈϰϾðÊó¤òÆÀ¤ë.
+
+    ´Ø¿ô mdraw_per_char_extents () ¤Ï¡¢M-text $MT 
+    Ãæ¤Î³Æʸ»ú¤Îɽ¼¨ÈϰϤò·×»»¤¹¤ë¡£¤³¤Î·×»»¤ËÍѤ¤¤ë¥Õ¥©¥ó¥È¤Ï¡¢
+    $MT ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ç»ØÄꤵ¤ì¤¿¥Õ¥§¡¼¥¹¤È¡¢¥Õ¥ì¡¼¥à $FRAME
+    ¤Î¥Ç¥Õ¥©¥ë¥È¥Õ¥§¡¼¥¹¤Ë¤è¤Ã¤Æ·è¤Þ¤ë¡£$ARRAY_RETURN ¤Î³ÆÍ×ÁǤϡ¢$MT
+    Ãæ¤Î³Æʸ»ú¤Îɽ¼¨ÈϰϾðÊó¤Ë¤è¤Ã¤Æ½ç¤ËËä¤á¤é¤ì¤ë¡£É½¼¨ÈϰϾðÊó¤È¤Ï¡¢
+    É½¼¨¸¶ÅÀ¤«¤é¤ÎÁêÂаÌÃ֤ȳÆʸ»ú¤ÎÀê¤á¤ëĹÊý·Á¤Ç¤¢¤ë¡£$ARRAY_RETURN 
+    ¤ÎÍ×ÁÇ¿ô¤Ï¡¢M-text Ãæ¤Îʸ»ú¿ô°Ê¾å¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
+
+    ¥Ý¥¤¥ó¥¿ $OVERALL_RETURN ¤¬ @c NULL 
+    ¤Ç¤Ê¤¤¾ì¹ç¤Ï¡¢¥Æ¥­¥¹¥ÈÁ´ÂΤÎɽ¼¨ÈϰϾðÊó¤â·×»»¤·¡¢¤½¤Î·ë²Ì¤ò 
+    $OVERALL_RETURN ¤Î»Ø¤¹¹½Â¤ÂΤ˳ÊǼ¤¹¤ë¡£
+
+    @latexonly \IPAlabel{mdraw_per_char_extents} @endlatexonly  */
+
+void
+mdraw_per_char_extents (MFrame *frame, MText *mt,
+                       MDrawMetric *array_return,
+                       MDrawMetric *overall_return)
+{
+  int n = mtext_nchars (mt);
+
+  mdraw_text_per_char_extents (frame, mt, 0, n, NULL, array_return, NULL,
+                              n, &n, overall_return, NULL);
+}
+
+/***en 
+    @brief clear cached information.    
+
+    The mdraw_clear_cache () function clear cached information
+    on M-text $MT that was attached by any of the drawing functions.
+    When the behavior of `format' or `line_break'
+    member functions of MDrawControl is changed, the cache must be cleared.
+
+    @seealso
+    MDrawControl */
+/***ja 
+    @brief ¥­¥ã¥Ã¥·¥å¾ðÊó¤ò¾Ã¤¹.
+
+    ´Ø¿ô mdraw_clear_cache () ¤ÏÉÁ²è´Ø¿ô¤Ë¤è¤Ã¤Æ M-text $MT 
+    ¤ËÉղ䵤줿¥­¥ã¥Ã¥·¥å¾ðÊó¤ò¤¹¤Ù¤Æ¾Ãµî¤¹¤ë¡£MDrawControl ¤Î `format' 
+    ¤¢¤ë¤¤¤Ï `line_break' 
+    ¥á¥ó¥Ð´Ø¿ô¤Î¿¶Éñ¤¤¤¬ÊѤï¤Ã¤¿¾ì¹ç¤Ë¤Ï¥­¥ã¥Ã¥·¥å¤ò¾Ãµî¤·¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    @seealso
+    MDrawControl */
+
+void
+mdraw_clear_cache (MText *mt)
+{
+  mtext_pop_prop (mt, 0, mtext_nchars (mt), M_glyph_string);
+}
+
+/*** @} */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/face.c b/src/face.c
new file mode 100644 (file)
index 0000000..f5d2ebf
--- /dev/null
@@ -0,0 +1,2097 @@
+/* face.c -- face module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nFace
+    @brief A face is an object to control appearance of M-text.
+
+    A @e face is an object of the type #MFace and controls how to
+    draw M-texts.  A face has a fixed number of @e face @e properties.
+    Like other types of properties, a face property consists of a key
+    and a value.  A key is one of the following symbols:
+
+    #Mforeground, #Mbackground, #Mvideomode, #Mhline, #Mbox,
+    #Mfoundry, #Mfamily, #Mweight, #Mstyle, #Mstretch, #Madstyle,
+    #Msize, #Mfontset, #Mratio, #Mhook_func, #Mhook_arg
+
+    The notation "xxx property of F" means the face property that
+    belongs to face F and whose key is @c Mxxx.
+
+    The M-text drawing functions first search an M-text for the text
+    property whose key is the symbol #Mface, then draw the M-text
+    using the value of that text property.  This value must be a
+    pointer to a face object.
+
+    If there are multiple text properties whose key is @c Mface, and
+    they are not conflicting one another, properties of those faces
+    are merged and used.
+
+    If no faces specify a certain property, the value of the default
+    face is used.  */
+
+/***ja
+    @addtogroup m17nFace
+    @brief ¥Õ¥§¡¼¥¹¤È¤Ï¡¢M-text ¤Î¸«±É¤¨¤òÀ©¸æ¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë.
+
+    @e ¥Õ¥§¡¼¥¹ ¤Ï #MFace ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ê¡¢M-text 
+    ¤Îɽ¼¨ÊýË¡¤òÀ©¸æ¤¹¤ë¡£¥Õ¥§¡¼¥¹¤Ï¸ÇÄê¸Ä¤Î @e ¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£ ¤ò»ý¤Ä¡£
+    Â¾¤Î¥×¥í¥Ñ¥Æ¥£Æ±ÍÍ¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Ï¥­¡¼¤ÈÃͤ«¤é¤Ê¤ê¡¢¥­¡¼¤Ï°Ê²¼¤Î¥·¥ó¥Ü¥ë¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£
+
+    #Mforeground, #Mbackground, #Mvideomode, #Mhline, #Mbox, 
+    #Mfoundry, #Mfamily, #Mweight, #Mstyle, #Mstretch, #Madstyle, 
+    #Msize, #Mfontset, #Mratio, #Mhook_func, #Mhook_arg
+
+    ¡Ö¥Õ¥§¡¼¥¹ F ¤Î¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¥­¡¼¤¬ @c Mxxx 
+    ¤Ç¤¢¤ë¤â¤Î¡×¤Î¤³¤È¤ò´Êñ¤Ë¡ÖF ¤Î xxx ¥×¥í¥Ñ¥Æ¥£¡×¤È¸Æ¤Ö¤³¤È¤¬¤¢¤ë¡£
+
+    M-text ¤Îɽ¼¨´Ø¿ô¤Ï¡¢¤Þ¤ººÇ½é¤Ë¤½¤Î M-text ¤«¤é¥­¡¼¤¬¥·¥ó¥Ü¥ë 
+    #Mface ¤Ç¤¢¤ë¤è¤¦¤Ê¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òõ¤·¡¢¼¡¤Ë¤½¤ÎÃͤ˽¾¤Ã¤Æ 
+    M-text ¤òɽ¼¨¤¹¤ë¡£¤³¤ÎÃͤϥե§¡¼¥¹¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
+
+    M-text ¤¬¡¢#Mface 
+    ¤ò¥­¡¼¤È¤¹¤ë¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÊ£¿ô»ý¤Ã¤Æ¤ª¤ê¡¢¤«¤Ä¤½¤ì¤é¤ÎÃͤ¬¾×Æͤ·¤Ê¤¤¤Ê¤é¤Ð¡¢¥Õ¥§¡¼¥¹¾ðÊó¤ÏÁȤ߹ç¤ï¤µ¤ì¤ÆÍѤ¤¤é¤ì¤ë¡£
+
+    ¤¢¤ë¥Æ¥­¥¹¥È°À­¤¬¤É¤Î¥Õ¥§¡¼¥¹¤Ë¤è¤Ã¤Æ¤â»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¥Õ¥§¡¼¥¹¤ÎÃͤ¬ÍѤ¤¤é¤ì¤ë¡£  */
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "config.h"
+#include "m17n-gui.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "charset.h"
+#include "symbol.h"
+#include "plist.h"
+#include "mtext.h"
+#include "textprop.h"
+#include "internal-gui.h"
+#include "face.h"
+#include "font.h"
+#include "fontset.h"
+
+static M17NObjectArray face_table;
+
+MSymbol Mlatin;
+
+static MSymbol M_face_prop_index;
+
+static MPlist *hline_prop_list;
+static MPlist *box_prop_list;
+
+/** Special hook function pointer that does nothing.  */
+static MFaceHookFunc noop_hook;
+
+/**  */
+static MFaceHLineProp *
+get_hline_create (MFaceHLineProp *prop)
+{
+  MPlist *plist;
+  MFaceHLineProp *hline;
+
+  if (prop->width == 0)
+    return MPLIST_VAL (hline_prop_list);
+  MPLIST_DO (plist, MPLIST_NEXT (hline_prop_list))
+    {
+      hline = MPLIST_VAL (plist);
+      if (prop->type == hline->type
+         && prop->width == hline->width
+         && prop->color == hline->color)
+       return hline;
+    }
+  MSTRUCT_MALLOC (hline, MERROR_FACE);
+  *hline = *prop;
+  mplist_push (plist, Mt, hline);
+  return hline;
+}
+
+static MFaceBoxProp *
+get_box_create (MFaceBoxProp *prop)
+{
+  MPlist *plist;
+  MFaceBoxProp *box;
+
+  if (prop->width == 0)
+    return MPLIST_VAL (box_prop_list);
+  MPLIST_DO (plist, MPLIST_NEXT (box_prop_list))
+    {
+      box = MPLIST_VAL (plist);
+      if (prop->width == box->width
+         && prop->color_top == box->color_top
+         && prop->color_bottom == box->color_bottom
+         && prop->color_left == box->color_left
+         && prop->color_right == box->color_right
+         && prop->inner_hmargin == box->inner_hmargin
+         && prop->inner_vmargin == box->inner_vmargin
+         && prop->outer_hmargin == box->inner_hmargin
+         && prop->inner_vmargin == box->inner_vmargin)
+       return box;
+    }
+  MSTRUCT_MALLOC (box, MERROR_FACE);
+  *box = *prop;
+  mplist_push (plist, Mt, box);
+  return box;
+}
+
+/** From FRAME->realized_face_list, find a realized face based on
+    FACE.  */
+
+static MRealizedFace *
+find_realized_face (MFrame *frame, MFace *face, MFont *font)
+{
+  MPlist *plist;
+
+  MPLIST_DO (plist, frame->realized_face_list)
+    {
+      MRealizedFace *rface = MPLIST_VAL (plist);
+
+      if (memcmp (rface->face.property, face->property,
+                 sizeof face->property) == 0
+         && (rface->font
+             ? (font && ! memcmp (rface->font, font, sizeof (MFont)))
+             : ! font))
+       return rface;
+    }
+  return NULL;
+}
+
+static void
+free_face (void *object)
+{
+  MFace *face = (MFace *) object;
+
+  if (face->property[MFACE_FONTSET])
+    M17N_OBJECT_UNREF (face->property[MFACE_FONTSET]);
+  M17N_OBJECT_UNREF (face->frame_list);
+  M17N_OBJECT_UNREGISTER (face_table, face);
+  free (object);
+}
+
+
+static MPlist *
+serialize_hline (MPlist *plist, MFaceHLineProp *hline)
+{
+  if (hline->width > 0)
+    {
+      MPlist *pl = mplist ();
+
+      mplist_add (pl, Minteger, (void *) hline->type);
+      mplist_add (pl, Minteger, (void *) hline->width);
+      mplist_add (pl, Msymbol, hline->color);
+      plist = mplist_add (plist, Mplist, pl);
+      M17N_OBJECT_UNREF (pl);
+    }
+  return plist;
+}
+
+static MPlist *
+serialize_box (MPlist *plist, MFaceBoxProp *box)
+{
+  if (box->width > 0)
+    {
+      MPlist *pl = mplist ();
+
+      mplist_add (pl, Minteger, (void *) box->width);
+      mplist_add (pl, Minteger, (void *) box->inner_hmargin);
+      mplist_add (pl, Minteger, (void *) box->inner_vmargin);
+      mplist_add (pl, Minteger, (void *) box->outer_hmargin);
+      mplist_add (pl, Minteger, (void *) box->outer_vmargin);
+      mplist_add (pl, Msymbol, box->color_top);
+      mplist_add (pl, Msymbol, box->color_bottom);
+      mplist_add (pl, Msymbol, box->color_left);
+      mplist_add (pl, Msymbol, box->color_right);
+      plist = mplist_add (plist, Mplist, pl);
+      M17N_OBJECT_UNREF (pl);
+    }
+  return plist;
+}
+
+static MPlist *
+serialize_face (void *val)
+{
+  MFace *face = val;
+  MPlist *plist = mplist (), *pl = plist;
+  int i;
+  struct {
+    MSymbol *key;
+    MSymbol *type;
+    MPlist *(*func) (MPlist *plist, void *val);
+  } serializer[MFACE_RATIO + 1]
+      = { { &Mfoundry,         &Msymbol },
+         { &Mfamily,           &Msymbol },
+         { &Mweight,           &Msymbol },
+         { &Mstyle,            &Msymbol },
+         { &Mstretch,          &Msymbol },
+         { &Madstyle,          &Msymbol },
+         { &Msize,             &Minteger },
+         { &Mfontset,          NULL },
+         { &Mforeground,       &Msymbol },
+         { &Mbackground,       &Msymbol },
+         { &Mhline,            NULL },
+         { &Mbox,              NULL },
+         { &Mvideomode,        &Msymbol },
+         { &Mratio,            &Minteger } };
+  
+  for (i = 0; i <= MFACE_RATIO; i++)
+    if (face->property[i] && serializer[i].key)
+      {
+       pl = mplist_add (pl, Msymbol, *serializer[i].key);
+       if (serializer[i].type)
+         pl = mplist_add (pl, *serializer[i].type, face->property[i]);
+       else if (i == MFACE_FONTSET)
+         pl = mplist_add (pl, Msymbol, mfontset_name ((MFontset *)
+                                                      face->property[i]));
+       else if (i == MFACE_HLINE)
+         pl = serialize_hline (pl, (MFaceHLineProp *) face->property[i]);
+       else if (i == MFACE_BOX)
+         pl = serialize_box (pl, (MFaceBoxProp *) face->property[i]);
+      }
+
+  return plist;
+}
+
+static void *
+deserialize_hline (MPlist *plist)
+{
+  MFaceHLineProp hline, *hline_ret;
+
+  if (! MPLIST_INTEGER_P (plist))
+    MERROR (MERROR_FACE, NULL);
+  hline.type = MPLIST_INTEGER_P (plist);
+  plist = MPLIST_NEXT (plist);
+  if (! MPLIST_INTEGER_P (plist))
+    MERROR (MERROR_FACE, NULL);
+  hline.width = MPLIST_INTEGER_P (plist);
+  plist = MPLIST_NEXT (plist);
+  if (! MPLIST_SYMBOL_P (plist))
+    MERROR (MERROR_FACE, NULL);
+  hline.color = MPLIST_SYMBOL (plist);
+  MSTRUCT_MALLOC (hline_ret, MERROR_FACE);
+  *hline_ret = hline;
+  return hline_ret;
+}
+
+static void *
+deserialize_box (MPlist *plist)
+{
+  MFaceBoxProp box, *box_ret;
+
+  if (! MPLIST_INTEGER_P (plist))
+    MERROR (MERROR_FACE, NULL);
+  box.width = MPLIST_INTEGER (plist);
+  plist = MPLIST_NEXT (plist);
+  if (! MPLIST_INTEGER_P (plist))
+    MERROR (MERROR_FACE, NULL);
+  box.inner_hmargin = MPLIST_INTEGER (plist);
+  plist = MPLIST_NEXT (plist);
+  if (! MPLIST_INTEGER_P (plist))
+    MERROR (MERROR_FACE, NULL);
+  box.inner_vmargin = MPLIST_INTEGER (plist);
+  plist = MPLIST_NEXT (plist);
+  if (! MPLIST_INTEGER_P (plist))
+    MERROR (MERROR_FACE, NULL);
+  box.outer_hmargin = MPLIST_INTEGER (plist);
+  plist = MPLIST_NEXT (plist);
+  if (! MPLIST_INTEGER_P (plist))
+    MERROR (MERROR_FACE, NULL);
+  box.outer_vmargin = MPLIST_INTEGER (plist);
+  plist = MPLIST_NEXT (plist);
+  if (! MPLIST_SYMBOL_P (plist))
+    MERROR (MERROR_FACE, NULL);
+  box.color_top = MPLIST_SYMBOL (plist);
+  plist = MPLIST_NEXT (plist);
+  if (! MPLIST_SYMBOL_P (plist))
+    MERROR (MERROR_FACE, NULL);
+  box.color_bottom = MPLIST_SYMBOL (plist);
+  plist = MPLIST_NEXT (plist);
+  if (! MPLIST_SYMBOL_P (plist))
+    MERROR (MERROR_FACE, NULL);
+  box.color_left = MPLIST_SYMBOL (plist);
+  plist = MPLIST_NEXT (plist);
+  if (! MPLIST_SYMBOL_P (plist))
+    MERROR (MERROR_FACE, NULL);
+  box.color_right = MPLIST_SYMBOL (plist);
+  MSTRUCT_MALLOC (box_ret, MERROR_FACE);
+  *box_ret = box;
+  return box_ret;
+}
+
+static void *
+deserialize_face (MPlist *plist)
+{
+  MFace *face = mface ();
+
+  MPLIST_DO (plist, plist)
+    {
+      MSymbol key;
+      int index;
+      void *val;
+
+      if (! MPLIST_SYMBOL_P (plist))
+       break;
+      key = MPLIST_SYMBOL (plist);
+      index = (int) msymbol_get (key, M_face_prop_index) - 1;
+      plist = MPLIST_NEXT (plist);
+      if (MPLIST_TAIL_P (plist))
+       break;
+      if (index < 0 || index > MFACE_RATIO)
+       continue;
+      if (key == Mfoundry || key == Mfamily || key == Mweight || key == Mstyle
+         || key == Mstretch || key == Madstyle
+         || key == Mforeground || key == Mbackground || key == Mvideomode)
+       {
+         if (! MPLIST_SYMBOL_P (plist))
+           continue;
+         val = MPLIST_VAL (plist);
+       }
+      else if (key == Msize || key == Mratio)
+       {
+         if (! MPLIST_INTEGER_P (plist))
+           continue;
+         val = MPLIST_VAL (plist);
+       }
+      else if (key == Mfontset)
+       {
+         if (! MPLIST_SYMBOL_P (plist))
+           continue;
+         val = mfontset (MSYMBOL_NAME (MPLIST_SYMBOL (plist)));
+       }
+      else if (key == Mhline)
+       {
+         if (! MPLIST_PLIST_P (plist))
+           continue;
+         val = deserialize_hline (MPLIST_PLIST (plist));
+       }
+      else if (key == Mbox)
+       {
+         if (! MPLIST_PLIST_P (plist))
+           continue;
+         val = deserialize_box (MPLIST_PLIST (plist));
+       }
+      face->property[index] = val;
+    }
+  return face;
+}
+
+static MGlyphString work_gstring;
+
+\f
+
+/* Internal API */
+
+MFace *mface__default;
+
+int
+mface__init ()
+{
+  int i;
+  MFaceHLineProp *hline;
+  MFaceBoxProp *box;
+
+  M17N_OBJECT_ADD_ARRAY (face_table, "Face");
+  Mface = msymbol_as_managing_key ("face");
+  msymbol_put_func (Mface, Mtext_prop_serializer,
+                   M17N_FUNC (serialize_face));
+  msymbol_put_func (Mface, Mtext_prop_deserializer,
+                   M17N_FUNC (deserialize_face));
+
+  Mforeground = msymbol ("foreground");
+  Mbackground = msymbol ("background");
+  Mvideomode = msymbol ("videomode");
+  Mnormal = msymbol ("normal");
+  Mreverse = msymbol ("reverse");
+  Mratio = msymbol ("ratio");
+  Mhline = msymbol ("hline");
+  Mbox = msymbol ("box");
+  Mhook_func = msymbol ("hook-func");
+  Mhook_arg = msymbol ("hook-arg");
+
+  Mlatin = msymbol ("latin");
+  M_face_prop_index = msymbol ("  face-prop-index");
+
+  {
+    struct {
+      /* Pointer to the key symbol of the face property.  */
+      MSymbol *key;
+      /* Index (enum face_property) of the face property. */
+      int index;
+    } mface_prop_data[MFACE_HOOK_ARG + 1] =
+       { { &Mfoundry,          MFACE_FOUNDRY },
+         { &Mfamily,           MFACE_FAMILY },
+         { &Mweight,           MFACE_WEIGHT },
+         { &Mstyle,            MFACE_STYLE },
+         { &Mstretch,          MFACE_STRETCH },
+         { &Madstyle,          MFACE_ADSTYLE },
+         { &Msize,             MFACE_SIZE },
+         { &Mfontset,          MFACE_FONTSET },
+         { &Mforeground,       MFACE_FOREGROUND },
+         { &Mbackground,       MFACE_BACKGROUND },
+         { &Mhline,            MFACE_HLINE },
+         { &Mbox,              MFACE_BOX },
+         { &Mvideomode,        MFACE_VIDEOMODE },
+         { &Mratio,            MFACE_RATIO },
+         { &Mhook_arg,         MFACE_HOOK_ARG } };
+
+    for (i = 0; i < MFACE_PROPERTY_MAX; i++)
+      /* We add one to distinguish it from no-property.  */
+      msymbol_put (*mface_prop_data[i].key, M_face_prop_index,
+                  (void *) (mface_prop_data[i].index + 1));
+  }
+
+  hline_prop_list = mplist ();
+  MSTRUCT_CALLOC (hline, MERROR_FACE);
+  mplist_push (hline_prop_list, Mt, hline);
+  box_prop_list = mplist ();
+  MSTRUCT_CALLOC (box, MERROR_FACE);
+  mplist_push (box_prop_list, Mt, box);
+
+  mface__default = mface ();
+  mface__default->property[MFACE_FOUNDRY] = msymbol ("misc");
+  mface__default->property[MFACE_FAMILY] = msymbol ("fixed");
+  mface__default->property[MFACE_WEIGHT] = msymbol ("medium");
+  mface__default->property[MFACE_STYLE] = msymbol ("r");
+  mface__default->property[MFACE_STRETCH] = msymbol ("normal");
+  mface__default->property[MFACE_ADSTYLE] = msymbol ("");
+  mface__default->property[MFACE_SIZE] = (void *) 120;
+  mface__default->property[MFACE_FONTSET] = mfontset (NULL);
+  mface__default->property[MFACE_FOREGROUND] = msymbol ("black");
+  mface__default->property[MFACE_BACKGROUND] = msymbol ("white");
+  mface__default->property[MFACE_HLINE] = hline;
+  mface__default->property[MFACE_BOX] = box;
+  mface__default->property[MFACE_VIDEOMODE] = Mnormal;
+  mface__default->hook = noop_hook;
+
+  mface_normal_video = mface ();
+  mface_normal_video->property[MFACE_VIDEOMODE] = (void *) Mnormal;
+
+  mface_reverse_video = mface ();
+  mface_reverse_video->property[MFACE_VIDEOMODE] = (void *) Mreverse;
+
+  {
+    MFaceHLineProp hline_prop;
+
+    hline_prop.type = MFACE_HLINE_UNDER;
+    hline_prop.width = 1;
+    hline_prop.color = Mnil;
+    mface_underline = mface ();
+    mface_put_prop (mface_underline, Mhline, &hline_prop);
+  }
+
+  mface_medium = mface ();
+  mface_medium->property[MFACE_WEIGHT] = (void *) msymbol ("medium");
+  mface_bold = mface ();
+  mface_bold->property[MFACE_WEIGHT] = (void *) msymbol ("bold");
+  mface_italic = mface ();
+  mface_italic->property[MFACE_STYLE] = (void *) msymbol ("i");
+  mface_bold_italic = mface_copy (mface_bold);
+  mface_bold_italic->property[MFACE_STYLE]
+    = mface_italic->property[MFACE_STYLE];
+
+  mface_xx_small = mface ();
+  mface_xx_small->property[MFACE_RATIO] = (void *) 50;
+  mface_x_small = mface ();
+  mface_x_small->property[MFACE_RATIO] = (void *) 67;
+  mface_small = mface ();
+  mface_small->property[MFACE_RATIO] = (void *) 75;
+  mface_normalsize = mface ();
+  mface_normalsize->property[MFACE_RATIO] = (void *) 100;
+  mface_large = mface ();
+  mface_large->property[MFACE_RATIO] = (void *) 120;
+  mface_x_large = mface ();
+  mface_x_large->property[MFACE_RATIO] = (void *) 150;
+  mface_xx_large = mface ();
+  mface_xx_large->property[MFACE_RATIO] = (void *) 200;
+
+  mface_black = mface ();
+  mface_black->property[MFACE_FOREGROUND] = (void *) msymbol ("black");
+  mface_white = mface ();
+  mface_white->property[MFACE_FOREGROUND] = (void *) msymbol ("white");
+  mface_red = mface ();
+  mface_red->property[MFACE_FOREGROUND] = (void *) msymbol ("red");
+  mface_green = mface ();
+  mface_green->property[MFACE_FOREGROUND] = (void *) msymbol ("green");
+  mface_blue = mface ();
+  mface_blue->property[MFACE_FOREGROUND] = (void *) msymbol ("blue");
+  mface_cyan = mface ();
+  mface_cyan->property[MFACE_FOREGROUND] = (void *) msymbol ("cyan");
+  mface_yellow = mface ();
+  mface_yellow->property[MFACE_FOREGROUND] = (void *) msymbol ("yellow");
+  mface_magenta = mface ();
+  mface_magenta->property[MFACE_FOREGROUND] = (void *) msymbol ("magenta");
+
+  work_gstring.glyphs = malloc (sizeof (MGlyph) * 2);
+  work_gstring.size = 2;
+  work_gstring.used = 0;
+  work_gstring.inc = 1;
+  return 0;
+}
+
+void
+mface__fini ()
+{
+  MPlist *plist;
+
+  M17N_OBJECT_UNREF (mface__default);
+  M17N_OBJECT_UNREF (mface_normal_video);
+  M17N_OBJECT_UNREF (mface_reverse_video);
+  M17N_OBJECT_UNREF (mface_underline);
+  M17N_OBJECT_UNREF (mface_medium);
+  M17N_OBJECT_UNREF (mface_bold);
+  M17N_OBJECT_UNREF (mface_italic);
+  M17N_OBJECT_UNREF (mface_bold_italic);
+  M17N_OBJECT_UNREF (mface_xx_small);
+  M17N_OBJECT_UNREF (mface_x_small);
+  M17N_OBJECT_UNREF (mface_small);
+  M17N_OBJECT_UNREF (mface_normalsize);
+  M17N_OBJECT_UNREF (mface_large);
+  M17N_OBJECT_UNREF (mface_x_large);
+  M17N_OBJECT_UNREF (mface_xx_large);
+  M17N_OBJECT_UNREF (mface_black);
+  M17N_OBJECT_UNREF (mface_white);
+  M17N_OBJECT_UNREF (mface_red);
+  M17N_OBJECT_UNREF (mface_green);
+  M17N_OBJECT_UNREF (mface_blue);
+  M17N_OBJECT_UNREF (mface_cyan);
+  M17N_OBJECT_UNREF (mface_yellow);
+  M17N_OBJECT_UNREF (mface_magenta);
+
+  MPLIST_DO (plist, hline_prop_list)
+    free (MPLIST_VAL (plist));
+  M17N_OBJECT_UNREF (hline_prop_list);
+  MPLIST_DO (plist, box_prop_list)
+    free (MPLIST_VAL (plist));
+  M17N_OBJECT_UNREF (box_prop_list);
+
+  free (work_gstring.glyphs);
+}
+
+/** Return a face realized from NUM number of base faces pointed by
+    FACES on the frame FRAME.  If SIZE is nonzero, it specifies the
+    maximum font size.  */
+
+MRealizedFace *
+mface__realize (MFrame *frame, MFace **faces, int num, int size, MFont *font)
+{
+  MRealizedFace *rface;
+  MRealizedFont *rfont;
+  MFace merged_face = *(frame->face);
+  int i, j;
+  MFaceHookFunc func;
+  MFont spec;
+
+  if (num == 0 && frame->rface && ! font)
+    return frame->rface;
+
+  if (! mplist_find_by_value (frame->face->frame_list, frame))
+    mplist_push (frame->face->frame_list, Mt, frame);
+  for (i = 0; i < num; i++)
+    if (! mplist_find_by_value (faces[i]->frame_list, frame))
+      mplist_push (faces[i]->frame_list, Mt, frame);
+
+  for (i = 0; i < MFACE_PROPERTY_MAX; i++)
+    for (j = num - 1; j >= 0; j--)
+      if (faces[j]->property[i])
+       {
+         merged_face.property[i] = faces[j]->property[i];
+         break;
+       }
+
+  if (font)
+    {
+      if (font->type != MFONT_TYPE_REALIZED)
+       font = mfont_copy (font);
+      for (i = 0; i <= MFACE_ADSTYLE; i++)
+       if (font->property[i])
+         merged_face.property[i] = FONT_PROPERTY (font, i);
+      if (font->size)
+       {
+         int font_size;
+
+         if (font->size < 0)
+           font->size = ((double) (- font->size)) * frame->dpi / 72.27 + 0.5;
+         font_size = font->size;
+         merged_face.property[MFACE_SIZE] = (void *) font_size;
+         merged_face.property[MFACE_RATIO] = (void *) 0;
+       }
+    }
+
+  if (! font || ! font->size)
+    {
+      double font_size = (int) merged_face.property[MFACE_SIZE];
+      int ifont_size;
+
+      if (font_size < 0)
+       font_size = - font_size * frame->dpi / 72.27;
+      if (merged_face.property[MFACE_RATIO]
+         && (int) merged_face.property[MFACE_RATIO] != 100)
+       {
+         font_size *= (int) merged_face.property[MFACE_RATIO];
+         font_size /= 100;
+       }
+      ifont_size = font_size + 0.5;
+      merged_face.property[MFACE_SIZE] = (void *) ifont_size;
+      merged_face.property[MFACE_RATIO] = (void *) 0;
+    }
+
+  merged_face.property[MFACE_FOUNDRY] = Mnil;
+  rface = find_realized_face (frame, &merged_face, font);
+  if (rface)
+    {
+      if (font && font->type != MFONT_TYPE_REALIZED)
+       free (font);
+      return rface;
+    }
+
+  MSTRUCT_CALLOC (rface, MERROR_FACE);
+  mplist_push (frame->realized_face_list, Mt, rface);
+  rface->frame = frame;
+  rface->face = merged_face;
+  rface->font = font;
+
+  if (font)
+    {
+      if (font->type == MFONT_TYPE_SPEC)
+       rfont = (MRealizedFont *) mfont_find (frame, font, NULL, 0);
+      else if (font->type == MFONT_TYPE_OBJECT)
+       {
+         MFONT_INIT (&spec);
+         spec.size = (int) merged_face.property[MFONT_SIZE];
+         if (font->property[MFONT_REGISTRY])
+           spec.property[MFONT_REGISTRY] = font->property[MFONT_REGISTRY];
+         else
+           mfont_put_prop (&spec, Mregistry,
+                           (font->source == MFONT_SOURCE_X
+                            ? Miso8859_1 : Municode_bmp));
+         rfont = mfont__open (frame, font, &spec);
+       }
+      else
+       rfont = (MRealizedFont *) font;
+    }
+  else
+    {
+      MFontset *fontset = (MFontset *) merged_face.property[MFACE_FONTSET];
+
+      rface->rfontset = mfont__realize_fontset (frame, fontset, &merged_face,
+                                               font);
+      rfont = NULL;
+      mfont__set_spec_from_face (&spec, &merged_face);
+      mfont_put_prop (&spec, Mregistry, Municode_bmp);
+      spec.source = MFONT_SOURCE_FT;
+      font = mfont__select (frame, &spec, 0);
+      if (font)
+       rfont = mfont__open (frame, font, &spec);
+      if (! rfont)
+       {
+         mfont_put_prop (&spec, Mregistry, Miso8859_1);
+         spec.source = MFONT_SOURCE_X;
+         font = mfont__select (frame, &spec, 0);
+         if (font)
+           rfont = mfont__open (frame, font, &spec);
+       }
+      if (! rfont)
+       {
+         num = 0;
+         rfont = mfont__lookup_fontset (rface->rfontset, NULL, &num,
+                                        Mlatin, Mnil, Mnil, size, 0);
+       }
+    }
+
+  if (rfont)
+    {
+      rface->rfont = rfont;
+      rface->layouter = rfont->layouter;
+      rfont->layouter = Mnil;
+      work_gstring.glyphs[0].rface = rface;
+      work_gstring.glyphs[0].g.code = MCHAR_INVALID_CODE;
+      work_gstring.glyphs[0].g.measured = 0;
+      mfont__get_metric (&work_gstring, 0, 1);
+      rface->ascent = work_gstring.glyphs[0].g.ascent;
+      rface->descent = work_gstring.glyphs[0].g.descent;
+      work_gstring.glyphs[0].g.code
+       = mfont__encode_char (frame, (MFont *) rfont, NULL, ' ');
+      if (work_gstring.glyphs[0].g.code != MCHAR_INVALID_CODE)
+       {
+         work_gstring.glyphs[0].g.measured = 0;
+         mfont__get_metric (&work_gstring, 0, 1);
+         rface->space_width = work_gstring.glyphs[0].g.xadv;
+       }
+      else
+       rface->space_width = rfont->spec.size / 10;
+      if (rfont->average_width)
+       rface->average_width = rfont->average_width >> 6;
+      else
+       {
+         work_gstring.glyphs[0].g.code
+           = mfont__encode_char (frame, (MFont *) rfont, NULL, 'x');
+         if (work_gstring.glyphs[0].g.code != MCHAR_INVALID_CODE)
+           {
+             work_gstring.glyphs[0].g.measured = 0;
+             mfont__get_metric (&work_gstring, 0, 1);
+             rface->average_width = work_gstring.glyphs[0].g.xadv;
+           }
+         else
+           rface->average_width = rface->space_width;
+       }
+    }
+  else
+    {
+      rface->rfont = NULL;
+      rface->space_width = frame->space_width;
+    }
+
+  rface->hline = (MFaceHLineProp *) merged_face.property[MFACE_HLINE];
+  if (rface->hline && rface->hline->width == 0)
+    rface->hline = NULL;
+  rface->box = (MFaceBoxProp *) merged_face.property[MFACE_BOX];
+  if (rface->box && rface->box->width == 0)
+    rface->box = NULL;
+  rface->ascii_rface = rface;
+  (*frame->driver->realize_face) (rface);
+
+  func = rface->face.hook;
+  if (func && func != noop_hook)
+    (func) (&(rface->face), rface->info, rface->face.property[MFACE_HOOK_ARG]);
+
+  rface->non_ascii_list = mplist ();
+  if (rface->rfont)
+    {
+      MRealizedFace *nofont;
+
+      MSTRUCT_CALLOC (nofont, MERROR_FACE);
+      *nofont = *rface;
+      nofont->non_ascii_list = NULL;
+      nofont->rfont = NULL;
+      mplist_add (rface->non_ascii_list, Mt, nofont);
+    }
+
+  return rface;
+}
+
+
+MGlyph *
+mface__for_chars (MSymbol script, MSymbol language, MSymbol charset,
+                 MGlyph *from_g, MGlyph *to_g, int size)
+{
+  MRealizedFont *rfont = from_g->rface->rfont;
+  MSymbol layouter;
+  int num = to_g - from_g;
+  int i;
+
+  if (from_g->rface->font)
+    {
+      MRealizedFace *rface = from_g->rface, *new;
+
+      if (! rfont)
+       rfont = mfontset__get_font (rface->frame,
+                                   rface->face.property[MFACE_FONTSET], 
+                                   script, language,
+                                   rface->font, NULL);
+      else if (script != Mlatin)
+       rfont = mfontset__get_font (rface->frame,
+                                   rface->face.property[MFACE_FONTSET],
+                                   script, language,
+                                   (MFont *) rfont, NULL);
+      if (! rfont)
+       {
+         for (; from_g < to_g && from_g->rface->font; from_g++)
+           from_g->g.code = MCHAR_INVALID_CODE;
+       }
+      else
+       {
+         if (rface->rfont == rfont && rfont->layouter == Mnil)
+           new = rface;
+         else
+           {
+             MSTRUCT_MALLOC (new, MERROR_FACE);
+             mplist_push (rface->non_ascii_list, Mt, new);
+             *new = *rface;
+             new->rfont = rfont;
+             new->layouter = rfont->layouter;
+             rfont->layouter = Mnil;
+             new->non_ascii_list = NULL;
+             new->ascent = rfont->ascent >> 6;
+             new->descent = rfont->descent >> 6;
+           } 
+         for (; from_g < to_g && from_g->rface->font; from_g++)
+           {
+             from_g->rface = new;
+             if (new->layouter)
+               {
+                 MFLT *flt = mflt_get (new->layouter);
+                 MCharTable *coverage;
+
+                 if (! flt
+                     || ((coverage = mflt_coverage (flt))
+                         && ! (from_g->g.code
+                               = (unsigned) mchartable_lookup (coverage,
+                                                               from_g->g.c))))
+                   {
+                     from_g->rface = rface;
+                     from_g->g.code = mfont__encode_char (rfont->frame, 
+                                                          (MFont *) rfont,
+                                                          NULL, from_g->g.c);
+                   }
+               }
+             else
+               from_g->g.code = mfont__encode_char (rfont->frame, 
+                                                    (MFont *) rfont,
+                                                    NULL, from_g->g.c);
+           }
+       }
+      return from_g;
+    }
+
+  if (rfont && script == Mlatin)
+    {
+      for (i = 0; i < num; i++)
+       {
+         unsigned code = mfont__encode_char (rfont->frame, (MFont *) rfont,
+                                             NULL, from_g[i].g.c);
+         if (code == MCHAR_INVALID_CODE)
+           break;
+         from_g[i].g.code = code;
+       }
+      if (i == num || from_g[i].rface->font)
+       return from_g + i;
+    }
+
+  rfont = mfont__lookup_fontset (from_g->rface->rfontset, from_g, &num,
+                                script, language, charset, size, 0);
+  if (rfont)
+    {
+      layouter = rfont->layouter;
+      rfont->layouter = Mnil;
+    }
+  else
+    {
+      from_g->g.code = MCHAR_INVALID_CODE;
+      num = 1;
+      rfont = NULL;
+      layouter = Mnil;
+    }
+  
+  to_g = from_g + num;
+  while (from_g < to_g)
+    {
+      MGlyph *g = from_g;
+      MRealizedFace *rface = from_g++->rface;
+
+      while (from_g < to_g && rface == from_g->rface) from_g++;
+      if (rface->rfont != rfont
+         || rface->layouter != layouter)
+       {
+         MPlist *plist = mplist_find_by_value (rface->non_ascii_list, rfont);
+         MRealizedFace *new = NULL;
+
+         while (plist)
+           {
+             new = MPLIST_VAL (plist);
+             if (new->layouter == layouter)
+               break;
+             plist = mplist_find_by_value (MPLIST_NEXT (plist), rfont);
+           }
+         if (! plist)
+           {
+             MSTRUCT_MALLOC (new, MERROR_FACE);
+             mplist_push (rface->non_ascii_list, Mt, new);
+             *new = *rface;
+             new->rfont = rfont;
+             new->layouter = layouter;
+             new->non_ascii_list = NULL;
+             if (rfont)
+               {
+                 new->ascent = rfont->ascent >> 6;
+                 new->descent = rfont->descent >> 6;
+               }
+           }
+         while (g < from_g)
+           g++->rface = new;
+       }
+    }
+  return to_g;
+}
+
+
+void
+mface__free_realized (MRealizedFace *rface)
+{
+  MPlist *plist;
+
+  MPLIST_DO (plist, rface->non_ascii_list)
+    free (MPLIST_VAL (plist));
+  M17N_OBJECT_UNREF (rface->non_ascii_list);
+  if (rface->font && rface->font->type != MFONT_TYPE_REALIZED)
+    free (rface->font);
+  free (rface);
+}
+
+void
+mface__update_frame_face (MFrame *frame)
+{
+  frame->rface = NULL;
+  frame->rface = mface__realize (frame, NULL, 0, 0, NULL);
+  frame->space_width = frame->rface->space_width;
+  frame->average_width = frame->rface->average_width;
+  frame->ascent = frame->rface->ascent;
+  frame->descent = frame->rface->descent;
+}
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+/* External API  */
+/*** @addtogroup m17nFace */
+/*** @{ */
+/*=*/
+
+/***en @name Variables: Keys of face property */
+/***ja @name ÊÑ¿ô: ¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼  */
+/*** @{ */
+/*=*/
+
+/***en
+    @brief Key of a face property specifying foreground color.
+
+    The variable #Mforeground is used as a key of face property.  The
+    property value must be a symbol whose name is a color name, or
+    #Mnil.
+
+    #Mnil means that the face does not specify a foreground color.
+    Otherwise, the foreground of an M-text is drawn by the specified
+    color.  */
+/***ja
+    @brief Á°·Ê¿§¤ò»ØÄꤹ¤ë¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¡¼¤Î¥­¡¼.
+
+    ÊÑ¿ô #Mforeground ¤Ï¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
+    ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢¿§Ì¾¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë¤« #Mnil ¤Ç¤¢¤ë¡£
+
+    #Mnil ¤Î¾ì¹ç¡¢Á°·Ê¿§¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð M-text 
+    ¤ÎÁ°·Ê¤Ï»ØÄꤵ¤ì¤¿¿§¤Çɽ¼¨¤µ¤ì¤ë¡£  */
+
+MSymbol Mforeground;
+
+/***en
+    @brief Key of a face property specifying background color.
+
+    The variable #Mbackground is used as a key of face property.  The
+    property value must be a symbol whose name is a color name, or
+    #Mnil.
+
+    #Mnil means that the face does not specify a background color.
+    Otherwise, the background of an M-text is drawn by the specified
+    color.  */
+/***ja
+    @brief ÇØ·Ê¿§¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¡¼¤Î¥­¡¼.
+
+    ÊÑ¿ô #Mbackground ¤Ï¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
+    ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢¿§Ì¾¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë¤« #Mnil ¤Ç¤¢¤ë¡£
+
+    #Mnil ¤Î¾ì¹ç¡¢ÇØ·Ê¿§¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð M-text 
+    ¤ÎÇطʤϻØÄꤵ¤ì¤¿¿§¤Çɽ¼¨¤µ¤ì¤ë¡£  */
+
+MSymbol Mbackground;
+
+/***en
+    @brief Key of a face property specifying video mode.
+
+    The variable #Mvideomode is used as a key of face property.  The
+    property value must be @b Mnormal, @b Mreverse, or #Mnil.
+
+    @b Mnormal means that an M-text is drawn in normal video mode
+    (i.e. the foreground is drawn by foreground color, the background
+    is drawn by background color).
+
+    @b Mreverse means that an M-text is drawn in reverse video mode
+    (i.e. the foreground is drawn by background color, the background
+    is drawn by foreground color).
+
+    #Mnil means that the face does not specify a video mode.  */
+/***ja
+    @brief ¥Ó¥Ç¥ª¥â¡¼¥É¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¡¼¤Î¥­¡¼.
+
+    ÊÑ¿ô #Mvideomode ¤Ï¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢
+    @b Mnormal, @b Mreverse, #Mnil ¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    @b Mnormal ¤Î¾ì¹ç¤Ï¡¢M-text 
+    ¤òɸ½à¤Î¥Ó¥Ç¥ª¥â¡¼¥É¡ÊÁ°·Ê¤òÁ°·Ê¿§¤Ç¡¢ÇطʤòÇØ·Ê¿§¤Ç¡Ë¤Çɽ¼¨¤¹¤ë¡£
+
+    @b Mreverse ¤Î¾ì¹ç¤Ï¥ê¥Ð¡¼¥¹¥Ó¥Ç¥ª¥â¡¼¥É¤Ç¡ÊÁ°·Ê¤òÇØ·Ê¿§¤Ç¡¢ÇطʤòÁ°·Ê¿§¤Ç¡Ëɽ¼¨¤¹¤ë¡£
+
+    #Mnil ¤Î¾ì¹ç¤Ï¥Ó¥Ç¥ª¥â¡¼¥É¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
+    */
+
+MSymbol Mvideomode;
+
+/***en
+    @brief Key of a face property specifying font size ratio.
+
+    The variable #Mratio is used as a key of face property.  The value
+    RATIO must be an integer.
+
+    The value 0 means that the face does not specify a font size
+    ratio.  Otherwise, an M-text is drawn by a font of size (FONTSIZE
+    * RATIO / 100) where FONTSIZE is a font size specified by the face
+    property #Msize.  */
+/***ja
+    @brief ¥Õ¥©¥ó¥È¤Î¥µ¥¤¥º¤ÎÈæΨ¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¡¼¤Î¥­¡¼.
+
+    ÊÑ¿ô #Mratio ¤Ï¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£ÃÍ RATIO 
+    ¤ÏÀ°¿ôÃͤǤʤ¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    Ãͤ¬0¤Ê¤é¤Ð¡¢¥Õ¥©¥ó¥È¥µ¥¤¥º¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢M-text 
+    ¤Ï(FONTSIZE * RATIO / 100) ¤È¤¤¤¦¥µ¥¤¥º¤Î¥Õ¥©¥ó¥È¤Çɽ¼¨¤µ¤ì¤ë¡£
+    FONTSIZE ¤Ï¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¡¼#Msize ¤Ç»ØÄꤵ¤ì¤¿¥µ¥¤¥º¤Ç¤¢¤ë¡£ */
+
+MSymbol Mratio;
+
+/***en
+    @brief Key of a face property specifying horizontal line.
+
+    The variable #Mhline is used as a key of face property.  The value
+    must be a pointer to an object of type #MFaceHLineProp, or @c
+    NULL.
+
+    The value @c NULL means that the face does not specify this
+    property.  Otherwise, an M-text is drawn with a horizontal line by
+    a way specified by the object that the value points to.  */
+/***ja
+    @brief ¿åÊ¿Àþ¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¡¼¤Î¥­¡¼.
+
+    ÊÑ¿ô #Mhline ¤Ï¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£ÃͤϠ
+    #MFaceHLineProp ·¿¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤« @c NULL ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    Ãͤ¬ @c NULL ¤Ê¤é¤Ð¡¢¤³¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤ÐÃͤ¬»Ø¤¹¥ª¥Ö¥¸¥§¥¯¥È¤Ë»ØÄꤵ¤ì¤¿¤è¤¦¤Ë¿åÊ¿Àþ¤òÉղ䷤ƠM-text 
+    ¤òɽ¼¨¤¹¤ë¡£*/
+
+MSymbol Mhline;
+
+/***en
+    @brief Key of a face property specifying box.
+
+    The variable #Mbox is used as a key of face property.  The value
+    must be a pointer to an object of type #MFaceBoxProp, or @c NULL.
+
+    The value @c NULL means that the face does not specify a box.
+    Otherwise, an M-text is drawn with a surrounding box by a way
+    specified by the object that the value points to.  */
+/***ja
+    @brief °Ï¤ßÏȤò»ØÄꤹ¤ë¤¿¤á¤Î¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¡¼¤Î¥­¡¼.
+
+    ÊÑ¿ô #Mbox ¤Ï¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£ÃͤϠ
+    #MFaceBoxProp ·¿¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤« @c NULL ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    Ãͤ¬ @c NULL ¤Ê¤é¤Ð¡¢¤³¤Î¥Õ¥§¡¼¥¹¤Ï°Ï¤ßÏȤò»ØÄꤷ¤Æ¤¤¤Ê¤¤¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤ÐÃͤ¬»Ø¤¹¥ª¥Ö¥¸¥§¥¯¥È¤Ë»ØÄꤵ¤ì¤¿¤è¤¦¤Ë°Ï¤ßÏȤòÉղ䷤Ơ
+    M-text ¤òɽ¼¨¤¹¤ë¡£*/
+
+MSymbol Mbox;
+
+/***en
+    @brief Key of a face property specifying fontset.
+
+    The variable #Mfontset is used as a key of face property.  The
+    value must be a pointer to an object of type #Mfontset, or @c
+    NULL.
+
+    The value @c NULL means that the face does not specify a fontset.
+    Otherwise, an M-text is drawn with a font selected from what
+    specified in the fontset.  */
+/***ja
+    @brief ¥Õ¥©¥ó¥È¥»¥Ã¥È¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¡¼¤Î¥­¡¼.
+
+    ÊÑ¿ô #Mfontset ¤Ï¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£ÃͤϠ
+    #Mfontset ·¿¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤« @c NULL ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    Ãͤ¬ @c NULL ¤Ê¤é¤Ð¡¢¥Õ¥©¥ó¥È¥»¥Ã¥È¤Ï»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤ÐÃͤ¬»Ø¤¹¥ª¥Ö¥¸¥§¥¯¥È¤Ë»ØÄꤵ¤ì¤¿¥Õ¥©¥ó¥È¥»¥Ã¥È¤«¤éÁª¤ó¤À¥Õ¥©¥ó¥È¤Ç 
+    M-text ¤òɽ¼¨¤¹¤ë¡£*/
+    
+MSymbol Mfontset;
+
+/***en
+    @brief Key of a face property specifying hook.
+
+    The variable #Mhook_func is used as a key of face property.  The
+    value must be a function of type #MFaceHookFunc, or @c NULL.
+
+    The value @c NULL means that the face does not specify a hook.
+    Otherwise, the specified function is called before the face is
+    realized.  */
+/***ja
+    @brief ¥Õ¥Ã¥¯¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¡¼¤Î¥­¡¼.
+
+    ÊÑ¿ô #Mhook_func ¤Ï¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£ÃͤϠ
+    #MFaceHookFunc ·¿¤Î´Ø¿ô¤« @c NULL ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    Ãͤ¬ @c NULL ¤Ê¤é¤Ð¡¢¥Õ¥Ã¥¯¤Ï»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¥Õ¥§¡¼¥¹¤ò¼Â¸½¤¹¤ëÁ°¤Ë»ØÄꤵ¤ì¤¿´Ø¿ô¤¬¸Æ¤Ð¤ì¤ë¡£      */
+MSymbol Mhook_func;
+
+/***en
+    @brief Key of a face property specifying argument of hook.
+
+    The variable #Mhook_arg is used as a key of face property.  The
+    value can be anything that is passed a hook function specified by
+    the face property #Mhook_func.  */
+/***ja
+    @brief ¥Õ¥Ã¥¯¤Î°ú¿ô¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¡¼¤Î¥­¡¼.
+
+    ÊÑ¿ô #Mhook_arg ¤Ï¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
+    Ãͤϲ¿¤Ç¤â¤è¤¯¡¢¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£ #Mhook_func ¤Ç»ØÄꤵ¤ì¤ë´Ø¿ô¤ËÅϤµ¤ì¤ë¡£ */
+MSymbol Mhook_arg;
+
+/*** @} */
+/*=*/
+
+/*** @ingroup m17nFace */
+/***en @name Variables: Possible values of #Mvideomode property of face */
+/***ja @name ÊÑ¿ô¡§  ¥Õ¥§¡¼¥¹¤Î #Mvideomode ¥×¥í¥Ñ¥Æ¥£¤Î²Äǽ¤ÊÃÍ */
+/*** @{ */
+
+/***en
+    See the documentation of the variable #Mvideomode.  */ 
+/***ja
+    ÊÑ¿ô #Mvideomode ¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£  */ 
+MSymbol Mnormal;
+MSymbol Mreverse;
+/*** @} */
+/*=*/
+
+/*** @ingroup m17nFace */
+/***en @name Variables: Predefined faces  */
+/***ja @name ÊÑ¿ô: ÄêµÁºÑ¤ß¥Õ¥§¡¼¥¹  */
+/*** @{ */
+/*=*/
+
+/***en
+    @brief Normal video face.
+
+    The variable #mface_normal_video points to a face that has the
+    #Mvideomode property with value @b Mnormal.  The other properties
+    are not specified.  An M-text drawn with this face appear normal
+    colors (i.e. the foreground is drawn by foreground color, and
+    background is drawn by background color).  */
+/***ja
+    @brief É¸½à¥Ó¥Ç¥ª¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_normal_video ¤Ï #Mvideomode ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬ @b Mnormal 
+    ¤Ç¤¢¤ë¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
+    ¤³¤Î¥Õ¥§¡¼¥¹¤Çɽ¼¨¤µ¤ì¤ëM-text 
+    ¤Ïɸ½à¤Î¿§ (¤¹¤Ê¤ï¤ÁÁ°·Ê¤ÏÁ°·Ê¿§¡¢ÇطʤÏÇØ·Ê¿§¡Ë¤ÇÉÁ¤«¤ì¤ë¡£  */
+
+MFace *mface_normal_video;
+
+/***en
+    @brief Reverse video face.
+
+    The variable #mface_reverse_video points to a face that has the
+    #Mvideomode property with value @b Mreverse.  The other properties
+    are not specified.  An M-text drawn with this face appear in
+    reversed colors (i.e. the foreground is drawn by background
+    color, and background is drawn by foreground color).  */
+/***ja
+    @brief ¥ê¥Ð¡¼¥¹¥Ó¥Ç¥ª¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_reverse_video ¤Ï #Mvideomode ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬ 
+    @b Mreverse ¤Ç¤¢¤ë¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
+    ¤³¤Î¥Õ¥§¡¼¥¹¤Çɽ¼¨¤µ¤ì¤ëM-text 
+    ¤ÏÁ°·Ê¿§¤ÈÇØ·Ê¿§¤¬Æþ¤ìÂؤï¤Ã¤Æ (¤¹¤Ê¤ï¤ÁÁ°·Ê¤ÏÇØ·Ê¿§¡¢ÇطʤÏÁ°·Ê¿§¡ËÉÁ¤«¤ì¤ë¡£  */
+
+MFace *mface_reverse_video;
+
+/***en
+    @brief Underline face.
+
+    The variable #mface_underline points to a face that has the
+    #Mhline property with value a pointer to an object of type
+    #MFaceHLineProp.  The members of the object are as follows:
+
+@verbatim
+    member  value
+    -----   -----
+    type    MFACE_HLINE_UNDER
+    width   1
+    color   Mnil
+@endverbatim
+
+    The other properties are not specified.  An M-text that has this
+    face is drawn with an underline.  */ 
+/***ja
+    @brief ²¼Àþ¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_underline ¤Ï #Mhline ¥×¥í¥Ñ¥Æ¥¤¤ÎÃͤ¬ #MFaceHLineProp 
+    ·¿¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£¥ª¥Ö¥¸¥§¥¯¥È¤Î¥á¥ó¥Ð¤Ï°Ê²¼¤ÎÄ̤ꡣ
+
+@verbatim
+    ¥á¥ó¥Ð  ÃÍ
+    -----   -----
+    type    MFACE_HLINE_UNDER
+    width   1
+    color   Mnil
+@endverbatim
+
+    Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text ¤Ï²¼ÀþÉÕ¤­¤Çɽ¼¨¤µ¤ì¤ë¡£*/ 
+
+MFace *mface_underline;
+
+/***en
+    @brief Medium face.
+
+    The variable #mface_medium points to a face that has the #Mweight
+    property with value a symbol of name "medium".  The other
+    properties are not specified.  An M-text that has this face is
+    drawn with a font of medium weight.  */
+/***ja
+    @brief ¥ß¥Ç¥£¥¢¥à¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_medium ¤Ï #Mweight ¥×¥í¥Ñ¥Æ¥¤¤ÎÃͤ¬ "medium" 
+    ¤È¤¤¤¦Ì¾Á°¤ò¤â¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¤è¤¦¤Ê¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text
+    ¤Ï¡¢¥ß¥Ç¥£¥¢¥à¥¦¥§¥¤¥È¤Î¥Õ¥©¥ó¥È¤Çɽ¼¨¤µ¤ì¤ë¡£  */
+MFace *mface_medium;
+
+/***en
+    @brief Bold face.
+
+    The variable #mface_bold points to a face that has the #Mweight
+    property with value a symbol of name "bold".  The other properties
+    are not specified.  An M-text that has this face is drawn with a
+    font of bold weight.  */
+/***ja
+    @brief ¥Ü¡¼¥ë¥É¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_bold ¤Ï #Mweight ¥×¥í¥Ñ¥Æ¥¤¤ÎÃͤ¬ "bold" 
+    ¤È¤¤¤¦Ì¾Á°¤ò¤â¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¤è¤¦¤Ê¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text 
+    ¤Ï¡¢¥Ü¡¼¥ë¥É¥Õ¥©¥ó¥È¤Çɽ¼¨¤µ¤ì¤ë¡£    */
+
+MFace *mface_bold;
+
+/***en
+    @brief Italic face.
+
+    The variable #mface_italic points to a face that has the #Mstyle
+    property with value a symbol of name "italic".  The other
+    properties are not specified.  An M-text that has this face is
+    drawn with a font of italic style.  */
+/***ja
+    @brief ¥¤¥¿¥ê¥Ã¥¯¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_italic ¤Ï #Mstyle ¥×¥í¥Ñ¥Æ¥¤¤ÎÃͤ¬ "italic" 
+    ¤È¤¤¤¦Ì¾Á°¤ò¤â¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¤è¤¦¤Ê¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text
+    ¤Ï¡¢¥¤¥¿¥ê¥Ã¥¯ÂΤÇɽ¼¨¤µ¤ì¤ë¡£    */
+
+MFace *mface_italic;
+
+/***en
+    @brief Bold italic face.
+
+    The variable #mface_bold_italic points to a face that has the
+    #Mweight property with value a symbol of name "bold", and #Mstyle
+    property with value a symbol of name "italic".  The other
+    properties are not specified.  An M-text that has this face is
+    drawn with a font of bold weight and italic style.  */
+/***ja
+    @brief ¥Ü¡¼¥ë¥É¥¤¥¿¥ê¥Ã¥¯¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_bold_italic ¤Ï¡¢#Mweight ¥×¥í¥Ñ¥Æ¥¤¤ÎÃͤ¬ "bold" 
+    ¤È¤¤¤¦Ì¾Á°¤ò¤â¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢¤«¤Ä #Mstyle ¥×¥í¥Ñ¥Æ¥¤¤ÎÃͤ¬ "italic" 
+    ¤È¤¤¤¦Ì¾Á°¤ò¤â¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¤è¤¦¤Ê¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text 
+    ¤Ï¡¢¥Ü¡¼¥ë¥É¥¤¥¿¥ê¥Ã¥¯ÂΤÇɽ¼¨¤µ¤ì¤ë¡£    */
+
+MFace *mface_bold_italic;
+
+/***en
+    @brief Smallest face.
+
+    The variable #mface_xx_small points to a face that has the #Mratio
+    property with value 50.  The other properties are not specified.
+    An M-text that has this face is drawn with a font whose size is
+    50% of a normal font.  */
+/***ja
+    @brief ºÇ¾®¤Î¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_xx_small ¤Ï¡¢#Mratio ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬ 50 
+    ¤Ç¤¢¤ë¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
+    ¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text ¤Ïɸ½à¥Õ¥©¥ó¥È¤Î 50% ¤ÎÂ礭¤µ¤Î¥Õ¥©¥ó¥È¤òÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£
+     */
+
+MFace *mface_xx_small;
+
+/***en
+    @brief Smaller face.
+
+    The variable #mface_x_small points to a face that has the #Mratio
+    property with value 66.  The other properties are not specified.
+    An M-text that has this face is drawn with a font whose size is
+    66% of a normal font.  */
+/***ja
+    @brief ¤è¤ê¾®¤µ¤¤¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_x_small ¤Ï¡¢#Mratio ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬ 66 
+    ¤Ç¤¢¤ë¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
+    ¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text ¤Ïɸ½à¥Õ¥©¥ó¥È¤Î 66% ¤ÎÂ礭¤µ¤Î¥Õ¥©¥ó¥È¤òÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£
+     */
+
+MFace *mface_x_small;
+
+/***en
+    @brief Small face.
+
+    The variable #mface_x_small points to a face that has the #Mratio
+    property with value 75.  The other properties are not specified.
+    An M-text that has this face is drawn with a font whose size is
+    75% of a normal font.  */
+/***ja
+    @brief ¾®¤µ¤¤¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_small ¤Ï¡¢#Mratio ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬ 75 
+    ¤Ç¤¢¤ë¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
+    ¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text ¤Ïɸ½à¥Õ¥©¥ó¥È¤Î 75% ¤ÎÂ礭¤µ¤Î¥Õ¥©¥ó¥È¤òÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£
+     */
+
+MFace *mface_small;
+
+/***en
+    @brief Normalsize face.
+
+    The variable #mface_normalsize points to a face that has the
+    #Mratio property with value 100.  The other properties are not
+    specified.  An M-text that has this face is drawn with a font
+    whose size is the same as a normal font.  */
+/***ja
+    @brief É¸½à¤ÎÂ礭¤µ¤Î¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_normalsize ¤Ï¡¢#Mratio ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬ 100 
+    ¤Ç¤¢¤ë¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
+    ¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text ¤Ïɸ½à¥Õ¥©¥ó¥È¤ÈƱ¤¸Â礭¤µ¤Î¥Õ¥©¥ó¥È¤òÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£
+     */
+
+MFace *mface_normalsize;
+
+/***en
+    @brief Large face.
+
+    The variable #mface_large points to a face that has the #Mratio
+    property with value 120.  The other properties are not specified.
+    An M-text that has this face is drawn with a font whose size is
+    120% of a normal font.  */
+/***ja
+    @brief Â礭¤¤¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_large ¤Ï¡¢#Mratio ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬ 120 
+    ¤Ç¤¢¤ë¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
+    ¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text ¤Ïɸ½à¥Õ¥©¥ó¥È¤Î 120% ¤ÎÂ礭¤µ¤Î¥Õ¥©¥ó¥È¤òÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£
+     */
+
+MFace *mface_large;
+
+/***en
+    @brief Larger face.
+
+    The variable #mface_x_large points to a face that has the #Mratio
+    property with value 150.  The other properties are not specified.
+    An M-text that has this face is drawn with a font whose size is
+    150% of a normal font.  */
+/***ja
+    @brief ¤â¤Ã¤ÈÂ礭¤¤¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_x_large ¤Ï¡¢#Mratio ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬ 150 
+    ¤Ç¤¢¤ë¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
+    ¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text ¤Ïɸ½à¥Õ¥©¥ó¥È¤Î 150% ¤ÎÂ礭¤µ¤Î¥Õ¥©¥ó¥È¤òÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£
+     */
+
+MFace *mface_x_large;
+
+/***en
+    @brief Largest face.
+
+    The variable #mface_xx_large points to a face that has the #Mratio
+    property with value 200.  The other properties are not specified.
+    An M-text that has this face is drawn with a font whose size is
+    200% of a normal font.  */
+/***ja
+    @brief ºÇÂç¤Î¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_xx_large ¤Ï¡¢#Mratio ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬ 200 
+    ¤Ç¤¢¤ë¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
+    ¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text ¤Ïɸ½à¥Õ¥©¥ó¥È¤Î 200% ¤ÎÂ礭¤µ¤Î¥Õ¥©¥ó¥È¤òÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£
+     */
+
+MFace *mface_xx_large;
+
+/***en
+    @brief Black face.
+
+    The variable #mface_black points to a face that has the
+    #Mforeground property with value a symbol of name "black".  The
+    other properties are not specified.  An M-text that has this face
+    is drawn with black foreground.  */
+/***ja 
+    @brief ¹õ¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_black ¤Ï¡¢#Mforeground ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤȤ·¤Æ "black" 
+    ¤È¤¤¤¦Ì¾Á°¤Î¥·¥ó¥Ü¥ë¤ò»ý¤Ä¤è¤¦¤Ê¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text 
+    ¤ÏÁ°·Ê¿§¤È¤·¤Æ¹õ¤òÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£     */
+
+MFace *mface_black;
+
+/***en
+    @brief White face.
+
+    The variable #mface_white points to a face that has the
+    #Mforeground property with value a symbol of name "white".  The
+    other properties are not specified.  An M-text that has this face
+    is drawn with white foreground.  */
+/***ja
+    @brief Çò¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_white ¤Ï¡¢#Mforeground ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤȤ·¤Æ "white" 
+    ¤È¤¤¤¦Ì¾Á°¤Î¥·¥ó¥Ü¥ë¤ò»ý¤Ä¤è¤¦¤Ê¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text 
+    ¤ÏÁ°·Ê¿§¤È¤·¤ÆÇò¤òÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£     */
+
+MFace *mface_white;
+
+/***en
+    @brief Red face.
+
+    The variable #mface_red points to a face that has the
+    #Mforeground property with value a symbol of name "red".  The
+    other properties are not specified.  An M-text that has this face
+    is drawn with red foreground.  */
+/***ja
+    @brief ÀÖ¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_red ¤Ï¡¢#Mforeground ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤȤ·¤Æ "red" 
+    ¤È¤¤¤¦Ì¾Á°¤Î¥·¥ó¥Ü¥ë¤ò»ý¤Ä¤è¤¦¤Ê¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text 
+    ¤ÏÁ°·Ê¿§¤È¤·¤ÆÀÖ¤òÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£  */
+
+MFace *mface_red;
+
+/***en
+    @brief Green face.
+
+    The variable #mface_green points to a face that has the
+    #Mforeground property with value a symbol of name "green".  The
+    other properties are not specified.  An M-text that has this face
+    is drawn with green foreground.  */
+/***ja
+    @brief ÎÐ¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_green ¤Ï¡¢#Mforeground ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤȤ·¤Æ "green" 
+    ¤È¤¤¤¦Ì¾Á°¤Î¥·¥ó¥Ü¥ë¤ò»ý¤Ä¤è¤¦¤Ê¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text 
+    ¤ÏÁ°·Ê¿§¤È¤·¤ÆÎФòÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£  */
+
+MFace *mface_green;
+
+/***en
+    @brief Blue face.
+
+    The variable #mface_blue points to a face that has the
+    #Mforeground property with value a symbol of name "blue".  The
+    other properties are not specified.  An M-text that has this face
+    is drawn with blue foreground.  */
+/***ja
+    @brief ÀÄ¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_blue ¤Ï¡¢#Mforeground ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤȤ·¤Æ "blue" 
+    ¤È¤¤¤¦Ì¾Á°¤Î¥·¥ó¥Ü¥ë¤ò»ý¤Ä¤è¤¦¤Ê¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text 
+    ¤ÏÁ°·Ê¿§¤È¤·¤ÆÀĤòÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£  */
+
+MFace *mface_blue;
+
+/***en
+    @brief Cyan face.
+
+    The variable #mface_cyan points to a face that has the
+    #Mforeground property with value a symbol of name "cyan".  The
+    other properties are not specified.  An M-text that has this face
+    is drawn with cyan foreground.  */
+/***ja
+    @brief ¥·¥¢¥ó¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_cyan ¤Ï¡¢#Mforeground ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤȤ·¤Æ "cyan"
+    ¤È¤¤¤¦Ì¾Á°¤Î¥·¥ó¥Ü¥ë¤ò»ý¤Ä¤è¤¦¤Ê¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text 
+    ¤ÏÁ°·Ê¿§¤È¤·¤Æ¥·¥¢¥ó¤òÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£  */
+
+MFace *mface_cyan;
+
+/***en
+    @brief yellow face.
+
+    The variable #mface_yellow points to a face that has the
+    #Mforeground property with value a symbol of name "yellow".  The
+    other properties are not specified.  An M-text that has this face
+    is drawn with yellow foreground.  */
+
+/***ja
+    @brief ²«¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_yellow ¤Ï¡¢#Mforeground ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤȤ·¤Æ "yellow" 
+    ¤È¤¤¤¦Ì¾Á°¤Î¥·¥ó¥Ü¥ë¤ò»ý¤Ä¤è¤¦¤Ê¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text 
+    ¤ÏÁ°·Ê¿§¤È¤·¤Æ²«¿§¤òÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£  */
+
+MFace *mface_yellow;
+
+/***en
+    @brief Magenta face.
+
+    The variable #mface_magenta points to a face that has the
+    #Mforeground property with value a symbol of name "magenta".  The
+    other properties are not specified.  An M-text that has this face
+    is drawn with magenta foreground.  */
+
+/***ja
+    @brief ¥Þ¥¼¥ó¥¿¥Õ¥§¡¼¥¹.
+
+    ÊÑ¿ô #mface_magenta ¤Ï¡¢#Mforeground ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤȤ·¤Æ 
+    "magenta" ¤È¤¤¤¦Ì¾Á°¤Î¥·¥ó¥Ü¥ë¤ò»ý¤Ä¤è¤¦¤Ê¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£¤³¤Î¥Õ¥§¡¼¥¹¤ò»ý¤Ä M-text 
+    ¤ÏÁ°·Ê¿§¤È¤·¤Æ¥Þ¥¼¥ó¥¿¤òÍѤ¤¤Æɽ¼¨¤µ¤ì¤ë¡£  */
+
+MFace *mface_magenta;
+
+/*** @} */
+/*=*/
+
+/***en @name Variables: The other symbols for face handling.  */
+/***ja @name ÊÑ¿ô: ¥Õ¥§¡¼¥¹¤ò¼è¤ê°·¤¦¤¿¤á¤Î¤½¤Î¾¤Î¥·¥ó¥Ü¥ë  */
+/*** @{ */
+/*=*/
+
+/***en
+    @brief Key of a text property specifying a face.
+
+    The variable #Mface is a symbol of name <tt>"face"</tt>.  A text
+    property whose key is this symbol must have a pointer to an object
+    of type #MFace.  This is a managing key.  */
+
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¤ò»ØÄꤹ¤ë¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼.
+
+    ÊÑ¿ô #Mface ¤Ï <tt>"face"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£¤³¤Î¥·¥ó¥Ü¥ë¤ò¥­¡¼¤È¤¹¤ë¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¡¢
+    #MFace ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò»ý¤¿¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
+    ¤³¤ì¤Ï´ÉÍý¥­¡¼¤Ç¤¢¤ë¡£  */
+
+MSymbol Mface;
+/*=*/
+/*** @} */
+/*=*/
+
+/***en
+    @brief Create a new face.
+
+    The mface () function creates a new face object that specifies no
+    property.
+
+    @return
+    This function returns a pointer to the created face.  */
+
+/***ja
+    @brief ¿·¤·¤¤¥Õ¥§¡¼¥¹¤ò¤Ä¤¯¤ë.
+
+    ´Ø¿ô mface () 
+    ¤Ï¥×¥í¥Ñ¥Æ¥£¤ò°ìÀÚ»ý¤¿¤Ê¤¤¿·¤·¤¤¥Õ¥§¡¼¥¹¥ª¥Ö¥¸¥§¥¯¥È¤òºî¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ïºî¤Ã¤¿¥Õ¥§¡¼¥¹¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£  */
+
+MFace *
+mface ()
+{
+  MFace *face;
+
+  M17N_OBJECT (face, free_face, MERROR_FACE);
+  face->frame_list = mplist ();
+  M17N_OBJECT_REGISTER (face_table, face);
+  return face;
+}
+
+/*=*/
+
+/***en
+    @brief Make a copy of a face.
+
+    The mface_copy () function makes a copy of $FACE and returns a
+    pointer to the created copy.  */
+
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¤Î¥³¥Ô¡¼¤òºî¤ë.
+
+    ´Ø¿ô mface_copy () ¤Ï¥Õ¥§¡¼¥¹ $FACE 
+    ¤Î¥³¥Ô¡¼¤òºî¤ê¡¢¤½¤Î¥³¥Ô¡¼¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£  */
+
+MFace *
+mface_copy (MFace *face)
+{
+  MFace *copy;
+
+  MSTRUCT_CALLOC (copy, MERROR_FACE);
+  *copy = *face;
+  copy->control.ref_count = 1;
+  M17N_OBJECT_REGISTER (face_table, copy);
+  copy->frame_list = mplist ();
+  if (copy->property[MFACE_FONTSET])
+    M17N_OBJECT_REF (copy->property[MFACE_FONTSET]);
+  return copy;
+}
+
+/*=*/
+/***en
+    @brief Compare faces.
+
+    The mface_equal () function compares faces $FACE1 and $FACE2.
+
+    @return
+    If two faces have the same property values, return 1.
+    Otherwise return 0.  */
+
+int
+mface_equal (MFace *face1, MFace *face2)
+{
+  MFaceHLineProp *hline1, *hline2;
+  MFaceBoxProp *box1, *box2;
+  int i;
+
+  if (face1 == face2)
+    return 1;
+  if (memcmp (face1->property, face2->property, sizeof face1->property) == 0)
+    return 1;
+  for (i = MFACE_FOUNDRY; i <= MFACE_BACKGROUND; i++)
+    if (face1->property[i] != face2->property[i])
+      return 0;
+  for (i = MFACE_VIDEOMODE; i <= MFACE_RATIO; i++)
+    if (face1->property[i] != face2->property[i])
+      return 0;
+  hline1 = (MFaceHLineProp *) face1->property[MFACE_HLINE];
+  hline2 = (MFaceHLineProp *) face2->property[MFACE_HLINE];
+  if (hline1 != hline2)
+    {
+      if (! hline1 || ! hline2)
+       return 0;
+      if (memcmp (hline1, hline2, sizeof (MFaceHLineProp)) != 0)
+       return 0;
+    }
+  box1 = (MFaceBoxProp *) face1->property[MFACE_BOX];
+  box2 = (MFaceBoxProp *) face2->property[MFACE_BOX];
+  if (box1 != box2)
+    {
+      if (! box1 || ! box2)
+       return 0;
+      if (memcmp (box1, box2, sizeof (MFaceBoxProp)) != 0)
+       return 0;
+    }
+  return 1;
+}
+
+
+/*=*/
+/***en
+    @brief Merge faces.
+
+    The mface_merge () functions merges the properties of face $SRC
+    into $DST.
+
+    @return
+    This function returns $DST.  */
+
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¤òÅý¹ç¤¹¤ë.
+
+    ´Ø¿ô mface_merge () ¤Ï¡¢¥Õ¥§¡¼¥¹ $SRC ¤Î¥×¥í¥Ñ¥Æ¥£¤ò¥Õ¥§¡¼¥¹ $DST 
+    ¤ËÅý¹ç¤¹¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï $DST ¤òÊÖ¤¹¡£  */
+
+MFace *
+mface_merge (MFace *dst, MFace *src)
+{
+  int i;
+  MPlist *plist;
+
+  for (i = 0; i < MFACE_PROPERTY_MAX; i++)
+    if (src->property[i])
+      {
+       if (i == MFACE_FONTSET)
+         {
+           M17N_OBJECT_UNREF (dst->property[i]);
+           M17N_OBJECT_REF (src->property[i]);
+         }
+       dst->property[i] = src->property[i];
+      }
+
+  MPLIST_DO (plist, dst->frame_list)
+    {
+      MFrame *frame = MPLIST_VAL (plist);
+
+      frame->tick++;
+      if (dst == frame->face)
+       mface__update_frame_face (frame);
+    }
+
+  return dst;
+}
+
+/*=*/
+
+/***en
+    @brief Make a face from a font.
+
+    The mface_from_font () function return a newly created face while
+    reflecting the properties of $FONT in its properties.   */
+
+/***ja
+    @brief ¥Õ¥©¥ó¥È¤«¤é¥Õ¥§¡¼¥¹¤òºî¤ë.
+
+    ´Ø¿ô mface_from_font () ¤Ï¥Õ¥©¥ó¥È $FONT 
+    ¤Î¥×¥í¥Ñ¥Æ¥£¤ò¥×¥í¥Ñ¥Æ¥£¤È¤·¤Æ»ý¤Ä¿·¤·¤¤¥Õ¥§¡¼¥¹¤òºî¤ê¡¢¤½¤ì¤òÊÖ¤¹¡£  */
+
+MFace *
+mface_from_font (MFont *font)
+{
+  MFace *face = mface ();
+
+  face->property[MFACE_FOUNDRY] = mfont_get_prop (font, Mfoundry);
+  face->property[MFACE_FAMILY] = mfont_get_prop (font, Mfamily);
+  face->property[MFACE_WEIGHT] = mfont_get_prop (font, Mweight);
+  face->property[MFACE_STYLE] = mfont_get_prop (font, Mstyle);
+  face->property[MFACE_STRETCH] = mfont_get_prop (font, Mstretch);
+  face->property[MFACE_ADSTYLE] = mfont_get_prop (font, Madstyle);
+  face->property[MFACE_SIZE] = mfont_get_prop (font, Msize);
+  return face;
+}
+
+/*=*/
+
+/***en
+    @brief Get the value of a face property.
+
+    The mface_get_prop () function returns the value of the face
+    property whose key is $KEY in face $FACE.  $KEY must be one of the
+    followings:
+
+        #Mforeground, #Mbackground, #Mvideomode, #Mhline, #Mbox,
+        #Mfoundry, #Mfamily, #Mweight, #Mstyle, #Mstretch, #Madstyle,
+        #Msize, #Mfontset, #Mratio, #Mhook_func, #Mhook_arg
+
+    @return
+    The actual type of the returned value depends of $KEY.  See
+    documentation of the above keys.  If an error is detected, it
+    returns @c NULL and assigns an error code to the external variable
+    #merror_code.  */
+
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë.
+
+    ´Ø¿ô mface_get_prop () ¤Ï¡¢¥Õ¥§¡¼¥¹ $FACE 
+    ¤¬»ý¤Ä¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤ÎÆâ¡¢¥­¡¼¤¬ $KEY ¤Ç¤¢¤ë¤â¤Î¤ÎÃͤòÊÖ¤¹¡£
+    $KEY ¤Ï²¼µ­¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
+
+        #Mforeground, #Mbackground, #Mvideomode, #Mhline, #Mbox,
+        #Mfoundry, #Mfamily, #Mweight, #Mstyle, #Mstretch, #Madstyle,
+        #Msize, #Mfontset, #Mratio, #Mhook_arg
+
+    @return 
+    Ìá¤êÃͤη¿¤Ï $KEY ¤Ë°Í¸¤¹¤ë¡£¾åµ­¤Î¥­¡¼¤ÎÀâÌÀ¤ò»²¾È¤¹¤ë¤³¤È¡£
+    ¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code 
+    ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @seealso
+    mface_put_prop (), mface_put_hook ()
+
+    @errors
+    @c MERROR_FACE  */
+
+void *
+mface_get_prop (MFace *face, MSymbol key)
+{
+  int index = (int) msymbol_get (key, M_face_prop_index) - 1;
+
+  if (index < 0)
+    {
+      if (key == Mhook_func)
+       /* This unsafe code is for backward compatiblity.  */
+       return (void *) face->hook;
+      MERROR (MERROR_FACE, NULL);
+    }
+  return face->property[index];
+}
+
+/*=*/
+
+/***en
+    @brief Get the hook function of a face.
+
+    The mface_get_hook () function returns the hook function of face
+    $FACE.  */
+
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¤Î¥Õ¥Ã¥¯´Ø¿ô¤òÆÀ¤ë.
+
+    ´Ø¿ô mface_get_hook () ¤Ï¥Õ¥§¡¼¥¹ $FACE ¤Î¥Õ¥Ã¥¯´Ø¿ô¤òÊÖ¤¹¡£ */
+
+MFaceHookFunc
+mface_get_hook (MFace *face)
+{
+  return face->hook;
+}
+
+/*=*/
+
+/***en
+    @brief Set a value of a face property.
+
+    The mface_put_prop () function assigns $VAL to the property whose
+    key is $KEY in face $FACE.  $KEY must be one the followings:
+
+        #Mforeground, #Mbackground, #Mvideomode, #Mhline, #Mbox,
+        #Mfoundry, #Mfamily, #Mweight, #Mstyle, #Mstretch, #Madstyle,
+        #Msize, #Mfontset, #Mratio, #Mhook_func, #Mhook_arg
+
+    Among them, font related properties (#Mfoundry through #Msize) are
+    used as the default values when a font in the fontset of $FACE
+    does not specify those values.
+
+    The actual type of the returned value depends of $KEY.  See
+    documentation of the above keys.
+
+    @return
+    If the operation was successful, mface_put_prop () returns 0.
+    Otherwise it returns -1 and assigns an error code to the external
+    variable #merror_code.  */
+
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÀßÄꤹ¤ë.
+
+    ´Ø¿ô mface_put_prop () ¤Ï¡¢¥Õ¥§¡¼¥¹ $FACE Æâ¤Ç¥­¡¼¤¬ $KEY 
+    ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ÎÃͤò $VAL ¤ËÀßÄꤹ¤ë¡£$KEY 
+    ¤Ï°Ê²¼¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+        #Mforeground, #Mbackground, #Mvideomode, #Mhline, #Mbox,
+        #Mfoundry, #Mfamily, #Mweight, #Mstyle, #Mstretch, #Madstyle,
+        #Msize, #Mfontset, #Mratio, #Mhook_func, #Mhook_arg.
+
+    ¤³¤ì¤é¤Î¤¦¤Á¤Î¡¢¥Õ¥©¥ó¥È´ØÏ¢¤Î¥×¥í¥Ñ¥Æ¥£ (#Mfamily ¤«¤é #Msize 
+    ¤Þ¤Ç) ¤Ï¡¢¥Õ¥§¡¼¥¹¤Î¥Õ¥©¥ó¥È¥»¥Ã¥ÈÃæ¤Î¥Õ¥©¥ó¥È¤Ë´Ø¤¹¤ë¥Ç¥Õ¥©¥ë¥ÈÃͤȤʤꡢ¸Ä¡¹¤Î¥Õ¥©¥ó¥È¤¬Ãͤò»ØÄꤷ¤Ê¤«¤Ã¤¿¾ì¹ç¤ËÍѤ¤¤é¤ì¤ë¡£
+
+    Ìá¤êÃͤη¿¤Ï $KEY ¤Ë°Í¸¤¹¤ë¡£¾åµ­¤Î¥­¡¼¤ÎÀâÌÀ¤ò»²¾È¤¹¤ë¤³¤È¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤·¤¿¾ì¹ç¡¢mface_put_prop () ¤Ï 0 ¤òÊÖ¤¹¡£¼ºÇÔ¤·¤¿¾ì¹ç¤Ï 
+    -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @seealso
+    mface_get_prop ()
+
+    @errors
+    @c MERROR_FACE  */
+
+int
+mface_put_prop (MFace *face, MSymbol key, void *val)
+{
+  int index = (int) msymbol_get (key, M_face_prop_index) - 1;
+  MPlist *plist;
+
+  if (key == Mhook_func)
+    {
+      /* This unsafe code is for backward compatiblity.  */
+      if (face->hook == (MFaceHookFunc) val)
+       return 0;
+      face->hook = (MFaceHookFunc) val;
+    }
+  else
+    {
+      if (index < 0)
+       MERROR (MERROR_FACE, -1);
+      if (key == Mfontset)
+       {
+         if (face->property[index])
+           M17N_OBJECT_UNREF (face->property[index]);
+         M17N_OBJECT_REF (val);
+       }
+      else if (key == Mhline)
+       val = get_hline_create (val);
+      else if (key == Mbox)
+       val = get_box_create (val);
+
+      if (face->property[index] == val)
+       return 0;
+      face->property[index] = val;
+    }
+
+  MPLIST_DO (plist, face->frame_list)
+    {
+      MFrame *frame = MPLIST_VAL (plist);
+
+      frame->tick++;
+      if (face == frame->face)
+       mface__update_frame_face (frame);
+    }
+
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Set a hook function to a face.
+
+    The mface_set_hook () function sets the hook function of face
+    $FACE to $FUNC.  */
+
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¤Î¥Õ¥Ã¥¯´Ø¿ô¤òÀßÄꤹ¤ë.
+
+    ´Ø¿ô mface_set_hook () ¤Ï¡¢¥Õ¥§¡¼¥¹ $FACE ¤Î¥Õ¥Ã¥¯´Ø¿ô¤ò$FUNC ¤ËÀß
+    Äꤹ¤ë¡£  */
+
+int
+mface_put_hook (MFace *face, MFaceHookFunc func)
+{
+  if (face->hook != func)
+    {
+      MPlist *plist;
+      face->hook = func;
+
+      MPLIST_DO (plist, face->frame_list)
+       {
+         MFrame *frame = MPLIST_VAL (plist);
+
+         frame->tick++;
+         if (face == frame->face)
+           mface__update_frame_face (frame);
+       }
+    }
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Update a face.
+
+    The mface_update () function update face $FACE on frame $FRAME by
+    calling a hook function of $FACE (if any).  */
+
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¤ò¹¹¿·¤¹¤ë.
+
+    ´Ø¿ô mface_update () ¤Ï¥Õ¥ì¡¼¥à $FRAME ¤Î¥Õ¥§¡¼¥¹ $FACE ¤ò $FACE 
+    ¤Î¥Õ¥Ã¥¯´Ø¿ô¤ò¡Ê¤¢¤ì¤Ð¡Ë¸Æ¤ó¤Ç¹¹¿·¤¹¤ë¡£  */
+
+void
+mface_update (MFrame *frame, MFace *face)
+{
+  MFaceHookFunc func = face->hook;
+  MPlist *rface_list;
+  MRealizedFace *rface;
+
+  if (func && func != noop_hook)
+    {
+      MPLIST_DO (rface_list, frame->realized_face_list)
+       {
+         rface = MPLIST_VAL (rface_list);
+         if (rface->face.hook == func)
+           (func) (&(rface->face), rface->face.property[MFACE_HOOK_ARG],
+                   rface->info);
+       }
+    }
+}
+/*=*/
+
+/*** @} */
+/*=*/
+
+/*** @addtogroup m17nDebug */
+/*** @{  */
+/*=*/
+
+/***en
+    @brief Dump a face.
+
+    The mdebug_dump_face () function prints face $FACE in a human readable
+    way to the stderr.  $INDENT specifies how many columns to indent
+    the lines but the first one.
+
+    @return
+    This function returns $FACE.  */
+
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¤ò¥À¥ó¥×¤¹¤ë.
+
+    ´Ø¿ô mdebug_dump_face () ¤Ï¥Õ¥§¡¼¥¹ $FACE ¤ò stderr 
+    ¤Ë¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç°õºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï $FACE ¤òÊÖ¤¹¡£  */
+
+MFace *
+mdebug_dump_face (MFace *face, int indent)
+{
+  char *prefix = (char *) alloca (indent + 1);
+  MFont spec;
+
+  memset (prefix, 32, indent);
+  prefix[indent] = 0;
+  mfont__set_spec_from_face (&spec, face);
+  fprintf (stderr, "(face font:\"");
+  mdebug_dump_font (&spec);
+  fprintf (stderr, "\"\n %s  fore:%s back:%s", prefix,
+          msymbol_name ((MSymbol) face->property[MFACE_FOREGROUND]),
+          msymbol_name ((MSymbol) face->property[MFACE_BACKGROUND]));
+  if (face->property[MFACE_FONTSET])
+    fprintf (stderr, " non-default-fontset");
+  fprintf (stderr, " hline:%s", face->property[MFACE_HLINE] ? "yes" : "no");
+  fprintf (stderr, " box:%s)", face->property[MFACE_BOX] ? "yes" : "no");
+  return face;
+}
+
+/*** @} */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/face.h b/src/face.h
new file mode 100644 (file)
index 0000000..31e326c
--- /dev/null
@@ -0,0 +1,131 @@
+/* face.h -- header file for the face module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_FACE_H_
+#define _M17N_FACE_H_
+
+enum MFaceProperty
+  {
+    /** The font related properties.  */
+    /* The order of MFACE_FOUNDRY to MFACE_ADSTYLE must be the same as
+       MFONT_FOUNDRY to MFONT_ADSTYLE of enum MFontProperty.  */
+    MFACE_FOUNDRY,
+    MFACE_FAMILY,
+    MFACE_WEIGHT,
+    MFACE_STYLE,
+    MFACE_STRETCH,
+    MFACE_ADSTYLE,
+    MFACE_SIZE,
+    MFACE_FONTSET,
+
+    /** The color related properties.   */
+    MFACE_FOREGROUND,
+    MFACE_BACKGROUND,
+
+    /** The other properties.   */
+    MFACE_HLINE,
+    MFACE_BOX,
+    MFACE_VIDEOMODE,
+
+    /* In a realized face, this is ignored because it is already
+       reflected in MFACE_SIZE.  */
+    MFACE_RATIO,
+
+    MFACE_HOOK_ARG,
+
+    MFACE_PROPERTY_MAX
+  };
+
+struct MFace
+{
+  M17NObject control;
+
+  /** Properties of the face.  */
+  void *property[MFACE_PROPERTY_MAX];
+
+  MFaceHookFunc hook;
+
+  /** List of frames affected by the face modification.  */
+  MPlist *frame_list;
+};
+
+
+/** A realized face is registered in MFrame->face_list, thus it does
+    not have to be a managed object.  */
+
+struct MRealizedFace
+{
+  /** Frame on which this realized face is created.  */
+  MFrame *frame;
+
+  /** Properties of all stacked faces are merged into here.  */
+  MFace face;
+
+  /** Font explicitly specified for the face (maybe NULL).  */
+  MFont *font;
+
+  /** From what faces this is realized.  Keys are Mface and values are
+     (MFace *).  */
+  MPlist *base_face_list;
+
+  /* Realized font, one of <frame>->realized_font_list.  */
+  MRealizedFont *rfont;
+
+  /* Realized fontset, one of <frame>->realized_fontset_list.  */
+  MRealizedFontset *rfontset;
+
+  MSymbol layouter;
+
+  MFaceHLineProp *hline;
+
+  MFaceBoxProp *box;
+
+  /** Realized face for ASCII chars that has the same face
+      properties. */
+  MRealizedFace *ascii_rface;
+
+  /** List of realized faces that have the same face properties.  */
+  MPlist *non_ascii_list;
+
+  int ascent, descent;
+  int space_width;
+  int average_width;
+
+  /** Pointer to a window system dependent object.  */
+  void *info;
+};
+
+
+extern MFace *mface__default;
+
+extern MRealizedFace *mface__realize (MFrame *frame, MFace **faces, int num,
+                                     int limitted_size, MFont *font);
+
+extern MGlyph *mface__for_chars (MSymbol script, MSymbol language,
+                                MSymbol charset, MGlyph *from_g, MGlyph *to_g,
+                                int size);
+
+extern void mface__free_realized (MRealizedFace *rface);
+
+extern void mface__update_frame_face (MFrame *frame);
+
+#endif /* _M17N_FACE_H_ */
diff --git a/src/font-ft.c b/src/font-ft.c
new file mode 100644 (file)
index 0000000..47fe1fa
--- /dev/null
@@ -0,0 +1,2864 @@
+/* font-ft.c -- FreeType interface sub-module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <ctype.h>
+
+#include "m17n-gui.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "plist.h"
+#include "symbol.h"
+#include "language.h"
+#include "internal-flt.h"
+#include "internal-gui.h"
+#include "font.h"
+#include "face.h"
+
+#ifdef HAVE_FREETYPE
+
+#ifdef HAVE_FTBDF_H
+#include FT_BDF_H
+#endif
+
+static int mdebug_flag = MDEBUG_FONT;
+
+#ifdef HAVE_FONTCONFIG
+#include <fontconfig/fcfreetype.h>
+
+static FcConfig *fc_config;
+static MSymbol Mgeneric_family;
+#endif /* HAVE_FONTCONFIG */
+
+/* Font properties; Mnormal is already defined in face.c.  */
+static MSymbol Mmedium, Mr, Mnull;
+
+static MSymbol M0[5], M3_1, M1_0;
+
+static FT_Library ft_library;
+
+#ifdef HAVE_OTF
+static OTF *invalid_otf = (OTF *) "";
+#endif /* HAVE_OTF */
+
+typedef struct
+{
+  MFont font;
+#ifdef HAVE_OTF
+  /* NULL if not yet opened.  invalid_otf if not OTF.  */
+  OTF *otf;
+#endif /* HAVE_OTF */
+#ifdef HAVE_FONTCONFIG
+  FcLangSet *langset;
+  FcCharSet *charset;
+#endif /* HAVE_FONTCONFIG */
+} MFontFT;
+
+typedef struct
+{
+  M17NObject control;
+  FT_Face ft_face;             /* This must be the 2nd member. */
+  MPlist *charmap_list;
+  int face_encapsulated;
+} MRealizedFontFT;
+
+typedef struct
+{
+  char *ft_style;
+  int len;
+  enum MFontProperty prop;
+  char *val;
+} MFTtoProp;
+
+static MFTtoProp ft_to_prop[] =
+  { { "italic", 0, MFONT_STYLE, "i" },
+    { "roman", 0, MFONT_STYLE, "r" },
+    { "oblique", 0, MFONT_STYLE, "o" },
+    { "regular", 0, MFONT_WEIGHT, "normal" },
+    { "normal", 0, MFONT_WEIGHT, "normal" },
+    /* We need this entry even if "bold" is in commone_weight[] to
+       handle such style names as "bolditalic" and "boldoblique".  */
+    { "bold", 0, MFONT_WEIGHT, "bold" },
+    { "demi bold", 0, MFONT_WEIGHT, "demibold" },
+    { "demi", 0, MFONT_WEIGHT, "demibold" } };
+static int ft_to_prop_size = sizeof ft_to_prop / sizeof ft_to_prop[0];
+
+/** List of FreeType fonts.  Keys are family names, values are plists
+    containing fonts of the corresponding family.  In the deeper
+    plist, keys are file names, values are (MFontFT *).  */
+static MPlist *ft_font_list;
+
+/** List of FreeType fonts.  Keys are script names, values are plists
+    containing fonts supporting the corresponding script.  In the
+    deeper plist, keys are family names, values are (MFontFT *).  */
+static MPlist *ft_script_list;
+
+/** List of FreeType fonts.  Keys are language names, values are
+    plists containing fonts supporting the corresponding language.  In
+    the deeper plist, keys are family names, values are (MFontFT *).  */
+static MPlist *ft_language_list;
+
+static MPlist *ft_file_list;
+
+static int all_fonts_scaned;
+
+#define STRDUP_LOWER(s1, size, s2)                             \
+  do {                                                         \
+    int len = strlen (s2) + 1;                                 \
+    char *p1, *p2;                                             \
+                                                               \
+    if ((size) < len)                                          \
+      (s1) = alloca (len), (size) = len;                       \
+    for (p1 = (s1), p2 = (s2); *p2; p1++, p2++)                        \
+      *p1 = (*p2 >= 'A' && *p2 <= 'Z' ? *p2 + 'a' - 'A' : *p2);        \
+    *p1 = '\0';                                                        \
+  } while (0)
+
+
+static MPlist *ft_list_family (MSymbol, int, int);
+
+static void
+free_ft_rfont (void *object)
+{
+  MRealizedFontFT *ft_rfont = object;
+
+  if (! ft_rfont->face_encapsulated)
+    {
+      M17N_OBJECT_UNREF (ft_rfont->charmap_list);
+      FT_Done_Face (ft_rfont->ft_face);
+    }
+  free (ft_rfont);
+}
+
+static void
+free_ft_info (MFontFT *ft_info)
+{
+#ifdef HAVE_OTF
+  if (ft_info->otf && ft_info->otf != invalid_otf)
+    OTF_close (ft_info->otf);
+#endif /* HAVE_OTF */
+#ifdef HAVE_FONTCONFIG
+  if (ft_info->langset)
+    FcLangSetDestroy (ft_info->langset);
+  if (ft_info->charset)
+    FcCharSetDestroy (ft_info->charset);
+#endif /* HAVE_FONTCONFIG */
+  free (ft_info);
+}
+
+static MPlist *
+ft_get_charmaps (FT_Face ft_face)
+{
+  MPlist *plist = mplist ();
+  int unicode_bmp = -1, unicode_full = -1;
+  int i;
+
+  mplist_add (plist, Mt, (void *) -1);
+  for (i = 0; i < ft_face->num_charmaps; i++)
+    {
+      MSymbol registry = Mnil;
+
+      if (ft_face->charmaps[i]->platform_id == 0)
+       {
+         if (ft_face->charmaps[i]->encoding_id <= 4)
+           registry = M0[ft_face->charmaps[i]->encoding_id], unicode_bmp = i;
+         if (ft_face->charmaps[i]->encoding_id == 4)
+           unicode_bmp = unicode_full = i;
+       }
+      else if (ft_face->charmaps[i]->platform_id == 3)
+       {
+         if (ft_face->charmaps[i]->encoding_id == 1)
+           registry = M3_1, unicode_bmp = i;
+         else if (ft_face->charmaps[i]->encoding_id == 10)
+           unicode_bmp = unicode_full = i;
+       }
+      else if (ft_face->charmaps[i]->platform_id == 1
+              && ft_face->charmaps[i]->encoding_id == 0)
+       {
+         registry = M1_0;
+         mplist_add (plist, Mapple_roman, (void *) i);
+       }
+      if (registry == Mnil)
+       {
+         char registry_buf[16];
+
+         sprintf (registry_buf, "%d-%d",
+                  ft_face->charmaps[i]->platform_id,
+                  ft_face->charmaps[i]->encoding_id);
+         registry = msymbol (registry_buf);
+       }
+      mplist_add (plist, registry, (void *) i);
+    }
+  if (unicode_full >= 0)
+    mplist_add (plist, Municode_full, (void *) unicode_full);
+  if (unicode_bmp >= 0)
+    {
+      int i;
+
+      mplist_add (plist, Municode_bmp, (void *) unicode_bmp);
+      FT_Set_Charmap (ft_face, ft_face->charmaps[unicode_bmp]);
+      for (i = 0x21; i < 0x7F && FT_Get_Char_Index (ft_face, i) > 0; i++);
+      if (i == 0x7F)
+       {
+         for (i = 0xC0; i < 0x100 && FT_Get_Char_Index (ft_face, i) > 0; i++);
+         if (i == 0x100)
+           mplist_add (plist, Miso8859_1, (void *) unicode_bmp);
+       }
+    }
+
+  return plist;
+}
+
+static MFontFT *
+ft_gen_font (FT_Face ft_face)
+{
+  MFontFT *ft_info;
+  MFont *font;
+  char *buf;
+  int bufsize = 0;
+  char *stylename;
+  MSymbol family;
+  int size;
+
+  if (FT_IS_SCALABLE (ft_face))
+    size = ft_face->size->metrics.y_ppem;
+  else if (ft_face->num_fixed_sizes == 0)
+    return NULL;
+  else
+    size = ft_face->available_sizes[0].height;
+
+  MSTRUCT_CALLOC (ft_info, MERROR_FONT_FT);
+  font = &ft_info->font;
+  STRDUP_LOWER (buf, bufsize, ft_face->family_name);
+  family = msymbol (buf);
+  mfont__set_property (font, MFONT_FAMILY, family);
+  mfont__set_property (font, MFONT_WEIGHT, Mmedium);
+  mfont__set_property (font, MFONT_STYLE, Mr);
+  mfont__set_property (font, MFONT_STRETCH, Mnormal);
+  mfont__set_property (font, MFONT_ADSTYLE, Mnull);
+  mfont__set_property (font, MFONT_REGISTRY, Municode_bmp);
+  font->size = size * 10;
+  font->type = MFONT_TYPE_OBJECT;
+  font->source = MFONT_SOURCE_FT;
+  font->file = NULL;
+
+  stylename = ft_face->style_name;
+  while (*stylename)
+    {
+      int i;
+
+      for (i = 0; i < ft_to_prop_size; i++)
+       if (! strncasecmp (ft_to_prop[i].ft_style, stylename,
+                          ft_to_prop[i].len))
+         {
+           mfont__set_property (font, ft_to_prop[i].prop,
+                                msymbol (ft_to_prop[i].val));
+           stylename += ft_to_prop[i].len;
+           break;
+         }
+      if (i == ft_to_prop_size)
+       {
+         char *p1 = stylename + 1;
+         MSymbol sym;
+
+         while (*p1 >= 'a' && *p1 <= 'z') p1++;
+         sym = msymbol__with_len (stylename, p1 - stylename);
+         for (i = MFONT_WEIGHT; i <= MFONT_STRETCH; i++)
+           if (msymbol_get (sym, mfont__property_table[i].property))
+             {
+               mfont__set_property (font, i, sym);
+               break;
+             }
+         stylename = p1;
+       }
+      while (*stylename && ! isalpha (*stylename))
+       stylename++;
+    }
+  return ft_info;
+}
+
+#ifdef HAVE_FONTCONFIG
+
+typedef struct
+{
+  int fc_value;
+  char *m17n_value;
+  MSymbol sym;
+} FC_vs_M17N_font_prop;
+
+static FC_vs_M17N_font_prop fc_weight_table[] =
+  { { FC_WEIGHT_THIN, "thin" },
+    { FC_WEIGHT_ULTRALIGHT, "extralight" },
+    { FC_WEIGHT_LIGHT, "light" },
+#ifdef FC_WEIGHT_BOOK
+    { FC_WEIGHT_BOOK, "book" },
+#endif /* FC_WEIGHT_BOOK */
+    { FC_WEIGHT_REGULAR, "normal" },
+    { FC_WEIGHT_NORMAL, "normal" },
+    { FC_WEIGHT_MEDIUM, "medium" },
+    { FC_WEIGHT_DEMIBOLD, "demibold" },
+    { FC_WEIGHT_BOLD, "bold" },
+    { FC_WEIGHT_EXTRABOLD, "extrabold" },
+    { FC_WEIGHT_BLACK, "black" },
+    { FC_WEIGHT_HEAVY, "heavy" },
+    { FC_WEIGHT_MEDIUM, NULL } };
+int fc_weight_table_size =
+  sizeof fc_weight_table / sizeof (FC_vs_M17N_font_prop);
+
+static FC_vs_M17N_font_prop fc_slant_table[] =
+  { { FC_SLANT_ROMAN, "r" },
+    { FC_SLANT_ITALIC, "i" },
+    { FC_SLANT_OBLIQUE, "o" },
+    { FC_SLANT_ROMAN, NULL } };
+int fc_slant_table_size =
+  sizeof fc_slant_table / sizeof (FC_vs_M17N_font_prop);
+
+static FC_vs_M17N_font_prop fc_width_table[] =
+  { { FC_WIDTH_ULTRACONDENSED, "ultracondensed" },
+    { FC_WIDTH_EXTRACONDENSED, "extracondensed" },
+    { FC_WIDTH_CONDENSED, "condensed" },
+    { FC_WIDTH_SEMICONDENSED, "semicondensed" },
+    { FC_WIDTH_NORMAL, "normal" },
+    { FC_WIDTH_SEMIEXPANDED, "semiexpanded" },
+    { FC_WIDTH_EXPANDED, "expanded" },
+    { FC_WIDTH_EXTRAEXPANDED, "extraexpanded" },
+    { FC_WIDTH_ULTRAEXPANDED, "ultraexpanded" },
+    { FC_WIDTH_NORMAL, NULL } };
+int fc_width_table_size =
+  sizeof fc_width_table / sizeof (FC_vs_M17N_font_prop);
+
+
+static FC_vs_M17N_font_prop *fc_all_table[] =
+  { fc_weight_table, fc_slant_table, fc_width_table };
+
+static MSymbol
+fc_decode_prop (int val, FC_vs_M17N_font_prop *table, int size)
+{
+  int i = size / 2;
+
+  if (val < table[i].fc_value)
+    {
+      for (i--; i >= 0; i--)
+       if (val > table[i].fc_value)
+         break;
+      i++;
+    }
+  else
+    {
+      for (; i < size; i++)
+       if (val <= table[i].fc_value)
+         break;
+    }
+  return table[i].sym;
+}
+
+static int
+fc_encode_prop (MSymbol sym, FC_vs_M17N_font_prop *table)
+{
+  int i;
+
+  for (i = 0; table[i].m17n_value; i++)
+    if (table[i].sym == sym)
+      break;
+  return table[i].fc_value;
+}
+
+FcPattern *
+fc_get_pattern (MFont *font)
+{
+  FcPattern *pat = FcPatternCreate ();
+  MSymbol sym, weight, style, stretch;
+
+
+  if ((sym = (MSymbol) FONT_PROPERTY (font, MFONT_FOUNDRY)) != Mnil)
+    FcPatternAddString (pat, FC_FOUNDRY, (FcChar8 *) MSYMBOL_NAME (sym));
+  if ((sym = (MSymbol) FONT_PROPERTY (font, MFONT_FAMILY)) != Mnil)
+    FcPatternAddString (pat, FC_FAMILY, (FcChar8 *) MSYMBOL_NAME (sym));
+  if ((weight = (MSymbol) FONT_PROPERTY (font, MFONT_WEIGHT)) != Mnil)
+    FcPatternAddInteger (pat, FC_WEIGHT,
+                        fc_encode_prop (weight, fc_weight_table));
+  if ((style = (MSymbol) FONT_PROPERTY (font, MFONT_STYLE)) != Mnil)
+    FcPatternAddInteger (pat, FC_SLANT,
+                        fc_encode_prop (style, fc_slant_table));
+  if ((stretch = (MSymbol) FONT_PROPERTY (font, MFONT_STRETCH)) != Mnil)
+    FcPatternAddInteger (pat, FC_WIDTH,
+                        fc_encode_prop (stretch, fc_width_table));
+  if (font->size > 0)
+    {
+      double size = font->size;
+      FcPatternAddDouble (pat, FC_PIXEL_SIZE, size / 10);
+    }
+  else if (font->size < 0)
+    {
+      double size = - font->size;
+      FcPatternAddDouble (pat, FC_SIZE, size / 10);
+    }
+  return pat;
+}
+
+static void
+fc_parse_pattern (FcPattern *pat, char *family, MFontFT *ft_info)
+{
+  FcChar8 *str;
+  int val;
+  double size;
+  char *buf;
+  int bufsize = 0;
+  MSymbol sym;
+  FcLangSet *ls;
+  FcCharSet *cs;
+  MFont *font = &ft_info->font;
+
+  MFONT_INIT (font);
+  if (FcPatternGetString (pat, FC_FOUNDRY, 0, &str) == FcResultMatch)
+    {
+      STRDUP_LOWER (buf, bufsize, (char *) str);
+      mfont__set_property (font, MFONT_FOUNDRY, msymbol (buf));
+    }
+  if (family)
+    mfont__set_property (font, MFONT_FAMILY, msymbol (family));
+  else if (FcPatternGetString (pat, FC_FAMILY, 0, &str) == FcResultMatch)
+    {
+      STRDUP_LOWER (buf, bufsize, (char *) str);
+      mfont__set_property (font, MFONT_FAMILY, msymbol (buf));
+    }
+  if (FcPatternGetInteger (pat, FC_WEIGHT, 0, &val) == FcResultMatch)
+    {
+      sym = fc_decode_prop (val, fc_weight_table, fc_weight_table_size);
+      mfont__set_property (font, MFONT_WEIGHT, sym);
+    }
+  if (FcPatternGetInteger (pat, FC_SLANT, 0, &val) == FcResultMatch)
+    {
+      sym = fc_decode_prop (val, fc_slant_table, fc_slant_table_size);
+      mfont__set_property (font, MFONT_STYLE, sym);
+    }
+  if (FcPatternGetInteger (pat, FC_WIDTH, 0, &val) == FcResultMatch)
+    {
+      sym = fc_decode_prop (val, fc_width_table, fc_width_table_size);
+      mfont__set_property (font, MFONT_STRETCH, sym);
+    }
+  if (FcPatternGetLangSet (pat, FC_LANG, 0, &ls) == FcResultMatch)
+    {
+      if (FcLangSetHasLang (ls, (FcChar8 *) "ja") != FcLangDifferentLang
+         || FcLangSetHasLang (ls, (FcChar8 *) "zh") != FcLangDifferentLang
+         || FcLangSetHasLang (ls, (FcChar8 *) "ko") != FcLangDifferentLang)
+       font->for_full_width = 1;
+      ft_info->langset = FcLangSetCopy (ls);
+    }
+  if (FcPatternGetCharSet (pat, FC_CHARSET, 0, &cs) == FcResultMatch)
+    ft_info->charset = FcCharSetCopy (cs);
+
+  mfont__set_property (font, MFONT_REGISTRY, Municode_bmp);
+  font->type = MFONT_TYPE_SPEC;
+  font->source = MFONT_SOURCE_FT;
+  if (FcPatternGetDouble (pat, FC_PIXEL_SIZE, 0, &size) == FcResultMatch)
+    font->size = size * 10;
+  if (FcPatternGetString (pat, FC_FILE, 0, &str) == FcResultMatch)
+    font->file = msymbol ((char *) str);
+}
+
+
+static MFontFT *
+fc_gen_font (FcPattern *pat, char *family)
+{
+  MFontFT *ft_info;
+
+  MSTRUCT_CALLOC (ft_info, MERROR_FONT_FT);
+  fc_parse_pattern (pat, family, ft_info);
+  ft_info->font.type = MFONT_TYPE_OBJECT;
+  return ft_info;
+}
+
+static void
+fc_init_font_list (void)
+{
+  FcPattern *pattern = FcPatternCreate ();
+  FcObjectSet *os = FcObjectSetBuild (FC_FAMILY, NULL);
+  FcFontSet *fs = FcFontList (fc_config, pattern, os);
+  MPlist *plist = mplist ();
+  char *buf;
+  int bufsize = 0;
+  int i;
+
+  ft_font_list = plist;
+  for (i = 0; i < fs->nfont; i++)
+    {
+      char *fam;
+
+      if (FcPatternGetString (fs->fonts[i], FC_FAMILY, 0,
+                             (FcChar8 **) &fam) != FcResultMatch)
+       continue;
+      STRDUP_LOWER (buf, bufsize, fam);
+      plist = mplist_add (plist, msymbol (buf), NULL);
+    }
+  FcFontSetDestroy (fs);
+  FcObjectSetDestroy (os);
+  FcPatternDestroy (pattern);
+}
+
+static MPlist *
+fc_list_pattern (FcPattern *pattern)
+{
+  FcObjectSet *os = NULL;
+  FcFontSet *fs = NULL;
+  MSymbol last_family = Mnil;
+  MPlist *plist = NULL, *pl = NULL;
+  char *buf;
+  int bufsize = 0;
+  int i;
+
+  if (! (os = FcObjectSetBuild (FC_FAMILY, FC_FILE, NULL)))
+    goto err;
+  if (! (fs = FcFontList (fc_config, pattern, os)))
+    goto err;
+
+  for (i = 0; i < fs->nfont; i++)
+    {
+      MSymbol family, file;
+      char *fam, *filename;
+      MFontFT *ft_info;
+
+      if (FcPatternGetString (fs->fonts[i], FC_FAMILY, 0,
+                             (FcChar8 **) &fam) != FcResultMatch)
+       continue;
+      if (FcPatternGetString (fs->fonts[i], FC_FILE, 0,
+                             (FcChar8 **) &filename) != FcResultMatch)
+       continue;
+      STRDUP_LOWER (buf, bufsize, fam);
+      family = msymbol (buf);
+      file = msymbol (filename);
+      if (family != last_family)
+       {
+         pl = MPLIST_PLIST (ft_list_family (family, 0, 1));
+         last_family = family;
+       }
+      ft_info = mplist_get (pl, file);
+      if (ft_info)
+       {
+         if (! plist)
+           plist = mplist ();
+         mplist_add (plist, family, ft_info);
+       }
+    }
+
+ err:
+  if (fs) FcFontSetDestroy (fs);
+  if (os) FcObjectSetDestroy (os);
+  return plist;
+}
+
+/* Return FcCharSet object built from CHAR_LIST or MT.  In the latter
+   case, it is assured that the M-text contains at least one
+   character.  */
+
+static FcCharSet *
+fc_build_charset (MPlist *char_list, MText *mt)
+{
+  FcCharSet *cs = FcCharSetCreate ();
+
+  if (! cs)
+    return NULL;
+  if (char_list)
+    {
+      for (; ! MPLIST_TAIL_P (char_list); char_list = MPLIST_NEXT (char_list))
+       if (! FcCharSetAddChar (cs, (FcChar32) MPLIST_INTEGER (char_list)))
+         {
+           FcCharSetDestroy (cs);
+           return NULL;
+         }
+    }
+  else
+    {
+      int i;
+
+      for (i = mtext_nchars (mt) - 1; i >= 0; i--)
+       if (! FcCharSetAddChar (cs, (FcChar32) mtext_ref_char (mt, i)))
+         {
+           FcCharSetDestroy (cs);
+           return NULL;
+         }
+      if (mtext_nchars (mt) > 0
+         && (mt = mtext_get_prop (mt, 0, Mtext)))
+       for (i = mtext_nchars (mt) - 1; i >= 0; i--)
+         if (! FcCharSetAddChar (cs, (FcChar32) mtext_ref_char (mt, i)))
+           {
+             FcCharSetDestroy (cs);
+             return NULL;
+           }
+      }
+  return cs;
+}
+
+#else  /* not HAVE_FONTCONFIG */
+
+static MPlist *
+ft_add_font (char *filename)
+{
+  FT_Face ft_face;
+  char *stylename;
+  int size = 0;
+  MSymbol family;
+  MFontFT *ft_info;
+  MFont *font;
+  MPlist *plist;
+  int i;
+  char *buf;
+  int bufsize = 0;
+
+  if (FT_New_Face (ft_library, filename, 0, &ft_face) != 0)
+    return NULL;
+  ft_info = ft_gen_font (ft_face);
+  FT_Done_Face (ft_face);
+  if (! ft_info)
+    return NULL;
+
+  font = &ft_info->font;
+  font->file = msymbol (filename);
+
+  plist = mplist_find_by_key (ft_font_list, family);
+  if (plist)
+    mplist_push (MPLIST_PLIST (plist), font->file, ft_info);
+  else
+    {
+      plist = mplist ();
+      mplist_add (plist, font->file, ft_info);
+      plist = mplist_push (ft_font_list, family, plist);
+    }
+  return plist;
+}
+
+static void
+ft_init_font_list (void)
+{
+  MPlist *plist;
+  struct stat buf;
+  char *pathname;
+  char *path;
+  USE_SAFE_ALLOCA;
+
+  ft_font_list = mplist ();
+  MPLIST_DO (plist, mfont_freetype_path)
+    if (MPLIST_STRING_P (plist)
+       && (pathname = MPLIST_STRING (plist))
+       && stat (pathname, &buf) == 0)
+      {
+       if (S_ISREG (buf.st_mode))
+         ft_add_font (pathname);
+       else if (S_ISDIR (buf.st_mode))
+         {
+           DIR *dir = opendir (pathname);
+
+           if (dir)
+             {
+               int len = strlen (pathname);
+               struct dirent *dp;
+
+               while ((dp = readdir (dir)) != NULL)
+                 {
+                   SAFE_ALLOCA (path, len + strlen (dp->d_name) + 2);
+                   strcpy (path, pathname);
+                   path[len] =  '/';
+                   strcpy (path + len + 1, dp->d_name);
+                   ft_add_font (path);
+                 }
+               closedir (dir);
+             }
+         }
+      }
+  SAFE_FREE (path);
+}
+
+/* Return 1 iff the font pointed by FT_INFO has all characters in
+   CHAR_LIST.  */
+
+static int
+ft_has_char_list_p (MFontFT *ft_info, MPlist *char_list)
+{
+  FT_Face ft_face;
+  MPlist *cl;
+
+  if (FT_New_Face (ft_library, MSYMBOL_NAME (ft_info->font.file), 0, &ft_face))
+    return 0;
+  MPLIST_DO (cl, char_list)
+    if (FT_Get_Char_Index (ft_face, (FT_ULong) MPLIST_INTEGER (cl)) == 0)
+      break;
+  FT_Done_Face (ft_face);
+  return MPLIST_TAIL_P (cl);
+}
+
+/* Return ((FAMILY . FONT) ...) where FONT is a pointer to MFontFT
+   that supports characters in CHAR_LIST or MT.  One of CHAR_LIST or
+   MT must be NULL.  */
+
+static MPlist *
+ft_list_char_list (MPlist *char_list, MText *mt)
+{
+  MPlist *plist = NULL, *pl, *p;
+
+  if (! ft_font_list)
+    ft_list_family (Mnil, 0, 1);
+
+  if (mt)
+    {
+      int len = mtext_nchars (mt);
+      MText *extra = mtext_get_prop (mt, 0, Mtext);
+      int total_len = len + (extra ? mtext_nchars (extra) : 0);
+      int i;
+
+      char_list = mplist ();
+      for (i = 0; i < total_len; i++)
+       {
+         int c = (i < len ? mtext_ref_char (mt, i)
+                  : mtext_ref_char (extra, i - len));
+
+         if (! mplist_find_by_value (char_list, (void *) c))
+           mplist_push (char_list, Minteger, (void *) c);
+       }
+    }
+
+  MPLIST_DO (pl, ft_font_list)
+    {
+      MPLIST_DO (p, MPLIST_PLIST (pl))
+       {
+         MFontFT *ft_info = MPLIST_VAL (p);
+
+         if (ft_has_char_list_p (ft_info, char_list))
+           {
+             MSymbol family = mfont_get_prop (&ft_info->font, Mfamily);
+
+             if (! plist)
+               plist = mplist ();
+             mplist_push (plist, family, ft_info);
+           }
+       }
+    }
+  if (mt)
+    M17N_OBJECT_UNREF (char_list);
+  return plist;
+}
+#endif /* not HAVE_FONTCONFIG */
+
+
+/* Return an element of ft_font_list for FAMILY.  If FAMILY is Mnil,
+   scan all fonts and return ft_font_list.  */
+
+static MPlist *
+ft_list_family (MSymbol family, int check_generic, int check_alias)
+{
+  MPlist *plist;
+#ifdef HAVE_FONTCONFIG
+  char *fam;
+  MPlist *pl, *p;
+  FcPattern *pattern;
+  FcObjectSet *os;
+  FcFontSet *fs;
+  int i;
+  char *buf;
+  int bufsize = 0;
+  MSymbol generic;
+
+  if (! ft_font_list)
+    {
+      MSymbol sym;
+
+      plist = ft_font_list = mplist ();
+      pattern = FcPatternCreate ();
+      os = FcObjectSetBuild (FC_FAMILY, NULL);
+      fs = FcFontList (fc_config, pattern, os);
+      for (i = 0; i < fs->nfont; i++)
+       {
+         if (FcPatternGetString (fs->fonts[i], FC_FAMILY, 0,
+                                 (FcChar8 **) &fam) != FcResultMatch)
+           continue;
+         STRDUP_LOWER (buf, bufsize, fam);
+         sym = msymbol (buf);
+         if (! mplist_find_by_key (ft_font_list, sym))
+           plist = mplist_add (plist, sym, NULL);
+       }
+      FcFontSetDestroy (fs);
+      FcObjectSetDestroy (os);
+      FcPatternDestroy (pattern);
+    }
+
+  if (family == Mnil)
+    {
+      if (! all_fonts_scaned)
+       {
+         MPLIST_DO (plist, ft_font_list)
+           {
+             if (! MPLIST_VAL (plist))
+               ft_list_family (MPLIST_KEY (plist), 0, 1);
+           }
+         all_fonts_scaned = 1;
+       }
+      return ft_font_list;
+    }
+
+  plist = mplist_find_by_key (ft_font_list, family);
+  if (plist)
+    {
+      if (! MPLIST_VAL (plist))
+       {
+         fam = MSYMBOL_NAME (family);
+         pattern = FcPatternCreate ();
+         FcPatternAddString (pattern, FC_FAMILY, (FcChar8 *) fam);
+         os = FcObjectSetBuild (FC_FOUNDRY, FC_WEIGHT, FC_SLANT, FC_WIDTH,
+                                FC_PIXEL_SIZE, FC_LANG, FC_CHARSET, FC_FILE,
+                                NULL);
+         fs = FcFontList (fc_config, pattern, os);
+         p = pl = mplist ();
+         for (i = 0; i < fs->nfont; i++)
+           {
+             MFontFT *ft_info = fc_gen_font (fs->fonts[i], fam);
+             p = mplist_add (p, ft_info->font.file, ft_info);
+           }
+         MPLIST_VAL (plist) = pl;
+         FcFontSetDestroy (fs);
+         FcObjectSetDestroy (os);
+         FcPatternDestroy (pattern);
+       }
+    }
+  else if (check_generic
+          && (generic = msymbol_get (family, Mgeneric_family)) != Mnil)
+    {
+      /* Check if FAMILY is a geneneric family (e.g. `serif').  */
+      FcChar8 *fam8;
+      
+      if (family != generic)
+       plist = ft_list_family (generic, 1, 1);
+      else
+       {
+         fam = MSYMBOL_NAME (family);
+         plist = mplist ();
+         mplist_push (ft_font_list, family, plist);
+         pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, fam, NULL);
+         FcConfigSubstitute (fc_config, pattern, FcMatchPattern);
+         for (i = 0; 1; i++)
+           {
+             if (FcPatternGetString (pattern, FC_FAMILY, i, &fam8)
+                 != FcResultMatch)
+               break;
+             STRDUP_LOWER (buf, bufsize, (char *) fam8);
+             family = msymbol (buf);
+             if (msymbol_get (family, Mgeneric_family))
+               break;
+             pl = ft_list_family (family, 0, 1);
+             if (! pl)
+               continue;
+             MPLIST_DO (pl, MPLIST_PLIST (pl))
+               plist = mplist_add (plist, Mt, MPLIST_VAL (pl));
+           }
+         plist = ft_font_list;
+       }
+    }
+  else if (check_alias)
+    {
+      /* Check if there exist an alias.  */
+      pl = mplist ();
+      plist = mplist_add (ft_font_list, family, pl);
+
+      pattern = FcPatternBuild (NULL,
+                               FC_FAMILY, FcTypeString, MSYMBOL_NAME (family),
+                               NULL);
+      FcConfigSubstitute (fc_config, pattern, FcMatchPattern);
+
+      for (i = 0; FcPatternGetString (pattern, FC_FAMILY, i,
+                                     (FcChar8 **) &fam) == FcResultMatch;
+          i++);
+      if (i > 0)
+       {
+         /* The last one is a generic family.  */
+         MSymbol sym;
+         int j;
+         FcPattern *pat = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, fam,
+                                          NULL);
+
+         FcConfigSubstitute (fc_config, pat, FcMatchPattern);
+         for (j = 0; FcPatternGetString (pat, FC_FAMILY, j,
+                                         (FcChar8 **) &fam) == FcResultMatch;
+              j++);
+
+         /* Now we know that the last J fonts in PATTERN are from
+            generic font, and the first one is not available.  So,
+            the remaining ones are aliases.  */
+         j = i - j;
+         for (i = 1; i < j; i++)
+           {
+             FcPatternGetString (pattern, FC_FAMILY, i, (FcChar8 **) &fam);
+             STRDUP_LOWER (buf, bufsize, fam);
+             sym = msymbol (buf);
+             p = MPLIST_PLIST (ft_list_family (sym, 0, 0));
+             if (! MPLIST_TAIL_P (p))
+               MPLIST_DO (p, p)
+                 mplist_push (pl, Mt, MPLIST_VAL (p));
+           }
+       }
+    }
+  else
+    {
+      pl = mplist ();
+      plist = mplist_add (ft_font_list, family, pl);
+    }
+
+#else  /* not HAVE_FONTCONFIG */
+
+  if (! all_fonts_scaned)
+    {
+      ft_init_font_list ();
+      all_fonts_scaned = 1;
+    }
+  if (family == Mnil)
+    plist = ft_font_list;
+  else
+    {
+      plist = mplist_find_by_key (ft_font_list, family);
+      if (! plist)
+       plist = mplist_push (ft_font_list, family, mplist ());
+    }
+#endif  /* not HAVE_FONTCONFIG */
+
+  return plist;
+}
+
+static MPlist *
+ft_list_language (MSymbol language)
+{
+  MPlist *plist = NULL;
+  MText *mt;
+
+  if (! ft_language_list)
+    ft_language_list = mplist ();
+  else if ((plist = mplist_find_by_key (ft_language_list, language)))
+    return (MPLIST_VAL (plist) ? MPLIST_PLIST (plist) : NULL);
+
+  mt = mlanguage_text (language);
+
+#ifdef HAVE_FONTCONFIG
+  {
+    FcPattern *pattern = NULL;
+    FcCharSet *cs = NULL;
+    FcLangSet *ls = NULL;
+
+    if (! (pattern = FcPatternCreate ()))
+      goto err;
+
+    if (mt && mtext_nchars (mt) > 0)
+      {
+       cs = fc_build_charset (NULL, mt);       
+       if (cs && ! FcPatternAddCharSet (pattern, FC_CHARSET, cs))
+         goto err;
+      }
+    else
+      {
+       if (! (ls = FcLangSetCreate ()))
+         goto err;
+       if (! FcLangSetAdd (ls, (FcChar8 *) MSYMBOL_NAME (language))
+           || ! FcPatternAddLangSet (pattern, FC_LANG, ls))
+         goto err;
+      }
+
+    plist = fc_list_pattern (pattern);
+  err:
+    if (cs) FcCharSetDestroy (cs);
+    if (ls) FcLangSetDestroy (ls);
+    if (pattern) FcPatternDestroy (pattern);
+  }
+#else  /* not HAVE_FONTCONFIG */
+  if (mt && mtext_nchars (mt) > 0)
+    plist = ft_list_char_list (NULL, mt);
+#endif  /* not HAVE_FONTCONFIG */
+
+  mplist_push (ft_language_list, language, plist);
+  return plist;
+}
+
+static MPlist *
+ft_list_script (MSymbol script)
+{
+  MPlist *plist = NULL;
+  MPlist *char_list;
+
+  if (! ft_script_list)
+    ft_script_list = mplist ();
+  else if ((plist = mplist_find_by_key (ft_script_list, script)))
+    return (MPLIST_VAL (plist) ? MPLIST_PLIST (plist) : NULL);
+
+  char_list = mscript__char_list (script);
+
+#ifdef HAVE_FONTCONFIG
+  if (char_list)
+    {
+      FcPattern *pattern = NULL;
+      FcCharSet *cs;
+
+      if (! (pattern = FcPatternCreate ()))
+       goto err;
+      cs = fc_build_charset (char_list, NULL);
+      if (cs && ! FcPatternAddCharSet (pattern, FC_CHARSET, cs))
+         goto err;
+      plist = fc_list_pattern (pattern);
+    err:
+      if (cs) FcCharSetDestroy (cs);
+      if (pattern) FcPatternDestroy (pattern);
+    }
+#else  /* not HAVE_FONTCONFIG */
+  if (char_list)
+    plist = ft_list_char_list (char_list, NULL);
+#endif /* not HAVE_FONTCONFIG */
+
+  mplist_push (ft_script_list, script, plist);
+  return (plist);
+}
+
+static int
+ft_check_cap_otf (MFontFT *ft_info, MFontCapability *cap, FT_Face ft_face)
+{
+#ifdef HAVE_OTF
+  if (ft_info->otf == invalid_otf)
+    return -1;
+  if (! ft_info->otf)
+    {
+#if (LIBOTF_MAJOR_VERSION > 0 || LIBOTF_MINOR_VERSION > 9 || LIBOTF_RELEASE_NUMBER > 4)
+      if (ft_face)
+       ft_info->otf = OTF_open_ft_face (ft_face);
+      else
+#endif
+       ft_info->otf = OTF_open (MSYMBOL_NAME (ft_info->font.file));
+      if (! ft_info->otf)
+       {
+         ft_info->otf = invalid_otf;
+         return -1;
+       }
+    }
+  if (cap->features[MFONT_OTT_GSUB].nfeatures
+      && (OTF_check_features
+         (ft_info->otf, 1,
+          cap->script_tag, cap->langsys_tag,
+          cap->features[MFONT_OTT_GSUB].tags,
+          cap->features[MFONT_OTT_GSUB].nfeatures) != 1))
+    return -1;
+  if (cap->features[MFONT_OTT_GPOS].nfeatures
+      && (OTF_check_features
+         (ft_info->otf, 0,
+          cap->script_tag, cap->langsys_tag,
+          cap->features[MFONT_OTT_GPOS].tags,
+          cap->features[MFONT_OTT_GPOS].nfeatures) != 1))
+    return -1;
+  return 0;
+#else  /* not HAVE_OTF */
+  return -1;
+#endif /* not HAVE_OTF */
+}
+
+static int
+ft_check_language (MFontFT *ft_info, MSymbol language, FT_Face ft_face)
+{
+  MText *mt;
+  MText *extra;
+  int ft_face_allocaed = 0;
+  int len, total_len;
+  int i;
+
+#ifdef HAVE_FONTCONFIG
+  if (ft_info->langset
+      && (FcLangSetHasLang (ft_info->langset,
+                           (FcChar8 *) MSYMBOL_NAME (language))
+         != FcLangDifferentLang))
+    return 0;
+#endif /* HAVE_FONTCONFIG */
+
+  mt = mlanguage_text (language);
+  if (! mt || mtext_nchars (mt) == 0)
+    return -1;
+
+  if (! ft_face)
+    {
+      char *filename = MSYMBOL_NAME (ft_info->font.file);
+
+      if (FT_New_Face (ft_library, filename, 0, &ft_face))
+       return -1;
+      ft_face_allocaed = 1;
+    }
+
+  len = mtext_nchars (mt);
+  extra = mtext_get_prop (mt, 0, Mtext);
+  total_len = len + (extra ? mtext_nchars (extra) : 0);
+
+  for (i = 0; i < total_len; i++)
+    {
+      int c = (i < len ? mtext_ref_char (mt, i)
+              : mtext_ref_char (extra, i - len));
+
+#ifdef HAVE_FONTCONFIG
+      if (ft_info->charset
+         && FcCharSetHasChar (ft_info->charset, (FcChar32) c) == FcFalse)
+       break;
+#endif /* HAVE_FONTCONFIG */
+      if (FT_Get_Char_Index (ft_face, (FT_ULong) c) == 0)
+       break;
+    }
+
+  if (ft_face_allocaed)
+    FT_Done_Face (ft_face);
+
+  return (i == total_len ? 0 : -1);
+}
+
+static int
+ft_check_script (MFontFT *ft_info, MSymbol script, FT_Face ft_face)
+{
+  MPlist *char_list = mscript__char_list (script);
+
+  if (! char_list)
+    return -1;
+#ifdef HAVE_FONTCONFIG
+  if (ft_info->charset)
+    {
+      MPLIST_DO (char_list, char_list)
+       if (FcCharSetHasChar (ft_info->charset,
+                             (FcChar32) MPLIST_INTEGER (char_list)) == FcFalse)
+         break;
+    }
+  else
+#endif /* HAVE_FONTCONFIG */
+    {
+      int ft_face_allocaed = 0;
+
+      if (! ft_face)
+       {
+         char *filename = MSYMBOL_NAME (ft_info->font.file);
+
+         if (FT_New_Face (ft_library, filename, 0, &ft_face))
+           return -1;
+         ft_face_allocaed = 1;
+       }
+
+      MPLIST_DO (char_list, char_list)
+       if (FT_Get_Char_Index (ft_face, (FT_ULong) MPLIST_INTEGER (char_list))
+           == 0)
+         break;
+      if (ft_face_allocaed)
+       FT_Done_Face (ft_face);
+    }
+
+  return (MPLIST_TAIL_P (char_list) ? 0 : -1);
+}
+
+static MPlist *ft_default_list;
+
+static MPlist *
+ft_list_default ()
+{
+  if (ft_default_list)
+    return ft_default_list;
+  ft_default_list = mplist ();
+#ifdef HAVE_FONTCONFIG
+  {
+    FcPattern *pat = FcPatternCreate ();
+    FcChar8 *fam;
+    char *buf;
+    int bufsize = 0;
+    int i;
+
+    FcConfigSubstitute (fc_config, pat, FcMatchPattern);
+    for (i = 0; FcPatternGetString (pat, FC_FAMILY, i, &fam) == FcResultMatch;
+        i++)
+      {
+       MSymbol family;
+       MPlist *plist;
+
+       STRDUP_LOWER (buf, bufsize, (char *) fam);
+       family = msymbol (buf);
+       if (msymbol_get (family, Mgeneric_family))
+         continue;
+       plist = MPLIST_PLIST (ft_list_family (family, 0, 1));
+       MPLIST_DO (plist, plist)
+         mplist_add (ft_default_list, family, MPLIST_VAL (plist));
+      }
+  }
+#else  /* not HAVE_FONTCONFIG */
+  {
+    MPlist *plist, *pl;
+
+    MPLIST_DO (plist, ft_list_family (Mnil, 0, 1))
+      {
+       pl = MPLIST_PLIST (plist);
+       if (! MPLIST_TAIL_P (pl))
+         mplist_add (ft_default_list, MPLIST_KEY (plist), pl);
+      }
+  }
+#endif /* not HAVE_FONTCONFIG */
+  return ft_default_list;
+}
+
+
+static MPlist *ft_capability_list;
+
+static MPlist *
+ft_list_capability (MSymbol capability)
+{
+  MFontCapability *cap;
+  MPlist *plist = NULL, *pl;
+
+  if (! ft_capability_list)
+    ft_capability_list = mplist ();
+  else if ((plist = mplist_find_by_key (ft_capability_list, capability)))
+    return (MPLIST_VAL (plist) ? MPLIST_VAL (plist) : NULL);
+
+  cap = mfont__get_capability (capability);
+
+  if (cap && cap->language != Mnil)
+    {
+      plist = ft_list_language (cap->language);
+      if (! plist)
+       return NULL;
+      plist = mplist_copy (plist);
+    }
+
+  if (cap && cap->script != Mnil)
+    {
+      if (! plist)
+       {
+         plist = ft_list_script (cap->script);
+         if (! plist)
+           return NULL;
+         plist = mplist_copy (plist);
+       }
+      else
+       {
+         for (pl = plist; ! MPLIST_TAIL_P (pl);)
+           {
+             if (ft_check_script (MPLIST_VAL (pl), cap->script, NULL) < 0)
+               mplist_pop (pl);
+             else
+               pl = MPLIST_NEXT (pl);
+           }
+       }
+
+      if (cap->script_tag)
+       {
+         for (pl = plist; ! MPLIST_TAIL_P (pl);)
+           {
+             if (ft_check_cap_otf (MPLIST_VAL (pl), cap, NULL) < 0)
+               mplist_pop (pl);
+             else
+               pl = MPLIST_NEXT (pl);
+           }
+       }
+
+      if (MPLIST_TAIL_P (plist))
+       {
+         M17N_OBJECT_UNREF (plist);
+         plist = NULL;
+       }
+    }
+
+  mplist_push (ft_capability_list, capability, plist);
+  return plist;
+}
+
+
+static MPlist *
+ft_list_file (MSymbol filename)
+{
+  MPlist *plist = NULL;
+
+  if (! ft_file_list)
+    ft_file_list = mplist ();
+  else if ((plist = mplist_find_by_key (ft_file_list, filename)))
+    return (MPLIST_VAL (plist) ? MPLIST_PLIST (plist) : NULL);
+
+#ifdef HAVE_FONTCONFIG
+  {
+    FcPattern *pattern = FcPatternCreate ();
+    FcObjectSet *os;
+    FcFontSet *fs;
+
+    FcPatternAddString (pattern, FC_FILE, (FcChar8 *) MSYMBOL_NAME (filename));
+    os = FcObjectSetBuild (FC_FAMILY, NULL);
+    fs = FcFontList (fc_config, pattern, os);
+    if (fs->nfont > 0)
+      {
+       char *fam;
+       char *buf;
+       int bufsize = 0;
+
+       if (FcPatternGetString (fs->fonts[0], FC_FAMILY, 0,
+                               (FcChar8 **) &fam) == FcResultMatch)
+         {
+           MSymbol family;
+           MPlist *pl;
+
+           STRDUP_LOWER (buf, bufsize, fam);
+           family = msymbol (buf);
+           pl = ft_list_family (family, 0, 1);
+           MPLIST_DO (pl, MPLIST_PLIST (pl))
+             {
+               MFontFT *ft_info = MPLIST_VAL (pl);
+
+               if (ft_info->font.file == filename)
+                 {
+                   plist = mplist ();
+                   mplist_add (plist, family, ft_info);
+                   break;
+                 }
+             }
+         }
+      }
+  }
+#else  /* not HAVE_FONTCONFIG */
+  {
+    MPlist *pl, *p;
+
+    MPLIST_DO (pl, ft_list_family (Mnil, 0, 1))
+      {
+       MPLIST_DO (p, MPLIST_PLIST (pl))
+         {
+           MFontFT *ft_info = MPLIST_VAL (pl);
+
+           if (ft_info->font.file == filename)
+             {
+               plist = mplist ();
+               mplist_add (plist, MPLIST_KEY (pl), ft_info);
+               break;
+             }
+         }
+       if (plist)
+         break;
+      }
+  }
+#endif /* not HAVE_FONTCONFIG */
+
+  mplist_push (ft_file_list, filename, plist);
+  return plist;
+}
+
+/* The FreeType font driver function SELECT.  */
+
+static MFont *
+ft_select (MFrame *frame, MFont *font, int limited_size)
+{
+  MFont *found = NULL;
+#ifdef HAVE_FONTCONFIG
+  MPlist *plist, *pl;
+  MFontFT *ft_info;
+  int check_font_property = 1;
+
+  if (font->file != Mnil)
+    {
+      plist = ft_list_file (font->file);
+      if (! plist)
+       return NULL;
+      check_font_property = 0;
+    }
+  else
+    {
+      MSymbol family = FONT_PROPERTY (font, MFONT_FAMILY);
+
+      if (family)
+       plist = MPLIST_PLIST (ft_list_family (family, 1, 1));
+      else
+       plist = ft_list_default ();
+      if (MPLIST_TAIL_P (plist))
+       return NULL;
+    }
+
+  plist = mplist_copy (plist);
+
+  if (font->capability != Mnil)
+    {
+      MFontCapability *cap = mfont__get_capability (font->capability);
+
+      for (pl = plist; ! MPLIST_TAIL_P (pl);)
+       {
+         if (cap->script_tag && ft_check_cap_otf (MPLIST_VAL (pl), cap, NULL) < 0)
+           {
+             mplist_pop (pl);
+             continue;
+           }
+         if (cap->language
+             && ft_check_language (MPLIST_VAL (pl), cap->language, NULL) < 0)
+           mplist_pop (pl);
+         else
+           pl = MPLIST_NEXT (pl);
+       }
+    }
+
+  if (check_font_property)
+    {
+      MSymbol weight = FONT_PROPERTY (font, MFONT_WEIGHT);
+      MSymbol style = FONT_PROPERTY (font, MFONT_STYLE);
+      MSymbol stretch = FONT_PROPERTY (font, MFONT_STRETCH);
+      MSymbol alternate_weight = Mnil;
+
+      if (weight == Mnormal)
+       alternate_weight = Mmedium;
+      else if (weight == Mmedium)
+       alternate_weight = Mnormal;
+      if (weight != Mnil || style != Mnil || stretch != Mnil || font->size > 0)
+       for (pl = plist; ! MPLIST_TAIL_P (pl); )
+         {
+           ft_info = MPLIST_VAL (pl);
+           if ((weight != Mnil
+                && (weight != FONT_PROPERTY (&ft_info->font, MFONT_WEIGHT)
+                    && alternate_weight != FONT_PROPERTY (&ft_info->font, MFONT_WEIGHT)))
+               || (style != Mnil
+                   && style != FONT_PROPERTY (&ft_info->font, MFONT_STYLE))
+               || (stretch != Mnil
+                   && stretch != FONT_PROPERTY (&ft_info->font,
+                                                MFONT_STRETCH))
+               || (font->size > 0
+                   && ft_info->font.size > 0
+                   && ft_info->font.size != font->size))
+             mplist_pop (pl);
+           else
+             pl = MPLIST_NEXT (pl);
+         }
+    }
+
+  MPLIST_DO (pl, plist)
+    {
+      font = MPLIST_VAL (plist);
+      if (limited_size == 0
+         || font->size == 0
+         || font->size <= limited_size)
+       {
+         found = font;
+         break;
+       }
+    }
+  M17N_OBJECT_UNREF (plist);
+#endif /* HAVE_FONTCONFIG */
+  return found;
+}
+
+
+static MRealizedFont *
+ft_open (MFrame *frame, MFont *font, MFont *spec, MRealizedFont *rfont)
+{
+  MFontFT *ft_info = (MFontFT *) font;
+  int reg = spec->property[MFONT_REGISTRY];
+  MSymbol registry = FONT_PROPERTY (spec, MFONT_REGISTRY);
+  MRealizedFontFT *ft_rfont;
+  FT_Face ft_face;
+  MPlist *plist, *charmap_list = NULL;
+  int charmap_index;
+  int size;
+
+  if (font->size)
+    /* non-scalable font */
+    size = font->size;
+  else if (spec->size)
+    {
+      int ratio = mfont_resize_ratio (font);
+
+      size = ratio == 100 ? spec->size : spec->size * ratio / 100;
+    }
+  else
+    size = 120;
+
+  if (rfont)
+    {
+      charmap_list = ((MRealizedFontFT *) rfont->info)->charmap_list;
+      for (; rfont; rfont = rfont->next)
+       if (rfont->font == font
+           && (rfont->font->size ? rfont->font->size == size
+               : rfont->spec.size == size)
+           && rfont->spec.property[MFONT_REGISTRY] == reg
+           && rfont->driver == &mfont__ft_driver)
+         return rfont;
+    }
+
+  MDEBUG_DUMP (" [FONT-FT] opening ", "", mdebug_dump_font (&ft_info->font));
+
+  if (FT_New_Face (ft_library, MSYMBOL_NAME (ft_info->font.file), 0,
+                  &ft_face))
+    {
+      font->type = MFONT_TYPE_FAILURE;
+      MDEBUG_PRINT ("  no (FT_New_Face)\n");
+      return NULL;
+    }
+  if (charmap_list)
+    M17N_OBJECT_REF (charmap_list);
+  else
+    charmap_list = ft_get_charmaps (ft_face);
+  if (registry == Mnil)
+    registry = Municode_bmp;
+  plist = mplist_find_by_key (charmap_list, registry);
+  if (! plist)
+    {
+      FT_Done_Face (ft_face);
+      M17N_OBJECT_UNREF (charmap_list);
+      MDEBUG_PRINT1 ("  no (%s)\n", MSYMBOL_NAME (registry));
+      return NULL;
+    }
+  charmap_index = (int) MPLIST_VAL (plist);
+  if ((charmap_index >= 0
+       && FT_Set_Charmap (ft_face, ft_face->charmaps[charmap_index]))
+      || FT_Set_Pixel_Sizes (ft_face, 0, size / 10))
+    {
+      FT_Done_Face (ft_face);
+      M17N_OBJECT_UNREF (charmap_list);
+      font->type = MFONT_TYPE_FAILURE;
+      MDEBUG_PRINT1 ("  no (size %d)\n", size);
+      return NULL;
+    }
+
+  M17N_OBJECT (ft_rfont, free_ft_rfont, MERROR_FONT_FT);
+  ft_rfont->ft_face = ft_face;
+  ft_rfont->charmap_list = charmap_list;
+  MSTRUCT_CALLOC (rfont, MERROR_FONT_FT);
+  rfont->id = ft_info->font.file;
+  rfont->spec = *font;
+  rfont->spec.type = MFONT_TYPE_REALIZED;
+  rfont->spec.property[MFONT_REGISTRY] = reg;
+  rfont->spec.size = size;
+  rfont->frame = frame;
+  rfont->font = font;
+  rfont->driver = &mfont__ft_driver;
+  rfont->info = ft_rfont;
+  rfont->fontp = ft_face;
+  rfont->ascent = ft_face->size->metrics.ascender;
+  rfont->descent = - ft_face->size->metrics.descender;
+  rfont->max_advance = ft_face->size->metrics.max_advance;
+  rfont->baseline_offset = 0;
+  rfont->x_ppem = ft_face->size->metrics.x_ppem;
+  rfont->y_ppem = ft_face->size->metrics.y_ppem;
+#ifdef HAVE_FTBDF_H
+  {
+    BDF_PropertyRec prop;
+
+    if (! FT_IS_SCALABLE (ft_face)
+       && FT_Get_BDF_Property (ft_face, "_MULE_BASELINE_OFFSET", &prop) == 0)
+      {
+       rfont->baseline_offset = prop.u.integer << 6;
+       rfont->ascent += prop.u.integer << 6;
+       rfont->descent -= prop.u.integer << 6;
+      }
+  }
+#endif /* HAVE_FTBDF_H */
+  if (FT_IS_SCALABLE (ft_face))
+    rfont->average_width = 0;
+  else
+    rfont->average_width = ft_face->available_sizes->width << 6;
+  rfont->next = MPLIST_VAL (frame->realized_font_list);
+  MPLIST_VAL (frame->realized_font_list) = rfont;
+  MDEBUG_PRINT ("  ok\n");
+  return rfont;
+}
+
+/* The FreeType font driver function FIND_METRIC.  */
+
+static void
+ft_find_metric (MRealizedFont *rfont, MGlyphString *gstring,
+               int from, int to)
+{
+  FT_Face ft_face = rfont->fontp;
+  MGlyph *g = MGLYPH (from), *gend = MGLYPH (to);
+
+  for (; g != gend; g++)
+    {
+      if (g->g.measured)
+       continue;
+      if (g->g.code == MCHAR_INVALID_CODE)
+       {
+         if (FT_IS_SCALABLE (ft_face))
+           {
+             g->g.lbearing = 0;
+             g->g.rbearing = ft_face->size->metrics.max_advance;
+             g->g.xadv = g->g.rbearing;
+             g->g.ascent = ft_face->size->metrics.ascender;
+             g->g.descent = - ft_face->size->metrics.descender;
+           }
+         else
+           {
+#ifdef HAVE_FTBDF_H
+             BDF_PropertyRec prop;
+#endif /* HAVE_FTBDF_H */
+
+             g->g.lbearing = 0;
+             g->g.rbearing = g->g.xadv = ft_face->available_sizes->width << 6;
+#ifdef HAVE_FTBDF_H
+             if (FT_Get_BDF_Property (ft_face, "ASCENT", &prop) == 0)
+               {
+                 g->g.ascent = prop.u.integer << 6;
+                 FT_Get_BDF_Property (ft_face, "DESCENT", &prop);
+                 g->g.descent = prop.u.integer << 6;
+                 if (FT_Get_BDF_Property (ft_face, "_MULE_BASELINE_OFFSET",
+                                          & prop) == 0)
+                   {
+                     g->g.ascent += prop.u.integer << 6;
+                     g->g.descent -= prop.u.integer << 6;
+                   }
+               }
+             else
+#endif /* HAVE_FTBDF_H */
+               {
+                 g->g.ascent = ft_face->available_sizes->height << 6;
+                 g->g.descent = 0;
+               }
+           }
+       }
+      else
+       {
+         FT_Glyph_Metrics *metrics;
+
+         FT_Load_Glyph (ft_face, (FT_UInt) g->g.code, FT_LOAD_DEFAULT);
+         metrics = &ft_face->glyph->metrics;
+         g->g.lbearing = metrics->horiBearingX;
+         g->g.rbearing = metrics->horiBearingX + metrics->width;
+         g->g.xadv = metrics->horiAdvance;
+         g->g.ascent = metrics->horiBearingY;
+         g->g.descent = metrics->height - metrics->horiBearingY;
+       }
+      g->g.yadv = 0;
+      g->g.ascent += rfont->baseline_offset;
+      g->g.descent -= rfont->baseline_offset;
+      g->g.measured = 1;
+    }
+}
+
+static int
+ft_has_char (MFrame *frame, MFont *font, MFont *spec, int c, unsigned code)
+{
+  MRealizedFont *rfont = NULL;
+  MRealizedFontFT *ft_rfont;
+  FT_UInt idx;
+
+  if (font->type == MFONT_TYPE_REALIZED)
+    rfont = (MRealizedFont *) font;
+  else if (font->type == MFONT_TYPE_OBJECT)
+    {
+      for (rfont = MPLIST_VAL (frame->realized_font_list); rfont;
+          rfont = rfont->next)
+       if (rfont->font == font && rfont->driver == &mfont__ft_driver)
+         break;
+      if (! rfont)
+       {
+#ifdef HAVE_FONTCONFIG
+         MFontFT *ft_info = (MFontFT *) font;
+
+         if (! ft_info->charset)
+           {
+             FcPattern *pat = FcPatternBuild (NULL, FC_FILE, FcTypeString,
+                                              MSYMBOL_NAME (font->file),
+                                              NULL);
+             FcObjectSet *os = FcObjectSetBuild (FC_CHARSET, NULL);
+             FcFontSet *fs = FcFontList (fc_config, pat, os);
+
+             if (fs->nfont > 0
+                 && FcPatternGetCharSet (fs->fonts[0], FC_CHARSET, 0,
+                                         &ft_info->charset) == FcResultMatch)
+               ft_info->charset = FcCharSetCopy (ft_info->charset);
+             else
+               ft_info->charset = FcCharSetCreate ();
+             FcFontSetDestroy (fs);
+             FcObjectSetDestroy (os);
+             FcPatternDestroy (pat);
+           }
+         return (FcCharSetHasChar (ft_info->charset, (FcChar32) c) == FcTrue);
+#else  /* not HAVE_FONTCONFIG */
+         rfont = ft_open (frame, font, spec, NULL);
+#endif /* not HAVE_FONTCONFIG */
+       }
+    }
+  else
+    MFATAL (MERROR_FONT_FT);
+
+  if (! rfont)
+    return 0;
+  ft_rfont = rfont->info;
+  idx = FT_Get_Char_Index (ft_rfont->ft_face, (FT_ULong) code);
+  return (idx != 0);
+}
+
+/* The FreeType font driver function ENCODE_CHAR.  */
+
+static unsigned
+ft_encode_char (MFrame *frame, MFont *font, MFont *spec, unsigned code)
+{
+  MRealizedFont *rfont;
+  MRealizedFontFT *ft_rfont;
+  FT_UInt idx;
+
+  if (font->type == MFONT_TYPE_REALIZED)
+    rfont = (MRealizedFont *) font;
+  else if (font->type == MFONT_TYPE_OBJECT)
+    {
+      for (rfont = MPLIST_VAL (frame->realized_font_list); rfont;
+          rfont = rfont->next)
+       if (rfont->font == font && rfont->driver == &mfont__ft_driver)
+         break;
+      if (! rfont)
+       {
+         rfont = ft_open (frame, font, spec, NULL);
+         if (! rfont)
+           return -1;
+       }
+    }
+  else
+    MFATAL (MERROR_FONT_FT);
+
+  ft_rfont = rfont->info;
+  idx = FT_Get_Char_Index (ft_rfont->ft_face, (FT_ULong) code);
+  return (idx ? (unsigned) idx : MCHAR_INVALID_CODE);
+}
+
+/* The FreeType font driver function RENDER.  */
+
+#define NUM_POINTS 0x1000
+
+typedef struct {
+  MDrawPoint points[NUM_POINTS];
+  MDrawPoint *p;
+} MPointTable;
+
+static void
+ft_render (MDrawWindow win, int x, int y,
+          MGlyphString *gstring, MGlyph *from, MGlyph *to,
+          int reverse, MDrawRegion region)
+{
+  FT_Face ft_face;
+  MRealizedFace *rface = from->rface;
+  MFrame *frame = rface->frame;
+  FT_Int32 load_flags = FT_LOAD_RENDER;
+  MGlyph *g;
+  int i, j;
+  MPointTable point_table[8];
+  int baseline_offset;
+  int pixel_mode = -1;
+
+  if (from == to)
+    return;
+
+  /* It is assured that the all glyphs in the current range use the
+     same realized face.  */
+  ft_face = rface->rfont->fontp;
+  baseline_offset = rface->rfont->baseline_offset >> 6;
+
+  if (! gstring->anti_alias)
+    {
+#ifdef FT_LOAD_TARGET_MONO
+      load_flags |= FT_LOAD_TARGET_MONO;
+#else
+      load_flags |= FT_LOAD_MONOCHROME;
+#endif
+    }
+
+  for (i = 0; i < 8; i++)
+    point_table[i].p = point_table[i].points;
+
+  for (g = from; g < to; x += g++->g.xadv)
+    {
+      unsigned char *bmp;
+      int intensity;
+      MPointTable *ptable;
+      int xoff, yoff;
+      int width, pitch;
+
+      FT_Load_Glyph (ft_face, (FT_UInt) g->g.code, load_flags);
+      if (pixel_mode < 0)
+       pixel_mode = ft_face->glyph->bitmap.pixel_mode;
+      yoff = y - ft_face->glyph->bitmap_top + g->g.yoff;
+      bmp = ft_face->glyph->bitmap.buffer;
+      width = ft_face->glyph->bitmap.width;
+      pitch = ft_face->glyph->bitmap.pitch;
+
+      if (pixel_mode != FT_PIXEL_MODE_MONO)
+       for (i = 0; i < ft_face->glyph->bitmap.rows;
+            i++, bmp += ft_face->glyph->bitmap.pitch, yoff++)
+         {
+           xoff = x + ft_face->glyph->bitmap_left + g->g.xoff;
+           for (j = 0; j < width; j++, xoff++)
+             {
+               intensity = bmp[j] >> 5;
+               if (intensity)
+                 {
+                   ptable = point_table + intensity;
+                   ptable->p->x = xoff;
+                   ptable->p->y = yoff - baseline_offset;
+                   ptable->p++;
+                   if (ptable->p - ptable->points == NUM_POINTS)
+                     {
+                       (*frame->driver->draw_points)
+                         (frame, win, rface,
+                          reverse ? 7 - intensity : intensity,
+                          ptable->points, NUM_POINTS, region);
+                       ptable->p = ptable->points;
+                     }
+                 }
+             }
+         }
+      else
+       for (i = 0; i < ft_face->glyph->bitmap.rows;
+            i++, bmp += ft_face->glyph->bitmap.pitch, yoff++)
+         {
+           xoff = x + ft_face->glyph->bitmap_left + g->g.xoff;
+           for (j = 0; j < width; j++, xoff++)
+             {
+               intensity = bmp[j / 8] & (1 << (7 - (j % 8)));
+               if (intensity)
+                 {
+                   ptable = point_table;
+                   ptable->p->x = xoff;
+                   ptable->p->y = yoff - baseline_offset;
+                   ptable->p++;
+                   if (ptable->p - ptable->points == NUM_POINTS)
+                     {
+                       (*frame->driver->draw_points) (frame, win, rface,
+                                          reverse ? 0 : 7,
+                                          ptable->points, NUM_POINTS, region);
+                       ptable->p = ptable->points;
+                     }             
+                 }
+             }
+       }
+    }
+
+  if (pixel_mode != FT_PIXEL_MODE_MONO)
+    {
+      for (i = 1; i < 8; i++)
+       if (point_table[i].p != point_table[i].points)
+         (*frame->driver->draw_points) (frame, win, rface, reverse ? 7 - i : i,
+                            point_table[i].points,
+                            point_table[i].p - point_table[i].points, region);
+    }
+  else
+    {
+      if (point_table[0].p != point_table[0].points)
+       (*frame->driver->draw_points) (frame, win, rface, reverse ? 0 : 7,
+                          point_table[0].points,
+                          point_table[0].p - point_table[0].points, region);
+    }
+}
+
+static int
+ft_list (MFrame *frame, MPlist *plist, MFont *font, int maxnum)
+{
+  MPlist *pl = NULL, *p;
+  int num = 0;
+  MPlist *file_list = NULL;
+  MPlist *family_list = NULL, *capability_list = NULL;
+  MSymbol registry = Mnil;
+
+  MDEBUG_DUMP (" [FONT-FT] listing ", "", mdebug_dump_font (font));
+
+  if (font)
+    {
+      MSymbol family;
+
+      registry = FONT_PROPERTY (font, MFONT_REGISTRY);
+      if (registry != Mnil && registry != Miso8859_1)
+       {
+         char *reg = MSYMBOL_NAME (registry);
+
+         if (strncmp (reg, "unicode-", 8)
+             && strncmp (reg, "apple-roman", 11)
+             && (reg[0] < '0' || reg[0] > '9' || reg[1] != '-'))
+           goto done;
+       }
+
+      if (font->file != Mnil
+         && ! (file_list = ft_list_file (font->file)))
+       goto done;
+      family = FONT_PROPERTY (font, MFONT_FAMILY);
+      if (family != Mnil
+         && (family_list = MPLIST_PLIST (ft_list_family (family, 1, 1)))
+         && MPLIST_TAIL_P (family_list))
+       goto done;
+      if (font->capability != Mnil)
+       {
+         capability_list = ft_list_capability (font->capability);
+         if (! capability_list || MPLIST_TAIL_P (capability_list))
+           goto done;
+       }
+    }
+
+  if (! file_list && ! family_list && ! capability_list)
+    {
+      /* No restriction.  Get all fonts.  */
+      pl = mplist ();
+      MPLIST_DO (family_list, ft_list_family (Mnil, 0, 1))
+       {
+         MPLIST_DO (p, MPLIST_PLIST (family_list))
+           mplist_push (pl, MPLIST_KEY (p), MPLIST_VAL (p));
+       }
+    }
+  else
+    {
+      if (file_list)
+       {
+         pl = mplist ();
+         mplist_push (pl, MPLIST_KEY (file_list), MPLIST_VAL (file_list));
+       }
+      if (family_list)
+       {
+         if (pl)
+           for (p = pl; ! MPLIST_TAIL_P (p);)
+             {
+               if (mplist_find_by_value (family_list, MPLIST_VAL (p)))
+                 p = MPLIST_NEXT (p);
+               else
+                 mplist_pop (p);
+             }
+         else
+           {
+             pl = mplist ();
+             MPLIST_DO (p, family_list)
+               mplist_push (pl, MPLIST_KEY (p), MPLIST_VAL (p));
+           }
+       }
+      if (capability_list)
+       {
+         if (pl)
+           for (p = pl; ! MPLIST_TAIL_P (p);)
+             {
+               if (mplist_find_by_value (capability_list, MPLIST_VAL (p)))
+                 p = MPLIST_NEXT (p);
+               else
+                 mplist_pop (p);
+             }
+         else
+           {
+             pl = mplist ();
+             MPLIST_DO (p, capability_list)
+               mplist_push (pl, MPLIST_KEY (p), MPLIST_VAL (p));
+           }
+       }
+    }
+             
+  if (font
+      && (font->property[MFONT_WEIGHT] + font->property[MFONT_STYLE]
+         + font->property[MFONT_STRETCH] + font->size) > 0)
+    {
+      MSymbol weight = FONT_PROPERTY (font, MFONT_WEIGHT);
+      MSymbol style = FONT_PROPERTY (font, MFONT_STYLE);
+      MSymbol stretch = FONT_PROPERTY (font, MFONT_STRETCH);
+      int size = font->size;
+
+      for (p = pl; ! MPLIST_TAIL_P (p); )
+       {
+         MFontFT *ft_info = MPLIST_VAL (p);
+
+         if ((weight != Mnil
+              && weight != FONT_PROPERTY (&ft_info->font, MFONT_WEIGHT))
+             || (style != Mnil
+                 && style != FONT_PROPERTY (&ft_info->font, MFONT_STYLE))
+             || (stretch != Mnil
+                 && stretch != FONT_PROPERTY (&ft_info->font,
+                                              MFONT_STRETCH))
+             || (size > 0
+                 && ft_info->font.size > 0
+                 && ft_info->font.size != size))
+           mplist_pop (p);
+         else
+           p = MPLIST_NEXT (p);
+       }
+    }
+
+  MPLIST_DO (p, pl)
+    {
+      mplist_push (plist, MPLIST_KEY (p), MPLIST_VAL (p));
+      num++;
+      if (maxnum && maxnum <= num)
+       break;
+    }
+  M17N_OBJECT_UNREF (pl);
+
+ done:
+  MDEBUG_PRINT1 ("  %d found\n", num);
+  return num;
+}
+
+static void
+ft_list_family_names (MFrame *frame, MPlist *plist)
+{
+  MPlist *pl;
+
+  if (! ft_font_list)
+    {
+#ifdef HAVE_FONTCONFIG
+      fc_init_font_list ();
+#else  /* not HAVE_FONTCONFIG */
+      ft_init_font_list ();
+#endif /* not HAVE_FONTCONFIG */
+    }
+
+  MPLIST_DO (pl, ft_font_list)
+    {
+      MSymbol family = MPLIST_KEY (pl);
+      MPlist *p;
+
+#ifdef HAVE_FONTCONFIG
+      if (msymbol_get (family, Mgeneric_family) != Mnil)
+       continue;
+#endif /* HAVE_FONTCONFIG */
+      MPLIST_DO (p, plist)
+       {
+         MSymbol sym = MPLIST_SYMBOL (p);
+
+         if (sym == family)
+           break;
+         if (strcmp (MSYMBOL_NAME (sym), MSYMBOL_NAME (family)) > 0)
+           {
+             mplist_push (p, Msymbol, family);
+             break;
+           }
+       }
+      if (MPLIST_TAIL_P (p))
+       mplist_push (p, Msymbol, family);
+    }
+}
+
+static int 
+ft_check_capability (MRealizedFont *rfont, MSymbol capability)
+{
+  MFontFT *ft_info = (MFontFT *) rfont->font;
+  MRealizedFontFT *ft_rfont = rfont->info;
+  MFontCapability *cap = mfont__get_capability (capability);
+
+  if (cap->script_tag)
+    {
+      if (ft_check_cap_otf (ft_info, cap, ft_rfont->ft_face) < 0)
+       return -1;
+    }
+  else if (cap->script != Mnil
+          && ft_check_script (ft_info, cap->script, ft_rfont->ft_face) < 0)
+    return -1;
+  if (cap->language != Mnil
+      && ft_check_language (ft_info, cap->language, ft_rfont->ft_face) < 0)
+    return -1;
+  return 0;
+}
+
+static MRealizedFont *
+ft_encapsulate (MFrame *frame, MSymbol data_type, void *data)
+{
+  MFontFT *ft_info;
+  MRealizedFont *rfont;
+  MRealizedFontFT *ft_rfont;
+  FT_Face ft_face;
+
+  if (data_type == Mfontconfig)
+    {
+#ifdef HAVE_FONTCONFIG
+      FcPattern *pattern = data;
+
+      if (FcPatternGetFTFace (pattern, FC_FT_FACE, 0, &ft_face)
+         != FcResultMatch)
+       return NULL;
+      ft_info = fc_gen_font (pattern, NULL);
+#else  /* not HAVE_FONTCONFIG */
+      return NULL;
+#endif /* not HAVE_FONTCONFIG */
+    }
+  else if (data_type == Mfreetype)
+    {
+      ft_face = data;
+      ft_info = ft_gen_font (ft_face);
+    }
+  else
+    return NULL;
+
+  M17N_OBJECT (ft_rfont, free_ft_rfont, MERROR_FONT_FT);
+  ft_rfont->ft_face = ft_face;
+  ft_rfont->face_encapsulated = 1;
+
+  MDEBUG_DUMP (" [FONT-FT] encapsulating ", (char *) ft_face->family_name,);
+
+  MSTRUCT_CALLOC (rfont, MERROR_FONT_FT);
+  rfont->id = ft_info->font.file;
+  rfont->font = (MFont *) ft_info;
+  rfont->info = ft_rfont;
+  rfont->fontp = ft_face;
+  rfont->driver = &mfont__ft_driver;
+  rfont->spec = ft_info->font;
+  rfont->spec.type = MFONT_TYPE_REALIZED;
+  rfont->frame = frame;
+  rfont->ascent = ft_face->size->metrics.ascender >> 6;
+  rfont->descent = - ft_face->size->metrics.descender >> 6;
+  rfont->max_advance = ft_face->size->metrics.max_advance >> 6;
+  rfont->baseline_offset = 0;
+  rfont->x_ppem = ft_face->size->metrics.x_ppem;
+  rfont->y_ppem = ft_face->size->metrics.y_ppem;
+#ifdef HAVE_FTBDF_H
+  {
+    BDF_PropertyRec prop;
+
+    if (! FT_IS_SCALABLE (ft_face)
+       && FT_Get_BDF_Property (ft_face, "_MULE_BASELINE_OFFSET", &prop) == 0)
+      {
+       rfont->baseline_offset = prop.u.integer << 6;
+       rfont->ascent += prop.u.integer << 6;
+       rfont->descent -= prop.u.integer << 6;
+      }
+  }
+#endif /* HAVE_FTBDF_H */
+  if (FT_IS_SCALABLE (ft_face))
+    rfont->average_width = 0;
+  else
+    rfont->average_width = ft_face->available_sizes->width << 6;
+  rfont->next = MPLIST_VAL (frame->realized_font_list);
+  MPLIST_VAL (frame->realized_font_list) = rfont;
+
+  return rfont;
+}
+
+static void
+ft_close (MRealizedFont *rfont)
+{
+  if (! rfont->encapsulating)
+    return;
+  free (rfont->font);
+  M17N_OBJECT_UNREF (rfont->info);
+  free (rfont);
+}
+
+static OTF *
+get_otf (MFLTFont *font, FT_Face *ft_face)
+{
+  MRealizedFont *rfont = ((MFLTFontForRealized *) font)->rfont;
+  MFontFT *ft_info = (MFontFT *) rfont->font;
+  MRealizedFontFT *ft_rfont = rfont->info;
+  OTF *otf = ft_info->otf;
+
+  if (! otf)
+    {
+#if (LIBOTF_MAJOR_VERSION > 0 || LIBOTF_MINOR_VERSION > 9 || LIBOTF_RELEASE_NUMBER > 4)
+      otf = OTF_open_ft_face (ft_rfont->ft_face);
+#else
+      otf = OTF_open (MSYMBOL_NAME (ft_info->font.file));
+#endif
+      if (! otf || OTF_get_table (otf, "head") < 0)
+       otf = invalid_otf;
+      ft_info->otf = otf;
+    }
+  if (ft_face)
+    *ft_face = ft_rfont->ft_face;
+  return (otf == invalid_otf ? NULL : otf);
+}
+
+static int 
+ft_check_otf (MFLTFont *font, MFLTOtfSpec *spec)
+{
+#ifdef HAVE_OTF
+  OTF_Tag *tags;
+  int i, n, negative;
+  OTF *otf = get_otf (font, NULL);
+
+  if (! otf)
+    goto not_otf;
+  for (i = 0; i < 2; i++)
+    {
+      if (! spec->features[i])
+       continue;
+      for (n = 0; spec->features[i][n]; n++);
+      tags = alloca (sizeof (OTF_Tag) * n);
+      for (n = 0, negative = 0; spec->features[i][n]; n++)
+       {
+         if (spec->features[i][n] == 0xFFFFFFFF)
+           negative = 1;
+         else if (negative)
+           tags[n - 1] = spec->features[i][n] | 0x80000000;
+         else
+           tags[n] = spec->features[i][n];
+       }
+      if (n - negative > 0
+         && OTF_check_features (otf, i == 0, spec->script, spec->langsys,
+                                tags, n - negative) != 1)
+       return 0;
+    }
+  return 1;
+#endif /* HAVE_OTF */
+ not_otf:
+  return ((! spec->features[0] || spec->features[0][0] == 0xFFFFFFFF)
+         && (! spec->features[1] || spec->features[1][0] == 0xFFFFFFFF));
+}
+
+#ifdef HAVE_OTF
+
+#define DEVICE_DELTA(table, size)                              \
+  (((size) >= (table).StartSize && (size) <= (table).EndSize)  \
+   ? (table).DeltaValue[(size) - (table).StartSize] << 6       \
+   : 0)
+
+void
+adjust_anchor (OTF_Anchor *anchor, FT_Face ft_face,
+              unsigned code, int x_ppem, int y_ppem, int *x, int *y)
+{
+  if (anchor->AnchorFormat == 2)
+    {
+      FT_Outline *outline;
+      int ap = anchor->f.f1.AnchorPoint;
+
+      FT_Load_Glyph (ft_face, (FT_UInt) code, FT_LOAD_MONOCHROME);
+      outline = &ft_face->glyph->outline;
+      if (ap < outline->n_points)
+       {
+         *x = outline->points[ap].x << 6;
+         *y = outline->points[ap].y << 6;
+       }
+    }
+  else if (anchor->AnchorFormat == 3)
+    {
+      if (anchor->f.f2.XDeviceTable.offset)
+       *x += DEVICE_DELTA (anchor->f.f2.XDeviceTable, x_ppem);
+      if (anchor->f.f2.YDeviceTable.offset)
+       *y += DEVICE_DELTA (anchor->f.f2.YDeviceTable, y_ppem);
+    }
+}
+#endif /* HAVE_OTF */
+
+static int 
+ft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
+             MFLTGlyphString *in, int from, int to,
+             MFLTGlyphString *out, MFLTGlyphAdjustment *adjustment)
+{
+  int len = to - from;
+  int i, j, gidx;
+#ifdef HAVE_OTF
+  MGlyph *in_glyphs = (MGlyph *) (in->glyphs);
+  MGlyph *out_glyphs = out ? (MGlyph *) (out->glyphs) : NULL;
+  OTF *otf;
+  FT_Face face;
+  OTF_GlyphString otf_gstring;
+  OTF_Glyph *otfg;
+  char script[5], *langsys = NULL;
+  char *gsub_features = NULL, *gpos_features = NULL;
+  unsigned int tag;
+
+  if (len == 0)
+    return from;
+  otf = get_otf (font, &face);
+  if (! otf)
+    goto simple_copy;
+  OTF_tag_name (spec->script, script);
+  if (spec->langsys)
+    {
+      langsys = alloca (5);
+      OTF_tag_name (spec->langsys, langsys);
+    }
+  for (i = 0; i < 2; i++)
+    {
+      char *p;
+
+      if (spec->features[i])
+       {
+         for (j = 0; spec->features[i][j]; j++);
+         if (i == 0)
+           p = gsub_features = alloca (6 * j);
+         else
+           p = gpos_features = alloca (6 * j);
+         for (j = 0; spec->features[i][j]; j++)
+           {
+             if (spec->features[i][j] == 0xFFFFFFFF)
+               *p++ = '*', *p++ = ',';
+             else
+               {
+                 OTF_tag_name (spec->features[i][j], p);
+                 p[4] = ',';
+                 p += 5;
+               }
+           }
+         *--p = '\0';
+       }
+    }
+
+  otf_gstring.size = otf_gstring.used = len;
+  otf_gstring.glyphs = (OTF_Glyph *) malloc (sizeof (OTF_Glyph) * len);
+  memset (otf_gstring.glyphs, 0, sizeof (OTF_Glyph) * len);
+  for (i = 0; i < len; i++)
+    {
+      otf_gstring.glyphs[i].c = ((MGlyph *)in->glyphs)[from + i].g.c & 0x11FFFF;
+      otf_gstring.glyphs[i].glyph_id = ((MGlyph *)in->glyphs)[from + i].g.code;
+    }
+
+  OTF_drive_gdef (otf, &otf_gstring);
+  gidx = out ? out->used : from;
+
+  if (gsub_features)
+    {
+      OTF_Feature *features;
+      MGlyph *g;
+
+      if (OTF_drive_gsub_with_log (otf, &otf_gstring, script, langsys,
+                                  gsub_features) < 0)
+       goto simple_copy;
+      features = otf->gsub->FeatureList.Feature;
+      if (out)
+       {
+         if (out->allocated < gidx + otf_gstring.used)
+           return -2;
+         for (i = 0, otfg = otf_gstring.glyphs, g = out_glyphs + gidx;
+              i < otf_gstring.used; i++, otfg++, g++, out->used++)
+           {
+             int feature_idx = otfg->positioning_type >> 4;
+             int j;
+             int min_from, max_to;
+
+             *g = in_glyphs[from + otfg->f.index.from];
+             min_from = g->g.from, max_to = g->g.to;
+             g->g.c = 0;
+             for (j = otfg->f.index.from; j <= otfg->f.index.to; j++)
+               if (in_glyphs[from + j].g.code == otfg->glyph_id)
+                 {
+                   g->g.c = in_glyphs[from + j].g.c;
+                   break;
+                 }
+             if (feature_idx)
+               {
+                 tag = features[feature_idx - 1].FeatureTag;
+                 tag = PACK_OTF_TAG (tag);
+                 g->g.internal = (g->g.internal & ~0x1FFFFFFF) | tag;
+               }
+             for (j = otfg->f.index.from + 1; j <= otfg->f.index.to; j++)
+               {
+                 if (min_from > in_glyphs[from + j].g.from)
+                   min_from = in_glyphs[from + j].g.from;
+                 if (max_to < in_glyphs[from + j].g.to)
+                   max_to = in_glyphs[from + j].g.to;
+               }
+             if (g->g.code != otfg->glyph_id)
+               {
+                 g->g.code = otfg->glyph_id;
+                 g->g.measured = 0;
+               }
+             g->g.from = min_from, g->g.to = max_to;
+           }
+       }
+      else
+       {
+         for (i = 0, otfg = otf_gstring.glyphs; i < otf_gstring.used;
+              i++, otfg++)
+           {
+             int feature_idx = otfg->positioning_type >> 4;
+
+             if (feature_idx)
+               {
+                 tag = features[feature_idx - 1].FeatureTag;
+                 tag = PACK_OTF_TAG (tag);
+                 for (j = otfg->f.index.from; j <= otfg->f.index.to; j++)
+                   {
+                     g = in_glyphs + (from + j);
+                     g->g.internal = (g->g.internal & ~0x1FFFFFFF) | tag;
+                   }
+               }
+           }
+       }
+    }
+  else if (out)
+    {
+      if (out->allocated < gidx + len)
+       return -2;
+      for (i = 0; i < len; i++)
+       out_glyphs[out->used++] = in_glyphs[from + i];
+    }
+
+  if (gpos_features)
+    {
+      OTF_Feature *features;
+      MGlyph *g;
+
+      if (OTF_drive_gpos_with_log (otf, &otf_gstring, script, langsys,
+                                  gpos_features) < 0)
+       return to;
+      features = otf->gpos->FeatureList.Feature;
+      if (out)
+       {
+         MGlyph *base = NULL, *mark = NULL;
+         int x_ppem = face->size->metrics.x_ppem;
+         int y_ppem = face->size->metrics.y_ppem;
+         int x_scale = face->size->metrics.x_scale;
+         int y_scale = face->size->metrics.y_scale;
+
+         for (i = j = 0, otfg = otf_gstring.glyphs, g = out_glyphs + gidx;
+              i < otf_gstring.used; i++, otfg++)
+           {
+             MGlyph *prev;
+             int adjust_idx = otfg->glyph_id ? j : j - 1;
+             int feature_idx = otfg->positioning_type >> 4;
+
+             if (feature_idx)
+               {
+                 tag = features[feature_idx - 1].FeatureTag;
+                 tag = PACK_OTF_TAG (tag);
+                 g->g.internal = (g->g.internal & ~0x1FFFFFFF) | tag;
+               }
+             switch (otfg->positioning_type & 0xF)
+               {
+               case 0:
+                 break;
+               case 1:                 /* Single */
+               case 2:                 /* Pair */
+                 {
+                   int format = otfg->f.f1.format;
+
+                   if (format & OTF_XPlacement)
+                     adjustment[adjust_idx].xoff
+                       += otfg->f.f1.value->XPlacement * x_scale / 0x10000;
+                   if (format & OTF_XPlaDevice)
+                     adjustment[adjust_idx].xoff
+                       += DEVICE_DELTA (otfg->f.f1.value->XPlaDevice, x_ppem);
+                   if (format & OTF_YPlacement)
+                     adjustment[adjust_idx].yoff
+                       -= otfg->f.f1.value->YPlacement * y_scale / 0x10000;
+                   if (format & OTF_YPlaDevice)
+                     adjustment[adjust_idx].yoff
+                       -= DEVICE_DELTA (otfg->f.f1.value->YPlaDevice, y_ppem);
+                   if (format & OTF_XAdvance)
+                     adjustment[adjust_idx].xadv
+                       += otfg->f.f1.value->XAdvance * x_scale / 0x10000;
+                   if (format & OTF_XAdvDevice)
+                     adjustment[adjust_idx].xadv
+                       += DEVICE_DELTA (otfg->f.f1.value->XAdvDevice, x_ppem);
+                   if (format & OTF_YAdvance)
+                     adjustment[adjust_idx].yadv
+                       += otfg->f.f1.value->YAdvance * y_scale / 0x10000;
+                   if (format & OTF_YAdvDevice)
+                     adjustment[adjust_idx].yadv
+                       += DEVICE_DELTA (otfg->f.f1.value->YAdvDevice, y_ppem);
+                   adjustment[adjust_idx].set = 1;
+                 }
+                 break;
+               case 3:         /* Cursive */
+                 /* Not yet supported.  */
+                 break;
+               case 4:         /* Mark-to-Base */
+               case 5:         /* Mark-to-Ligature */
+                 if (! base)
+                   break;
+                 prev = base;
+                 goto label_adjust_anchor;
+               default:                /* i.e. case 6 Mark-to-Mark */
+                 if (! mark)
+                   break;
+                 prev = mark;
+
+               label_adjust_anchor:
+                 {
+                   int base_x, base_y, mark_x, mark_y;
+                   int this_from, this_to;
+                   int k;
+
+                   base_x = otfg->f.f4.base_anchor->XCoordinate * x_scale / 0x10000;
+                   base_y = otfg->f.f4.base_anchor->YCoordinate * y_scale / 0x10000;
+                   mark_x = otfg->f.f4.mark_anchor->XCoordinate * x_scale / 0x10000;
+                   mark_y = otfg->f.f4.mark_anchor->YCoordinate * y_scale / 0x10000;;
+
+                   if (otfg->f.f4.base_anchor->AnchorFormat != 1)
+                     adjust_anchor (otfg->f.f4.base_anchor, face, prev->g.code,
+                                    x_ppem, y_ppem, &base_x, &base_y);
+                   if (otfg->f.f4.mark_anchor->AnchorFormat != 1)
+                     adjust_anchor (otfg->f.f4.mark_anchor, face, g->g.code,
+                                    x_ppem, y_ppem, &mark_x, &mark_y);
+                   adjustment[adjust_idx].xoff = base_x - mark_x;
+                   adjustment[adjust_idx].yoff = - (base_y - mark_y);
+                   adjustment[adjust_idx].back = (g - prev);
+                   adjustment[adjust_idx].xadv = 0;
+                   adjustment[adjust_idx].advance_is_absolute = 1;
+                   adjustment[adjust_idx].set = 1;
+                   this_from = g->g.from;
+                   this_to = g->g.to;
+                   for (k = 0; prev + k < g; k++)
+                     {
+                       if (this_from > prev[k].g.from)
+                         this_from = prev[k].g.from;
+                       if (this_to < prev[k].g.to)
+                         this_to = prev[k].g.to;
+                     }
+                   for (; prev <= g; prev++)
+                     {
+                       prev->g.from = this_from;
+                       prev->g.to = this_to;
+                     }
+                 }
+               }
+             if (otfg->glyph_id)
+               {
+                 if (otfg->GlyphClass == OTF_GlyphClass0)
+                   base = mark = g;
+                 else if (otfg->GlyphClass == OTF_GlyphClassMark)
+                   mark = g;
+                 else
+                   base = g;
+                 j++, g++;
+               }
+           }
+       }
+      else
+       {
+         for (i = 0, otfg = otf_gstring.glyphs; i < otf_gstring.used;
+              i++, otfg++)
+           if (otfg->positioning_type & 0xF)
+             {
+               int feature_idx = otfg->positioning_type >> 4;
+
+               if (feature_idx)
+                 {
+                   tag = features[feature_idx - 1].FeatureTag;
+                   tag = PACK_OTF_TAG (tag);
+                   for (j = otfg->f.index.from; j <= otfg->f.index.to; j++)
+                     {
+                       g = in_glyphs + (from + j);
+                       g->g.internal = (g->g.internal & ~0x1FFFFFFF) | tag;
+                     }
+                 }
+             }
+       }
+    }
+
+  free (otf_gstring.glyphs);
+  return to;
+
+ simple_copy:
+  if (otf_gstring.glyphs)
+    free (otf_gstring.glyphs);
+#endif /* HAVE_OTF */
+  if (out)
+    {
+      if (out->allocated < out->used + len)
+       return -2;
+      font->get_metrics (font, in, from, to);
+      memcpy ((MGlyph *)out->glyphs + out->used, (MGlyph *) in->glyphs + from,
+             sizeof (MGlyph) * len);
+      out->used += len;
+    }
+  return to;
+}
+
+static int 
+ft_try_otf (MFLTFont *font, MFLTOtfSpec *spec,
+           MFLTGlyphString *in, int from, int to)
+{
+  return ft_drive_otf (font, spec, in, from, to, NULL, NULL);
+}
+
+
+#ifdef HAVE_OTF
+static unsigned char *iterate_bitmap;
+
+static int
+iterate_callback (OTF *otf, const char *feature, unsigned glyph_id)
+{
+  if (glyph_id <= otf->cmap->max_glyph_id)
+    iterate_bitmap[glyph_id / 8] |= 1 << (glyph_id % 8);
+  return 0;
+}
+
+static int
+ft_iterate_otf_feature (MFLTFont *font, MFLTOtfSpec *spec,
+                       int from, int to, unsigned char *table)
+{
+  OTF *otf = get_otf (font, NULL);
+  char id[13];
+  int bmp_size;
+  unsigned char *bitmap = NULL;
+  int i, j;
+  char script[5], *langsys = NULL;
+
+  if (! otf)
+    return -1;
+  if (OTF_get_table (otf, "cmap") < 0)
+    return -1;
+  if (! spec->features[0])
+    return -1;
+  strcpy (id, "feature-");
+  id[12] = '\0';
+  OTF_tag_name (spec->script, script);
+  if (spec->langsys)
+    {
+      langsys = alloca (5);
+      OTF_tag_name (spec->langsys, langsys);
+    }
+  bmp_size = (otf->cmap->max_glyph_id / 8) + 1;
+  for (i = 0; spec->features[0][i]; i++)
+    {
+      unsigned char *bmp;
+
+      OTF_tag_name (spec->features[0][i], id + 8);
+      bmp = OTF_get_data (otf, id);
+      if (! bmp)
+       {
+         iterate_bitmap = bmp = calloc (bmp_size, 1);
+         OTF_iterate_gsub_feature (otf, iterate_callback,
+                                   script, langsys, id + 8);
+         OTF_put_data (otf, id, bmp, free);
+       }
+      if (i == 0 && ! spec->features[0][1])
+       /* Single feature */
+       bitmap = bmp;
+      else
+       {
+         if (! bitmap)
+           {
+             bitmap = alloca (bmp_size);
+             memcpy (bitmap, bmp, bmp_size);
+           }
+         else
+           {
+             int j;
+
+             for (j = 0; j < bmp_size; j++)
+               bitmap[j] &= bmp[j];
+           }
+       }
+    }
+  for (i = 0; i < bmp_size; i++)
+    if (bitmap[i])
+      {
+       for (j = 0; j < 8; j++)
+         if (bitmap[i] & (1 << j))
+           {
+             int c = OTF_get_unicode (otf, (i * 8) + j);
+
+             if (c >= from && c <= to)
+               table[c - from] = 1;
+           }
+      }
+  return 0;
+}
+#endif
+
+
+\f
+/* Internal API */
+
+MFontDriver mfont__ft_driver =
+  { ft_select, ft_open, ft_find_metric, ft_has_char, ft_encode_char,
+    ft_render, ft_list, ft_list_family_names, ft_check_capability,
+    ft_encapsulate, ft_close, ft_check_otf, ft_drive_otf, ft_try_otf,
+#ifdef HAVE_OTF
+    ft_iterate_otf_feature
+#endif /* HAVE_OTF */
+  };
+
+int
+mfont__ft_init ()
+{
+  int i;
+
+  if (FT_Init_FreeType (&ft_library) != 0)
+    MERROR (MERROR_FONT_FT, -1);
+
+  for (i = 0; i < ft_to_prop_size; i++)
+    ft_to_prop[i].len = strlen (ft_to_prop[i].ft_style);
+
+  Mmedium = msymbol ("medium");
+  Mr = msymbol ("r");
+  Mnull = msymbol ("");
+
+  M0[0] = msymbol ("0-0");
+  M0[1] = msymbol ("0-1");
+  M0[2] = msymbol ("0-2");
+  M0[3] = msymbol ("0-3");
+  M0[4] = msymbol ("0-4");
+  M3_1 = msymbol ("3-1");
+  M1_0 = msymbol ("1-0");
+
+#ifdef HAVE_FONTCONFIG
+  for (i = 0; i < (sizeof (fc_all_table) / sizeof fc_all_table[0]); i++)
+    {
+      FC_vs_M17N_font_prop *table = fc_all_table[i];
+      int j;
+
+      for (j = 0; table[j].m17n_value; j++)
+       table[j].sym = msymbol (table[j].m17n_value);
+      table[j].sym = table[j - 1].sym;
+    }
+
+  {
+    char *pathname;
+    struct stat buf;
+    MPlist *plist;
+    MSymbol serif, sans_serif, monospace;
+
+    fc_config = FcInitLoadConfigAndFonts ();
+    if (mfont_freetype_path)
+      {
+       MPLIST_DO (plist, mfont_freetype_path)
+         if (MPLIST_STRING_P (plist)
+             && (pathname = MPLIST_STRING (plist))
+             && stat (pathname, &buf) == 0)
+           {
+             FcStrList *strlist = FcConfigGetFontDirs (fc_config);
+             FcChar8 *dir;
+
+             while ((dir = FcStrListNext (strlist)))
+               if (strcmp ((char *) dir, pathname) == 0)
+                 break;
+             if (! dir)
+               FcConfigAppFontAddDir (fc_config, (FcChar8 *) pathname);
+             FcStrListDone (strlist);
+           }
+      }
+    Mgeneric_family = msymbol ("generic famly");
+    serif = msymbol ("serif");
+    msymbol_put (serif, Mgeneric_family, serif);
+    sans_serif = msymbol ("sans-serif");
+    msymbol_put (sans_serif, Mgeneric_family, sans_serif);
+    msymbol_put (msymbol ("sans serif"), Mgeneric_family, sans_serif);
+    msymbol_put (msymbol ("sans"), Mgeneric_family, sans_serif);
+    monospace = msymbol ("monospace");
+    msymbol_put (monospace, Mgeneric_family, monospace);
+    msymbol_put (msymbol ("mono"), Mgeneric_family, monospace);
+  }
+#endif /* HAVE_FONTCONFIG */
+
+  return 0;
+}
+
+void
+mfont__ft_fini ()
+{
+  MPlist *plist, *p;
+
+  if (ft_default_list)
+    {
+      M17N_OBJECT_UNREF (ft_default_list);
+      ft_default_list = NULL;
+    }
+
+  if (ft_font_list)
+    {
+      MPLIST_DO (plist, ft_font_list)
+       {
+         if (MPLIST_VAL (plist))
+           MPLIST_DO (p, MPLIST_VAL (plist))
+             {
+               if (MPLIST_KEY (p) != Mt)
+                 free_ft_info (MPLIST_VAL (p));
+             }
+         M17N_OBJECT_UNREF (MPLIST_VAL (plist));
+       }
+      M17N_OBJECT_UNREF (ft_font_list);
+      ft_font_list = NULL;
+
+      if (ft_language_list)
+       {
+         MPLIST_DO (plist, ft_language_list)
+           M17N_OBJECT_UNREF (MPLIST_VAL (plist));
+         M17N_OBJECT_UNREF (ft_language_list);
+         ft_language_list = NULL;
+       }
+
+      if (ft_script_list)
+       {
+         MPLIST_DO (plist, ft_script_list)
+           M17N_OBJECT_UNREF (MPLIST_VAL (plist));
+         M17N_OBJECT_UNREF (ft_script_list);
+         ft_script_list = NULL;
+       }
+
+      if (ft_capability_list)
+       {
+         MPLIST_DO (plist, ft_capability_list)
+           M17N_OBJECT_UNREF (MPLIST_VAL (plist));
+         M17N_OBJECT_UNREF (ft_capability_list);
+         ft_capability_list = NULL;
+       }
+
+      if (ft_file_list)
+       {
+         MPLIST_DO (plist, ft_file_list)
+           M17N_OBJECT_UNREF (MPLIST_VAL (plist));
+         M17N_OBJECT_UNREF (ft_file_list);
+         ft_file_list = NULL;
+       }
+    }
+  FT_Done_FreeType (ft_library);
+#ifdef HAVE_FONTCONFIG
+  FcConfigDestroy (fc_config);
+  fc_config = NULL;
+#endif /* HAVE_FONTCONFIG */
+  all_fonts_scaned = 0;
+}
+
+#ifdef HAVE_FONTCONFIG
+
+int
+mfont__ft_parse_name (const char *name, MFont *font)
+{
+  FcPattern *pat = FcNameParse ((FcChar8 *) name);
+  FcChar8 *str;
+  int val;
+  double size;
+  char *buf;
+  int bufsize = 0;
+  
+  if (! pat)
+    return -1;
+  if (FcPatternGetString (pat, FC_FOUNDRY, 0, &str) == FcResultMatch)
+    {
+      STRDUP_LOWER (buf, bufsize, (char *) str);
+      mfont__set_property (font, MFONT_FOUNDRY, msymbol (buf));
+    }
+  if (FcPatternGetString (pat, FC_FAMILY, 0, &str) == FcResultMatch)
+    {
+      STRDUP_LOWER (buf, bufsize, (char *) str);
+      mfont__set_property (font, MFONT_FAMILY, msymbol (buf));
+    }
+  if (FcPatternGetInteger (pat, FC_WEIGHT, 0, &val) == FcResultMatch)
+    mfont__set_property (font, MFONT_WEIGHT,
+                        fc_decode_prop (val, fc_weight_table,
+                                        fc_weight_table_size));
+  if (FcPatternGetInteger (pat, FC_SLANT, 0, &val) == FcResultMatch)
+    mfont__set_property (font, MFONT_STYLE,
+                        fc_decode_prop (val, fc_slant_table,
+                                        fc_slant_table_size));
+  if (FcPatternGetInteger (pat, FC_WIDTH, 0, &val) == FcResultMatch)
+    mfont__set_property (font, MFONT_STRETCH,
+                        fc_decode_prop (val, fc_width_table,
+                                        fc_width_table_size));
+  if (FcPatternGetDouble (pat, FC_PIXEL_SIZE, 0, &size) == FcResultMatch)
+    font->size = size * 10 + 0.5;
+  else if (FcPatternGetDouble (pat, FC_SIZE, 0, &size) == FcResultMatch)
+    font->size = - (size * 10 + 0.5);
+  if (FcPatternGetString (pat, FC_FILE, 0, &str) == FcResultMatch)
+    {
+      font->file = msymbol ((char *) str);
+    }
+  mfont__set_property (font, MFONT_REGISTRY, Municode_bmp);
+  font->type = MFONT_TYPE_SPEC;
+  FcPatternDestroy (pat);
+  return 0;
+}
+
+char *
+mfont__ft_unparse_name (MFont *font)
+{
+  FcPattern *pat = fc_get_pattern (font);
+  char *name = (char *) FcNameUnparse (pat);
+
+  FcPatternDestroy (pat);
+  return name;
+}
+#endif /* HAVE_FONTCONFIG */
+
+#endif /* HAVE_FREETYPE */
diff --git a/src/font.c b/src/font.c
new file mode 100644 (file)
index 0000000..be4a270
--- /dev/null
@@ -0,0 +1,3235 @@
+/* font.c -- font module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nFont
+    @brief Font object.
+
+    The m17n GUI API represents a font by an object of the type @c
+    MFont.  A font can have @e font @e properties.  Like other types
+    of properties, a font property consists of a key and a value.  The
+    key of a font property must be one of the following symbols:
+
+    @c Mfoundry, @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
+    @c Madstyle, @c Mregistry, @c Msize, @c Mresolution, @c Mspacing.
+
+    When the key of a font property is @c Msize or @c Mresolution, its
+    value is an integer.  Otherwise the value is a symbol.  
+
+    The notation "xxx property of F" means the font property that
+    belongs to font F and whose key is @c Mxxx.
+
+    The value of a foundry property is a symbol representing font
+    foundry information, e.g. adobe, misc, etc.
+
+    The value of a family property is a symbol representing font family
+    information, e.g. times, helvetica, etc.
+
+    The value of a weight property is a symbol representing weight
+    information, e.g. normal, bold, etc.
+
+    The value of a style property is a symbol representing slant
+    information, e.g. normal, italic, etc.
+
+    The value of a stretch property is a symbol representing width
+    information, e.g. normal, semicondensed, etc.
+
+    The value of an adstyle property is a symbol representing abstract
+    font family information, e.g. serif, sans-serif, etc.
+
+    The value of a registry property is a symbol representing registry
+    information, e.g. iso10646-1, iso8895-1, etc.
+
+    The value of a size property is an integer representing design
+    size in the unit of 1/10 point.
+
+    The value of a resolution property is an integer representing
+    assumed device resolution in the unit of dots per inch (dpi).
+
+    The value of a type property is a symbol indicating a font driver;
+    currently Mx or Mfreetype.
+
+    The m17n library uses font objects for two purposes: to receive
+    font specification from an application program, and to present
+    available fonts to an application program.  When the m17n library
+    presents an available font to an application program, all font
+    properties have a concrete value.
+
+    The m17n library supports three kinds of fonts: Window system fonts,
+    FreeType fonts, and OpenType fonts.
+
+    <ul>
+
+    <li> Window system fonts
+
+    The m17n-X library supports all fonts handled by an X server and
+    an X font server.  The correspondence between XLFD fields and font
+    properties are shown below.
+
+@verbatim
+    XLFD field                                  property
+    ---------------                             --------
+    FOUNDRY                                     foundry
+    FAMILY_NAME                                 family
+    WEIGHT_NAME                                 weight
+    SLANT                                       style
+    SETWIDTH_NAME                               stretch
+    ADD_STYLE_NAME                              adstyle
+    PIXEL_SIZE                                  size
+    RESOLUTION_Y                                resolution
+    CHARSET_REGISTRY-CHARSET_ENCODING           registry
+@endverbatim
+
+    XLFD fields not listed in the above table are ignored.
+
+    <li> FreeType fonts
+
+    The m17n library, if configured to use the FreeType library,
+    supports all fonts that can be handled by the FreeType library.
+    The variable #mfont_freetype_path is initialized properly according
+    to the configuration of the m17n library and the environment
+    variable @c M17NDIR.  See the documentation of the variable for
+    details.
+
+    If the m17n library is configured to use the fontconfig library,
+    in addition to #mfont_freetype_path, all fonts available via
+    fontconfig are supported.
+
+    The family name of a FreeType font corresponds to the family
+    property.  Style names of FreeType fonts correspond to the weight,
+    style, and stretch properties as below.
+
+@verbatim
+    style name          weight  style   stretch
+    ----------          ------  -----   -------
+    Regular             medium  r       normal
+    Italic              medium  i       normal
+    Bold                bold    r       normal
+    Bold Italic         bold    i       normal
+    Narrow              medium  r       condensed
+    Narrow Italic       medium  i       condensed
+    Narrow Bold         bold    r       condensed
+    Narrow Bold Italic  bold    i       condensed
+    Black               black   r       normal
+    Black Italic        black   i       normal
+    Oblique             medium  o       normal
+    BoldOblique         bold    o       normal
+@endverbatim
+
+    Style names not listed in the above table are treated as
+    "Regular".
+
+    Combination of a platform ID and an encoding ID corresponds to the
+    registry property.  For example, if a font has the combination (1
+    1), the registry property is 1-1.  Some frequent combinations have
+    a predefined registry property as below.
+
+@verbatim
+    platform ID         encoding ID     registry property
+    -----------         -----------     -----------------
+    0                   3               unicode-bmp
+    0                   4               unicode-full
+    1                   0               apple-roman
+    3                   1               unicode-bmp
+    3                   1               unicode-full
+@endverbatim
+
+    Thus, a font that has two combinations (1 0) and (3 1) corresponds
+    to four font objects whose registries are 1-0, apple-roman, 3-1,
+    and unicode-bmp.
+
+    <li> OpenType fonts 
+
+    The m17n library, if configured to use both the FreeType library
+    and the OTF library, supports any OpenType fonts.  The list of
+    actually available fonts is created in the same way as in the case
+    of FreeType fonts.  If a fontset instructs to use an OpenType font
+    via an FLT (Font Layout Table), and the FLT has an OTF-related
+    command (e.g. otf:deva), the OTF library converts a character
+    sequence to a glyph code sequence according to the OpenType layout
+    tables of the font, and the FreeType library gives a bitmap image
+    for each glyph.
+
+    </ul>
+
+  */
+
+/***ja
+    @addtogroup m17nFont
+    @brief ¥Õ¥©¥ó¥È¥ª¥Ö¥¸¥§¥¯¥È.
+
+    m17n GUI API ¤Ï¥Õ¥©¥ó¥È¤ò @c MFont ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤È¤·¤Æɽ¸½¤¹¤ë¡£
+    ¥Õ¥©¥ó¥È¤Ï @e ¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£ ¤ò»ý¤Ä¤³¤È¤¬¤Ç¤­¤ë¡£Â¾¤Î¥¿¥¤¥×¤Î¥×
+    ¥í¥Ñ¥Æ¥£Æ±ÍÍ¡¢¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Ï¥­¡¼¤ÈÃͤ«¤é¤Ê¤ê¡¢¥­¡¼¤Ï°Ê²¼¤Î¥·
+    ¥ó¥Ü¥ë¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£
+
+    @c Mfoundry, @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
+    @c Madstyle, @c Mregistry, @c Msize, @c Mresolution, @c Mspacing
+
+    ¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤¬ @c Msize ¤¢¤ë¤¤¤Ï @c Mresolution 
+    ¤Î¾ì¹ç¡¢ÃͤÏÀ°¿ôÃͤǤ¢¤ê¡¢¥­¡¼¤¬¤½¤ì°Ê³°¤Î¾ì¹ç¡¢Ãͤϥ·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    ¡Ö¥Õ¥©¥ó¥È F ¤Î¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¥­¡¼¤¬ @c Mxxx 
+    ¤Ç¤¢¤ë¤â¤Î¡×¤Î¤³¤È¤ò´Êñ¤Ë¡ÖF ¤Î xxx ¥×¥í¥Ñ¥Æ¥£¡×¤È¸Æ¤Ö¤³¤È¤¬¤¢¤ë¡£
+
+    foundry ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢adobe, misc 
+    Åù¤Î¥Õ¥©¥ó¥È¤Î³«È¯¸µ¾ðÊó¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    family ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢times, helvetica 
+    Åù¤Î¥Õ¥©¥ó¥È¥Õ¥¡¥ß¥ê¡¼¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    weight ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢normal, bold Åù¤ÎÂÀ¤µ¤Ë´Ø¤¹¤ë¾ðÊó¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    style ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢normal, italic 
+    Åù¤Î¥¹¥¿¥¤¥ë¤Ë´Ø¤¹¤ë¾ðÊó¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    stretch ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢normal, semicondensed 
+    Åù¤Îʸ»úÉý¤Ë´Ø¤¹¤ë¾ðÊó¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    adstyle ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢serif, sans-serif
+    Åù¤ÎÃê¾ÝŪ¤Ê¥Õ¥©¥ó¥È¥Õ¥¡¥ß¥ê¡¼¤Ë´Ø¤¹¤ë¾ðÊó¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    registry ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢iso10646, iso8895-1
+    Åù¤Î¥ì¥¸¥¹¥È¥ê¾ðÊó¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    size ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢¥Õ¥©¥ó¥È¤Î¥Ç¥¶¥¤¥ó¥µ¥¤¥º¤òɽ¤ï¤¹À°¿ôÃͤǤ¢¤ê¡¢
+    Ã±°Ì¤Ï1/10 ¥Ý¥¤¥ó¥È¤Ç¤¢¤ë¡£
+
+    resolution ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢ÁÛÄꤵ¤ì¤Æ¤¤¤ë¥Ç¥Ð¥¤¥¹¤Î²òÁüÅÙ¤òɽ¤ï¤¹
+    À°¿ôÃͤǤ¢¤ê¡¢Ã±°Ì¤Ïdots per inch (dpi) ¤Ç¤¢¤ë¡£
+
+    type ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢¥Õ¥©¥ó¥È¥É¥é¥¤¥Ð¤ò»Ø¼¨¤·¡¢¸½ºß Mx ¤â¤·¤¯¤Ï
+    Mfreetype ¤Ç¤¢¤ë¡£
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï¥Õ¥©¥ó¥È¥ª¥Ö¥¸¥§¥¯¥È¤ò£²¤Ä¤ÎÌÜŪ¤ÇÍѤ¤¤Æ¤¤¤ë¡£¥¢¥×
+    ¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¥Õ¥©¥ó¥È¤Î»ØÄê¤ò¼õ¤±¼è¤ëÌÜŪ¤È¡¢¥¢¥×¥ê¥±¡¼
+    ¥·¥ç¥ó¥×¥í¥°¥é¥à¤ËÍøÍѲÄǽ¤Ê¥Õ¥©¥ó¥È¤òÄ󼨤¹¤ëÌÜŪ¤Ç¤¢¤ë¡£¥¢¥×¥ê¥±¡¼
+    ¥·¥ç¥ó¥×¥í¥°¥é¥à¤ËÂФ·¤ÆÄ󼨤ò¹Ô¤¦ºÝ¤Ë¤Ï¡¢¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù
+    ¤Æ¶ñÂÎŪ¤ÊÃͤò»ý¤Ä¡£
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï Window ¥·¥¹¥Æ¥à¥Õ¥©¥ó¥È¡¢FreeType¥Õ¥©¥ó¥È¡¢
+    OpenType¥Õ¥©¥ó¥È¤Î£³¼ïÎà¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¡£
+
+    <ul>
+
+    <li> Window ¥·¥¹¥Æ¥à¥Õ¥©¥ó¥È
+
+    m17n X ¥é¥¤¥Ö¥é¥ê¤Ï¡¢X ¥µ¡¼¥Ð¤È X ¥Õ¥©¥ó¥È¥µ¡¼¥Ð¤¬¼è¤ê°·¤¦Á´¤Æ¤Î¥Õ¥©¥ó¥È¤ò¥µ¥Ý¡¼¥È¤¹¤ë¡£
+    XLFD ¤Î³Æ¥Õ¥£¡¼¥ë¥É¤È¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤ÎÂбþ¤Ï°Ê²¼¤ÎÄ̤ꡣ¤³¤Îɽ¤Ë¤Ê¤¤¥Õ¥£¡¼¥ë¥É¤Ï̵»ë¤µ¤ì¤ë¡£
+
+@verbatim
+    XLFD ¥Õ¥£¡¼¥ë¥É                             ¥×¥í¥Ñ¥Æ¥£
+    ---------------                             --------
+    FOUNDRY                                     foundry
+    FAMILY_NAME                                 family
+    WEIGHT_NAME                                 weight
+    SLANT                                       style
+    SETWIDTH_NAME                               stretch
+    ADD_STYLE_NAME                              adstyle
+    PIXEL_SIZE                                  size
+    RESOLUTION_Y                                resolution
+    CHARSET_REGISTRY-CHARSET_ENCODING           registry
+@endverbatim
+
+    <li> FreeType fonts
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï¡¢FreeType ¥é¥¤¥Ö¥é¥ê¤ò»È¤¦¤è¤¦¤ËÀßÄꤵ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
+    FreeType ¤¬°·¤¦¤¹¤Ù¤Æ¤Î¥Õ¥©¥ó¥È¤ò¥µ¥Ý¡¼¥È¤¹¤ë¡£ÊÑ¿ô 
+    #mfont_freetype_path ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤ÎÀßÄê¤È´Ä¶­ÊÑ¿ô @c M17NDIR 
+    ¤Ë±þ¤¸¤Æ½é´ü²½¤µ¤ì¤ë¡£¾ÜºÙ¤ÏÊÑ¿ô¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£
+
+    ¤â¤· m17n ¥é¥¤¥Ö¥é¥ê¤¬ fontconfig ¥é¥¤¥Ö¥é¥ê¤ò»È¤¦¤è¤¦¤ËÀßÄꤵ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
+    #mfont_freetype_path ¤Ë²Ã¤¨¤Æ¡¢ fontconfig ¤Ç»ÈÍѲÄǽ¤Ê¥Õ¥©¥ó¥È¤â¤¹¤Ù¤Æ¥µ¥Ý¡¼¥È¤µ¤ì¤ë¡£
+
+    FreeType ¥Õ¥©¥ó¥È¤Î¥Õ¥¡¥ß¥ê̾¤Ï family ¥×¥í¥Ñ¥Æ¥£¤ËÂбþ¤¹¤ë¡£
+    FreeType ¥Õ¥©¥ó¥È¤Î¥¹¥¿¥¤¥ë̾¤Ï¡¢²¼¤Îɽ¤Î¤è¤¦¤Ë weight, style,
+    stretch ¥×¥í¥Ñ¥Æ¥£¤ËÂбþ¤¹¤ë¡£
+
+@verbatim
+    ¥¹¥¿¥¤¥ë̾          weight  style   stretch
+    ----------          ------  -----   -------
+    Regular             medium  r       normal
+    Italic              medium  i       normal
+    Bold                bold    r       normal
+    Bold Italic         bold    i       normal
+    Narrow              medium  r       condensed
+    Narrow Italic       medium  i       condensed
+    Narrow Bold         bold    r       condensed
+    Narrow Bold Italic  bold    i       condensed
+    Black               black   r       normal
+    Black Italic        black   i       normal
+    Oblique             medium  o       normal
+    BoldOblique         bold    o       normal
+@endverbatim
+
+    ¾å¤Îɽ¤Ë¸½¤ï¤ì¤Ê¤¤¥¹¥¿¥¤¥ë̾¤Ï "Regular" ¤È¤·¤Æ°·¤ï¤ì¤ë¡£
+
+    platform ID ¤È encoding ID ¤ÎÁȤ߹ç¤ï¤»¤¬ registry 
+    ¥×¥í¥Ñ¥Æ¥£¤ËÂбþ¤¹¤ë¡£¤¿¤È¤¨¤Ð¤¢¤ë¥Õ¥©¥ó¥È¤¬ (1 1) ¤È¤¤¤¦ ID ¤ÎÁȹ礻¤ò»ý¤Æ¤Ð¡¢
+    registry ¥×¥í¥Ñ¥Æ¥£¤Ï 1-1 ¤È¤Ê¤ë¡£ÉÑÈˤˤ¢¤é¤ï¤ì¤ëÁȹ礻¤Ë¤Ï°Ê²¼¤Î¤è¤¦¤ÊÄêµÁºÑ¤ß
+    registry ¥×¥í¥Ñ¥Æ¥£ ¤¬Í¿¤¨¤é¤ì¤Æ¤¤¤ë¡£
+
+@verbatim
+    platform ID         encoding ID     registry ¥×¥í¥Ñ¥Æ¥£
+    -----------         -----------     -----------------
+    0                   3               unicode-bmp
+    0                   4               unicode-full
+    1                   0               apple-roman
+    3                   1               unicode-bmp
+    3                   1               unicode-full
+@endverbatim
+
+    ¤·¤¿¤¬¤Ã¤Æ¡¢Æó¤Ä¤ÎÁȹ礻 (1 0) ¡¢(3 1) ¤ò»ý¤Ä¥Õ¥©¥ó¥È¤Ï¡¢¤½¤ì¤¾¤ì
+    registry ¥×¥í¥Ñ¥Æ¥£¤¬ 1-0, apple-roman, 3-1, unicode-bmp
+    ¤Ç¤¢¤ë£´¤Ä¤Î¥Õ¥©¥ó¥È¥ª¥Ö¥¸¥§¥¯¥È¤ËÂбþ¤¹¤ë¡£
+
+    <li> OpenType ¥Õ¥©¥ó¥È
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï¡¢FreeType ¥é¥¤¥Ö¥é¥ê¤È OTF 
+    ¥é¥¤¥Ö¥é¥ê¤ò»ÈÍѤ¹¤ë¤è¤¦¤ËÀßÄꤹ¤ì¤Ð¡¢¤¹¤Ù¤Æ¤Î OpenType 
+    ¥Õ¥©¥ó¥È¤ò¥µ¥Ý¡¼¥È¤¹¤ë¡£¼ÂºÝ¤ËÍøÍѤǤ­¤ë¥Õ¥©¥ó¥È¤Î¥ê¥¹¥È¤Ï FreeType
+    ¥Õ¥©¥ó¥È¤Î¾ì¹ç¤ÈƱÍͤ˺î¤é¤ì¤ë¡£OpenType ¥Õ¥©¥ó¥È¤ò FLT (Font Layout Table)
+    ·Ðͳ¤Ç»ÈÍѤ¹¤ë¤è¤¦¥Õ¥©¥ó¥È¥»¥Ã¥È¤Ë»ØÄꤵ¤ì¤Æ¤ª¤ê¡¢FLT ¤Ë OTF 
+    ´ØÏ¢¤Î¥³¥Þ¥ó¥É (¤¿¤È¤¨¤Ð otf:deva) ¤¬¤¢¤ì¤Ð¡¢OTF ¥é¥¤¥Ö¥é¥ê¤¬¥Õ¥©¥ó¥È¤Î OpenType
+    ¥ì¥¤¥¢¥¦¥È¥Æ¡¼¥Ö¥ë¤Ë½¾¤Ã¤Æʸ»úÎó¤ò¥°¥ê¥Õ¥³¡¼¥ÉÎó¤ËÊÑ´¹¤·¡¢FreeType
+    ¥é¥¤¥Ö¥é¥ê¤¬³Æ¥°¥ê¥Õ¤Î¥Ó¥Ã¥È¥Þ¥Ã¥×¥¤¥á¡¼¥¸¤òÄ󶡤¹¤ë¡£
+
+    </ul>
+
+*/
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "m17n-gui.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "mtext.h"
+#include "symbol.h"
+#include "plist.h"
+#include "charset.h"
+#include "language.h"
+#include "internal-gui.h"
+#include "font.h"
+#include "face.h"
+#include "fontset.h"
+
+MPlist *mfont__driver_list;
+
+static MSymbol M_font_capability, M_font_list, M_font_list_len;
+
+/** Indices to font properties sorted by their priority.  */
+static int font_score_priority[] =
+  { MFONT_SIZE,
+    MFONT_WEIGHT,
+    MFONT_STYLE,
+    MFONT_STRETCH,
+    MFONT_FAMILY,
+    MFONT_ADSTYLE,
+    MFONT_FOUNDRY
+  };
+
+#define FONT_SCORE_PRIORITY_SIZE       \
+  (sizeof font_score_priority / sizeof font_score_priority[0])
+
+/* Indexed by a font property MFONT_XXX, and the value is how many
+   bits to shift the difference of property values.  */
+static int font_score_shift_bits[MFONT_SIZE + 1];
+
+/** Predefined symbols for each font property.  The order is important
+    because the function font_score () decides how well a font matches
+    with a spec by checking how close the index is.  */
+
+static char *common_foundry[] =
+  { "misc",
+    "adobe" };
+static char *common_family[] =
+  { "fixed",
+    "courier",
+    "helvetica",
+    "times" };
+static char *common_weight[] =
+  { "thin"
+    "ultralight",
+    "extralight",
+    "light",
+    "demilight",
+    "book",
+    "regular",
+    "normal",
+    "medium",
+    "demibold",
+    "semibold",
+    "bold",
+    "extrabold",
+    "ultrabold",
+    "black",
+    "heavy" };
+static char *common_style[] =
+  { "o",
+    "i",
+    "slanted",
+    "r",
+    "rslanted",
+    "ri",
+    "ro" };
+static char *common_stretch[] =
+  { "ultracondensed",
+    "extracondensed",
+    "condensed",
+    "narrow",
+    "semicondensed",
+    "normal",
+    "semiexpanded",
+    "expanded",
+    "extraexpanded",
+    "ultraexpanded" };
+static char *common_adstyle[] =
+  { "serif",
+    "",
+    "sans" };
+static char *common_registry[] =
+  { "iso8859-1" };
+
+static unsigned short font_weight_regular;
+static unsigned short font_weight_normal;
+static unsigned short font_weight_medium;
+
+/* Table containing all the data above.  */
+
+struct MFontCommonNames
+{
+  int num;
+  char **names;
+};
+
+static struct MFontCommonNames font_common_names[] =
+  {
+    { sizeof (common_foundry) / sizeof (char *), common_foundry},
+    { sizeof (common_family) / sizeof (char *), common_family},
+    { sizeof (common_weight) / sizeof (char *), common_weight},
+    { sizeof (common_style) / sizeof (char *), common_style},
+    { sizeof (common_stretch) / sizeof (char *), common_stretch},
+    { sizeof (common_adstyle) / sizeof (char *), common_adstyle},
+    { sizeof (common_registry) / sizeof (char *), common_registry}
+  };
+
+
+/** Table of available font property names.  */
+
+MFontPropertyTable mfont__property_table[MFONT_REGISTRY + 1];
+
+
+/** Return the numeric value of SYMBOL as the Nth font property.  */
+
+#define FONT_PROPERTY_NUMERIC(symbol, n)       \
+  ((symbol) == Mnil                            \
+   ? 0                                         \
+   : ((int) msymbol_get ((symbol), mfont__property_table[(n)].property)))
+
+
+/** Set the numeric value of SYMBOL as the Nth font property to NUMERIC.  */
+
+#define SET_FONT_PROPERTY_NUMERIC(symbol, n, numeric)          \
+  msymbol_put((symbol), mfont__property_table[(n)].property,   \
+             (void *) (numeric))
+
+\f
+/* Font selector.  */
+
+struct MFontEncoding {
+  MFont spec;
+  MSymbol encoding_name;
+  MCharset *encoding_charset;
+  MSymbol repertory_name;
+  MCharset *repertory_charset;
+};
+
+static MPlist *font_encoding_list;
+static MFontEncoding default_encoding;
+
+/** Load font encoding table from the data <font encoding>.
+    The data has this form:
+       (FONT-SPEC ENCODING) ...
+    where FONT-SPEC has this form:
+       ([FOUNDRY FAMILY [WEIGHT [STYLE [STRETCH [ADSTYLE]]]]] REGISTRY)
+    All elements are symbols.  */
+
+static int
+load_font_encoding_table ()
+{
+  MDatabase *mdb;
+  MPlist *encoding_list, *plist, *pl, *elt;
+
+  font_encoding_list = pl = mplist ();
+
+  mdb = mdatabase_find (Mfont, msymbol ("encoding"), Mnil, Mnil);
+  if (! mdb
+      || ! (encoding_list = (MPlist *) mdatabase_load (mdb)))
+    MERROR (MERROR_FONT, -1);
+
+  MPLIST_DO (plist, encoding_list)
+    {
+      MFontEncoding *encoding;
+      MSymbol registry;
+
+      MSTRUCT_CALLOC (encoding, MERROR_FONT);
+
+      if (! MPLIST_PLIST_P (plist)
+         || (elt = MPLIST_PLIST (plist), mplist_length (elt) < 2)
+         || ! MPLIST_PLIST_P (elt))
+       MWARNING (MERROR_FONT);
+      registry = mfont__set_spec_from_plist (&encoding->spec,
+                                            MPLIST_PLIST (elt));
+      elt = MPLIST_NEXT (elt);
+      if (! MPLIST_SYMBOL_P (elt))
+       MWARNING (MERROR_FONT);
+      encoding->encoding_name = MPLIST_SYMBOL (elt);
+      elt = MPLIST_NEXT (elt);
+      if (MPLIST_TAIL_P (elt))
+       encoding->repertory_name = encoding->encoding_name;
+      else if (! MPLIST_SYMBOL_P (elt))
+       MWARNING (MERROR_FONT);
+      else
+       encoding->repertory_name = MPLIST_SYMBOL (elt);
+
+      if (registry == Mnil)
+       mplist_push (font_encoding_list, Mt, encoding);
+      else
+       pl = mplist_add (pl, registry, encoding);
+      continue;
+
+    warning:
+      free (encoding);
+    }
+
+  M17N_OBJECT_UNREF (encoding_list);
+  return 0;
+}
+
+typedef struct {
+  MFont spec;
+  int resize;
+} MFontResize;
+
+static MPlist *font_resize_list;
+
+/** Load font size table from the data <font size>.
+    The data has this form:
+       (FONT-SPEC RESIZE-FACTOR) ...
+    where FONT-SPEC has this form:
+       ([FOUNDRY FAMILY [WEIGHT [STYLE [STRETCH [ADSTYLE]]]]] REGISTRY)
+    All elements of FONT-SPEC are symbols.  */
+
+static int
+load_font_resize_table ()
+{
+  MDatabase *mdb;
+  MPlist *size_adjust_list, *plist, *pl, *elt;
+
+  font_resize_list = pl = mplist ();
+
+  mdb = mdatabase_find (Mfont, msymbol ("resize"), Mnil, Mnil);
+  if (! mdb)
+    return -1;
+  if (! (size_adjust_list = (MPlist *) mdatabase_load (mdb)))
+    MERROR (MERROR_FONT, -1);
+
+  MPLIST_DO (plist, size_adjust_list)
+    {
+      MFontResize *resize;
+      MSymbol registry;
+
+      MSTRUCT_CALLOC (resize, MERROR_FONT);
+
+      if (! MPLIST_PLIST_P (plist)
+         || (elt = MPLIST_PLIST (plist), mplist_length (elt) != 2)
+         || ! MPLIST_PLIST_P (elt))
+       MWARNING (MERROR_FONT);
+      registry = mfont__set_spec_from_plist (&resize->spec,
+                                            MPLIST_PLIST (elt));
+      elt = MPLIST_NEXT (elt);
+      if (! MPLIST_INTEGER_P (elt))
+       MWARNING (MERROR_FONT);
+      resize->resize = MPLIST_INTEGER (elt);
+
+      if (registry == Mnil)
+       registry = Mt;
+      pl = mplist_add (pl, registry, resize);
+      continue;
+
+    warning:
+      free (resize);
+    }
+
+  M17N_OBJECT_UNREF (size_adjust_list);
+  return 0;
+}
+
+/** Return a font encoding (and repertory) of FONT.  */
+
+static MFontEncoding *
+find_encoding (MFont *font)
+{
+  MSymbol registry = FONT_PROPERTY (font, MFONT_REGISTRY);
+  MFontEncoding *encoding = NULL;
+  MPlist *plist;
+
+  if (! font_encoding_list)
+    load_font_encoding_table ();
+  plist = font_encoding_list;
+  while (! MPLIST_TAIL_P (plist))
+    {
+      encoding = (MFontEncoding *) MPLIST_VAL (plist);
+      if (mfont__match_p (font, &encoding->spec, MFONT_REGISTRY))
+       {
+         if (encoding->encoding_name != Mnil
+             && ! encoding->encoding_charset)
+           {
+             encoding->encoding_charset = MCHARSET (encoding->encoding_name);
+             if (! encoding->encoding_charset)
+               {
+                 mplist_pop (plist);
+                 continue;
+               }
+           }
+         if (encoding->repertory_name == encoding->encoding_name)
+           encoding->repertory_charset = encoding->encoding_charset;
+         else if (encoding->repertory_name != Mnil)
+           {
+             encoding->repertory_charset
+               = MCHARSET (encoding->repertory_name);
+             if (! encoding->repertory_charset)
+               {
+                 mplist_pop (plist);
+                 continue;
+               }
+           }
+         font->encoding = encoding;
+         return encoding;
+       }
+
+      if (registry && MPLIST_KEY (plist) != Mt)
+       {
+         plist = mplist_find_by_key (plist, registry);
+         if (! plist)
+           break;
+       }
+      else
+       plist = MPLIST_NEXT (plist);
+    }
+  font->encoding = &default_encoding;
+  return &default_encoding;
+}
+
+#ifndef HAVE_OTF
+static OTF_Tag
+OTF_tag (char *name)
+{
+  unsigned char *p = (unsigned char *) name;
+
+  if (! name)
+    return (OTF_Tag) 0;
+  return (OTF_Tag) ((p[0] << 24)
+                   | (! p[1] ? 0
+                      : ((p[1] << 16)
+                         | (! p[2] ? 0
+                            : (p[2] << 8) | p[3]))));
+}
+
+void
+OTF_tag_name (OTF_Tag tag, char *name)
+{
+  name[0] = (char) (tag >> 24);
+  name[1] = (char) ((tag >> 16) & 0xFF);
+  name[2] = (char) ((tag >> 8) & 0xFF);
+  name[3] = (char) (tag & 0xFF);
+  name[4] = '\0';
+}
+#endif /* not HAVE_OTF */
+
+/* XLFD parser/generator */
+
+/** Indices to each field of split font name.  */
+
+enum xlfd_field_idx
+  {
+    XLFD_FOUNDRY,
+    XLFD_FAMILY,
+    XLFD_WEIGHT,
+    XLFD_SLANT,
+    XLFD_SWIDTH,
+    XLFD_ADSTYLE,
+    XLFD_PIXEL,
+    XLFD_POINT,
+    XLFD_RESX,
+    XLFD_RESY,
+    XLFD_SPACING,
+    XLFD_AVGWIDTH,
+    XLFD_REGISTRY,             /* This contains ENCODING.  */
+    /* anchor */
+    XLFD_FIELD_MAX
+  };
+
+static int
+xlfd_parse_name (const char *name, MFont *font)
+{
+  char *field[XLFD_FIELD_MAX];
+  unsigned short resy, avgwidth;
+  unsigned size;
+  char copy[513];
+  int i;
+  char *p;
+  MSymbol sym;
+
+  if (name[0] != '-')
+    return -1;
+
+  field[0] = copy;
+  for (i = 1, p = copy, name++; *name; p++, name++)
+    {
+      if (p - copy > 512)
+       return -1;
+      if (*name == '-'
+         && i < XLFD_FIELD_MAX)
+       {
+         *p = '\0';
+         if (field[i - 1][0] == '*')
+           field[i - 1] = NULL;
+         field[i++] = p + 1;
+       }
+      else
+       *p = tolower (*name);
+    }
+  *p = '\0';
+  if (field[i - 1][0] == '*')
+    field[i - 1] = NULL;
+  while (i < XLFD_FIELD_MAX)
+    field[i++] = NULL;
+
+  resy = field[XLFD_RESY] ? atoi (field[XLFD_RESY]) : 0;
+  avgwidth = ((field[XLFD_AVGWIDTH] && isdigit (field[XLFD_AVGWIDTH][0]))
+             ? atoi (field[XLFD_AVGWIDTH]) : 1);
+  if (! avgwidth)
+    size = 0;
+  else if (! field[XLFD_PIXEL])
+    size = field[XLFD_POINT] ? atoi (field[XLFD_POINT]) * resy / 72 : 0;
+  else if (field[XLFD_PIXEL][0] == '[')
+    {
+      /* The pixel size field specifies a transformation matrix of the
+        form "[A B C D]".  The XLFD spec says that the scalar value N
+        for the pixel size is equivalent to D.  */
+      char *p0 = field[XLFD_PIXEL] + 1, *p1;
+      double d;
+
+      for (i = 0; i < 4; i++, p0 = p1)
+       d = strtod (p0, &p1);
+      size = d * 10;
+    }
+  else
+    size = atoi (field[XLFD_PIXEL]) * 10;
+
+  if (field[XLFD_FOUNDRY])
+    {
+      sym = msymbol (field[XLFD_FOUNDRY]);
+      if (! sym)
+       sym = msymbol ("Nil");
+      mfont__set_property (font, MFONT_FOUNDRY, sym);
+    }
+  if (field[XLFD_FAMILY])
+    {
+      sym = msymbol (field[XLFD_FAMILY]);
+      if (! sym)
+       sym = msymbol ("Nil");
+      mfont__set_property (font, MFONT_FAMILY, sym);
+    }
+  if (field[XLFD_WEIGHT])
+    mfont__set_property (font, MFONT_WEIGHT, msymbol (field[XLFD_WEIGHT]));
+  if (field[XLFD_SLANT])
+    mfont__set_property (font, MFONT_STYLE, msymbol (field[XLFD_SLANT]));
+  if (field[XLFD_SWIDTH])
+    mfont__set_property (font, MFONT_STRETCH, msymbol (field[XLFD_SWIDTH]));
+  if (field[XLFD_ADSTYLE])
+    mfont__set_property (font, MFONT_ADSTYLE, msymbol (field[XLFD_ADSTYLE]));
+  font->property[MFONT_RESY] = resy;
+  font->size = size;
+  if (field[XLFD_SPACING])
+    font->spacing
+      = ((field[XLFD_SPACING][0] == 'p' || field[XLFD_SPACING][0] == 'P')
+        ? MFONT_SPACING_PROPORTIONAL
+        : (field[XLFD_SPACING][0] == 'm' || field[XLFD_SPACING][0] == 'M')
+        ? MFONT_SPACING_MONO : MFONT_SPACING_CHARCELL);
+  if (field[XLFD_REGISTRY])
+    mfont__set_property (font, MFONT_REGISTRY, msymbol (field[XLFD_REGISTRY]));
+  font->type = MFONT_TYPE_SPEC;
+  font->source = MFONT_SOURCE_X;
+  return 0;
+}
+
+static char *
+xlfd_unparse_name (MFont *font, int full_xlfd)
+{
+  MSymbol prop[7];
+  char name[513];
+  char *str[7];
+  int len, i;
+  char spacing;
+  int size, resy;
+  int all_nil = 1;
+
+  prop[0] = (MSymbol) mfont_get_prop (font, Mfoundry);
+  prop[1] = (MSymbol) mfont_get_prop (font, Mfamily);
+  prop[2] = (MSymbol) mfont_get_prop (font, Mweight);
+  prop[3] = (MSymbol) mfont_get_prop (font, Mstyle);
+  prop[4] = (MSymbol) mfont_get_prop (font, Mstretch);
+  prop[5] = (MSymbol) mfont_get_prop (font, Madstyle);
+  prop[6] = (MSymbol) mfont_get_prop (font, Mregistry);
+  for (len = 0, i = 0; i < 7; i++)
+    {
+      if (prop[i] != Mnil)
+       {
+         str[i] = msymbol_name (prop[i]);
+         len += strlen (str[i]);
+         all_nil = 0;
+       }
+      else
+       {
+         str[i] = "*";
+         len++;
+       }
+    }
+  spacing = (font->spacing == MFONT_SPACING_UNDECIDED ? '*'
+            : font->spacing == MFONT_SPACING_PROPORTIONAL ? 'p'
+            : font->spacing == MFONT_SPACING_MONO ? 'm'
+            : 'c');
+
+  if ((len
+       + 13                    /* 13 dashes */
+       + 2                     /* 2 asterisks */
+       + 30                    /* 3 integers (each 10 digits) */
+       + 1                     /* 1 spacing char */
+       + 1)                    /* '\0' terminal */
+      > 513)
+    return NULL;
+
+  resy = (int) mfont_get_prop (font, Mresolution);
+  size = font->size;
+  if (size >= 0)
+    {
+      if (font->multiple_sizes)
+       {
+         for (size = 0; size < 24; size++)
+           if (font->size & (1 << size))
+             break;
+         size += 6;
+       }
+      else if ((size % 10) < 5)
+       size /= 10;
+      else
+       size = size / 10 + 1;
+    }
+  else
+    size = - size;
+
+  if (full_xlfd)
+    {
+      if (font->size >= 0)
+       sprintf (name, "-%s-%s-%s-%s-%s-%s-%d-*-%d-%d-%c-*-%s",
+                str[0], str[1], str[2], str[3], str[4], str[5],
+                size, resy, resy, spacing, str[6]);
+      else
+       sprintf (name, "-%s-%s-%s-%s-%s-%s-*-%d-%d-%d-%c-*-%s",
+                str[0], str[1], str[2], str[3], str[4], str[5],
+                size, resy, resy, spacing, str[6]);
+    }
+  else if (all_nil && size == 0)
+    sprintf (name, "*");
+  else
+    {
+      char *p = name;
+
+      p += sprintf (p, "-%s", str[0]);
+      for (i = 1; i < 6; i++)
+       if (p[-1] != '*' || str[i][0] != '*')
+         p += sprintf (p, "-%s", str[i]);
+      if (p[-1] != '*' || font->size > 0)
+       {
+         if (font->size > 0)
+           p += sprintf (p, "-%d-*", size);
+         else
+           p += sprintf (p, "-*");
+       }
+      if (str[6][0] != '*')
+       sprintf (p, "-%s", str[6]);
+    }
+
+  return strdup (name);
+}
+
+/* Compare FONT with REQUEST and return how much they differs.  */
+
+static int
+font_score (MFont *font, MFont *request)
+{
+  int score = 0;
+  int i = FONT_SCORE_PRIORITY_SIZE;
+
+  while (--i >= 0)
+    {
+      enum MFontProperty prop = font_score_priority[i];
+      int val;
+
+      if (prop == MFONT_SIZE)
+       {
+         if (font->size && request->size)
+           {
+             if (font->multiple_sizes)
+               {
+                 int j, closest = 23;
+
+                 for (j = 23; j >= 0; j--)
+                   if (font->size & (1 << j))
+                     {
+                       closest = j;
+                       if (request->size >= (j + 6) * 10)
+                         break;
+                     }
+                 val = request->size - (closest + 6) * 10;
+               }
+             else
+               val = font->size - request->size;
+             if (val)
+               {
+                 if (val < 0)
+                   val = - val;
+                 if (val >= 0x10000)
+                   val = 0xFFFF;
+                 score |= (val << font_score_shift_bits[MFONT_SIZE]);
+               }
+           }
+       }
+      else if (font->property[prop] && request->property[prop]
+              && font->property[prop] != request->property[prop])
+       {
+         if (prop <= MFONT_FAMILY)
+           val = 1;
+         else if (prop == MFONT_WEIGHT)
+           {
+             unsigned short v1 = font->property[prop];
+             unsigned short v2 = request->property[prop];
+
+             if (v1 == font_weight_regular || v1 == font_weight_normal)
+               v1 = font_weight_medium;
+             if (v2 == font_weight_regular || v2 == font_weight_normal)
+               v2 = font_weight_medium;
+             val = v1 > v2 ? v1 - v2 : v2 - v1;
+           }
+         else
+           {
+             val = font->property[prop] - request->property[prop];
+             if (val < 0)
+               val = - val;
+             if (val > 3)
+               val = 3;
+           }
+         score |= val << font_score_shift_bits[prop];
+       }
+    }
+  if (request->file != Mnil && request->file != font->file)
+    score |= 40000000;
+  return score;
+}
+
+static MSymbol
+merge_capability (MSymbol capability, MSymbol key, MSymbol val, int overwrite)
+{
+  MFontCapability *cap = NULL;
+  char *lang = NULL, *script = NULL, *otf = NULL, *buf, *p;
+  int lang_len = 0, script_len = 0, otf_len = 0;
+
+  if (key == Mlanguage)
+    lang = MSYMBOL_NAME (val), lang_len = MSYMBOL_NAMELEN (val) + 6;
+  else if (key == Mscript)
+    script = MSYMBOL_NAME (val), script_len = MSYMBOL_NAMELEN (val) + 7;
+  else if (key == Motf)
+    otf = MSYMBOL_NAME (val), otf_len = MSYMBOL_NAMELEN (val) + 5;
+  else
+    return capability;
+
+  if (capability != Mnil)
+    {
+      cap = mfont__get_capability (capability);
+      if (! overwrite)
+       {
+         if (cap->language)
+           lang = NULL;
+         if (cap->script)
+           script = NULL;
+         if (cap->script_tag)
+           otf = NULL;
+         if (! lang && !script && !otf)
+           return capability;
+       }
+    }
+
+  if (! lang && cap && cap->language)
+    {
+      lang_len = MSYMBOL_NAMELEN (cap->language);
+      lang = MSYMBOL_NAME (cap->language);
+    }
+  if (! script && cap && cap->script != Mnil)
+    {
+      script_len = MSYMBOL_NAMELEN (cap->script);
+      script = MSYMBOL_NAME (cap->script);
+    }
+  if (! otf && cap && cap->script_tag)
+    {
+      int i;
+
+      otf_len = 4;                     /* for script_tag */
+      if (cap->langsys_tag)
+       otf_len += 5;           /* for "/XXXX */
+      for (i = 0; i < MFONT_OTT_MAX; i++)
+       if (cap->features[i].str)
+         otf_len += strlen (cap->features[i].str) + 1; /* for "[=+]..." */
+      otf = p = alloca (otf_len + 1);
+      OTF_tag_name (cap->script_tag, otf);
+      p += 4;
+      if (cap->langsys_tag)
+       {
+         *p++ = '/';
+         OTF_tag_name (cap->langsys_tag, p);
+         p += 4;
+       }
+      if (cap->features[MFONT_OTT_GSUB].str)
+       p += sprintf (p, "=%s", cap->features[MFONT_OTT_GSUB].str);
+      if (cap->features[MFONT_OTT_GPOS].str)
+       p += sprintf (p, "=%s", cap->features[MFONT_OTT_GSUB].str);
+    }
+  buf = p = alloca (lang_len + script_len + otf_len + 1);
+  if (lang_len)
+    p += sprintf (p, ":lang=%s", lang);
+  if (script_len)
+    p += sprintf (p, ":script=%s", script);
+  if (otf_len)
+    p += sprintf (p, ":otf=%s", otf);
+  return msymbol (buf);
+}
+
+\f
+/* Internal API */
+
+MSymbol Miso8859_1, Miso10646_1, Municode_bmp, Municode_full, Mapple_roman;
+
+int
+mfont__init ()
+{
+  int i, shift;
+  MSymbol regular = msymbol ("regular");
+  MSymbol normal = msymbol ("normal");
+  MSymbol medium = msymbol ("medium");
+
+  M_font_capability = msymbol_as_managing_key ("  font-capability");
+  M_font_list = msymbol_as_managing_key ("  font-list");
+  M_font_list_len = msymbol ("  font-list-len");
+
+  Mfoundry = msymbol ("foundry");
+  mfont__property_table[MFONT_FOUNDRY].property = Mfoundry;
+  Mfamily = msymbol ("family");
+  mfont__property_table[MFONT_FAMILY].property = Mfamily;
+  Mweight = msymbol ("weight");
+  mfont__property_table[MFONT_WEIGHT].property = Mweight;
+  Mstyle = msymbol ("style");
+  mfont__property_table[MFONT_STYLE].property = Mstyle;
+  Mstretch = msymbol ("stretch");
+  mfont__property_table[MFONT_STRETCH].property = Mstretch;
+  Madstyle = msymbol ("adstyle");
+  mfont__property_table[MFONT_ADSTYLE].property = Madstyle;
+  Mregistry = msymbol ("registry");
+  mfont__property_table[MFONT_REGISTRY].property = Mregistry;
+
+  Mspacing = msymbol ("spacing");
+  Msize = msymbol ("size");
+  Mresolution = msymbol ("resolution");
+  Mmax_advance = msymbol ("max-advance");
+  Mfontfile = msymbol ("fontfile");
+
+  Mfontconfig = msymbol ("fontconfig");
+
+  Mx = msymbol ("x");
+  Mfreetype = msymbol ("freetype");
+  Mxft = msymbol ("xft");
+
+  Miso8859_1 = msymbol ("iso8859-1");
+  Miso10646_1 = msymbol ("iso10646-1");
+  Municode_bmp = msymbol ("unicode-bmp");
+  Municode_full = msymbol ("unicode-full");
+  Mapple_roman = msymbol ("apple-roman");
+
+  Motf = msymbol ("otf");
+
+  /* The first entry of each mfont__property_table must be Mnil so
+     that actual properties get positive numeric numbers.  */
+  for (i = 0; i <= MFONT_REGISTRY; i++)
+    {
+      MLIST_INIT1 (&mfont__property_table[i], names, 8);
+      MLIST_APPEND1 (&mfont__property_table[i], names, Mnil, MERROR_FONT);
+    }
+
+  /* Register predefined font property names.  */
+  for (i = 0; i <= MFONT_REGISTRY; i++)
+    {
+      int j;
+
+      for (j = 0; j < font_common_names[i].num; j++)
+       {
+         MSymbol sym = msymbol (font_common_names[i].names[j]);
+
+         if (sym == Mnil)
+           return -1;
+         if (msymbol_put (sym, mfont__property_table[i].property,
+                          (void *) (j + 1)) < 0)
+           return -1;
+         MLIST_APPEND1 (&mfont__property_table[i], names, sym,
+                        MERROR_FONT);
+         if (i == MFONT_WEIGHT)
+           {
+             if (sym == regular)
+               font_weight_regular = j + 1;
+             else if (sym == normal)
+               font_weight_normal = j + 1;
+             else if (sym == medium)
+               font_weight_medium = j + 1;
+           }
+       }
+    }
+
+  /* Here, SHIFT starts from 1, not 0.  This is because the lowest bit
+     of a score is a flag for a scalable font (see the documentation
+     of font_score).  */
+  i = FONT_SCORE_PRIORITY_SIZE - 1;
+  for (shift = 1; i >= 0; i--)
+    {
+      font_score_shift_bits[font_score_priority[i]] = shift;
+      if (font_score_priority[i] == MFONT_SIZE)
+       shift += 16;
+      else if (font_score_priority[i] <= MFONT_FAMILY)
+       shift++;
+      else
+       shift += 2;
+    }
+
+  MFONT_INIT (&default_encoding.spec);
+  default_encoding.encoding_name = Municode_full;
+  default_encoding.encoding_charset = mcharset__unicode;
+  default_encoding.repertory_name = Mnil;
+  default_encoding.repertory_charset = NULL;
+  {
+    char *path, *buf;
+    int bufsize;
+    USE_SAFE_ALLOCA;
+
+    mfont_freetype_path = mplist ();
+    bufsize = strlen (M17NDIR) + 7;
+    SAFE_ALLOCA (buf, bufsize);
+    sprintf (buf, "%s/fonts", M17NDIR);
+    mplist_add (mfont_freetype_path, Mstring, strdup (buf));
+    path = getenv ("M17NDIR");
+    if (path)
+      {
+       bufsize = strlen (path) + 7;
+       SAFE_ALLOCA (buf, bufsize);
+       sprintf (buf, "%s/fonts", path);
+       mplist_push (mfont_freetype_path, Mstring, strdup (buf));
+      }
+    SAFE_FREE (buf);
+  }
+
+#ifdef HAVE_FREETYPE
+  if (mfont__ft_init () < 0)
+    return -1;
+#endif /* HAVE_FREETYPE */
+
+  return 0;
+}
+
+void
+mfont__fini ()
+{
+  MPlist *plist;
+  int i;
+
+#ifdef HAVE_FREETYPE
+  mfont__ft_fini ();
+#endif /* HAVE_FREETYPE */
+
+  MPLIST_DO (plist, mfont_freetype_path)
+    free (MPLIST_VAL (plist));
+  M17N_OBJECT_UNREF (mfont_freetype_path);
+
+  if (font_resize_list)
+    {
+      MPLIST_DO (plist, font_resize_list)
+       free (MPLIST_VAL (plist));
+      M17N_OBJECT_UNREF (font_resize_list);
+      font_resize_list = NULL;
+    }
+  if (font_encoding_list)
+    {
+      MPLIST_DO (plist, font_encoding_list)
+       free (MPLIST_VAL (plist));
+      M17N_OBJECT_UNREF (font_encoding_list);
+      font_encoding_list = NULL;
+    }
+
+  for (i = 0; i <= MFONT_REGISTRY; i++)
+    MLIST_FREE1 (&mfont__property_table[i], names);
+}
+
+
+MSymbol
+mfont__id (MFont *font)
+{
+  char *buf, *p;
+  int i;
+  int file_len = (font->file == Mnil ? 0 : MSYMBOL_NAMELEN (font->file));
+  int capability_len  = (font->capability == Mnil ? 0
+                        : MSYMBOL_NAMELEN (font->capability));
+  int total_len = MFONT_PROPERTY_MAX * 5 + 9 + file_len + capability_len;
+  MSymbol id;
+  USE_SAFE_ALLOCA;
+
+  SAFE_ALLOCA (buf, total_len);
+  p = buf;
+  if (font->property[0])
+    p += sprintf (p, "%X", font->property[0]);
+  for (i = 1; i < MFONT_PROPERTY_MAX; i++)
+    {
+      if (font->property[i])
+       p += sprintf (p, "-%X", font->property[i]);
+      else
+       *p++ = '-';
+    }
+  if (font->size)
+    p += sprintf (p, "-%X", font->size);
+  if (font->spacing)
+    p += sprintf (p, "-%X", font->spacing);
+  if (capability_len > 0)
+    {
+      *p++ = '-';
+      memcpy (p, MSYMBOL_NAME (font->capability), capability_len);
+      p += capability_len;
+    }
+  if (file_len > 0)
+    {
+      *p++ = '-';
+      memcpy (p, MSYMBOL_NAME (font->file), file_len);
+      p += file_len;
+    }      
+  id = msymbol__with_len (buf, p - buf);
+  SAFE_FREE (buf);
+  return id;
+}
+
+/** Return 1 iff FONT matches SPEC.  */
+
+int
+mfont__match_p (MFont *font, MFont *spec, int prop)
+{
+  if (spec->capability != font->capability
+      && spec->capability != Mnil)
+    {
+      MRealizedFont *rfont;
+
+      if (font->type != MFONT_TYPE_REALIZED)
+       return (font->capability == Mnil);
+      rfont = (MRealizedFont *) font;
+      return (rfont->driver->check_capability
+             && (rfont->driver->check_capability (rfont, spec->capability)
+                 >= 0));
+    }
+  if (spec->file != font->file
+      && spec->file != Mnil && font->file != Mnil)
+    return 0;
+  for (; prop >= 0; prop--)
+    if (spec->property[prop] && font->property[prop]
+       && font->property[prop] != spec->property[prop])
+      return 0;
+  return 1;
+}
+
+/* Merge SRC into DST.  If error_on_conflict is nonzero and a font
+   property differs in SRC and DST, return -1.  */
+
+int
+mfont__merge (MFont *dst, MFont *src, int error_on_conflict)
+{
+  int i;
+
+  for (i = 0; i < MFONT_PROPERTY_MAX; i++)
+    {
+      if (! dst->property[i])
+       dst->property[i] = src->property[i];
+      else if (error_on_conflict
+              && src->property[i]
+              && dst->property[i] != src->property[i])
+       return -1;
+    }
+  if (! dst->spacing)
+    dst->spacing = src->spacing;
+  else if (error_on_conflict
+          && src->spacing
+          && dst->spacing != src->spacing)
+    return -1;
+  if (! dst->size)
+    dst->size = src->size;
+  else if (error_on_conflict
+          && src->size
+          && dst->size != src->size)
+    return -1;
+  if (dst->capability == Mnil)
+    dst->capability = src->capability;
+  else if (error_on_conflict
+          && src->capability
+          && dst->capability != src->capability)
+    return -1;
+  if (dst->file == Mnil)
+    dst->file = src->file;
+  else if (error_on_conflict
+          && src->file
+          && dst->file != src->file)
+    return -1;
+  return 0;
+}
+
+void
+mfont__set_spec_from_face (MFont *spec, MFace *face)
+{
+  int i;
+
+  for (i = 0; i <= MFONT_ADSTYLE; i++)
+    mfont__set_property (spec, i, face->property[i]);
+  spec->property[MFONT_REGISTRY] = 0;
+  spec->property[MFONT_RESY] = 0;
+  spec->multiple_sizes = 0;
+  spec->size = (int) (face->property[MFACE_SIZE]);
+  spec->type = MFONT_TYPE_SPEC;
+  spec->source = MFONT_SOURCE_UNDECIDED;
+  spec->file = spec->capability = Mnil;
+  spec->encoding = NULL;
+}
+
+
+extern MSymbol
+mfont__set_spec_from_plist (MFont *spec, MPlist *plist)
+{
+  int i;
+  MSymbol spec_list[MFONT_REGISTRY + 1];
+  MSymbol registry;
+  char *reg;
+
+  MFONT_INIT (spec);
+  memset (spec_list, 0, sizeof spec_list);
+  for (i = 0; ! MPLIST_TAIL_P (plist); i++, plist = MPLIST_NEXT (plist))
+    {
+      if (! MPLIST_SYMBOL_P (plist))
+       MERROR (MERROR_FONT, Mnil);     
+      spec_list[i] = MPLIST_SYMBOL (plist);
+    }
+  registry = spec_list[i - 1];
+  if (i > 1 && registry != Mnil)
+    {
+      reg = MSYMBOL_NAME (registry);
+      if (reg[0] == ':')
+       {
+         mfont__get_capability (registry);
+         spec->capability = registry;
+         registry = spec_list[i - 2];
+         i--;
+       }
+    }
+  mfont__set_property (spec, MFONT_REGISTRY, registry);
+  for (i -= 2; i >= 0; i--)
+    mfont__set_property (spec, i, spec_list[i]);
+  spec->type = MFONT_TYPE_SPEC;
+
+  return registry;
+}
+
+
+MFont *
+mfont__select (MFrame *frame, MFont *font, int max_size)
+{
+  MFontDriver *driver;
+
+  if (font->type == MFONT_TYPE_FAILURE)
+    return NULL;
+  if (font->type != MFONT_TYPE_SPEC)
+    return font;
+  if (font->source == MFONT_SOURCE_UNDECIDED)
+    {
+      if (font->file != Mnil || font->capability != Mnil)
+       font->source = MFONT_SOURCE_FT;
+      else if (font->property[MFONT_REGISTRY])
+       {
+         MSymbol registry = FONT_PROPERTY (font, MFONT_REGISTRY);
+         char *reg = MSYMBOL_NAME (registry);
+
+         if (strncmp (reg, "unicode-", 8) == 0
+             || strncmp (reg, "apple-roman", 11) == 0
+             || (reg[0] >= '0' && reg[0] <= '9' && reg[1] == '-'))
+           font->source = MFONT_SOURCE_FT;
+       }
+    }
+  if (font->source != MFONT_SOURCE_FT)
+    {
+      driver = mplist_get (frame->font_driver_list, Mx);
+      if (driver)
+       return (driver->select) (frame, font, max_size);
+    }
+  driver = mplist_get (frame->font_driver_list, Mfreetype);
+  if (! driver)
+    return NULL;
+  return (driver->select) (frame, font, max_size);
+}
+
+
+int
+mfont__available (MFrame *frame, MFont *font)
+{
+  return -1;
+}
+
+static int
+compare_font_score (const void *e1, const void *e2)
+{
+  MFontScore *s1 = (MFontScore *) e1, *s2 = (MFontScore *) e2;
+
+  return (s1->font->for_full_width == s2->font->for_full_width
+         ? s1->score > s2->score
+         : s1->font->for_full_width);
+}
+
+void
+mdebug_dump_font_list (MFontList *font_list)
+{
+  int i;
+
+  for (i = 0; i < font_list->nfonts; i++)
+    {
+      fprintf (stderr, "%04X - ", font_list->fonts[i].score);
+      mdebug_dump_font (font_list->fonts[i].font);
+      fprintf (stderr, "\n");
+    }
+}
+
+void
+mfont__free_realized (MRealizedFont *rfont)
+{
+  MRealizedFont *next;
+
+  for (; rfont; rfont = next)
+    {
+      next = rfont->next;
+      M17N_OBJECT_UNREF (rfont->info);
+      free (rfont);
+      rfont = next;
+    }
+}
+
+MFontList *
+mfont__list (MFrame *frame, MFont *spec, MFont *request, int max_size)
+{
+  MFontList *list;
+  MSymbol id = mfont__id (spec);
+  MPlist *pl, *p;
+  int num, i;
+
+  pl = msymbol_get (id, M_font_list);
+  if (pl)
+    num = (int) msymbol_get (id, M_font_list_len);
+  else
+    {
+      pl = mplist ();
+      num = 0;
+      MPLIST_DO (p, frame->font_driver_list)
+       {
+         if (spec->source == MFONT_SOURCE_X ? MPLIST_KEY (p) == Mx
+             : spec->source == MFONT_SOURCE_FT ? MPLIST_KEY (p) == Mfreetype
+             : 1)
+           {
+             MFontDriver *driver = MPLIST_VAL (p);
+             num += (driver->list) (frame, pl, spec, 0);
+           }
+       }
+      msymbol_put (id, M_font_list, pl);
+      M17N_OBJECT_UNREF (pl);
+      msymbol_put (id, M_font_list_len, (void *) num);
+    }
+  
+  if (num == 0)
+    return NULL;
+
+  MSTRUCT_MALLOC (list, MERROR_FONT);
+  MTABLE_MALLOC (list->fonts, num, MERROR_FONT);
+  for (i = 0; num > 0; num--, pl = MPLIST_NEXT (pl))
+    {
+      MFont *font = MPLIST_VAL (pl), *adjusted = font;
+
+      if (max_size == 0
+         || font->size == 0
+         || font->size < max_size)
+       {
+         list->fonts[i].font = font;
+         if (spec == request)
+           list->fonts[i].score = 0;
+         else
+           {
+             int resize_ratio;
+             MFont resized;
+
+             if (font->size > 0
+                 && (resize_ratio = mfont_resize_ratio (font)) != 100)
+               {
+                 resized = *font;
+                 resized.size = font->size * 100 / resize_ratio;
+                 adjusted = &resized;
+               }
+             list->fonts[i].score = font_score (adjusted, request);
+           }
+         i++;
+       }
+    }
+  if (i == 0)
+    {
+      free (list->fonts);
+      free (list);
+      return NULL;
+    }
+  list->nfonts = i;
+  if (spec != request)
+    qsort (list->fonts, i, sizeof (MFontScore), compare_font_score);
+  list->object = *spec;
+  mfont__merge (&list->object, request, 0);
+  list->object.type = MFONT_TYPE_OBJECT;
+  return list;
+}
+
+/** Open a font specified in FONT.  */
+
+MRealizedFont *
+mfont__open (MFrame *frame, MFont *font, MFont *spec)
+{
+  MFontDriver *driver;
+  MRealizedFont *rfont;
+
+  if (font->source == MFONT_SOURCE_UNDECIDED)
+    MFATAL (MERROR_FONT);
+  if (font->type != MFONT_TYPE_OBJECT)
+    MFATAL (MERROR_FONT);
+  for (rfont = MPLIST_VAL (frame->realized_font_list); rfont;
+       rfont = rfont->next)
+    {
+      driver = rfont->driver;
+      if (rfont->font == font
+         && mplist_find_by_value (frame->font_driver_list, driver))
+       break;
+    }
+
+  if (! rfont)
+    {
+      driver = mplist_get (frame->font_driver_list,
+                          font->source == MFONT_SOURCE_X ? Mx : Mfreetype);
+      if (! driver)
+       MFATAL (MERROR_FONT);
+    }
+  return (driver->open) (frame, font, spec, rfont);
+}
+
+int
+mfont__has_char (MFrame *frame, MFont *font, MFont *spec, int c)
+{
+  MFontEncoding *encoding;
+  unsigned code;
+  MFontDriver *driver;
+
+  if (font->source == MFONT_SOURCE_UNDECIDED)
+    MFATAL (MERROR_FONT);
+  encoding = (font->encoding ? font->encoding : find_encoding (font));
+  if (! encoding->encoding_charset)
+    return 0;
+  if (encoding->repertory_charset)
+    {
+      code = ENCODE_CHAR (encoding->repertory_charset, c);
+      return (code != MCHAR_INVALID_CODE);
+    }
+  code = ENCODE_CHAR (encoding->encoding_charset, c);
+  if (code == MCHAR_INVALID_CODE)
+    return 0;
+  if (font->type == MFONT_TYPE_REALIZED)
+    driver = ((MRealizedFont *) font)->driver;
+  else
+    {
+      driver = mplist_get (frame->font_driver_list,
+                          font->source == MFONT_SOURCE_X ? Mx : Mfreetype);
+      if (! driver)
+       MFATAL (MERROR_FONT);
+    }
+  return (driver->has_char) (frame, font, spec, c, code);
+}
+
+unsigned
+mfont__encode_char (MFrame *frame, MFont *font, MFont *spec, int c)
+{
+  MFontEncoding *encoding;
+  unsigned code;
+  MFontDriver *driver;
+
+  if (font->source == MFONT_SOURCE_UNDECIDED)
+    MFATAL (MERROR_FONT);
+  encoding = (font->encoding ? font->encoding : find_encoding (font));
+  if (! encoding->encoding_charset)
+    return MCHAR_INVALID_CODE;
+  if (font->source == MFONT_SOURCE_X && encoding->repertory_charset)
+    return (ENCODE_CHAR (encoding->repertory_charset, c));
+  code = ENCODE_CHAR (encoding->encoding_charset, c);
+  if (code == MCHAR_INVALID_CODE)
+    return MCHAR_INVALID_CODE;
+  if (font->type == MFONT_TYPE_REALIZED)
+    driver = ((MRealizedFont *) font)->driver;
+  else
+    {
+      driver = mplist_get (frame->font_driver_list,
+                          font->source == MFONT_SOURCE_X ? Mx : Mfreetype);
+      if (! driver)
+       MFATAL (MERROR_FONT);
+    }
+  return (driver->encode_char) (frame, font, spec, code);
+}
+
+void
+mfont__get_metric (MGlyphString *gstring, int from, int to)
+{
+  MGlyph *from_g = MGLYPH (from), *to_g = MGLYPH (to), *g;
+  MRealizedFont *rfont = from_g->rface->rfont;
+
+  for (g = from_g; ; g++)
+    if (g == to_g || g->rface->rfont != rfont)
+      {
+       int idx = GLYPH_INDEX (g);
+
+       (rfont->driver->find_metric) (rfont, gstring, from, idx);
+       while (from_g < g)
+         {
+           from_g->g.xadv >>= 6;
+           from_g->g.yadv >>= 6;
+           from_g->g.xoff >>= 6;
+           from_g->g.yoff >>= 6;
+           from_g->g.ascent >>= 6;
+           from_g->g.descent >>= 6;
+           from_g->g.lbearing >>= 6;
+           from_g->g.rbearing >>= 6;
+           from_g++;
+         }
+       if (g == to_g)
+         break;
+       rfont = g->rface->rfont;
+       from = idx;
+      }
+}
+
+int
+mfont__get_glyph_id (MFLTFont *font, MFLTGlyphString *gstring,
+                    int from, int to)
+{
+  MFont *mfont = (MFont *) ((MFLTFontForRealized *) font)->rfont;
+  MRealizedFont *rfont = ((MFLTFontForRealized *) font)->rfont;
+  MFontEncoding *encoding;
+  MFontDriver *driver = NULL;
+  MGlyph *glyphs = (MGlyph *) gstring->glyphs;
+  int result = 0;
+
+  encoding = mfont->encoding ? mfont->encoding : find_encoding (mfont);
+  for (; from < to; from++)
+    {
+      MGlyph *g = glyphs + from;
+
+      if (g->g.encoded)
+       continue;
+      if (mfont->source == MFONT_SOURCE_X && encoding->repertory_charset)
+       g->g.code = ENCODE_CHAR (encoding->repertory_charset, g->g.c);
+      else
+       {
+         unsigned code;
+
+         if (encoding->encoding_charset)
+           code = ENCODE_CHAR (encoding->encoding_charset, g->g.c);
+         else
+           code = g->g.code;
+
+         if (code != MCHAR_INVALID_CODE)
+           {
+             if (! driver)
+               {
+                 if (mfont->type == MFONT_TYPE_REALIZED)
+                   driver = rfont->driver;
+                 else
+                   {
+                     driver = mplist_get (rfont->frame->font_driver_list,
+                                          mfont->source == MFONT_SOURCE_X
+                                          ? Mx : Mfreetype);
+                     if (! driver)
+                       MFATAL (MERROR_FONT);
+                   }
+               }
+             g->g.code = (driver->encode_char) (rfont->frame, rfont->font,
+                                                mfont, code);
+           }
+       }
+      g->g.encoded = 1;
+      if (g->g.code == MCHAR_INVALID_CODE)
+       result = -1;
+    }
+  return result;
+}
+
+int
+mfont__get_metrics (MFLTFont *font, MFLTGlyphString *gstring,
+                   int from, int to)
+{
+  MRealizedFont *rfont = ((MFLTFontForRealized *) font)->rfont;
+  MGlyphString gstr;
+
+  gstr.glyphs = (MGlyph *) gstring->glyphs;
+  (rfont->driver->find_metric) (rfont, &gstr, from, to);
+  return 0;
+}
+
+/* KEY <= MFONT_REGISTRY */
+
+void
+mfont__set_property (MFont *font, enum MFontProperty key, MSymbol val)
+{
+  int numeric;
+
+  if (val == Mnil)
+    numeric = 0;
+  else
+    {
+      numeric = FONT_PROPERTY_NUMERIC (val, key);
+      if (! numeric)
+       {
+         numeric = mfont__property_table[key].used;
+         MLIST_APPEND1 (mfont__property_table + key, names, val, MERROR_FONT);
+         SET_FONT_PROPERTY_NUMERIC (val, key, numeric);
+       }
+    }
+  font->property[key] = numeric;
+}
+
+int
+mfont__parse_name_into_font (const char *name, MSymbol format, MFont *font)
+{
+  int result = -1;
+
+  if (format == Mx || format == Mnil)
+    result = xlfd_parse_name (name, font);
+#ifdef HAVE_FONTCONFIG
+  if (format == Mfontconfig || (result < 0 && format == Mnil))
+    result = mfont__ft_parse_name (name, font);
+#endif /* HAVE_FONTCONFIG */
+  return result;
+}
+
+MPlist *
+mfont__encoding_list (void)
+{
+  if (! font_encoding_list)
+    load_font_encoding_table ();
+  return font_encoding_list;
+}
+
+static void
+free_font_capability (void *object)
+{
+  MFontCapability *cap = object;
+  
+  if (cap->script_tag)
+    {
+      int i;
+      for (i = 0; i < MFONT_OTT_MAX; i++)
+       {
+         if (cap->features[i].str)
+           free (cap->features[i].str);
+         if (cap->features[i].tags)
+           free (cap->features[i].tags);
+       }
+    }
+  free (cap);
+}
+
+MFontCapability *
+mfont__get_capability (MSymbol sym)
+{
+  MFontCapability *cap = msymbol_get (sym, M_font_capability);
+  char *str, *p, *endp;
+
+  if (cap)
+    return cap;
+  str = MSYMBOL_NAME (sym);
+  if (str[0] != ':')
+    return NULL;
+  M17N_OBJECT (cap, free_font_capability, MERROR_FONT);
+  msymbol_put (sym, M_font_capability, cap);
+  M17N_OBJECT_UNREF (cap);
+  endp = str + MSYMBOL_NAMELEN (sym);
+  while (str < endp)
+    {
+      if (*str++ != ':')
+       continue;
+      if (str[0] == 'o' && strncmp (str + 1, "tf=", 3) == 0)
+       {
+         char *beg;
+         MSymbol sym;
+         int i;
+
+         str += 4;
+         beg = str;
+         for (i = 0, p = str; i < 4 && p < endp; i++, p++);
+         if (i < 4)
+           break;
+         sym = msymbol__with_len (str, 4);
+         cap->script = mscript__from_otf_tag (sym);
+         if (cap->script == Mnil)
+           break;
+         cap->script_tag = OTF_tag (str);
+         if (*p == '/')
+           {
+             for (i = 0, str = ++p; i < 4 && p < endp; i++, p++);
+             if (i < 4)
+               {
+                 cap->script = Mnil;
+                 cap->script_tag = 0;
+                 break;
+               }
+             cap->langsys_tag = OTF_tag (str);
+           }
+         else
+           cap->langsys_tag = 0;
+
+         for (i = 0; i < MFONT_OTT_MAX; i++)
+           cap->features[i].nfeatures = -1;
+
+         while (*p == '=' || *p == '+')
+           {
+             int idx = *p == '=' ? MFONT_OTT_GSUB : MFONT_OTT_GPOS;
+
+             str = ++p;
+             while (p < endp && *p != '+') p++;
+             if (str < p)
+               {
+                 int n;
+                 /* We never have more than (p - str) tags.  */
+                 OTF_Tag *tags = alloca (sizeof (OTF_Tag) * (p - str));
+                 char *p0;
+
+                 cap->features[idx].str = malloc (p - str + 1);
+                 for (i = n = 0, p0 = str; str + i < p; i++)
+                   {
+                     cap->features[idx].str[i] = str[i];
+                     if (str[i] == ',' || str + i + 1 == p)
+                       {
+                         if (*p0 == '*')
+                           tags[n] = 0;
+                         else if (*p0 == '~')
+                           tags[n] = OTF_tag (p0 + 1) | 0x80000000;
+                         else
+                           tags[n] = OTF_tag (p0);
+                         n++;
+                         p0 = str + i + 1;
+                       }
+                   }
+                 cap->features[idx].str[i] = '\0';
+                 cap->features[idx].nfeatures = n;
+                 if (n > 0)
+                   {
+                     int size = sizeof (OTF_Tag) * n;
+
+                     cap->features[idx].tags = malloc (size);
+                     memcpy (cap->features[idx].tags, tags, size);
+                   }
+               }
+             else
+               {
+                 cap->features[idx].str = NULL;
+                 cap->features[idx].nfeatures = 0;
+               }
+           }
+
+         for (i = 0; i < MFONT_OTT_MAX; i++)
+           if (cap->features[i].nfeatures < 0)
+             {
+               cap->features[i].str = strdup ("*");
+               cap->features[i].nfeatures = 1;
+               cap->features[i].tags = malloc (sizeof (OTF_Tag));
+               cap->features[i].tags[0] = 0;
+             }
+         cap->otf = msymbol__with_len (beg, p - beg);
+         str = p;
+       }
+      else if (str[0] == 'l' && strncmp (str + 1, "ang=", 4) == 0)
+       {
+         str += 5;
+         for (p = str; p < endp && *p != ':'; p++);
+         if (str < p)
+           cap->language = msymbol__with_len (str, p - str);
+         str = p;
+       }
+      else if (str[0] == 's' && strncmp (str + 1, "cript=", 6) == 0)
+       {
+         str += 7;
+         for (p = str; p < endp && *p != ':'; p++);
+         if (str < p)
+           cap->script = msymbol__with_len (str, p - str);
+         str = p;
+       }
+    }
+  return cap;
+}
+
+int
+mfont__check_capability (MRealizedFont *rfont, MSymbol capability)
+{
+  return (rfont->driver->check_capability (rfont, capability));
+}
+
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+
+/* External API */
+
+/*** @addtogroup m17nFont */
+/*** @{ */
+/*=*/
+
+/***en @name Variables: Keys of font property.  */
+/***ja @name ÊÑ¿ô: ¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤹ¤ëÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë */
+/*** @{ */
+/*=*/
+
+/***en
+    @brief Key of font property specifying foundry.
+
+    The variable #Mfoundry is a symbol of name <tt>"foundry"</tt> and
+    is used as a key of font property and face property.  The property
+    value must be a symbol whose name is a foundry name of a font.  */
+/***ja
+    @brief ³«È¯¸µ¤ò»ØÄꤹ¤ë¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼.
+    
+    ÊÑ¿ô #Mfoundry ¤Ï <tt>"foundry"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤È¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
+    Ãͤϡ¢¥Õ¥©¥ó¥È¤Î³«È¯¸µÌ¾¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£    */
+
+MSymbol Mfoundry;
+
+/***en
+    @brief Key of font property specifying family.
+
+    The variable #Mfamily is a symbol of name <tt>"family"</tt> and is
+    used as a key of font property and face property.  The property
+    value must be a symbol whose name is a family name of a font.  */ 
+/***ja
+    @brief ¥Õ¥¡¥ß¥ê¤ò»ØÄꤹ¤ë¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼.
+    
+    ÊÑ¿ô #Mfamily ¤Ï <tt>"family"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤È¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
+    Ãͤϡ¢¥Õ¥©¥ó¥È¤Î¥Õ¥¡¥ß¥ê̾¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£    */
+
+MSymbol Mfamily;
+
+/***en
+    @brief Key of font property specifying weight.
+
+    The variable #Mweight is a symbol of name <tt>"weight"</tt> and is
+    used as a key of font property and face property.  The property
+    value must be a symbol whose name is a weight name of a font (e.g
+    "medium", "bold").  */ 
+/***ja
+    @brief ÂÀ¤µ¤ò»ØÄꤹ¤ë¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼.
+    
+    ÊÑ¿ô #Mweight ¤Ï <tt>"weight"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤È¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
+    Ãͤϡ¢¥Õ¥©¥ó¥È¤ÎÂÀ¤µÌ¾ ( "medium", "bold" Åù) ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£    */
+
+MSymbol Mweight;
+
+/***en
+    @brief Key of font property specifying style.
+
+    The variable #Mstyle is a symbol of name <tt>"style"</tt> and is
+    used as a key of font property and face property.  The property
+    value must be a symbol whose name is a style name of a font (e.g
+    "r", "i", "o").  */ 
+/***ja
+    @brief ¥¹¥¿¥¤¥ë¤ò»ØÄꤹ¤ë¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼.
+    
+    ÊÑ¿ô #Mstyle ¤Ï <tt>"style"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤È¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
+    Ãͤϡ¢¥Õ¥©¥ó¥È¤Î¥¹¥¿¥¤¥ë̾ ("r", "i", "o" Åù)¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£    */
+
+MSymbol Mstyle;
+
+/***en
+    @brief Key of font property specifying stretch.
+
+    The variable #Mstretch is a symbol of name <tt>"stretch"</tt> and
+    is used as a key of font property and face property.  The property
+    value must be a symbol whose name is a stretch name of a font (e.g
+    "normal", "condensed").  */ 
+/***ja
+    @brief Éý¤ò»ØÄꤹ¤ë¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼.
+    
+    ÊÑ¿ô #Mstretch ¤Ï <tt>"stretch"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤È¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
+    Ãͤϡ¢¥Õ¥©¥ó¥È¤Îʸ»úÉý̾ ( "normal", "condensed" Åù)¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£    */
+
+MSymbol Mstretch;
+
+/***en
+    @brief Key of font property specifying additional style.
+
+    The variable #Madstyle is a symbol of name <tt>"adstyle"</tt> and
+    is used as a key of font property and face property.  The property
+    value must be a symbol whose name is an additional style name of a
+    font (e.g "serif", "", "sans").  */ 
+/***ja
+    @brief adstyle ¤ò»ØÄꤹ¤ë¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼.
+    
+    ÊÑ¿ô #Madstyle ¤Ï <tt>"adstyle"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤È¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
+    Ãͤϡ¢¥Õ¥©¥ó¥È¤Î adstyle Ì¾("serif", "", "sans" Åù)¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£    */
+
+MSymbol Madstyle;
+
+/***en
+    @brief Key of font property specifying spacing.
+
+    The variable #Madstyle is a symbol of name <tt>"spacing"</tt> and
+    is used as a key of font property.  The property value must be a
+    symbol whose name specifies the spacing of a font (e.g "p" for
+    proportional, "m" for monospaced).  */ 
+/***ja
+    @brief spacing ¤ò»ØÄꤹ¤ë¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼.
+    
+    ÊÑ¿ô #Mspacing ¤Ï <tt>"spacing"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢
+    ¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£Ãͤϡ¢¥Õ¥©¥ó¥È¤Î spacing
+    ÆÃÀ­¤ò¼¨¤¹Ì¾Á° ("p", "m" Åù)¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£  */
+
+MSymbol Mspacing;
+
+/***en
+    @brief Key of font property specifying registry.
+
+    The variable #Mregistry is a symbol of name <tt>"registry"</tt>
+    and is used as a key of font property.  The property value must be
+    a symbol whose name is a registry name a font registry
+    (e.g. "iso8859-1", "jisx0208.1983-0").  */ 
+/***ja
+    @brief ¥ì¥¸¥¹¥È¥ê¤ò»ØÄꤹ¤ë¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼.
+    
+    ÊÑ¿ô #Mregistry ¤Ï <tt>"registry"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤È¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
+    Ãͤϡ¢¥Õ¥©¥ó¥È¤Î¥ì¥¸¥¹¥È¥ê̾ ( "iso8859-1", "jisx0208.1983-0" 
+    Åù) ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£    */
+
+MSymbol Mregistry;
+
+/***en
+    @brief Key of font property specifying size.
+
+    The variable #Msize is a symbol of name <tt>"size"</tt> and is
+    used as a key of font property and face property.  The property
+    value must be an integer specifying a font design size in the unit
+    of 1/10 point (on 100 dpi display).  */ 
+/***ja
+    @brief ¥µ¥¤¥º¤ò»ØÄꤹ¤ë¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼.
+    
+    ÊÑ¿ô #Msize ¤Ï <tt>"size"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤È¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£Ãͤϡ¢
+    100 dpi ¤Î¥Ç¥£¥¹¥×¥ì¥¤¾å¤Ç¤Î¥Õ¥©¥ó¥È¤Î¥Ç¥¶¥¤¥ó¥µ¥¤¥º¤ò 1/10 
+    ¥Ý¥¤¥ó¥Èñ°Ì¤Ç¼¨¤¹À°¿ôÃͤǤ¢¤ë¡£
+    */
+
+MSymbol Msize;
+
+/***en
+    @brief Key of font property specifying file name.
+
+    The variable #Mfontfile is a symbol of name <tt>"fontfile"</tt>
+    and is used as a key of font property.  The property value must be
+    a symbol whose name is a font file name.  */ 
+MSymbol Motf;
+
+/***en
+    @brief Key of font property specifying file name.
+
+    The variable #Mfontfile is a symbol of name <tt>"fontfile"</tt>
+    and is used as a key of font property.  The property value must be
+    a symbol whose name is a font file name.  */ 
+/***ja
+    @brief ¥Õ¥©¥ó¥È¥Õ¥¡¥¤¥ë¤ò»ØÄꤹ¤ë¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼.
+    
+    ÊÑ¿ô #Mfontfile ¤Ï <tt>"fontfile"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢
+    ¤ê¡¢¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£Ãͤϡ¢¥Õ¥©¥ó¥È¥Õ¥¡¥¤
+    ¥ë̾¤ò̾Á°¤È¤·¤Æ»ý¤Ä¤È¤¹¤ë¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£ */
+
+MSymbol Mfontfile;
+
+/***en
+    @brief Key of font property specifying resolution.
+
+    The variable #Mresolution is a symbol of name <tt>"resolution"</tt> and
+    is used as a key of font property and face property.  The property
+    value must be an integer to specifying a font resolution in the
+    unit of dots per inch (dpi).  */ 
+/***ja
+    @brief ²òÁüÅÙ¤ò»ØÄꤹ¤ë¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼.
+    
+    ÊÑ¿ô #Mresolution ¤Ï <tt>"resolution"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤È¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
+    Ãͤϡ¢¥Õ¥©¥ó¥È¤Î²òÁüÅÙ¤ò dots per inch (dpi) Ã±°Ì¤Ç¼¨¤¹À°¿ôÃͤǤ¢¤ë¡£    */
+
+MSymbol Mresolution;
+
+/***en
+    @brief Key of font property specifying max advance width.
+
+    The variable #Mmax_advance is a symbol of name
+    <tt>"max-advance"</tt> and is used as a key of font property.  The
+    property value must be an integer specifying a font's max advance
+    value by pixels.  */ 
+
+MSymbol Mmax_advance;
+
+
+/***en
+    @brief Symbol of name "fontconfig".
+
+    The variable #Mfontconfig is to be used as an argument of the
+    functions mfont_parse_name () and mfont_unparse_name ().  */
+/***ja
+    @brief "fontconfig" ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë.
+
+    ÊÑ¿ô #Mfontconfig ¤Ï´Ø¿ô mfont_parse_name () ¤È mfont_unparse_name ()
+    ¤Î°ú¿ô¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£  */
+
+MSymbol Mfontconfig;
+
+/***en
+    @brief Symbol of name "x".
+
+    The variable #Mx is to be used for a value of \<type\> member of the
+    structure #MDrawGlyph to specify the type of \<fontp\> member is
+    actually (XFontStruct *).  */
+/***ja
+    @brief "x" ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë.
+
+    ÊÑ¿ô #Mx ¤Ï¹½Â¤ #MDrawGlyph ¤Î¥á¥ó¥Ð \<type\> 
+    ¤ÎÃͤȤ·¤ÆÍѤ¤¤é¤ì¡¢¥á¥ó¥Ð \<fontp\> ¤Î·¿¤¬¼ÂºÝ¤Ë¤Ï (XFontStruct *) ¤Ç¤¢¤ë¤³¤È¤òɽ¤¹.  */
+
+MSymbol Mx;
+
+/***en
+    @brief Symbol of name "freetype".
+
+    The variable #Mfreetype is to be used for a value of \<type\> member
+    of the structure #MDrawGlyph to specify the type of \<fontp\> member
+    is actually FT_Face.  */
+/***ja
+    @brief "freetype" ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë.
+
+    ÊÑ¿ô #Mfreetype ¤Ï¹½Â¤ #MDrawGlyph ¤Î¥á¥ó¥Ð \<type\> 
+    ¤ÎÃͤȤ·¤ÆÍѤ¤¤é¤ì¡¢¥á¥ó¥Ð \<fontp\> ¤Î·¿¤¬¼ÂºÝ¤Ë¤Ï FT_Face ¤Ç¤¢¤ë¤³¤È¤òɽ¤¹¡£  */
+
+MSymbol Mfreetype;
+
+/***en
+    @brief Symbol of name "xft".
+
+    The variable #Mxft is to be used for a value of \<type\> member of the
+    structure #MDrawGlyph to specify the type of \<fontp\> member
+    is actually (XftFont *).  */
+/***ja
+    @brief  "xft" ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë.
+
+    ÊÑ¿ô #Mxft ¤Ï¹½Â¤ #MDrawGlyph ¤Î¥á¥ó¥Ð \<type\> 
+    ¤ÎÃͤȤ·¤ÆÍѤ¤¤é¤ì¡¢¥á¥ó¥Ð \<fontp\> ¤Î·¿¤¬¼ÂºÝ¤Ë¤Ï (XftFont *) ¤Ç¤¢¤ë¤³¤È¤òɽ¤¹¡£  */
+
+MSymbol Mxft;
+
+/*=*/
+/*** @} */
+/*=*/
+
+/***en
+    @brief List of font files and directories that contain font files.
+
+    The variable @c mfont_freetype_path is a plist of FreeType font
+    files and directories that contain FreeType font files.  Key of
+    the element is @c Mstring, and the value is a string that
+    represents a font file or a directory.
+
+    The macro M17N_INIT () sets up this variable to contain the
+    sub-directory "fonts" of the m17n database and the environment
+    variable "M17NDIR".  The first call of mframe () creates the
+    internal list of the actually available fonts from this variable.
+    Thus, an application program, if necessary, must modify the
+    variable before calling mframe ().  If it is going to add a new
+    element, value must be a string that can be safely freed.
+
+    If the m17n library is not configured to use the FreeType library,
+    this variable is not used.  */
+/***ja
+    @brief ¥Õ¥©¥ó¥È¥Õ¥¡¥¤¥ë¤È¥Õ¥©¥ó¥È¥Õ¥¡¥¤¥ë¤ò´Þ¤à¥Ç¥£¥ì¥¯¥È¥ê¤Î¥ê¥¹¥È.
+
+    ÊÑ¿ô @c mfont_freetype_path ¤Ï¡¢¥Õ¥©¥ó¥È¥Õ¥¡¥¤¥ë¤È¥Õ¥©¥ó¥È¥Õ¥¡¥¤¥ë¤ò´Þ¤à¥Ç¥£¥ì¥¯¥È¥ê¤Î 
+    plist ¤Ç¤¢¤ë¡£³ÆÍ×ÁǤΥ­¡¼¤Ï @c Mstring 
+    ¤Ç¤¢¤ê¡¢Ãͤϥե©¥ó¥È¥Õ¥¡¥¤¥ë¤«¥Ç¥£¥ì¥¯¥È¥ê¤ò¼¨¤¹Ê¸»úÎó¤Ç¤¢¤ë¡£
+
+    ¥Þ¥¯¥í M17N_INIT () ¤Ë¤è¤Ã¤Æ¡¢¤³¤ÎÊÑ¿ô¤Ï m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤È´Ä¶­ÊÑ¿ô 
+    "M17NDIR" ÁÐÊý¤Î¥µ¥Ö¥Ç¥£¥ì¥¯¥È¥ê "fonts" ¤ò´Þ¤à¤è¤¦¤ËÀßÄꤵ¤ì¤ë¡£
+    mframe () ¤ÎºÇ½é¤Î¸Æ¤Ó½Ð¤·¤ÎºÝ¤Ë¡¢¤³¤ÎÊÑ¿ô¤«¤é¼ÂºÝ¤Ë»ÈÍѤǤ­¤ë¥Õ¥©¥ó¥È¤ÎÆâÉô¥ê¥¹¥È¤¬ºî¤é¤ì¤ë¡£
+    ¤½¤³¤Ç¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï¡¢mframe () 
+    ¤ò¸Æ¤ÖÁ°¤Ë¡ÊɬÍפʤé¤Ð¡Ë¤³¤ÎÊÑ¿ô¤òÊѹ¹¤·¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+    ¿·¤·¤¤Í×ÁǤòÄɲ乤ë¾ì¹ç¤Ë¤Ï¡¢¤½¤ÎÃͤϰÂÁ´¤Ë³«Êü¤Ç¤­¤ëʸ»úÎó¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤¬ FreeType ¥é¥¤¥Ö¥é¥ê¤ò»È¤¦¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢¤³¤ÎÊÑ¿ô¤ÏÍѤ¤¤é¤ì¤Ê¤¤¡£ */
+
+MPlist *mfont_freetype_path;
+
+/*=*/
+
+/***en
+    @brief Create a new font.
+
+    The mfont () function creates a new font object that has no
+    property.
+
+    @return
+    This function returns a pointer to the created font object.  */
+/***ja
+    @brief ¿·¤·¤¤¥Õ¥©¥ó¥È¤òºî¤ë.
+
+    ´Ø¿ô mfont () ¤Ï¥×¥í¥Ñ¥Æ¥£¤ò°ìÀÚ»ý¤¿¤Ê¤¤¿·¤·¤¤¥Õ¥©¥ó¥È¤ò¥ª¥Ö¥¸¥§¥¯¥È¤òºî¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ïºî¤Ã¤¿¥Õ¥©¥ó¥È¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£  */
+
+MFont *
+mfont ()
+{
+  MFont *font;
+
+  MSTRUCT_CALLOC (font, MERROR_FONT);
+  return font;
+}
+
+/*=*/
+
+/***en
+    @brief Create a font by parsing a fontname.
+
+    The mfont_parse_name () function creates a new font object.  The
+    properties are extracted fontname $NAME.
+
+    $FORMAT specifies the format of $NAME.  If $FORMAT is #Mx, $NAME
+    is parsed as XLFD (X Logical Font Description).  If $FORMAT is
+    #Mfontconfig, $NAME is parsed as Fontconfig's textual
+    representation of font.  If $FORMAT is #Mnil, $NAME is at first
+    parsed as XLFD, and it it fails, parsed as Fontconfig's
+    representation.
+
+    @return
+    If the operation was successful, this function returns a pointer
+    to the created font.  Otherwise it returns @c NULL.  */
+
+/***ja
+    @brief ¥Õ¥©¥ó¥È̾¤«¤é¥Õ¥©¥ó¥È¤òºî¤ë.
+
+    ´Ø¿ô mfont_parse_name () ¤Ï¡¢¥Õ¥©¥ó¥È̾ 
+    $NAME ¤«¤é¼è¤ê½Ð¤µ¤ì¤¿¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¡¢¿·¤·¤¤¥Õ¥©¥ó¥È¥ª¥Ö¥¸¥§¥¯¥È¤òºî¤ë¡£
+
+    $FORMAT ¤Ï $NAME ¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤ò»ØÄꤹ¤ë¡£$FORMAT ¤¬ #Mx ¤Ç¤¢¤ì¤Ð¡¢
+    $NAME ¤Ï XLFD (X Logical Font Description) ¤Ë½¾¤Ã¤Æ²òÀϤµ¤ì¤ë¡£
+    $FORMAT ¤¬ #Mfontconfig ¤Ç¤¢¤ì¤Ð $NAME ¤Ï Fontfonfig 
+    ¤Î¥Õ¥©¥ó¥È¥Æ¥­¥¹¥Èɽ¸½¤Ë½¾¤Ã¤Æ²òÀϤµ¤ì¤ë¡£$FORMAT ¤¬ #Mnil ¤Ç¤¢¤ì¤Ð¡¢¤Þ¤º XLFD 
+    ¤Ë½¾¤Ã¤Æ²òÀϤµ¤ì¡¢¤½¤ì¤Ë¼ºÇÔ¤·¤¿¤é Fontconfig ¤Ë½¾¤Ã¤Æ²òÀϤµ¤ì¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mfont_parse_name () 
+    ¤Ï¿·¤·¤¯ºî¤é¤ì¤¿¥Õ¥©¥ó¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£  */
+
+MFont *
+mfont_parse_name (const char *name, MSymbol format)
+{
+  MFont template, *font;
+  
+  MFONT_INIT (&template);
+  if (mfont__parse_name_into_font (name, format, &template) < 0)
+    MERROR (MERROR_FONT, NULL);
+  MSTRUCT_CALLOC (font, MERROR_FONT);
+  *font = template;
+  return font;
+}
+
+/*=*/
+
+/***en
+    @brief Create a fontname from a font.
+
+    The mfont_unparse_name () function creates a fontname string
+    from font $FONT according to $FORMAT.
+
+    $FORMAT must be #Mx or #Mfontconfig.  If it is #Mx, the fontname
+    is in XLFD (X Logical Font Description) format.  If it is
+    #Mfontconfig, the fontname is in the style of Fontconfig's text
+    representation.
+
+    @return
+    This function returns a newly allocated fontname string, which is
+    not freed unless the user explicitly does so by free ().  */
+
+/***ja
+    @brief ¥Õ¥©¥ó¥È¤«¤é¥Õ¥©¥ó¥È̾¤òºî¤ë.
+
+    ´Ø¿ô mfont_unparse_name () ¤Ï ¥Õ¥©¥ó¥È̾¤Îʸ»úÎó¤ò¥Õ¥©¥ó¥È $FONT 
+    ¤ò¸µ¤Ë$FORMAT ¤Ë½¾¤Ã¤Æºî¤ë¡£
+
+    $FORMAT ¤Ï #Mx ¤Þ¤¿¤Ï #Mfontconfig ¤Ç¤¢¤ë¡£
+    #Mx ¤Ê¤é¤Ð¥Õ¥©¥ó¥È̾¤Ï XLFD (X Logical Font Description) ¤Ë½¾¤¦¡£
+    #Mfontconfig ¤Ê¤é¤Ð¥Õ¥©¥ó¥È̾¤Ï Fontconfig ¤Î¥Õ¥©¥ó¥È¥Æ¥­¥¹¥Èɽ¸½¤Ë½¾¤¦¡£
+
+    @return 
+    ¤³¤Î´Ø¿ô¤Ï¿·¤¿¤Ë¥¢¥í¥±¡¼¥È¤·¤¿¥Õ¥©¥ó¥È̾¤Îʸ»úÎó¤òÊÖ¤¹¡£Ê¸»úÎó¤Ï¡¢¥æ¡¼¥¶¤¬
+    free () ¤Ë¤è¤Ã¤ÆÌÀ¼¨Åª¤Ë²òÊü¤·¤Ê¤¤¸Â¤ê²òÊü¤µ¤ì¤Ê¤¤¡£  */
+
+char *
+mfont_unparse_name (MFont *font, MSymbol format)
+{
+  char *name;
+
+  if (format == Mx)
+    name = xlfd_unparse_name (font, 1);
+#ifdef HAVE_FONTCONFIG
+  else if (format == Mfontconfig)
+    name = mfont__ft_unparse_name (font);
+
+#endif /* HAVE_FONTCONFIG */
+  else
+    MERROR (MERROR_FONT, NULL);
+  return name;
+}
+
+/*=*/
+
+/***en
+    @brief Make a copy of a font.
+
+    The mfont_copy () function returns a new copy of font $FONT.  */
+/***ja
+    @brief ¥Õ¥©¥ó¥È¤Î¥³¥Ô¡¼¤òºî¤ë.
+
+    ´Ø¿ô Mfont_copy () ¤Ï¥Õ¥©¥ó¥È $FONT ¤Î¥³¥Ô¡¼¤òºî¤ê¡¢¤½¤ì¤òÊÖ¤¹¡£ */
+
+MFont *
+mfont_copy (MFont *font)
+{
+  MFont *copy;
+
+  MSTRUCT_MALLOC (copy, MERROR_FONT);
+  *copy = *font;
+  return copy;
+}
+
+/*=*/
+
+/***en
+    @brief Get a property value of a font.
+
+    The mfont_get_prop () function gets the value of $KEY property of
+    font $FONT.  $KEY must be one of the following symbols:
+
+       @c Mfoundry, @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
+       @c Madstyle, @c Mregistry, @c Msize, @c Mresolution, @c Mspacing.
+
+    If $FONT is a return value of mfont_find (), $KEY can also be one
+    of the following symbols:
+
+       @b Mfont_ascent, @b Mfont_descent, #Mmax_advance.
+
+    @return 
+    If $KEY is @c Mfoundry, @c Mfamily, @c Mweight, @c Mstyle,
+    @c Mstretch, @c Madstyle, @c Mregistry, or @c Mspacing, this
+    function returns the corresponding value as a symbol.  If the font
+    does not have $KEY property, it returns @c Mnil.  If $KEY is @c
+    Msize, @c Mresolution, @b Mfont_ascent, Mfont_descent, or
+    #Mmax_advance, this function returns the corresponding value as an
+    integer.  If the font does not have $KEY property, it returns 0.
+    If $KEY is something else, it returns @c NULL and assigns an error
+    code to the external variable #merror_code.  */
+/***ja
+    @brief ¥Õ¥©¥ó¥È¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë.
+
+    ´Ø¿ô mfont_get_prop () ¤Ï¥Õ¥©¥ó¥È $FONT ¤Î¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¡¢¥­¡¼¤¬
+    $KEY ¤Ç¤¢¤ë¤â¤Î¤ÎÃͤòÊÖ¤¹¡£$KEY ¤Ï°Ê²¼¤Î¥·¥ó¥Ü¥ë¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤±¤ì
+    ¤Ð¤Ê¤é¤Ê¤¤¡£
+
+       @c Mfoundry, @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
+       @c Madstyle, @c Mregistry, @c Msize, @c Mresolution, @c Mspacing.
+
+    @return 
+    $KEY ¤¬ @c Mfoundry, @c Mfamily, @c Mweight, @c Mstyle, @c
+    Mstretch, @c Madstyle, @c Mregistry, @c Mspacing ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ì¤Ð¡¢
+    ÁêÅö¤¹¤ëÃͤò¥·¥ó¥Ü¥ë¤È¤·¤ÆÊÖ¤¹¡£¥Õ¥©¥ó¥È¤¬¤½¤Î¥×¥í¥Ñ¥Æ¥£¤ò»ý¤¿¤Ê¤¤
+    ¾ì¹ç¤Ë¤Ï@c Mnil ¤òÊÖ¤¹¡£$KEY ¤¬ @c Msize ¤¢¤ë¤¤¤Ï @c Mresolution ¤Î
+    ¾ì¹ç¤Ë¤Ï¡¢ÁêÅö¤¹¤ëÃͤò¤ÏÀ°¿ôÃͤȤ·¤ÆÊÖ¤¹¡£¥Õ¥©¥ó¥È¤¬¤½¤Î¥×¥í¥Ñ¥Æ¥£
+    ¤ò»ý¤¿¤Ê¤¤¾ì¹ç¤Ë¤Ï 0 ¤òÊÖ¤¹¡£$KEY ¤¬¤½¤ì°Ê³°¤Î¤â¤Î¤Ç¤¢¤ì¤Ð¡¢@c
+    NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+void *
+mfont_get_prop (MFont *font, MSymbol key)
+{
+  MRealizedFont *rfont = NULL;
+
+  if (font->type == MFONT_TYPE_REALIZED)
+    rfont = (MRealizedFont *) font;
+
+  if (key == Mfoundry)
+    return (void *) FONT_PROPERTY (font, MFONT_FOUNDRY);
+  if (key == Mfamily)
+    return (void *) FONT_PROPERTY (font, MFONT_FAMILY);
+  if (key == Mweight)
+    return (void *) FONT_PROPERTY (font, MFONT_WEIGHT);
+  if (key == Mstyle)
+    return (void *) FONT_PROPERTY (font, MFONT_STYLE);
+  if (key == Mstretch)
+    return (void *) FONT_PROPERTY (font, MFONT_STRETCH);
+  if (key == Madstyle)
+    return (void *) FONT_PROPERTY (font, MFONT_ADSTYLE);
+  if (key == Mregistry)
+    return (void *) FONT_PROPERTY (font, MFONT_REGISTRY);
+  if (key == Msize)
+    {
+      int size = font->size;
+      return (void *) size;
+    }
+  if (key == Mresolution)
+    {
+      int resy = font->property[MFONT_RESY];
+      return (void *) resy;
+    }
+  if (key == Mlanguage || key == Mscript || key == Motf)
+    {
+      MFontCapability *cap;
+
+      if (! font->capability)
+       return NULL;
+      cap = mfont__get_capability (font->capability);
+      if (key == Mlanguage)
+       return cap->language;
+      if (key == Mscript)
+       return cap->script;
+      return cap->otf;
+    }
+
+  if (key == Mfontfile)
+    return (void *) font->file;
+  if (key == Mspacing)
+    return (font->spacing == MFONT_SPACING_UNDECIDED ? Mnil
+           : msymbol (font->spacing == MFONT_SPACING_PROPORTIONAL ? "p"
+                      : font->spacing == MFONT_SPACING_MONO ? "m" : "c"));
+  if (rfont)
+    {
+      if (key == Mfont_ascent)
+       return (void *) rfont->ascent;
+      if (key == Mfont_descent)
+       return (void *) rfont->descent;
+      if (key == Mmax_advance)
+       return (void *) rfont->max_advance;
+    }
+  MERROR (MERROR_FONT, NULL);
+}
+
+
+/*=*/
+/***en
+    @brief Put a property value to a font.
+
+    The mfont_put_prop () function puts a font property whose key is
+    $KEY and value is $VAL to font $FONT.  $KEY must be one of the
+    following symbols:
+
+       @c Mfoundry, @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
+       @c Madstyle, @c Mregistry, @c Msize, @c Mresolution.
+
+    If $KEY is @c Msize or @c Mresolution, $VAL must be an integer.
+    Otherwise, $VAL must be a symbol of a property value name.  But,
+    if the name is "nil", a symbol of name "Nil" must be
+    specified.  */
+ /***ja
+    @brief ¥Õ¥©¥ó¥È¤Î¥×¥í¥Ñ¥Æ¥£¤ËÃͤòÀßÄꤹ¤ë.
+
+    ´Ø¿ô mfont_put_prop () ¤Ï¡¢¥Õ¥©¥ó¥È $FONT ¤Î¥­¡¼¤¬$KEY ¤Ç¤¢¤ë¥×¥í¥Ñ
+    ¥Æ¥£¤ÎÃͤò $VAL ¤ËÀßÄꤹ¤ë¡£$KEY ¤Ï°Ê²¼¤Î¥·¥ó¥Ü¥ë¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£
+
+       @c Mfoundry, @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
+       @c Madstyle, @c Mregistry, @c Msize, @c Mresolution.
+
+    $KEY ¤¬ @c Msize ¤« @c Mresolution ¤Ç¤¢¤ì¤Ð $VAL ¤ÏÀ°¿ôÃͤǤʤ¯¤Æ¤Ï
+    ¤é¤Ê¤¤¡£¤½¤ì°Ê³°¤Î¾ì¹ç¡¢$VAL ¤Ï¥×¥í¥Ñ¥Æ¥£ÃͤÎ̾Á°¤Î¥·¥ó¥Ü¥ë¤Ç¤Ê¤¯¤Æ
+    ¤Ï¤Ê¤é¤Ê¤¤¡£¤¿¤À¤·¤â¤·¤½¤Î̾Á°¤¬ "nil" ¤Î¾ì¹ç¤Ï¡¢Ì¾Á°¤¬ "Nil" ¤Î¥·
+    ¥ó¥Ü¥ë¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£*/
+
+int
+mfont_put_prop (MFont *font, MSymbol key, void *val)
+{
+  if (key == Mfoundry)
+    mfont__set_property (font, MFONT_FOUNDRY, (MSymbol) val);
+  else if (key == Mfamily)
+    mfont__set_property (font, MFONT_FAMILY, (MSymbol) val);
+  else if (key == Mweight)
+    mfont__set_property (font, MFONT_WEIGHT, (MSymbol) val);
+  else if (key == Mstyle)
+    mfont__set_property (font, MFONT_STYLE, (MSymbol) val);
+  else if (key == Mstretch)
+    mfont__set_property (font, MFONT_STRETCH, (MSymbol) val);
+  else if (key == Madstyle)
+    mfont__set_property (font, MFONT_ADSTYLE, (MSymbol) val);
+  else if (key == Mregistry)
+    mfont__set_property (font, MFONT_REGISTRY, (MSymbol) val);
+  else if (key == Msize)
+    {
+      int size = (int) val;
+      font->size = size;
+    }
+  else if (key == Mresolution)
+    {
+      unsigned resy = (unsigned) val;
+      font->property[MFONT_RESY] = resy;
+    }
+  else if (key == Mlanguage || key == Mscript || key == Motf)
+    {
+      font->capability = merge_capability (font->capability,
+                                          key, (MSymbol) val, 1);
+    }
+  else if (key == Mfontfile)
+    {
+      font->file = (MSymbol) val;
+    }
+  else
+    MERROR (MERROR_FONT, -1);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Return the font selection priority.
+
+    The mfont_selection_priority () function returns a newly created
+    array of six symbols.  The elements are the following
+    keys of font properties ordered by priority.
+
+       @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
+       @c Madstyle, @c Msize.
+
+   The m17n library selects the best matching font according to the
+   order of this array.  A font that has a different value for a
+   property of lower priority is preferred to a font that has a
+   different value for a property of higher priority.  */
+/***ja
+    @brief ¥Õ¥©¥ó¥ÈÁªÂò¤ÎÍ¥ÀèÅÙ¤òÊÖ¤¹.
+
+    ´Ø¿ô mfont_selection_priority () ¤Ï 6 ¤Ä¤Î¥·¥ó¥Ü¥ë¤«¤é¤Ê¤ëÇÛÎó¤òºî¤Ã¤ÆÊÖ¤¹¡£
+    ÇÛÎó¤ÎÍ×ÁǤϡ¢°Ê²¼¤Î¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤òÍ¥ÀèÅÙ½ç¤Ëʤ٤¿¤â¤Î¤Ç¤¢¤ë¡£
+
+       @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
+       @c Madstyle, @c Msize.
+
+   m17n ¥é¥¤¥Ö¥é¥ê¤Ï¤³¤ÎÇÛÎó¤Ë½¾¤Ã¤Æ¡¢ºÇ¤â¹çÃפ¹¤ë¥Õ¥©¥ó¥È¤òÁªÂò¤¹¤ë¡£
+   ÌÜŪ¤Î¥Õ¥©¥ó¥È¤È¡¢¤½¤ì¤¾¤ì°ã¤¦¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬¹çÃפ·¤Ê¤¤¥Õ¥©¥ó¥È¤¬¤¢¤Ã¤¿¾ì¹ç¡¢Í¥ÀèÅÙ¤ÎÄ㤤¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬¹çÃפ·¤Ê¤¤¥Õ¥©¥ó¥È¡ÊÍ¥ÀèÅ٤ι⤤¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬¹çÃפ·¤Æ¤¤¤ë¥Õ¥©¥ó¥È¡Ë¤¬ÁªÂò¤µ¤ì¤ë¡£
+
+   */
+
+MSymbol *
+mfont_selection_priority ()
+{
+  MSymbol *keys;
+  int i;
+
+  MTABLE_MALLOC (keys, FONT_SCORE_PRIORITY_SIZE, MERROR_FONT);
+  for (i = 0; i < FONT_SCORE_PRIORITY_SIZE; i++)
+    {
+      enum MFontProperty prop = font_score_priority[i];
+
+      if (prop == MFONT_SIZE)
+       keys[i] = Msize;
+      else if (prop == MFONT_ADSTYLE)
+       keys[i] = Madstyle;
+      else if (prop == MFONT_FAMILY)
+       keys[i] = Mfamily;
+      else if (prop == MFONT_WEIGHT)
+       keys[i] = Mweight;
+      else if (prop == MFONT_STYLE)
+       keys[i] = Mstyle;
+      else if (prop == MFONT_STRETCH)
+       keys[i] = Mstretch;
+      else
+       keys[i] = Mfoundry;
+    }
+  return keys;
+}
+
+/*=*/
+
+/***en
+    @brief Set the font selection priority.
+
+    The mfont_set_selection_priority () function sets font selection
+    priority according to $KEYS, which is an array of six symbols.
+    Each element must be one of the below.  No two elements must be
+    the same.
+
+       @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
+       @c Madstyle, @c Msize.
+
+    See the documentation of the function mfont_selection_priority ()
+    for details.  */
+/***ja
+    @brief ¥Õ¥©¥ó¥ÈÁªÂòÍ¥ÀèÅÙ¤òÀßÄꤹ¤ë.
+
+    ´Ø¿ô mfont_set_selection_priority () ¤Ï¡¢6¤Ä¤Î¥·¥ó¥Ü¥ë¤ÎÇÛÎó $KEYS 
+    ¤Ë¤·¤¿¤¬¤Ã¤Æ¥Õ¥©¥ó¥ÈÁªÂòÍ¥ÀèÅÙ¤òÀßÄꤹ¤ë¡£ÇÛÎó¤Ï°Ê²¼¤Î³ÆÍ×ÁǤòŬÀÚ
+    ¤Ê½çÈÖ¤Çʤ٤¿¤â¤Î¤Ç¤¢¤ë¡£
+
+       @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
+       @c Madstyle, @c Msize.
+
+    ¾ÜºÙ¤Ï´Ø¿ô mfont_selection_priority () ¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£
+     */
+
+int
+mfont_set_selection_priority (MSymbol *keys)
+{
+  int priority[FONT_SCORE_PRIORITY_SIZE];
+  int i, j, shift;
+
+  for (i = 0; i < FONT_SCORE_PRIORITY_SIZE; i++, keys++)
+    {
+      enum MFontProperty prop;
+
+      if (*keys == Msize)
+       prop = MFONT_SIZE;
+      else if (*keys == Madstyle)
+       prop = MFONT_ADSTYLE;
+      else if (*keys == Mfamily)
+       prop = MFONT_FAMILY;
+      else if (*keys == Mweight)
+       prop = MFONT_WEIGHT;
+      else if (*keys == Mstyle)
+       prop = MFONT_STYLE;
+      else if (*keys == Mstretch)
+       prop = MFONT_STRETCH;
+      else if (*keys == Mfoundry)
+       prop = MFONT_FOUNDRY;
+      else
+       /* Invalid element.  */
+       return -1;
+      for (j = 0; j < i; j++)
+       if (priority[j] == prop)
+         /* Duplicated element.  */
+         return -1;
+      priority[i] = prop;
+    }
+  for (i = 0; i < FONT_SCORE_PRIORITY_SIZE; i++)
+    font_score_priority[i] = priority[i];
+  /* Here, SHIFT starts from 1, not 0.  This is because the lowest bit
+     of a score is a flag for a scalable font (see the documentation
+     of font_score).  */
+  i = FONT_SCORE_PRIORITY_SIZE - 1;
+  for (shift = 1; i >= 0; i--)
+    {
+      font_score_shift_bits[font_score_priority[i]] = shift;
+      if (font_score_priority[i] == MFONT_SIZE)
+       shift += 16;
+      else if (font_score_priority[i] <= MFONT_FAMILY)
+       shift++;
+      else
+       shift += 2;
+    }
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Find a font.
+
+    The mfont_find () function returns a pointer to the available font
+    that matches best the specification $SPEC on frame $FRAME.
+
+    $SCORE, if not NULL, must point to a place to store the score
+    value that indicates how well the found font matches to $SPEC.  The
+    smaller score means a better match.  */
+/***ja
+    @brief ¥Õ¥©¥ó¥È¤òõ¤¹.
+
+    ´Ø¿ô mfont_find () ¤Ï¡¢¥Õ¥ì¡¼¥à $FRAME ¾å¤Ç¥Õ¥©¥ó¥ÈÄêµÁ $SPEC 
+    ¤Ë¤â¤Ã¤È¤â¹çÃפ¹¤ëÍøÍѲÄǽ¤Ê¥Õ¥©¥ó¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£  
+
+    $SCORE ¤Ï NULL ¤Ç¤¢¤ë¤«¡¢¸«¤Ä¤«¤Ã¤¿¥Õ¥©¥ó¥È¤¬ $SPEC 
+    ¤Ë¤É¤ì¤Û¤É¹ç¤Ã¤Æ¤¤¤ë¤«¤ò¼¨¤¹¥¹¥³¥¢¤òÊݸ¤¹¤ë¾ì½ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    ¥¹¥³¥¢¤¬¾®¤µ¤¤¤Û¤ÉÎɤ¯¹ç¤Ã¤Æ¤¤¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
+    */
+
+MFont *
+mfont_find (MFrame *frame, MFont *spec, int *score, int max_size)
+{
+  MFont spec_copy;
+  MFont *best;
+  MFontList *list;
+  MRealizedFont *rfont;
+  MFont adjusted;
+
+  if (spec->size < 0)
+    {
+      double pt = - spec->size;
+
+      adjusted = *spec;
+      adjusted.size = pt * frame->dpi / 72.27 + 0.5;
+      spec = &adjusted;
+    }
+  MFONT_INIT (&spec_copy);
+  spec_copy.property[MFONT_FAMILY] = spec->property[MFONT_FAMILY];
+  spec_copy.property[MFONT_REGISTRY] = spec->property[MFONT_REGISTRY];
+  spec_copy.capability = spec->capability;
+  spec_copy.file = spec->file;
+
+  list = mfont__list (frame, &spec_copy, spec, max_size);
+  if (! list)
+    return NULL;
+
+  best = list->fonts[0].font;
+  if (score)
+    *score = list->fonts[0].score;
+  free (list->fonts);
+  free (list);
+  spec_copy = *best;
+  mfont__merge (&spec_copy, spec, 0);
+  rfont = mfont__open (frame, best, spec);
+  if (! rfont)
+    return NULL;
+  return (MFont *) rfont;
+}
+
+/*=*/
+/***en
+    @brief Set encoding of a font.
+
+    The mfont_set_encoding () function sets the encoding information
+    of font $FONT.
+
+    $ENCODING_NAME is a symbol representing a charset that has the
+    same encoding as the font.
+
+    $REPERTORY_NAME is @c Mnil or a symbol representing a charset that
+    has the same repertory as the font.  If it is @c Mnil, whether a
+    specific character is supported by the font is asked to each font
+    driver.
+
+    @return
+    If the operation was successful, this function returns 0.
+    Otherwise it returns -1 and assigns an error code to the external
+    variable #merror_code.  */
+/***ja
+    @brief ¥Õ¥©¥ó¥È¤Î¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤òÀßÄꤹ¤ë.
+
+    ´Ø¿ô mfont_set_encoding () ¤Ï¥Õ¥©¥ó¥È $FONT ¤Î¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¾ðÊó¤òÀßÄꤹ¤ë¡£
+
+    $ENCODING_NAME ¤Ï¥Õ¥©¥ó¥È¤ÈƱ¤¸¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤ò»ý¤Äʸ»ú¥»¥Ã¥È¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    $REPERTORY_NAME ¤Ï @c Mnil ¤Ç¤¢¤ë¤«¡¢¥Õ¥©¥ó¥È¤ÈƱ¤¸¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤ò»ý¤Äʸ»ú¥»¥Ã¥È¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+    @c Mnil ¤Ç¤¢¤ì¤Ð¡¢¸Ä¡¹¤Îʸ»ú¤¬¤½¤Î¥Õ¥©¥ó¥È¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤Ï¡¢³Æ¡¹¤Î¥Õ¥©¥ó¥È¥É¥é¥¤¥Ð¤ËÌ䤤¹ç¤ï¤»¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¤³¤Î´Ø¿ô¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô
+    #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+
+int
+mfont_set_encoding (MFont *font, MSymbol encoding_name, MSymbol repertory_name)
+{
+  MCharset *encoding_charset = MCHARSET (encoding_name);
+  MCharset *repertory_charset;
+  MSymbol registry;
+  MFontEncoding *encoding;
+  MPlist *plist;
+
+  if (! encoding_charset)
+    MERROR (MERROR_FONT, -1);
+  if (repertory_name != Mnil)
+    {
+      repertory_charset = MCHARSET (repertory_name);
+      if (! repertory_charset)
+       MERROR (MERROR_FONT, -1);
+    }
+  else
+    repertory_charset = NULL;
+
+  MSTRUCT_CALLOC (encoding, MERROR_FONT);
+  encoding->spec = *font;
+  encoding->encoding_name = encoding_name;
+  encoding->encoding_charset = encoding_charset;
+  encoding->repertory_name = repertory_name;
+  encoding->repertory_charset = repertory_charset;
+  registry = FONT_PROPERTY (font, MFONT_REGISTRY);
+  if (registry == Mnil)
+    registry = Mt;
+  if (! font_encoding_list)
+    load_font_encoding_table ();
+  mplist_push (font_encoding_list, registry, encoding);
+  MPLIST_DO (plist, MPLIST_NEXT (font_encoding_list))
+    if (! memcmp (font, &((MFontEncoding *) MPLIST_VAL (plist))->spec,
+                 sizeof (MFont)))
+      {
+       mplist_pop (plist);
+       break;
+      }
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Create a fontname from a font.
+
+    This function is obsolete.   Use mfont_unparse_name instead. */
+/***ja
+    @brief ¥Õ¥©¥ó¥È̾¤«¤é¥Õ¥©¥ó¥È¤òºî¤ë.
+
+    ¤³¤Î´Ø¿ô¤ÏÇÑ»ßͽÄê¤Ç¤¢¤ë¡£ mfont_unparse_name () ¤ò»ÈÍѤΤ³¤È¡£ */
+
+char *
+mfont_name (MFont *font)
+{
+  return mfont_unparse_name (font, Mx);
+}
+
+/*=*/
+
+/***en
+    @brief Create a new font from fontname.
+
+    This function is obsolete.  Use mfont_parse_name () instead.  */
+
+/***ja
+    @brief ¥Õ¥©¥ó¥È¤«¤é¥Õ¥©¥ó¥È̾¤òºî¤ë.
+
+    ¤³¤ì¤Ï´Ø¿ô¤ÏÇÑ»ßͽÄê¤Ç¤¢¤ë¡£ mfont_parse_name () ¤ò»ÈÍѤΤ³¤È¡£  */
+
+MFont *
+mfont_from_name (const char *name)
+{
+  return mfont_parse_name (name, Mx);
+}
+
+/*=*/
+
+/***en
+    @brief Get resize information of a font.
+
+    The mfont_resize_ratio () function lookups the m17n database
+    \<font, reisize\> and returns a resizing ratio (in percentage) of
+    FONT.  For instance, if the return value is 150, that means that
+    the m17n library uses an 1.5 time bigger font than a specified
+    size.  */
+
+/***ja
+    @brief ¥Õ¥©¥ó¥È¤Î¥ê¥µ¥¤¥º¾ðÊó¤òÆÀ¤ë
+
+    ´Ø¿ô mfont_resize_ratio ¤Ï m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹ \<font, reisize\> 
+    ¤ò¸¡º÷¤·¡¢¥Õ¥©¥ó¥È FONT ¤Î¥ê¥µ¥¤¥º¤ÎÈæΨ¡Ê¥Ñ¡¼¥»¥ó¥Æ¡¼¥¸¡Ë
+    ¤òÊÖ¤¹¡£¤¿¤È¤¨¤ÐÊÖ¤¹Ãͤ¬ 150 ¤Ç¤¢¤ì¤Ð¡¢m17n ¥é¥¤¥Ö¥é¥ê¤Ï»ØÄꤵ¤ì¤¿¥µ¥¤¥º¤Î 1.5 
+    ÇܤΥե©¥ó¥È¤ò»ÈÍѤ¹¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£ */
+
+int
+mfont_resize_ratio (MFont *font)
+{
+  MSymbol registry = FONT_PROPERTY (font, MFONT_REGISTRY);
+  MFontResize *resize;
+  MPlist *plist;
+
+  if (! font_resize_list)
+    load_font_resize_table ();
+  if (! MPLIST_TAIL_P (font_resize_list))
+    while (1)
+      {
+       plist = font_resize_list;
+       while (registry ? (plist = mplist_find_by_key (plist, registry))
+              : plist)
+         {
+           resize = (MFontResize *) MPLIST_VAL (plist);
+           if (mfont__match_p (font, &resize->spec, MFONT_ADSTYLE))
+             return resize->resize;
+           plist = MPLIST_NEXT (plist);
+         }
+       if (registry == Mt)
+         break;
+       registry = Mt;
+      }
+  return 100;
+}
+
+/*=*/
+
+/***en
+    @brief Get a list of fonts.
+
+    The mfont_list () functions returns a list of fonts available on
+    frame $FRAME.  $FONT, if not NULL, limits fonts to ones
+    that match with $FONT.  $LANGUAGE, if not @c Mnil, limits fonts to
+    ones that support $LANGUAGE.  $MAXNUM, if greater than 0, limits
+    the number of fonts.
+
+    $LANGUAGE argument exists just for backward compatibility, and the
+    use is deprecated.  Use #Mlanguage font property instead.  If
+    $FONT already has #Mlanguage property, $LANGUAGE is ignored.
+
+    @return
+    This function returns a plist whose keys are family names and
+    values are pointers to the object MFont.  The plist must be freed
+    by m17n_object_unref ().  If no font is found, it returns
+    NULL.  */
+
+/***ja
+    @brief ¥Õ¥©¥ó¥È¤Î¥ê¥¹¥È¤òÆÀ¤ë
+
+    ´Ø¿ô mfont_list () ¤Ï¥Õ¥ì¡¼¥à $FRAME ¤ÇÍøÍѲÄǽ¤Ê¥Õ¥©¥ó¥È¤Î¥ê¥¹¥È¤ò
+    ÊÖ¤¹¡£$FONT ¤¬ NULL ¤Ç¤Ê¤±¤ì¤Ð¡¢$FONT ¤È¹çÃפ¹¤ëÍøÍѲÄǽ¤Ê¥Õ¥©¥ó¥È
+    ¤Î¥ê¥¹¥È¤òÊÖ¤¹¡£$LANGUAGE ¤¬ @c Mnil ¤Ç¤Ê¤±¤ì¤Ð¡¢$LANGUAGE ¤ò¥µ¥Ý¡¼
+    ¥È¤¹¤ëÍøÍѲÄǽ¤Ê¥Õ¥©¥ó¥È¤Î¥ê¥¹¥È¤òÊÖ¤¹¡£$MAXNUM ¤Ï¡¢0 ¤è¤êÂ礭¤¤¾ì
+    ¹ç¤Ë¤Ï¡¢ÊÖ¤¹¥Õ¥©¥ó¥È¤Î¿ô¤Î¾å¸Â¤Ç¤¢¤ë¡£
+
+    ¤¿¤À¤·¡¢°ú¿ô $LANGUAGE ¤ÏµìÈǤȤÎÀ°¹çÀ­¤Î¤¿¤á¤À¤±¤Ë¤¢¤ê¡¢¤½¤Î»ÈÍѤÏ
+    ´«¤á¤é¤ì¤Ê¤¤¡£¥Õ¥©¥ó¥È¤Î #Mlanguage ¥×¥í¥Ñ¥Æ¥£¤ò»È¤¦¤Ù¤­¤Ç¤¢¤ë¡£¤â
+    ¤· $FONT ¤¬¤¹¤Ç¤Ë¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ã¤Æ¤¤¤¿¤é¡¢°ú¿ô $LANGUAGE ¤Ï̵
+
+
+    @return 
+    ¤³¤Î´Ø¿ô¤Ï¥­¡¼¤¬¥Õ¥©¥ó¥È¥Õ¥¡¥ß¥ê̾¤Ç¤¢¤êÃͤ¬ MFont ¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î
+    ¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¤è¤¦¤Êplist ¤òÊÖ¤¹¡£plist ¤Ï m17n_object_unref () ¤Ç
+    ²òÊü¤¹¤ëɬÍפ¬¤¢¤ë¡£¥Õ¥©¥ó¥È¤¬¸«¤Ä¤«¤é¤Ê¤±¤ì¤ÐNULL ¤òÊÖ¤¹¡£  */
+
+MPlist *
+mfont_list (MFrame *frame, MFont *font, MSymbol language, int maxnum)
+{
+  MPlist *plist, *pl;
+  MFontList *font_list;
+  int i;
+  MFont spec;
+  
+  if (font)
+    spec = *font;
+  else
+    MFONT_INIT (&spec);
+
+  if (spec.size < 0)
+    {
+      double pt = - spec.size;
+
+      spec.size = pt * frame->dpi / 72.27 + 0.5;
+    }
+
+  if (language != Mnil)
+    spec.capability = merge_capability (spec.capability, Mlanguage, language,
+                                       0);
+
+  font_list = mfont__list (frame, &spec, &spec, 0);
+  if (! font_list)
+    return NULL;
+  if (font_list->nfonts == 0)
+    {
+      free (font_list);
+      return NULL;
+    }
+
+  plist = pl = mplist ();
+  for (i = 0; i < font_list->nfonts; i++)
+    {
+      MSymbol family = FONT_PROPERTY (font_list->fonts[i].font, MFONT_FAMILY);
+
+      if (family != Mnil)
+       pl = mplist_add (pl, family, font_list->fonts[i].font);
+    }
+  free (font_list);
+  return plist;
+}
+
+/***en
+    @brief Get a list of font famiy names.
+
+    The mfont_list_family_names () functions returns a list of font
+    family names available on frame $FRAME.
+
+    @return
+
+    This function returns a plist whose keys are #Msymbol and values
+    are symbols representing font family names.  The elements are
+    sorted by alphabetical order.  The plist must be freed by
+    m17n_object_unref ().  If not font is found, it returns NULL.  */
+
+MPlist *
+mfont_list_family_names (MFrame *frame)
+{
+  MPlist *plist = mplist (), *p;
+
+  MPLIST_DO (p, frame->font_driver_list)
+    {
+      MFontDriver *driver = MPLIST_VAL (p);
+
+      (driver->list_family_names) (frame, plist);
+    }
+  return plist;
+}
+
+
+/*=*/
+
+/***en
+    @brief Check the usability of a font.
+
+    The mfont_check () function checkes if $FONT can be used for
+    $SCRIPT and $LANGUAGE in $FONTSET on $FRAME.
+
+    @return 
+    If the font is usable, return 1.  Otherwise return 0.
+ */
+
+int
+mfont_check (MFrame *frame, MFontset *fontset,
+            MSymbol script, MSymbol language, MFont *font)
+{
+  MRealizedFont *rfont;
+  int best, score;
+
+  if (! fontset)
+    fontset = frame->face->property[MFACE_FONTSET];
+  rfont = mfontset__get_font (frame, fontset, script, language, font, &best);
+  if (! rfont || ! best)
+    return 0;
+  score = font_score (&rfont->spec, font);
+  return (score == 0 ? 2 : 1);
+}
+
+/*=*/
+
+/***en
+    @brief Check is a font matches with a font spec.
+
+    The mfont_match_p () function checks if $FONT matches with the
+    font-spec $SPEC.
+
+    @return 
+    If the font matches, 1 is returned.  Otherwise 0 is returned.  */
+
+int
+mfont_match_p (MFont *font, MFont *spec)
+{
+  return mfont__match_p (font, spec, MFONT_REGISTRY);
+}
+
+/*=*/
+/***en
+    @brief Open a font.
+
+    The mfont_open () function opens $FONT on $FRAME, and returns a
+    realized font.
+
+    @return
+    If the font was successfully opened, a realized font is returned.
+    Otherwize NULL is returned.
+
+    @seealso
+    mfont_close ().  */
+
+
+MFont *
+mfont_open (MFrame *frame, MFont *font)
+{
+  enum MFontType font_type = font->type;
+
+  if (font_type == MFONT_TYPE_SPEC)
+    return mfont_find (frame, font, NULL, 0);
+  if (font_type == MFONT_TYPE_OBJECT)
+    return (MFont *) mfont__open (frame, font, font);
+  if (font_type == MFONT_TYPE_REALIZED)
+    return font;
+  MERROR (MERROR_FONT, NULL);
+}
+
+/*=*/
+/***en
+    @brief Encapusulate a font.
+
+    The mfont_encapsulate () functions realizes a font by
+    encapusulating data $DATA or type $DATA_TYPE on $FRAME.  Currently
+    $DATA_TAPE is #Mfontconfig or #Mfreetype, and $DATA points to an
+    object of FcPattern or FT_Face respectively.
+
+    @return
+    If the operation was successful, a realized font is returned.
+    Otherwise NULL is return.
+
+    @seealso
+    mfont_close ().  */
+
+
+MFont *
+mfont_encapsulate (MFrame *frame, MSymbol data_type, void *data)
+{
+  MPlist *p;
+
+  MPLIST_DO (p, frame->font_driver_list)
+    {
+      MFontDriver *driver = MPLIST_VAL (p);
+      MRealizedFont *rfont;
+
+      if (driver->encapsulate
+         && (rfont = driver->encapsulate (frame, data_type, data)))
+       return (MFont *) rfont;
+    }
+
+  return NULL;
+}
+
+/*=*/
+/***en
+    @brief Close a font.
+
+    The mfont_close () function close a realized font $FONT.  $FONT
+    must be opened previously by mfont_open () or mfont_encapsulate
+    ().
+
+    @return
+    If the operation was successful, 0 is returned.  Otherwise, -1 is
+    returned.
+
+    @seealso
+    mfont_open (), mfont_encapsulate ().  */
+
+int
+mfont_close (MFont *font)
+{
+  enum MFontType font_type = font->type;
+  MRealizedFont *rfont;
+
+  if (font_type != MFONT_TYPE_REALIZED)
+    MERROR (MERROR_FONT, -1);
+  rfont = (MRealizedFont *) font;
+  if (rfont->encapsulating
+      && rfont->driver->close)
+    rfont->driver->close (rfont);
+  return 0;
+}
+
+/*** @} */
+
+/*** @addtogroup m17nDebug */
+/*=*/
+/*** @{ */
+
+/***en
+    @brief Dump a font.
+
+    The mdebug_dump_font () function prints font $FONT in a human readable
+    way to the stderr.
+
+    @return
+    This function returns $FONT.  */
+/***ja
+    @brief ¥Õ¥©¥ó¥È¤ò¥À¥ó¥×¤¹¤ë.
+
+    ´Ø¿ô mdebug_dump_font () ¤Ï¥Õ¥©¥ó¥È $FONT ¤ò stderr 
+    ¤Ë¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç°õºþ¤¹¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï $FONT ¤òÊÖ¤¹¡£  */
+
+MFont *
+mdebug_dump_font (MFont *font)
+{
+  char *name;
+  
+  name = xlfd_unparse_name (font, 0);
+  if (name)
+    {
+      fprintf (stderr, "%s", name);
+      free (name);
+    }
+  if (font->file != Mnil)
+    {
+      char *file = MSYMBOL_NAME (font->file);
+      char *lastslash = file, *p;
+
+      for (p = file; *p; p++)
+       if (*p == '/')
+         lastslash = p;
+      if (name)
+       fprintf (stderr, ",");
+      fprintf (stderr, "%s", lastslash + 1);
+    }
+  if (font->capability != Mnil)
+    fprintf (stderr, "%s", MSYMBOL_NAME (font->capability));
+  return font;
+}
+
+/*** @} */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/font.h b/src/font.h
new file mode 100644 (file)
index 0000000..592fa2a
--- /dev/null
@@ -0,0 +1,375 @@
+/* font.h -- header file for the font module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_FONT_H_
+#define _M17N_FONT_H_
+
+enum MFontProperty
+  {
+    /* The order of MFONT_FOUNDRY to MFONT_ADSTYLE must be the same as
+       enum MFaceProperty.  */
+    MFONT_FOUNDRY,
+    MFONT_FAMILY,
+    MFONT_WEIGHT,
+    MFONT_STYLE,
+    MFONT_STRETCH,
+    MFONT_ADSTYLE,
+    MFONT_REGISTRY,
+    MFONT_RESY,
+    /* The follwoings should not be used as an index to
+       MFont->propperty.  */
+    MFONT_SIZE,
+    MFONT_SPACING,
+    /* anchor */
+    MFONT_PROPERTY_MAX = MFONT_SIZE
+  };
+
+enum MFontType
+  {
+    MFONT_TYPE_SPEC,
+    MFONT_TYPE_OBJECT,
+    MFONT_TYPE_REALIZED,
+    MFONT_TYPE_FAILURE
+  };
+
+enum MFontSource
+  {
+    MFONT_SOURCE_UNDECIDED = 0,
+    MFONT_SOURCE_X = 1,
+    MFONT_SOURCE_FT = 2
+  };
+
+enum MFontSpacing
+  {
+    MFONT_SPACING_UNDECIDED,
+    MFONT_SPACING_PROPORTIONAL,
+    MFONT_SPACING_MONO,
+    MFONT_SPACING_CHARCELL
+  };
+
+typedef struct MFontEncoding MFontEncoding;
+typedef struct MFontDriver MFontDriver;
+
+/** Information about a font.  This structure is used in three ways:
+    FONT-OBJ, FONT-OPENED, and FONT-SPEC.  
+
+    FONT-OBJ: To store information of an existing font.  Instances
+    appear only in <font_list> of MDisplay.
+
+    FONT-OPENED: To store information of an opened font.  Instances
+    appear only in <opend_list> of MDisplay.
+
+    FONT-SPEC: To store specifications of a font.  Instances appear
+    only in <spec_list> of MFontset.  */
+
+struct MFont
+{
+  /** Numeric value of each font property.  Also used as an index to
+      the table @c mfont__property_table to get the actual name of the
+      property.
+
+      For FONT-OBJ, FONT-OPENED: The value is greater than zero.
+
+      For FONT-SPEC: The value is equal to or greater than zero.  Zero
+      means that the correponding property is not specified (i.e. wild
+      card).
+
+      For FONT-OBJ: If the value is 0, the font is scalable or
+      auto-scaled.
+
+      For FONT-OPENED: The actual size of opened font.
+
+      <property>[MFONT_RESY] is the designed resolution of the font in
+      DPI, or zero.  Zero means that the font is scalable.
+
+      For the time being, we mention only Y-resolution (resy) and
+      assume that resx is always equal to resy.  */
+  unsigned short property[MFONT_PROPERTY_MAX];
+  unsigned type : 2;
+  unsigned source : 2;
+  unsigned spacing : 2;
+  unsigned for_full_width : 1;
+  /* For FONT-OBJ, 1 means `size' is a logical or of bit masks for
+     available pixel sizes (Nth bit corresponds to (6 + N) pixels), 0
+     means `size' is an actual pixel size * 10.  For FONT-SPEC and
+     FONT-OPENED, this is always 0, and `size' is an actual pixel
+     size * 10.  */
+  unsigned multiple_sizes : 1;
+  unsigned size : 24;
+  MSymbol file;
+  MSymbol capability;
+  MFontEncoding *encoding;
+};
+
+typedef struct
+{
+  int size, inc, used;
+  MSymbol property;
+  MSymbol *names;
+} MFontPropertyTable;
+
+extern MFontPropertyTable mfont__property_table[MFONT_REGISTRY + 1];
+
+/** Return the symbol of the Nth font property of FONT.  */
+#define FONT_PROPERTY(font, n) \
+  (mfont__property_table[(n)].names[(font)->property[(n)]])
+
+struct MRealizedFont
+{
+  /* Font spec used to find the font.
+     MRealizedFont::spec.property[MFONT_TYPE] is MFONT_TYPE_REALIZED
+     so that this object can be distingushed from MFont.  */
+  MFont spec;
+
+  /* Font identifier. */
+  MSymbol id;
+
+  /* Frame on which the font is realized.  */
+  MFrame *frame;
+
+  /* The found font.  */
+  MFont *font;
+
+  MFontDriver *driver;
+
+  /* Font Layout Table for the font.  This is just a container to
+     carry the infomation.  */
+  MSymbol layouter;
+
+  /* 1 iff the font is opend by encapsulating client-side font data.  */
+  int encapsulating;
+
+  /* Extra information set by MRealizedFont::driver->open.  If
+     non-NULL, it must be a pointer to a managed object.  */
+  void *info;
+
+  int x_ppem, y_ppem;
+
+  int ascent, descent, max_advance, average_width, baseline_offset;
+
+  /* Pointer to the font structure.  */
+  void *fontp;
+
+  MRealizedFont *next;
+};
+
+typedef struct MFLTFontForRealized {
+  MFLTFont font;
+  MRealizedFont *rfont;
+} MFLTFontForRealized;
+
+typedef struct {
+  MFont *font;
+  int score;
+} MFontScore;
+
+/** Structure to hold a list of fonts.  */
+
+typedef struct
+{
+  MFont object;
+  MFontScore *fonts;
+  int nfonts;
+} MFontList;
+
+struct MFontDriver
+{
+  /** Return a font best matching with FONT.  */
+  MFont *(*select) (MFrame *frame, MFont *font, int limited_size);
+
+  /** Open a font specified by RFONT.  */
+  MRealizedFont *(*open) (MFrame *frame, MFont *font, MFont *spec,
+                         MRealizedFont *rfont);
+
+  /** Set metrics of glyphs in GSTRING from FROM to TO.  */
+  void (*find_metric) (MRealizedFont *rfont, MGlyphString *gstring,
+                      int from, int to);
+
+  /** Check if the font has a glyph for CODE.  CODE is a code point of
+      a character in font->encoder->encoding_charset.  Return nonzero
+      iff the font has the glyph.  */
+  int (*has_char) (MFrame *frame, MFont *font, MFont *spec,
+                  int c, unsigned code);
+
+  /** Encode CODE into a glyph code the font.  CODE is a code point of
+      a character in rfont->encoder->encoding_charset.  If the font
+      has no glyph for CODE, return MCHAR_INVALID_CODE.  */
+  unsigned (*encode_char) (MFrame *frame, MFont *font, MFont *spec,
+                          unsigned code);
+
+  /** Draw glyphs from FROM to TO (exclusive) on window WIN of FRAME
+      at coordinate (X, Y) relative to WIN.  */
+  void (*render) (MDrawWindow win, int x, int y,
+                 MGlyphString *gstring, MGlyph *from, MGlyph *to,
+                 int reverse, MDrawRegion region);
+
+  /** Push to PLIST fonts matching with FONT.  MAXNUM if greater than
+      0 limits the number of listed fonts.  Return the number of fonts
+      listed.  */
+  int (*list) (MFrame *frame, MPlist *plist, MFont *font, int maxnum);
+
+  /** Push to PLIST font family names (symbol) available on FRAME.  */
+  void (*list_family_names) (MFrame *frame, MPlist *plist);
+
+  /** Check if RFONT support CAPABILITY.  */
+  int (*check_capability) (MRealizedFont *rfont, MSymbol capability);
+
+  /** Open a font by encapsulating DATA.  */
+  MRealizedFont *(*encapsulate) (MFrame *frame, MSymbol source, void *data);
+
+  void (*close) (MRealizedFont *rfont);
+
+  int (*check_otf) (MFLTFont *font, MFLTOtfSpec *spec);
+
+  int (*drive_otf) (MFLTFont *font, MFLTOtfSpec *spec,
+                   MFLTGlyphString *in, int from, int to,
+                   MFLTGlyphString *out, MFLTGlyphAdjustment *adjustment);
+
+  int (*try_otf) (MFLTFont *font, MFLTOtfSpec *spec,
+                 MFLTGlyphString *in, int from, int to);
+
+  int (*iterate_otf_feature) (struct _MFLTFont *font, MFLTOtfSpec *spec,
+                             int from, int to, unsigned char *table);
+};
+
+/** Initialize the members of FONT.  */
+
+#define MFONT_INIT(font) memset ((font), 0, sizeof (MFont))
+
+extern MSymbol Mlayouter;
+extern MSymbol Miso8859_1, Miso10646_1, Municode_bmp, Municode_full;
+extern MSymbol Mapple_roman;
+
+extern int mfont__flt_init ();
+
+extern void mfont__flt_fini ();
+
+#ifdef HAVE_FREETYPE
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#endif
+
+#ifdef HAVE_FONTCONFIG
+#include <fontconfig/fontconfig.h>
+#endif
+
+#ifdef HAVE_OTF
+#include <otf.h>
+#else  /* not HAVE_OTF */
+typedef unsigned OTF_Tag;
+#endif /* not HAVE_OTF */
+
+enum MFontOpenTypeTable
+  {
+    MFONT_OTT_GSUB,
+    MFONT_OTT_GPOS,
+    MFONT_OTT_MAX
+  };
+
+typedef struct
+{
+  M17NObject control;
+  MSymbol language;
+  MSymbol script;
+  MSymbol otf;
+  OTF_Tag script_tag;
+  OTF_Tag langsys_tag;
+  struct {
+    char *str;
+    int nfeatures;
+    OTF_Tag *tags;
+  } features[MFONT_OTT_MAX];
+} MFontCapability;
+
+#ifdef HAVE_FREETYPE
+extern MFontDriver mfont__ft_driver;
+
+extern int mfont__ft_init ();
+
+extern void mfont__ft_fini ();
+
+extern int mfont__ft_parse_name (const char *name, MFont *font);
+
+extern char *mfont__ft_unparse_name (MFont *font);
+
+#ifdef HAVE_OTF
+
+extern int mfont__ft_drive_otf (MGlyphString *gstring, int from, int to,
+                               MFontCapability *capability);
+
+extern int mfont__ft_decode_otf (MGlyph *g);
+
+#endif /* HAVE_OTF */
+
+#endif /* HAVE_FREETYPE */
+
+extern void mfont__free_realized (MRealizedFont *rfont);
+
+extern int mfont__match_p (MFont *font, MFont *spec, int prop);
+
+extern int mfont__merge (MFont *dst, MFont *src, int error_on_conflict);
+
+extern void mfont__set_spec_from_face (MFont *spec, MFace *face);
+
+extern MSymbol mfont__set_spec_from_plist (MFont *spec, MPlist *plist);
+
+extern int mfont__has_char (MFrame *frame, MFont *font, MFont *spec, int c);
+
+extern unsigned mfont__encode_char (MFrame *frame, MFont *font, MFont *spec,
+                                   int c);
+
+extern int mfont__get_glyph_id (MFLTFont *font, MFLTGlyphString *gstring,
+                               int from, int to);
+
+extern MFont *mfont__select (MFrame *frame, MFont *font, int max_size);
+
+extern MFontList *mfont__list (MFrame *frame, MFont *spec, MFont *request,
+                              int limited_size);
+
+extern MRealizedFont *mfont__open (MFrame *frame, MFont *font, MFont *spec);
+
+extern void mfont__get_metric (MGlyphString *gstring, int from, int to);
+
+extern int mfont__get_metrics (MFLTFont *font, MFLTGlyphString *gstring,
+                              int from, int to);
+
+extern void mfont__set_property (MFont *font, enum MFontProperty key,
+                                MSymbol val);
+
+extern int mfont__split_name (char *name, int *property_idx,
+                             unsigned short *point, unsigned short *resy);
+
+extern int mfont__parse_name_into_font (const char *name, MSymbol format,
+                                       MFont *font);
+
+extern MPlist *mfont__encoding_list (void);
+
+extern MFontCapability *mfont__get_capability (MSymbol sym);
+
+extern int mfont__check_capability (MRealizedFont *rfont, MSymbol capability);
+
+extern unsigned mfont__flt_encode_char (MSymbol layouter_name, int c);
+
+extern int mfont__flt_run (MGlyphString *gstring, int from, int to,
+                          MRealizedFace *rface);
+
+#endif /* _M17N_FONT_H_ */
diff --git a/src/fontset.c b/src/fontset.c
new file mode 100644 (file)
index 0000000..6a8bca1
--- /dev/null
@@ -0,0 +1,1526 @@
+/* fontset.c -- fontset module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nFontset
+    @brief A fontset is an object that maps a character to fonts.
+
+    A @e fontset is an object of the type @c MFontset.  When drawing an
+    M-text, a fontset provides rules to select a font for each
+    character in the M-text according to the following information.
+
+    @li The script character property of a character.
+    @li The language text property of a character.
+    @li The charset text property of a character.
+
+    The documentation of mdraw_text () describes how that information is
+    used.  */
+
+/***ja @addtogroup m17nFontset 
+
+    @brief ¥Õ¥©¥ó¥È¥»¥Ã¥È¤Ïʸ»ú¤«¤é¥Õ¥©¥ó¥È¤Ø¤ÎÂбþÉÕ¤±¤ò¹Ô¤¦¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë.
+
+    @e ¥Õ¥©¥ó¥È¥»¥Ã¥È ¤Ï @c MFontset ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë¡£M-text 
+    ¤Îɽ¼¨¤ÎºÝ¡¢¥Õ¥©¥ó¥È¥»¥Ã¥È¤Ï°Ê²¼¤Î¾ðÊó¤òÍѤ¤¤Æ M-text 
+    Ãæ¤Î¸Ä¡¹¤Îʸ»ú¤Ë¤É¤Î¥Õ¥©¥ó¥È¤òÍѤ¤¤ë¤«·è¤á¤ëµ¬Â§¤òÍ¿¤¨¤ë¡£
+
+    @li Ê¸»ú¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£ "¥¹¥¯¥ê¥×¥È"
+    @li Ê¸»ú¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ "¸À¸ì"
+    @li Ê¸»ú¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ "ʸ»ú¥»¥Ã¥È"
+
+    ¤³¤ì¤é¤Î¾ðÊ󤬤ɤΤ褦¤ËÍѤ¤¤é¤ì¤ë¤«¤Ï mdraw_text () ¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£
+
+    */
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "config.h"
+#include "m17n-gui.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "symbol.h"
+#include "plist.h"
+#include "character.h"
+#include "charset.h"
+#include "internal-gui.h"
+#include "font.h"
+#include "fontset.h"
+
+static int mdebug_flag = MDEBUG_FONTSET;
+
+static M17NObjectArray fontset_table;
+
+struct MFontset
+{
+  M17NObject control;
+
+  /* Name of the fontset.  */
+  MSymbol name;
+
+  /* Initialized to 0, and incremented by one each time the fontset is
+     modified.  */
+  unsigned tick;
+
+  /* Database from which to load the contents of the fontset.  Once
+     loaded, this member is set to NULL.  */
+  MDatabase *mdb;
+
+  /* SCRIPT vs PER-LANGUAGE (which is a plist LANGUAGE vs FONT-GROUP) */
+  MPlist *per_script;
+
+  /* CHARSET vs FONT-GROUP */
+  MPlist *per_charset;
+
+  /* FONT-GROUP */
+  MPlist *fallback;
+};
+
+static MFontset *default_fontset;
+
+static MPlist *fontset_list;
+
+struct MRealizedFontset
+{
+  /* Fontset from which the realized fontset is realized.  */
+  MFontset *fontset;
+
+  /* Initialized to <fontset>->tick.  */
+  unsigned tick;
+
+  /* Font spec that must be satisfied, or NULL.  */
+  MFont *spec;
+
+  /* Font spec requested by a face.  */
+  MFont request;
+
+  /* The frame on which the realized fontset is realized.  */
+  MFrame *frame;
+
+  MPlist *per_script;
+
+  MPlist *per_charset;
+
+  MPlist *fallback;
+};
+
+
+static MPlist *
+load_font_group (MPlist *plist, MPlist *elt)
+{
+  MPLIST_DO (elt, elt)
+    {
+      /* ELT ::= ( FONT-SPEC [ LAYOUTER ] ) ...  */
+      MPlist *elt2;
+      MFont *font;
+      MSymbol layouter_name;
+
+      if (! MPLIST_PLIST_P (elt))
+       MWARNING (MERROR_FONTSET);
+      elt2 = MPLIST_PLIST (elt);
+      if (! MPLIST_PLIST_P (elt2))
+       MWARNING (MERROR_FONTSET);
+      MSTRUCT_CALLOC (font, MERROR_FONTSET);
+      mfont__set_spec_from_plist (font, MPLIST_PLIST (elt2));
+      elt2 = MPLIST_NEXT (elt2);
+      layouter_name = Mt;
+      if (MPLIST_SYMBOL_P (elt2))
+       layouter_name = MPLIST_SYMBOL (elt2);
+      if (layouter_name == Mnil)
+       layouter_name = Mt;
+      plist = mplist_add (plist, layouter_name, font);
+      continue;
+    warning:
+      /* ANSI-C requires some statement after a label.  */
+      continue;
+    }
+  return plist;
+}
+
+/* Load FONTSET->per_script from the data in FONTSET->mdb.  */
+
+static void
+load_fontset_contents (MFontset *fontset)
+{
+  MPlist *per_script, *per_charset, *font_group;
+  MPlist *fontset_def, *plist;
+
+  fontset->per_script = per_script = mplist ();
+  fontset->per_charset = per_charset = mplist ();
+  fontset->fallback = mplist ();
+  if (! (fontset_def = (MPlist *) mdatabase_load (fontset->mdb)))
+    return;
+
+  MPLIST_DO (plist, fontset_def)
+    {
+      /* PLIST ::=   ( SCRIPT ( LANGUAGE ( FONT-SPEC [LAYOUTER]) ... ) ... )
+                  | ( CHARSET ( FONT-SPEC [LAYOUTER] ) ...)
+                  | ( nil ( FONT-SPEC [LAYOUTER] ) ...)
+        FONT-SPEC :: = ( ... ) */
+      MPlist *elt;
+      MSymbol sym;
+
+      if (! MPLIST_PLIST_P (plist))
+       MWARNING (MERROR_FONTSET);
+      elt = MPLIST_PLIST (plist);
+      if (! MPLIST_SYMBOL_P (elt))
+       MWARNING (MERROR_FONTSET);
+      sym = MPLIST_SYMBOL (elt);
+      elt = MPLIST_NEXT (elt);
+      if (! MPLIST_PLIST_P (elt))
+       MWARNING (MERROR_FONTSET);
+      if (sym == Mnil)
+       load_font_group (fontset->fallback, elt);
+      else if (MPLIST_PLIST_P (MPLIST_PLIST (elt)))
+       {
+         /* SYM is a charset.  */
+         font_group = mplist ();
+         per_charset = mplist_add (per_charset, sym, font_group);
+         load_font_group (font_group, elt);
+       }
+      else
+       {
+         /* SYM is a script */
+         MPlist *per_lang = mplist ();
+
+         per_script = mplist_add (per_script, sym, per_lang);
+         MPLIST_DO (elt, elt)
+           {
+             /* ELT ::= ( LANGUAGE FONT-DEF ...) ... */
+             MPlist *elt2;
+             MSymbol lang;
+
+             if (! MPLIST_PLIST_P (elt))
+               MWARNING (MERROR_FONTSET);
+             elt2 = MPLIST_PLIST (elt);
+             if (! MPLIST_SYMBOL_P (elt2))
+               MWARNING (MERROR_FONTSET);
+             lang = MPLIST_SYMBOL (elt2);
+             if (lang == Mnil)
+               lang = Mt;
+             font_group = mplist ();
+             mplist_add (per_lang, lang, font_group);
+             elt2 = MPLIST_NEXT (elt2);
+             load_font_group (font_group, elt2);
+           }
+       }
+      continue;
+
+    warning:
+      /* ANSI-C requires some statement after a label.  */
+      continue;
+    }
+
+  M17N_OBJECT_UNREF (fontset_def);
+  fontset->mdb = NULL;
+}
+
+static void
+free_fontset (void *object)
+{
+  MFontset *fontset = (MFontset *) object;
+  MPlist *plist, *pl, *p;
+
+  if (fontset->per_script)
+    {
+      MPLIST_DO (plist, fontset->per_script)
+       {
+         MPLIST_DO (pl, MPLIST_PLIST (plist))
+           {
+             MPLIST_DO (p, MPLIST_PLIST (pl))
+               free (MPLIST_VAL (p));
+             p = MPLIST_PLIST (pl);
+             M17N_OBJECT_UNREF (p);
+           }
+         pl = MPLIST_PLIST (plist);
+         M17N_OBJECT_UNREF (pl);
+       }
+      M17N_OBJECT_UNREF (fontset->per_script);
+    }
+  if (fontset->per_charset)
+    {
+      MPLIST_DO (pl, fontset->per_charset)
+       {
+         MPLIST_DO (p, MPLIST_PLIST (pl))
+           free (MPLIST_VAL (p));
+         p = MPLIST_PLIST (p);
+         M17N_OBJECT_UNREF (p);
+       }
+      M17N_OBJECT_UNREF (fontset->per_charset);
+    }
+  if (fontset->fallback)
+    {
+      MPLIST_DO (p, fontset->fallback)
+       free (MPLIST_VAL (p));
+      M17N_OBJECT_UNREF (fontset->fallback);
+    }
+
+  plist = mplist_find_by_key (fontset_list, fontset->name);
+  if (! plist)
+    mdebug_hook ();
+  mplist_pop (plist);
+  if (MPLIST_TAIL_P (fontset_list))
+    {
+      M17N_OBJECT_UNREF (fontset_list);
+      fontset_list = NULL;
+    }
+  M17N_OBJECT_UNREGISTER (fontset_table, fontset);
+  free (object);
+}
+
+static void
+realize_fontset_elements (MFrame *frame, MRealizedFontset *realized)
+{
+  MFontset *fontset = realized->fontset;
+  MPlist *per_script, *per_charset, *font_group;
+  MPlist *plist, *pl, *p;
+
+  realized->per_script = per_script = mplist ();
+  /* The actual elements of per_script are realized on demand.  */
+#if 0
+  MPLIST_DO (plist, fontset->per_script)
+    {
+      per_lang = mplist ();
+      per_script = mplist_add (per_script, MPLIST_KEY (plist), per_lang);
+      MPLIST_DO (pl, MPLIST_PLIST (plist))
+       {
+         font_group = mplist ();
+         per_lang = mplist_add (per_lang, MPLIST_KEY (pl), font_group);
+         MPLIST_DO (p, MPLIST_PLIST (pl))
+           font_group = mplist_add (font_group,
+                                    MPLIST_KEY (p), MPLIST_VAL (p));
+       }
+    }
+#endif
+
+  realized->per_charset = per_charset = mplist ();
+  MPLIST_DO (pl, fontset->per_charset)
+    {
+      font_group = mplist ();
+      per_charset = mplist_add (per_charset, MPLIST_KEY (plist), font_group);
+      MPLIST_DO (p, MPLIST_PLIST (pl))
+       font_group = mplist_add (font_group, MPLIST_KEY (p), MPLIST_VAL (p));
+    }
+  realized->fallback = font_group = mplist ();
+  MPLIST_DO (p, fontset->fallback)
+    font_group = mplist_add (font_group, MPLIST_KEY (p), MPLIST_VAL (p));
+}
+
+
+/* Return a plist of fonts for SCRIPT in FONTSET.  The returned list
+   is acutally a plist of languages vs font groups (which is a plist).
+   If SCRIPT is nil, return a plist of fallback fonts.  If FONTSET
+   doesn't record any fonts for SCRIPT, generate a proper font spec
+   lists for X backend and FreeType backend.  */
+
+MPlist *
+get_per_script (MFontset *fontset, MSymbol script)
+{
+  MPlist *plist;
+
+  if (script == Mnil)
+    return fontset->fallback;
+  plist = mplist_get (fontset->per_script, script);
+  if (! plist)
+    {
+      int len = MSYMBOL_NAMELEN (script);
+      char *cap = alloca (8 + len + 1);
+      MSymbol capability;
+      MFont *font;
+      MPlist *pl, *p;
+
+      sprintf (cap, ":script=%s", MSYMBOL_NAME (script));
+      capability = msymbol (cap);
+
+      pl = mplist ();
+      MPLIST_DO (p, fontset->fallback)
+       {
+         font = mfont_copy (MPLIST_VAL (p));
+         mfont_put_prop (font, Mregistry, Municode_bmp);
+         font->source = MFONT_SOURCE_FT;
+         font->capability = capability;
+         mplist_add (pl, Mt, font);
+
+         font = mfont_copy (MPLIST_VAL (p));
+         mfont_put_prop (font, Mregistry, Miso10646_1);
+         font->source = MFONT_SOURCE_X;
+         font->capability = capability;
+         mplist_add (pl, Mt, font);
+       }
+      plist = mplist ();
+      mplist_add (plist, Mt, pl);
+      mplist_add (fontset->per_script, script, plist);
+    }
+  return plist;
+}
+
+static void
+free_realized_fontset_elements (MRealizedFontset *realized)
+{
+  MPlist *plist, *pl, *p;
+  MFont *font;
+  MFontList *font_list;
+
+  if (realized->per_script)
+    {
+      MPLIST_DO (plist, realized->per_script)
+       {
+         MPLIST_DO (pl, MPLIST_PLIST (plist))
+           {
+             MPLIST_DO (p, MPLIST_PLIST (pl))
+               {
+                 font = MPLIST_VAL (p);
+                 if (font->type == MFONT_TYPE_OBJECT)
+                   {
+                     font_list = (MFontList *) font;
+                     free (font_list->fonts);
+                     free (font_list);
+                   }
+                 /* This is to avoid freeing rfont again by the later
+                    M17N_OBJECT_UNREF (p) */
+                 MPLIST_KEY (p) = Mt;
+               }
+             p = MPLIST_PLIST (pl);
+             M17N_OBJECT_UNREF (p);
+           }
+         pl = MPLIST_PLIST (plist);
+         M17N_OBJECT_UNREF (pl);
+       }
+      M17N_OBJECT_UNREF (realized->per_script);
+    }
+  if (realized->per_charset)
+    {
+      MPLIST_DO (plist, realized->per_charset)
+       {
+         MPLIST_DO (pl, MPLIST_PLIST (plist))
+           {
+             font = MPLIST_VAL (pl);
+             if (font->type == MFONT_TYPE_OBJECT)
+               {
+                 font_list = (MFontList *) font;
+                 free (font_list->fonts);
+                 free (font_list);
+               }
+             MPLIST_KEY (pl) = Mt;
+           }
+         pl = MPLIST_PLIST (plist);
+         M17N_OBJECT_UNREF (pl);
+       }
+      M17N_OBJECT_UNREF (realized->per_charset);
+    }
+  if (realized->fallback)
+    {
+      MPLIST_DO (plist, realized->fallback)
+       {
+         font = MPLIST_VAL (plist);
+         if (font->type == MFONT_TYPE_OBJECT)
+           {
+             font_list = (MFontList *) font;
+             free (font_list->fonts);
+             free (font_list);
+           }
+         MPLIST_KEY (plist) = Mt;
+       }
+      M17N_OBJECT_UNREF (realized->fallback);
+    }
+}
+
+static void
+update_fontset_elements (MRealizedFontset *realized)
+{
+  free_realized_fontset_elements (realized);
+  realize_fontset_elements (realized->frame, realized);
+}
+
+
+\f
+
+/* Internal API */
+
+int
+mfont__fontset_init ()
+{
+  M17N_OBJECT_ADD_ARRAY (fontset_table, "Fontset");
+
+  Mfontset = msymbol ("fontset");
+  Mfontset->managing_key = 1;
+  fontset_list = mplist ();
+  default_fontset = mfontset ("default");
+  if (! default_fontset->mdb)
+    {
+      MFont font;
+
+      MFONT_INIT (&font);
+      mfont_put_prop (&font, Mregistry, msymbol ("iso8859-1"));
+      mfontset_modify_entry (default_fontset, Mnil, Mnil, Mnil,
+                            &font, Mnil, 1);
+      mfont_put_prop (&font, Mregistry, msymbol ("iso10646-1"));
+      mfontset_modify_entry (default_fontset, Mnil, Mnil, Mnil,
+                            &font, Mnil, 1);
+    }
+  return 0;
+}
+
+
+void
+mfont__fontset_fini ()
+{
+  M17N_OBJECT_UNREF (default_fontset);
+  default_fontset = NULL;
+}
+
+
+MRealizedFontset *
+mfont__realize_fontset (MFrame *frame, MFontset *fontset,
+                       MFace *face, MFont *spec)
+{
+  MRealizedFontset *realized;
+  MFont request;
+  MPlist *plist;
+
+  if (fontset->mdb)
+    load_fontset_contents (fontset);
+
+  MFONT_INIT (&request);
+  mfont__set_spec_from_face (&request, face);
+  if (request.size <= 0)
+    {
+      mdebug_hook ();
+      request.size = 120;
+    }
+  MPLIST_DO (plist, frame->realized_fontset_list)
+    {
+      realized = (MRealizedFontset *) MPLIST_VAL (plist);
+      if (fontset->name == MPLIST_KEY (plist)
+         && ! memcmp (&request, &realized->request, sizeof (MFont))
+         && (realized->spec
+             ? (spec && ! memcmp (spec, &realized->spec, sizeof (MFont)))
+             : ! spec))
+       return realized;
+    }
+
+  MSTRUCT_CALLOC (realized, MERROR_FONTSET);
+  realized->fontset = fontset;
+  M17N_OBJECT_REF (fontset);
+  realized->tick = fontset->tick;
+  if (spec)
+    {
+      MSTRUCT_CALLOC (realized->spec, MERROR_FONTSET);
+      *realized->spec = *spec;
+    }
+  realized->request = request;
+  realized->frame = frame;
+  realize_fontset_elements (frame, realized);
+  mplist_add (frame->realized_fontset_list, fontset->name, realized);
+  return realized;
+}
+
+
+void
+mfont__free_realized_fontset (MRealizedFontset *realized)
+{
+  free_realized_fontset_elements (realized);
+  M17N_OBJECT_UNREF (realized->fontset);
+  if (realized->spec)
+    free (realized->spec);
+  free (realized);
+}
+
+
+static MRealizedFont *
+try_font_list (MFrame *frame, MFontList *font_list, MFont *request,
+              MSymbol layouter, MGlyph *g, int *num, int all, int exact)
+{
+  int i, j;
+  MFont *font;
+  MRealizedFont *rfont;
+
+  for (i = 0; i < font_list->nfonts; i++)
+    {
+      if (font_list->fonts[i].font->type == MFONT_TYPE_SPEC)
+       MFATAL (MERROR_FONT);
+      if (exact)
+       {
+         if (font_list->fonts[i].score > 0)
+           break;
+       }
+      else
+       {
+         if (font_list->fonts[i].score == 0)
+           continue;
+       }
+      font = font_list->fonts[i].font;
+      if (font->type == MFONT_TYPE_FAILURE)
+       continue;
+      /* Check if this font can display all glyphs.  */
+      for (j = 0; j < *num; j++)
+       {
+         int c = g[j].type == GLYPH_CHAR ? g[j].g.c : ' ';
+         MFLT *flt;
+         MCharTable *coverage;
+
+         if (layouter != Mt
+             ? ((flt = mflt_get (layouter))
+                ? (coverage = mflt_coverage (flt),
+                   ! mchartable_lookup (coverage, c))
+                : 0)
+             : ! mfont__has_char (frame, font, &font_list->object, c))
+           break;
+       }
+      if (j == 0 && *num > 0)
+       continue;
+      if (j == *num || !all)
+       {
+         MCharTable *coverage = NULL;
+
+         /* We found a font that can display the requested range of
+            glyphs.  */
+         if (font->type == MFONT_TYPE_REALIZED)
+           rfont = (MRealizedFont *) font;
+         else
+           {
+             rfont = mfont__open (frame, font, &font_list->object);
+             if (! rfont)
+               continue;
+             font_list->fonts[i].font = (MFont *) rfont;
+           }
+         rfont->layouter = layouter == Mt ? Mnil : layouter;
+         if (rfont->layouter)
+           {
+             MFLT *flt = mflt_get (rfont->layouter);
+
+             if (flt)
+               coverage = mflt_coverage (flt);
+           }
+         *num = j;
+         for (j = 0; j < *num; j++)
+           {
+             int c = g[j].type == GLYPH_CHAR ? g[j].g.c : ' ';
+
+             g[j].g.code = (coverage
+                            ? (unsigned ) mchartable_lookup (coverage, c)
+                            : mfont__encode_char (frame, (MFont *) rfont,
+                                                  &font_list->object, c));
+           }
+         return rfont;
+       }
+    }
+  return NULL;
+}
+
+
+static MRealizedFont *
+try_font_group (MRealizedFontset *realized, MFont *request,
+               MPlist *font_group, MGlyph *g, int *num, int size)
+{
+  MFrame *frame = realized->frame;
+  MFont *font;
+  MFontList *font_list;
+  MRealizedFont *rfont;
+  MPlist *plist;
+  MSymbol layouter;
+  int best_score = -1, worst_score;
+
+  for (plist = font_group; ! MPLIST_TAIL_P (plist); )
+    {
+      int this_score;
+
+      layouter = MPLIST_KEY (plist);
+      font = MPLIST_VAL (plist);
+      if (font->type == MFONT_TYPE_SPEC)
+       {
+         /* We have not yet made this entry a MFontList.  */
+         if (realized->spec)
+           {
+             MFont this = *font;
+             
+             if (mfont__merge (&this, realized->spec, 1) < 0)
+               {
+                 mplist_pop (plist);
+                 continue;
+               }
+             font_list = mfont__list (frame, &this, &this, size);
+           }
+         else
+           font_list = mfont__list (frame, font, request, size);
+         if (! font_list)
+           {
+             /* As there's no font matching this spec, remove this
+                element from the font group.  */
+             mplist_pop (plist);
+             continue;
+           }
+         MPLIST_VAL (plist) = font_list;
+       }
+      else
+       font_list = (MFontList *) font;
+
+      this_score = font_list->fonts[0].score;
+      if ((this_score == 0)
+         && (rfont = try_font_list (frame, font_list, request,
+                                    layouter, g, num, 1, 1)))
+       return rfont;
+      if (best_score < 0)
+       {
+         best_score = worst_score = this_score;
+         plist = MPLIST_NEXT (plist);
+       }
+      else if (this_score >= worst_score)
+       {
+         worst_score = this_score;
+         plist = MPLIST_NEXT (plist);
+       }
+      else
+       {
+         MPlist *pl;
+
+         MPLIST_DO (pl, font_group)
+           if (this_score < ((MFontList *) MPLIST_VAL (pl))->fonts[0].score)
+             break;
+         mplist_pop (plist);
+         mplist_push (pl, layouter, font_list);
+       }
+    }
+
+  /* We couldn't find an exact matching font that can display all
+     glyphs.  Find one that can at least display all glyphs.  */
+  MPLIST_DO (plist, font_group)
+    {
+      rfont = try_font_list (frame, MPLIST_VAL (plist), request,
+                            MPLIST_KEY (plist), g, num, 1, 0);
+      if (rfont)
+       return rfont;
+    }
+
+  /* We couldn't find a font that can display all glyphs.  Find an
+     exact matching font that can at least display the first
+     glyph.  */
+  MPLIST_DO (plist, font_group)
+    {
+      rfont = try_font_list (frame, MPLIST_VAL (plist), request,
+                            MPLIST_KEY (plist), g, num, 0, 1);
+      if (rfont)
+       return rfont;
+    }
+
+  /* Find any font that can at least display the first glyph.  */
+  MPLIST_DO (plist, font_group)
+    {
+      rfont = try_font_list (frame, MPLIST_VAL (plist), request,
+                            MPLIST_KEY (plist), g, num, 0, 0);
+      if (rfont)
+       return rfont;
+    }
+
+  return NULL;
+}
+
+MRealizedFont *
+mfont__lookup_fontset (MRealizedFontset *realized, MGlyph *g, int *num,
+                      MSymbol script, MSymbol language, MSymbol charset,
+                      int size, int ignore_fallback)
+{
+  MCharset *preferred_charset = (charset == Mnil ? NULL : MCHARSET (charset));
+  MPlist *per_charset, *per_script, *per_lang;
+  MPlist *plist;
+  MRealizedFont *rfont = NULL;
+
+  if (MDEBUG_FLAG ())
+    {
+      int i;
+
+      MDEBUG_PRINT1 (" [FONTSET] fontset looking up for %s:",
+                    script ? script->name : "none");
+      for (i = 0; i < *num; i++)
+       MDEBUG_PRINT1 (" U+%04X", g[i].g.c);
+      MDEBUG_PRINT ("\n");
+    }
+
+  if (realized->tick != realized->fontset->tick)
+    update_fontset_elements (realized);
+
+  if (preferred_charset
+      && (per_charset = mplist_get (realized->per_charset, charset)) != NULL
+      && (rfont = try_font_group (realized, &realized->request, per_charset,
+                                 g, num, size)))
+    goto done;
+
+  if (script != Mnil)
+    {
+      MFont request = realized->request;
+
+      if (script != Mlatin)
+       /* This is not appropriate for non-Latin scripts.  */
+       request.property[MFONT_REGISTRY] = 0;
+
+      per_script = mplist_get (realized->per_script, script);
+      if (! per_script)
+       {
+         per_script = mplist_copy (get_per_script (realized->fontset, script));
+         /* PER_SCRIPT ::= (LANGUAGE:(LAYOUTER:FONT-SPEC ...) ...) */
+         MPLIST_DO (plist, per_script)
+           MPLIST_VAL (plist) = mplist_copy (MPLIST_VAL (plist));
+         mplist_add (realized->per_script, script, per_script);
+       }
+
+      /* We prefer font groups in this order:
+         (1) group matching with LANGUAGE if LANGUAGE is not Mnil
+         (2) group for generic language
+         (3) group not matching with LANGUAGE  */
+      if (language == Mnil)
+       language = Mt;
+      if ((per_lang = mplist_get (per_script, language))
+         && (rfont = try_font_group (realized, &request, per_lang,
+                                     g, num, size)))
+       goto done;
+
+      if (per_lang && *num > 1)
+       *num = 1;
+      if (language == Mt)
+       {
+         /* Try the above (3) */
+         MPLIST_DO (plist, per_script)
+           if (MPLIST_KEY (plist) != language
+               && (rfont = try_font_group (realized, &request,
+                                           MPLIST_PLIST (plist),
+                                           g, num, size)))
+             goto done;
+       }
+      else
+       {
+         /* At first try the above (2) */
+         if ((per_lang = mplist_get (per_script, Mt))
+             && (rfont = try_font_group (realized, &request, per_lang,
+                                         g, num, size)))
+           goto done;
+
+         if (per_lang && *num > 1)
+           *num = 1;
+         /* Then try the above (3) */
+         MPLIST_DO (plist, per_script)
+           if (MPLIST_KEY (plist) != language
+               && MPLIST_KEY (plist) != Mt
+               && (rfont = try_font_group (realized, &request,
+                                           MPLIST_PLIST (plist),
+                                           g, num, size)))
+             goto done;
+       }
+      if (ignore_fallback)
+       goto done;
+    }
+
+  if (language != Mnil)
+    /* Find a font group for this language from all scripts.  */
+    MPLIST_DO (plist, realized->per_script)
+      {
+       MFont request = realized->request;
+
+       if (MPLIST_KEY (plist) != Mlatin)
+         request.property[MFONT_FOUNDRY]
+           = request.property[MFONT_FAMILY]
+           = request.property[MFONT_FAMILY] = 0;
+       if ((per_lang = mplist_get (MPLIST_PLIST (plist), language))
+           && (rfont = try_font_group (realized, &request, per_lang,
+                                       g, num, size)))
+         goto done;
+      }
+
+  /* Try fallback fonts.  */
+  rfont = try_font_group (realized, &realized->request,
+                         realized->fallback, g, num, size);
+ done:
+  if (MDEBUG_FLAG ())
+    {
+      if (rfont)
+       {
+         MSymbol family = mfont_get_prop (rfont->font, Mfamily);
+         MDEBUG_PRINT1 (" [FONTSET] found %s\n", family->name);
+       }
+      else
+       MDEBUG_PRINT (" [FONTSET] not found\n");
+    }
+
+  return rfont;
+}
+
+MRealizedFont *
+get_font_from_group (MFrame *frame, MPlist *plist, MFont *font)
+{
+  MRealizedFont *rfont;
+
+  MPLIST_DO (plist, plist)
+    {
+      MFont spec = *(MFont *) MPLIST_VAL (plist);
+      if (mfont__merge (&spec, font, 1) < 0)
+       continue;
+      if (font->type == MFONT_TYPE_SPEC)
+       rfont = (MRealizedFont *) mfont_find (frame, &spec, NULL, 0);
+      else if (font->type == MFONT_TYPE_OBJECT)
+       rfont = mfont__open (frame, font, &spec);
+      else
+       rfont = (MRealizedFont *) font;
+      if (rfont
+         && (spec.capability == Mnil
+             || mfont__check_capability (rfont, spec.capability) == 0))
+       {
+         rfont->layouter
+           = MPLIST_KEY (plist) == Mt ? Mnil : MPLIST_KEY (plist);
+         return rfont;
+       }
+    }
+  return NULL;
+}
+
+MRealizedFont *
+mfontset__get_font (MFrame *frame, MFontset *fontset,
+                   MSymbol script, MSymbol language, MFont *font,
+                   int *best)
+{
+  MPlist *per_script, *per_lang;
+  MRealizedFont *rfont;
+
+  if (best)
+    *best = 0;
+
+  if (language == Mnil)
+    language = Mt;
+
+  if (script != Mnil)
+    {
+      per_script = get_per_script (fontset, script);
+      if ((per_lang = mplist_get (per_script, language))
+         && (rfont = get_font_from_group (frame, per_lang, font)))
+       {
+         if (best)
+           *best = 1;
+         return rfont;
+       }
+      if (best)
+       *best = per_lang ? 0 : 1;
+      if (language == Mt)
+       {
+         MPLIST_DO (per_script, per_script)
+           if (MPLIST_KEY (per_script) != language
+               && (rfont = get_font_from_group (frame,
+                                                MPLIST_PLIST (per_script),
+                                                font)))
+             return rfont;
+       }
+      else
+       {
+         if ((per_lang = mplist_get (per_script, Mt))
+             && (rfont = get_font_from_group (frame, per_lang, font)))
+           return rfont;
+         if (best)
+           *best = 0;
+         MPLIST_DO (per_script, per_script)
+           if (MPLIST_KEY (per_script) != language
+               && MPLIST_KEY (per_script) != Mt
+               && (rfont = get_font_from_group (frame,
+                                                MPLIST_PLIST (per_script),
+                                                font)))
+             return rfont;
+       }
+    }
+
+  if (language != Mt)
+    MPLIST_DO (per_script, fontset->per_script)
+      {
+       if ((per_lang = mplist_get (MPLIST_PLIST (per_script), language))
+           && (rfont = get_font_from_group (frame, per_lang, font)))
+         {
+           if (best)
+             *best = 1;
+           return rfont;
+         }
+      }
+
+  if (best)
+    *best = 0;
+  if ((rfont = get_font_from_group (frame, fontset->fallback, font)))
+    return rfont;
+  return NULL;
+}
+
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+/* External API */
+
+/*** @addtogroup m17nFontset */
+/*** @{ */
+
+/*=*/
+/***en
+    @brief Return a fontset.
+
+    The mfontset () function returns a pointer to a fontset object of
+    name $NAME.  If $NAME is @c NULL, it returns a pointer to the
+    default fontset.
+
+    If no fontset has the name $NAME, a new one is created.  At that
+    time, if there exists a data \<@c fontset, $NAME\> in the m17n
+    database, the fontset contents are initialized according to the
+    data.  If no such data exists, the fontset contents are left
+    vacant.
+
+    The macro M17N_INIT () creates the default fontset.  An
+    application program can modify it before the first call of 
+    mframe ().
+
+    @return
+    This function returns a pointer to the found or newly created
+    fontset.  */
+/***ja 
+    @brief ¥Õ¥©¥ó¥È¥»¥Ã¥È¤òÊÖ¤¹.
+
+    ´Ø¿ô mfontset () ¤Ï̾Á° $NAME ¤ò»ý¤Ä¥Õ¥©¥ó¥È¥»¥Ã¥È¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£ 
+    $NAME ¤¬ @c NULL ¤Ê¤é¤Ð¡¢¥Ç¥Õ¥©¥ë¥È¥Õ¥©¥ó¥È¥»¥Ã¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
+
+    $NAME ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥Õ¥©¥ó¥È¥»¥Ã¥È¤¬¤Ê¤±¤ì¤Ð¡¢¿·¤·¤¤¤â¤Î¤¬ºî¤é¤ì¤ë¡£¤½¤ÎºÝ¡¢
+    m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë \<@c fontset, $NAME\> 
+    ¤È¤¤¤¦¥Ç¡¼¥¿¤¬¤¢¤ì¤Ð¡¢¥Õ¥©¥ó¥È¥»¥Ã¥È¤Ï¤½¤Î¥Ç¡¼¥¿¤Ë±è¤Ã¤Æ½é´ü²½¤µ¤ì¤ë¡£
+    ¤Ê¤±¤ì¤Ð¡¢¶õ¤Î¤Þ¤Þ¤Ë¤µ¤ì¤ë¡£
+
+    ¥Þ¥¯¥í M17N_INIT () ¤Ï¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¥»¥Ã¥È¤òºî¤ë¡£¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï
+    mframe () ¤ò½é¤á¤Æ¸Æ¤Ö¤Þ¤Ç¤Î´Ö¤Ï¥Ç¥Õ¥©¥ë¥È¥Õ¥©¥ó¥È¥»¥Ã¥È¤òÊѹ¹¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¸«¤Ä¤«¤Ã¤¿¡¢¤¢¤ë¤¤¤Ïºî¤Ã¤¿¥Õ¥©¥ó¥È¥»¥Ã¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
+     */
+
+MFontset *
+mfontset (char *name)
+{
+  MSymbol sym;
+  MFontset *fontset;
+
+  if (! name)
+    {
+      fontset = default_fontset;
+      M17N_OBJECT_REF (fontset);
+    }
+  else
+    {
+      sym = msymbol (name);
+      fontset = mplist_get (fontset_list, sym);
+      if (fontset)
+       M17N_OBJECT_REF (fontset);
+      else
+       {
+         M17N_OBJECT (fontset, free_fontset, MERROR_FONTSET);
+         M17N_OBJECT_REGISTER (fontset_table, fontset);
+         fontset->name = sym;
+         fontset->mdb = mdatabase_find (Mfontset, sym, Mnil, Mnil);
+         if (! fontset->mdb)
+           {
+             fontset->per_script = mplist ();
+             fontset->per_charset = mplist ();
+             fontset->fallback = mplist ();
+           }
+         mplist_put (fontset_list, sym, fontset);
+       }
+    }
+  return fontset;
+}
+
+/*=*/
+
+/***en
+    @brief Return the name of a fontset.
+
+    The mfontset_name () function returns the name of fontset $FONTSET.  */
+/***ja
+    @brief ¥Õ¥©¥ó¥È¥»¥Ã¥È¤Î̾Á°¤òÊÖ¤¹.
+
+    ´Ø¿ô mfontset_name () ¤Ï¥Õ¥©¥ó¥È¥»¥Ã¥È $FONTSET ¤Î̾Á°¤òÊÖ¤¹¡£  */
+MSymbol
+mfontset_name (MFontset *fontset)
+{
+  return fontset->name;
+}
+
+/*=*/
+
+/***en
+    @brief Make a copy of a fontset.
+
+    The mfontset_copy () function makes a copy of fontset $FONTSET, gives it a
+    name $NAME, and returns a pointer to the created copy.  $NAME must
+    not be a name of existing fontset.  In such case, this function
+    returns NULL without making a copy.  */
+/***ja
+    @brief ¥Õ¥©¥ó¥È¥»¥Ã¥È¤Î¥³¥Ô¡¼¤òºî¤ë.
+
+    ´Ø¿ô mfontset_copy () ¤Ï¥Õ¥©¥ó¥È¥»¥Ã¥È $FONTSET ¤Î¥³¥Ô¡¼¤òºî¤Ã¤Æ¡¢Ì¾Á°
+    $NAME ¤òÍ¿¤¨¡¢¤½¤Î¥³¥Ô¡¼¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£$NAME 
+    ¤Ï´û¸¤Î¥Õ¥©¥ó¥È¥»¥Ã¥È¤Î̾Á°¤Ç¤¢¤Ã¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤½¤Î¤è¤¦¤Ê¾ì¹ç¤Ë¤Ï¥³¥Ô¡¼¤òºî¤é¤º¤Ë
+    NULL ¤òÊÖ¤¹¡£  */
+
+MFontset *
+mfontset_copy (MFontset *fontset, char *name)
+{
+  MSymbol sym = msymbol (name);
+  MFontset *copy = mplist_get (fontset_list, sym);
+  MPlist *plist, *pl, *p;
+
+  if (copy)
+    return NULL;
+  M17N_OBJECT (copy, free_fontset, MERROR_FONTSET);
+  M17N_OBJECT_REGISTER (fontset_table, copy);
+  copy->name = sym;
+
+  if (fontset->mdb)
+    load_fontset_contents (fontset);
+
+  if (fontset->per_script)
+    {
+      copy->per_script = mplist ();
+      MPLIST_DO (plist, fontset->per_script)
+        {
+         MPlist *per_lang = mplist ();
+
+         mplist_add (copy->per_script, MPLIST_KEY (plist), per_lang);
+         MPLIST_DO (pl, MPLIST_PLIST (plist))
+           {
+             MPlist *font_group = mplist ();
+
+             per_lang = mplist_add (per_lang, MPLIST_KEY (pl), font_group);
+             MPLIST_DO (p, MPLIST_PLIST (pl))
+               font_group = mplist_add (font_group, MPLIST_KEY (p),
+                                        mfont_copy (MPLIST_VAL (p)));
+           }
+       }
+    }
+  if (fontset->per_charset)
+    {
+      MPlist *per_charset = mplist ();
+
+      copy->per_charset = per_charset;
+      MPLIST_DO (pl, fontset->per_charset)
+       {
+         MPlist *font_group = mplist ();
+
+         per_charset = mplist_add (per_charset, MPLIST_KEY (pl), font_group);
+         MPLIST_DO (p, MPLIST_PLIST (pl))
+           font_group = mplist_add (font_group, MPLIST_KEY (p),
+                                    mfont_copy (MPLIST_VAL (p)));
+       }
+    }
+  if (fontset->fallback)
+    {
+      MPlist *font_group = mplist ();
+
+      copy->fallback = font_group;
+      MPLIST_DO (p, fontset->fallback)
+       font_group = mplist_add (font_group, MPLIST_KEY (p),
+                                mfont_copy (MPLIST_VAL (p)));
+    }                           
+
+  mplist_put (fontset_list, sym, copy);
+  return copy;
+}
+
+/*=*/
+
+/***en
+    @brief Modify the contents of a fontset.
+
+    The mfontset_modify_entry () function associates, in fontset
+    $FONTSET, a copy of $FONT with the $SCRIPT / $LANGUAGE pair or
+    with $CHARSET.
+
+    Each font in a fontset is associated with a particular
+    script/language pair, with a particular charset, or with the
+    symbol @c Mnil.  The fonts that are associated with the same item
+    make a group.
+
+    If $SCRIPT is not @c Mnil, it must be a symbol identifying a
+    script.  In this case, $LANGUAGE is either a symbol identifying a
+    language or @c Mnil, and $FONT is associated with the $SCRIPT /
+    $LANGUAGE pair.
+
+    If $CHARSET is not @c Mnil, it must be a symbol representing a
+    charset object.  In this case, $FONT is associated with that
+    charset.
+
+    If both $SCRIPT and $CHARSET are not @c Mnil, two copies of $FONT
+    are created.  Then one is associated with the $SCRIPT / $LANGUAGE
+    pair and the other with that charset.
+
+    If both $SCRIPT and $CHARSET are @c Mnil, $FONT is associated with
+    @c Mnil.  This kind of fonts are called @e fallback @e fonts.
+
+    The argument $HOW specifies the priority of $FONT.  If $HOW is
+    positive, $FONT has the highest priority in the group of fonts
+    that are associated with the same item.  If $HOW is negative,
+    $FONT has the lowest priority.  If $HOW is zero, $FONT becomes the
+    only available font for the associated item; all the other fonts
+    are removed from the group.
+
+    If $LAYOUTER_NAME is not @c Mnil, it must be a symbol representing
+    a @ref mdbFLT (font layout table).  In that case, if $FONT is
+    selected for drawing an M-text, that font layout table is used to
+    generate a glyph code sequence from a character sequence.
+
+    @return
+    If the operation was successful, mfontset_modify_entry () returns 0.
+    Otherwise it returns -1 and assigns an error code to the external
+    variable #merror_code.  */
+
+/***ja
+    @brief ¥Õ¥©¥ó¥È¥»¥Ã¥È¤ÎÆâÍƤòÊѹ¹¤¹¤ë.
+
+    ´Ø¿ô mfontset_modify_entry () ¤Ï¡¢$LANGUAGE ¤È $SCRIPT ¤ÎÁȤ߹ç¤ï¤»¡¢¤Þ¤¿¤Ï
+    $CHARSET ¤ËÂФ·¤Æ $FONT ¤Î¥³¥Ô¡¼¤ò»È¤¦¤è¤¦¤Ë¡¢¥Õ¥©¥ó¥È¥»¥Ã¥È $FONTSET ¤òÀßÄꤹ¤ë¡£
+
+    ¥Õ¥©¥ó¥È¥»¥Ã¥ÈÃæ¤Î³Æ¥Õ¥©¥ó¥È¤Ï¡¢ÆÃÄê¤Î¥¹¥¯¥ê¥×¥È¤È¸À¸ì¤Î¥Ú¥¢¡¢ÆÃÄê¤Îʸ»ú¥»¥Ã¥È¡¢¥·¥ó¥Ü¥ë
+    @c Mnil ¤Î¤¤¤º¤ì¤«¤È´ØÏ¢ÉÕ¤±¤é¤ì¤Æ¤¤¤ë¡£Æ±¤¸¤â¤Î¤È´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Õ¥©¥ó¥È¤Ï¥°¥ë¡¼¥×¤ò¹½À®¤¹¤ë¡£
+
+    $SCRIPT ¤Ï @c Mnil ¤Ç¤¢¤ë¤«¡¢¥¹¥¯¥ê¥×¥È¤òÆÃÄꤹ¤ë¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+    ¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢$LANGUAGE ¤Ï¸À¸ì¤òÆÃÄꤹ¤ë¥·¥ó¥Ü¥ë¤« @c
+    Mnil ¤Ç¤¢¤ê¡¢$FONT ¤Ïthe $SCRIPT / $LANGUAGE ¥Ú¥¢¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤ë¡£
+
+    $CHARSET ¤Ï @c Mnil ¤Ç¤¢¤ë¤«¡¢Ê¸»ú¥»¥Ã¥È¥ª¥Ö¥¸¥§¥¯¥È¤òɽ¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+    ¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¾ì¹ç¤Ë¤Ï $FONT ¤Ï¤½¤Îʸ»ú¥»¥Ã¥È¤È´ØÏ¢ÉÕ¤±¤é¤ì¤ë¡£
+
+    $SCRIPT ¤È $CHARSET ¤ÎÁÐÊý¤¬ @c Mnil ¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Ï $FONT 
+    ¤Î¥³¥Ô¡¼¤¬£²¤Äºî¤é¤ì¡¢¤½¤ì¤¾¤ì $SCRIPT / $LANGUAGE 
+    ¥Ú¥¢¤Èʸ»ú¥»¥Ã¥È¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤ë¡£
+
+    $SCRIPT ¤È $CHARSET ¤ÎÁÐÊý¤¬ @c Mnil ¤Ê¤é¤Ð¡¢ $FONT ¤Ï @c Mnil 
+    ¤È´ØÏ¢ÉÕ¤±¤é¤ì¤ë¡£¤³¤Î¼ï¤Î¥Õ¥©¥ó¥È¤Ï @e fallback @e font ¤È¸Æ¤Ð¤ì¤ë¡£
+
+    °ú¿ô $HOW ¤Ï $FONT ¤ÎÍ¥ÀèÅÙ¤ò»ØÄꤹ¤ë¡£$HOW ¤¬Àµ¤Ê¤é¤Ð¡¢$FONT 
+    ¤ÏƱ¤¸¤â¤Î¤È´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥°¥ë¡¼¥×Ãæ¤ÇºÇ¹â¤ÎÍ¥ÀèÅÙ¤ò»ý¤Ä¡£$HOW 
+    ¤¬Éé¤Ê¤é¤Ð¡¢ºÇÄã¤ÎÍ¥ÀèÅÙ¤ò»ý¤Ä¡£$HOW ¤¬ 0 ¤Ê¤é¤Ð¡¢$FONT 
+    ¤Ï´ØÏ¢ÉÕ¤±¤é¤ì¤¿¤â¤Î¤ËÂФ¹¤ëÍ£°ì¤ÎÍøÍѲÄǽ¤Ê¥Õ¥©¥ó¥È¤È¤Ê¤ê¡¢Â¾¤Î¥Õ¥©¥ó¥È¤Ï¥°¥ë¡¼¥×¤«¤é¼è¤ê½ü¤«¤ì¤ë¡£
+
+    $LAYOUTER_NAME ¤Ï @c Mnil ¤Ç¤¢¤ë¤«¡¢@ref mdbFLT 
+    ¡Ê¥Õ¥©¥ó¥È¥ì¥¤¥¢¥¦¥È¥Æ¡¼¥Ö¥ë¡Ë¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£¥·¥ó¥Ü¥ë¤Ç¤¢¤ì¤Ð¡¢$FONT ¤òÍѤ¤¤Æ
+    M-text ¤òɽ¼¨¤¹¤ëºÝ¤Ë¤Ï¡¢¤½¤Î¥Õ¥©¥ó¥È¥ì¥¤¥¢¥¦¥È¥Æ¡¼¥Ö¥ë¤ò»È¤Ã¤Æʸ»úÎ󤫤饰¥ê¥Õ¥³¡¼¥ÉÎó¤òÀ¸À®¤¹¤ë¡£
+
+    @return 
+    ½èÍý¤¬À®¸ù¤·¤¿¤È¤­¡¢mfontset_modify_entry () ¤Ï 0 ¤òÊÖ¤¹¡£
+    ¼ºÇÔ¤·¤¿¤È¤­¤Ï -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_SYMBOL  */
+
+int
+mfontset_modify_entry (MFontset *fontset,
+                      MSymbol script, MSymbol language, MSymbol charset,
+                      MFont *spec, MSymbol layouter_name,
+                      int how)
+{
+  MPlist *per_lang, *plist[3];
+  MFont *font = NULL;
+  int i;
+
+  if (fontset->mdb)
+    load_fontset_contents (fontset);
+
+  i = 0;
+  if (script != Mnil)
+    {
+      if (language == Mnil)
+       language = Mt;
+      per_lang = mplist_get (fontset->per_script, script);
+      if (! per_lang)
+       mplist_add (fontset->per_script, script, per_lang = mplist ());
+      plist[i] = mplist_get (per_lang, language);
+      if (! plist[i])
+       mplist_add (per_lang, language, plist[i] = mplist ());
+      i++;
+    }
+  if (charset != Mnil)
+    {
+      plist[i] = mplist_get (fontset->per_charset, charset);
+      if (! plist[i])
+       mplist_add (fontset->per_charset, charset, plist[i] = mplist ());
+      i++;
+    }
+  if (script == Mnil && charset == Mnil)
+    {
+      plist[i++] = fontset->fallback;
+    }
+
+  if (layouter_name == Mnil)
+    layouter_name = Mt;
+  for (i--; i >= 0; i--)
+    {
+      font = mfont_copy (spec);
+      font->type = MFONT_TYPE_SPEC;
+      if (how == 1)
+       mplist_push (plist[i], layouter_name, font);
+      else if (how == -1)
+       mplist_add (plist[i], layouter_name, font);
+      else
+       {
+         MPlist *pl;
+
+         MPLIST_DO (pl, plist[i])
+           free (MPLIST_VAL (pl));
+         mplist_set (plist[i], Mnil, NULL);
+         mplist_add (plist[i], layouter_name, font);
+       }
+    }
+
+  fontset->tick++;
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Lookup a fontset.
+
+    The mfontset_lookup () function lookups $FONTSET and returns a
+    plist that describes the contents of $FONTSET corresponding to the
+    specified script, language, and charset.
+
+    If $SCRIPT is @c Mt, keys of the returned plist are script name
+    symbols for which some fonts are specified and values are NULL.
+
+    If $SCRIPT is a script name symbol, the returned plist is decided
+    by $LANGUAGE.
+    
+    @li If $LANGUAGE is @c Mt, keys of the plist are language name
+    symbols for which some fonts are specified and values are NULL.  A
+    key may be @c Mt which means some fallback fonts are specified for
+    the script.
+
+    @li If $LANGUAGE is a language name symbol, the plist is a @c
+    FONT-GROUP for the specified script and language.  @c FONT-GROUP
+    is a plist whose keys are FLT (FontLayoutTable) name symbols (@c
+    Mt if no FLT is associated with the font) and values are pointers
+    to #MFont.
+
+    @li If $LANGUAGE is @c Mnil, the plist is fallback @c FONT-GROUP
+    for the script. 
+
+    If $SCRIPT is @c Mnil, the returned plist is decided as below.
+
+    @li If $CHARSET is @c Mt, keys of the returned plist are charset name
+    symbols for which some fonts are specified and values are NULL.
+
+    @li If $CHARSET is a charset name symbol, the plist is a @c FONT-GROUP for
+    the charset.
+
+    @li If $CHARSET is @c Mnil, the plist is a fallback @c FONT-GROUP.
+
+    @return
+    It returns a plist describing the contents of a fontset.  The
+    plist should be freed by m17n_object_unref ().  */
+/***ja
+    @brief ¥Õ¥©¥ó¥È¥»¥Ã¥È¤ò¸¡º÷¤¹¤ë.
+
+    ´Ø¿ô mfontset_lookup () ¤Ï $FONTSET ¤ò¸¡º÷¤·¡¢$FONTSET 
+    ¤ÎÆâÍƤΤ¦¤Á»ØÄꤷ¤¿¥¹¥¯¥ê¥×¥È¡¢¸À¸ì¡¢Ê¸»ú¥»¥Ã¥È¤ËÂбþ¤¹¤ëÉôʬ¤òɽ¤¹
+    plist ¤òÊÖ¤¹¡£
+
+    $SCRIPT ¤¬ @c Mt ¤Ê¤é¤Ð¡¢ÊÖ¤¹ plist 
+    ¤Î¥­¡¼¤Ï¥Õ¥©¥ó¥È¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¥¹¥¯¥ê¥×¥È̾¤Î¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢ÃͤÏ
+    NULL ¤Ç¤¢¤ë¡£
+
+    $SCRIPT ¤¬¥¹¥¯¥ê¥×¥È̾¤Î¥·¥ó¥Ü¥ë¤Ç¤¢¤ì¤Ð¡¢ÊÖ¤¹ 
+    plist ¤Ï $LANGUAGE¤Ë¤è¤Ã¤ÆÄê¤Þ¤ë¡£
+    
+    @li $LANGUAGE ¤¬ @c Mt ¤Ê¤é¤Ð¡¢plist 
+    ¤Î¥­¡¼¤Ï¥Õ¥©¥ó¥È¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¸À¸ì̾¤Î¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢ÃͤÏ
+    NULL ¤Ç¤¢¤ë¡£¥­¡¼¤Ï @c Mt
+    ¤Ç¤¢¤ë¤³¤È¤â¤¢¤ê¡¢¤½¤Î¾ì¹ç¤½¤Î¥¹¥¯¥ê¥×¥È¤Ë¥Õ¥©¡¼¥ë¥Ð¥Ã¥¯¥Õ¥©¥ó¥È¤¬¤¢¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
+
+    @li $LANGUAGE ¤¬¸À¸ì̾¤Î¥·¥ó¥Ü¥ë¤Ê¤é¤Ð¡¢plist ¤Ï»ØÄê¤Î¥¹¥¯¥ê¥×¥È¤È¸À¸ì¤ËÂФ¹¤ë
+    @c FONT-GROUP ¤Ç¤¢¤ë¡£@c FONT-GROUP ¤È¤Ï¡¢¥­¡¼¤¬ FLT
+    (FontLayoutTable) Ì¾¤Î¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢Ãͤ¬ #MFont 
+    ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¤è¤¦¤Ê plist ¤Ç¤¢¤ë¡£¤¿¤À¤·¥Õ¥©¥ó¥È¤Ë FLT 
+    ¤¬ÂбþÉÕ¤±¤é¤ì¤Æ¤¤¤Ê¤¤»þ¤Ë¤Ï¡¢¥­¡¼¤Ï @c Mt ¤Ë¤Ê¤ë¡£
+
+    @li $LANGUAGE ¤¬ @c Mnil ¤Ê¤é¤Ð¡¢plist ¤Ï¤½¤Î¥¹¥¯¥ê¥×¥ÈÍѤΥե©¡¼¥ë¥Ð¥Ã¥¯
+    @c FONT-GROUP ¤Ç¤¢¤ë¡£
+
+    $SCRIPT ¤¬ @c Mnil ¤Ê¤é¤Ð¡¢ÊÖ¤¹ plist ¤Ï°Ê²¼¤Î¤è¤¦¤ËÄê¤Þ¤ë¡£
+
+    @li $CHARSET ¤¬ @c Mt ¤Ê¤é¤Ð¡¢plist 
+    ¤Î¥­¡¼¤Ï¥Õ¥©¥ó¥È¤¬»ØÄꤵ¤ì¤Æ¤¤¤ëʸ»ú¥»¥Ã¥È̾¤Î¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢ÃͤÏ
+    NULL ¤Ç¤¢¤ë¡£
+
+    @li $CHARSET ¤¬Ê¸»ú¥»¥Ã¥È̾¤Î¥·¥ó¥Ü¥ë¤Ê¤é¤Ð¡¢plist ¤Ï¤½¤Îʸ»ú¥»¥Ã¥ÈÍѤΠ
+    @c FONT-GROUP ¤Ç¤¢¤ë¡£
+
+    @li $CHARSET ¤¬ @c Mnil ¤Ê¤é¤Ð¡¢plist ¤Ï¥Õ¥©¡¼¥ë¥Ð¥Ã¥¯ @c FONT-GROUP ¤Ç¤¢¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¥Õ¥©¥ó¥È¥»¥Ã¥È¤ÎÆâÍƤòɽ¤¹ plist ¤òÊÖ¤¹¡£
+    plist ¤Ï m17n_object_unref () ¤Ç²òÊü¤µ¤ì¤ë¤Ù¤­¤Ç¤¢¤ë¡£  */
+
+MPlist *
+mfontset_lookup (MFontset *fontset,
+                MSymbol script, MSymbol language, MSymbol charset)
+{
+  MPlist *plist = mplist (), *pl, *p;
+
+  if (fontset->mdb)
+    load_fontset_contents (fontset);
+  if (script == Mt)
+    {
+      if (! fontset->per_script)
+       return plist;
+      p = plist;
+      MPLIST_DO (pl, fontset->per_script)
+       p = mplist_add (p, MPLIST_KEY (pl), NULL);
+      return plist;
+    }
+  if (script != Mnil)
+    {
+      pl = get_per_script (fontset, script);
+      if (MPLIST_TAIL_P (pl))
+       return plist;
+      if (language == Mt)
+       {
+         p = plist;
+         MPLIST_DO (pl, pl)
+           p = mplist_add (p, MPLIST_KEY (pl), NULL);
+         return plist;
+       }
+      if (language == Mnil)
+       language = Mt;
+      pl = mplist_get (pl, language);
+    }
+  else if (charset != Mnil)
+    {
+      if (! fontset->per_charset)
+       return plist;
+      if (charset == Mt)
+       {
+         p = plist;
+         MPLIST_DO (pl, fontset->per_charset)
+           p = mplist_add (p, MPLIST_KEY (pl), NULL);
+         return plist;
+       }
+      pl = mplist_get (fontset->per_charset, charset);
+    }
+  else
+    pl = fontset->fallback;
+  if (! pl)
+    return plist;
+  return mplist_copy (pl);
+}
+
+
+/*** @} */
+
+/*** @addtogroup m17nDebug */
+/*=*/
+/*** @{  */
+
+/***en
+    @brief Dump a fontset.
+
+    The mdebug_dump_fontset () function prints fontset $FONTSET in a human readable
+    way to the stderr.  $INDENT specifies how many columns to indent
+    the lines but the first one.
+
+    @return
+    This function returns $FONTSET.  */
+/***ja
+    @brief ¥Õ¥©¥ó¥È¥»¥Ã¥È¤ò¥À¥ó¥×¤¹¤ë.
+
+    ´Ø¿ô mdebug_dump_face () ¤Ï¥Õ¥©¥ó¥È¥»¥Ã¥È $FONTSET ¤ò stderr 
+    ¤Ë¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç°õºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï $FONTSET ¤òÊÖ¤¹¡£  */
+
+MFontset *
+mdebug_dump_fontset (MFontset *fontset, int indent)
+{
+  char *prefix = (char *) alloca (indent + 1);
+  MPlist *plist, *pl, *p;
+
+  memset (prefix, 32, indent);
+  prefix[indent] = 0;
+
+  fprintf (stderr, "(fontset %s", fontset->name->name);
+  if (fontset->per_script)
+    MPLIST_DO (plist, fontset->per_script)
+      {
+       fprintf (stderr, "\n  %s(%s", prefix, MPLIST_KEY (plist)->name);
+       MPLIST_DO (pl, MPLIST_PLIST (plist))
+         {
+           fprintf (stderr, "\n    %s(%s", prefix, MPLIST_KEY (pl)->name);
+           MPLIST_DO (p, MPLIST_PLIST (pl))
+             {
+               fprintf (stderr, "\n      %s(0x%X %s ", prefix,
+                        (unsigned) MPLIST_VAL (p),
+                        MPLIST_KEY (p)->name);
+               mdebug_dump_font (MPLIST_VAL (p));
+               fprintf (stderr, ")");
+             }
+           fprintf (stderr, ")");
+         }
+       fprintf (stderr, ")");
+      }
+  if (fontset->per_charset)
+    MPLIST_DO (pl, fontset->per_charset)
+      {
+       fprintf (stderr, "\n  %s(%s", prefix, MPLIST_KEY (pl)->name);
+       MPLIST_DO (p, MPLIST_PLIST (pl))
+         {
+           fprintf (stderr, "\n    %s(%s ", prefix, MPLIST_KEY (p)->name);
+           mdebug_dump_font (MPLIST_VAL (p));
+           fprintf (stderr, ")");
+         }
+       fprintf (stderr, ")");
+      }
+
+  if (fontset->fallback)
+    MPLIST_DO (p, fontset->fallback)
+      {
+       fprintf (stderr, "\n  %s(%s ", prefix, MPLIST_KEY (p)->name);
+       mdebug_dump_font (MPLIST_VAL (p));
+       fprintf (stderr, ")");
+      }
+
+  fprintf (stderr, ")");
+  return fontset;
+}
+
+/*** @} */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/fontset.h b/src/fontset.h
new file mode 100644 (file)
index 0000000..6b7c3d9
--- /dev/null
@@ -0,0 +1,43 @@
+/* fontset.h -- header file for the fontset module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_FONTSET_H_
+#define _M17N_FONTSET_H_
+
+extern MRealizedFontset *mfont__realize_fontset (MFrame *frame,
+                                                MFontset *fontset,
+                                                MFace *face, MFont *spec);
+
+void mfont__free_realized_fontset (MRealizedFontset *realized);
+
+extern MRealizedFont *mfont__lookup_fontset (MRealizedFontset *realized,
+                                            MGlyph *g, int *num,
+                                            MSymbol script, MSymbol language,
+                                            MSymbol charset, int size,
+                                            int ignore_fallback);
+
+extern MRealizedFont *mfontset__get_font (MFrame *frame, MFontset *fontset,
+                                         MSymbol script, MSymbol language,
+                                         MFont *font, int *best);
+
+
+#endif /* _M17N_FONTSET_H_ */
diff --git a/src/input-gui.c b/src/input-gui.c
new file mode 100644 (file)
index 0000000..2c1ac42
--- /dev/null
@@ -0,0 +1,762 @@
+/* input-gui.c -- gui-based input method module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nInputMethodWin
+    @brief Input method support on window systems.
+
+    The input driver @c minput_gui_driver is provided for internal
+    input methods that is useful on window systems.  It displays
+    preedit text and status text at the inputting spot.  See the
+    documentation of @c minput_gui_driver for more details.
+
+    In the m17n-X library, the foreign input method of name @c Mxim is
+    provided.  It uses XIM (X Input Method) as a background input
+    engine.  The symbol @c Mxim has a property @c Minput_driver whose
+    value is a pointer to the input driver @c minput_xim_driver.  See
+    the documentation of @c minput_xim_driver for more details.  */
+
+/***ja
+    @addtogroup m17nInputMethodWin
+    @brief ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¾å¤ÎÆþÎϥ᥽¥Ã¥É¤Î¥µ¥Ý¡¼¥È.
+
+    ÆþÎϥɥ饤¥Ð @c minput_gui_driver ¤Ï¡¢
+    ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¾å¤ÇÍѤ¤¤é¤ì¤ëÆâÉôÆþÎϥ᥽¥Ã¥ÉÍѤΥɥ饤¥Ð¤Ç¤¢¤ë¡£
+    ¤³¤Î¥É¥é¥¤¥Ð¤ÏÆþÎÏ¥¹¥Ý¥Ã¥È¤Ë preedit ¥Æ¥­¥¹¥È¤È status 
+    ¥Æ¥­¥¹¥È¤òɽ¼¨¤¹¤ë¡£¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï @c minput_gui_driver ¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£
+
+    m17n-X ¥é¥¤¥Ö¥é¥ê¤Ï¡¢@c Mxim ¤È¸À¤¦Ì¾Á°¤ò»ý¤Ä³°ÉôÆþÎϥ᥽¥Ã¥É¤òÄ󶡤·¤Æ¤¤¤ë¡£¤³¤ì¤Ï 
+    XIM (X Input Method) ¤ò¥Ð¥Ã¥¯¥°¥é¥¦¥ó¥É¤ÎÆþÎÏ¥¨¥ó¥¸¥ó¤È¤·¤ÆÍøÍѤ¹¤ë¡£¥·¥ó¥Ü¥ë
+    @c Mxim ¤Ï @c Minput_driver ¤È¤¤¤¦¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ã¤Æ¤ª¤ê¡¢¤½¤ÎÃͤÏÆþÎϥɥ饤¥Ð 
+    @c minput_xim_driver ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£ ¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï 
+    @c minput_xim_driver ¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£  */
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <string.h>
+#include <ctype.h>
+
+#include "config.h"
+#include "m17n-gui.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "internal-gui.h"
+#include "input.h"
+
+typedef struct
+{
+  MDrawWindow win;
+  MDrawMetric geometry;
+  MDrawControl control;
+  int mapped;
+} MInputGUIWinInfo;
+
+typedef struct
+{
+  MInputContextInfo *ic_info;
+
+  MFrame *frame;
+  /* <geometry>.x and <geometry>.y are not used.  */
+  MInputGUIWinInfo client;
+  /* In the following members, <geometry> is relative to <client>.  */
+  MInputGUIWinInfo focus;
+  MInputGUIWinInfo preedit;
+  MInputGUIWinInfo status;
+  MInputGUIWinInfo candidates;
+} MInputGUIContextInfo;
+
+static MFace *status_face;
+static MFaceBoxProp face_box_prop;
+
+static int
+win_create_ic (MInputContext *ic)
+{
+  MInputGUIContextInfo *win_ic_info;
+  MInputGUIArgIC *win_info = (MInputGUIArgIC *) ic->arg;
+  MFrame *frame = win_info->frame;
+
+  if ((*minput_default_driver.create_ic) (ic) < 0)
+    return -1;
+
+  MSTRUCT_CALLOC (win_ic_info, MERROR_IM);
+  win_ic_info->ic_info = (MInputContextInfo *) ic->info;
+  win_ic_info->frame = frame;
+  win_ic_info->client.win = win_info->client;
+  (*frame->driver->window_geometry) (frame, win_info->client, win_info->client,
+                        &win_ic_info->client.geometry);
+  win_ic_info->focus.win = win_info->focus;
+  (*frame->driver->window_geometry) (frame, win_info->focus, win_info->client,
+                        &win_ic_info->focus.geometry);
+
+  win_ic_info->preedit.win = (*frame->driver->create_window) (frame, win_info->client);
+  win_ic_info->preedit.control.two_dimensional = 1;
+  win_ic_info->preedit.control.as_image = 0;
+  win_ic_info->preedit.control.with_cursor = 1;
+  win_ic_info->preedit.control.cursor_width = 1;
+  win_ic_info->preedit.control.enable_bidi = 1;
+  win_ic_info->preedit.geometry.x = -1;
+  win_ic_info->preedit.geometry.y = -1;
+
+  win_ic_info->status.win = (*frame->driver->create_window) (frame, win_info->client);
+  win_ic_info->status.control.as_image = 1;
+  win_ic_info->status.control.enable_bidi = 1;
+
+  win_ic_info->candidates.win = (*frame->driver->create_window) (frame, win_info->client);
+  win_ic_info->candidates.control.as_image = 1;
+
+  ic->info = win_ic_info;
+
+  return 0;
+}
+
+static void
+win_destroy_ic (MInputContext *ic)
+{
+  MInputGUIContextInfo *win_ic_info = (MInputGUIContextInfo *) ic->info;
+  MInputContextInfo *ic_info = (MInputContextInfo *) win_ic_info->ic_info;
+  MFrame *frame = win_ic_info->frame;
+
+  (*frame->driver->destroy_window) (frame, win_ic_info->preedit.win);
+  (*frame->driver->destroy_window) (frame, win_ic_info->status.win);
+  (*frame->driver->destroy_window) (frame, win_ic_info->candidates.win);
+  ic->info = ic_info;
+  (*minput_default_driver.destroy_ic) (ic);
+  free (win_ic_info);
+}
+
+static int
+win_filter (MInputContext *ic, MSymbol key, void *arg)
+{
+  MInputGUIContextInfo *win_ic_info = (MInputGUIContextInfo *) ic->info;
+  MInputContextInfo *ic_info = (MInputContextInfo *) win_ic_info->ic_info;
+  int ret;
+
+  if (! ic
+      || ! ic->active)
+    return 0;
+
+  if (key == Mnil && arg)
+    {
+      key = minput_event_to_key (win_ic_info->frame, arg);
+      if (key == Mnil)
+       return 1;
+    }
+  ic->info = ic_info;
+  ret = (*minput_default_driver.filter) (ic, key, arg);
+  ic->info = win_ic_info;
+  return ret;
+}
+
+static void
+adjust_window_and_draw (MFrame *frame, MInputContext *ic, MText *mt, int type)
+{
+  MInputGUIContextInfo *win_ic_info = (MInputGUIContextInfo *) ic->info;
+  MDrawControl *control;
+  MDrawWindow win;
+  MDrawMetric *geometry, physical, logical;
+  int xoff = win_ic_info->focus.geometry.x;
+  int yoff = win_ic_info->focus.geometry.y;
+  int x0, x1, y0, y1;
+  int len = mtext_nchars (mt);
+
+  if (type == 0)
+    {
+      win = win_ic_info->preedit.win;
+      control = &win_ic_info->preedit.control;
+      geometry = &win_ic_info->preedit.geometry;
+      len++;
+    }
+  else if (type == 1)
+    {
+      win = win_ic_info->status.win;
+      control = &win_ic_info->status.control;
+      geometry = &win_ic_info->status.geometry;
+    }
+  else
+    {
+      win = win_ic_info->candidates.win;
+      control = &win_ic_info->candidates.control;
+      geometry = &win_ic_info->candidates.geometry;
+    }
+
+  mdraw_text_extents (frame, mt, 0, len, control, &physical, &logical, NULL);
+  x0 = physical.x, x1 = x0 + physical.width;
+  y0 = physical.y, y1 = y0 + physical.height;
+  if (x0 > logical.x)
+    x0 = logical.x;
+  if (x1 < logical.x + logical.width)
+    x1 = logical.x + logical.width;
+  if (y0 > logical.y)
+    y0 = logical.y;
+  if (y1 < logical.y + logical.height)
+    y1 = logical.y + logical.height;
+  physical.width = x1 - x0;
+  physical.height = y1 - y0;
+  physical.x = xoff + ic->spot.x;
+  if (physical.x + physical.width > win_ic_info->client.geometry.width)
+    physical.x = win_ic_info->client.geometry.width - physical.width;
+  if (type == 0)
+    {
+      if (len <= 1)
+       {
+         physical.height = physical.width = 1;
+         physical.x = physical.y = -1;
+       }
+      else
+       {
+         if (y0 > - ic->spot.ascent)
+           {
+             physical.height += y0 + ic->spot.ascent;
+             y0 = - ic->spot.ascent;
+           }
+         if (y1 < ic->spot.descent)
+           {
+             physical.height += ic->spot.descent - y1;
+           }
+         physical.y = yoff + ic->spot.y + y0;
+       }
+    }
+  else if (type == 1)
+    {
+      physical.y = yoff + ic->spot.y + ic->spot.descent + 2;
+      if (physical.y + physical.height > win_ic_info->client.geometry.height
+         && yoff + ic->spot.y - ic->spot.ascent - 2 - physical.height >= 0)
+       physical.y = yoff + ic->spot.y - ic->spot.ascent - 2 - physical.height;
+    }
+  else
+    {
+      if (win_ic_info->status.mapped)
+       {
+         /* We assume that status is already drawn.  */
+         if (win_ic_info->status.geometry.y < yoff + ic->spot.y)
+           /* As there was no lower room for status, candidates must also
+              be drawn upper.  */
+           physical.y = win_ic_info->status.geometry.y - 1 - physical.height;
+         else
+           {
+             /* There was a lower room for status.  */
+             physical.y = (win_ic_info->status.geometry.y
+                           + win_ic_info->status.geometry.height
+                           + 1);
+             if (physical.y + physical.height
+                 > win_ic_info->client.geometry.height)
+               /* But not for candidates.  */
+               physical.y = (yoff + ic->spot.y - ic->spot.ascent - 1
+                             - physical.height);
+           }
+       }
+      else
+       {
+         physical.y = yoff + ic->spot.y + ic->spot.descent + 2;
+         if ((physical.y + physical.height
+              > win_ic_info->client.geometry.height)
+             && (yoff + ic->spot.y - ic->spot.ascent - 2 - physical.height
+                 >= 0))
+           physical.y = (yoff + ic->spot.y - ic->spot.ascent - 2
+                         - physical.height);
+       }
+    }
+
+  (*frame->driver->adjust_window) (frame, win, geometry, &physical);
+  mdraw_text_with_control (frame, win, -x0, -y0, mt, 0, len, control);
+}
+
+static void
+win_callback (MInputContext *ic, MSymbol command)
+{
+  MInputGUIContextInfo *win_ic_info = (MInputGUIContextInfo *) ic->info;
+  MFrame *frame = win_ic_info->frame;
+
+  if (command == Minput_preedit_draw)
+    {
+      MText *mt;
+      MFace *face = mface ();
+
+      if (! win_ic_info->preedit.mapped)
+       {
+         (*frame->driver->map_window) (frame, win_ic_info->preedit.win);
+         win_ic_info->preedit.mapped = 1;
+       }
+      win_ic_info->preedit.control.cursor_pos = ic->cursor_pos;
+      if (ic->spot.fontsize)
+       mface_put_prop (face, Msize, (void *) ic->spot.fontsize);
+      mface_merge (face, mface_underline);
+      mtext_push_prop (ic->preedit, 0, mtext_nchars (ic->preedit),
+                      Mface, face);
+      M17N_OBJECT_UNREF (face);
+      if (ic->im->language != Mnil)
+       mtext_put_prop (ic->preedit, 0, mtext_nchars (ic->preedit), Mlanguage,
+                       ic->im->language);
+      if (ic->candidate_list && ic->candidate_show)
+       mtext_push_prop (ic->preedit, ic->candidate_from, ic->candidate_to,
+                        Mface, mface_reverse_video);
+      if (mtext_nchars (ic->produced) == 0)
+       mt = ic->preedit;
+      else
+       {
+         mt = mtext_dup (ic->produced);
+         mtext_cat (mt, ic->preedit);
+         win_ic_info->preedit.control.cursor_pos
+           += mtext_nchars (ic->produced);
+       }
+      adjust_window_and_draw (frame, ic, mt, 0);
+      if (ic->candidate_list)
+       mtext_pop_prop (ic->preedit, 0, mtext_nchars (ic->preedit), Mface);
+      mtext_pop_prop (ic->preedit, 0, mtext_nchars (ic->preedit), Mface);
+      if (mtext_nchars (ic->produced) != 0)
+       M17N_OBJECT_UNREF (mt);
+    }
+  else if (command == Minput_status_draw)
+    {
+      if (! win_ic_info->client.win)
+       return;
+      mtext_put_prop (ic->status, 0, mtext_nchars (ic->status), Mface,
+                     status_face);
+      if (ic->im->language != Mnil)
+       mtext_put_prop (ic->status, 0, mtext_nchars (ic->status), Mlanguage,
+                       ic->im->language);
+      adjust_window_and_draw (frame, ic, ic->status, 1);
+    }
+  else if (command == Minput_candidates_draw)
+    {
+      MPlist *group;
+      MText *mt;
+      int i, len;
+      int from, to;
+
+      if (! ic->candidate_list || ! ic->candidate_show)
+       {
+         if (win_ic_info->candidates.mapped)
+           {
+             (*frame->driver->unmap_window) (frame, win_ic_info->candidates.win);
+             win_ic_info->candidates.mapped = 0;
+           }
+         return;
+       }
+
+      if (! win_ic_info->candidates.mapped)
+       {
+         (*frame->driver->map_window) (frame, win_ic_info->candidates.win);
+         win_ic_info->candidates.mapped = 1;
+       }
+
+      i = 0;
+      group = ic->candidate_list;
+      while (1)
+       {
+         if (mplist_key (group) == Mtext)
+           len = mtext_len (mplist_value (group));
+         else
+           len = mplist_length (mplist_value (group));
+         if (i + len > ic->candidate_index)
+           break;
+         i += len;
+         group = mplist_next (group);
+       }
+
+      mt = mtext ();
+      if (mplist_key (group) == Mtext)
+       {
+         MText *candidates = (MText *) mplist_value (group);
+
+         from = (ic->candidate_index - i) * 2 + 1;
+         to = from + 1;
+         for (i = 0; i < len; i++)
+           {
+             mtext_cat_char (mt, ' ');
+             mtext_cat_char (mt, mtext_ref_char (candidates, i));
+           }
+       }
+      else
+       {
+         MPlist *pl;
+
+         for (pl = (MPlist *) mplist_value (group);
+              i < ic->candidate_index && mplist_key (pl) != Mnil;
+              i++, pl = mplist_next (pl))
+           {
+             mtext_cat_char (mt, ' ');
+             mtext_cat (mt, (MText *) mplist_value (pl));
+           }
+         from = mtext_nchars (mt) + 1;
+         to = from + mtext_nchars ((MText *) mplist_value (pl));
+         for (; mplist_key (pl) != Mnil; pl = mplist_next (pl))
+           {
+             mtext_cat_char (mt, ' ');
+             mtext_cat (mt, (MText *) mplist_value (pl));
+           }
+       }
+      mtext_cat_char (mt, ' ');
+      mtext_push_prop (mt, 0, mtext_nchars (mt), Mface, status_face);
+      mtext_push_prop (mt, from, to, Mface, mface_reverse_video);
+      if (ic->im->language != Mnil)
+       mtext_put_prop (mt, 0, mtext_nchars (mt), Mlanguage, ic->im->language);
+      adjust_window_and_draw (frame, ic, mt, 2);
+      M17N_OBJECT_UNREF (mt);
+    }
+  else if (command == Minput_set_spot)
+    {
+      minput_callback (ic, Minput_preedit_draw);
+      minput_callback (ic, Minput_status_draw);
+      minput_callback (ic, Minput_candidates_draw);
+    }
+  else if (command == Minput_toggle)
+    {
+      if (ic->active)
+       {
+         minput_callback (ic, Minput_preedit_done);
+         minput_callback (ic, Minput_status_done);
+         minput_callback (ic, Minput_candidates_done);
+       }
+      else
+       {
+         minput_callback (ic, Minput_preedit_start);
+         minput_callback (ic, Minput_status_start);
+         minput_callback (ic, Minput_candidates_start);
+       }
+    }
+  else if (command == Minput_preedit_start)
+    {
+    }
+  else if (command == Minput_preedit_done)
+    {
+      if (win_ic_info->preedit.mapped)
+       {
+         (*frame->driver->unmap_window) (frame, win_ic_info->preedit.win);
+         win_ic_info->preedit.mapped = 0;
+       }
+    }
+  else if (command == Minput_status_start)
+    {
+      if (! win_ic_info->status.mapped)
+       {
+         (*frame->driver->map_window) (frame, win_ic_info->status.win);
+         win_ic_info->status.mapped = 1;
+       }
+    }
+  else if (command == Minput_status_done)
+    {
+      if (win_ic_info->status.mapped)
+       {
+         (*frame->driver->unmap_window) (frame, win_ic_info->status.win);
+         win_ic_info->status.mapped = 0;
+       }
+    }
+  else if (command == Minput_candidates_start)
+    {
+      if (! win_ic_info->candidates.mapped)
+       {
+         (*frame->driver->map_window) (frame, win_ic_info->candidates.win);
+         win_ic_info->candidates.mapped = 1;
+       }
+    }
+  else if (command == Minput_candidates_done)
+    {
+      if (win_ic_info->candidates.mapped)
+       {
+         (*frame->driver->unmap_window) (frame, win_ic_info->candidates.win);
+         win_ic_info->candidates.mapped = 0;
+       }
+    }
+  else if (command == Minput_reset)
+    {
+      MInputCallbackFunc func;
+
+      if (minput_default_driver.callback_list
+         && (func = ((MInputCallbackFunc)
+                     mplist_get_func (minput_default_driver.callback_list,
+                                      Minput_reset))))
+       {
+         MInputContextInfo *ic_info
+           = (MInputContextInfo *) win_ic_info->ic_info;
+         ic->info = ic_info;
+         (func) (ic, Minput_reset);
+         ic->info = win_ic_info;
+       }
+      if (ic->preedit_changed)
+       minput_callback (ic, Minput_preedit_draw);
+      if (ic->status_changed)
+       minput_callback (ic, Minput_status_draw);
+      if (ic->candidates_changed)
+       minput_callback (ic, Minput_candidates_draw);
+    }
+}
+
+static int
+win_lookup (MInputContext *ic, MSymbol key, void *arg, MText *mt)
+{
+  MInputGUIContextInfo *win_ic_info = (MInputGUIContextInfo *) ic->info;
+  MInputContextInfo *ic_info = (MInputContextInfo *) win_ic_info->ic_info;
+  int ret;
+
+  ic->info = ic_info;
+  ret = (*minput_default_driver.lookup) (ic, key, arg, mt);
+  ic->info = win_ic_info;
+  return ret;
+}
+
+\f
+
+int
+minput__win_init ()
+{
+  minput_gui_driver = minput_default_driver;
+
+  minput_gui_driver.create_ic = win_create_ic;
+  minput_gui_driver.destroy_ic = win_destroy_ic;
+  minput_gui_driver.filter = win_filter;
+  minput_gui_driver.lookup = win_lookup;
+  {
+    MPlist *plist = mplist ();
+
+    minput_gui_driver.callback_list = plist;
+    mplist_put_func (plist, Minput_preedit_start, M17N_FUNC (win_callback));
+    mplist_put_func (plist, Minput_preedit_draw, M17N_FUNC (win_callback));
+    mplist_put_func (plist, Minput_preedit_done, M17N_FUNC (win_callback));
+    mplist_put_func (plist, Minput_status_start, M17N_FUNC (win_callback));
+    mplist_put_func (plist, Minput_status_draw, M17N_FUNC (win_callback));
+    mplist_put_func (plist, Minput_status_done, M17N_FUNC (win_callback));
+    mplist_put_func (plist, Minput_candidates_start, M17N_FUNC (win_callback));
+    mplist_put_func (plist, Minput_candidates_draw, M17N_FUNC (win_callback));
+    mplist_put_func (plist, Minput_candidates_done, M17N_FUNC (win_callback));
+    mplist_put_func (plist, Minput_set_spot, M17N_FUNC (win_callback));
+    mplist_put_func (plist, Minput_toggle, M17N_FUNC (win_callback));
+    mplist_put_func (plist, Minput_reset, M17N_FUNC (win_callback));
+  }
+#if 0
+  /* This will make the caller of minput_method_open() pazzled.  */
+  minput_driver = &minput_gui_driver;
+#endif
+
+  face_box_prop.width = 1;
+  face_box_prop.color_top = face_box_prop.color_left
+    = face_box_prop.color_bottom = face_box_prop.color_right
+    = msymbol ("black");
+  face_box_prop.inner_hmargin = face_box_prop.inner_vmargin = 2;
+  face_box_prop.outer_hmargin = face_box_prop.outer_vmargin = 1;
+  status_face = mface ();
+  mface_put_prop (status_face, Mbox, &face_box_prop);
+
+  return 0;
+}
+
+void
+minput__win_fini ()
+{
+  M17N_OBJECT_UNREF (status_face);
+  if (minput_gui_driver.callback_list)
+    {
+      M17N_OBJECT_UNREF (minput_gui_driver.callback_list);
+      minput_gui_driver.callback_list = NULL;
+    }
+}
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+/* External API */
+
+/*** @addtogroup m17nInputMethodWin */
+/*** @{ */
+
+/*=*/
+/***en
+    @brief Input driver for internal input methods on window systems.
+
+    The input driver @c minput_gui_driver is for internal input
+    methods to be used on window systems.
+
+    It creates sub-windows for a preedit text and a status text, and
+    displays them at the input spot set by the function
+    minput_set_spot ().
+
+    The macro M17N_INIT () set the variable @c minput_driver to the
+    pointer to this driver so that all internal input methods use it.
+
+    Therefore, unless @c minput_driver is changed from the default,
+    the driver dependent arguments to the functions whose name begin
+    with minput_ must are treated as follows.
+
+    The argument $ARG of the function minput_open_im () is ignored.
+
+    The argument $ARG of the function minput_create_ic () must be a
+    pointer to the structure @c MInputGUIArgIC.  See the documentation
+    of @c MInputGUIArgIC for more details.
+
+    If the argument $KEY of function minput_filter () is @c Mnil, the
+    argument $ARG must be a pointer to the object of type @c XEvent.
+    In that case, $KEY is generated from $ARG.
+
+    The argument $ARG of the function minput_lookup () must be the
+    same one as that of the function minput_filter (). */
+
+/***ja
+    @brief ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤ÎÆâÉôÆþÎϥ᥽¥Ã¥ÉÍÑÆþÎϥɥ饤¥Ð.
+
+    ÆþÎϥɥ饤¥Ð @c minput_gui_driver
+    ¤Ï¡¢¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¾å¤ÇÍѤ¤¤é¤ì¤ëÆþÎϥ᥽¥Ã¥ÉÍѥɥ饤¥Ð¤Ç¤¢¤ë¡£
+
+    ¤³¤Î¥É¥é¥¤¥Ð¤Ï¡¢´Ø¿ô minput_set_spot () ¤Ë¤è¤Ã¤ÆÀßÄꤵ¤ì¤¿ÆþÎÏ¥¹¥Ý¥Ã¥È¤Ë
+    preedit ¥Æ¥­¥¹¥ÈÍѤΥµ¥Ö¥¦¥£¥ó¥É¥¦¤È status 
+    ¥Æ¥­¥¹¥ÈÍѤΥµ¥Ö¥¦¥£¥ó¥É¥¦¤òºî¤ê¡¢¤½¤ì¤¾¤ì¤òɽ¼¨¤¹¤ë¡£
+
+    ¥Þ¥¯¥í M17N_INIT () ¤ÏÊÑ¿ô @c minput_driver 
+    ¤ò¤³¤Î¥É¥é¥¤¥Ð¤Ø¤Î¥Ý¥¤¥ó¥¿¤ËÀßÄꤷ¡¢Á´¤Æ¤ÎÆâÉôÆþÎϥ᥽¥Ã¥É¤¬¤³¤Î¥É¥é¥¤¥Ð¤ò»È¤¦¤è¤¦¤Ë¤¹¤ë¡£
+
+    ¤·¤¿¤¬¤Ã¤Æ¡¢@c minput_driver ¤¬¥Ç¥Õ¥©¥ë¥ÈÃͤΤޤޤǤ¢¤ì¤Ð¡¢minput_ 
+    ¤Ç»Ï¤Þ¤ë̾Á°¤ò»ý¤Ä´Ø¿ô¤Î°ú¿ô¤Î¤¦¤Á¥É¥é¥¤¥Ð°Í¸¤Î¤â¤Î¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤Ê¤ë¡£
+
+    ´Ø¿ô minput_open_im () ¤Î°ú¿ô $ARG ¤Ï̵»ë¤µ¤ì¤ë¡£
+
+    ´Ø¿ô minput_create_ic () ¤Î°ú¿ô $ARG ¤Ï¹½Â¤ÂΠ@c MInputGUIArgIC 
+    ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï @c MInputGUIArgIC 
+    ¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£
+
+    ´Ø¿ô minput_filter () ¤Î°ú¿ô $ARG ¤¬ @c Mnil ¤Î¾ì¹ç¡¢ $ARG ¤Ï @c
+    XEvent ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤³¤Î¾ì¹ç 
+    $KEY ¤Ï $ARG ¤«¤éÀ¸À®¤µ¤ì¤ë¡£
+
+    ´Ø¿ô minput_lookup () ¤Î°ú¿ô $ARG ¤Ï´Ø¿ô minput_filter () ¤Î°ú¿ô 
+    $ARG ¤ÈƱ¤¸¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£ */
+
+MInputDriver minput_gui_driver;
+
+/*=*/
+
+/***en
+    @brief Symbol of the name "xim".
+
+    The variable Mxim is a symbol of name "xim".  It is a name of the
+    input method driver #minput_xim_driver.  */ 
+/***ja
+    @brief "xim"¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë .
+
+    ÊÑ¿ô Mxim ¤Ï"xim"¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£"xim" 
+    ¤ÏÆþÎϥ᥽¥Ã¥É¥É¥é¥¤¥Ð #minput_xim_driver ¤Î̾Á°¤Ç¤¢¤ë¡£  */ 
+
+MSymbol Mxim;
+
+/*=*/
+
+/***en
+    @brief Convert an event to an input key.
+
+    The minput_event_to_key () function returns the input key
+    corresponding to event $EVENT on $FRAME by a window system
+    dependent manner.
+
+    In the m17n-X library, $EVENT must be a pointer to the structure
+    @c XKeyEvent, and it is handled as below.
+
+    At first, the keysym name of $EVENT is acquired by the function @c
+    XKeysymToString.  Then, the name is modified as below.
+
+    If the name is one of "a" .. "z" and $EVENT has a Shift modifier,
+    the name is converted to "A" .. "Z" respectively, and the Shift
+    modifier is cleared.
+
+    If the name is one byte length and $EVENT has a Control modifier,
+    the byte is bitwise anded by 0x1F and the Control modifier is
+    cleared.
+
+    If $EVENT still has modifiers, the name is preceded by "S-"
+    (Shift), "C-" (Control), "M-" (Meta), "A-" (Alt), "s-" (Super),
+    and/or "H-" (Hyper) in this order.
+
+    For instance, if the keysym name is "a" and the event has Shift,
+    Meta, and Hyper modifiers, the resulting name is "M-H-A".
+
+    At last, a symbol who has the name is returned.  */
+
+/***ja
+    @brief ¥¤¥Ù¥ó¥È¤òÆþÎÏ¥­¡¼¤ËÊÑ´¹¤¹¤ë.
+
+    ´Ø¿ô minput_event_to_key () ¤Ï¡¢$FRAME ¤Î¥¤¥Ù¥ó¥È $EVENT 
+    ¤ËÂбþ¤¹¤ëÆþÎÏ¥­¡¼¤òÊÖ¤¹¡£¤³¤³¤Ç¤Î¡ÖÂбþ¡×¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡£
+
+    m17n-X ¥é¥¤¥Ö¥é¥ê¤Î¾ì¹ç¤Ë¤Ï¡¢$EVENT ¤Ï ¹½Â¤ÂΠ@c XKeyEvent 
+    ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ê¡¢¼¡¤Î¤è¤¦¤Ë½èÍý¤µ¤ì¤ë¡£
+
+    ¤Þ¤º¡¢´Ø¿ô @c XKeysymToString ¤Ë¤è¤Ã¤Æ¡¢$EVENT ¤Î keysym 
+    Ì¾¤ò¼èÆÀ¤·¡¢¼¡¤¤¤Ç°Ê²¼¤ÎÊѹ¹¤ò²Ã¤¨¤ë¡£
+
+    Ì¾Á°¤¬ "a" .. "z" ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤Ã¤Æ $EVENT ¤Ë Shift 
+    ¥â¥Ç¥£¥Õ¥¡¥¤¥¢¤¬¤¢¤ì¤Ð¡¢Ì¾Á°¤Ï¤½¤ì¤¾¤ì "A" .. "Z" ¤ËÊÑ´¹¤µ¤ì¡¢Shift 
+    ¥â¥Ç¥£¥Õ¥¡¥¤¥¢¤Ï¼è¤ê½ü¤«¤ì¤ë¡£
+
+    Ì¾Á°¤¬£±¥Ð¥¤¥ÈŤǠ$EVENT ¤Ë Control ¥â¥Ç¥£¥Õ¥¡¥¤¥¢¤¬¤¢¤ì¤Ð¡¢Ì¾Á°¤È
+    0x1F ¤È¤ò¥Ó¥Ã¥Èñ°Ì¤Ç and ±é»»¤·¡¢Control ¥â¥Ç¥£¥Õ¥¡¥¤¥¢¤Ï¼è¤ê½ü¤«¤ì¤ë¡£
+
+    ¤½¤ì¤Ç¤â $EVENT ¤Ë¤Þ¤À¥â¥Ç¥£¥Õ¥¡¥¤¥¢¤¬¤¢¤ì¤Ð¡¢Ì¾Á°¤ÎÁ°¤Ë¤½¤ì¤¾¤ì
+    "S-" (Shift), "C-" (Control), "M-" (Meta), "A-" (Alt), "s-"
+    (Super), "H-" (Hyper)¤¬¤³¤Î½çÈÖ¤ÇÉÕ¤¯¡£
+    
+    ¤¿¤È¤¨¤Ð¡¢keysym Ì¾¤¬ "a" ¤Ç¥¤¥Ù¥ó¥È¤¬ Shift, Meta, and Hyper 
+    ¥â¥Ç¥£¥Õ¥¡¥¤¥¢¤ò»ý¤Æ¤Ð¡¢ÆÀ¤é¤ì¤ë̾Á°¤Ï "M-H-A" ¤Ç¤¢¤ë¡£
+
+    ºÇ¸å¤Ë¤½¤Î̾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤òÊÖ¤¹¡£*/
+
+
+MSymbol
+minput_event_to_key (MFrame *frame, void *event)
+{
+  int modifiers;
+  MSymbol key;
+  char *name, *str;
+
+  M_CHECK_READABLE (frame, MERROR_IM, Mnil);
+  key = (*frame->driver->parse_event) (frame, event, &modifiers);
+  if (! modifiers)
+    return key;
+
+  name = msymbol_name (key);
+  str = alloca (strlen (name) + 2 * 6 + 1);
+  str[0] = '\0';
+  if (modifiers & MINPUT_KEY_SHIFT_MODIFIER)
+    strcat (str, "S-");
+  if (modifiers & MINPUT_KEY_CONTROL_MODIFIER)
+    strcat (str, "C-");
+  if (modifiers & MINPUT_KEY_META_MODIFIER)
+    strcat (str, "M-");
+  if (modifiers & MINPUT_KEY_ALT_MODIFIER)
+    strcat (str, "A-");
+  if (modifiers & MINPUT_KEY_SUPER_MODIFIER)
+    strcat (str, "s-");
+  if (modifiers & MINPUT_KEY_HYPER_MODIFIER)
+    strcat (str, "H-");
+  strcat (str, name);
+
+  return msymbol (str);
+}
+
+/*** @} */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/input.c b/src/input.c
new file mode 100644 (file)
index 0000000..6fbd21d
--- /dev/null
@@ -0,0 +1,6396 @@
+/* input.c -- input method module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nInputMethod
+    @brief API for Input method.
+
+    An input method is an object to enable inputting various
+    characters.  An input method is identified by a pair of symbols,
+    LANGUAGE and NAME.  This pair decides an input method driver of the
+    input method.  An input method driver is a set of functions for
+    handling the input method.  There are two kinds of input methods;
+    internal one and foreign one.
+
+    <ul>
+    <li> Internal Input Method
+
+    An internal input method has non @c Mnil LANGUAGE, and its body is
+    defined in the m17n database by the tag <Minput_method, LANGUAGE,
+    NAME>.  For this kind of input methods, the m17n library uses two
+    predefined input method drivers, one for CUI use and the other for
+    GUI use.  Those drivers utilize the input processing engine
+    provided by the m17n library itself.  The m17n database may
+    provide input methods that are not limited to a specific language.
+    The database uses @c Mt as LANGUAGE of those input methods.
+
+    An internal input method accepts an input key which is a symbol
+    associated with an input event.  As there is no way for the @c
+    m17n @c library to know how input events are represented in an
+    application program, an application programmer has to convert an
+    input event to an input key by himself.  See the documentation of
+    the function minput_event_to_key () for the detail.
+
+    <li> Foreign Input Method @anchor foreign-input-method
+
+    A foreign input method has @c Mnil LANGUAGE, and its body is
+    defined in an external resource (e.g. XIM of X Window System).
+    For this kind of input methods, the symbol NAME must have a
+    property of key #Minput_driver, and the value must be a pointer
+    to an input method driver.  Therefore, by preparing a proper
+    driver, any kind of input method can be treated in the framework
+    of the @c m17n @c library.
+
+    For convenience, the m17n-X library provides an input method
+    driver that enables the input style of OverTheSpot for XIM, and
+    stores #Minput_driver property of the symbol @c Mxim with a
+    pointer to the driver.  See the documentation of m17n GUI API for
+    the detail.
+
+    </ul>
+
+    PROCESSING FLOW
+
+    The typical processing flow of handling an input method is: 
+
+     @li open an input method
+     @li create an input context for the input method
+     @li filter an input key
+     @li look up a produced text in the input context  */
+
+/*=*/
+/***ja
+    @addtogroup m17nInputMethod
+    @brief ÆþÎϥ᥽¥Ã¥ÉÍÑAPI.
+
+    ÆþÎϥ᥽¥Ã¥É¤Ï¿ÍͤÊʸ»ú¤òÆþÎϤ¹¤ë¤¿¤á¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë¡£
+    ÆþÎϥ᥽¥Ã¥É¤Ï¥·¥ó¥Ü¥ë LANGUAGE ¤È NAME ¤ÎÁȤˤè¤Ã¤Æ¼±Ê̤µ¤ì¡¢
+    ¤³¤ÎÁȹ礻¤Ë¤è¤Ã¤ÆÆþÎϥ᥽¥Ã¥É¥É¥é¥¤¥Ð¤¬·èÄꤹ¤ë¡£
+    ÆþÎϥ᥽¥Ã¥É¥É¥é¥¤¥Ð¤È¤Ï¡¢¤¢¤ëÆþÎϥ᥽¥Ã¥É¤ò°·¤¦¤¿¤á¤Î´Ø¿ô¤Î½¸¤Þ¤ê¤Ç¤¢¤ë¡£
+    ÆþÎϥ᥽¥Ã¥É¤Ë¤ÏÆâÉô¥á¥½¥Ã¥É¤È³°Éô¥á¥½¥Ã¥É¤ÎÆó¼ïÎब¤¢¤ë¡£
+
+    <ul> 
+    <li> ÆâÉôÆþÎϥ᥽¥Ã¥É
+
+    ÆâÉôÆþÎϥ᥽¥Ã¥É¤È¤Ï LANGUAGE ¤¬ @c Mnil °Ê³°¤Î¤â¤Î¤Ç¤¢¤ê¡¢¤½¤ÎËÜÂÎ
+    ¤Ïm17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë<Minput_method, LANGUAGE, NAME> ¤È¤¤¤¦¥¿¥°¤òÉÕ
+    ¤±¤ÆÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£¤³¤Î¼ï¤ÎÆþÎϥ᥽¥Ã¥É¤ËÂФ·¤Æ¡¢m17n ¥é¥¤¥Ö¥é¥ê¤Ç
+    ¤ÏCUI ÍѤȠGUI ÍѤ½¤ì¤¾¤ì¤ÎÆþÎϥ᥽¥Ã¥É¥É¥é¥¤¥Ð¤ò¤¢¤é¤«¤¸¤áÄêµÁ¤·¤Æ
+    ¤¤¤ë¡£¤³¤ì¤é¤Î¥É¥é¥¤¥Ð¤Ï m17n ¥é¥¤¥Ö¥é¥ê¼«ÂΤÎÆþÎϽèÍý¥¨¥ó¥¸¥ó¤òÍø
+    ÍѤ¹¤ë¡£m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë¤Ï¡¢ÆÃÄê¤Î¸À¸ìÀìÍѤǤʤ¤ÆþÎϥ᥽¥Ã¥É¤òÄê
+    µÁ¤¹¤ë¤³¤È¤â¤Ç¤­¡¢¤½¤Î¤è¤¦¤ÊÆþÎϥ᥽¥Ã¥É¤Î LANGUAGE ¤Ï @c Mt ¤Ç¤¢¤ë¡£
+
+    ÆâÉôÆþÎϥ᥽¥Ã¥É¤Ï¡¢¥æ¡¼¥¶¤ÎÆþÎÏ¥¤¥Ù¥ó¥È¤ËÂбþ¤·¤¿¥·¥ó¥Ü¥ë¤Ç¤¢¤ëÆþ
+    ÎÏ¥­¡¼¤ò¼õ¤±¼è¤ë¡£@c m17n @c ¥é¥¤¥Ö¥é¥ê ¤ÏÆþÎÏ¥¤¥Ù¥ó¥È¤¬¥¢¥×¥ê¥±¡¼
+    ¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ç¤É¤¦É½¸½¤µ¤ì¤Æ¤¤¤ë¤«¤òÃΤ뤳¤È¤¬¤Ç¤­¤Ê¤¤¤Î¤Ç¡¢Æþ
+    ÎÏ¥¤¥Ù¥ó¥È¤«¤éÆþÎÏ¥­¡¼¤Ø¤ÎÊÑ´¹¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥Þ¤ÎÀÕǤ¤Ç
+    ¹Ô¤ï¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï´Ø¿ô minput_event_to_key () ¤Î
+    ÀâÌÀ¤ò»²¾È¡£
+
+    <li> ³°ÉôÆþÎϥ᥽¥Ã¥É @anchor foreign-input-method
+
+    ³°ÉôÆþÎϥ᥽¥Ã¥É¤È¤Ï LANGUAGE ¤¬ @c Mnil ¤Î¤â¤Î¤Ç¤¢¤ê¡¢¤½¤ÎËÜÂΤϳ°
+    Éô¤Î¥ê¥½¡¼¥¹¤È¤·¤ÆÄêµÁ¤µ¤ì¤ë¡£¡Ê¤¿¤È¤¨¤ÐX Window System ¤ÎXIM ¤Ê
+    ¤É¡£) ¤³¤Î¼ï¤ÎÆþÎϥ᥽¥Ã¥É¤Ç¤Ï¡¢¥·¥ó¥Ü¥ë NAME ¤Ï #Minput_driver ¤ò
+    ¥­¡¼¤È¤¹¤ë¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Á¡¢¤½¤ÎÃͤÏÆþÎϥ᥽¥Ã¥É¥É¥é¥¤¥Ð¤Ø¤Î¥Ý¥¤¥ó
+    ¥¿¤Ç¤¢¤ë¡£¤³¤Î¤³¤È¤Ë¤è¤ê¡¢Å¬Àڤʥɥ饤¥Ð¤ò½àÈ÷¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¡¢¤¤
+    ¤«¤Ê¤ë¼ïÎà¤ÎÆþÎϥ᥽¥Ã¥É¤â@c m17n @c ¥é¥¤¥Ö¥é¥ê ¤ÎÏÈÁȤÎÃæ¤Ç°·¤¦»ö
+    ¤¬¤Ç¤­¤ë¡£
+
+    ÍøÊØÀ­¤Î´ÑÅÀ¤«¤é¡¢m17n X ¥é¥¤¥Ö¥é¥ê¤Ï XIM ¤Î OverTheSpot ¤ÎÆþÎÏ¥¹¥¿
+    ¥¤¥ë¤ò¼Â¸½¤¹¤ëÆþÎϥ᥽¥Ã¥É¥É¥é¥¤¥Ð¤òÄ󶡤·¡¢¤Þ¤¿¥·¥ó¥Ü¥ë @c Mxim ¤Î
+    #Minput_driver ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤȤ·¤Æ¤½¤Î¥É¥é¥¤¥Ð¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÝ»ý
+    ¤·¤Æ¤¤¤ë¡£¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï m17n GUI API ¤Î¥É¥­¥å¥á¥ó¥È¤ò»²¾È¤Î¤³¤È¡£
+
+    </ul> 
+
+    ½èÍý¤Îή¤ì
+
+    ÆþÎϥ᥽¥Ã¥É½èÍý¤Îŵ·¿Åª¤Ê½èÍý¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤Ê¤ë¡£
+    
+    @li ÆþÎϥ᥽¥Ã¥É¤Î¥ª¡¼¥×¥ó
+    @li ¤½¤ÎÆþÎϥ᥽¥Ã¥É¤ÎÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤ÎÀ¸À®
+    @li ÆþÎÏ¥¤¥Ù¥ó¥È¤Î¥Õ¥£¥ë¥¿
+    @li ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤Ç¤ÎÀ¸À®¥Æ¥­¥¹¥È¤Î¸¡º÷     */
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <time.h>
+
+#include "config.h"
+
+#ifdef HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include "m17n.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "mtext.h"
+#include "input.h"
+#include "symbol.h"
+#include "plist.h"
+#include "database.h"
+#include "charset.h"
+
+static int mdebug_flag = MDEBUG_INPUT;
+
+static int fully_initialized;
+
+/** Symbols to load an input method data.  */
+static MSymbol Mtitle, Mmacro, Mmodule, Mstate, Minclude;
+
+/** Symbols for actions.  */
+static MSymbol Minsert, Mdelete, Mmark, Mmove, Mpushback, Mundo, Mcall, Mshift;
+static MSymbol Mselect, Mshow, Mhide, Mcommit, Munhandle, Mpop;
+static MSymbol Mset, Madd, Msub, Mmul, Mdiv, Mequal, Mless, Mgreater;
+static MSymbol Mless_equal, Mgreater_equal;
+static MSymbol Mcond;
+static MSymbol Mplus, Mminus, Mstar, Mslash, Mand, Mor, Mnot;
+
+/** Special action symbol.  */
+static MSymbol Mat_reload;
+
+static MSymbol M_candidates;
+
+static MSymbol Mcandidate_list, Mcandidate_index;
+
+static MSymbol Minit, Mfini;
+
+/** Symbols for variables.  */
+static MSymbol Mcandidates_group_size, Mcandidates_charset;
+
+/** Symbols for key events.  */
+static MSymbol one_char_symbol[256];
+
+static MSymbol M_key_alias;
+
+static MSymbol Mdescription, Mcommand, Mvariable, Mglobal, Mconfig;
+
+static MSymbol M_gettext;
+
+/** Structure to hold a map.  */
+
+struct MIMMap
+{
+  /** List of actions to take when we reach the map.  In a root map,
+      the actions are executed only when there is no more key.  */
+  MPlist *map_actions;
+
+  /** List of deeper maps.  If NULL, this is a terminal map.  */
+  MPlist *submaps;
+
+  /** List of actions to take when we leave the map successfully.  In
+      a root map, the actions are executed only when none of submaps
+      handle the current key.  */
+  MPlist *branch_actions;
+};
+
+typedef MPlist *(*MIMExternalFunc) (MPlist *plist);
+
+typedef struct
+{
+  void *handle;
+  MPlist *func_list;           /* function name vs (MIMExternalFunc *) */
+} MIMExternalModule;
+
+struct MIMState
+{
+  M17NObject control;
+
+  /** Name of the state.  */
+  MSymbol name;
+
+  /** Title of the state, or NULL.  */
+  MText *title;
+
+  /** Key translation map of the state.  Built by merging all maps of
+      branches.  */
+  MIMMap *map;
+};
+
+#define CUSTOM_FILE "config.mic"
+
+static MPlist *load_im_info_keys;
+
+/* List of input method information.  The format is:
+     (LANGUAGE NAME t:IM_INFO ... ... ...)  */
+static MPlist *im_info_list;
+
+/* Database for user's customization file.  */
+static MDatabase *im_custom_mdb;
+
+/* List of input method information loaded from im_custom_mdb.  The
+   format is the same as im_info_list.  */
+static MPlist *im_custom_list;
+
+/* List of input method information configured by
+   minput_config_command and minput_config_variable.  The format is
+   the same as im_info_list.  */
+static MPlist *im_config_list;
+
+/* Global input method information.  It points into the element of
+   im_info_list corresponding to LANGUAGE == `nil' and NAME ==
+   `global'.  */
+static MInputMethodInfo *global_info;
+
+static int update_global_info (void);
+static int update_custom_info (void);
+static MInputMethodInfo *get_im_info (MSymbol, MSymbol, MSymbol, MSymbol);
+
+\f
+void
+fully_initialize ()
+{
+  char *key_names[32]
+    = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+       "BackSpace", "Tab", "Linefeed", "Clear", NULL, "Return", NULL, NULL,
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+       NULL, NULL, NULL, "Escape", NULL, NULL, NULL, NULL };
+  char buf[6], buf2[32], buf3[2];
+  int i, j;
+  /* Maximum case: '\215', C-M-m, C-M-M, M-Return, C-A-m, C-A-M, A-Return
+     plus one for cyclic alias.  */
+  MSymbol alias[8];
+
+  M_key_alias = msymbol ("  key-alias");
+
+  buf3[1] = '\0';
+
+  /* Aliases for 0x00-0x1F */
+  buf[0] = 'C';
+  buf[1] = '-';
+  buf[3] = '\0';
+  for (i = 0, buf[2] = '@'; i < ' '; i++, buf[2]++)
+    {
+      j = 0;
+      buf3[0] = i;
+      alias[j++] = msymbol (buf3);
+      alias[j++] = one_char_symbol[i] = msymbol (buf);
+      if (key_names[i] || (buf[2] >= 'A' && buf[2] <= 'Z'))
+       {
+         if (key_names[i])
+           {
+             /* Ex: `Escape' == `C-['  */
+             alias[j++] = msymbol (key_names[i]);
+           }
+         if (buf[2] >= 'A' && buf[2] <= 'Z')
+           {
+             /* Ex: `C-a' == `C-A'  */
+             buf[2] += 32;
+             alias[j++] = msymbol (buf);
+             buf[2] -= 32;
+           }
+       }
+      /* Establish cyclic alias chain.  */
+      alias[j] = alias[0];
+      while (--j >= 0)
+       msymbol_put (alias[j], M_key_alias, alias[j + 1]);
+    }
+
+  /* Aliases for 0x20-0x7E */
+  buf[0] = 'S';
+  for (i = buf[2] = ' '; i < 127; i++, buf[2]++)
+    {
+      one_char_symbol[i] = msymbol (buf + 2);
+      if (i >= 'A' && i <= 'Z')
+       {
+         /* Ex: `A' == `S-A' == `S-a'.  */
+         alias[0] = alias[3] = one_char_symbol[i];
+         alias[1] = msymbol (buf);
+         buf[2] += 32;
+         alias[2] = msymbol (buf);
+         buf[2] -= 32;
+         for (j = 0; j < 3; j++)
+           msymbol_put (alias[j], M_key_alias, alias[j + 1]);
+       }
+    }
+
+  /* Aliases for 0x7F */
+  buf3[0] = 0x7F;
+  alias[0] = alias[3] = msymbol (buf3);
+  alias[1] = one_char_symbol[127] = msymbol ("Delete");
+  alias[2] = msymbol ("C-?");
+  for (j = 0; j < 3; j++)
+    msymbol_put (alias[j], M_key_alias, alias[j + 1]);
+
+  /* Aliases for 0x80-0x9F */
+  buf[0] = 'C';
+  /* buf[1] = '-'; -- already done */
+  buf[3] = '-';
+  buf[5] = '\0';
+  buf2[1] = '-';
+  for (i = 128, buf[4] = '@'; i < 160; i++, buf[4]++)
+    {
+      j = 0;
+      buf3[0] = i;
+      alias[j++] = msymbol (buf3);
+      /* `C-M-a' == `C-A-a' */
+      buf[2] = 'M';
+      alias[j++] = one_char_symbol[i] = msymbol (buf);
+      buf[2] = 'A';
+      alias[j++] = msymbol (buf);
+      if (key_names[i - 128])
+       {
+         /* Ex: `M-Escape' == `A-Escape' == `C-M-['.  */
+         buf2[0] = 'M';
+         strcpy (buf2 + 2, key_names[i - 128]);
+         alias[j++] = msymbol (buf2);
+         buf2[0] = 'A';
+         alias[j++] = msymbol (buf2);
+       }
+      if (buf[4] >= 'A' && buf[4] <= 'Z')
+       {
+         /* Ex: `C-M-a' == `C-M-A'.  */
+         buf[4] += 32;
+         buf[2] = 'M';
+         alias[j++] = msymbol (buf);
+         buf[2] = 'A';
+         alias[j++] = msymbol (buf);
+         buf[4] -= 32;
+       }
+
+      /* Establish cyclic alias chain.  */
+      alias[j] = alias[0];
+      while (--j >= 0)
+       msymbol_put (alias[j], M_key_alias, alias[j + 1]);
+    }
+
+  /* Aliases for 0xA0-0xFF */
+  for (i = 160, buf[4] = ' '; i < 255; i++, buf[4]++)
+    {
+      j = 0;
+      buf3[0] = i;
+      alias[j++] = msymbol (buf3);
+      buf[2] = 'M';
+      alias[j++] = one_char_symbol[i] = msymbol (buf + 2);
+      buf[2] = 'A';
+      alias[j++] = msymbol (buf + 2);
+      alias[j]= alias[0];
+      while (--j >= 0)
+       msymbol_put (alias[j], M_key_alias, alias[j + 1]);
+    }
+
+  buf3[0] = 255;
+  alias[0] = alias[3] = msymbol (buf3);
+  alias[1] = one_char_symbol[255] = msymbol ("M-Delete");
+  alias[2] = msymbol ("A-Delete");
+  for (j = 0; j < 3; j++)
+    msymbol_put (alias[j], M_key_alias, alias[j + 1]);
+
+  /* Aliases for keys that can't be mapped to one-char-symbol
+     (e.g. C-A-1) */
+  /* buf is already set to "C-?-".  */
+  for (i = ' '; i <= '~'; i++)
+    {
+      if (i == '@')
+       {
+         i = '_';
+         continue;
+       }
+      if (i == 'a')
+       {
+         i = 'z';
+         continue;
+       }
+      buf[2] = 'M';
+      buf[4] = i;
+      alias[0] = alias[2] = msymbol (buf);
+      buf[2] = 'A';
+      alias[1] = msymbol (buf);
+      for (j = 0; j < 2; j++)
+       msymbol_put (alias[j], M_key_alias, alias[j + 1]);
+    }
+
+  Minput_method = msymbol ("input-method");
+  Mtitle = msymbol ("title");
+  Mmacro = msymbol ("macro");
+  Mmodule = msymbol ("module");
+  Mmap = msymbol ("map");
+  Mstate = msymbol ("state");
+  Minclude = msymbol ("include");
+  Minsert = msymbol ("insert");
+  M_candidates = msymbol ("  candidates");
+  Mdelete = msymbol ("delete");
+  Mmove = msymbol ("move");
+  Mmark = msymbol ("mark");
+  Mpushback = msymbol ("pushback");
+  Mpop = msymbol ("pop");
+  Mundo = msymbol ("undo");
+  Mcall = msymbol ("call");
+  Mshift = msymbol ("shift");
+  Mselect = msymbol ("select");
+  Mshow = msymbol ("show");
+  Mhide = msymbol ("hide");
+  Mcommit = msymbol ("commit");
+  Munhandle = msymbol ("unhandle");
+  Mset = msymbol ("set");
+  Madd = msymbol ("add");
+  Msub = msymbol ("sub");
+  Mmul = msymbol ("mul");
+  Mdiv = msymbol ("div");
+  Mequal = msymbol ("=");
+  Mless = msymbol ("<");
+  Mgreater = msymbol (">");
+  Mless_equal = msymbol ("<=");
+  Mgreater_equal = msymbol (">=");
+  Mcond = msymbol ("cond");
+  Mplus = msymbol ("+");
+  Mminus = msymbol ("-");
+  Mstar = msymbol ("*");
+  Mslash = msymbol ("/");
+  Mand = msymbol ("&");
+  Mor = msymbol ("|");
+  Mnot = msymbol ("!");
+
+  Mat_reload = msymbol ("-reload");
+
+  Mcandidates_group_size = msymbol ("candidates-group-size");
+  Mcandidates_charset = msymbol ("candidates-charset");
+
+  Mcandidate_list = msymbol_as_managing_key ("  candidate-list");
+  Mcandidate_index = msymbol ("  candidate-index");
+
+  Minit = msymbol ("init");
+  Mfini = msymbol ("fini");
+
+  Mdescription = msymbol ("description");
+  Mcommand = msymbol ("command");
+  Mvariable = msymbol ("variable");
+  Mglobal = msymbol ("global");
+  Mconfig = msymbol ("config");
+  M_gettext = msymbol ("_");
+
+  load_im_info_keys = mplist ();
+  mplist_add (load_im_info_keys, Mstate, Mnil);
+  mplist_push (load_im_info_keys, Mmap, Mnil);
+
+  im_info_list = mplist ();
+  im_config_list = im_custom_list = NULL;
+  im_custom_mdb = NULL;
+  update_custom_info ();
+  global_info = NULL;
+  update_global_info ();
+
+  fully_initialized = 1;
+}
+
+#define MINPUT__INIT()         \
+  do {                         \
+    if (! fully_initialized)   \
+      fully_initialize ();     \
+  } while (0)
+
+\f
+static int
+marker_code (MSymbol sym, int surrounding)
+{
+  char *name;
+
+  if (sym == Mnil)
+    return -1;
+  name = MSYMBOL_NAME (sym);
+  return (name[0] != '@' ? -1
+         : (((name[1] >= '0' && name[1] <= '9')
+             || name[1] == '<' || name[1] == '>' || name[1] == '='
+             || name[1] == '[' || name[1] == ']'
+             || name[1] == '@')
+            && name[2] == '\0') ? name[1]
+         : (name[1] != '+' && name[1] != '-') ? -1
+         : (name[2] == '\0' || surrounding) ? name[1]
+         : -1);
+}
+
+
+/* Return a plist containing an integer value of VAR.  The plist must
+   not be UNREFed. */
+
+static MPlist *
+resolve_variable (MInputContextInfo *ic_info, MSymbol var)
+{
+  MPlist *plist = mplist__assq (ic_info->vars, var);
+
+  if (plist)
+    {
+      plist = MPLIST_PLIST (plist);
+      return MPLIST_NEXT (plist);
+    }
+
+  plist = mplist ();
+  mplist_push (ic_info->vars, Mplist, plist);
+  M17N_OBJECT_UNREF (plist);
+  plist = mplist_add (plist, Msymbol, var);
+  plist = mplist_add (plist, Minteger, (void *) 0);
+  return plist;
+}
+
+static MText *
+get_surrounding_text (MInputContext *ic, int len)
+{
+  MText *mt = NULL;
+
+  mplist_push (ic->plist, Minteger, (void *) len);
+  if (minput_callback (ic, Minput_get_surrounding_text) >= 0
+      && MPLIST_MTEXT_P (ic->plist))
+    mt = MPLIST_MTEXT (ic->plist);
+  mplist_pop (ic->plist);
+  return mt;
+}
+
+static void
+delete_surrounding_text (MInputContext *ic, int pos)
+{
+  MInputContextInfo *ic_info = (MInputContextInfo *) ic->info;
+
+  mplist_push (ic->plist, Minteger, (void *) pos);
+  minput_callback (ic, Minput_delete_surrounding_text);
+  mplist_pop (ic->plist);
+  if (pos < 0)
+    {
+      M17N_OBJECT_UNREF (ic_info->preceding_text);
+      ic_info->preceding_text = NULL;
+    }
+  else if (pos > 0)
+    {
+      M17N_OBJECT_UNREF (ic_info->following_text);
+      ic_info->following_text = NULL;
+    }
+}
+
+static int
+get_preceding_char (MInputContext *ic, int pos)
+{
+  MInputContextInfo *ic_info = (MInputContextInfo *) ic->info;
+  MText *mt;
+  int len;
+
+  if (pos && ic_info->preceding_text)
+    {
+      len = mtext_nchars (ic_info->preceding_text);
+      if (pos <= len)
+       return mtext_ref_char (ic_info->preceding_text, len - pos);
+    }
+  mt = get_surrounding_text (ic, - pos);
+  if (! mt)
+    return -2;
+  len = mtext_nchars (mt);
+  if (ic_info->preceding_text)
+    {
+      if (mtext_nchars (ic_info->preceding_text) < len)
+       {
+         M17N_OBJECT_UNREF (ic_info->preceding_text);
+         ic_info->preceding_text = mt;
+       }
+      else
+       M17N_OBJECT_UNREF (mt);
+    }
+  else
+    ic_info->preceding_text = mt;
+  if (pos > len)
+    return -1;
+  return mtext_ref_char (ic_info->preceding_text, len - pos);
+}
+
+static int
+get_following_char (MInputContext *ic, int pos)
+{
+  MInputContextInfo *ic_info = (MInputContextInfo *) ic->info;
+  MText *mt;
+  int len;
+
+  if (ic_info->following_text)
+    {
+      len = mtext_nchars (ic_info->following_text);
+      if (pos < len)
+       return mtext_ref_char (ic_info->following_text, pos);
+    }
+  mt = get_surrounding_text (ic, pos + 1);
+  if (! mt)
+    return -2;
+  len = mtext_nchars (mt);
+  if (ic_info->following_text)
+    {
+      if (mtext_nchars (ic_info->following_text) < len)
+       {
+         M17N_OBJECT_UNREF (ic_info->following_text);
+         ic_info->following_text = mt;
+       }
+      else
+       M17N_OBJECT_UNREF (mt);
+    }
+  else
+    ic_info->following_text = mt;
+  if (pos >= len)
+    return -1;
+  return mtext_ref_char (ic_info->following_text, pos);
+}
+
+static int
+surrounding_pos (MSymbol sym, int *pos)
+{
+  char *name;
+
+  if (sym == Mnil)
+    return 0;
+  name = MSYMBOL_NAME (sym);
+  if (name[0] == '@'
+      && (name[1] == '-' ? (name[2] >= '1' && name[2] <= '9')
+         : name[1] == '+' ? (name[2] >= '0' && name[2] <= '9')
+         : 0))
+    {
+      *pos = name[1] == '-' ? - atoi (name + 2) : atoi (name + 2);
+      return 1;
+    }
+  return 0;
+}
+
+static int
+integer_value (MInputContext *ic, MPlist *arg, int surrounding)
+{
+  MInputContextInfo *ic_info = (MInputContextInfo *) ic->info;
+  int code, pos;
+  MText *preedit = ic->preedit;
+  int len = mtext_nchars (preedit);
+
+  if (MPLIST_INTEGER_P (arg))
+    return MPLIST_INTEGER (arg);
+
+  code = marker_code (MPLIST_SYMBOL (arg), surrounding);
+  if (code < 0)
+    {
+      MPlist *val = resolve_variable (ic_info, MPLIST_SYMBOL (arg));
+
+      return (MPLIST_INTEGER_P (val) ? MPLIST_INTEGER (val) : 0);
+    }
+  if (code == '@')
+    return ic_info->key_head;
+  if ((code == '-' || code == '+'))
+    {
+      char *name = MSYMBOL_NAME (MPLIST_SYMBOL (arg));
+
+      if (name[2])
+       {
+         pos = atoi (name + 1);
+         if (pos == 0 && code == '-')
+           return get_preceding_char (ic, 0);
+         pos = ic->cursor_pos + pos;
+         if (pos < 0)
+           {
+             if (ic->produced && mtext_len (ic->produced) + pos >= 0)
+               return mtext_ref_char (ic->produced,
+                                      mtext_len (ic->produced) + pos);
+             return get_preceding_char (ic, - pos);
+           }
+         else if (pos >= len)
+           return get_following_char (ic, pos - len);
+       }
+      else
+       pos = ic->cursor_pos + (code == '+' ? 1 : -1);
+    }
+  else if (code >= '0' && code <= '9')
+    pos = code - '0';
+  else if (code == '=')
+    pos = ic->cursor_pos;
+  else if (code == '[')
+    pos = ic->cursor_pos - 1;
+  else if (code == ']')
+    pos = ic->cursor_pos + 1;
+  else if (code == '<')
+    pos = 0;
+  else if (code == '>')
+    pos = len - 1;
+  return (pos >= 0 && pos < len ? mtext_ref_char (preedit, pos) : -1);
+}
+
+static int
+parse_expression (MPlist *plist)
+{
+  MSymbol op;
+
+  if (MPLIST_INTEGER_P (plist) || MPLIST_SYMBOL_P (plist))
+    return 0;
+  if (! MPLIST_PLIST_P (plist))
+    return -1;
+  plist = MPLIST_PLIST (plist);
+  op = MPLIST_SYMBOL (plist);
+  if (op != Mplus && op != Mminus && op != Mstar && op != Mslash
+      && op != Mand && op != Mor && op != Mnot
+      && op != Mless && op != Mgreater && op != Mequal
+      && op != Mless_equal && op != Mgreater_equal)
+    MERROR (MERROR_IM, -1);
+  MPLIST_DO (plist, MPLIST_NEXT (plist))
+    if (parse_expression (plist) < 0)
+      return -1;
+  return 0;
+}
+
+static int
+resolve_expression (MInputContext *ic, MPlist *plist)
+{
+  int val;
+  MSymbol op;
+  
+  if (MPLIST_INTEGER_P (plist))
+    return MPLIST_INTEGER (plist);
+  if (MPLIST_SYMBOL_P (plist))
+    return integer_value (ic, plist, 1);
+  if (! MPLIST_PLIST_P (plist))
+    return 0;
+  plist = MPLIST_PLIST (plist);
+  if (! MPLIST_SYMBOL_P (plist))
+    return 0;
+  op = MPLIST_SYMBOL (plist);
+  plist = MPLIST_NEXT (plist);
+  val = resolve_expression (ic, plist);
+  if (op == Mplus)
+    MPLIST_DO (plist, MPLIST_NEXT (plist))
+      val += resolve_expression (ic, plist);
+  else if (op == Mminus)
+    MPLIST_DO (plist, MPLIST_NEXT (plist))
+      val -= resolve_expression (ic, plist);
+  else if (op == Mstar)
+    MPLIST_DO (plist, MPLIST_NEXT (plist))
+      val *= resolve_expression (ic, plist);
+  else if (op == Mslash)
+    MPLIST_DO (plist, MPLIST_NEXT (plist))
+      val /= resolve_expression (ic, plist);
+  else if (op == Mand)
+    MPLIST_DO (plist, MPLIST_NEXT (plist))
+      val &= resolve_expression (ic, plist);
+  else if (op == Mor)
+    MPLIST_DO (plist, MPLIST_NEXT (plist))
+      val |= resolve_expression (ic, plist);
+  else if (op == Mnot)
+    val = ! val;
+  else if (op == Mless)
+    val = val < resolve_expression (ic, MPLIST_NEXT (plist));
+  else if (op == Mequal)
+    val = val == resolve_expression (ic, MPLIST_NEXT (plist));
+  else if (op == Mgreater)
+    val = val > resolve_expression (ic, MPLIST_NEXT (plist));
+  else if (op == Mless_equal)
+    val = val <= resolve_expression (ic, MPLIST_NEXT (plist));
+  else if (op == Mgreater_equal)
+    val = val >= resolve_expression (ic, MPLIST_NEXT (plist));
+  return val;
+}
+
+/* Parse PLIST as an action list.  PLIST should have this form:
+      PLIST ::= ( (ACTION-NAME ACTION-ARG *) *).
+   Return 0 if successfully parsed, otherwise return -1.  */
+
+static int
+parse_action_list (MPlist *plist, MPlist *macros)
+{
+  MPLIST_DO (plist, plist)
+    {
+      if (MPLIST_MTEXT_P (plist))
+       {
+         /* This is a short form of (insert MTEXT).  */
+         /* if (mtext_nchars (MPLIST_MTEXT (plist)) == 0)
+            MERROR (MERROR_IM, -1); */
+       }
+      else if (MPLIST_PLIST_P (plist)
+              && (MPLIST_MTEXT_P (MPLIST_PLIST (plist))
+                  || MPLIST_PLIST_P (MPLIST_PLIST (plist))))
+       {
+         MPlist *pl;
+
+         /* This is a short form of (insert (GROUPS *)).  */
+         MPLIST_DO (pl, MPLIST_PLIST (plist))
+           {
+             if (MPLIST_PLIST_P (pl))
+               {
+                 MPlist *elt;
+
+                 MPLIST_DO (elt, MPLIST_PLIST (pl))
+                   if (! MPLIST_MTEXT_P (elt)
+                       || mtext_nchars (MPLIST_MTEXT (elt)) == 0)
+                     MERROR (MERROR_IM, -1);
+               }
+             else
+               {
+                 if (! MPLIST_MTEXT_P (pl)
+                     || mtext_nchars (MPLIST_MTEXT (pl)) == 0)
+                   MERROR (MERROR_IM, -1);
+               }
+           }
+       }
+      else if (MPLIST_INTEGER_P (plist))
+       {
+         int c = MPLIST_INTEGER (plist);
+
+         if (c < 0 || c > MCHAR_MAX)
+           MERROR (MERROR_IM, -1);
+       }
+      else if (MPLIST_PLIST_P (plist)
+              && MPLIST_SYMBOL_P (MPLIST_PLIST (plist)))
+       {
+         MPlist *pl = MPLIST_PLIST (plist);
+         MSymbol action_name = MPLIST_SYMBOL (pl);
+
+         pl = MPLIST_NEXT (pl);
+
+         if (action_name == M_candidates)
+           {
+             /* This is an already regularised action.  */
+             continue;
+           }
+         if (action_name == Minsert)
+           {
+             if (MPLIST_MTEXT_P (pl))
+               {
+                 if (mtext_nchars (MPLIST_MTEXT (pl)) == 0)
+                   MERROR (MERROR_IM, -1);
+               }
+             else if (MPLIST_INTEGER_P (pl))
+               {
+                 int c = MPLIST_INTEGER (pl);
+
+                 if (c < 0 || c > MCHAR_MAX)
+                   MERROR (MERROR_IM, -1);
+               }
+             else if (MPLIST_PLIST_P (pl))
+               {
+                 MPLIST_DO (pl, MPLIST_PLIST (pl))
+                   {
+                     if (MPLIST_PLIST_P (pl))
+                       {
+                         MPlist *elt;
+
+                         MPLIST_DO (elt, MPLIST_PLIST (pl))
+                           if (! MPLIST_MTEXT_P (elt)
+                               || mtext_nchars (MPLIST_MTEXT (elt)) == 0)
+                             MERROR (MERROR_IM, -1);
+                       }
+                     else
+                       {
+                         if (! MPLIST_MTEXT_P (pl)
+                             || mtext_nchars (MPLIST_MTEXT (pl)) == 0)
+                           MERROR (MERROR_IM, -1);
+                       }
+                   }
+               }
+             else if (! MPLIST_SYMBOL_P (pl))
+               MERROR (MERROR_IM, -1); 
+           }
+         else if (action_name == Mselect
+                  || action_name == Mdelete
+                  || action_name == Mmove)
+           {
+             if (parse_expression (pl) < 0)
+               return -1;
+           }
+         else if (action_name == Mmark
+                  || action_name == Mcall
+                  || action_name == Mshift)
+           {
+             if (! MPLIST_SYMBOL_P (pl))
+               MERROR (MERROR_IM, -1);
+           }
+         else if (action_name == Mundo)
+           {
+             if (! MPLIST_TAIL_P (pl))
+               {
+                 if (! MPLIST_SYMBOL_P (pl)
+                     && ! MPLIST_INTEGER_P (pl))
+                   MERROR (MERROR_IM, -1);                 
+               }
+           }
+         else if (action_name == Mpushback)
+           {
+             if (MPLIST_MTEXT_P (pl))
+               {
+                 MText *mt = MPLIST_MTEXT (pl);
+
+                 if (mtext_nchars (mt) != mtext_nbytes (mt))
+                   MERROR (MERROR_IM, -1);                 
+               }
+             else if (MPLIST_PLIST_P (pl))
+               {
+                 MPlist *p;
+
+                 MPLIST_DO (p, MPLIST_PLIST (pl))
+                   if (! MPLIST_SYMBOL_P (p))
+                     MERROR (MERROR_IM, -1);
+               }
+             else if (! MPLIST_INTEGER_P (pl))
+               MERROR (MERROR_IM, -1);
+           }
+         else if (action_name == Mset || action_name == Madd
+                  || action_name == Msub || action_name == Mmul
+                  || action_name == Mdiv)
+           {
+             if (! MPLIST_SYMBOL_P (pl))
+               MERROR (MERROR_IM, -1);
+             if (parse_expression (MPLIST_NEXT (pl)) < 0)
+               return -1;
+           }
+         else if (action_name == Mequal || action_name == Mless
+                  || action_name == Mgreater || action_name == Mless_equal
+                  || action_name == Mgreater_equal)
+           {
+             if (parse_expression (pl) < 0
+                 || parse_expression (MPLIST_NEXT (pl)) < 0)
+               return -1;
+             pl = MPLIST_NEXT (MPLIST_NEXT (pl));
+             if (! MPLIST_PLIST_P (pl))
+               MERROR (MERROR_IM, -1);
+             if (parse_action_list (MPLIST_PLIST (pl), macros) < 0)
+               MERROR (MERROR_IM, -1);
+             pl = MPLIST_NEXT (pl);
+             if (MPLIST_PLIST_P (pl)
+                 && parse_action_list (MPLIST_PLIST (pl), macros) < 0)
+               MERROR (MERROR_IM, -1);
+           }
+         else if (action_name == Mshow || action_name == Mhide
+                  || action_name == Mcommit || action_name == Munhandle
+                  || action_name == Mpop)
+           ;
+         else if (action_name == Mcond)
+           {
+             MPLIST_DO (pl, pl)
+               if (! MPLIST_PLIST_P (pl))
+                 MERROR (MERROR_IM, -1);
+           }
+         else if (! macros || ! mplist_get (macros, action_name))
+           MERROR (MERROR_IM, -1);
+       }
+      else if (! MPLIST_SYMBOL_P (plist))
+       MERROR (MERROR_IM, -1);
+    }
+
+  return 0;
+}
+
+static MPlist *
+resolve_command (MPlist *cmds, MSymbol command)
+{
+  MPlist *plist;
+
+  if (! cmds || ! (plist = mplist__assq (cmds, command)))
+    return NULL;
+  plist = MPLIST_PLIST (plist);        /* (NAME DESC STATUS [KEYSEQ ...]) */
+  plist = MPLIST_NEXT (plist);
+  plist = MPLIST_NEXT (plist);
+  plist = MPLIST_NEXT (plist);
+  return plist;
+}
+
+/* Load a translation into MAP from PLIST.
+   PLIST has this form:
+      PLIST ::= ( KEYSEQ MAP-ACTION * )  */
+
+static int
+load_translation (MIMMap *map, MPlist *keylist, MPlist *map_actions,
+                 MPlist *branch_actions, MPlist *macros)
+{
+  MSymbol *keyseq;
+  int len, i;
+
+  if (MPLIST_MTEXT_P (keylist))
+    {
+      MText *mt = MPLIST_MTEXT (keylist);
+
+      len = mtext_nchars (mt);
+      if (MFAILP (len > 0 && len == mtext_nbytes (mt)))
+       return -1;
+      keyseq = (MSymbol *) alloca (sizeof (MSymbol) * len);
+      for (i = 0; i < len; i++)
+       keyseq[i] = one_char_symbol[MTEXT_DATA (mt)[i]];
+    }
+  else
+    {
+      MPlist *elt;
+         
+      if (MFAILP (MPLIST_PLIST_P (keylist)))
+       return -1;
+      elt = MPLIST_PLIST (keylist);
+      len = MPLIST_LENGTH (elt);
+      if (MFAILP (len > 0))
+       return -1;
+      keyseq = (MSymbol *) alloca (sizeof (int) * len);
+      for (i = 0; i < len; i++, elt = MPLIST_NEXT (elt))
+       {
+         if (MPLIST_INTEGER_P (elt))
+           {
+             int c = MPLIST_INTEGER (elt);
+
+             if (MFAILP (c >= 0 && c < 0x100))
+               return -1;
+             keyseq[i] = one_char_symbol[c];
+           }
+         else
+           {
+             if (MFAILP (MPLIST_SYMBOL_P (elt)))
+               return -1;
+             keyseq[i] = MPLIST_SYMBOL (elt);
+           }
+       }
+    }
+
+  for (i = 0; i < len; i++)
+    {
+      MIMMap *deeper = NULL;
+
+      if (map->submaps)
+       deeper = mplist_get (map->submaps, keyseq[i]);
+      else
+       map->submaps = mplist ();
+      if (! deeper)
+       {
+         /* Fixme: It is better to make all deeper maps at once.  */
+         MSTRUCT_CALLOC (deeper, MERROR_IM);
+         mplist_put (map->submaps, keyseq[i], deeper);
+       }
+      map = deeper;
+    }
+
+  /* We reach a terminal map.  */
+  if (map->map_actions
+      || map->branch_actions)
+    /* This map is already defined.  We avoid overriding it.  */
+    return 0;
+
+  if (! MPLIST_TAIL_P (map_actions))
+    {
+      if (parse_action_list (map_actions, macros) < 0)
+       MERROR (MERROR_IM, -1);
+      map->map_actions = map_actions;
+    }
+  if (branch_actions)
+    {
+      map->branch_actions = branch_actions;
+      M17N_OBJECT_REF (branch_actions);
+    }
+
+  return 0;
+}
+
+/* Load a branch from PLIST into MAP.  PLIST has this form:
+      PLIST ::= ( MAP-NAME BRANCH-ACTION * )  */
+
+static int
+load_branch (MInputMethodInfo *im_info, MPlist *plist, MIMMap *map)
+{
+  MSymbol map_name;
+  MPlist *branch_actions;
+
+  if (MFAILP (MPLIST_SYMBOL_P (plist)))
+    return -1;
+  map_name = MPLIST_SYMBOL (plist);
+  plist = MPLIST_NEXT (plist);
+  if (MPLIST_TAIL_P (plist))
+    branch_actions = NULL;
+  else if (MFAILP (parse_action_list (plist, im_info->macros) >= 0))
+    return -1;
+  else
+    branch_actions = plist;
+  if (map_name == Mnil)
+    {
+      map->branch_actions = branch_actions;
+      if (branch_actions)
+       M17N_OBJECT_REF (branch_actions);
+    }
+  else if (map_name == Mt)
+    {
+      map->map_actions = branch_actions;
+      if (branch_actions)
+       M17N_OBJECT_REF (branch_actions);
+    }
+  else if (im_info->maps) 
+    {
+      plist = (MPlist *) mplist_get (im_info->maps, map_name);
+      if (! plist && im_info->configured_vars)
+       {
+         MPlist *p = mplist__assq (im_info->configured_vars, map_name);
+
+         if (p && MPLIST_PLIST_P (p))
+           {
+             p = MPLIST_NEXT (MPLIST_NEXT (MPLIST_NEXT (MPLIST_PLIST (p))));
+             if (MPLIST_SYMBOL_P (p))
+               plist = mplist_get (im_info->maps, MPLIST_SYMBOL (p));
+           }
+       }
+      if (plist)
+       {
+         MPLIST_DO (plist, plist)
+           {
+             MPlist *keylist, *map_actions;
+
+             if (! MPLIST_PLIST_P (plist))
+               MERROR (MERROR_IM, -1);
+             keylist = MPLIST_PLIST (plist);
+             map_actions = MPLIST_NEXT (keylist);
+             if (MPLIST_SYMBOL_P (keylist))
+               {
+                 MSymbol command = MPLIST_SYMBOL (keylist);
+                 MPlist *pl;
+
+                 if (MFAILP (command != Mat_reload))
+                   continue;
+                 pl = resolve_command (im_info->configured_cmds, command);
+                 if (MFAILP (pl))
+                   continue;
+                 MPLIST_DO (pl, pl)
+                   load_translation (map, pl, map_actions, branch_actions,
+                                     im_info->macros);
+               }
+             else
+               load_translation (map, keylist, map_actions, branch_actions,
+                                 im_info->macros);
+           }
+       }
+    }
+
+  return 0;
+}
+
+/* Load a macro from PLIST into IM_INFO->macros.
+   PLIST has this form:
+      PLIST ::= ( MACRO-NAME ACTION * )
+   IM_INFO->macros is a plist of macro names vs action list.  */
+
+static int
+load_macros (MInputMethodInfo *im_info, MPlist *plist)
+{
+  MSymbol name; 
+  MPlist *pl;
+
+  if (! MPLIST_SYMBOL_P (plist))
+    MERROR (MERROR_IM, -1);
+  name = MPLIST_SYMBOL (plist);
+  plist = MPLIST_NEXT (plist);
+  if (MFAILP (! MPLIST_TAIL_P (plist)))
+    MERROR (MERROR_IM, -1);
+  pl = mplist_get (im_info->macros, name);
+  M17N_OBJECT_UNREF (pl);
+  mplist_put (im_info->macros, name, plist);
+  M17N_OBJECT_REF (plist);
+  return 0;
+}
+
+/* Load an external module from PLIST into IM_INFO->externals.
+   PLIST has this form:
+      PLIST ::= ( MODULE-NAME FUNCTION * )
+   IM_INFO->externals is a plist of MODULE-NAME vs (MIMExternalModule *).  */
+
+static int
+load_external_module (MInputMethodInfo *im_info, MPlist *plist)
+{
+  void *handle;
+  MSymbol module;
+  char *module_file;
+  MIMExternalModule *external;
+  MPlist *func_list;
+  void *func;
+
+  if (MPLIST_MTEXT_P (plist))
+    module = msymbol ((char *) MTEXT_DATA (MPLIST_MTEXT (plist)));
+  else if (MPLIST_SYMBOL_P (plist))
+    module = MPLIST_SYMBOL (plist);
+  module_file = alloca (strlen (M17N_MODULE_DIR) + 1
+                       + strlen (MSYMBOL_NAME (module))
+                       + strlen (DLOPEN_SHLIB_EXT) + 1);
+  sprintf (module_file, "%s/%s%s",
+          M17N_MODULE_DIR, MSYMBOL_NAME (module), DLOPEN_SHLIB_EXT);
+
+  handle = dlopen (module_file, RTLD_NOW);
+  if (MFAILP (handle))
+    {
+      fprintf (stderr, "%s\n", dlerror ());
+      return -1;
+    }
+  func_list = mplist ();
+  MPLIST_DO (plist, MPLIST_NEXT (plist))
+    {
+      if (! MPLIST_SYMBOL_P (plist))
+       MERROR_GOTO (MERROR_IM, err_label);
+      func = dlsym (handle, MSYMBOL_NAME (MPLIST_SYMBOL (plist)));
+      if (MFAILP (func))
+       goto err_label;
+      mplist_add (func_list, MPLIST_SYMBOL (plist), func);
+    }
+
+  MSTRUCT_MALLOC (external, MERROR_IM);
+  external->handle = handle;
+  external->func_list = func_list;
+  mplist_add (im_info->externals, module, external);
+  return 0;
+
+ err_label:
+  dlclose (handle);
+  M17N_OBJECT_UNREF (func_list);
+  return -1;
+}
+
+static void
+free_map (MIMMap *map, int top)
+{
+  MPlist *plist;
+
+  if (top)
+    M17N_OBJECT_UNREF (map->map_actions);
+  if (map->submaps)
+    {
+      MPLIST_DO (plist, map->submaps)
+       free_map ((MIMMap *) MPLIST_VAL (plist), 0);
+      M17N_OBJECT_UNREF (map->submaps);
+    }
+  M17N_OBJECT_UNREF (map->branch_actions);
+  free (map);
+}
+
+static void
+free_state (void *object)
+{
+  MIMState *state = object;
+
+  M17N_OBJECT_UNREF (state->title);
+  if (state->map)
+    free_map (state->map, 1);
+  free (state);
+}
+
+/** Load a state from PLIST into a newly allocated state object.
+    PLIST has this form:
+      PLIST ::= ( STATE-NAME STATE-TITLE ? BRANCH * )
+      BRANCH ::= ( MAP-NAME BRANCH-ACTION * )
+   Return the state object.  */
+
+static MIMState *
+load_state (MInputMethodInfo *im_info, MPlist *plist)
+{
+  MIMState *state;
+
+  if (MFAILP (MPLIST_SYMBOL_P (plist)))
+    return NULL;
+  M17N_OBJECT (state, free_state, MERROR_IM);
+  state->name = MPLIST_SYMBOL (plist);
+  plist = MPLIST_NEXT (plist);
+  if (MPLIST_MTEXT_P (plist))
+    {
+      state->title = MPLIST_MTEXT (plist);
+      mtext_put_prop (state->title, 0, mtext_nchars (state->title),
+                     Mlanguage, im_info->language);
+      M17N_OBJECT_REF (state->title);
+      plist = MPLIST_NEXT (plist);
+    }
+  MSTRUCT_CALLOC (state->map, MERROR_IM);
+  MPLIST_DO (plist, plist)
+    {
+      if (MFAILP (MPLIST_PLIST_P (plist)))
+       continue;
+      load_branch (im_info, MPLIST_PLIST (plist), state->map);
+    }
+  return state;
+}
+
+/* Return a newly created IM_INFO for an input method specified by
+   LANUAGE, NAME, and EXTRA.  IM_INFO is stored in PLIST.  */
+
+static MInputMethodInfo *
+new_im_info (MDatabase *mdb, MSymbol language, MSymbol name, MSymbol extra,
+            MPlist *plist)
+{
+  MInputMethodInfo *im_info;
+  MPlist *elt;
+
+  if (name == Mnil && extra == Mnil)
+    language = Mt, extra = Mglobal;
+  MSTRUCT_CALLOC (im_info, MERROR_IM);
+  im_info->mdb = mdb;
+  im_info->language = language;
+  im_info->name = name;
+  im_info->extra = extra;
+
+  elt = mplist ();
+  mplist_add (plist, Mplist, elt);
+  M17N_OBJECT_UNREF (elt);
+  elt = mplist_add (elt, Msymbol, language);
+  elt = mplist_add (elt, Msymbol, name);
+  elt = mplist_add (elt, Msymbol, extra);
+  mplist_add (elt, Mt, im_info);
+
+  return im_info;
+}
+
+static void
+fini_im_info (MInputMethodInfo *im_info)
+{
+  MPlist *plist;
+
+  M17N_OBJECT_UNREF (im_info->cmds);
+  M17N_OBJECT_UNREF (im_info->configured_cmds);
+  M17N_OBJECT_UNREF (im_info->bc_cmds);
+  M17N_OBJECT_UNREF (im_info->vars);
+  M17N_OBJECT_UNREF (im_info->configured_vars);
+  M17N_OBJECT_UNREF (im_info->bc_vars);
+  M17N_OBJECT_UNREF (im_info->description);
+  M17N_OBJECT_UNREF (im_info->title);
+  if (im_info->states)
+    {
+      MPLIST_DO (plist, im_info->states)
+       {
+         MIMState *state = (MIMState *) MPLIST_VAL (plist);
+
+         M17N_OBJECT_UNREF (state);
+       }
+      M17N_OBJECT_UNREF (im_info->states);
+    }
+
+  if (im_info->macros)
+    {
+      MPLIST_DO (plist, im_info->macros)
+       M17N_OBJECT_UNREF (MPLIST_VAL (plist)); 
+      M17N_OBJECT_UNREF (im_info->macros);
+    }
+
+  if (im_info->externals)
+    {
+      MPLIST_DO (plist, im_info->externals)
+       {
+         MIMExternalModule *external = MPLIST_VAL (plist);
+
+         dlclose (external->handle);
+         M17N_OBJECT_UNREF (external->func_list);
+         free (external);
+         MPLIST_KEY (plist) = Mt;
+       }
+      M17N_OBJECT_UNREF (im_info->externals);
+    }
+  if (im_info->maps)
+    {
+      MPLIST_DO (plist, im_info->maps)
+       {
+         MPlist *p = MPLIST_PLIST (plist);
+
+         M17N_OBJECT_UNREF (p);
+       }
+      M17N_OBJECT_UNREF (im_info->maps);
+    }
+
+  im_info->tick = 0;
+}
+
+static void
+free_im_info (MInputMethodInfo *im_info)
+{
+  fini_im_info (im_info);
+  free (im_info);
+}
+
+static void
+free_im_list (MPlist *plist)
+{
+  MPlist *pl, *elt;
+
+  MPLIST_DO (pl, plist)
+    {
+      MInputMethodInfo *im_info;
+
+      elt = MPLIST_NEXT (MPLIST_NEXT (MPLIST_NEXT (MPLIST_PLIST (pl))));
+      im_info = MPLIST_VAL (elt);
+      free_im_info (im_info);
+    }
+  M17N_OBJECT_UNREF (plist);
+}
+
+static MInputMethodInfo *
+lookup_im_info (MPlist *plist, MSymbol language, MSymbol name, MSymbol extra)
+{
+  if (name == Mnil && extra == Mnil)
+    language = Mt, extra = Mglobal;
+  while ((plist = mplist__assq (plist, language)))
+    {
+      MPlist *elt = MPLIST_PLIST (plist);
+
+      plist = MPLIST_NEXT (plist);
+      elt = MPLIST_NEXT (elt);
+      if (MPLIST_SYMBOL (elt) != name)
+       continue;
+      elt = MPLIST_NEXT (elt);
+      if (MPLIST_SYMBOL (elt) != extra)
+       continue;
+      elt = MPLIST_NEXT (elt);
+      return MPLIST_VAL (elt);
+    }
+  return NULL;
+}
+
+static void load_im_info (MPlist *, MInputMethodInfo *);
+
+#define get_custom_info(im_info)                               \
+  (im_custom_list                                              \
+   ? lookup_im_info (im_custom_list, (im_info)->language,      \
+                    (im_info)->name, (im_info)->extra)         \
+   : NULL)
+
+#define get_config_info(im_info)                               \
+  (im_config_list                                              \
+   ? lookup_im_info (im_config_list, (im_info)->language,      \
+                    (im_info)->name, (im_info)->extra)         \
+   : NULL)
+
+static int
+update_custom_info (void)
+{
+  MPlist *plist, *pl;
+
+  if (im_custom_mdb)
+    {
+      if (mdatabase__check (im_custom_mdb) > 0)
+       return 1;
+    }
+  else
+    {
+      MDatabaseInfo *custom_dir_info;
+      char custom_path[PATH_MAX + 1];
+
+      custom_dir_info = MPLIST_VAL (mdatabase__dir_list);
+      if (! custom_dir_info->filename
+         || custom_dir_info->len + strlen (CUSTOM_FILE) > PATH_MAX)
+       return -1;
+      strcpy (custom_path, custom_dir_info->filename);
+      strcat (custom_path, CUSTOM_FILE);
+      im_custom_mdb = mdatabase_define (Minput_method, Mt, Mnil, Mconfig,
+                                       NULL, custom_path);
+    }
+
+  if (im_custom_list)
+    {
+      free_im_list (im_custom_list);
+      im_custom_list = NULL;
+    }
+  plist = mdatabase_load (im_custom_mdb);
+  if (! plist)
+    return -1;
+  im_custom_list = mplist ();
+
+  MPLIST_DO (pl, plist)
+    {
+      MSymbol language, name, extra;
+      MInputMethodInfo *im_info;
+      MPlist *im_data, *p;
+
+      if (! MPLIST_PLIST_P (pl))
+       continue;
+      p = MPLIST_PLIST (pl);
+      im_data = MPLIST_NEXT (p);
+      if (! MPLIST_PLIST_P (p))
+       continue;
+      p = MPLIST_PLIST (p);
+      if (! MPLIST_SYMBOL_P (p)
+         || MPLIST_SYMBOL (p) != Minput_method)
+       continue;
+      p = MPLIST_NEXT (p);
+      if (! MPLIST_SYMBOL_P (p))
+       continue;
+      language = MPLIST_SYMBOL (p);
+      p = MPLIST_NEXT (p);
+      if (! MPLIST_SYMBOL_P (p))
+       continue;
+      name = MPLIST_SYMBOL (p);
+      p = MPLIST_NEXT (p);
+      if (MPLIST_TAIL_P (p))
+       extra = Mnil;
+      else if (MPLIST_SYMBOL_P (p))
+       extra = MPLIST_SYMBOL (p);
+      if (language == Mnil || (name == Mnil && extra == Mnil))
+       continue;
+      im_info = new_im_info (NULL, language, name, extra, im_custom_list);
+      load_im_info (im_data, im_info);
+    }
+  M17N_OBJECT_UNREF (plist);
+  return 0;
+}
+
+static int
+update_global_info (void)
+{
+  MPlist *plist;
+
+  if (global_info)
+    {
+      int ret = mdatabase__check (global_info->mdb);
+
+      if (ret)
+       return ret;
+      fini_im_info (global_info);
+    }
+  else
+    {
+      MDatabase *mdb = mdatabase_find (Minput_method, Mt, Mnil, Mglobal);
+
+      if (! mdb)
+       return -1;
+      global_info = new_im_info (mdb, Mt, Mnil, Mglobal, im_info_list);
+    }
+  if (! global_info->mdb
+      || ! (plist = mdatabase_load (global_info->mdb)))
+    return -1;
+
+  load_im_info (plist, global_info);
+  M17N_OBJECT_UNREF (plist);
+  return 0;
+}
+
+
+/* Return an IM_INFO for the an method specified by LANGUAGE, NAME,
+   and EXTRA.  KEY, if not Mnil, tells which kind of information about
+   the input method is necessary, and the returned IM_INFO may contain
+   only that information.  */
+
+static MInputMethodInfo *
+get_im_info (MSymbol language, MSymbol name, MSymbol extra, MSymbol key)
+{
+  MPlist *plist;
+  MInputMethodInfo *im_info;
+  MDatabase *mdb;
+
+  if (name == Mnil && extra == Mnil)
+    language = Mt, extra = Mglobal;
+  im_info = lookup_im_info (im_info_list, language, name, extra);
+  if (im_info)
+    {
+      if (key == Mnil ? im_info->states != NULL
+         : key == Mcommand ? im_info->cmds != NULL
+         : key == Mvariable ? im_info->vars != NULL
+         : key == Mtitle ? im_info->title != NULL
+         : key == Mdescription ? im_info->description != NULL
+         : 1)
+       /* IM_INFO already contains required information.  */
+       return im_info;
+      /* We have not yet loaded required information.  */
+    }
+  else
+    {
+      mdb = mdatabase_find (Minput_method, language, name, extra);
+      if (! mdb)
+       return NULL;
+      im_info = new_im_info (mdb, language, name, extra, im_info_list);
+    }
+
+  if (key == Mnil)
+    {
+      plist = mdatabase_load (im_info->mdb);
+    }
+  else
+    {
+      mplist_push (load_im_info_keys, key, Mt);
+      plist = mdatabase__load_for_keys (im_info->mdb, load_im_info_keys);
+      mplist_pop (load_im_info_keys);
+    }
+  im_info->tick = 0;
+  if (! plist)
+    MERROR (MERROR_IM, im_info);
+  update_global_info ();
+  load_im_info (plist, im_info);
+  M17N_OBJECT_UNREF (plist);
+  if (key == Mnil)
+    {
+      if (! im_info->cmds)
+       im_info->cmds = mplist ();
+      if (! im_info->vars)
+       im_info->vars = mplist ();
+      if (! im_info->states)
+       im_info->states = mplist ();
+    }
+  if (! im_info->title
+      && (key == Mnil || key == Mtitle))
+    im_info->title = (name == Mnil ? mtext ()
+                     : mtext_from_data (MSYMBOL_NAME (name),
+                                        MSYMBOL_NAMELEN (name),
+                                        MTEXT_FORMAT_US_ASCII));
+  return im_info;
+}
+
+/* Check if IM_INFO->mdb is updated or not.  If not updated, return 0.
+   If updated, but got unloadable, return -1.  Otherwise, update
+   contents of IM_INFO from the new database, and return 1.  */
+
+static int
+reload_im_info (MInputMethodInfo *im_info)
+{
+  int check;
+  MPlist *plist;
+
+  update_custom_info ();
+  update_global_info ();
+  check = mdatabase__check (im_info->mdb);
+  if (check < 0)
+    return -1;
+  plist = mdatabase_load (im_info->mdb);
+  if (! plist)
+    return -1;
+  fini_im_info (im_info);
+  load_im_info (plist, im_info);
+  M17N_OBJECT_UNREF (plist);
+  if (! im_info->cmds)
+    im_info->cmds = mplist ();
+  if (! im_info->vars)
+    im_info->vars = mplist ();
+  if (! im_info->title)
+    {
+      MSymbol name = im_info->name;
+
+      im_info->title = (name == Mnil ? mtext ()
+                       : mtext_from_data (MSYMBOL_NAME (name),
+                                          MSYMBOL_NAMELEN (name),
+                                          MTEXT_FORMAT_US_ASCII));
+    }
+  return 1;
+}
+
+static MInputMethodInfo *
+get_im_info_by_tags (MPlist *plist)
+{
+  MSymbol tag[3];
+  int i;
+
+  for (i = 0; i < 3 && MPLIST_SYMBOL_P (plist);
+       i++, plist = MPLIST_NEXT (plist))
+    tag[i] = MPLIST_SYMBOL (plist);
+  if (i < 2)
+    return NULL;
+  for (; i < 3; i++)
+    tag[i] = Mnil;
+  return get_im_info (tag[0], tag[1], tag[2], Mnil);
+}
+
+
+static int
+check_description (MPlist *plist)
+{
+  MText *mt;
+
+  if (MPLIST_MTEXT_P (plist))
+    return 1;
+  if (MPLIST_PLIST_P (plist))
+    {
+      MPlist *pl = MPLIST_PLIST (plist);
+
+      if (MFAILP (MPLIST_SYMBOL_P (pl) && MPLIST_SYMBOL (pl) == M_gettext))
+       return 0;
+      pl =MPLIST_NEXT (pl);
+      if (MFAILP (MPLIST_MTEXT_P (pl)))
+       return 0;
+      mt = MPLIST_MTEXT (pl);
+      M17N_OBJECT_REF (mt);
+#if ENABLE_NLS
+      {
+       char *translated = dgettext ("m17n-db", (char *) MTEXT_DATA (mt));
+
+       if (translated == (char *) MTEXT_DATA (mt))
+         translated = dgettext ("m17n-contrib", (char *) MTEXT_DATA (mt));
+       if (translated != (char *) MTEXT_DATA (mt))
+         {
+           M17N_OBJECT_UNREF (mt);
+           mt = mtext__from_data (translated, strlen (translated),
+                                  MTEXT_FORMAT_UTF_8, 1);
+         }
+      }
+#endif
+      mplist_set (plist, Mtext, mt);
+      M17N_OBJECT_UNREF (mt);
+      return 1;
+    }
+  if (MFAILP (MPLIST_SYMBOL_P (plist) && MPLIST_SYMBOL (plist) == Mnil))
+    return 0;
+  return 1;
+}
+
+
+/* Check KEYSEQ, and return 1 if it is valid as a key sequence, return
+   0 if not.  */
+
+static int
+check_command_keyseq (MPlist *keyseq)
+{
+  if (MPLIST_PLIST_P (keyseq))
+    {
+      MPlist *p = MPLIST_PLIST (keyseq);
+
+      MPLIST_DO (p, p)
+       if (! MPLIST_SYMBOL_P (p) && ! MPLIST_INTEGER_P (p))
+         return 0;
+      return 1;
+    }
+  if (MPLIST_MTEXT_P (keyseq))
+    {
+      MText *mt = MPLIST_MTEXT (keyseq);
+      int i;
+      
+      for (i = 0; i < mtext_nchars (mt); i++)
+       if (mtext_ref_char (mt, i) >= 256)
+         return 0;
+      return 1;
+    }
+  return 0;
+}
+
+/* Load command defitions from PLIST into IM_INFO->cmds.
+
+   PLIST is well-formed and has this form;
+     (command (NAME [DESCRIPTION KEYSEQ ...]) ...)
+   NAME is a symbol.  DESCRIPTION is an M-text or `nil'.  KEYSEQ is an
+   M-text or a plist of symbols.
+
+   The returned list has the same form, but for each element...
+
+   (1) If DESCRIPTION and the rest are omitted, the element is not
+   stored in the returned list.
+
+   (2) If DESCRIPTION is nil, it is complemented by the corresponding
+   description in global_info->cmds (if any).  */
+
+static void
+load_commands (MInputMethodInfo *im_info, MPlist *plist)
+{
+  MPlist *tail;
+
+  im_info->cmds = tail = mplist ();
+
+  MPLIST_DO (plist, MPLIST_NEXT (plist))
+    {
+      /* PLIST ::= ((NAME DESC KEYSEQ ...) ...) */
+      MPlist *pl, *p;
+
+      if (MFAILP (MPLIST_PLIST_P (plist)))
+       continue;
+      pl = MPLIST_PLIST (plist); /* PL ::= (NAME DESC KEYSEQ ...) */
+      if (MFAILP (MPLIST_SYMBOL_P (pl)))
+       continue;
+      p = MPLIST_NEXT (pl);    /* P ::= (DESC KEYSEQ ...) */
+      if (MPLIST_TAIL_P (p))   /* PL ::= (NAME) */
+       {
+         if (MFAILP (im_info != global_info))
+           mplist_add (p, Msymbol, Mnil); /* PL ::= (NAME nil) */
+       }
+      else
+       {
+         if (! check_description (p))
+           mplist_set (p, Msymbol, Mnil);
+         p = MPLIST_NEXT (p);
+         while (! MPLIST_TAIL_P (p))
+           {
+             if (MFAILP (check_command_keyseq (p)))
+               mplist__pop_unref (p);
+             else
+               p = MPLIST_NEXT (p);
+           }
+       }
+      tail = mplist_add (tail, Mplist, pl);
+    }
+}
+
+static MPlist *
+config_command (MPlist *plist, MPlist *global_cmds, MPlist *custom_cmds,
+               MPlist *config_cmds)
+{
+  MPlist *global = NULL, *custom = NULL, *config = NULL;
+  MSymbol name = MPLIST_SYMBOL (plist);
+  MSymbol status;
+  MPlist *description, *keyseq;
+
+  if (global_cmds && (global = mplist__assq (global_cmds, name)))
+    global = MPLIST_NEXT (MPLIST_PLIST (global));  
+
+  plist = MPLIST_NEXT (plist);
+  if (MPLIST_MTEXT_P (plist) || MPLIST_PLIST_P (plist))
+    {
+      description = plist;
+      plist = MPLIST_NEXT (plist);
+    }
+  else
+    {
+      description = global;
+      if (! MPLIST_TAIL_P (plist))
+       plist = MPLIST_NEXT (plist);
+    }
+  if (MPLIST_TAIL_P (plist) && global)
+    {
+      keyseq = MPLIST_NEXT (global);
+      status = Minherited;
+    }
+  else
+    {
+      keyseq = plist;
+      status = Mnil;
+    }
+
+  if (config_cmds && (config = mplist__assq (config_cmds, name)))
+    {
+      status = Mconfigured;
+      config = MPLIST_NEXT (MPLIST_PLIST (config));
+      if (! MPLIST_TAIL_P (config))
+       keyseq = config;
+    }
+  else if (custom_cmds && (custom = mplist__assq (custom_cmds, name)))
+    {
+      MPlist *this_keyseq = MPLIST_NEXT (MPLIST_NEXT (MPLIST_PLIST (custom)));
+
+      if (MPLIST_TAIL_P (this_keyseq))
+       mplist__pop_unref (custom);
+      else
+       {
+         status = Mcustomized;
+         keyseq = this_keyseq;
+       }
+    }
+  
+  plist = mplist ();
+  mplist_add (plist, Msymbol, name);
+  if (description)
+    mplist_add (plist, MPLIST_KEY (description), MPLIST_VAL (description));
+  else
+    mplist_add (plist, Msymbol, Mnil);
+  mplist_add (plist, Msymbol, status);
+  mplist__conc (plist, keyseq);
+  return plist;
+}
+
+static void
+config_all_commands (MInputMethodInfo *im_info)
+{
+  MPlist *global_cmds, *custom_cmds, *config_cmds;
+  MInputMethodInfo *temp;
+  MPlist *tail, *plist;
+
+  M17N_OBJECT_UNREF (im_info->configured_cmds);
+
+  if (MPLIST_TAIL_P (im_info->cmds)
+      || ! im_info->mdb)
+    return;
+
+  global_cmds = im_info != global_info ? global_info->cmds : NULL;
+  custom_cmds = ((temp = get_custom_info (im_info)) ? temp->cmds : NULL);
+  config_cmds = ((temp = get_config_info (im_info)) ? temp->cmds : NULL);
+
+  im_info->configured_cmds = tail = mplist ();
+  MPLIST_DO (plist, im_info->cmds)
+    {
+      MPlist *pl = config_command (MPLIST_PLIST (plist),
+                                  global_cmds, custom_cmds, config_cmds);
+      if (pl)
+       {
+         tail = mplist_add (tail, Mplist, pl);
+         M17N_OBJECT_UNREF (pl);
+       }
+    }
+}
+
+/* Check VAL's value against VALID_VALUES, and return 1 if it is
+   valid, return 0 if not.  */
+
+static int
+check_variable_value (MPlist *val, MPlist *global)
+{
+  MSymbol type = MPLIST_KEY (val);
+  MPlist *valids = MPLIST_NEXT (val);
+
+  if (type != Minteger && type != Mtext && type != Msymbol)
+    return 0;
+  if (global)
+    {
+      if (MPLIST_KEY (global) != Mt
+         && MPLIST_KEY (global) != MPLIST_KEY (val))
+       return 0;
+      if (MPLIST_TAIL_P (valids))
+       valids = MPLIST_NEXT (global);
+    }
+  if (MPLIST_TAIL_P (valids))
+    return 1;
+
+  if (type == Minteger)
+    {
+      int n = MPLIST_INTEGER (val);
+
+      MPLIST_DO (valids, valids)
+       {
+         if (MPLIST_INTEGER_P (valids))
+           {
+             if (n == MPLIST_INTEGER (valids))
+               break;
+           }
+         else if (MPLIST_PLIST_P (valids))
+           {
+             MPlist *p = MPLIST_PLIST (valids);
+             int min_bound, max_bound;
+
+             if (! MPLIST_INTEGER_P (p))
+               MERROR (MERROR_IM, 0);
+             min_bound = MPLIST_INTEGER (p);
+             p = MPLIST_NEXT (p);
+             if (! MPLIST_INTEGER_P (p))
+               MERROR (MERROR_IM, 0);
+             max_bound = MPLIST_INTEGER (p);
+             if (n >= min_bound && n <= max_bound)
+               break;
+           }
+       }
+    }
+  else if (type == Msymbol)
+    {
+      MSymbol sym = MPLIST_SYMBOL (val);
+
+      MPLIST_DO (valids, valids)
+       {
+         if (! MPLIST_SYMBOL_P (valids))
+           MERROR (MERROR_IM, 0);
+         if (sym == MPLIST_SYMBOL (valids))
+           break;
+       }
+    }
+  else
+    {
+      MText *mt = MPLIST_MTEXT (val);
+
+      MPLIST_DO (valids, valids)
+       {
+         if (! MPLIST_MTEXT_P (valids))
+           MERROR (MERROR_IM, 0);
+         if (mtext_cmp (mt, MPLIST_MTEXT (valids)) == 0)
+           break;
+       }
+    }
+
+  return (! MPLIST_TAIL_P (valids));
+}
+
+/* Load variable defitions from PLIST into IM_INFO->vars.
+
+   PLIST is well-formed and has this form;
+     ((NAME [DESCRIPTION DEFAULT-VALUE VALID-VALUE ...])
+      ...)
+   NAME is a symbol.  DESCRIPTION is an M-text or `nil'.
+
+   The returned list has the same form, but for each element...
+
+   (1) If DESCRIPTION and the rest are omitted, the element is not
+   stored in the returned list.
+
+   (2) If DESCRIPTION is nil, it is complemented by the corresponding
+   description in global_info->vars (if any).  */
+
+static void
+load_variables (MInputMethodInfo *im_info, MPlist *plist)
+{
+  MPlist *global_vars = ((im_info->mdb && im_info != global_info)
+                        ? global_info->vars : NULL);
+  MPlist *tail;
+
+  im_info->vars = tail = mplist ();
+  MPLIST_DO (plist, MPLIST_NEXT (plist))
+    {
+      MPlist *pl, *p;
+
+      if (MFAILP (MPLIST_PLIST_P (plist)))
+       continue;
+      pl = MPLIST_PLIST (plist); /* PL ::= (NAME DESC VALUE VALID ...) */
+      if (MFAILP (MPLIST_SYMBOL_P (pl)))
+       continue;
+      if (im_info == global_info)
+       {
+         /* Loading a global variable.  */
+         p = MPLIST_NEXT (pl);
+         if (MPLIST_TAIL_P (p))
+           mplist_add (p, Msymbol, Mnil);
+         else
+           {
+             if (! check_description (p))
+               mplist_set (p, Msymbol, Mnil);
+             p = MPLIST_NEXT (p);
+             if (MFAILP (! MPLIST_TAIL_P (p)
+                         && check_variable_value (p, NULL)))
+               mplist_set (p, Mt, NULL);
+           }
+       }
+      else if (im_info->mdb)
+       {
+         /* Loading a local variable.  */
+         MSymbol name = MPLIST_SYMBOL (pl);
+         MPlist *global = NULL;
+
+         if (global_vars
+             && (p = mplist__assq (global_vars, name)))
+           {
+             /* P ::= ((NAME DESC ...) ...) */
+             p = MPLIST_PLIST (p); /* P ::= (NAME DESC ...) */
+             global = MPLIST_NEXT (p); /* P ::= (DESC VALUE ...) */
+             global = MPLIST_NEXT (global); /* P ::= (VALUE ...) */
+           }
+
+         p = MPLIST_NEXT (pl); /* P ::= (DESC VALUE VALID ...) */
+         if (! MPLIST_TAIL_P (p))
+           {
+             if (! check_description (p))
+               mplist_set (p, Msymbol, Mnil);
+             p = MPLIST_NEXT (p); /* P ::= (VALUE VALID ...) */
+             if (MFAILP (! MPLIST_TAIL_P (p)))
+               mplist_set (p, Mt, NULL);
+             else
+               {
+                 MPlist *valid_values = MPLIST_NEXT (p);
+
+                 if (! MPLIST_TAIL_P (valid_values)
+                     ? MFAILP (check_variable_value (p, NULL))
+                     : global && MFAILP (check_variable_value (p, global)))
+                   mplist_set (p, Mt, NULL);
+               }
+           }
+       }
+      else
+       {
+         /* Loading a variable customization.  */
+         p = MPLIST_NEXT (pl); /* P ::= (nil VALUE) */
+         if (MFAILP (! MPLIST_TAIL_P (p)))
+           continue;
+         p = MPLIST_NEXT (p);  /* P ::= (VALUE) */
+         if (MFAILP (MPLIST_INTEGER_P (p) || MPLIST_SYMBOL_P (p)
+                     || MPLIST_MTEXT_P (p)))
+           continue;
+       }
+      tail = mplist_add (tail, Mplist, pl);
+    }
+}
+
+static MPlist *
+config_variable (MPlist *plist, MPlist *global_vars, MPlist *custom_vars,
+                MPlist *config_vars)
+{
+  MPlist *global = NULL, *custom = NULL, *config = NULL;
+  MSymbol name = MPLIST_SYMBOL (plist);
+  MSymbol status;
+  MPlist *description = NULL, *value, *valids;
+
+  if (global_vars)
+    {
+      global = mplist__assq (global_vars, name);
+      if (global)
+       global = MPLIST_NEXT (MPLIST_PLIST (global)); /* (DESC VALUE ...) */
+    }
+
+  plist = MPLIST_NEXT (plist);
+  if (MPLIST_MTEXT_P (plist) || MPLIST_PLIST_P (plist))
+    description = plist;
+  else if (global)
+    description = global;
+  if (global)
+    global = MPLIST_NEXT (global); /* (VALUE VALIDS ...) */
+
+  if (MPLIST_TAIL_P (plist))
+    {
+      /* Inherit from global (if any).  */
+      if (global)
+       {
+         value = global;
+         if (MPLIST_KEY (value) == Mt)
+           value = NULL;
+         valids = MPLIST_NEXT (global);
+         status = Minherited;
+       }
+      else
+       {
+         value = NULL;
+         valids = NULL;
+         status = Mnil;
+         plist = NULL;
+       }
+    }
+  else
+    {
+      value = plist = MPLIST_NEXT (plist);
+      valids = MPLIST_NEXT (value);
+      if (MPLIST_KEY (value) == Mt)
+       value = NULL;
+      if (! MPLIST_TAIL_P (valids))
+       global = NULL;
+      else if (global)
+       valids = MPLIST_NEXT (global);
+      status = Mnil;
+    }
+
+  if (config_vars && (config = mplist__assq (config_vars, name)))
+    {
+      status = Mconfigured;
+      config = MPLIST_NEXT (MPLIST_PLIST (config));
+      if (! MPLIST_TAIL_P (config))
+       {
+         value = config;
+         if (MFAILP (check_variable_value (value, global ? global : plist)))
+           value = NULL;
+       }
+    }
+  else if (custom_vars && (custom = mplist__assq (custom_vars, name)))
+    {
+      MPlist *this_value = MPLIST_NEXT (MPLIST_NEXT (MPLIST_PLIST (custom)));
+
+      if (MPLIST_TAIL_P (this_value))
+       mplist__pop_unref (custom);
+      else
+       {
+         value = this_value;
+         if (MFAILP (check_variable_value (value, global ? global : plist)))
+           value = NULL;
+         status = Mcustomized;
+       }
+    }
+  
+  plist = mplist ();
+  mplist_add (plist, Msymbol, name);
+  if (description)
+    mplist_add (plist, MPLIST_KEY (description), MPLIST_VAL (description));
+  else
+    mplist_add (plist, Msymbol, Mnil);
+  mplist_add (plist, Msymbol, status);
+  if (value)
+    mplist_add (plist, MPLIST_KEY (value), MPLIST_VAL (value));
+  else
+    mplist_add (plist, Mt, NULL);
+  if (valids && ! MPLIST_TAIL_P (valids))
+    mplist__conc (plist, valids);
+  return plist;
+}
+
+/* Return a configured variable definition list based on
+   IM_INFO->vars.  If a variable in it doesn't contain a value, try to
+   get it from global_info->vars.  */
+
+static void
+config_all_variables (MInputMethodInfo *im_info)
+{
+  MPlist *global_vars, *custom_vars, *config_vars;
+  MInputMethodInfo *temp;
+  MPlist *tail, *plist;
+
+  M17N_OBJECT_UNREF (im_info->configured_vars);
+
+  if (MPLIST_TAIL_P (im_info->vars)
+      || ! im_info->mdb)
+    return;
+
+  global_vars = im_info != global_info ? global_info->vars : NULL;
+  custom_vars = ((temp = get_custom_info (im_info)) ? temp->vars : NULL);
+  config_vars = ((temp = get_config_info (im_info)) ? temp->vars : NULL);
+
+  im_info->configured_vars = tail = mplist ();
+  MPLIST_DO (plist, im_info->vars)
+    {
+      MPlist *pl = config_variable (MPLIST_PLIST (plist),
+                                   global_vars, custom_vars, config_vars);
+      if (pl)
+       {
+         tail = mplist_add (tail, Mplist, pl);
+         M17N_OBJECT_UNREF (pl);
+       }
+    }
+}
+
+/* Load an input method (LANGUAGE NAME) from PLIST into IM_INFO.
+   CONFIG contains configuration information of the input method.  */
+
+static void
+load_im_info (MPlist *plist, MInputMethodInfo *im_info)
+{
+  MPlist *pl, *p;
+
+  if (! im_info->cmds && (pl = mplist__assq (plist, Mcommand)))
+    {
+      load_commands (im_info, MPLIST_PLIST (pl));
+      config_all_commands (im_info);
+      pl = mplist_pop (pl);
+      M17N_OBJECT_UNREF (pl);
+    }
+
+  if (! im_info->vars && (pl = mplist__assq (plist, Mvariable)))
+    {
+      load_variables (im_info, MPLIST_PLIST (pl));
+      config_all_variables (im_info);
+      pl = mplist_pop (pl);
+      M17N_OBJECT_UNREF (pl);
+    }
+
+  MPLIST_DO (plist, plist)
+    if (MPLIST_PLIST_P (plist))
+      {
+       MPlist *elt = MPLIST_PLIST (plist);
+       MSymbol key;
+
+       if (MFAILP (MPLIST_SYMBOL_P (elt)))
+         continue;
+       key = MPLIST_SYMBOL (elt);
+       if (key == Mtitle)
+         {
+           if (im_info->title)
+             continue;
+           elt = MPLIST_NEXT (elt);
+           if (MFAILP (MPLIST_MTEXT_P (elt)))
+             continue;
+           im_info->title = MPLIST_MTEXT (elt);
+           M17N_OBJECT_REF (im_info->title);
+         }
+       else if (key == Mmap)
+         {
+           pl = mplist__from_alist (MPLIST_NEXT (elt));
+           if (MFAILP (pl))
+             continue;
+           if (! im_info->maps)
+             im_info->maps = pl;
+           else
+             {
+               mplist__conc (im_info->maps, pl);
+               M17N_OBJECT_UNREF (pl);
+             }
+         }
+       else if (key == Mmacro)
+         {
+           if (! im_info->macros)
+             im_info->macros = mplist ();
+           MPLIST_DO (elt, MPLIST_NEXT (elt))
+             {
+               if (MFAILP (MPLIST_PLIST_P (elt)))
+                 continue;
+               load_macros (im_info, MPLIST_PLIST (elt));
+             }
+         }
+       else if (key == Mmodule)
+         {
+           if (! im_info->externals)
+             im_info->externals = mplist ();
+           MPLIST_DO (elt, MPLIST_NEXT (elt))
+             {
+               if (MFAILP (MPLIST_PLIST_P (elt)))
+                 continue;
+               load_external_module (im_info, MPLIST_PLIST (elt));
+             }
+         }
+       else if (key == Mstate)
+         {
+           MPLIST_DO (elt, MPLIST_NEXT (elt))
+             {
+               MIMState *state;
+
+               if (MFAILP (MPLIST_PLIST_P (elt)))
+                 continue;
+               pl = MPLIST_PLIST (elt);
+               if (! im_info->states)
+                 im_info->states = mplist ();
+               state = load_state (im_info, MPLIST_PLIST (elt));
+               if (MFAILP (state))
+                 continue;
+               mplist_put (im_info->states, state->name, state);
+             }
+         }
+       else if (key == Minclude)
+         {
+           /* elt ::= include (tag1 tag2 ...) key item ... */
+           MSymbol key;
+           MInputMethodInfo *temp;
+
+           elt = MPLIST_NEXT (elt);
+           if (MFAILP (MPLIST_PLIST_P (elt)))
+             continue;
+           temp = get_im_info_by_tags (MPLIST_PLIST (elt));
+           if (MFAILP (temp))
+             continue;
+           elt = MPLIST_NEXT (elt);
+           if (MFAILP (MPLIST_SYMBOL_P (elt)))
+             continue;
+           key = MPLIST_SYMBOL (elt);
+           elt = MPLIST_NEXT (elt);
+           if (key == Mmap)
+             {
+               if (! temp->maps || MPLIST_TAIL_P (temp->maps))
+                 continue;
+               if (! im_info->maps)
+                 im_info->maps = mplist ();
+               MPLIST_DO (pl, temp->maps)
+                 {
+                   p = MPLIST_VAL (pl);
+                   MPLIST_ADD_PLIST (im_info->maps, MPLIST_KEY (pl), p);
+                   M17N_OBJECT_REF (p);
+                 }
+             }
+           else if (key == Mmacro)
+             {
+               if (! temp->macros || MPLIST_TAIL_P (temp->macros))
+                 continue;
+               if (! im_info->macros)
+                 im_info->macros = mplist ();
+               MPLIST_DO (pl, temp->macros)
+                 {
+                   p = MPLIST_VAL (pl);
+                   MPLIST_ADD_PLIST (im_info->macros, MPLIST_KEY (pl), p);
+                   M17N_OBJECT_REF (p);
+                 }
+             }
+           else if (key == Mstate)
+             {
+               if (! temp->states || MPLIST_TAIL_P (temp->states))
+                 continue;
+               if (! im_info->states)
+                 im_info->states = mplist ();
+               MPLIST_DO (pl, temp->states)
+                 {
+                   MIMState *state = MPLIST_VAL (pl);
+
+                   mplist_add (im_info->states, MPLIST_KEY (pl), state);
+                   M17N_OBJECT_REF (state);
+                 }
+             }
+         }
+       else if (key == Mdescription)
+         {
+           if (im_info->description)
+             continue;
+           elt = MPLIST_NEXT (elt);
+           if (! check_description (elt))
+             continue;
+           im_info->description = MPLIST_MTEXT (elt);
+           M17N_OBJECT_REF (im_info->description);
+         }
+      }
+  if (im_info->macros)
+    {
+      MPLIST_DO (pl, im_info->macros)
+       parse_action_list (MPLIST_PLIST (pl), im_info->macros);
+    }
+
+  im_info->tick = time (NULL);
+}
+
+\f
+
+static int take_action_list (MInputContext *ic, MPlist *action_list);
+static void preedit_commit (MInputContext *ic, int need_prefix);
+
+static void
+shift_state (MInputContext *ic, MSymbol state_name)
+{
+  MInputMethodInfo *im_info = (MInputMethodInfo *) ic->im->info;
+  MInputContextInfo *ic_info = (MInputContextInfo *) ic->info;
+  MIMState *orig_state = ic_info->state, *state;
+
+  /* Find a state to shift to.  If not found, shift to the initial
+     state.  */
+  if (state_name == Mt)
+    {
+      if (! ic_info->prev_state)
+       return;
+      state = ic_info->prev_state;
+    }
+  else if (state_name == Mnil)
+    {
+      state = (MIMState *) MPLIST_VAL (im_info->states);
+    }
+  else
+    {
+      state = (MIMState *) mplist_get (im_info->states, state_name);
+      if (! state)
+       state = (MIMState *) MPLIST_VAL (im_info->states);
+    }
+
+  if (MDEBUG_FLAG ())
+    {
+      if (orig_state)
+       MDEBUG_PRINT2 ("\n  [IM] [%s] (shift %s)\n",
+                      MSYMBOL_NAME (orig_state->name),
+                      MSYMBOL_NAME (state->name));
+      else
+       MDEBUG_PRINT1 (" (shift %s)\n", MSYMBOL_NAME (state->name));
+    }
+
+  /* Enter the new state.  */
+  ic_info->state = state;
+  ic_info->map = state->map;
+  ic_info->state_key_head = ic_info->key_head;
+  if (state == (MIMState *) MPLIST_VAL (im_info->states)
+      && orig_state)
+    /* We have shifted to the initial state.  */
+    preedit_commit (ic, 0);
+  mtext_cpy (ic_info->preedit_saved, ic->preedit);
+  ic_info->state_pos = ic->cursor_pos;
+  if (state != orig_state)
+    {
+      if (state == (MIMState *) MPLIST_VAL (im_info->states))
+       {
+         /* Shifted to the initial state.  */
+         ic_info->prev_state = NULL;
+         M17N_OBJECT_UNREF (ic_info->vars_saved);
+         ic_info->vars_saved = mplist_copy (ic_info->vars);
+       }
+      else
+       ic_info->prev_state = orig_state;
+
+      if (state->title)
+       ic->status = state->title;
+      else
+       ic->status = im_info->title;
+      ic->status_changed = 1;
+      if (ic_info->map == ic_info->state->map
+         && ic_info->map->map_actions)
+       {
+         MDEBUG_PRINT1 ("  [IM] [%s] init-actions:",
+                        MSYMBOL_NAME (state->name));
+         take_action_list (ic, ic_info->map->map_actions);
+       }
+    }
+}
+
+/* Find a candidate group that contains a candidate number INDEX from
+   PLIST.  Set START_INDEX to the first candidate number of the group,
+   END_INDEX to the last candidate number plus 1, GROUP_INDEX to the
+   candidate group number if they are non-NULL.  If INDEX is -1, find
+   the last candidate group.  */
+
+static MPlist *
+find_candidates_group (MPlist *plist, int index,
+                      int *start_index, int *end_index, int *group_index)
+{
+  int i = 0, gidx = 0, len;
+
+  MPLIST_DO (plist, plist)
+    {
+      if (MPLIST_MTEXT_P (plist))
+       len = mtext_nchars (MPLIST_MTEXT (plist));
+      else
+       len = mplist_length (MPLIST_PLIST (plist));
+      if (index < 0 ? MPLIST_TAIL_P (MPLIST_NEXT (plist))
+         : i + len > index)
+       {
+         if (start_index)
+           *start_index = i;
+         if (end_index)
+           *end_index = i + len;
+         if (group_index)
+           *group_index = gidx;
+         return plist;
+       }
+      i += len;
+      gidx++;
+    }
+  return NULL;
+}
+
+/* Adjust markers for the change of preedit text.
+   If FROM == TO, the change is insertion of INS chars.
+   If FROM < TO and INS == 0, the change is deletion of the range.
+   If FROM < TO and INS > 0, the change is replacement.  */
+
+static void
+adjust_markers (MInputContext *ic, int from, int to, int ins)
+{
+  MInputContextInfo *ic_info = ((MInputContext *) ic)->info;
+  MPlist *markers;
+
+  if (from == to)
+    {
+      MPLIST_DO (markers, ic_info->markers)
+       if (MPLIST_INTEGER (markers) > from)
+         MPLIST_VAL (markers) = (void *) (MPLIST_INTEGER (markers) + ins);
+      if (ic->cursor_pos >= from)
+       ic->cursor_pos += ins;
+    }
+  else
+    {
+      MPLIST_DO (markers, ic_info->markers)
+       {
+         if (MPLIST_INTEGER (markers) >= to)
+           MPLIST_VAL (markers)
+             = (void *) (MPLIST_INTEGER (markers) + ins - (to - from));
+         else if (MPLIST_INTEGER (markers) > from)
+           MPLIST_VAL (markers) = (void *) from;
+       }
+      if (ic->cursor_pos >= to)
+       ic->cursor_pos += ins - (to - from);
+      else if (ic->cursor_pos > from)
+       ic->cursor_pos = from;
+    }
+}
+
+
+static void
+preedit_insert (MInputContext *ic, int pos, MText *mt, int c)
+{
+  int nchars = mt ? mtext_nchars (mt) : 1;
+
+  if (mt)
+    {
+      mtext_ins (ic->preedit, pos, mt);
+      MDEBUG_PRINT1 ("(\"%s\")", MTEXT_DATA (mt));
+    }
+  else
+    {
+      mtext_ins_char (ic->preedit, pos, c, 1);
+      if (c < 0x7F)
+       MDEBUG_PRINT1 ("('%c')", c);
+      else
+       MDEBUG_PRINT1 ("(U+%04X)", c);
+    }
+  adjust_markers (ic, pos, pos, nchars);
+  ic->preedit_changed = 1;
+}
+
+
+static void
+preedit_delete (MInputContext *ic, int from, int to)
+{
+  mtext_del (ic->preedit, from, to);
+  adjust_markers (ic, from, to, 0);
+  ic->preedit_changed = 1;
+}
+
+static void
+preedit_replace (MInputContext *ic, int from, int to, MText *mt, int c)
+{
+  int ins;
+
+  mtext_del (ic->preedit, from, to);
+  if (mt)
+    {
+      mtext_ins (ic->preedit, from, mt);
+      ins = mtext_nchars (mt);
+    }
+  else
+    {
+      mtext_ins_char (ic->preedit, from, c, 1);
+      ins = 1;
+    }
+  adjust_markers (ic, from, to, ins);
+  ic->preedit_changed = 1;
+}
+
+
+static void
+preedit_commit (MInputContext *ic, int need_prefix)
+{
+  MInputContextInfo *ic_info = (MInputContextInfo *) ic->info;
+  int preedit_len = mtext_nchars (ic->preedit);
+
+  if (preedit_len > 0)
+    {
+      MPlist *p;
+
+      mtext_put_prop_values (ic->preedit, 0, mtext_nchars (ic->preedit),
+                            Mcandidate_list, NULL, 0);
+      mtext_put_prop_values (ic->preedit, 0, mtext_nchars (ic->preedit),
+                            Mcandidate_index, NULL, 0);
+      mtext_cat (ic->produced, ic->preedit);
+      if (MDEBUG_FLAG ())
+       {
+         int i;
+
+         if (need_prefix)
+           MDEBUG_PRINT1 ("\n  [IM] [%s]",
+                          MSYMBOL_NAME (ic_info->state->name));
+         MDEBUG_PRINT (" (commit");
+         for (i = 0; i < mtext_nchars (ic->preedit); i++)
+           MDEBUG_PRINT1 (" U+%04X", mtext_ref_char (ic->preedit, i));
+         MDEBUG_PRINT (")");
+       }
+
+      mtext_reset (ic->preedit);
+      mtext_reset (ic_info->preedit_saved);
+      MPLIST_DO (p, ic_info->markers)
+       MPLIST_VAL (p) = 0;
+      ic->cursor_pos = ic_info->state_pos = 0;
+      ic->preedit_changed = 1;
+      ic_info->commit_key_head = ic_info->key_head;
+    }
+  if (ic->candidate_list)
+    {
+      M17N_OBJECT_UNREF (ic->candidate_list);
+      ic->candidate_list = NULL;
+      ic->candidate_index = 0;
+      ic->candidate_from = ic->candidate_to = 0;
+      ic->candidates_changed = MINPUT_CANDIDATES_LIST_CHANGED;
+      if (ic->candidate_show)
+       {
+         ic->candidate_show = 0;
+         ic->candidates_changed |= MINPUT_CANDIDATES_SHOW_CHANGED;
+       }
+    }
+}
+
+static int
+new_index (MInputContext *ic, int current, int limit, MSymbol sym, MText *mt)
+{
+  int code = marker_code (sym, 0);
+
+  if (mt && (code == '[' || code == ']'))
+    {
+      int pos = current;
+
+      if (code == '[' && current > 0)
+       {
+         if (mtext_prop_range (mt, Mcandidate_list, pos - 1, &pos, NULL, 1)
+             && pos > 0)
+           current = pos;
+       }
+      else if (code == ']' && current < mtext_nchars (mt))
+       {
+         if (mtext_prop_range (mt, Mcandidate_list, pos, NULL, &pos, 1))
+           current = pos;
+       }
+      return current;
+    }
+  if (code >= 0)
+    return (code == '<' ? 0
+           : code == '>' ? limit
+           : code == '-' ? current - 1
+           : code == '+' ? current + 1
+           : code == '=' ? current
+           : code - '0' > limit ? limit
+           : code - '0');
+  if (! ic)  
+    return 0;
+  return (int) mplist_get (((MInputContextInfo *) ic->info)->markers, sym);
+}
+
+static void
+update_candidate (MInputContext *ic, MTextProperty *prop, int idx)
+{
+  int from = mtext_property_start (prop);
+  int to = mtext_property_end (prop);
+  int start;
+  MPlist *candidate_list = mtext_property_value (prop);
+  MPlist *group = find_candidates_group (candidate_list, idx, &start,
+                                        NULL, NULL);
+  int ingroup_index = idx - start;
+  MText *mt;
+
+  candidate_list = mplist_copy (candidate_list);
+  if (MPLIST_MTEXT_P (group))
+    {
+      mt = MPLIST_MTEXT (group);
+      preedit_replace (ic, from, to, NULL, mtext_ref_char (mt, ingroup_index));
+      to = from + 1;
+    }
+  else
+    {
+      int i;
+      MPlist *plist;
+
+      for (i = 0, plist = MPLIST_PLIST (group); i < ingroup_index;
+          i++, plist = MPLIST_NEXT (plist));
+      mt = MPLIST_MTEXT (plist);
+      preedit_replace (ic, from, to, mt, 0);
+      to = from + mtext_nchars (mt);
+    }
+  mtext_put_prop (ic->preedit, from, to, Mcandidate_list, candidate_list);
+  M17N_OBJECT_UNREF (candidate_list);
+  mtext_put_prop (ic->preedit, from, to, Mcandidate_index, (void *) idx);
+  ic->cursor_pos = to;
+}
+
+static MCharset *
+get_select_charset (MInputContextInfo * ic_info)
+{
+  MPlist *plist = resolve_variable (ic_info, Mcandidates_charset);
+  MSymbol sym;
+
+  if (! MPLIST_VAL (plist))
+    return NULL;
+  sym = MPLIST_SYMBOL (plist);
+  if (sym == Mnil)
+    return NULL;
+  return MCHARSET (sym);
+}
+
+/* The returned plist must be UNREFed.  */
+
+static MPlist *
+adjust_candidates (MPlist *plist, MCharset *charset)
+{
+  MPlist *pl;
+
+  /* plist ::= MTEXT ... | PLIST ... */
+  plist = mplist_copy (plist);
+  if (MPLIST_MTEXT_P (plist))
+    {
+      pl = plist;
+      while (! MPLIST_TAIL_P (pl))
+       {
+         /* pl ::= MTEXT ... */
+         MText *mt = MPLIST_MTEXT (pl);
+         int mt_copied = 0;
+         int i, c;
+
+         for (i = mtext_nchars (mt) - 1; i >= 0; i--)
+           {
+             c = mtext_ref_char (mt, i);
+             if (ENCODE_CHAR (charset, c) == MCHAR_INVALID_CODE)
+               {
+                 if (! mt_copied)
+                   {
+                     mt = mtext_dup (mt);
+                     mplist_set (pl, Mtext, mt);
+                     M17N_OBJECT_UNREF (mt);
+                     mt_copied = 1;
+                   }
+                 mtext_del (mt, i, i + 1);
+               }
+           }
+         if (mtext_len (mt) > 0)
+           pl = MPLIST_NEXT (pl);
+         else
+           {
+             mplist_pop (pl);
+             M17N_OBJECT_UNREF (mt);
+           }
+       }
+    }
+  else                         /* MPLIST_PLIST_P (plist) */
+    {
+      pl = plist;
+      while (! MPLIST_TAIL_P (pl))
+       {
+         /* pl ::= (MTEXT ...) ... */
+         MPlist *p = MPLIST_PLIST (pl);
+         int p_copied = 0;
+         /* p ::= MTEXT ... */
+         MPlist *p0 = p;
+         int n = 0;
+
+         while (! MPLIST_TAIL_P (p0))
+           {
+             MText *mt = MPLIST_MTEXT (p0);
+             int i, c;
+
+             for (i = mtext_nchars (mt) - 1; i >= 0; i--)
+               {
+                 c = mtext_ref_char (mt, i);
+                 if (ENCODE_CHAR (charset, c) == MCHAR_INVALID_CODE)
+                   break;
+               }
+             if (i < 0)
+               {
+                 p0 = MPLIST_NEXT (p0);
+                 n++;
+               }
+             else
+               {
+                 if (! p_copied)
+                   {
+                     p = mplist_copy (p);
+                     mplist_set (pl, Mplist, p);
+                     M17N_OBJECT_UNREF (p);
+                     p_copied = 1;
+                     p0 = p;
+                     while (n-- > 0)
+                       p0 = MPLIST_NEXT (p0);
+                   }     
+                 mplist_pop (p0);
+                 M17N_OBJECT_UNREF (mt);
+               }
+           }
+         if (! MPLIST_TAIL_P (p))
+           pl = MPLIST_NEXT (pl);
+         else
+           {
+             mplist_pop (pl);
+             M17N_OBJECT_UNREF (p);
+           }
+       }
+    }
+  if (MPLIST_TAIL_P (plist))
+    {
+      M17N_OBJECT_UNREF (plist);
+      return NULL;
+    }      
+  return plist;
+}
+
+/* The returned Plist must be UNREFed.  */
+
+static MPlist *
+get_candidate_list (MInputContextInfo *ic_info, MPlist *args)
+{
+  MCharset *charset = get_select_charset (ic_info);
+  MPlist *plist;
+  int column;
+  int i, len;
+
+  plist = resolve_variable (ic_info, Mcandidates_group_size);
+  column = MPLIST_INTEGER (plist);
+
+  plist = MPLIST_PLIST (args);
+  if (! plist)
+    return NULL;
+  if (charset)
+    {
+      plist = adjust_candidates (plist, charset);
+      if (! plist)
+       return NULL;
+    }
+  else
+    M17N_OBJECT_REF (plist);
+
+  if (column == 0)
+    return plist;
+
+  if (MPLIST_MTEXT_P (plist))
+    {
+      MText *mt = MPLIST_MTEXT (plist);
+      MPlist *next = MPLIST_NEXT (plist);
+
+      if (MPLIST_TAIL_P (next))
+       M17N_OBJECT_REF (mt);
+      else
+       {
+         mt = mtext_dup (mt);
+         while (! MPLIST_TAIL_P (next))
+           {
+             mt = mtext_cat (mt, MPLIST_MTEXT (next));
+             next = MPLIST_NEXT (next);
+           }
+       }
+      M17N_OBJECT_UNREF (plist);
+      plist = mplist ();
+      len = mtext_nchars (mt);
+      if (len <= column)
+       mplist_add (plist, Mtext, mt);
+      else
+       {
+         for (i = 0; i < len; i += column)
+           {
+             int to = (i + column < len ? i + column : len);
+             MText *sub = mtext_copy (mtext (), 0, mt, i, to);
+                                                      
+             mplist_add (plist, Mtext, sub);
+             M17N_OBJECT_UNREF (sub);
+           }
+       }
+      M17N_OBJECT_UNREF (mt);
+    }
+  else if (MPLIST_PLIST_P (plist))
+    {
+      MPlist *tail = plist;
+      MPlist *new = mplist ();
+      MPlist *this = mplist ();
+      int count = 0;
+
+      MPLIST_DO (tail, tail)
+       {
+         MPlist *p = MPLIST_PLIST (tail);
+
+         MPLIST_DO (p, p)
+           {
+             MText *mt = MPLIST_MTEXT (p);
+
+             if (count == column)
+               {
+                 mplist_add (new, Mplist, this);
+                 M17N_OBJECT_UNREF (this);
+                 this = mplist ();
+                 count = 0;
+               }
+             mplist_add (this, Mtext, mt);
+             count++;
+           }
+       }
+      mplist_add (new, Mplist, this);
+      M17N_OBJECT_UNREF (this);
+      mplist_set (plist, Mnil, NULL);
+      MPLIST_DO (tail, new)
+       {
+         MPlist *elt = MPLIST_PLIST (tail);
+
+         mplist_add (plist, Mplist, elt);
+       }
+      M17N_OBJECT_UNREF (new);
+    }
+
+  return plist;
+}
+
+
+static MPlist *
+regularize_action (MPlist *action_list, MInputContextInfo *ic_info)
+{
+  MPlist *action = NULL;
+  MSymbol name;
+  MPlist *args;
+
+  if (MPLIST_SYMBOL_P (action_list))
+    {
+      MSymbol var = MPLIST_SYMBOL (action_list);
+      MPlist *p;
+
+      MPLIST_DO (p, ic_info->vars)
+       if (MPLIST_SYMBOL (MPLIST_PLIST (p)) == var)
+         break;
+      if (MPLIST_TAIL_P (p))
+       return NULL;
+      action = MPLIST_NEXT (MPLIST_PLIST (p));
+      mplist_set (action_list, MPLIST_KEY (action), MPLIST_VAL (action));
+    }
+
+  if (MPLIST_PLIST_P (action_list))
+    {
+      action = MPLIST_PLIST (action_list);
+      if (MPLIST_SYMBOL_P (action))
+       {
+         name = MPLIST_SYMBOL (action);
+         args = MPLIST_NEXT (action);
+         if (name == Minsert
+             && MPLIST_PLIST_P (args))
+           mplist_set (action, Msymbol, M_candidates);
+       }
+      else if (MPLIST_MTEXT_P (action) || MPLIST_PLIST_P (action))
+       {
+         action = mplist ();
+         mplist_push (action, Mplist, MPLIST_VAL (action_list));
+         mplist_push (action, Msymbol, M_candidates);
+         mplist_set (action_list, Mplist, action);
+         M17N_OBJECT_UNREF (action);
+       }
+    }
+  else if (MPLIST_MTEXT_P (action_list) || MPLIST_INTEGER_P (action_list))
+    {
+      action = mplist ();
+      mplist_push (action, MPLIST_KEY (action_list), MPLIST_VAL (action_list));
+      mplist_push (action, Msymbol, Minsert);
+      mplist_set (action_list, Mplist, action);
+      M17N_OBJECT_UNREF (action);
+    }
+  return action;
+}
+
+/* Perform list of actions in ACTION_LIST for the current input
+   context IC.  If unhandle action was not performed, return 0.
+   Otherwise, return -1.  */
+
+static int
+take_action_list (MInputContext *ic, MPlist *action_list)
+{
+  MInputContextInfo *ic_info = (MInputContextInfo *) ic->info;
+  MPlist *candidate_list = ic->candidate_list;
+  int candidate_index = ic->candidate_index;
+  int candidate_show = ic->candidate_show;
+  MTextProperty *prop;
+
+  MPLIST_DO (action_list, action_list)
+    {
+      MPlist *action = regularize_action (action_list, ic_info);
+      MSymbol name;
+      MPlist *args;
+
+      if (! action)
+       continue;
+      name = MPLIST_SYMBOL (action);
+      args = MPLIST_NEXT (action);
+
+      MDEBUG_PRINT1 (" %s", MSYMBOL_NAME (name));
+      if (name == Minsert)
+       {
+         if (MPLIST_SYMBOL_P (args))
+           {
+             args = resolve_variable (ic_info, MPLIST_SYMBOL (args));
+             if (! MPLIST_MTEXT_P (args) && ! MPLIST_INTEGER_P (args))
+               continue;
+           }
+         if (MPLIST_MTEXT_P (args))
+           preedit_insert (ic, ic->cursor_pos, MPLIST_MTEXT (args), 0);
+         else                  /* MPLIST_INTEGER_P (args)) */
+           preedit_insert (ic, ic->cursor_pos, NULL, MPLIST_INTEGER (args));
+       }
+      else if (name == M_candidates)
+       {
+         MPlist *plist = get_candidate_list (ic_info, args);
+         MPlist *pl;
+         int len;
+
+         if (! plist)
+           continue;
+         if (MPLIST_PLIST_P (plist) && MPLIST_TAIL_P (plist))
+           {
+             M17N_OBJECT_UNREF (plist);
+             continue;
+           }
+         if (MPLIST_MTEXT_P (plist))
+           {
+             preedit_insert (ic, ic->cursor_pos, NULL,
+                             mtext_ref_char (MPLIST_MTEXT (plist), 0));
+             len = 1;
+           }
+         else
+           {
+             MText * mt = MPLIST_MTEXT (MPLIST_PLIST (plist));
+
+             preedit_insert (ic, ic->cursor_pos, mt, 0);
+             len = mtext_nchars (mt);
+           }
+         pl = mplist_copy (plist);
+         M17N_OBJECT_UNREF (plist);
+         mtext_put_prop (ic->preedit,
+                         ic->cursor_pos - len, ic->cursor_pos,
+                         Mcandidate_list, pl);
+         M17N_OBJECT_UNREF (pl);
+         mtext_put_prop (ic->preedit,
+                         ic->cursor_pos - len, ic->cursor_pos,
+                         Mcandidate_index, (void *) 0);
+       }
+      else if (name == Mselect)
+       {
+         int start, end;
+         int code, idx, gindex;
+         int pos = ic->cursor_pos;
+         MPlist *group;
+         int idx_decided = 0;
+
+         if (pos == 0
+             || ! (prop = mtext_get_property (ic->preedit, pos - 1,
+                                              Mcandidate_list)))
+           continue;
+         idx = (int) mtext_get_prop (ic->preedit, pos - 1, Mcandidate_index);
+         group = find_candidates_group (mtext_property_value (prop), idx,
+                                        &start, &end, &gindex);
+         if (MPLIST_SYMBOL_P (args))
+           {
+             code = marker_code (MPLIST_SYMBOL (args), 0);
+             if (code < 0)
+               {
+                 args = resolve_variable (ic_info, MPLIST_SYMBOL (args));
+                 if (! MPLIST_INTEGER_P (args))
+                   continue;
+                 idx = start + MPLIST_INTEGER (args);
+                 if (idx < start || idx >= end)
+                   continue;
+                 idx_decided = 1;
+               }                 
+           }
+         else
+           code = -1;
+
+         if (code != '[' && code != ']')
+           {
+             if (! idx_decided)
+               idx = (start
+                      + (code >= 0
+                         ? new_index (NULL, ic->candidate_index - start,
+                                      end - start - 1, MPLIST_SYMBOL (args),
+                                      NULL)
+                         : MPLIST_INTEGER (args)));
+             if (idx < 0)
+               {
+                 find_candidates_group (mtext_property_value (prop), -1,
+                                        NULL, &end, NULL);
+                 idx = end - 1;
+               }
+             else if (idx >= end
+                      && MPLIST_TAIL_P (MPLIST_NEXT (group)))
+               idx = 0;
+           }
+         else
+           {
+             int ingroup_index = idx - start;
+             int len;
+
+             group = mtext_property_value (prop);
+             len = mplist_length (group);
+             if (code == '[')
+               {
+                 gindex--;
+                 if (gindex < 0)
+                   gindex = len - 1;;
+               }
+             else
+               {
+                 gindex++;
+                 if (gindex >= len)
+                   gindex = 0;
+               }
+             for (idx = 0; gindex > 0; gindex--, group = MPLIST_NEXT (group))
+               idx += (MPLIST_MTEXT_P (group)
+                       ? mtext_nchars (MPLIST_MTEXT (group))
+                       : mplist_length (MPLIST_PLIST (group)));
+             len = (MPLIST_MTEXT_P (group)
+                    ? mtext_nchars (MPLIST_MTEXT (group))
+                    : mplist_length (MPLIST_PLIST (group)));
+             if (ingroup_index >= len)
+               ingroup_index = len - 1;
+             idx += ingroup_index;
+           }
+         update_candidate (ic, prop, idx);
+         MDEBUG_PRINT1 ("(%d)", idx);
+       }
+      else if (name == Mshow)
+       ic->candidate_show = 1;
+      else if (name == Mhide)
+       ic->candidate_show = 0;
+      else if (name == Mdelete)
+       {
+         int len = mtext_nchars (ic->preedit);
+         int pos;
+         int to;
+
+         if (MPLIST_SYMBOL_P (args)
+             && surrounding_pos (MPLIST_SYMBOL (args), &pos))
+           {
+             to = ic->cursor_pos + pos;
+             if (to < 0)
+               {
+                 delete_surrounding_text (ic, to);
+                 to = 0;
+               }
+             else if (to > len)
+               {
+                 delete_surrounding_text (ic, to - len);
+                 to = len;
+               }
+           }
+         else
+           {
+             to = (MPLIST_SYMBOL_P (args)
+                   ? new_index (ic, ic->cursor_pos, len, MPLIST_SYMBOL (args),
+                                ic->preedit)
+                   : MPLIST_INTEGER (args));
+             if (to < 0)
+               to = 0;
+             else if (to > len)
+               to = len;
+             pos = to - ic->cursor_pos;
+           }
+         MDEBUG_PRINT1 ("(%d)", pos);
+         if (to < ic->cursor_pos)
+           preedit_delete (ic, to, ic->cursor_pos);
+         else if (to > ic->cursor_pos)
+           preedit_delete (ic, ic->cursor_pos, to);
+       }
+      else if (name == Mmove)
+       {
+         int len = mtext_nchars (ic->preedit);
+         int pos
+           = (MPLIST_SYMBOL_P (args)
+              ? new_index (ic, ic->cursor_pos, len, MPLIST_SYMBOL (args),
+                           ic->preedit)
+              : MPLIST_INTEGER (args));
+
+         if (pos < 0)
+           pos = 0;
+         else if (pos > len)
+           pos = len;
+         if (pos != ic->cursor_pos)
+           {
+             ic->cursor_pos = pos;
+             ic->preedit_changed = 1;
+           }
+         MDEBUG_PRINT1 ("(%d)", ic->cursor_pos);
+       }
+      else if (name == Mmark)
+       {
+         int code = marker_code (MPLIST_SYMBOL (args), 0);
+
+         if (code < 0)
+           {
+             mplist_put (ic_info->markers, MPLIST_SYMBOL (args),
+                         (void *) ic->cursor_pos);
+             MDEBUG_PRINT1 ("(%d)", ic->cursor_pos);
+           }
+       }
+      else if (name == Mpushback)
+       {
+         if (MPLIST_INTEGER_P (args) || MPLIST_SYMBOL_P (args))
+           {
+             int num;
+
+             if (MPLIST_SYMBOL_P (args))
+               {
+                 args = resolve_variable (ic_info, MPLIST_SYMBOL (args));
+                 if (MPLIST_INTEGER_P (args))
+                   num = MPLIST_INTEGER (args);
+                 else
+                   num = 0;
+               }
+             else
+               num = MPLIST_INTEGER (args);
+
+             if (num > 0)
+               ic_info->key_head -= num;
+             else if (num == 0)
+               ic_info->key_head = 0;
+             else
+               ic_info->key_head = - num;
+             if (ic_info->key_head > ic_info->used)
+               ic_info->key_head = ic_info->used;
+           }
+         else if (MPLIST_MTEXT_P (args))
+           {
+             MText *mt = MPLIST_MTEXT (args);
+             int i, len = mtext_nchars (mt);
+             MSymbol key;
+
+             ic_info->key_head--;
+             for (i = 0; i < len; i++)
+               {
+                 key = one_char_symbol[MTEXT_DATA (mt)[i]];
+                 if (ic_info->key_head + i < ic_info->used)
+                   ic_info->keys[ic_info->key_head + i] = key;
+                 else
+                   MLIST_APPEND1 (ic_info, keys, key, MERROR_IM);
+               }
+           }
+         else
+           {
+             MPlist *plist = MPLIST_PLIST (args), *pl;
+             int i = 0;
+             MSymbol key;
+
+             ic_info->key_head--;
+
+             MPLIST_DO (pl, plist)
+               {
+                 key = MPLIST_SYMBOL (pl);
+                 if (ic_info->key_head < ic_info->used)
+                   ic_info->keys[ic_info->key_head + i] = key;
+                 else
+                   MLIST_APPEND1 (ic_info, keys, key, MERROR_IM);
+                 i++;
+               }
+           }
+       }
+      else if (name == Mpop)
+       {
+         if (ic_info->key_head < ic_info->used)
+           MLIST_DELETE1 (ic_info, keys, ic_info->key_head, 1);
+       }
+      else if (name == Mcall)
+       {
+         MInputMethodInfo *im_info = (MInputMethodInfo *) ic->im->info;
+         MIMExternalFunc func = NULL;
+         MSymbol module, func_name;
+         MPlist *func_args, *val;
+         int ret = 0;
+
+         module = MPLIST_SYMBOL (args);
+         args = MPLIST_NEXT (args);
+         func_name = MPLIST_SYMBOL (args);
+
+         if (im_info->externals)
+           {
+             MIMExternalModule *external
+               = (MIMExternalModule *) mplist_get (im_info->externals,
+                                                   module);
+             if (external)
+               func = ((MIMExternalFunc)
+                       mplist_get_func (external->func_list, func_name));
+           }
+         if (! func)
+           continue;
+         func_args = mplist ();
+         mplist_add (func_args, Mt, ic);
+         MPLIST_DO (args, MPLIST_NEXT (args))
+           {
+             int code;
+
+             if (MPLIST_KEY (args) == Msymbol
+                 && MPLIST_KEY (args) != Mnil
+                 && (code = marker_code (MPLIST_SYMBOL (args), 0)) >= 0)
+               {
+                 code = new_index (ic, ic->cursor_pos, 
+                                   mtext_nchars (ic->preedit),
+                                   MPLIST_SYMBOL (args), ic->preedit);
+                 mplist_add (func_args, Minteger, (void *) code);
+               }
+             else
+               mplist_add (func_args, MPLIST_KEY (args), MPLIST_VAL (args));
+           }
+         val = (func) (func_args);
+         M17N_OBJECT_UNREF (func_args);
+         if (val && ! MPLIST_TAIL_P (val))
+           ret = take_action_list (ic, val);
+         M17N_OBJECT_UNREF (val);
+         if (ret < 0)
+           return ret;
+       }
+      else if (name == Mshift)
+       {
+         shift_state (ic, MPLIST_SYMBOL (args));
+       }
+      else if (name == Mundo)
+       {
+         int intarg = (MPLIST_TAIL_P (args)
+                       ? ic_info->used - 2
+                       : integer_value (ic, args, 0));
+
+         mtext_reset (ic->preedit);
+         mtext_reset (ic_info->preedit_saved);
+         mtext_reset (ic->produced);
+         M17N_OBJECT_UNREF (ic_info->vars);
+         ic_info->vars = mplist_copy (ic_info->vars_saved);
+         ic->cursor_pos = ic_info->state_pos = 0;
+         ic_info->state_key_head = ic_info->key_head
+           = ic_info->commit_key_head = 0;
+
+         shift_state (ic, Mnil);
+         if (intarg < 0)
+           {
+             if (MPLIST_TAIL_P (args))
+               {
+                 ic_info->used = 0;
+                 return -1;
+               }
+             ic_info->used += intarg;
+           }
+         else
+           ic_info->used = intarg;
+         break;
+       }
+      else if (name == Mset || name == Madd || name == Msub
+              || name == Mmul || name == Mdiv)
+       {
+         MSymbol sym = MPLIST_SYMBOL (args);
+         MPlist *value = resolve_variable (ic_info, sym);
+         int val1, val2;
+         char *op;
+
+         val1 = MPLIST_INTEGER (value);
+         args = MPLIST_NEXT (args);
+         val2 = resolve_expression (ic, args);
+         if (name == Mset)
+           val1 = val2, op = "=";
+         else if (name == Madd)
+           val1 += val2, op = "+=";
+         else if (name == Msub)
+           val1 -= val2, op = "-=";
+         else if (name == Mmul)
+           val1 *= val2, op = "*=";
+         else
+           val1 /= val2, op = "/=";
+         MDEBUG_PRINT4 ("(%s %s 0x%X(%d))",
+                        MSYMBOL_NAME (sym), op, val1, val1);
+         mplist_set (value, Minteger, (void *) val1);
+       }
+      else if (name == Mequal || name == Mless || name == Mgreater
+              || name == Mless_equal || name == Mgreater_equal)
+       {
+         int val1, val2;
+         MPlist *actions1, *actions2;
+         int ret = 0;
+
+         val1 = resolve_expression (ic, args);
+         args = MPLIST_NEXT (args);
+         val2 = resolve_expression (ic, args);
+         args = MPLIST_NEXT (args);
+         actions1 = MPLIST_PLIST (args);
+         args = MPLIST_NEXT (args);
+         if (MPLIST_TAIL_P (args))
+           actions2 = NULL;
+         else
+           actions2 = MPLIST_PLIST (args);
+         MDEBUG_PRINT3 ("(%d %s %d)? ", val1, MSYMBOL_NAME (name), val2);
+         if (name == Mequal ? val1 == val2
+             : name == Mless ? val1 < val2
+             : name == Mgreater ? val1 > val2
+             : name == Mless_equal ? val1 <= val2
+             : val1 >= val2)
+           {
+             MDEBUG_PRINT ("ok");
+             ret = take_action_list (ic, actions1);
+           }
+         else
+           {
+             MDEBUG_PRINT ("no");
+             if (actions2)
+               ret = take_action_list (ic, actions2);
+           }
+         if (ret < 0)
+           return ret;
+       }
+      else if (name == Mcond)
+       {
+         int idx = 0;
+
+         MPLIST_DO (args, args)
+           {
+             MPlist *cond;
+
+             idx++;
+             if (! MPLIST_PLIST (args))
+               continue;
+             cond = MPLIST_PLIST (args);
+             if (resolve_expression (ic, cond) != 0)
+               {
+                 MDEBUG_PRINT1 ("(%dth)", idx);
+                 if (take_action_list (ic, MPLIST_NEXT (cond)) < 0)
+                   return -1;;
+                 break;
+               }
+           }
+       }
+      else if (name == Mcommit)
+       {
+         preedit_commit (ic, 0);
+       }
+      else if (name == Munhandle)
+       {
+         preedit_commit (ic, 0);
+         return -1;
+       }
+      else
+       {
+         MInputMethodInfo *im_info = (MInputMethodInfo *) ic->im->info;
+         MPlist *actions;
+
+         if (im_info->macros
+             && (actions = mplist_get (im_info->macros, name)))
+           {
+             if (take_action_list (ic, actions) < 0)
+               return -1;
+           };
+       }
+    }
+
+  if (ic->candidate_list)
+    {
+      M17N_OBJECT_UNREF (ic->candidate_list);
+      ic->candidate_list = NULL;
+    }
+  if (ic->cursor_pos > 0
+      && (prop = mtext_get_property (ic->preedit, ic->cursor_pos - 1,
+                                    Mcandidate_list)))
+    {
+      ic->candidate_list = mtext_property_value (prop);
+      M17N_OBJECT_REF (ic->candidate_list);
+      ic->candidate_index
+       = (int) mtext_get_prop (ic->preedit, ic->cursor_pos - 1,
+                               Mcandidate_index);
+      ic->candidate_from = mtext_property_start (prop);
+      ic->candidate_to = mtext_property_end (prop);
+    }
+
+  if (candidate_list != ic->candidate_list)
+    ic->candidates_changed |= MINPUT_CANDIDATES_LIST_CHANGED;
+  if (candidate_index != ic->candidate_index)
+    ic->candidates_changed |= MINPUT_CANDIDATES_INDEX_CHANGED;
+  if (candidate_show != ic->candidate_show)
+    ic->candidates_changed |= MINPUT_CANDIDATES_SHOW_CHANGED;    
+  return 0;
+}
+
+
+/* Handle the input key KEY in the current state and map specified in
+   the input context IC.  If KEY is handled correctly, return 0.
+   Otherwise, return -1.  */
+
+static int
+handle_key (MInputContext *ic)
+{
+  MInputMethodInfo *im_info = (MInputMethodInfo *) ic->im->info;
+  MInputContextInfo *ic_info = (MInputContextInfo *) ic->info;
+  MIMMap *map = ic_info->map;
+  MIMMap *submap = NULL;
+  MSymbol key = ic_info->keys[ic_info->key_head];
+  MSymbol alias = Mnil;
+  int i;
+
+  MDEBUG_PRINT2 ("  [IM] [%s] handle `%s'", 
+                MSYMBOL_NAME (ic_info->state->name), msymbol_name (key));
+
+  if (map->submaps)
+    {
+      submap = mplist_get (map->submaps, key);
+      alias = key;
+      while (! submap
+            && (alias = msymbol_get (alias, M_key_alias))
+            && alias != key)
+       submap = mplist_get (map->submaps, alias);
+    }
+
+  if (submap)
+    {
+      if (! alias || alias == key)
+       MDEBUG_PRINT (" submap-found");
+      else
+       MDEBUG_PRINT1 (" submap-found (by alias `%s')", MSYMBOL_NAME (alias));
+      mtext_cpy (ic->preedit, ic_info->preedit_saved);
+      ic->preedit_changed = 1;
+      ic->cursor_pos = ic_info->state_pos;
+      ic_info->key_head++;
+      ic_info->map = map = submap;
+      if (map->map_actions)
+       {
+         MDEBUG_PRINT (" map-actions:");
+         if (take_action_list (ic, map->map_actions) < 0)
+           {
+             MDEBUG_PRINT ("\n");
+             return -1;
+           }
+       }
+      else if (map->submaps)
+       {
+         for (i = ic_info->state_key_head; i < ic_info->key_head; i++)
+           {
+             MSymbol key = ic_info->keys[i];
+             char *name = msymbol_name (key);
+
+             if (! name[0] || ! name[1])
+               mtext_ins_char (ic->preedit, ic->cursor_pos++, name[0], 1);
+           }
+       }
+
+      /* If this is the terminal map or we have shifted to another
+        state, perform branch actions (if any).  */
+      if (! map->submaps || map != ic_info->map)
+       {
+         if (map->branch_actions)
+           {
+             MDEBUG_PRINT (" branch-actions:");
+             if (take_action_list (ic, map->branch_actions) < 0)
+               {
+                 MDEBUG_PRINT ("\n");
+                 return -1;
+               }
+           }
+         /* If MAP is still not the root map, shift to the current
+            state.  */
+         if (ic_info->map != ic_info->state->map)
+           shift_state (ic, ic_info->state->name);
+       }
+    }
+  else
+    {
+      /* MAP can not handle KEY.  */
+
+      /* Perform branch actions if any.  */
+      if (map->branch_actions)
+       {
+         MDEBUG_PRINT (" branch-actions:");
+         if (take_action_list (ic, map->branch_actions) < 0)
+           {
+             MDEBUG_PRINT ("\n");
+             return -1;
+           }
+       }
+
+      if (map == ic_info->map)
+       {
+         /* The above branch actions didn't change the state.  */
+
+         /* If MAP is the root map of the initial state, and there
+            still exist an unhandled key, it means that the current
+            input method can not handle it.  */
+         if (map == ((MIMState *) MPLIST_VAL (im_info->states))->map
+             && ic_info->key_head < ic_info->used)
+           {
+             MDEBUG_PRINT (" unhandled\n");
+             return -1;
+           }
+
+         if (map != ic_info->state->map)
+           {
+             /* MAP is not the root map.  Shift to the root map of the
+                current state. */
+             shift_state (ic, ic_info->state->name);
+           }
+         else if (! map->branch_actions)
+           {
+             /* MAP is the root map without any default branch
+                actions.  Shift to the initial state.  */
+             shift_state (ic, Mnil);
+           }
+       }
+    }
+  MDEBUG_PRINT ("\n");
+  return 0;
+}
+
+/* Initialize IC->ic_info.  */
+
+static void
+init_ic_info (MInputContext *ic)
+{
+  MInputMethodInfo *im_info = ic->im->info;
+  MInputContextInfo *ic_info = ic->info;
+  MPlist *plist;
+  
+  MLIST_INIT1 (ic_info, keys, 8);;
+
+  ic_info->markers = mplist ();
+
+  ic_info->vars = mplist ();
+  if (im_info->configured_vars)
+    MPLIST_DO (plist, im_info->configured_vars)
+      {
+       MPlist *pl = MPLIST_PLIST (plist);
+       MSymbol name = MPLIST_SYMBOL (pl);
+
+       pl = MPLIST_NEXT (MPLIST_NEXT (MPLIST_NEXT (pl)));
+       if (MPLIST_KEY (pl) != Mt)
+         {
+           MPlist *p = mplist ();
+
+           mplist_push (ic_info->vars, Mplist, p);
+           M17N_OBJECT_UNREF (p);
+           mplist_add (p, Msymbol, name);
+           mplist_add (p, MPLIST_KEY (pl), MPLIST_VAL (pl));
+         }
+      }
+  ic_info->vars_saved = mplist_copy (ic_info->vars);
+
+  if (im_info->externals)
+    {
+      MPlist *func_args = mplist (), *plist;
+
+      mplist_add (func_args, Mt, ic);
+      MPLIST_DO (plist, im_info->externals)
+       {
+         MIMExternalModule *external = MPLIST_VAL (plist);
+         MIMExternalFunc func
+           = (MIMExternalFunc) mplist_get_func (external->func_list, Minit);
+
+         if (func)
+           (func) (func_args);
+       }
+      M17N_OBJECT_UNREF (func_args);
+    }
+
+  ic_info->preedit_saved = mtext ();
+  ic_info->tick = im_info->tick;
+}
+
+/* Finalize IC->ic_info.  */
+
+static void
+fini_ic_info (MInputContext *ic)
+{
+  MInputMethodInfo *im_info = ic->im->info;
+  MInputContextInfo *ic_info = ic->info;
+
+  if (im_info->externals)
+    {
+      MPlist *func_args = mplist (), *plist;
+
+      mplist_add (func_args, Mt, ic);
+      MPLIST_DO (plist, im_info->externals)
+       {
+         MIMExternalModule *external = MPLIST_VAL (plist);
+         MIMExternalFunc func
+           = (MIMExternalFunc) mplist_get_func (external->func_list, Mfini);
+
+         if (func)
+           (func) (func_args);
+       }
+      M17N_OBJECT_UNREF (func_args);
+    }
+
+  MLIST_FREE1 (ic_info, keys);
+  M17N_OBJECT_UNREF (ic_info->preedit_saved);
+  M17N_OBJECT_UNREF (ic_info->markers);
+  M17N_OBJECT_UNREF (ic_info->vars);
+  M17N_OBJECT_UNREF (ic_info->vars_saved);
+  M17N_OBJECT_UNREF (ic_info->preceding_text);
+  M17N_OBJECT_UNREF (ic_info->following_text);
+
+  memset (ic_info, 0, sizeof (MInputContextInfo));
+}
+
+static void
+re_init_ic (MInputContext *ic, int reload)
+{
+  MInputMethodInfo *im_info = (MInputMethodInfo *) ic->im->info;
+  MInputContextInfo *ic_info = (MInputContextInfo *) ic->info;
+  int status_changed, preedit_changed, cursor_pos_changed, candidates_changed;
+
+  status_changed = ic_info->state != (MIMState *) MPLIST_VAL (im_info->states);
+  preedit_changed = mtext_nchars (ic->preedit) > 0;
+  cursor_pos_changed = ic->cursor_pos > 0;
+  candidates_changed = 0;
+  if (ic->candidate_list)
+    {
+      candidates_changed |= MINPUT_CANDIDATES_LIST_CHANGED;
+      M17N_OBJECT_UNREF (ic->candidate_list);
+      ic->candidate_list = NULL;
+    }
+  if (ic->candidate_show)
+    {
+      candidates_changed |= MINPUT_CANDIDATES_SHOW_CHANGED;
+      ic->candidate_show = 0;
+    }
+  if (ic->candidate_index > 0)
+    {
+      candidates_changed |= MINPUT_CANDIDATES_INDEX_CHANGED;
+      ic->candidate_index = 0;
+      ic->candidate_from = ic->candidate_to = 0;
+    }
+  if (mtext_nchars (ic->produced) > 0)
+    mtext_reset (ic->produced);
+  if (mtext_nchars (ic->preedit) > 0)
+    mtext_reset (ic->preedit);
+  ic->cursor_pos = 0;
+  M17N_OBJECT_UNREF (ic->plist);
+  ic->plist = mplist ();
+
+  fini_ic_info (ic);
+  if (reload)
+    reload_im_info (im_info);
+  if (! im_info->states)
+    {
+      struct MIMState *state;
+
+      M17N_OBJECT (state, free_state, MERROR_IM);
+      state->name = msymbol ("init");
+      state->title = mtext__from_data ("ERROR!", 6, MTEXT_FORMAT_US_ASCII, 0);
+      MSTRUCT_CALLOC (state->map, MERROR_IM);
+      im_info->states = mplist ();
+      mplist_add (im_info->states, state->name, state);
+    }
+  init_ic_info (ic);
+  shift_state (ic, Mnil);
+
+  ic->status_changed = status_changed;
+  ic->preedit_changed = preedit_changed;
+  ic->cursor_pos_changed = cursor_pos_changed;
+  ic->candidates_changed = candidates_changed;
+}
+
+static void
+reset_ic (MInputContext *ic, MSymbol ignore)
+{
+  MDEBUG_PRINT ("\n  [IM] reset\n");
+  re_init_ic (ic, 0);
+}
+
+static int
+open_im (MInputMethod *im)
+{
+  MInputMethodInfo *im_info = get_im_info (im->language, im->name, Mnil, Mnil);
+
+  if (! im_info || ! im_info->states)
+    MERROR (MERROR_IM, -1);
+  im->info = im_info;
+
+  return 0;
+}
+
+static void
+close_im (MInputMethod *im)
+{
+  im->info = NULL;
+}
+
+static int
+create_ic (MInputContext *ic)
+{
+  MInputContextInfo *ic_info;
+
+  MSTRUCT_CALLOC (ic_info, MERROR_IM);
+  ic->info = ic_info;
+  init_ic_info (ic);
+  shift_state (ic, Mnil);
+  return 0;
+}
+
+static void
+destroy_ic (MInputContext *ic)
+{
+  fini_ic_info (ic);
+  free (ic->info);
+}
+
+static int
+check_reload (MInputContext *ic, MSymbol key)
+{
+  MInputMethodInfo *im_info = ic->im->info;
+  MPlist *plist = resolve_command (im_info->configured_cmds, Mat_reload);
+
+  if (! plist)
+    {
+      plist = resolve_command (global_info->configured_cmds, Mat_reload);
+      if (! plist)
+       return 0;
+    }
+  MPLIST_DO (plist, plist)
+    {
+      MSymbol this_key, alias;
+
+      if (MPLIST_MTEXT_P (plist))
+       {
+         MText *mt = MPLIST_MTEXT (plist);
+         int c = mtext_ref_char (mt, 0);
+
+         if (c >= 256)
+           continue;
+         this_key = one_char_symbol[c];
+       }
+      else
+       {
+         MPlist *pl = MPLIST_PLIST (plist);
+      
+         this_key = MPLIST_SYMBOL (pl);
+       }
+      alias = this_key;
+      while (alias != key 
+            && (alias = msymbol_get (alias, M_key_alias))
+            && alias != this_key);
+      if (alias == key)
+       break;
+    }
+  if (MPLIST_TAIL_P (plist))
+    return 0;
+
+  MDEBUG_PRINT ("\n  [IM] reload");
+  re_init_ic (ic, 1);
+  return 1;
+}
+
+
+/** Handle the input key KEY in the current state and map of IC->info.
+    If KEY is handled but no text is produced, return 0, otherwise
+    return 1.
+
+    Ignore ARG.  */
+
+static int
+filter (MInputContext *ic, MSymbol key, void *arg)
+{
+  MInputMethodInfo *im_info = (MInputMethodInfo *) ic->im->info;
+  MInputContextInfo *ic_info = (MInputContextInfo *) ic->info;
+  int i = 0;
+
+  if (check_reload (ic, key))
+    return 0;
+
+  if (! ic_info->state)
+    {
+      ic_info->key_unhandled = 1;
+      return 0;
+    }
+  mtext_reset (ic->produced);
+  ic->status_changed = ic->preedit_changed = ic->candidates_changed = 0;
+  M17N_OBJECT_UNREF (ic_info->preceding_text);
+  M17N_OBJECT_UNREF (ic_info->following_text);
+  ic_info->preceding_text = ic_info->following_text = NULL;
+  MLIST_APPEND1 (ic_info, keys, key, MERROR_IM);
+  ic_info->key_unhandled = 0;
+
+  do {
+    if (handle_key (ic) < 0)
+      {
+       /* KEY was not handled.  Delete it from the current key sequence.  */
+       if (ic_info->used > 0)
+         {
+           memmove (ic_info->keys, ic_info->keys + 1,
+                    sizeof (int) * (ic_info->used - 1));
+           ic_info->used--;
+           if (ic_info->state_key_head > 0)
+             ic_info->state_key_head--;
+           if (ic_info->commit_key_head > 0)
+             ic_info->commit_key_head--;             
+         }
+       /* This forces returning 1.  */
+       ic_info->key_unhandled = 1;
+       break;
+      }
+    if (i++ == 100)
+      {
+       mdebug_hook ();
+       reset_ic (ic, Mnil);
+       ic_info->key_unhandled = 1;
+       break;
+      }
+    /* Break the loop if all keys were handled.  */
+  } while (ic_info->key_head < ic_info->used);
+
+  /* If the current map is the root of the initial state, we should
+     produce any preedit text in ic->produced.  */
+  if (ic_info->map == ((MIMState *) MPLIST_VAL (im_info->states))->map)
+    preedit_commit (ic, 1);
+
+  if (mtext_nchars (ic->produced) > 0)
+    {
+      if (MDEBUG_FLAG ())
+       {
+         MDEBUG_PRINT1 ("\n  [IM] [%s] (produced",
+                        MSYMBOL_NAME (ic_info->state->name));
+         for (i = 0; i < mtext_nchars (ic->produced); i++)
+           MDEBUG_PRINT1 (" U+%04X", mtext_ref_char (ic->produced, i));
+         MDEBUG_PRINT (")");
+       }
+
+      mtext_put_prop (ic->produced, 0, mtext_nchars (ic->produced),
+                     Mlanguage, ic->im->language);
+    }
+  if (ic_info->commit_key_head > 0)
+    {
+      memmove (ic_info->keys, ic_info->keys + ic_info->commit_key_head,
+              sizeof (int) * (ic_info->used - ic_info->commit_key_head));
+      ic_info->used -= ic_info->commit_key_head;
+      ic_info->key_head -= ic_info->commit_key_head;
+      ic_info->state_key_head -= ic_info->commit_key_head;
+      ic_info->commit_key_head = 0;
+    }
+  if (ic_info->key_unhandled)
+    {
+      ic_info->used = 0;
+      ic_info->key_head = ic_info->state_key_head
+       = ic_info->commit_key_head = 0;
+    }
+
+  return (! ic_info->key_unhandled && mtext_nchars (ic->produced) == 0);
+}
+
+
+/** Return 1 if the last event or key was not handled, otherwise
+    return 0.
+
+    There is no need of looking up because ic->produced should already
+    contain the produced text (if any).
+
+    Ignore KEY.  */
+
+static int
+lookup (MInputContext *ic, MSymbol key, void *arg, MText *mt)
+{
+  mtext_cat (mt, ic->produced);
+  mtext_reset (ic->produced);
+  return (((MInputContextInfo *) ic->info)->key_unhandled ? -1 : 0);
+}
+
+\f
+/* Input method command handler.  */
+
+/* List of all (global and local) commands. 
+   (LANG:(IM-NAME:(COMMAND ...) ...) ...) ...
+   COMMAND is CMD-NAME:(mtext:DESCRIPTION plist:KEYSEQ ...))
+   Global commands are stored as (t (t COMMAND ...))  */
+
+\f
+/* Input method variable handler.  */
+
+
+/* Support functions for mdebug_dump_im.  */
+
+static void
+dump_im_map (MPlist *map_list, int indent)
+{
+  char *prefix;
+  MSymbol key = MPLIST_KEY (map_list);
+  MIMMap *map = (MIMMap *) MPLIST_VAL (map_list);
+
+  prefix = (char *) alloca (indent + 1);
+  memset (prefix, 32, indent);
+  prefix[indent] = '\0';
+
+  fprintf (stderr, "(\"%s\" ", msymbol_name (key));
+  if (map->map_actions)
+    mdebug_dump_plist (map->map_actions, indent + 2);
+  if (map->submaps)
+    {
+      MPLIST_DO (map_list, map->submaps)
+       {
+         fprintf (stderr, "\n%s  ", prefix);
+         dump_im_map (map_list, indent + 2);
+       }
+    }
+  if (map->branch_actions)
+    {
+      fprintf (stderr, "\n%s  (branch\n%s    ", prefix, prefix);
+      mdebug_dump_plist (map->branch_actions, indent + 4);
+      fprintf (stderr, ")");      
+    }
+  fprintf (stderr, ")");
+}
+
+
+static void
+dump_im_state (MIMState *state, int indent)
+{
+  char *prefix;
+  MPlist *map_list;
+
+  prefix = (char *) alloca (indent + 1);
+  memset (prefix, 32, indent);
+  prefix[indent] = '\0';
+
+  fprintf (stderr, "(%s", msymbol_name (state->name));
+  if (state->map->submaps)
+    {
+      MPLIST_DO (map_list, state->map->submaps)
+       {
+         fprintf (stderr, "\n%s  ", prefix);
+         dump_im_map (map_list, indent + 2);
+       }
+    }
+  fprintf (stderr, ")");
+}
+
+\f
+
+int
+minput__init ()
+{
+  Minput_driver = msymbol ("input-driver");
+
+  Minput_preedit_start = msymbol ("input-preedit-start");
+  Minput_preedit_done = msymbol ("input-preedit-done");
+  Minput_preedit_draw = msymbol ("input-preedit-draw");
+  Minput_status_start = msymbol ("input-status-start");
+  Minput_status_done = msymbol ("input-status-done");
+  Minput_status_draw = msymbol ("input-status-draw");
+  Minput_candidates_start = msymbol ("input-candidates-start");
+  Minput_candidates_done = msymbol ("input-candidates-done");
+  Minput_candidates_draw = msymbol ("input-candidates-draw");
+  Minput_set_spot = msymbol ("input-set-spot");
+  Minput_focus_move = msymbol ("input-focus-move");
+  Minput_focus_in = msymbol ("input-focus-in");
+  Minput_focus_out = msymbol ("input-focus-out");
+  Minput_toggle = msymbol ("input-toggle");
+  Minput_reset = msymbol ("input-reset");
+  Minput_get_surrounding_text = msymbol ("input-get-surrounding-text");
+  Minput_delete_surrounding_text = msymbol ("input-delete-surrounding-text");
+  Mcustomized = msymbol ("customized");
+  Mconfigured = msymbol ("configured");
+  Minherited = msymbol ("inherited");
+
+  minput_default_driver.open_im = open_im;
+  minput_default_driver.close_im = close_im;
+  minput_default_driver.create_ic = create_ic;
+  minput_default_driver.destroy_ic = destroy_ic;
+  minput_default_driver.filter = filter;
+  minput_default_driver.lookup = lookup;
+  minput_default_driver.callback_list = mplist ();
+  mplist_put_func (minput_default_driver.callback_list, Minput_reset,
+                  M17N_FUNC (reset_ic));
+  minput_driver = &minput_default_driver;
+
+  fully_initialized = 0;
+  return 0;
+}
+
+void
+minput__fini ()
+{
+  if (fully_initialized)
+    {
+      free_im_list (im_info_list);
+      if (im_custom_list)
+       free_im_list (im_custom_list);
+      if (im_config_list)
+       free_im_list (im_config_list);
+      M17N_OBJECT_UNREF (load_im_info_keys);
+    }
+
+  M17N_OBJECT_UNREF (minput_default_driver.callback_list);
+  M17N_OBJECT_UNREF (minput_driver->callback_list);
+
+}
+
+MSymbol
+minput__char_to_key (int c)
+{
+  if (c < 0 || c >= 0x100)
+    return Mnil;
+
+  return one_char_symbol[c];
+}
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+/* External API */
+
+/*** @addtogroup m17nInputMethod */
+/*** @{ */
+/*=*/
+
+/***en
+    @brief Symbol whose name is "input-method".
+ */
+/***ja
+    @brief "input-method" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
+ */
+MSymbol Minput_method;
+
+/***en
+    @name Variables: Predefined symbols for callback commands.  */
+/***ja
+    @name ÊÑ¿ô¡§ ¥³¡¼¥ë¥Ð¥Ã¥¯¥³¥Þ¥ó¥ÉÍÑÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë.  */
+/*** @{ */ 
+/***en
+    These are the predefined symbols that are used as the @c COMMAND
+    argument of callback functions of an input method driver (see
+    #MInputDriver::callback_list).  
+
+    Most of them do not require extra argument nor return any value;
+    exceptions are these:
+
+    @b Minput_get_surrounding_text: When a callback function assigned for
+    this command is called, the first element of #MInputContext::plist
+    has key #Minteger and the value specifies which portion of the
+    surrounding text should be retrieved.  If the value is positive,
+    it specifies the number of characters following the current cursor
+    position.  If the value is negative, the absolute value specifies
+    the number of characters preceding the current cursor position.
+    If the value is zero, it means that the caller just wants to know
+    if the surrounding text is currently supported or not.
+
+    If the surrounding text is currently supported, the callback
+    function must set the key of this element to #Mtext and the value
+    to the retrieved M-text.  The length of the M-text may be shorter
+    than the requested number of characters, if the available text is
+    not that long.  The length can be zero in the worst case.  Or, the
+    length may be longer if an application thinks it is more efficient
+    to return that length.
+
+    If the surrounding text is not currently supported, the callback
+    function should return without changing the first element of
+    #MInputContext::plist.
+
+    @b Minput_delete_surrounding_text: When a callback function assigned
+    for this command is called, the first element of
+    #MInputContext::plist has key #Minteger and the value specifies
+    which portion of the surrounding text should be deleted in the
+    same way as the case of Minput_get_surrounding_text.  The callback
+    function must delete the specified text.  It should not alter
+    #MInputContext::plist.  */ 
+/***ja
+    ÆþÎϥ᥽¥Ã¥É¥É¥é¥¤¥Ð¤Î¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤Ë¤ª¤¤¤Æ @c COMMAND 
+    °ú¿ô¤È¤·¤ÆÍѤ¤¤é¤ì¤ëÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë (#MInputDriver::callback_list »²¾È)¡£
+
+    ¤Û¤È¤ó¤É¤ÏÄɲäΰú¿ô¤òɬÍפȤ·¤Ê¤¤¤·ÃͤòÊÖ¤µ¤Ê¤¤¤¬¡¢°Ê²¼¤ÏÎã³°¤Ç¤¢¤ë¡£
+
+    Minput_get_surrounding_text: ¤³¤Î¥³¥Þ¥ó¥É¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿¥³¡¼¥ë¥Ð¥Ã
+    ¥¯´Ø¿ô¤¬¸Æ¤Ð¤ì¤¿ºÝ¤Ë¤Ï¡¢ #MInputContext::plist ¤ÎÂè°ìÍ×ÁǤϥ­¡¼¤È¤·
+    ¤Æ#Minteger ¤ò¤È¤ê¡¢¤½¤ÎÃͤϥµ¥é¥¦¥ó¥Ç¥£¥ó¥°¥Æ¥­¥¹¥È¤Î¤¦¤Á¤É¤ÎÉôʬ
+    ¤ò¼è¤Ã¤ÆÍè¤ë¤«¤ò»ØÄꤹ¤ë¡£Ãͤ¬Àµ¤Ç¤¢¤ì¤Ð¡¢¸½ºß¤Î¥«¡¼¥½¥ë°ÌÃ֤˳¤¯
+    ÃͤθĿôʬ¤Îʸ»ú¤ò¼è¤ë¡£Éé¤Ç¤¢¤ì¤Ð¡¢¥«¡¼¥½¥ë°ÌÃÖ¤ËÀè¹Ô¤¹¤ëÃͤÎÀäÂÐ
+    ÃÍʬ¤Îʸ»ú¤ò¼è¤ë¡£¸½ºß¥µ¥é¥¦¥ó¥É¥Æ¥­¥¹¥È¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤«¤É¤¦
+    ¤«¤òÃΤꤿ¤¤¤À¤±¤Ç¤¢¤ì¤Ð¡¢¤³¤ÎÃͤϥ¼¥í¤Ç¤âÎɤ¤¡£
+
+    ¥µ¥é¥¦¥ó¥Ç¥£¥ó¥°¥Æ¥­¥¹¥È¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤Ï
+    ¤³¤ÎÍ×ÁǤΥ­¡¼¤ò #Mtext ¤Ë¡¢Ãͤò¼è¤ê¹þ¤ó¤ÀM-text ¤ËÀßÄꤷ¤Ê¤¯¤Æ¤Ï¤Ê
+    ¤é¤Ê¤¤¡£¤â¤·¥Æ¥­¥¹¥È¤ÎŤµ¤¬½¼Ê¬¤Ç¤Ê¤±¤ì¤Ð¡¢¤³¤Î M-text ¤ÎŤµ¤ÏÍ×
+    µá¤µ¤ì¤Æ¤¤¤ëʸ»ú¿ô¤è¤êû¤¯¤ÆÎɤ¤¡£ºÇ°­¤Î¾ì¹ç 0 ¤Ç¤â¤è¤¤¤·¡¢¥¢¥×¥ê¥±¡¼
+    ¥·¥ç¥ó¦¤ÇɬÍפǸúΨŪ¤À¤È»×¤¨¤ÐŤ¯¤Æ¤âÎɤ¤¡£
+
+    ¥µ¥é¥¦¥ó¥Ç¥£¥ó¥°¥Æ¥­¥¹¥È¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¡¢¥³¡¼¥ë¥Ð¥Ã¥¯´Ø
+    ¿ô¤Ï #MInputContext::plist ¤ÎÂè°ìÍ×ÁǤòÊѹ¹¤·¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    Minput_delete_surrounding_text: ¤³¤Î¥³¥Þ¥ó¥É¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿¥³¡¼¥ë
+    ¥Ð¥Ã¥¯´Ø¿ô¤¬¸Æ¤Ð¤ì¤¿ºÝ¤Ë¤Ï¡¢#MInputContext::plist ¤ÎÂè°ìÍ×ÁǤϡ¢¥­¡¼
+    ¤È¤·¤Æ#Minteger ¤ò¤È¤ê¡¢ÃͤϺï½ü¤¹¤ë¤Ù¤­¥µ¥é¥¦¥ó¥Ç¥£¥ó¥°¥Æ¥­¥¹¥È¤ò
+    Minput_get_surrounding_text ¤ÈƱÍͤΤä¤êÊý¤Ç»ØÄꤹ¤ë¡£¥³¡¼¥ë¥Ð¥Ã¥¯
+    ´Ø¿ô¤Ï»ØÄꤵ¤ì¤¿¥Æ¥­¥¹¥È¤òºï½ü¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£¤Þ¤¿
+    #MInputContext::plist ¤òÊѤ¨¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£  */ 
+MSymbol Minput_preedit_start;
+MSymbol Minput_preedit_done;
+MSymbol Minput_preedit_draw;
+MSymbol Minput_status_start;
+MSymbol Minput_status_done;
+MSymbol Minput_status_draw;
+MSymbol Minput_candidates_start;
+MSymbol Minput_candidates_done;
+MSymbol Minput_candidates_draw;
+MSymbol Minput_set_spot;
+MSymbol Minput_toggle;
+MSymbol Minput_reset;
+MSymbol Minput_get_surrounding_text;
+MSymbol Minput_delete_surrounding_text;
+/*** @} */
+
+/*=*/
+
+/***en
+    @name Variables: Predefined symbols for special input events.
+
+    These are the predefined symbols that are used as the @c KEY
+    argument of minput_filter ().  */ 
+/***ja
+    @name ÊÑ¿ô: ÆÃÊ̤ÊÆþÎÏ¥¤¥Ù¥ó¥ÈÍÑÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë.
+
+    minput_filter () ¤Î @c KEY °ú¿ô¤È¤·¤ÆÍѤ¤¤é¤ì¤ëÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë¡£  */ 
+
+/*** @{ */ 
+/*=*/
+
+MSymbol Minput_focus_out;
+MSymbol Minput_focus_in;
+MSymbol Minput_focus_move;
+
+/*** @} */
+
+/*=*/
+/***en
+    @name Variables: Predefined symbols used in input method information.  */
+/***ja
+    @name ÊÑ¿ô: ÆþÎϥ᥽¥Ã¥É¾ðÊóÍÑÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë.  */
+/*** @{ */ 
+/*=*/
+/***en
+    These are the predefined symbols describing status of input method
+    command and variable, and are used in a return value of
+    minput_get_command () and minput_get_variable ().  */
+/***ja
+    ÆþÎϥ᥽¥Ã¥É¤Î¥³¥Þ¥ó¥É¤äÊÑ¿ô¤Î¾õÂÖ¤òɽ¤·¡¢minput_get_command () ¤È
+    minput_get_variable () ¤ÎÌá¤êÃͤȤ·¤ÆÍѤ¤¤é¤ì¤ëÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë¡£  */
+MSymbol Minherited;
+MSymbol Mcustomized;
+MSymbol Mconfigured;
+/*** @} */ 
+
+/*=*/
+
+/***en
+    @brief The default driver for internal input methods.
+
+    The variable #minput_default_driver is the default driver for
+    internal input methods.
+
+    The member MInputDriver::open_im () searches the m17n database for
+    an input method that matches the tag \< #Minput_method, $LANGUAGE,
+    $NAME\> and loads it.
+
+    The member MInputDriver::callback_list () is @c NULL.  Thus, it is
+    programmers responsibility to set it to a plist of proper callback
+    functions.  Otherwise, no feedback information (e.g. preedit text)
+    can be shown to users.
+
+    The macro M17N_INIT () sets the variable #minput_driver to the
+    pointer to this driver so that all internal input methods use it.
+
+    Therefore, unless @c minput_driver is set differently, the driver
+    dependent arguments $ARG of the functions whose name begins with
+    "minput_" are all ignored.  */
+/***ja
+    @brief ÆâÉôÆþÎϥ᥽¥Ã¥ÉÍѥǥե©¥ë¥È¥É¥é¥¤¥Ð.
+
+    ÊÑ¿ô #minput_default_driver ¤ÏÆâÉôÆþÎϥ᥽¥Ã¥ÉÍѤΥǥե©¥ë¥È¤Î¥É¥é¥¤¥Ð¤òɽ¤¹¡£
+
+    ¥á¥ó¥Ð MInputDriver::open_im () ¤Ï m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹Ã椫¤é¥¿¥° 
+    \< #Minput_method, $LANGUAGE, $NAME\> 
+    ¤Ë¹çÃפ¹¤ëÆþÎϥ᥽¥Ã¥É¤òõ¤·¡¢¤½¤ì¤ò¥í¡¼¥É¤¹¤ë¡£
+
+    ¥á¥ó¥Ð MInputDriver::callback_list () ¤Ï @c NULL ¤Ç¤¢¤ê¡¢
+    ¤·¤¿¤¬¤Ã¤Æ¡¢¥×¥í¥°¥é¥Þ¦¤ÇÀÕǤ¤ò»ý¤Ã¤Æ Å¬Àڤʥ³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤Î plist
+    ¤ËÀßÄꤷ¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤µ¤â¤Ê¤¤¤È¡¢preedit 
+    ¥Æ¥­¥¹¥È¤Ê¤É¤Î¥Õ¥£¡¼¥É¥Ð¥Ã¥¯¾ðÊ󤬥桼¥¶¤Ëɽ¼¨¤µ¤ì¤Ê¤¤¡£
+
+    ¥Þ¥¯¥í M17N_INIT () ¤ÏÊÑ¿ô #minput_driver 
+    ¤ò¤³¤Î¥É¥é¥¤¥Ð¤Ø¤Î¥Ý¥¤¥ó¥¿¤ËÀßÄꤷ¡¢Á´¤Æ¤ÎÆâÉôÆþÎϥ᥽¥Ã¥É¤¬¤³¤Î¥É¥é¥¤¥Ð¤ò»È¤¦¤è¤¦¤Ë¤¹¤ë¡£
+
+    ¤·¤¿¤¬¤Ã¤Æ¡¢@c minput_driver ¤¬¥Ç¥Õ¥©¥ë¥ÈÃͤΤޤޤǤ¢¤ì¤Ð¡¢minput_ 
+    ¤Ç»Ï¤Þ¤ë´Ø¿ô¤Î¥É¥é¥¤¥Ð¤Ë°Í¸¤¹¤ë°ú¿ô $ARG ¤Ï¤¹¤Ù¤Æ̵»ë¤µ¤ì¤ë¡£  */
+
+MInputDriver minput_default_driver;
+/*=*/
+
+/***en
+    @brief The driver for internal input methods.
+
+    The variable #minput_driver is a pointer to the input method
+    driver that is used by internal input methods.  The macro
+    M17N_INIT () initializes it to a pointer to #minput_default_driver
+    if <m17n<EM></EM>.h> is included.  */ 
+/***ja
+    @brief ÆâÉôÆþÎϥ᥽¥Ã¥ÉÍѥɥ饤¥Ð.
+
+    ÊÑ¿ô #minput_driver ¤ÏÆâÉôÆþÎϥ᥽¥Ã¥É¤Ë¤è¤Ã¤Æ»ÈÍѤµ¤ì¤Æ¤¤¤ëÆþÎÏ¥á
+    ¥½¥Ã¥É¥É¥é¥¤¥Ð¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£¥Þ¥¯¥í M17N_INIT () ¤Ï¤³¤Î¥Ý¥¤¥ó
+    ¥¿¤ò#minput_default_driver (<m17n<EM></EM>.h> ¤¬ include ¤µ¤ì¤Æ¤¤¤ë
+    »þ) ¤Ë½é´ü²½¤¹¤ë¡£  */ 
+
+MInputDriver *minput_driver;
+
+/*=*/
+/***
+    The variable #Minput_driver is a symbol for a foreign input method.
+    See @ref foreign-input-method "foreign input method" for the detail.  */
+MSymbol Minput_driver;
+
+/*=*/
+
+/***en
+    @name Functions
+*/
+/***ja
+    @name ´Ø¿ô
+*/
+/*** @{ */
+
+/*=*/
+
+/***en
+    @brief Open an input method.
+
+    The minput_open_im () function opens an input method whose
+    language and name match $LANGUAGE and $NAME, and returns a pointer
+    to the input method object newly allocated.
+
+    This function at first decides a driver for the input method as
+    described below.
+
+    If $LANGUAGE is not #Mnil, the driver pointed by the variable
+    #minput_driver is used.
+
+    If $LANGUAGE is #Mnil and $NAME has the property #Minput_driver, the
+    driver pointed to by the property value is used to open the input
+    method.  If $NAME has no such a property, @c NULL is returned.
+
+    Then, the member MInputDriver::open_im () of the driver is
+    called.  
+
+    $ARG is set in the member @c arg of the structure MInputMethod so
+    that the driver can refer to it.  */
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¤ò¥ª¡¼¥×¥ó¤¹¤ë.
+
+    ´Ø¿ô minput_open_im () ¤Ï¸À¸ì $LANGUAGE ¤È̾Á° $NAME 
+    ¤Ë¹çÃפ¹¤ëÆþÎϥ᥽¥Ã¥É¤ò¥ª¡¼¥×¥ó¤·¡¢¿·¤¿¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿ÆþÎϥ᥽¥Ã¥É¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
+    
+    ¤³¤Î´Ø¿ô¤Ï¡¢¤Þ¤ºÆþÎϥ᥽¥Ã¥ÉÍѤΥɥ饤¥Ð¤ò°Ê²¼¤Î¤è¤¦¤Ë¤·¤Æ·èÄꤹ¤ë¡£
+
+    $LANGUAGE ¤¬ #Mnil ¤Ç¤Ê¤±¤ì¤Ð¡¢ÊÑ¿ô #minput_driver 
+    ¤Ç»Ø¤µ¤ì¤Æ¤¤¤ë¥É¥é¥¤¥Ð¤òÍѤ¤¤ë¡£
+
+    $LANGUAGE ¤¬ #Mnil ¤Ç¤¢¤ê¡¢$NAME ¤¬ #Minput_driver
+    ¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¾ì¹ç¤Ë¤Ï¡¢¤½¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤǻؤµ¤ì¤Æ¤¤¤ëÆþÎϥɥ饤¥Ð¤òÍѤ¤¤ÆÆþÎϥ᥽¥Ã¥É¤ò¥ª¡¼¥×¥ó¤¹¤ë¡£
+    $NAME ¤Ë¤½¤Î¤è¤¦¤Ê¥×¥í¥Ñ¥Æ¥£¤¬Ìµ¤«¤Ã¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤¹¡£
+
+    ¼¡¤¤¤Ç¡¢¥É¥é¥¤¥Ð¤Î¥á¥ó¥Ð MInputDriver::open_im () ¤¬¸Æ¤Ð¤ì¤ë¡£
+
+    $ARG ¤Ï¹½Â¤ÂΠMInputMethod ¤Î¥á¥ó¥Ð @c arg ¤ËÀßÄꤵ¤ì¡¢¥É¥é¥¤¥Ð¤«¤é»²¾È¤Ç¤­¤ë¡£
+
+    @latexonly \IPAlabel{minput_open} @endlatexonly
+
+*/
+
+MInputMethod *
+minput_open_im (MSymbol language, MSymbol name, void *arg)
+{
+  MInputMethod *im;
+  MInputDriver *driver;
+
+  MINPUT__INIT ();
+
+  MDEBUG_PRINT2 ("  [IM] opening (%s %s) ... ",
+                msymbol_name (language), msymbol_name (name));
+  if (language)
+    {
+      if (name == Mnil)
+       MERROR (MERROR_IM, NULL);
+      driver = minput_driver;
+    }
+  else
+    {
+      driver = (MInputDriver *) msymbol_get (name, Minput_driver);
+      if (! driver)
+       MERROR (MERROR_IM, NULL);
+    }
+
+  MSTRUCT_CALLOC (im, MERROR_IM);
+  im->language = language;
+  im->name = name;
+  im->arg = arg;
+  im->driver = *driver;
+  if ((*im->driver.open_im) (im) < 0)
+    {
+      MDEBUG_PRINT (" failed\n");
+      free (im);
+      return NULL;
+    }
+  MDEBUG_PRINT (" ok\n");
+  return im;
+}
+
+/*=*/
+
+/***en
+    @brief Close an input method.
+
+    The minput_close_im () function closes the input method $IM, which
+    must have been created by minput_open_im ().  */
+
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¤ò¥¯¥í¡¼¥º¤¹¤ë.
+
+    ´Ø¿ô minput_close_im () ¤Ï¡¢ÆþÎϥ᥽¥Ã¥É $IM ¤ò¥¯¥í¡¼¥º¤¹¤ë¡£
+    ¤³¤ÎÆþÎϥ᥽¥Ã¥É $IM ¤Ï minput_open_im () ¤Ë¤è¤Ã¤Æºî¤é¤ì¤¿¤â¤Î¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£  */
+
+void
+minput_close_im (MInputMethod *im)
+{
+  MDEBUG_PRINT2 ("  [IM] closing (%s %s) ... ",
+                msymbol_name (im->name), msymbol_name (im->language));
+  (*im->driver.close_im) (im);
+  free (im);
+  MDEBUG_PRINT (" done\n");
+}
+
+/*=*/
+
+/***en
+    @brief Create an input context.
+
+    The minput_create_ic () function creates an input context object
+    associated with input method $IM, and calls callback functions
+    corresponding to @b Minput_preedit_start, @b Minput_status_start, and
+    @b Minput_status_draw in this order.
+
+    @return
+    If an input context is successfully created, minput_create_ic ()
+    returns a pointer to it.  Otherwise it returns @c NULL.  */
+
+/***ja
+    @brief ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤òÀ¸À®¤¹¤ë.
+
+    ´Ø¿ô minput_create_ic () ¤ÏÆþÎϥ᥽¥Ã¥É $IM
+    ¤ËÂбþ¤¹¤ëÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¥ª¥Ö¥¸¥§¥¯¥È¤òÀ¸À®¤·¡¢
+    @b Minput_preedit_start, @b Minput_status_start, @b Minput_status_draw
+    ¤ËÂбþ¤¹¤ë¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤ò¤³¤Î½ç¤Ë¸Æ¤Ö¡£
+
+    @return
+    ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤¬À¸À®¤µ¤ì¤¿¾ì¹ç¡¢minput_create_ic () 
+    ¤Ï¤½¤ÎÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¼ºÇÔ¤·¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤¹¡£
+      */
+
+MInputContext *
+minput_create_ic (MInputMethod *im, void *arg)
+{
+  MInputContext *ic;
+
+  MDEBUG_PRINT2 ("  [IM] creating context (%s %s) ... ",
+                msymbol_name (im->name), msymbol_name (im->language));
+  MSTRUCT_CALLOC (ic, MERROR_IM);
+  ic->im = im;
+  ic->arg = arg;
+  ic->preedit = mtext ();
+  ic->candidate_list = NULL;
+  ic->produced = mtext ();
+  ic->spot.x = ic->spot.y = 0;
+  ic->active = 1;
+  ic->plist = mplist ();
+  if ((*im->driver.create_ic) (ic) < 0)
+    {
+      MDEBUG_PRINT (" failed\n");
+      M17N_OBJECT_UNREF (ic->preedit);
+      M17N_OBJECT_UNREF (ic->produced);
+      M17N_OBJECT_UNREF (ic->plist);
+      free (ic);
+      return NULL;
+    };
+
+  if (im->driver.callback_list)
+    {
+      minput_callback (ic, Minput_preedit_start);
+      minput_callback (ic, Minput_status_start);
+      minput_callback (ic, Minput_status_draw);
+    }
+
+  MDEBUG_PRINT (" ok\n");
+  return ic;
+}
+
+/*=*/
+
+/***en
+    @brief Destroy an input context.
+
+    The minput_destroy_ic () function destroys the input context $IC,
+    which must have been created by minput_create_ic ().  It calls
+    callback functions corresponding to @b Minput_preedit_done,
+    @b Minput_status_done, and @b Minput_candidates_done in this order.  */
+
+/***ja
+    @brief ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤òÇ˲õ¤¹¤ë.
+
+    ´Ø¿ô minput_destroy_ic () ¤Ï¡¢ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È $IC ¤òÇ˲õ¤¹¤ë¡£
+    ¤³¤ÎÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤Ï minput_create_ic () 
+    ¤Ë¤è¤Ã¤Æºî¤é¤ì¤¿¤â¤Î¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£¤³¤Î´Ø¿ô¤Ï 
+    @b Minput_preedit_done, @b Minput_status_done, @b Minput_candidates_done 
+    ¤ËÂбþ¤¹¤ë¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤ò¤³¤Î½ç¤Ë¸Æ¤Ö¡£
+  */
+
+void
+minput_destroy_ic (MInputContext *ic)
+{
+  MDEBUG_PRINT2 ("  [IM] destroying context (%s %s) ... ",
+                msymbol_name (ic->im->name), msymbol_name (ic->im->language));
+  if (ic->im->driver.callback_list)
+    {
+      minput_callback (ic, Minput_preedit_done);
+      minput_callback (ic, Minput_status_done);
+      minput_callback (ic, Minput_candidates_done);
+    }
+  (*ic->im->driver.destroy_ic) (ic);
+  M17N_OBJECT_UNREF (ic->preedit);
+  M17N_OBJECT_UNREF (ic->produced);
+  M17N_OBJECT_UNREF (ic->plist);
+  MDEBUG_PRINT (" done\n");
+  free (ic);
+}
+
+/*=*/
+
+/***en
+    @brief Filter an input key.
+
+    The minput_filter () function filters input key $KEY according to
+    input context $IC, and calls callback functions corresponding to
+    @b Minput_preedit_draw, @b Minput_status_draw, and
+    @b Minput_candidates_draw if the preedit text, the status, and the
+    current candidate are changed respectively.
+
+    To make the input method commit the current preedit text (if any)
+    and shift to the initial state, call this function with #Mnil as
+    $KEY.
+
+    To inform the input method about the focus-out event, call this
+    function with @b Minput_focus_out as $KEY.
+
+    To inform the input method about the focus-in event, call this
+    function with @b Minput_focus_in as $KEY.
+
+    To inform the input method about the focus-move event (i.e. input
+    spot change within the same input context), call this function
+    with @b Minput_focus_move as $KEY.
+
+    @return
+    If $KEY is filtered out, this function returns 1.  In that case,
+    the caller should discard the key.  Otherwise, it returns 0, and
+    the caller should handle the key, for instance, by calling the
+    function minput_lookup () with the same key.  */
+
+/***ja
+    @brief ÆþÎÏ¥­¡¼¤ò¥Õ¥£¥ë¥¿¤¹¤ë.
+
+    ´Ø¿ô minput_filter () ¤ÏÆþÎÏ¥­¡¼ $KEY ¤òÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È $IC 
+    ¤Ë±þ¤¸¤Æ¥Õ¥£¥ë¥¿¤·¡¢preedit ¥Æ¥­¥¹¥È¡¢¥¹¥Æ¡¼¥¿¥¹¡¢¸½»þÅÀ¤Ç¤Î¸õÊ䤬ÊѲ½¤·¤¿»þÅÀ¤Ç¡¢¤½¤ì¤¾¤ì
+    @b Minput_preedit_draw, @b Minput_status_draw,
+    @b Minput_candidates_draw ¤ËÂбþ¤¹¤ë¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤ò¸Æ¤Ö¡£
+
+    @return 
+    $KEY ¤¬¥Õ¥£¥ë¥¿¤µ¤ì¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ï 1 ¤òÊÖ¤¹¡£
+    ¤³¤Î¾ì¹ç¸Æ¤Ó½Ð¤·Â¦¤Ï¤³¤Î¥­¡¼¤ò¼Î¤Æ¤ë¤Ù¤­¤Ç¤¢¤ë¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð 0 ¤òÊÖ¤·¡¢¸Æ¤Ó½Ð¤·Â¦¤Ï¡¢¤¿¤È¤¨¤ÐƱ¤¸¥­¡¼¤Ç´Ø¿ô minput_lookup ()
+    ¤ò¸Æ¤Ö¤Ê¤É¤·¤Æ¡¢¤³¤Î¥­¡¼¤ò½èÍý¤¹¤ë¡£
+
+    @latexonly \IPAlabel{minput_filter} @endlatexonly
+*/
+
+int
+minput_filter (MInputContext *ic, MSymbol key, void *arg)
+{
+  int ret;
+
+  if (! ic
+      || ! ic->active)
+    return 0;
+  if (ic->im->driver.callback_list
+      && mtext_nchars (ic->preedit) > 0)
+    minput_callback (ic, Minput_preedit_draw);
+
+  ret = (*ic->im->driver.filter) (ic, key, arg);
+
+  if (ic->im->driver.callback_list)
+    {
+      if (ic->preedit_changed)
+       minput_callback (ic, Minput_preedit_draw);
+      if (ic->status_changed)
+       minput_callback (ic, Minput_status_draw);
+      if (ic->candidates_changed)
+       minput_callback (ic, Minput_candidates_draw);
+    }
+
+  return ret;
+}
+
+/*=*/
+
+/***en
+    @brief Look up a text produced in the input context.
+
+    The minput_lookup () function looks up a text in the input context
+    $IC.  $KEY must be identical to the one that was used in the previous call of
+    minput_filter ().
+
+    If a text was produced by the input method, it is concatenated
+    to M-text $MT.
+
+    This function calls #MInputDriver::lookup .
+
+    @return
+    If $KEY was correctly handled by the input method, this function
+    returns 0.  Otherwise, it returns -1, even though some text
+    might be produced in $MT.  */
+
+/***ja
+    @brief ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥ÈÃæ¤Î¥Æ¥­¥¹¥È¤òõ¤¹.
+
+    ´Ø¿ô minput_lookup () ¤ÏÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È $IC Ãæ¤Î¥Æ¥­¥¹¥È¤òõ¤¹¡£
+    $KEY ¤Ï´Ø¿ô minput_filter () ¤Ø¤ÎľÁ°¤Î¸Æ¤Ó½Ð¤·¤ËÍѤ¤¤é¤ì¤¿¤â¤Î¤ÈƱ¤¸¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    ¥Æ¥­¥¹¥È¤¬ÆþÎϥ᥽¥Ã¥É¤Ë¤è¤Ã¤ÆÀ¸À®¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢¥Æ¥­¥¹¥È¤Ï M-text
+    $MT ¤ËÏ¢·ë¤µ¤ì¤ë¡£
+
+    ¤³¤Î´Ø¿ô¤Ï¡¢#MInputDriver::lookup ¤ò¸Æ¤Ö¡£
+
+    @return 
+    $KEY ¤¬ÆþÎϥ᥽¥Ã¥É¤Ë¤è¤Ã¤ÆŬÀڤ˽èÍý¤Ç¤­¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ï 0 ¤òÊÖ¤¹¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤¹¡£
+    ¤³¤Î¾ì¹ç¤Ç¤â $MT ¤Ë²¿¤é¤«¤Î¥Æ¥­¥¹¥È¤¬À¸À®¤µ¤ì¤Æ¤¤¤ë¤³¤È¤¬¤¢¤ë¡£
+
+    @latexonly \IPAlabel{minput_lookup} @endlatexonly  */
+
+int
+minput_lookup (MInputContext *ic, MSymbol key, void *arg, MText *mt)
+{
+  return (ic ? (*ic->im->driver.lookup) (ic, key, arg, mt) : -1);
+}
+/*=*/
+
+/***en
+    @brief Set the spot of the input context.
+
+    The minput_set_spot () function sets the spot of input context $IC
+    to coordinate ($X, $Y ) with the height specified by $ASCENT and $DESCENT .
+    The semantics of these values depends on the input method driver.
+
+    For instance, a driver designed to work in a CUI environment may
+    use $X and $Y as the column- and row numbers, and may ignore $ASCENT and
+    $DESCENT .  A driver designed to work in a window system may
+    interpret $X and $Y as the pixel offsets relative to the origin of the
+    client window, and may interpret $ASCENT and $DESCENT as the ascent- and
+    descent pixels of the line at ($X . $Y ).
+
+    $FONTSIZE specifies the fontsize of preedit text in 1/10 point.
+
+    $MT and $POS are the M-text and the character position at the spot.
+    $MT may be @c NULL, in which case, the input method cannot get
+    information about the text around the spot.  */
+
+/***ja
+    @brief ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤Î¥¹¥Ý¥Ã¥È¤òÀßÄꤹ¤ë.
+
+    ´Ø¿ô minput_set_spot () ¤Ï¡¢ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È $IC ¤Î¥¹¥Ý¥Ã¥È¤ò¡¢ºÂɸ ($X, $Y )
+    ¤Î°ÌÃ֤ˠ¡¢¹â¤µ $ASCENT¡¢ $DESCENT 
+    ¤ÇÀßÄꤹ¤ë¡£ ¤³¤ì¤é¤ÎÃͤΰÕÌ£¤ÏÆþÎϥ᥽¥Ã¥É¥É¥é¥¤¥Ð¤Ë°Í¸¤¹¤ë¡£
+
+    ¤¿¤È¤¨¤Ð CUI ´Ä¶­¤ÇÆ°ºî¤¹¤ë¥É¥é¥¤¥Ð¤Ï $X ¤È $Y 
+    ¤ò¤½¤ì¤¾¤ìÎó¤È¹Ô¤ÎÈÖ¹æ¤È¤·¤ÆÍѤ¤¡¢$ASCENT ¤È $DESCENT 
+    ¤ò̵»ë¤¹¤ë¤«¤â¤·¤ì¤Ê¤¤¡£ ¤Þ¤¿¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥àÍѤΥɥ饤¥Ð¤Ï
+    $X ¤È $Y ¤ò¥¯¥é¥¤¥¢¥ó¥È¥¦¥£¥ó¥É¥¦¤Î¸¶ÅÀ¤«¤é¤Î¥ª¥Õ¥»¥Ã¥È¤ò¥Ô¥¯¥»¥ëñ°Ì¤Çɽ¤·¤¿¤â¤Î¤È¤·¤Æ°·¤¤¡¢
+    $ASCENT ¤È $DESCENT ¤ò ($X . $Y )
+    ¤ÎÎó¤Î¥¢¥»¥ó¥È¤È¥Ç¥£¥»¥ó¥È¤ò¥Ô¥¯¥»¥ëñ°Ì¤Çɽ¤·¤¿¤â¤Î¤È¤·¤Æ°·¤¦¤«¤â¤·¤ì¤Ê¤¤¡£
+
+    $FONTSIZE ¤Ë¤Ï preedit ¥Æ¥­¥¹¥È¤Î¥Õ¥©¥ó¥È¥µ¥¤¥º¤ò 1/10 ¥Ý¥¤¥ó¥Èñ°Ì¤Ç»ØÄꤹ¤ë¡£
+
+    $MT ¤È $POS ¤Ï¤½¤Î¥¹¥Ý¥Ã¥È¤Î M-text ¤Èʸ»ú°ÌÃ֤Ǥ¢¤ë¡£$MT ¤Ï @c
+    NULL ¤Ç¤â¤è¤¯¡¢¤½¤Î¾ì¹ç¤Ë¤ÏÆþÎϥ᥽¥Ã¥É¤Ï¥¹¥Ý¥Ã¥È¼þÊդΥƥ­¥¹¥È¤Ë´Ø¤¹¤ë¾ðÊó¤òÆÀ¤ë¤³¤È¤¬¤Ç¤­¤Ê¤¤¡£
+    */
+
+void
+minput_set_spot (MInputContext *ic, int x, int y,
+                int ascent, int descent, int fontsize,
+                MText *mt, int pos)
+{
+  ic->spot.x = x;
+  ic->spot.y = y;
+  ic->spot.ascent = ascent;
+  ic->spot.descent = descent;
+  ic->spot.fontsize = fontsize;
+  ic->spot.mt = mt;
+  ic->spot.pos = pos;
+  if (ic->im->driver.callback_list)
+    minput_callback (ic, Minput_set_spot);
+}
+/*=*/
+
+/***en
+    @brief Toggle input method.
+
+    The minput_toggle () function toggles the input method associated
+    with input context $IC.  */
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¤òÀÚÂؤ¨¤ë.
+
+    ´Ø¿ô minput_toggle () ¤ÏÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È $IC 
+    ¤ËÂбþÉÕ¤±¤é¤ì¤¿ÆþÎϥ᥽¥Ã¥É¤ò¥È¥°¥ë¤¹¤ë¡£
+    */
+
+void
+minput_toggle (MInputContext *ic)
+{
+  if (ic->im->driver.callback_list)
+    minput_callback (ic, Minput_toggle);
+  ic->active = ! ic->active;
+}
+
+/*=*/
+
+/***en
+    @brief Reset an input context.
+
+    The minput_reset_ic () function resets input context $IC by
+    calling a callback function corresponding to @b Minput_reset.  It
+    resets the status of $IC to its initial one.  As the
+    current preedit text is deleted without commitment, if necessary,
+    call minput_filter () with the arg @b key #Mnil to force the input
+    method to commit the preedit in advance.  */
+
+/***ja
+    @brief ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤ò¥ê¥»¥Ã¥È¤¹¤ë.
+
+    ´Ø¿ô minput_reset_ic () ¤Ï @b Minput_reset ¤ËÂбþ¤¹¤ë¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô
+    ¤ò¸Æ¤Ö¤³¤È¤Ë¤è¤Ã¤ÆÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È $IC ¤ò¥ê¥»¥Ã¥È¤¹¤ë¡£¥ê¥»¥Ã¥È¤È¤Ï¡¢
+    ¼ÂºÝ¤Ë¤ÏÆþÎϥ᥽¥Ã¥É¤ò½é´ü¾õÂ֤˰ܤ¹¤³¤È¤Ç¤¢¤ë¡£¸½ºßÆþÎÏÃæ¤Î¥Æ¥­¥¹
+    ¥È¤Ï¥³¥ß¥Ã¥È¤µ¤ì¤ë¤³¤È¤Ê¤¯ºï½ü¤µ¤ì¤ë¤Î¤Ç¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é
+    ¥à¤Ï¡¢É¬Íפʤé¤Ðͽ¤á minput_filter () ¤ò°ú¿ô @b key #Mnil ¤Ç¸Æ¤ó¤Ç
+    ¶¯À©Åª¤Ë¥×¥ê¥¨¥Ç¥£¥Ã¥È¥Æ¥­¥¹¥È¤ò¥³¥ß¥Ã¥È¤µ¤»¤ë¤³¤È¡£  */
+
+void
+minput_reset_ic (MInputContext *ic)
+{
+  if (ic->im->driver.callback_list)
+    minput_callback (ic, Minput_reset);
+}
+
+/*=*/
+
+/***en
+    @brief Get title and icon filename of an input method.
+
+    The minput_get_title_icon () function returns a plist containing a
+    title and icon filename (if any) of an input method specified by
+    $LANGUAGE and $NAME.
+
+    The first element of the plist has key #Mtext and the value is an
+    M-text of the title for identifying the input method.  The second
+    element (if any) has key #Mtext and the value is an M-text of the
+    icon image (absolute) filename for the same purpose.
+
+    @return
+    If there exists a specified input method and it defines an title,
+    a plist is returned.  Otherwise, NULL is returned.  The caller
+    must free the plist by m17n_object_unref ().  */
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¤Î¥¿¥¤¥È¥ë¤È¥¢¥¤¥³¥óÍÑ¥Õ¥¡¥¤¥ë̾¤òÆÀ¤ë.
+
+    ´Ø¿ô minput_get_title_icon () ¤Ï¡¢ $LANGUAGE ¤È $NAME ¤Ç»ØÄꤵ¤ì¤ë
+    ÆþÎϥ᥽¥Ã¥É¤Î¥¿¥¤¥È¥ë¤È¡Ê¤¢¤ì¤Ð¡Ë¥¢¥¤¥³¥óÍÑ¥Õ¥¡¥¤¥ë¤ò´Þ¤à plist ¤ò
+    ÊÖ¤¹¡£
+
+    plist ¤ÎÂè°ìÍ×ÁǤϡ¢#Mtext ¤ò¥­¡¼¤Ë»ý¤Á¡¢ÃͤÏÆþÎϥ᥽¥Ã¥É¤ò¼±Ê̤¹¤ë
+    ¥¿¥¤¥È¥ë¤òɽ¤¹ M-text ¤Ç¤¢¤ë¡£ÂèÆóÍ×ÁǤ¬¤¢¤ì¤Ð¡¢¥­¡¼¤Ï #Mtext ¤Ç¤¢
+    ¤ê¡¢Ãͤϼ±ÊÌÍÑ¥¢¥¤¥³¥ó²èÁü¥Õ¥¡¥¤¥ë¤ÎÀäÂХѥ¹¤òɽ¤¹ M-text ¤Ç¤¢¤ë¡£
+
+    @return
+    »ØÄê¤ÎÆþÎϥ᥽¥Ã¥É¤¬Â¸ºß¤·¡¢¥¿¥¤¥È¥ë¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ì¤Ð
+     plist ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð NULL ¤òÊÖ¤¹¡£¸Æ½Ð¦¤Ï
+     ´Ø¿ô m17n_object_unref () ¤òÍѤ¤¤Æ plist ¤ò²òÊü¤·¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£  */
+
+MPlist *
+minput_get_title_icon (MSymbol language, MSymbol name)
+{
+  MInputMethodInfo *im_info;
+  MPlist *plist;
+  char *file = NULL;
+  MText *mt;
+
+  MINPUT__INIT ();
+
+  im_info = get_im_info (language, name, Mnil, Mtitle);
+  if (! im_info || !im_info->title)
+    return NULL;
+  mt = mtext_get_prop (im_info->title, 0, Mtext);
+  if (mt)
+    file = mdatabase__find_file ((char *) MTEXT_DATA (mt));
+  else
+    {
+      char *buf = alloca (MSYMBOL_NAMELEN (language) + MSYMBOL_NAMELEN (name)
+                         + 12);
+
+      sprintf (buf, "icons/%s-%s.png", (char *) MSYMBOL_NAME (language), 
+              (char *) MSYMBOL_NAME (name));
+      file = mdatabase__find_file (buf);
+      if (! file && language == Mt)
+       {
+         sprintf (buf, "icons/%s.png", (char *) MSYMBOL_NAME (name));
+         file = mdatabase__find_file (buf);
+       }
+    }
+
+  plist = mplist ();
+  mplist_add (plist, Mtext, im_info->title);
+  if (file)
+    {
+      mt = mtext__from_data (file, strlen (file), MTEXT_FORMAT_UTF_8, 1);
+      free (file);
+      mplist_add (plist, Mtext, mt);
+      M17N_OBJECT_UNREF (mt);
+    }
+  return plist;
+}
+
+/*=*/
+
+/***en
+    @brief Get description text of an input method.
+
+    The minput_get_description () function returns an M-text that
+    describes the input method specified by $LANGUAGE and $NAME.
+
+    @return
+    If the specified input method has a description text, a pointer to
+    #MText is returned.  The caller has to free it by m17n_object_unref ().
+    If the input method does not have a description text, @c NULL is
+    returned.  */
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¤ÎÀâÌÀ¥Æ¥­¥¹¥È¤òÆÀ¤ë.
+
+    ´Ø¿ô minput_get_description () ¤Ï¡¢$LANGUAGE ¤È $NAME ¤Ë¤è¤Ã¤Æ»ØÄê
+    ¤µ¤ì¤¿ÆþÎϥ᥽¥Ã¥É¤òÀâÌÀ¤¹¤ë M-text ¤òÊÖ¤¹¡£
+
+    @return
+    »ØÄꤵ¤ì¤¿ÆþÎϥ᥽¥Ã¥É¤¬ÀâÌÀ¤¹¤ë¥Æ¥­¥¹¥È¤ò»ý¤Ã¤Æ¤¤¤ì¤Ð¡¢
+    #MText ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¸Æ¤Ó½Ð¤·Â¦¤Ï¡¢¤½¤ì¤ò m17n_object_unref
+    () ¤òÍѤ¤¤Æ²òÊü¤·¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£ÆþÎϥ᥽¥Ã¥É¤ËÀâÌÀ¥Æ¥­¥¹¥È¤¬Ìµ¤±
+    ¤ì¤Ð@c NULL ¤òÊÖ¤¹¡£ */
+
+MText *
+minput_get_description (MSymbol language, MSymbol name)
+{
+  MInputMethodInfo *im_info;
+  MSymbol extra;
+
+  MINPUT__INIT ();
+
+  if (name != Mnil)
+    extra = Mnil;
+  else
+    extra = language, language = Mt;
+
+  im_info = get_im_info (language, name, extra, Mdescription);
+  if (! im_info || ! im_info->description)
+    return NULL;
+  M17N_OBJECT_REF (im_info->description);
+  return im_info->description;
+}
+
+/*=*/
+
+/***en
+    @brief Get information about input method command(s).
+
+    The minput_get_command () function returns information about
+    the command $COMMAND of the input method specified by $LANGUAGE and
+    $NAME.  An input method command is a pseudo key event to which one
+    or more actual input key sequences are assigned.
+
+    There are two kinds of commands, global and local.  A global
+    command has a global definition, and the description and the key
+    assignment may be inherited by a local command.  Each input method
+    defines a local command which has a local key assignment.  It may
+    also declare a local command that inherits the definition of a
+    global command of the same name.
+
+    If $LANGUAGE is #Mt and $NAME is #Mnil, this function returns
+    information about a global command.  Otherwise information about a
+    local command is returned.
+
+    If $COMMAND is #Mnil, information about all commands is returned.
+
+    The return value is a @e well-formed plist (@ref m17nPlist) of this
+    format:
+@verbatim
+  ((NAME DESCRIPTION STATUS [KEYSEQ ...]) ...)
+@endverbatim
+    @c NAME is a symbol representing the command name.
+
+    @c DESCRIPTION is an M-text describing the command, or #Mnil if the
+    command has no description.
+
+    @c STATUS is a symbol representing how the key assignment is decided.
+    The value is #Mnil (the default key assignment), @b Mcustomized (the
+    key assignment is customized by per-user customization file), or
+    @b Mconfigured (the key assignment is set by the call of
+    minput_config_command ()).  For a local command only, it may also
+    be @b Minherited (the key assignment is inherited from the
+    corresponding global command).
+
+    @c KEYSEQ is a plist of one or more symbols representing a key
+    sequence assigned to the command.  If there's no KEYSEQ, the
+    command is currently disabled (i.e. no key sequence can trigger
+    actions of the command).
+
+    If $COMMAND is not #Mnil, the first element of the returned plist
+    contains the information about $COMMAND.
+
+    @return
+
+    If the requested information was found, a pointer to a non-empty
+    plist is returned.  As the plist is kept in the library, the
+    caller must not modify nor free it.
+
+    Otherwise (the specified input method or the specified command
+    does not exist), @c NULL is returned.  */
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¤Î¥³¥Þ¥ó¥É¤Ë´Ø¤¹¤ë¾ðÊó¤òÆÀ¤ë.
+
+    ´Ø¿ô minput_get_command () ¤Ï¡¢$LANGUAGE ¤È $NAME ¤Ç»ØÄꤵ¤ì¤ëÆþÎÏ
+    ¥á¥½¥Ã¥É¤Î¥³¥Þ¥ó¥É $COMMAND ¤Ë´Ø¤¹¤ë¾ðÊó¤òÊÖ¤¹¡£ÆþÎϥ᥽¥Ã¥É¤Î¥³¥Þ
+    ¥ó¥É¤È¤Ï¡¢µ¿»÷¥­¡¼¥¤¥Ù¥ó¥È¤Ç¤¢¤ê¡¢£±¤Ä°Ê¾å¤Î¼ÂºÝ¤ÎÆþÎÏ¥­¡¼¥·¡¼¥¯¥¨
+    ¥ó¥¹¤¬³ä¤êÅö¤Æ¤é¤ì¤ë¡£
+
+    ¥³¥Þ¥ó¥É¤Ë¤Ï¡¢¥°¥í¡¼¥Ð¥ë¤È¥í¡¼¥«¥ë¤Î£²¼ïÎब¤¢¤ë¡£¥°¥í¡¼¥Ð¥ë¤Ê¥³¥Þ¥ó¥É
+    ¤Ï¥°¥í¡¼¥Ð¥ë¤ËÄêµÁ¤µ¤ì¡¢¥í¡¼¥«¥ë¤Ê¥³¥Þ¥ó¥É¤Ï¤½¤ÎÀâÌÀ¤È¥­¡¼³ä¤êÅö¤Æ
+    ¤ò·Ñ¾µ¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£³ÆÆþÎϥ᥽¥Ã¥É¤Ï¥í¡¼¥«¥ë¤Ê¥­¡¼³äÅö¤ò»ý¤Ä¥í¡¼
+    ¥«¥ë¤Ê¥³¥Þ¥ó¥É¤òÄêµÁ¤¹¤ë¡£¤Þ¤¿Æ±Ì¾¤Î¥°¥í¡¼¥Ð¥ë¤Ê¥³¥Þ¥ó¥É¤ÎÄêµÁ¤ò·Ñ
+    ¾µ¤¹¤ë¥í¡¼¥«¥ë¤Ê¥³¥Þ¥ó¥É¤òÀë¸À¤¹¤ë¤³¤È¤â¤Ç¤­¤ë¡£
+
+    $LANGUAGE ¤¬ #Mt ¤Ç $NAME ¤¬ #Mnil ¤Î¾ì¹ç¤Ï¡¢¤³¤Î´Ø¿ô¤Ï¥°¥í¡¼¥Ð¥ë¥³
+    ¥Þ¥ó¥É¤Ë´Ø¤¹¤ë¾ðÊó¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¥í¡¼¥«¥ë¥³¥Þ¥ó¥É¤Ë´Ø¤¹¤ë¤â
+    ¤Î¤òÊÖ¤¹¡£
+
+    $COMMAND ¤¬ #Mnil ¤Î¾ì¹ç¤Ï¡¢¤¹¤Ù¤Æ¤Î¥³¥Þ¥ó¥É¤Ë´Ø¤¹¤ë¾ðÊó¤òÊÖ¤¹¡£
+
+    Ìá¤êÃͤϰʲ¼¤Î·Á¼°¤Î @e well-formed plist (@ref m17nPlist) ¤Ç¤¢¤ë¡£
+
+@verbatim
+  ((NAME DESCRIPTION STATUS [KEYSEQ ...]) ...)
+@endverbatim
+    @c NAME ¤Ï¥³¥Þ¥ó¥É̾¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    @c DESCRIPTION ¤Ï¥³¥Þ¥ó¥É¤òÀâÌÀ¤¹¤ë M-text ¤Ç¤¢¤ë¤«¡¢ÀâÌÀ¤¬Ìµ¤¤¾ì¹ç¤Ë
+    ¤Ï #Mnil ¤Ç¤¢¤ë¡£
+
+    @c STATUS ¤Ï¥­¡¼³ä¤êÅö¤Æ¤¬¤É¤Î¤è¤¦¤ËÄê¤á¤é¤ì¤ë¤«¤ò¤¢¤é¤ï¤¹¥·¥ó¥Ü¥ë
+    ¤Ç¤¢¤ê¡¢¤½¤ÎÃͤϠ#Mnil ¡Ê¥Ç¥Õ¥©¥ë¥È¤Î³ä¤êÅö¤Æ¡Ë, @b Mcustomized ¡Ê¥æ¡¼
+    ¥¶Ëè¤Î¥«¥¹¥¿¥Þ¥¤¥º¥Õ¥¡¥¤¥ë¤Ë¤è¤Ã¤Æ¥«¥¹¥¿¥Þ¥¤¥º¤µ¤ì¤¿³ä¤êÅö¤Æ¡Ë,
+    @b Mconfigured ¡Êminput_config_command ()¤ò¸Æ¤Ö¤³¤È¤Ë¤è¤Ã¤ÆÀßÄꤵ¤ì¤ë
+    ³ä¤êÅö¤Æ¡Ë¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£¥í¡¼¥«¥ë¥³¥Þ¥ó¥É¤Î¾ì¹ç¤Ë¤Ï¡¢
+    @b Minherited ¡ÊÂбþ¤¹¤ë¥°¥í¡¼¥Ð¥ë¥³¥Þ¥ó¥É¤«¤é¤Î·Ñ¾µ¤Ë¤è¤ë³ä¤êÅö¤Æ¡Ë
+    ¤Ç¤â¤è¤¤¡£
+
+    @c KEYSEQ ¤Ï£±¤Ä°Ê¾å¤Î¥·¥ó¥Ü¥ë¤«¤é¤Ê¤ë plist ¤Ç¤¢¤ê¡¢³Æ¥·¥ó¥Ü¥ë¤Ï¥³¥Þ
+    ¥ó¥É¤Ë³ä¤êÅö¤Æ¤é¤ì¤Æ¤¤¤ë¥­¡¼¥·¡¼¥¯¥¨¥ó¥¹¤òɽ¤¹¡£KEYSEQ ¤¬Ìµ¤¤¾ì¹ç¤Ï¡¢
+    ¤½¤Î¥³¥Þ¥ó¥É¤Ï¸½¾õ¤Ç»ÈÍÑÉÔǽ¤Ç¤¢¤ë¡£¡Ê¤¹¤Ê¤ï¤Á¥³¥Þ¥ó¥É¤ÎÆ°ºî¤òµ¯
+    Æ°¤Ç¤­¤ë¥­¡¼¥·¡¼¥¯¥¨¥ó¥¹¤¬Ìµ¤¤¡£¡Ë
+
+    $COMMAND ¤¬ #Mnil ¤Ç¤Ê¤±¤ì¤Ð¡¢ÊÖ¤µ¤ì¤ë plist ¤ÎºÇ½é¤ÎÍ×ÁǤϡ¢
+    $COMMAND ¤Ë´Ø¤¹¤ë¾ðÊó¤ò´Þ¤à¡£
+
+    @return
+
+    µá¤á¤é¤ì¤¿¾ðÊ󤬸«¤Ä¤«¤ì¤Ð¡¢¶õ¤Ç¤Ê¤¤ plist ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¥ê¥¹
+    ¥È¤Ï¥é¥¤¥Ö¥é¥ê¤¬´ÉÍý¤·¤Æ¤¤¤ë¤Î¤Ç¡¢¸Æ½Ð¦¤¬Êѹ¹¤·¤¿¤ê²òÊü¤·¤¿¤ê¤¹¤ë
+    ¤³¤È¤Ï¤Ç¤­¤Ê¤¤¡£
+
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢¤¹¤Ê¤ï¤Á»ØÄê¤ÎÆþÎϥ᥽¥Ã¥É¤ä¥³¥Þ¥ó¥É¤¬Â¸ºß¤·¤Ê¤±¤ì¤Ð
+    @c NULL ¤òÊÖ¤¹¡£  */
+
+#if EXAMPLE_CODE
+MText *
+get_im_command_description (MSymbol language, MSymbol name, MSymbol command)
+{
+  /* Return a description of the command COMMAND of the input method
+     specified by LANGUAGE and NAME.  */
+  MPlist *cmd = minput_get_command (langauge, name, command);
+  MPlist *plist;
+
+  if (! cmds)
+    return NULL;
+  plist = mplist_value (cmds); /* (NAME DESCRIPTION STATUS KEY-SEQ ...) */
+  plist = mplist_next (plist); /* (DESCRIPTION STATUS KEY-SEQ ...) */
+  return  (mplist_key (plist) == Mtext
+          ? (MText *) mplist_value (plist)
+          : NULL);
+}
+#endif
+
+MPlist *
+minput_get_command (MSymbol language, MSymbol name, MSymbol command)
+{
+  MInputMethodInfo *im_info;
+
+  MINPUT__INIT ();
+
+  im_info = get_im_info (language, name, Mnil, Mcommand);
+  if (! im_info
+      || ! im_info->configured_cmds
+      || MPLIST_TAIL_P (im_info->configured_cmds))
+    return NULL;
+  if (command == Mnil)
+    return im_info->configured_cmds;
+  return mplist__assq (im_info->configured_cmds, command);
+}
+
+/*=*/
+
+/***en
+    @brief Configure the key sequence of an input method command.
+
+    The minput_config_command () function assigns a list of key
+    sequences $KEYSEQLIST to the command $COMMAND of the input method
+    specified by $LANGUAGE and $NAME.
+
+    If $KEYSEQLIST is a non-empty plist, it must be a list of key
+    sequences, and each key sequence must be a plist of symbols.
+
+    If $KEYSEQLIST is an empty plist, any configuration and
+    customization of the command are cancelled, and default key
+    sequences become effective.
+
+    If $KEYSEQLIST is NULL, the configuration of the command is
+    canceled, and the original key sequences (what saved in per-user
+    customization file, or the default one) become effective.
+
+    In the latter two cases, $COMMAND can be #Mnil to make all the
+    commands of the input method the target of the operation.
+
+    If $NAME is #Mnil, this function configures the key assignment of a
+    global command, not that of a specific input method.
+
+    The configuration takes effect for input methods opened or
+    re-opened later in the current session.  In order to make the
+    configuration take effect for the future session, it must be saved
+    in a per-user customization file by the function
+    minput_save_config ().
+
+    @return
+    If the operation was successful, this function returns 0,
+    otherwise returns -1.  The operation fails in these cases:
+    <ul>
+    <li>$KEYSEQLIST is not in a valid form.
+    <li>$COMMAND is not available for the input method.
+    <li>$LANGUAGE and $NAME do not specify an existing input method.
+    </ul>
+
+    @seealso
+    minput_get_commands (), minput_save_config ().
+*/
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¤Î¥³¥Þ¥ó¥É¤Î¥­¡¼¥·¡¼¥¯¥¨¥ó¥¹¤òÀßÄꤹ¤ë.
+
+    ´Ø¿ô minput_config_command () ¤Ï¥­¡¼¥·¡¼¥¯¥¨¥ó¥¹¤Î¥ê¥¹¥È
+    $KEYSEQLIST ¤ò¡¢$LANGUAGE ¤È $NAME ¤Ë¤è¤Ã¤Æ»ØÄꤵ¤ì¤ëÆþÎϥ᥽¥Ã¥É¤Î
+    ¥³¥Þ¥ó¥É $COMMAND ¤Ë³ä¤êÅö¤Æ¤ë¡£
+
+    $KEYSEQLIST ¤¬¶õ¥ê¥¹¥È¤Ç¤Ê¤±¤ì¤Ð¡¢¥­¡¼¥·¡¼¥¯¥¨¥ó¥¹¤Î¥ê¥¹¥È¤Ç¤¢¤ê¡¢
+    ³Æ¥­¡¼¥·¡¼¥¯¥¨¥ó¥¹¤Ï¥·¥ó¥Ü¥ë¤Î plist ¤Ç¤¢¤ë¡£
+
+    $KEYSEQLIST ¤¬¶õ¤Î plist ¤Ê¤é¤Ð¡¢¤½¤Î¥³¥Þ¥ó¥É¤ÎÀßÄê¤ä¥«¥¹¥¿¥Þ¥¤¥º¤Ï
+    ¤¹¤Ù¤Æ¥­¥ã¥ó¥»¥ë¤µ¤ì¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥­¡¼¥·¡¼¥¯¥¨¥ó¥¹¤¬Í­¸ú¤Ë¤Ê¤ë¡£
+
+    $KEYSEQLIST ¤¬ NULL ¤Ç¤¢¤ì¤Ð¡¢¤½¤Î¥³¥Þ¥ó¥É¤ÎÀßÄê¤Ï¥­¥ã¥ó¥»¥ë¤µ¤ì¡¢
+    ¸µ¤Î¥­¡¼¥·¡¼¥¯¥¨¥ó¥¹¡Ê¥æ¡¼¥¶Ëè¤Î¥«¥¹¥¿¥Þ¥¤¥º¥Õ¥¡¥¤¥ë¤ËÊݸ¤µ¤ì¤Æ¤¤
+    ¤ë¤â¤Î¡¢¤¢¤ë¤¤¤Ï¥Ç¥Õ¥©¥ë¥È¤Î¤â¤Î¡Ë¤¬Í­¸ú¤Ë¤Ê¤ë¡£
+
+    ¸å¤Î¤Õ¤¿¤Ä¤Î¾ì¹ç¤Ë¤Ï¡¢$COMMAND ¤Ï #Mnil ¤ò¤È¤ë¤³¤È¤¬¤Ç¤­¡¢»ØÄê¤ÎÆþ
+    Îϥ᥽¥Ã¥É¤ÎÁ´¤Æ¤Î¥³¥Þ¥ó¥ÉÀßÄê¤Î¥­¥ã¥ó¥»¥ë¤ò°ÕÌ£¤¹¤ë¡£
+
+    $NAME ¤¬ #Mnil ¤Ê¤é¤Ð¡¢¤³¤Î´Ø¿ô¤Ï¸Ä¡¹¤ÎÆþÎϥ᥽¥Ã¥É¤Ç¤Ï¤Ê¤¯¥°¥í¡¼¥Ð
+    ¥ë¤Ê¥³¥Þ¥ó¥É¤Î¥­¡¼³ä¤êÅö¤Æ¤òÀßÄꤹ¤ë¡£
+
+    ¤³¤ì¤é¤ÎÀßÄê¤Ï¡¢¸½¹Ô¤Î¥»¥Ã¥·¥ç¥óÃæ¤ÇÆþÎϥ᥽¥Ã¥É¤¬¥ª¡¼¥×¥ó¡Ê¤Þ¤¿¤Ï
+    ºÆ¥ª¡¼¥×¥ó¡Ë¤µ¤ì¤¿»þÅÀ¤ÇÍ­¸ú¤Ë¤Ê¤ë¡£¾­Íè¤Î¥»¥Ã¥·¥ç¥óÃæ¤Ç¤âÍ­¸ú¤Ë¤¹
+    ¤ë¤¿¤á¤Ë¤Ï¡¢´Ø¿ô minput_save_config () ¤òÍѤ¤¤Æ¥æ¡¼¥¶Ëè¤Î¥«¥¹¥¿¥Þ¥¤
+    ¥º¥Õ¥¡¥¤¥ë¤ËÊݸ¤·¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    @return
+
+    ¤³¤Î´Ø¿ô¤Ï¡¢½èÍý¤¬À®¸ù¤¹¤ì¤Ð 0 ¤ò¡¢¼ºÇÔ¤¹¤ì¤Ð -1 ¤òÊÖ¤¹¡£¼ºÇԤȤϰʲ¼¤Î¾ì¹ç¤Ç¤¢¤ë¡£
+    <ul>
+    <li>$KEYSEQLIST ¤¬Í­¸ú¤Ê·Á¼°¤Ç¤Ê¤¤¡£
+    <li>$COMMAND ¤¬»ØÄê¤ÎÆþÎϥ᥽¥Ã¥É¤ÇÍøÍѤǤ­¤Ê¤¤¡£
+    <li>$LANGUAGE ¤È $NAME ¤Ç»ØÄꤵ¤ì¤ëÆþÎϥ᥽¥Ã¥É¤¬Â¸ºß¤·¤Ê¤¤¡£
+    </ul>
+
+    @seealso
+    minput_get_commands (), minput_save_config ().
+*/
+
+#if EXAMPLE_CODE
+/* Add "C-x u" to the "start" command of Unicode input method.  */
+{
+  MSymbol start_command = msymbol ("start");
+  MSymbol unicode = msymbol ("unicode");
+  MPlist *cmd, *plist, *key_seq_list, *key_seq;
+
+  /* At first get the current key-sequence assignment.  */
+  cmd = minput_get_command (Mt, unicode, start_command);
+  if (! cmd)
+    {
+      /* The input method does not have the command "start".  Here
+        should come some error handling code.  */
+    }
+  /* Now CMD == ((start DESCRIPTION STATUS KEY-SEQUENCE ...) ...).
+     Extract the part (KEY-SEQUENCE ...).  */
+  plist = mplist_next (mplist_next (mplist_next (mplist_value (cmd))));
+  /* Copy it because we should not modify it directly.  */
+  key_seq_list = mplist_copy (plist);
+  
+  key_seq = mplist ();
+  mplist_add (key_seq, Msymbol, msymbol ("C-x"));
+  mplist_add (key_seq, Msymbol, msymbol ("u"));
+  mplist_add (key_seq_list, Mplist, key_seq);
+  m17n_object_unref (key_seq);
+
+  minput_config_command (Mt, unicode, start_command, key_seq_list);
+  m17n_object_unref (key_seq_list);
+}
+#endif
+
+int
+minput_config_command (MSymbol language, MSymbol name, MSymbol command,
+                      MPlist *keyseqlist)
+{
+  MInputMethodInfo *im_info, *config;
+  MPlist *plist;
+
+  MINPUT__INIT ();
+
+  im_info = get_im_info (language, name, Mnil, Mcommand);
+  if (! im_info)
+    MERROR (MERROR_IM, -1);
+  if (command == Mnil ? (keyseqlist && ! MPLIST_TAIL_P (keyseqlist))
+      : (! im_info->cmds
+        || ! mplist__assq (im_info->configured_cmds, command)))
+    MERROR (MERROR_IM, -1);
+  if (keyseqlist && ! MPLIST_TAIL_P (keyseqlist))
+    {
+      MPLIST_DO (plist, keyseqlist)
+       if (! check_command_keyseq (plist))
+         MERROR (MERROR_IM, -1);
+    }
+
+  config = get_config_info (im_info);
+  if (! config)
+    {
+      if (! im_config_list)
+       im_config_list = mplist ();
+      config = new_im_info (NULL, language, name, Mnil, im_config_list);
+      config->cmds = mplist ();
+      config->vars = mplist ();
+    }
+
+  if (! keyseqlist && MPLIST_TAIL_P (config->cmds))
+    /* Nothing to do.  */
+    return 0;
+
+  if (command == Mnil)
+    {
+      if (! keyseqlist)
+       {
+         /* Cancal the configuration. */
+         if (MPLIST_TAIL_P (config->cmds))
+           return 0;
+         mplist_set (config->cmds, Mnil, NULL);
+       }
+      else
+       {
+         /* Cancal the customization. */
+         MInputMethodInfo *custom = get_custom_info (im_info);
+
+         if (MPLIST_TAIL_P (config->cmds)
+             && (! custom || ! custom->cmds || MPLIST_TAIL_P (custom->cmds)))
+           /* Nothing to do.  */
+           return 0;
+         mplist_set (config->cmds, Mnil, NULL);
+         MPLIST_DO (plist, custom->cmds)
+           {
+             command = MPLIST_SYMBOL (MPLIST_PLIST (plist));
+             plist = mplist ();
+             mplist_add (plist, Msymbol, command);
+             mplist_push (config->cmds, Mplist, plist);
+             M17N_OBJECT_UNREF (plist);
+           }
+       }
+    }
+  else
+    {
+      plist = mplist__assq (config->cmds, command);
+      if (! keyseqlist)
+       {
+         /* Cancel the configuration.  */
+         if (! plist)
+           return 0;
+         mplist__pop_unref (plist);
+       }
+      else if (MPLIST_TAIL_P (keyseqlist))
+       {
+         /* Cancel the customization.  */
+         MInputMethodInfo *custom = get_custom_info (im_info);
+         int no_custom = (! custom || ! custom->cmds
+                          || ! mplist__assq (custom->cmds, command));
+         if (! plist)
+           {
+             if (no_custom)
+               return 0;
+             plist = mplist ();
+             mplist_add (config->cmds, Mplist, plist);
+             M17N_OBJECT_UNREF (plist);
+             plist = mplist_add (plist, Msymbol, command);
+           }
+         else
+           {
+             if (no_custom)
+               mplist__pop_unref (plist);
+             else
+               {
+                 plist = MPLIST_PLIST (plist); /* (NAME nil KEYSEQ ...) */
+                 plist = MPLIST_NEXT (plist);
+                 mplist_set (plist, Mnil, NULL);
+               }
+           }
+       }
+      else
+       {
+         MPlist *pl;
+
+         if (plist)
+           {
+             plist = MPLIST_NEXT (MPLIST_PLIST (plist));
+             if (! MPLIST_TAIL_P (plist))
+               mplist_set (plist, Mnil, NULL);
+           }
+         else
+           {
+             plist = mplist ();
+             mplist_add (config->cmds, Mplist, plist);
+             M17N_OBJECT_UNREF (plist);
+             plist = mplist_add (plist, Msymbol, command);
+             plist = MPLIST_NEXT (plist);
+           }
+         MPLIST_DO (keyseqlist, keyseqlist)
+           {
+             pl = mplist_copy (MPLIST_VAL (keyseqlist));
+             plist = mplist_add (plist, Mplist, pl);
+             M17N_OBJECT_UNREF (pl);
+           }
+       }
+    }
+  config_all_commands (im_info);
+  im_info->tick = time (NULL);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Get information about input method variable(s).
+
+    The minput_get_variable () function returns information about
+    variable $VARIABLE of the input method specified by $LANGUAGE and $NAME.
+    An input method variable controls behavior of an input method.
+
+    There are two kinds of variables, global and local.  A global
+    variable has a global definition, and the description and the value
+    may be inherited by a local variable.  Each input method defines a
+    local variable which has local value.  It may also declare a
+    local variable that inherits definition of a global variable of
+    the same name.
+
+    If $LANGUAGE is #Mt and $NAME is #Mnil, information about a global
+    variable is returned.  Otherwise information about a local variable
+    is returned.
+
+    If $VARIABLE is #Mnil, information about all variables is
+    returned.
+
+    The return value is a @e well-formed plist (@ref m17nPlist) of this
+    format:
+@verbatim
+  ((NAME DESCRIPTION STATUS VALUE [VALID-VALUE ...]) ...)
+@endverbatim
+    @c NAME is a symbol representing the variable name.
+
+    @c DESCRIPTION is an M-text describing the variable, or #Mnil if the
+    variable has no description.
+
+    @c STATUS is a symbol representing how the value is decided.  The
+    value is #Mnil (the default value), @b Mcustomized (the value is
+    customized by per-user customization file), or @b Mconfigured (the
+    value is set by the call of minput_config_variable ()).  For a
+    local variable only, it may also be @b Minherited (the value is
+    inherited from the corresponding global variable).
+
+    @c VALUE is the initial value of the variable.  If the key of this
+    element is #Mt, the variable has no initial value.  Otherwise, the
+    key is #Minteger, #Msymbol, or #Mtext and the value is of the
+    corresponding type.
+
+    @c VALID-VALUEs (if any) specify which values the variable can have.
+    They have the same type (i.e. having the same key) as @c VALUE except
+    for the case that VALUE is an integer.  In that case, @c VALID-VALUE
+    may be a plist of two integers specifying the range of possible
+    values.
+
+    If there no @c VALID-VALUE, the variable can have any value as long
+    as the type is the same as @c VALUE.
+
+    If $VARIABLE is not #Mnil, the first element of the returned plist
+    contains the information about $VARIABLE.
+
+    @return
+
+    If the requested information was found, a pointer to a non-empty
+    plist is returned.  As the plist is kept in the library, the
+    caller must not modify nor free it.
+
+    Otherwise (the specified input method or the specified variable
+    does not exist), @c NULL is returned.  */
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¤ÎÊÑ¿ô¤Ë´Ø¤¹¤ë¾ðÊó¤òÆÀ¤ë.
+
+    ´Ø¿ô minput_get_variable () ¤Ï¡¢$LANGUAGE ¤È $NAME ¤Ç»ØÄꤵ¤ì¤ëÆþÎÏ
+    ¥á¥½¥Ã¥É¤ÎÊÑ¿ô $VARIABLE ¤Ë´Ø¤¹¤ë¾ðÊó¤òÊÖ¤¹¡£ÆþÎϥ᥽¥Ã¥É¤ÎÊÑ¿ô¤È¤Ï¡¢
+    ÆþÎϥ᥽¥Ã¥É¤Î¿¶Éñ¤òÀ©¸æ¤¹¤ë¤â¤Î¤Ç¤¢¤ë¡£
+
+    ÊÑ¿ô¤Ë¤Ï¡¢¥°¥í¡¼¥Ð¥ë¤È¥í¡¼¥«¥ë¤Î£²¼ïÎब¤¢¤ë¡£¥°¥í¡¼¥Ð¥ë¤ÊÊÑ¿ô¤Ï¥°
+    ¥í¡¼¥Ð¥ë¤ËÄêµÁ¤µ¤ì¡¢¥í¡¼¥«¥ë¤ÊÊÑ¿ô¤Ï¤½¤ÎÀâÌÀ¤ÈÃͤò·Ñ¾µ¤¹¤ë¤³¤È¤¬¤Ç
+    ¤­¤ë¡£³ÆÆþÎϥ᥽¥Ã¥É¤Ï¥í¡¼¥«¥ë¤ÊÃͤò»ý¤Ä¥í¡¼¥«¥ë¤ÊÊÑ¿ô¤òÄêµÁ¤¹¤ë¡£
+    ¤Þ¤¿Æ±Ì¾¤Î¥°¥í¡¼¥Ð¥ë¤ÊÊÑ¿ô¤ÎÄêµÁ¤ò·Ñ¾µ¤¹¤ë¥í¡¼¥«¥ë¤ÊÊÑ¿ô¤òÀë¸À¤¹¤ë
+    ¤³¤È¤â¤Ç¤­¤ë¡£
+
+    $LANGUAGE ¤¬ #Mt ¤Ç $NAME ¤¬ #Mnil ¤Î¾ì¹ç¤Ï¡¢¤³¤Î´Ø¿ô¤Ï¥°¥í¡¼¥Ð¥ëÊÑ
+    ¿ô¤Ë´Ø¤¹¤ë¾ðÊó¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¥í¡¼¥«¥ëÊÑ¿ô¤Ë´Ø¤¹¤ë¤â¤Î¤òÊÖ¤¹¡£
+
+    $VARIABLE ¤¬ #Mnil ¤Î¾ì¹ç¤Ï¡¢¤¹¤Ù¤Æ¤Î¥³¥Þ¥ó¥É¤Ë´Ø¤¹¤ë¾ðÊó¤òÊÖ¤¹¡£
+
+    Ìá¤êÃͤϰʲ¼¤Î·Á¼°¤Î @e well-formed plist (@ref m17nPlist) ¤Ç¤¢¤ë¡£
+@verbatim
+  ((NAME DESCRIPTION STATUS VALUE [VALID-VALUE ...]) ...)
+@endverbatim
+
+    @c NAME ¤ÏÊÑ¿ô¤Î̾Á°¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    @c DESCRIPTION ¤ÏÊÑ¿ô¤òÀâÌÀ¤¹¤ë M-text ¤Ç¤¢¤ë¤«¡¢ÀâÌÀ¤¬Ìµ¤¤¾ì¹ç¤Ë¤Ï
+    #Mnil ¤Ç¤¢¤ë¡£
+
+    @c STATUS ¤ÏÃͤ¬¤É¤Î¤è¤¦¤ËÄê¤á¤é¤ì¤ë¤«¤ò¤¢¤é¤ï¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢
+    @c STATUS ¤ÎÃͤϠ#Mnil ¡Ê¥Ç¥Õ¥©¥ë¥È¤ÎÃÍ¡Ë, @b Mcustomized ¡Ê¥æ¡¼¥¶Ëè¤Î
+    ¥«¥¹¥¿¥Þ¥¤¥º¥Õ¥¡¥¤¥ë¤Ë¤è¤Ã¤Æ¥«¥¹¥¿¥Þ¥¤¥º¤µ¤ì¤¿ÃÍ¡Ë, @b Mconfigured
+    ¡Êminput_config_variable ()¤ò¸Æ¤Ö¤³¤È¤Ë¤è¤Ã¤ÆÀßÄꤵ¤ì¤ëÃ͡ˤΤ¤¤º¤ì
+    ¤«¤Ç¤¢¤ë¡£¥í¡¼¥«¥ëÊÑ¿ô¤Î¾ì¹ç¤Ë¤Ï¡¢@b Minherited ¡ÊÂбþ¤¹¤ë¥°¥í¡¼¥Ð¥ë
+    ÊÑ¿ô¤«¤é·Ñ¾µ¤·¤¿Ã͡ˤǤâ¤è¤¤¡£
+
+    @c VALUE ¤ÏÊÑ¿ô¤Î½é´üÃͤǤ¢¤ë¡£¤³¤ÎÍ×ÁǤΥ­¡¼¤¬#Mt ¤Ç¤¢¤ì¤Ð½é´üÃͤò»ý
+    ¤¿¤Ê¤¤¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢¥­¡¼¤Ï #Minteger, #Msymbol, #Mtext ¤Î¤¤¤º¤ì
+    ¤«¤Ç¤¢¤ê¡¢ÃͤϤ½¤ì¤¾¤ìÂбþ¤¹¤ë·¿¤Î¤â¤Î¤Ç¤¢¤ë¡£
+
+    @c VALID-VALUE ¤Ï¤â¤·¤¢¤ì¤Ð¡¢ÊÑ¿ô¤Î¼è¤êÆÀ¤ëÃͤò»ØÄꤹ¤ë¡£¤³¤ì¤Ï @c VALUE
+    ¤ÈƱ¤¸·¿(¤¹¤Ê¤ï¤ÁƱ¤¸¥­¡¼¤ò»ý¤Ä) ¤Ç¤¢¤ë¤¬¡¢Îã³°¤È¤·¤Æ @c VALUE ¤¬
+    integer ¤Î¾ì¹ç¤Ï @c VALID-VALUE ¤Ï²Äǽ¤ÊÃͤÎÈϰϤò¼¨¤¹Æó¤Ä¤ÎÀ°¿ô¤«¤é
+    ¤Ê¤ë plist ¤È¤Ê¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
+
+    @c VALID-VALUE ¤¬¤Ê¤±¤ì¤Ð¡¢ÊÑ¿ô¤Ï @c VALUE ¤ÈƱ¤¸·¿¤Ç¤¢¤ë¸Â¤ê¤¤¤«¤Ê¤ëÃͤâ
+    ¤È¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
+
+    $VARIABLE ¤¬ #Mnil ¤Ç¤Ê¤±¤ì¤Ð¡¢ÊÖ¤µ¤ì¤ë plist ¤ÎºÇ½é¤ÎÍ×ÁǤÏ
+    $VARIABLE ¤Ë´Ø¤¹¤ë¾ðÊó¤ò´Þ¤à¡£
+
+    @return
+
+    µá¤á¤é¤ì¤¿¾ðÊ󤬸«¤Ä¤«¤ì¤Ð¡¢¶õ¤Ç¤Ê¤¤ plist ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¥ê¥¹
+    ¥È¤Ï¥é¥¤¥Ö¥é¥ê¤¬´ÉÍý¤·¤Æ¤¤¤ë¤Î¤Ç¡¢¸Æ½Ð¦¤¬Êѹ¹¤·¤¿¤ê²òÊü¤·¤¿¤ê¤¹¤ë
+    ¤³¤È¤Ï¤Ç¤­¤Ê¤¤¡£
+
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢¤¹¤Ê¤ï¤Á»ØÄê¤ÎÆþÎϥ᥽¥Ã¥É¤äÊÑ¿ô¤¬Â¸ºß¤·¤Ê¤±¤ì¤Ð
+    @c NULL ¤òÊÖ¤¹¡£ */
+
+MPlist *
+minput_get_variable (MSymbol language, MSymbol name, MSymbol variable)
+{
+  MInputMethodInfo *im_info;
+
+  MINPUT__INIT ();
+
+  im_info = get_im_info (language, name, Mnil, Mvariable);
+  if (! im_info || ! im_info->configured_vars)
+    return NULL;
+  if (variable == Mnil)
+    return im_info->configured_vars;
+  return mplist__assq (im_info->configured_vars, variable);
+}
+
+/*=*/
+
+/***en
+    @brief Configure the value of an input method variable.
+
+    The minput_config_variable () function assigns $VALUE to the
+    variable $VARIABLE of the input method specified by $LANGUAGE and
+    $NAME.
+
+    If $VALUE is a non-empty plist, it must be a plist of one element
+    whose key is #Minteger, #Msymbol, or #Mtext, and the value is of
+    the corresponding type.  That value is assigned to the variable.
+
+    If $VALUE is an empty plist, any configuration and customization
+    of the variable are canceled, and the default value is assigned to
+    the variable.
+
+    If $VALUE is NULL, the configuration of the variable is canceled,
+    and the original value (what saved in per-user customization file,
+    or the default value) is assigned to the variable.
+
+    In the latter two cases, $VARIABLE can be #Mnil to make all the
+    variables of the input method the target of the operation.
+
+    If $NAME is #Mnil, this function configures the value of global
+    variable, not that of a specific input method.
+
+    The configuration takes effect for input methods opened or
+    re-opened later in the current session.  To make the configuration
+    take effect for the future session, it must be saved in a per-user
+    customization file by the function minput_save_config ().
+
+    @return
+
+    If the operation was successful, this function returns 0,
+    otherwise returns -1.  The operation fails in these cases:
+    <ul>
+    <li>$VALUE is not in a valid form, the type does not match the
+    definition, or the value is our of range.
+    <li>$VARIABLE is not available for the input method.
+    <li>$LANGUAGE and $NAME do not specify an existing input method.  
+    </ul>
+
+    @seealso
+    minput_get_variable (), minput_save_config ().  */
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¤ÎÊÑ¿ô¤ÎÃͤòÀßÄꤹ¤ë.
+
+    ´Ø¿ô minput_config_variable () ¤ÏÃÍ $VALUE ¤ò¡¢$LANGUAGE ¤È $NAME
+    ¤Ë¤è¤Ã¤Æ»ØÄꤵ¤ì¤ëÆþÎϥ᥽¥Ã¥É¤ÎÊÑ¿ô $VARIABLE ¤Ë³ä¤êÅö¤Æ¤ë¡£
+
+    $VALUE ¤¬ ¶õ¥ê¥¹¥È¤Ç¤Ê¤±¤ì¤Ð¡¢£±Í×ÁǤΠplist ¤Ç¤¢¤ê¡¢¤½¤Î¥­¡¼¤Ï
+    #Minteger, #Msymbol, #Mtext ¤Î¤¤¤º¤ì¤«¡¢ÃͤÏÂбþ¤¹¤ë·¿¤Î¤â¤Î¤Ç¤¢¤ë¡£
+    ¤³¤ÎÃͤ¬ÊÑ¿ô $VARIABLE ¤Ë³ä¤êÅö¤Æ¤é¤ì¤ë¡£
+
+    $VALUE ¤¬ ¶õ¥ê¥¹¥È¤Ç¤¢¤ì¤Ð¡¢ÊÑ¿ô¤ÎÀßÄê¤È¥«¥¹¥¿¥Þ¥¤¥º¤¬¥­¥ã¥ó¥»¥ë¤µ
+    ¤ì¡¢¥Ç¥Õ¥©¥ë¥ÈÃͤ¬ÊÑ¿ô $VARIABLE ¤Ë³ä¤êÅö¤Æ¤é¤ì¤ë¡£
+
+    $VALUE ¤¬ NULL ¤Ç¤¢¤ì¤Ð¡¢ÊÑ¿ô¤ÎÀßÄê¤Ï¥­¥ã¥ó¥»¥ë¤µ¤ì¡¢¸µ¤ÎÃ͡ʥ桼¥¶
+    Ëè¤Î¥«¥¹¥¿¥Þ¥¤¥º¥Õ¥¡¥¤¥ëÃæ¤ÎÃÍ¡¢¤Þ¤¿¤Ï¥Ç¥Õ¥©¥ë¥È¤ÎÃ͡ˤ¬³ä¤êÅö¤Æ¤é¤ì¤ë¡£
+
+    ¸å¤Î¤Õ¤¿¤Ä¤Î¾ì¹ç¤Ë¤Ï¡¢$VARIABLE ¤Ï #Mnil ¤ò¤È¤ë¤³¤È¤¬¤Ç¤­¡¢»ØÄꤵ¤ì
+    ¤¿ÆþÎϥ᥽¥Ã¥É¤ÎÁ´¤Æ¤ÎÊÑ¿ôÀßÄê¤Î¥­¥ã¥ó¥»¥ë¤ò°ÕÌ£¤¹¤ë¡£
+
+    $NAME ¤¬ #Mnil ¤Ê¤é¤Ð¡¢¤³¤Î´Ø¿ô¤Ï¸Ä¡¹¤ÎÆþÎϥ᥽¥Ã¥É¤Ç¤Ï¤Ê¤¯¥°¥í¡¼¥Ð
+    ¥ë¤ÊÊÑ¿ô¤ÎÃͤòÀßÄꤹ¤ë¡£
+
+    ¤³¤ì¤é¤ÎÀßÄê¤Ï¡¢¸½¹Ô¤Î¥»¥Ã¥·¥ç¥óÃæ¤ÇÆþÎϥ᥽¥Ã¥É¤¬¥ª¡¼¥×¥ó¡Ê¤Þ¤¿¤Ï
+    ºÆ¥ª¡¼¥×¥ó¡Ë¤µ¤ì¤¿»þÅÀ¤ÇÍ­¸ú¤Ë¤Ê¤ë¡£¾­Íè¤Î¥»¥Ã¥·¥ç¥óÃæ¤Ç¤âÍ­¸ú¤Ë¤¹
+    ¤ë¤¿¤á¤Ë¤Ï¡¢´Ø¿ô minput_save_config () ¤òÍѤ¤¤Æ¥æ¡¼¥¶Ëè¤Î¥«¥¹¥¿¥Þ¥¤
+    ¥º¥Õ¥¡¥¤¥ë¤ËÊݸ¤·¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    @return
+
+    ¤³¤Î´Ø¿ô¤Ï¡¢½èÍý¤¬À®¸ù¤¹¤ì¤Ð 0 ¤ò¡¢¼ºÇÔ¤¹¤ì¤Ð -1 ¤òÊÖ¤¹¡£¼ºÇԤȤϰʲ¼¤Î¾ì¹ç¤Ç¤¢¤ë¡£
+    <ul>
+    <li>$VALUE¤¬Í­¸ú¤Ê·Á¼°¤Ç¤Ê¤¤¡£·¿¤¬ÄêµÁ¤Ë¹ç¤ï¤Ê¤¤¡¢¤Þ¤¿¤ÏÃͤ¬Èϰϳ°¤Ç¤¢¤ë¡£
+    <li>$VARIABLE ¤¬»ØÄê¤ÎÆþÎϥ᥽¥Ã¥É¤ÇÍøÍѤǤ­¤Ê¤¤¡£
+    <li>$LANGUAGE ¤È $NAME ¤Ç»ØÄꤵ¤ì¤ëÆþÎϥ᥽¥Ã¥É¤¬Â¸ºß¤·¤Ê¤¤¡£
+    </ul>
+
+    @seealso
+    minput_get_commands (), minput_save_config ().
+*/
+int
+minput_config_variable (MSymbol language, MSymbol name, MSymbol variable,
+                       MPlist *value)
+{
+  MInputMethodInfo *im_info, *config;
+  MPlist *plist;
+
+  MINPUT__INIT ();
+
+  im_info = get_im_info (language, name, Mnil, Mvariable);
+  if (! im_info)
+    MERROR (MERROR_IM, -1);
+  if (variable == Mnil ? (value && ! MPLIST_TAIL_P (value))
+      : (! im_info->vars
+        || ! (plist = mplist__assq (im_info->configured_vars, variable))))
+    MERROR (MERROR_IM, -1);
+
+  if (value && ! MPLIST_TAIL_P (value))
+    {
+      plist = MPLIST_PLIST (plist);
+      plist = MPLIST_NEXT (plist); /* (DESC STATUS VALUE VALIDS ...) */
+      plist = MPLIST_NEXT (plist); /* (STATUS VALUE VALIDS ...) */
+      plist = MPLIST_NEXT (plist); /* (VALUE VALIDS ...) */
+      if (MPLIST_KEY (plist) != Mt
+         && ! check_variable_value (value, plist))
+       MERROR (MERROR_IM, -1);
+    }
+
+  config = get_config_info (im_info);
+  if (! config)
+    {
+      if (! im_config_list)
+       im_config_list = mplist ();
+      config = new_im_info (NULL, language, name, Mnil, im_config_list);
+      config->cmds = mplist ();
+      config->vars = mplist ();
+    }
+
+  if (! value && MPLIST_TAIL_P (config->vars))
+    /* Nothing to do.  */
+    return 0;
+
+  if (variable == Mnil)
+    {
+      if (! value)
+       {
+         /* Cancel the configuration.  */
+         if (MPLIST_TAIL_P (config->vars))
+           return 0;
+         mplist_set (config->vars, Mnil, NULL);
+       }
+      else
+       {
+         /* Cancel the customization.  */
+         MInputMethodInfo *custom = get_custom_info (im_info);
+
+         if (MPLIST_TAIL_P (config->vars)
+             && (! custom || ! custom->vars || MPLIST_TAIL_P (custom->vars)))
+           /* Nothing to do.  */
+           return 0;
+         mplist_set (config->vars, Mnil, NULL);
+         MPLIST_DO (plist, custom->vars)
+           {
+             variable = MPLIST_SYMBOL (MPLIST_PLIST (plist));
+             plist = mplist ();
+             mplist_add (plist, Msymbol, variable);
+             mplist_push (config->vars, Mplist, plist);
+             M17N_OBJECT_UNREF (plist);
+           }
+       }
+    }
+  else
+    {
+      plist = mplist__assq (config->vars, variable);
+      if (! value)
+       {
+         /* Cancel the configuration.  */
+         if (! plist)
+           return 0;
+         mplist__pop_unref (plist);
+       }
+      else if (MPLIST_TAIL_P (value))
+       {
+         /* Cancel the customization.  */
+         MInputMethodInfo *custom = get_custom_info (im_info);
+         int no_custom = (! custom || ! custom->vars
+                          || ! mplist__assq (custom->vars, variable));
+         if (! plist)
+           {
+             if (no_custom)
+               return 0;
+             plist = mplist ();
+             mplist_add (config->vars, Mplist, plist);
+             M17N_OBJECT_UNREF (plist);
+             plist = mplist_add (plist, Msymbol, variable);
+           }
+         else
+           {
+             if (no_custom)
+               mplist__pop_unref (plist);
+             else
+               {
+                 plist = MPLIST_PLIST (plist); /* (NAME nil VALUE) */
+                 plist = MPLIST_NEXT (plist);  /* ([nil VALUE]) */
+                 mplist_set (plist, Mnil ,NULL);
+               }
+           }
+       }
+      else
+       {
+         if (plist)
+           {
+             plist = MPLIST_NEXT (MPLIST_PLIST (plist));
+             if (! MPLIST_TAIL_P (plist))
+               mplist_set (plist, Mnil, NULL);
+           }
+         else
+           {
+             plist = mplist ();
+             mplist_add (config->vars, Mplist, plist);
+             M17N_OBJECT_UNREF (plist);
+             plist = mplist_add (plist, Msymbol, variable);
+             plist = MPLIST_NEXT (plist);
+           }
+         mplist_add (plist, MPLIST_KEY (value), MPLIST_VAL (value));
+       }
+    }
+  config_all_variables (im_info);
+  im_info->tick = time (NULL);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Get the name of per-user customization file.
+    
+    The minput_config_file () function returns the absolute path name
+    of per-user customization file into which minput_save_config ()
+    save configurations.  It is usually @c config.mic under the
+    directory <tt>${HOME}/.m17n.d</tt> (${HOME} is user's home
+    directory).  It is not assured that the file of the returned name
+    exists nor is readable/writable.  If minput_save_config () fails
+    and returns -1, an application program might check the file, make
+    it writable (if possible), and try minput_save_config () again.
+
+    @return
+
+    This function returns a string.  As the string is kept in the
+    library, the caller must not modify nor free it.
+
+    @seealso
+    minput_save_config ()
+*/
+/***ja
+    @brief ¥æ¡¼¥¶Ëè¤Î¥«¥¹¥¿¥Þ¥¤¥º¥Õ¥¡¥¤¥ë¤Î̾Á°¤òÆÀ¤ë.
+    
+    ´Ø¿ô minput_config_file () ¤Ï¡¢´Ø¿ô minput_save_config () ¤¬ÀßÄê¤ò
+    Êݸ¤¹¤ë¥æ¡¼¥¶Ëè¤Î¥«¥¹¥¿¥Þ¥¤¥º¥Õ¥¡¥¤¥ë¤Ø¤ÎÀäÂХѥ¹Ì¾¤òÊÖ¤¹¡£Ä̾ï¤Ï¡¢¥æ¡¼¥¶
+    ¤Î¥Û¡¼¥à¥Ç¥£¥ì¥¯¥È¥ê¤Î²¼¤Î¥Ç¥£¥ì¥¯¥È¥ê @c ".m17n.d" ¤Ë¤¢¤ë@c
+    "config.mic" ¤È¤Ê¤ë¡£ÊÖ¤µ¤ì¤¿Ì¾Á°¤Î¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¤«¡¢Æɤ߽ñ¤­¤Ç
+    ¤­¤ë¤«¤ÏÊݾڤµ¤ì¤Ê¤¤¡£´Ø¿ôminput_save_config () ¤¬¼ºÇÔ¤·¤Æ -1 ¤òÊÖ
+    ¤·¤¿¾ì¹ç¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï¥Õ¥¡¥¤¥ë¤Î¸ºß¤ò³Îǧ¤·¡¢
+    ¡Ê¤Ç¤­¤ì¤Ð¡Ë½ñ¤­¹þ¤ß²Äǽ¤Ë¤·ºÆÅÙminput_save_config () ¤ò»î¤¹¤³¤È¤¬
+    ¤Ç¤­¤ë¡£
+
+    @return
+
+    ¤³¤Î´Ø¿ô¤Ïʸ»úÎó¤òÊÖ¤¹¡£Ê¸»úÎó¤Ï¥é¥¤¥Ö¥é¥ê¤¬´ÉÍý¤·¤Æ¤¤¤ë¤Î¤Ç¡¢¸Æ½Ð
+    Â¦¤¬½¤Àµ¤·¤¿¤ê²òÊü¤·¤¿¤ê¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Ê¤¤¡£
+
+    @seealso
+    minput_save_config ()
+*/
+
+char *
+minput_config_file ()
+{
+  MINPUT__INIT ();
+
+  return mdatabase__file (im_custom_mdb);
+}
+
+/*=*/
+
+/***en
+    @brief Save configurations in per-user customization file.
+
+    The minput_save_config () function saves the configurations done
+    so far in the current session into the per-user customization
+    file.
+
+    @return
+
+    If the operation was successful, 1 is returned.  If the per-user
+    customization file is currently locked, 0 is returned.  In that
+    case, the caller may wait for a while and try again.  If the
+    configuration file is not writable, -1 is returned.  In that case,
+    the caller may check the name of the file by calling
+    minput_config_file (), make it writable if possible, and try
+    again.
+
+    @seealso
+    minput_config_file ()  */
+/***ja
+    @brief ÀßÄê¤ò¥æ¡¼¥¶Ëè¤Î¥«¥¹¥¿¥Þ¥¤¥º¥Õ¥¡¥¤¥ë¤ËÊݸ¤¹¤ë.
+
+    ´Ø¿ô minput_save_config () ¤Ï¸½¹Ô¤Î¥»¥Ã¥·¥ç¥ó¤Ç¤³¤ì¤Þ¤Ç¤Ë¹Ô¤Ã¤¿ÀßÄê
+    ¤ò¥æ¡¼¥¶Ëè¤Î¥«¥¹¥¿¥Þ¥¤¥º¥Õ¥¡¥¤¥ë¤ËÊݸ¤¹¤ë¡£
+
+    @return
+
+    À®¸ù¤¹¤ì¤Ð 1 ¤òÊÖ¤¹¡£¥æ¡¼¥¶Ëè¤Î¥«¥¹¥¿¥Þ¥¤¥º¥Õ¥¡¥¤¥ë¤¬¥í¥Ã¥¯¤µ¤ì¤Æ¤¤
+    ¤ì¤Ð 0 ¤òÊÖ¤¹¡£¤³¤Î¾ì¹ç¡¢¸Æ½Ð¦¤Ï¤·¤Ð¤é¤¯ÂԤäƺƻî¹Ô¤Ç¤­¤ë¡£ÀßÄê¥Õ¥¡
+    ¥¤¥ë¤¬½ñ¤­¹þ¤ßÉԲĤξì¹ç¡¢-1 ¤òÊÖ¤¹¡£¤³¤Î¾ì¹ç¡¢minput_config_file
+    () ¤ò¸Æ¤ó¤Ç¥Õ¥¡¥¤¥ë̾¤ò¥Á¥§¥Ã¥¯¤·¡¢¤Ç¤­¤ì¤Ð½ñ¤­¹þ¤ß²Äǽ¤Ë¤·¡¢ºÆ»î¹Ô
+    ¤Ç¤­¤ë¡£
+
+    @seealso
+    minput_config_file ()  */
+
+int
+minput_save_config (void)
+{
+  MPlist *data, *tail, *plist, *p, *elt;
+  int ret;
+
+  MINPUT__INIT ();
+  ret = mdatabase__lock (im_custom_mdb);
+  if (ret <= 0)
+    return ret;
+  if (! im_config_list)
+    return 1;
+  update_custom_info ();
+  if (! im_custom_list)
+    im_custom_list = mplist ();
+
+  /* At first, reflect configuration in customization.  */
+  MPLIST_DO (plist, im_config_list)
+    {
+      MPlist *pl = MPLIST_PLIST (plist);
+      MSymbol language, name, extra, command, variable;
+      MInputMethodInfo *custom, *config;
+
+      language = MPLIST_SYMBOL (pl);
+      pl = MPLIST_NEXT (pl);
+      name = MPLIST_SYMBOL (pl);
+      pl = MPLIST_NEXT (pl);
+      extra = MPLIST_SYMBOL (pl);
+      pl = MPLIST_NEXT (pl);
+      config = MPLIST_VAL (pl);
+      custom = get_custom_info (config);
+      if (! custom)
+       custom = new_im_info (NULL, language, name, extra, im_custom_list);
+      if (config->cmds)
+       MPLIST_DO (pl, config->cmds)
+         {
+           elt = MPLIST_PLIST (pl);
+           command = MPLIST_SYMBOL (elt);
+           if (custom->cmds)
+             p = mplist__assq (custom->cmds, command);
+           else
+             custom->cmds = mplist (), p = NULL;
+           elt = MPLIST_NEXT (elt);
+           if (p)
+             {
+               p = MPLIST_NEXT (MPLIST_NEXT (MPLIST_PLIST (p)));
+               mplist_set (p, Mnil, NULL);
+             }
+           else
+             {
+               p = mplist ();
+               mplist_add (custom->cmds, Mplist, p);
+               M17N_OBJECT_UNREF (p);
+               mplist_add (p, Msymbol, command);
+               p = mplist_add (p, Msymbol, Mnil);
+               p = MPLIST_NEXT (p);
+             }
+           mplist__conc (p, elt);
+         }
+      if (config->vars)
+       MPLIST_DO (pl, config->vars)
+         {
+           elt = MPLIST_PLIST (pl);
+           variable = MPLIST_SYMBOL (elt);
+           if (custom->vars)
+             p = mplist__assq (custom->vars, variable);
+           else
+             custom->vars = mplist (), p = NULL;
+           elt = MPLIST_NEXT (elt);
+           if (p)
+             {
+               p = MPLIST_NEXT (MPLIST_NEXT (MPLIST_PLIST (p)));
+               mplist_set (p, Mnil, NULL);
+             }
+           else
+             {
+               p = mplist ();
+               mplist_add (custom->vars, Mplist, p);
+               M17N_OBJECT_UNREF (p);
+               mplist_add (p, Msymbol, variable);
+               p = mplist_add (p, Msymbol, Mnil);
+               p = MPLIST_NEXT (p);
+             }
+           mplist__conc (p, elt);
+         }
+    }
+  free_im_list (im_config_list);
+  im_config_list = NULL;
+
+  /* Next, reflect customization to the actual plist to be written.  */
+  data = tail = mplist ();
+  MPLIST_DO (plist, im_custom_list)
+    {
+      MPlist *pl = MPLIST_PLIST (plist);
+      MSymbol language, name, extra;
+      MInputMethodInfo *custom, *im_info;
+
+      language = MPLIST_SYMBOL (pl);
+      pl  = MPLIST_NEXT (pl);
+      name = MPLIST_SYMBOL (pl);
+      pl = MPLIST_NEXT (pl);
+      extra = MPLIST_SYMBOL (pl);
+      pl = MPLIST_NEXT (pl);
+      custom = MPLIST_VAL (pl);
+      if ((! custom->cmds || MPLIST_TAIL_P (custom->cmds))
+         && (! custom->vars || MPLIST_TAIL_P (custom->vars)))
+       continue;
+      im_info = lookup_im_info (im_info_list, language, name, extra);
+      if (im_info)
+       {
+         if (im_info->cmds)
+           config_all_commands (im_info);
+         if (im_info->vars)
+           config_all_variables (im_info);
+       }
+      
+      elt = NULL;
+      if (custom->cmds && ! MPLIST_TAIL_P (custom->cmds))
+       {
+         MPLIST_DO (p, custom->cmds)
+           if (! MPLIST_TAIL_P (MPLIST_NEXT (MPLIST_PLIST (p))))
+             break;
+         if (! MPLIST_TAIL_P (p))
+           {
+             elt = mplist ();
+             pl = mplist ();
+             mplist_add (elt, Mplist, pl);
+             M17N_OBJECT_UNREF (pl);
+             pl = mplist_add (pl, Msymbol, Mcommand);
+             MPLIST_DO (p, custom->cmds)
+               if (! MPLIST_TAIL_P (MPLIST_NEXT (MPLIST_PLIST (p))))
+                 pl = mplist_add (pl, Mplist, MPLIST_PLIST (p));
+           }
+       }
+      if (custom->vars && ! MPLIST_TAIL_P (custom->vars))
+       {
+         MPLIST_DO (p, custom->vars)
+           if (! MPLIST_TAIL_P (MPLIST_NEXT (MPLIST_PLIST (p))))
+             break;
+         if (! MPLIST_TAIL_P (p))
+           {
+             if (! elt)
+               elt = mplist ();
+             pl = mplist ();
+             mplist_add (elt, Mplist, pl);
+             M17N_OBJECT_UNREF (pl);
+             pl = mplist_add (pl, Msymbol, Mvariable);
+             MPLIST_DO (p, custom->vars)
+               if (! MPLIST_TAIL_P (MPLIST_NEXT (MPLIST_PLIST (p))))
+                 pl = mplist_add (pl, Mplist, MPLIST_PLIST (p));
+           }
+       }
+      if (elt)
+       {
+         pl = mplist ();
+         mplist_push (elt, Mplist, pl);
+         M17N_OBJECT_UNREF (pl);
+         pl = mplist_add (pl, Msymbol, Minput_method);
+         pl = mplist_add (pl, Msymbol, language);
+         pl = mplist_add (pl, Msymbol, name);
+         if (extra != Mnil)
+           pl = mplist_add (pl, Msymbol, extra);
+         tail = mplist_add (tail, Mplist, elt);
+         M17N_OBJECT_UNREF (elt);
+       }
+    }
+
+  mplist_push (data, Mstring, ";; -*- mode:lisp; coding:utf-8 -*-");
+  ret = mdatabase__save (im_custom_mdb, data);
+  mdatabase__unlock (im_custom_mdb);
+  M17N_OBJECT_UNREF (data);
+  return (ret < 0 ? -1 : 1);
+}
+
+/*=*/
+/*** @} */
+/*=*/
+/***en
+    @name Obsolete functions
+*/
+/***ja
+    @name Obsolete ¤Ê´Ø¿ô
+*/
+/*** @{ */
+
+/*=*/
+/***en
+    @brief Get a list of variables of an input method (obsolete).
+
+    This function is obsolete.  Use minput_get_variable () instead.
+
+    The minput_get_variables () function returns a plist (#MPlist) of
+    variables used to control the behavior of the input method
+    specified by $LANGUAGE and $NAME.  The plist is @e well-formed
+    (@ref m17nPlist) of the following format:
+
+@verbatim
+    (VARNAME (DOC-MTEXT DEFAULT-VALUE [ VALUE ... ] )
+     VARNAME (DOC-MTEXT DEFAULT-VALUE [ VALUE ... ] )
+     ...)
+@endverbatim
+
+    @c VARNAME is a symbol representing the variable name.
+
+    @c DOC-MTEXT is an M-text describing the variable.
+
+    @c DEFAULT-VALUE is the default value of the variable.  It is a
+    symbol, integer, or M-text.
+
+    @c VALUEs (if any) specifies the possible values of the variable.
+    If @c DEFAULT-VALUE is an integer, @c VALUE may be a plist (@c FROM
+    @c TO), where @c FROM and @c TO specifies a range of possible
+    values.
+
+    For instance, suppose an input method has the variables:
+
+    @li name:intvar, description:"value is an integer",
+         initial value:0, value-range:0..3,10,20
+
+    @li name:symvar, description:"value is a symbol",
+         initial value:nil, value-range:a, b, c, nil
+
+    @li name:txtvar, description:"value is an M-text",
+         initial value:empty text, no value-range (i.e. any text)
+
+    Then, the returned plist is as follows.
+
+@verbatim
+    (intvar ("value is an integer" 0 (0 3) 10 20)
+     symvar ("value is a symbol" nil a b c nil)
+     txtvar ("value is an M-text" ""))
+@endverbatim
+
+    @return
+    If the input method uses any variables, a pointer to #MPlist is
+    returned.  As the plist is kept in the library, the caller must not
+    modify nor free it.  If the input method does not use any
+    variable, @c NULL is returned.  */
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¤ÎÊÑ¿ô¥ê¥¹¥È¤òÆÀ¤ë.
+
+    ´Ø¿ô minput_get_variables () ¤Ï¡¢$LANGUAGE ¤È $NAME ¤Ë¤è¤Ã¤Æ»ØÄꤵ
+    ¤ì¤¿ÆþÎϥ᥽¥Ã¥É¤Î¿¶¤ëÉñ¤¤¤òÀ©¸æ¤¹¤ëÊÑ¿ô¤Î¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È
+    (#MPlist) ¤òÊÖ¤¹¡£¤³¤Î¥ê¥¹¥È¤Ï @e well-formed ¤Ç¤¢¤ê(@ref m17nPlist) °Ê
+    ²¼¤Î·Á¼°¤Ç¤¢¤ë¡£
+
+@verbatim
+    (VARNAME (DOC-MTEXT DEFAULT-VALUE [ VALUE ... ] )
+     VARNAME (DOC-MTEXT DEFAULT-VALUE [ VALUE ... ] )
+     ...)
+@endverbatim
+
+    @c VARNAME ¤ÏÊÑ¿ô¤Î̾Á°¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    @c DOC-MTEXT ¤ÏÊÑ¿ô¤òÀâÌÀ¤¹¤ë M-text ¤Ç¤¢¤ë¡£
+
+    @c DEFAULT-VALUE ¤ÏÊÑ¿ô¤Î¥Ç¥Õ¥©¥ë¥ÈÃͤǤ¢¤ê¡¢¥·¥ó¥Ü¥ë¡¢À°¿ô¤â¤·¤¯¤Ï
+    M-text ¤Ç¤¢¤ë¡£
+
+    @c VALUE ¤Ï¡¢¤â¤·»ØÄꤵ¤ì¤Æ¤¤¤ì¤ÐÊÑ¿ô¤Î¼è¤êÆÀ¤ëÃͤò¼¨¤¹¡£¤â¤·
+    @c DEFAULT-VALUE ¤¬À°¿ô¤Ê¤é¡¢ @c VALUE ¤Ï (@c FROM @c TO) ¤È¤¤¤¦·Á
+    ¤Î¥ê¥¹¥È¤Ç¤âÎɤ¤¡£¤³¤Î¾ì¹ç @c FROM ¤È @c TO ¤Ï²Äǽ¤ÊÃͤÎÈϰϤò¼¨¤¹¡£
+
+    Îã¤È¤·¤Æ¡¢¤¢¤ëÆþÎϥ᥽¥Ã¥É¤¬¼¡¤Î¤è¤¦¤ÊÊÑ¿ô¤ò»ý¤Ä¾ì¹ç¤ò¹Í¤¨¤è¤¦¡£
+
+    @li name:intvar, ÀâÌÀ:"value is an integer",
+        ½é´üÃÍ:0, ÃͤÎÈÏ°Ï:0..3,10,20
+
+    @li name:symvar, ÀâÌÀ:"value is a symbol",
+         ½é´üÃÍ:nil, ÃͤÎÈÏ°Ï:a, b, c, nil
+
+    @li name:txtvar, ÀâÌÀ:"value is an M-text",
+        ½é´üÃÍ:empty text, ÃͤÎÈϰϤʤ·(¤É¤ó¤Ê M-text ¤Ç¤â²Ä)
+
+    ¤³¤Î¾ì¹ç¡¢ÊÖ¤µ¤ì¤ë¥ê¥¹¥È¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤Ê¤ë¡£
+
+@verbatim
+    (intvar ("value is an integer" 0 (0 3) 10 20)
+     symvar ("value is a symbol" nil a b c nil)
+     txtvar ("value is an M-text" ""))
+@endverbatim
+
+    @return 
+    ÆþÎϥ᥽¥Ã¥É¤¬²¿¤é¤«¤ÎÊÑ¿ô¤ò»ÈÍѤ·¤Æ¤¤¤ì¤Ð #MPlist ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
+    ÊÖ¤µ¤ì¤ë¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤Ï¥é¥¤¥Ö¥é¥ê¤Ë¤è¤Ã¤Æ´ÉÍý¤µ¤ì¤Æ¤ª¤ê¡¢¸Æ¤Ó½Ð¤·Â¦¤ÇÊѹ¹¤·¤¿¤ê²òÊü¤·¤¿¤ê¤·¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+    ÆþÎϥ᥽¥Ã¥É¤¬ÊÑ¿ô¤ò°ìÀÚ»ÈÍѤ·¤Æ¤Ê¤±¤ì¤Ð¡¢@c NULL ¤òÊÖ¤¹¡£  */
+
+MPlist *
+minput_get_variables (MSymbol language, MSymbol name)
+{
+  MInputMethodInfo *im_info;
+  MPlist *vars;
+
+  MINPUT__INIT ();
+
+  im_info = get_im_info (language, name, Mnil, Mvariable);
+  if (! im_info || ! im_info->configured_vars)
+    return NULL;
+
+  M17N_OBJECT_UNREF (im_info->bc_vars);
+  im_info->bc_vars = mplist ();
+  MPLIST_DO (vars, im_info->configured_vars)
+    {
+      MPlist *plist = MPLIST_PLIST (vars);
+      MPlist *elt = mplist ();
+
+      mplist_push (im_info->bc_vars, Mplist, elt);
+      mplist_add (elt, Msymbol, MPLIST_SYMBOL (plist));
+      elt = MPLIST_NEXT (elt);
+      mplist_set (elt, Mplist, mplist_copy (MPLIST_NEXT (plist)));
+      M17N_OBJECT_UNREF (elt);
+    }
+  return im_info->bc_vars;
+}
+
+/*=*/
+
+/***en
+    @brief Set the initial value of an input method variable.
+
+    The minput_set_variable () function sets the initial value of
+    input method variable $VARIABLE to $VALUE for the input method
+    specified by $LANGUAGE and $NAME.
+
+    By default, the initial value is 0.
+
+    This setting gets effective in a newly opened input method.
+
+    @return
+    If the operation was successful, 0 is returned.  Otherwise -1 is
+    returned, and #merror_code is set to @c MERROR_IM.  */
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥ÉÊÑ¿ô¤Î½é´üÃͤòÀßÄꤹ¤ë.
+
+    ´Ø¿ô minput_set_variable () ¤Ï¡¢$LANGUAGE ¤È $NAME 
+    ¤Ë¤è¤Ã¤Æ»ØÄꤵ¤ì¤¿ÆþÎϥ᥽¥Ã¥É¤ÎÆþÎϥ᥽¥Ã¥ÉÊÑ¿ô $VARIABLE
+    ¤Î½é´üÃͤò¡¢ $VALUE ¤ËÀßÄꤹ¤ë¡£
+
+    ¥Ç¥Õ¥©¥ë¥È¤Î½é´üÃͤϠ0 ¤Ç¤¢¤ë¡£
+
+    ¤³¤ÎÀßÄê¤Ï¡¢¿·¤·¤¯¥ª¡¼¥×¥ó¤µ¤ì¤¿ÆþÎϥ᥽¥Ã¥É¤«¤éÍ­¸ú¤È¤Ê¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤·¡¢
+    #merror_code ¤ò @c MERROR_IM ¤ËÀßÄꤹ¤ë¡£  */
+
+int
+minput_set_variable (MSymbol language, MSymbol name,
+                    MSymbol variable, void *value)
+{
+  MPlist *plist, *pl;
+  MInputMethodInfo *im_info;
+  int ret;
+
+  MINPUT__INIT ();
+
+  if (variable == Mnil)
+    MERROR (MERROR_IM, -1);
+  plist = minput_get_variable (language, name, variable);
+  plist = MPLIST_PLIST (plist);
+  plist = MPLIST_NEXT (plist);
+  pl = mplist ();
+  mplist_add (pl, MPLIST_KEY (plist), value);
+  ret = minput_config_variable (language, name, variable, pl);
+  M17N_OBJECT_UNREF (pl);
+  if (ret == 0)
+    {
+      im_info = get_im_info (language, name, Mnil, Mvariable);
+      im_info->tick = 0;
+    }
+  return ret;
+}
+
+/*=*/
+
+/***en
+    @brief Get information about input method commands.
+
+    The minput_get_commands () function returns information about
+    input method commands of the input method specified by $LANGUAGE
+    and $NAME.  An input method command is a pseudo key event to which
+    one or more actual input key sequences are assigned.
+
+    There are two kinds of commands, global and local.  Global
+    commands are used by multiple input methods for the same purpose,
+    and have global key assignments.  Local commands are used only by
+    a specific input method, and have only local key assignments.
+
+    Each input method may locally change key assignments for global
+    commands.  The global key assignment for a global command is
+    effective only when the current input method does not have local
+    key assignments for that command.
+
+    If $NAME is #Mnil, information about global commands is returned.
+    In this case $LANGUAGE is ignored.
+
+    If $NAME is not #Mnil, information about those commands that have
+    local key assignments in the input method specified by $LANGUAGE
+    and $NAME is returned.
+
+    @return
+    If no input method commands are found, this function returns @c NULL.
+
+    Otherwise, a pointer to a plist is returned.  The key of each
+    element in the plist is a symbol representing a command, and the
+    value is a plist of the form COMMAND-INFO described below.
+
+    The first element of COMMAND-INFO has the key #Mtext, and the
+    value is an M-text describing the command.
+
+    If there are no more elements, that means no key sequences are
+    assigned to the command.  Otherwise, each of the remaining
+    elements has the key #Mplist, and the value is a plist whose keys are
+    #Msymbol and values are symbols representing input keys, which are
+    currently assigned to the command.
+
+    As the returned plist is kept in the library, the caller must not
+    modify nor free it.  */
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¤Î¥³¥Þ¥ó¥É¤Ë´Ø¤¹¤ë¾ðÊó¤òÆÀ¤ë.
+
+    ´Ø¿ô minput_get_commands () ¤Ï¡¢ $LANGUAGE ¤È $NAME ¤Ë¤è¤Ã¤Æ»ØÄꤵ
+    ¤ì¤¿ÆþÎϥ᥽¥Ã¥É¤ÎÆþÎϥ᥽¥Ã¥É¥³¥Þ¥ó¥É¤Ë´Ø¤¹¤ë¾ðÊó¤òÊÖ¤¹¡£ÆþÎϥ᥽¥Ã
+    ¥É¥³¥Þ¥ó¥É¤È¤Ï¡¢µ¿»÷¥­¡¼¥¤¥Ù¥ó¥È¤Ç¤¢¤ê¡¢¤½¤ì¤¾¤ì¤Ë£±¤Ä°Ê¾å¤Î¼ÂºÝ¤Î
+    ÆþÎÏ¥­¡¼¥·¡¼¥¯¥¨¥ó¥¹¤¬³ä¤êÅö¤Æ¤é¤ì¤Æ¤¤¤ë¤â¤Î¤ò»Ø¤¹¡£
+
+    ¥³¥Þ¥ó¥É¤Ë¤Ï¥°¥í¡¼¥Ð¥ë¤È¥í¡¼¥«¥ë¤Î£²¼ïÎब¤¢¤ë¡£¥°¥í¡¼¥Ð¥ë¥³¥Þ¥ó¥É
+    ¤ÏÊ£¿ô¤ÎÆþÎϥ᥽¥Ã¥É¤Ë¤ª¤¤¤Æ¡¢Æ±¤¸ÌÜŪ¤Ç¡¢¥°¥í¡¼¥Ð¥ë¤Ê¥­¡¼³ä¤êÅö¤Æ
+    ¤ÇÍѤ¤¤é¤ì¤ë¡£¥í¡¼¥«¥ë¥³¥Þ¥ó¥É¤ÏÆÃÄê¤ÎÆþÎϥ᥽¥Ã¥É¤Ç¤Î¤ß¡¢¥í¡¼¥«¥ë
+    ¤Ê¥­¡¼³äÅö¤Ç»ÈÍѤµ¤ì¤ë¡£
+
+    ¸Ä¡¹¤ÎÆþÎϥ᥽¥Ã¥É¤Ï¥°¥í¡¼¥Ð¥ë¥³¥Þ¥ó¥É¤Î¥­¡¼³äÅö¤òÊѹ¹¤¹¤ë¤³¤È¤â¤Ç
+    ¤­¤ë¡£¥°¥í¡¼¥Ð¥ë¥³¥Þ¥ó¥ÉÍѤΥ°¥í¡¼¥Ð¥ë¥­¡¼³ä¤êÅö¤Æ¤Ï¡¢»ÈÍѤ¹¤ëÆþÎÏ
+    ¥á¥½¥Ã¥É¤Ë¤ª¤¤¤Æ¤½¤Î¥³¥Þ¥ó¥ÉÍÑ¤Î¥í¡¼¥«¥ë¤Ê¥­¡¼³äÅö¤¬Â¸ºß¤·¤Ê¤¤¾ì¹ç
+    ¤Ë¤Î¤ßÍ­¸ú¤Ç¤¢¤ë¡£
+
+    $NAME ¤¬ #Mnil ¤Ç¤¢¤ì¤Ð¡¢¥°¥í¡¼¥Ð¥ë¥³¥Þ¥ó¥É¤Ë´Ø¤¹¤ë¾ðÊó¤òÊÖ¤¹¡£¤³¤Î
+    ¾ì¹ç¡¢$LANGUAGE ¤Ï̵»ë¤µ¤ì¤ë¡£
+
+    $NAME ¤¬ #Mnil ¤Ç¤Ê¤±¤ì¤Ð¡¢$LANGUAGE ¤È $NAME ¤Ë¤è¤Ã¤Æ»ØÄꤵ¤ì¤ëÆþ
+    Îϥ᥽¥Ã¥É¤ËÃÖ¤±¤ë¥í¡¼¥«¥ë¤Ê¥­¡¼³ä¤êÅö¤Æ¤ò»ý¤Ä¥³¥Þ¥ó¥É¤Ë´Ø¤¹¤ë¾ðÊó
+    ¤òÊÖ¤¹¡£
+
+    @return
+    ÆþÎϥ᥽¥Ã¥É¥³¥Þ¥ó¥É¤¬¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ï @c NULL ¤òÊÖ¤¹¡£
+
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¥ê¥¹¥È¤Î³ÆÍ×ÁǤÎ
+    ¥­¡¼¤Ï¸Ä¡¹¤Î¥³¥Þ¥ó¥É¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢Ãͤϲ¼µ­¤Î COMMAND-INFO
+    ¤Î·Á¼°¤Î¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤Ç¤¢¤ë¡£
+
+    COMMAND-INFO ¤ÎÂè°ìÍ×ÁǤΥ­¡¼¤Ï #Mtext ¤Þ¤¿¤Ï #Msymbol ¤Ç¤¢¤ë¡£¥­¡¼
+    ¤¬ #Mtext ¤Ê¤é¡¢ÃͤϤ½¤Î¥³¥Þ¥ó¥É¤òÀâÌÀ¤¹¤ë M-text ¤Ç¤¢¤ë¡£¥­¡¼¤¬
+    #Msymbol ¤Ê¤éÃͤϠ#Mnil ¤Ç¤¢¤ê¡¢¤³¤Î¥³¥Þ¥ó¥É¤ÏÀâÌÀ¥Æ¥­¥¹¥È¤ò»ý¤¿¤Ê
+    ¤¤¤³¤È¤Ë¤Ê¤ë¡£
+
+    ¤½¤ì°Ê³°¤ÎÍ×ÁǤ¬Ìµ¤±¤ì¤Ð¡¢¤³¤Î¥³¥Þ¥ó¥É¤ËÂФ·¤Æ¥­¡¼¥·¡¼¥¯¥¨¥ó¥¹¤¬³ä
+    ¤êÅö¤Æ¤é¤ì¤Æ¤¤¤Ê¤¤¤³¤È¤ò°ÕÌ£¤¹¤ë¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢»Ä¤ê¤Î³ÆÍ×ÁǤϥ­
+    ¡¼¤È¤·¤Æ#Mplist ¤ò¡¢ÃͤȤ·¤Æ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤ò»ý¤Ä¡£¤³¤Î¥×¥í¥Ñ¥Æ¥£
+    ¥ê¥¹¥È¤Î¥­¡¼¤Ï #Msymbol ¤Ç¤¢¤ê¡¢Ãͤϸ½ºß¤½¤Î¥³¥Þ¥ó¥É¤Ë³ä¤êÅö¤Æ¤é¤ì
+    ¤Æ¤¤¤ëÆþÎÏ¥­¡¼¤òɽ¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    ÊÖ¤µ¤ì¤ë¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤Ï¥é¥¤¥Ö¥é¥ê¤Ë¤è¤Ã¤Æ´ÉÍý¤µ¤ì¤Æ¤ª¤ê¡¢¸Æ¤Ó½Ð
+    ¤·Â¦¤ÇÊѹ¹¤·¤¿¤ê²òÊü¤·¤¿¤ê¤·¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£*/
+
+MPlist *
+minput_get_commands (MSymbol language, MSymbol name)
+{
+  MInputMethodInfo *im_info;
+  MPlist *cmds;
+
+  MINPUT__INIT ();
+
+  im_info = get_im_info (language, name, Mnil, Mcommand);
+  if (! im_info || ! im_info->configured_vars)
+    return NULL;
+  M17N_OBJECT_UNREF (im_info->bc_cmds);
+  im_info->bc_cmds = mplist ();
+  MPLIST_DO (cmds, im_info->configured_cmds)
+    {
+      MPlist *plist = MPLIST_PLIST (cmds);
+      MPlist *elt = mplist ();
+
+      mplist_push (im_info->bc_cmds, Mplist, elt);
+      mplist_add (elt, MPLIST_SYMBOL (plist),
+                 mplist_copy (MPLIST_NEXT (plist)));
+      M17N_OBJECT_UNREF (elt);
+    }
+  return im_info->bc_cmds;
+}
+
+/*=*/
+
+/***en
+    @brief Assign a key sequence to an input method command (obsolete).
+
+    This function is obsolete.  Use minput_config_command () instead.
+
+    The minput_assign_command_keys () function assigns input key
+    sequence $KEYSEQ to input method command $COMMAND for the input
+    method specified by $LANGUAGE and $NAME.  If $NAME is #Mnil, the
+    key sequence is assigned globally no matter what $LANGUAGE is.
+    Otherwise the key sequence is assigned locally.
+
+    Each element of $KEYSEQ must have the key $Msymbol and the value
+    must be a symbol representing an input key.
+
+    $KEYSEQ may be @c NULL, in which case, all assignments are deleted
+    globally or locally.
+
+    This assignment gets effective in a newly opened input method.
+
+    @return
+    If the operation was successful, 0 is returned.  Otherwise -1 is
+    returned, and #merror_code is set to @c MERROR_IM.  */
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¥³¥Þ¥ó¥É¤Ë¥­¡¼¥·¡¼¥¯¥¨¥ó¥¹¤ò³ä¤êÅö¤Æ¤ë.
+
+    ´Ø¿ô minput_assign_command_keys () ¤Ï¡¢ $LANGUAGE ¤È $NAME ¤Ë¤è¤Ã¤Æ
+    »ØÄꤵ¤ì¤¿ÆþÎϥ᥽¥Ã¥ÉÍѤÎÆþÎϥ᥽¥Ã¥É¥³¥Þ¥ó¥É $COMMAND ¤ËÂФ·¤Æ¡¢
+    ÆþÎÏ¥­¡¼¥·¡¼¥¯¥¨¥ó¥¹ $KEYSEQ ¤ò³ä¤êÅö¤Æ¤ë¡£ $NAME ¤¬ #Mnil ¤Ê¤é¤Ð¡¢
+    $LANGUAGE ¤Ë´Ø·¸¤Ê¤¯¡¢ÆþÎÏ¥­¡¼¥·¡¼¥¯¥¨¥ó¥¹¤Ï¥°¥í¡¼¥Ð¥ë¤Ë³ä¤êÅö¤Æ¤é
+    ¤ì¤ë¡£¤½¤¦¤Ç¤Ê¤ì¤Ð¡¢³ä¤êÅö¤Æ¤Ï¥í¡¼¥«¥ë¤Ç¤¢¤ë¡£
+
+    $KEYSEQ ¤Î³ÆÍ×ÁǤϥ­¡¼¤È¤·¤Æ $Msymbol ¤ò¡¢ÃͤȤ·¤ÆÆþÎÏ¥­¡¼¤òɽ¤¹¥·
+    ¥ó¥Ü¥ë¤ò»ý¤¿¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    $KEYSEQ ¤Ï @c NULL ¤Ç¤â¤è¤¤¡£¤³¤Î¾ì¹ç¡¢¥°¥í¡¼¥Ð¥ë¤â¤·¤¯¤Ï¥í¡¼¥«¥ë¤Ê
+    ¤¹¤Ù¤Æ¤Î³ä¤êÅö¤Æ¤¬¾Ãµî¤µ¤ì¤ë¡£
+
+    ¤³¤Î³ä¤êÅö¤Æ¤Ï¡¢³ä¤êÅö¤Æ°Ê¹ß¿·¤·¤¯¥ª¡¼¥×¥ó¤µ¤ì¤¿ÆþÎϥ᥽¥Ã¥É¤«¤éÍ­
+    ¸ú¤Ë¤Ê¤ë¡£
+
+    @return 
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤·¡¢
+    #merror_code ¤ò @c MERROR_IM ¤ËÀßÄꤹ¤ë¡£  */
+
+int
+minput_assign_command_keys (MSymbol language, MSymbol name,
+                           MSymbol command, MPlist *keyseq)
+{
+  int ret;
+
+  MINPUT__INIT ();
+
+  if (command == Mnil)
+    MERROR (MERROR_IM, -1);
+  if (keyseq)
+    {
+      MPlist *plist;
+
+      if  (! check_command_keyseq (keyseq))
+       MERROR (MERROR_IM, -1);
+      plist = mplist ();
+      mplist_add (plist, Mplist, keyseq);
+      keyseq = plist;
+    }  
+  else
+    keyseq = mplist ();
+  ret = minput_config_command (language, name, command, keyseq);
+  M17N_OBJECT_UNREF (keyseq);
+  return ret;
+}
+
+/*=*/
+
+/***en
+    @brief Call a callback function
+
+    The minput_callback () functions calls a callback function
+    $COMMAND assigned for the input context $IC.  The caller must set
+    specific elements in $IC->plist if the callback function requires.
+
+    @return
+    If there exists a specified callback function, 0 is returned.
+    Otherwise -1 is returned.  By side effects, $IC->plist may be
+    modified.  */
+
+int
+minput_callback (MInputContext *ic, MSymbol command)
+{
+  MInputCallbackFunc func;
+
+  if (! ic->im->driver.callback_list)
+    return -1;
+  func = ((MInputCallbackFunc)
+         mplist_get_func (ic->im->driver.callback_list, command));
+  if (! func)
+    return -1;
+  (func) (ic, command);
+  return 0;
+}
+
+/*** @} */ 
+/*** @} */
+/*=*/
+/*** @addtogroup m17nDebug */
+/*=*/
+/*** @{  */
+/*=*/
+
+/***en
+    @brief Dump an input method.
+
+    The mdebug_dump_im () function prints the input method $IM in a
+    human readable way to the stderr.  $INDENT specifies how many
+    columns to indent the lines but the first one.
+
+    @return
+    This function returns $IM.  */
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¤ò¥À¥ó¥×¤¹¤ë.
+
+    ´Ø¿ô mdebug_dump_im () ¤ÏÆþÎϥ᥽¥Ã¥É $IM ¤ò stderr 
+    ¤Ë¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç°õºþ¤¹¤ë¡£$INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï $IM ¤òÊÖ¤¹¡£  */
+
+MInputMethod *
+mdebug_dump_im (MInputMethod *im, int indent)
+{
+  MInputMethodInfo *im_info = (MInputMethodInfo *) im->info;
+  char *prefix;
+
+  prefix = (char *) alloca (indent + 1);
+  memset (prefix, 32, indent);
+  prefix[indent] = '\0';
+
+  fprintf (stderr, "(input-method %s %s ", msymbol_name (im->language),
+          msymbol_name (im->name));
+  mdebug_dump_mtext (im_info->title, 0, 0);
+  if (im->name != Mnil)
+    {
+      MPlist *state;
+
+      MPLIST_DO (state, im_info->states)
+       {
+         fprintf (stderr, "\n%s  ", prefix);
+         dump_im_state (MPLIST_VAL (state), indent + 2);
+       }
+    }
+  fprintf (stderr, ")");
+  return im;
+}
+
+/*** @} */ 
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/input.h b/src/input.h
new file mode 100644 (file)
index 0000000..3956fbf
--- /dev/null
@@ -0,0 +1,104 @@
+/* input.h -- header file for the input method module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_INPUT_H_
+#define _M17N_INPUT_H_
+
+typedef struct _MInputMethodInfo MInputMethodInfo;
+
+struct _MInputMethodInfo
+{
+  MDatabase *mdb;
+  MSymbol language, name, extra;
+  MPlist *cmds, *configured_cmds, *bc_cmds;
+  MPlist *vars, *configured_vars, *bc_vars;
+  MText *description;
+  MText *title;
+  MPlist *maps;
+  MPlist *states;
+  MPlist *macros;
+  MPlist *externals;
+  unsigned long tick;
+};
+
+typedef struct MIMState MIMState;
+
+typedef struct MIMMap MIMMap;
+
+typedef struct
+{
+  /** The current state.  */
+  MIMState *state;
+
+  /** The previous state.  */
+  MIMState *prev_state;
+
+  /** The current map.  */
+  MIMMap *map;
+
+  /** Table of typed keys.  */
+  int size, inc, used;
+  MSymbol *keys;
+
+  /** Index of the key handled firstly in the current state.  */
+  int state_key_head;
+
+  /** Index of the key not yet handled.  */
+  int key_head;
+
+  /** Index of the key at the time of committing.  */
+  int commit_key_head;
+
+  /** Saved M-text when entered in the current state.  */
+  MText *preedit_saved;
+
+  /** The insertion position when shifted to the current state.  */
+  int state_pos;
+
+  /** List of markers.  */
+  MPlist *markers;
+
+  /** List of variables. */
+  MPlist *vars;
+
+  MPlist *vars_saved;
+
+  MText *preceding_text, *following_text;
+
+  int key_unhandled;
+
+  /** Used by minput_win_driver (input-win.c).  */
+  void *win_info;
+
+  unsigned long tick;
+} MInputContextInfo;
+
+#define MINPUT_KEY_SHIFT_MODIFIER      (1 << 0)
+#define MINPUT_KEY_CONTROL_MODIFIER    (1 << 1)
+#define MINPUT_KEY_META_MODIFIER       (1 << 2)
+#define MINPUT_KEY_ALT_MODIFIER                (1 << 3)
+#define MINPUT_KEY_SUPER_MODIFIER      (1 << 4)
+#define MINPUT_KEY_HYPER_MODIFIER      (1 << 5)
+
+extern MSymbol minput__char_to_key (int c);
+
+#endif /* not _M17N_INPUT_H_ */
diff --git a/src/internal-flt.h b/src/internal-flt.h
new file mode 100644 (file)
index 0000000..fd7fc10
--- /dev/null
@@ -0,0 +1,49 @@
+/* internal-flt.h -- common header file for the internal FLT API.
+   Copyright (C) 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M_INTERNAL_FLT_H
+#define _M_INTERNAL_FLT_H
+
+#define MAKE_COMBINING_CODE(base_y, base_x, add_y, add_x, off_y, off_x)        \
+  (((off_y) << 16)                                                     \
+   | ((off_x) << 8)                                                    \
+   | ((base_x) << 6)                                                   \
+   | ((base_y) << 4)                                                   \
+   | ((add_x) << 2)                                                    \
+   | (add_y))
+
+#define COMBINING_CODE_OFF_Y(code) ((((code) >> 16) & 0xFF) - 128)
+#define COMBINING_CODE_OFF_X(code) ((((code) >> 8) & 0xFF) - 128)
+#define COMBINING_CODE_BASE_X(code) (((code) >> 6) & 0x3)
+#define COMBINING_CODE_BASE_Y(code) (((code) >> 4) & 0x3)
+#define COMBINING_CODE_ADD_X(code) (((code) >> 2) & 0x3)
+#define COMBINING_CODE_ADD_Y(code) ((code) & 0x3)
+
+#define PACK_OTF_TAG(TAG)              \
+  ((((TAG) & 0x7F000000) >> 3) \
+   | (((TAG) & 0x7F0000) >> 2) \
+   | (((TAG) & 0x7F00) >> 1)   \
+   | ((TAG) & 0x7F))
+
+extern MSymbol Mcombining;
+
+#endif /* _M_INTERNAL_FLT_H */
diff --git a/src/internal-gui.h b/src/internal-gui.h
new file mode 100644 (file)
index 0000000..0ea3d04
--- /dev/null
@@ -0,0 +1,269 @@
+/* internal-gui.h -- common header file for the internal GUI API.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M_INTERNAL_GUI_H
+#define _M_INTERNAL_GUI_H
+
+enum MDeviceType
+  {
+    MDEVICE_SUPPORT_OUTPUT = 1,
+    MDEVICE_SUPPORT_INPUT = 2
+  };
+
+typedef struct MRealizedFont MRealizedFont;
+typedef struct MRealizedFace MRealizedFace;
+typedef struct MRealizedFontset MRealizedFontset;
+typedef struct MDeviceDriver MDeviceDriver;
+
+/** Information about a frame.  */
+
+struct MFrame
+{
+  M17NObject control;
+
+  MSymbol foreground, background, videomode;
+
+  MFont *font;
+
+  /** The default face of the frame.  */
+  MFace *face;
+
+  /** The default realized face of the frame.  */
+  MRealizedFace *rface;
+
+  /** The default width of one-char space.  It is a width of SPACE
+      character of the default face.  */
+  int space_width;
+
+  int average_width;
+
+  /** The default ascent and descent of a line.  It is ascent and
+      descent of ASCII font of the default face.  */
+  int ascent, descent;
+
+  /** Initialized to 0 and incremented on each modification of a face
+      on which one of the realized faces is based.  */
+  unsigned tick;
+
+  /** Pointer to device dependent information associated with the
+      frame.  */
+  void *device;
+
+  /** The following members are set by "device_open" function of a
+      device dependent library.  */
+
+  /** Logical OR of enum MDeviceType.  */
+  int device_type;
+
+  /** Resolution (dots per inch) of the device.  */
+  int dpi;
+
+  /** Correction of functions to manipulate the device.  */
+  MDeviceDriver *driver;
+
+  /** List of font drivers.  */
+  MPlist *font_driver_list;
+
+  /** List of realized fonts.  */
+  MPlist *realized_font_list;
+
+  /** List of realized faces.  */
+  MPlist *realized_face_list;
+
+  /** List of realized fontsets.  */
+  MPlist *realized_fontset_list;
+};
+
+#define M_CHECK_WRITABLE(frame, err, ret)                      \
+  do {                                                         \
+    if (! ((frame)->device_type & MDEVICE_SUPPORT_OUTPUT))     \
+      MERROR ((err), (ret));                                   \
+  } while (0)
+
+#define M_CHECK_READABLE(frame, err, ret)                      \
+  do {                                                         \
+    if (! ((frame)->device_type & MDEVICE_SUPPORT_INPUT))      \
+      MERROR ((err), (ret));                                   \
+  } while (0)
+
+enum glyph_type
+  {
+    GLYPH_CHAR,
+    GLYPH_SPACE,
+    GLYPH_PAD,
+    GLYPH_BOX,
+    GLYPH_ANCHOR,
+    GLYPH_TYPE_MAX
+  };
+
+enum glyph_category
+  {
+    GLYPH_CATEGORY_NORMAL,
+    GLYPH_CATEGORY_MODIFIER,
+    GLYPH_CATEGORY_FORMATTER
+  };
+
+typedef struct
+{
+  MFLTGlyph g;
+  MRealizedFace *rface;
+  unsigned left_padding : 1;
+  unsigned right_padding : 1;
+  unsigned enabled : 1;
+  unsigned bidi_level : 6;
+  unsigned category : 2;
+  unsigned type : 3;
+} MGlyph;
+
+struct MGlyphString
+{
+  M17NObject head;
+
+  MFrame *frame;
+  int tick;
+
+  int size, inc, used;
+  MGlyph *glyphs;
+  int from, to;
+  short width, height, ascent, descent;
+  short physical_ascent, physical_descent, lbearing, rbearing;
+  short text_ascent, text_descent, line_ascent, line_descent;
+  int indent, width_limit;
+
+  /* Copied for <control>.anti_alias but never set if the frame's
+     depth is less than 8.  */
+  unsigned anti_alias : 1;
+
+  MDrawControl control;
+
+  struct MGlyphString *next, *top;
+};
+
+#define MGLYPH(idx)    \
+  (gstring->glyphs + ((idx) >= 0 ? (idx) : (gstring->used + (idx))))
+
+#define GLYPH_INDEX(g) \
+  ((g) - gstring->glyphs)
+
+#define INIT_GLYPH(g)  \
+  (memset (&(g), 0, sizeof (g)))
+
+#define APPEND_GLYPH(gstring, g)       \
+  MLIST_APPEND1 ((gstring), glyphs, (g), MERROR_DRAW)
+
+#define INSERT_GLYPH(gstring, at, g)                           \
+  do {                                                         \
+    MLIST_INSERT1 ((gstring), glyphs, (at), 1, MERROR_DRAW);   \
+    (gstring)->glyphs[at] = g;                                 \
+  } while (0)
+
+#define DELETE_GLYPH(gstring, at)              \
+  do {                                         \
+    MLIST_DELETE1 (gstring, glyphs, at, 1);    \
+  } while (0)
+
+#define REPLACE_GLYPHS(gstring, from, to, len)                           \
+  do {                                                                   \
+    int newlen = (gstring)->used - (from);                               \
+    int diff = newlen - (len);                                           \
+                                                                         \
+    if (diff < 0)                                                        \
+      MLIST_DELETE1 (gstring, glyphs, (to) + newlen, -diff);             \
+    else if (diff > 0)                                                   \
+      MLIST_INSERT1 ((gstring), glyphs, (to) + (len), diff, MERROR_DRAW); \
+    memmove ((gstring)->glyphs + to, (gstring)->glyphs + (from + diff),          \
+            (sizeof (MGlyph)) * newlen);                                 \
+    (gstring)->used -= newlen;                                           \
+  } while (0)
+
+typedef struct MGlyphString MGlyphString;
+
+typedef struct
+{
+  short x, y;
+} MDrawPoint;
+
+struct MDeviceDriver
+{
+  void (*close) (MFrame *frame);
+  void *(*get_prop) (MFrame *frame, MSymbol key);
+  void (*realize_face) (MRealizedFace *rface);
+  void (*free_realized_face) (MRealizedFace *rface);
+  void (*fill_space) (MFrame *frame, MDrawWindow win,
+                     MRealizedFace *rface, int reverse,
+                     int x, int y, int width, int height,
+                     MDrawRegion region);
+  void (*draw_empty_boxes) (MDrawWindow win, int x, int y,
+                           MGlyphString *gstring,
+                           MGlyph *from, MGlyph *to,
+                           int reverse, MDrawRegion region);
+  void (*draw_hline) (MFrame *frame, MDrawWindow win,
+                     MGlyphString *gstring,
+                     MRealizedFace *rface, int reverse,
+                     int x, int y, int width, MDrawRegion region);
+  void (*draw_box) (MFrame *frame, MDrawWindow win,
+                   MGlyphString *gstring,
+                   MGlyph *g, int x, int y, int width,
+                   MDrawRegion region);
+
+  void (*draw_points) (MFrame *frame, MDrawWindow win,
+                      MRealizedFace *rface,
+                      int intensity, MDrawPoint *points, int num,
+                      MDrawRegion region);
+  MDrawRegion (*region_from_rect) (MDrawMetric *rect);
+  void (*union_rect_with_region) (MDrawRegion region, MDrawMetric *rect);
+  void (*intersect_region) (MDrawRegion region1, MDrawRegion region2);
+  void (*region_add_rect) (MDrawRegion region, MDrawMetric *rect);
+  void (*region_to_rect) (MDrawRegion region, MDrawMetric *rect);
+  void (*free_region) (MDrawRegion region);
+  void (*dump_region) (MDrawRegion region);
+  MDrawWindow (*create_window) (MFrame *frame, MDrawWindow parent);
+  void (*destroy_window) (MFrame *frame, MDrawWindow win);
+  void (*map_window) (MFrame *frame, MDrawWindow win);
+  void (*unmap_window) (MFrame *frame, MDrawWindow win);
+  void (*window_geometry) (MFrame *frame, MDrawWindow win,
+                          MDrawWindow parent, MDrawMetric *geometry);
+  void (*adjust_window) (MFrame *frame, MDrawWindow win,
+                        MDrawMetric *current, MDrawMetric *new);
+  MSymbol (*parse_event) (MFrame *frame, void *arg, int *modifiers);
+};
+
+extern MSymbol Mlatin;
+
+extern MSymbol Mgd;
+
+extern int mfont__init ();
+extern void mfont__fini ();
+
+extern int mface__init ();
+extern void mface__fini ();
+
+extern int mdraw__init ();
+extern void mdraw__fini ();
+
+extern int mfont__fontset_init ();
+extern void mfont__fontset_fini ();
+
+extern int minput__win_init ();
+extern void minput__win_fini ();
+
+#endif /* _M_INTERNAL_GUI_H */
diff --git a/src/internal.h b/src/internal.h
new file mode 100644 (file)
index 0000000..71020db
--- /dev/null
@@ -0,0 +1,681 @@
+/* internal.h -- common header file for the internal CORE and SHELL APIs.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_INTERNAL_H_
+#define _M17N_INTERNAL_H_
+
+/** @file internal.h
+    @brief a documentation for internal.h
+
+    longer version of internal.h description 
+*/
+
+extern int m17n__core_initialized;
+extern int m17n__shell_initialized;
+extern int m17n__gui_initialized;
+
+extern int mdebug_hook ();
+
+#if ENABLE_NLS
+#include <libintl.h>
+#define _(String) dgettext ("m17n-lib", String)
+#else
+#define _(String) (String)
+#endif
+
+/** Return with code RET while setting merror_code to ERR.  */
+
+#define MERROR(err, ret)       \
+  do {                         \
+    merror_code = (err);       \
+    mdebug_hook ();            \
+    return (ret);              \
+  } while (0)
+
+
+#define MERROR_GOTO(err, label)        \
+  do {                         \
+    if ((err))                 \
+      merror_code = (err);     \
+    mdebug_hook ();            \
+    goto label;                        \
+  } while (0)
+
+
+#define MWARNING(err)  \
+  do {                 \
+    mdebug_hook ();    \
+    goto warning;      \
+  } while (0)
+
+#define MFATAL(err)    \
+  do {                 \
+    mdebug_hook ();    \
+    exit (err);                \
+  } while (0)
+
+#define MFAILP(cond) ((cond) ? 0 : mdebug_hook ())
+
+#define M_CHECK_CHAR(c, ret)           \
+  if ((c) < 0 || (c) > MCHAR_MAX)      \
+    MERROR (MERROR_CHAR, (ret));       \
+  else
+
+\f
+/** Memory allocation stuffs.  */
+
+/* Call a handler function for memory full situation with argument
+   ERR.  ERR must be one of enum MErrorCode.  By default, the
+   handler function just calls exit () with argument ERR.  */
+
+#define MEMORY_FULL(err)               \
+  do {                                 \
+    (*m17n_memory_full_handler) (err); \
+    exit (err);                                \
+  } while (0)
+
+
+/** The macro MTABLE_MALLOC () allocates memory (by malloc) for an
+    array of SIZE objects.  The size of each object is determined by
+    the type of P.  Then, it sets P to the allocated memory.  ERR must
+    be one of enum MErrorCode.  If the allocation fails, the macro
+    MEMORY_FULL () is called with argument ERR.  */
+
+#define MTABLE_MALLOC(p, size, err)                            \
+  do {                                                         \
+    if (! ((p) = (void *) malloc (sizeof (*(p)) * (size))))    \
+      MEMORY_FULL (err);                                       \
+  } while (0)
+
+
+/** The macro MTABLE_CALLOC() is like the macro MTABLE_MALLOC but use
+    calloc instead of malloc, thus the allocated memory are zero
+    cleared.  */
+
+#define MTABLE_CALLOC(p, size, err)                            \
+  do {                                                         \
+    if (! ((p) = (void *) calloc (sizeof (*(p)), size)))       \
+      MEMORY_FULL (err);                                       \
+  } while (0)
+
+#define MTABLE_CALLOC_SAFE(p, size)    \
+  ((p) = (void *) calloc (sizeof (*(p)), (size)))
+
+
+/** The macro MTABLE_REALLOC () changes the size of memory block
+    pointed to by P to a size suitable for an array of SIZE objects.
+    The size of each object is determined by the type of P.  ERR must
+    be one of enum MErrorCode.  If the allocation fails, the macro
+    MEMORY_FULL () is called with argument ERR.  */
+
+#define MTABLE_REALLOC(p, size, err)                                   \
+  do {                                                                 \
+    if (! ((p) = (void *) realloc ((p), sizeof (*(p)) * (size))))      \
+      MEMORY_FULL (err);                                               \
+  } while (0)
+
+
+/** The macro MTABLE_ALLOCA () allocates memory (by alloca) for an
+    array of SIZE objects.  The size of each object is determined by
+    the type of P.  Then, it sets P to the allocated memory.  ERR must
+    be one of enum MErrorCode.  If the allocation fails, the macro
+    MEMORY_FULL () is called with argument ERR.  */
+
+#define MTABLE_ALLOCA(p, size, err)            \
+  do {                                         \
+    int allocasize = sizeof (*(p)) * (size);   \
+    if (! ((p) = (void *) alloca (allocasize)))        \
+      MEMORY_FULL (err);                       \
+    memset ((p), 0, allocasize);               \
+  } while (0)
+
+
+/** short description of MSTRUCT_MALLOC */
+/** The macro MSTRUCT_MALLOC () allocates memory (by malloc) for an
+    object whose size is determined by the type of P, and sets P to
+    the allocated memory.  ERR must be one of enum MErrorCode.  If
+    the allocation fails, the macro MEMORY_FULL () is called with
+    argument ERR.  */
+
+#define MSTRUCT_MALLOC(p, err)                         \
+  do {                                                 \
+    if (! ((p) = (void *) malloc (sizeof (*(p)))))     \
+      MEMORY_FULL (err);                               \
+  } while (0)
+
+
+#define MSTRUCT_CALLOC(p, err) MTABLE_CALLOC ((p), 1, (err))
+
+#define MSTRUCT_CALLOC_SAFE(p) MTABLE_CALLOC_SAFE ((p), 1)
+
+#define USE_SAFE_ALLOCA \
+  int sa_must_free = 0, sa_size = 0
+
+/* P must be the same in all calls to SAFE_ALLOCA and SAFE_FREE in a
+   function.  */
+
+#define SAFE_ALLOCA(P, SIZE)           \
+  do {                                 \
+    if (sa_size < (SIZE))              \
+      {                                        \
+       if (sa_must_free)               \
+         (P) = realloc ((P), (SIZE));  \
+       else                            \
+         {                             \
+           (P) = alloca ((SIZE));      \
+           if (! (P))                  \
+             {                         \
+               (P) = malloc (SIZE);    \
+               sa_must_free = 1;       \
+             }                         \
+         }                             \
+       if (! (P))                      \
+         MEMORY_FULL (1);              \
+       sa_size = (SIZE);               \
+      }                                        \
+  } while (0)
+
+#define SAFE_FREE(P)                   \
+  do {                                 \
+    if (sa_must_free && sa_size > 0)   \
+      {                                        \
+       free ((P));                     \
+       sa_must_free = sa_size = 0;     \
+      }                                        \
+  } while (0)
+
+\f
+/** Extendable array.  */
+
+#define MLIST_RESET(list)      \
+  ((list)->used = 0)
+
+
+#define MLIST_INIT1(list, mem, increment)      \
+  do {                                         \
+    (list)->size = (list)->used = 0;           \
+    (list)->inc = (increment);                 \
+    (list)->mem = NULL;                                \
+  } while (0)
+
+
+#define MLIST_APPEND1(list, mem, elt, err)                     \
+  do {                                                         \
+    if ((list)->inc <= 0)                                      \
+      mdebug_hook ();                                          \
+    if ((list)->size == (list)->used)                          \
+      {                                                                \
+       (list)->size += (list)->inc;                            \
+       MTABLE_REALLOC ((list)->mem, (list)->size, (err));      \
+      }                                                                \
+    (list)->mem[(list)->used++] = (elt);                       \
+  } while (0)
+
+
+#define MLIST_PREPEND1(list, mem, elt, err)                    \
+  do {                                                         \
+    if ((list)->inc <= 0)                                      \
+      mdebug_hook ();                                          \
+    if ((list)->size == (list)->used)                          \
+      {                                                                \
+       (list)->size += (list)->inc;                            \
+       MTABLE_REALLOC ((list)->mem, (list)->size, (err));      \
+      }                                                                \
+    memmove ((list)->mem + 1, (list)->mem,                     \
+            sizeof *((list)->mem) * ((list)->used));           \
+    (list)->mem[0] = (elt);                                    \
+    (list)->used++;                                            \
+  } while (0)
+
+
+#define MLIST_INSERT1(list, mem, idx, len, err)                                \
+  do {                                                                 \
+    while ((list)->used + (len) > (list)->size)                                \
+      {                                                                        \
+       (list)->size += (list)->inc;                                    \
+       MTABLE_REALLOC ((list)->mem, (list)->size, (err));              \
+      }                                                                        \
+    memmove ((list)->mem + ((idx) + (len)), (list)->mem + (idx),       \
+            (sizeof *((list)->mem)) * ((list)->used - (idx)));         \
+    (list)->used += (len);                                             \
+  } while (0)
+
+
+#define MLIST_DELETE1(list, mem, idx, len)                             \
+  do {                                                                 \
+    memmove ((list)->mem + (idx), (list)->mem + (idx) + (len),         \
+            (sizeof *((list)->mem)) * ((list)->used - (idx) - (len))); \
+    (list)->used -= (len);                                             \
+  } while (0)
+
+
+#define MLIST_COPY1(list0, list1, mem, err)                    \
+  do {                                                         \
+    (list0)->size = (list0)->used = (list1)->used;             \
+    (list0)->inc = 1;                                          \
+    MTABLE_MALLOC ((list0)->mem, (list0)->used, (err));                \
+    memcpy ((list0)->mem, (list1)->mem,                                \
+           (sizeof (list0)->mem) * (list0)->used);             \
+  } while (0)
+
+
+#define MLIST_FREE1(list, mem)         \
+  if ((list)->size)                    \
+    {                                  \
+      free ((list)->mem);              \
+      (list)->mem = NULL;              \
+      (list)->size = (list)->used = 0; \
+    }                                  \
+  else
+
+\f
+
+typedef struct
+{
+  void (*freer) (void *);
+  int size, inc, used;
+  unsigned *counts;
+} M17NObjectRecord;
+
+typedef struct
+{
+  /**en Reference count of the object.  */
+  /**ja ¥ª¥Ö¥¸¥§¥¯¥È¤Î»²¾È¿ô.  */
+  unsigned ref_count : 16;
+
+  unsigned ref_count_extended : 1;
+
+  /**en A flag bit used for various perpose.  */
+  /**ja ¤µ¤Þ¤¶¤Þ¤ÊÌÜŪ¤ËÍѤ¤¤é¤ì¤ë¥Õ¥é¥°¥Ó¥Ã¥È.  */
+  unsigned flag : 15;
+
+  union {
+    /**en If <ref_count_extended> is zero, a function to free the
+       object.  */
+    /**ja <ref_count_extended> ¤¬ 0 ¤Ê¤é¤Ð¥ª¥Ö¥¸¥§¥¯¥È¤ò²òÊü¤¹¤ë´Ø¿ô.  */
+    void (*freer) (void *);
+    /**en If <ref_count_extended> is nonzero, a pointer to the
+       struct M17NObjectRecord.  */
+    /**ja <ref_count_extended> ¤¬ 0 ¤Ç¤Ê¤±¤ì¤Ð¹½Â¤ÂΠM17NObjectRecord ¤Ø¤Î¥Ý¥¤¥ó¥¿.  */
+    M17NObjectRecord *record;
+  } u;
+} M17NObject;
+
+
+/** Allocate a managed object OBJECT which has freer FREE_FUNC.  */
+
+#define M17N_OBJECT(object, free_func, err)            \
+  do {                                                 \
+    MSTRUCT_CALLOC ((object), (err));                  \
+    ((M17NObject *) (object))->ref_count = 1;          \
+    ((M17NObject *) (object))->u.freer = free_func;    \
+  } while (0)
+
+
+/**en Increment the reference count of OBJECT if the count is not
+   0.  */
+/**ja OBJECT ¤Î»²¾È¿ô¤¬ 0 ¤Ç¤Ê¤±¤ì¤Ð 1 Áý¤ä¤¹.  */
+
+#define M17N_OBJECT_REF(object)                                \
+  do {                                                 \
+    if (((M17NObject *) (object))->ref_count_extended) \
+      m17n_object_ref (object);                                \
+    else if (((M17NObject *) (object))->ref_count > 0) \
+      {                                                        \
+       ((M17NObject *) (object))->ref_count++;         \
+       if (! ((M17NObject *) (object))->ref_count)     \
+         {                                             \
+           ((M17NObject *) (object))->ref_count--;     \
+           m17n_object_ref (object);                   \
+         }                                             \
+      }                                                        \
+  } while (0)
+
+
+#define M17N_OBJECT_REF_NTIMES(object, n)                              \
+  do {                                                                 \
+    int i;                                                             \
+                                                                       \
+    if (((M17NObject *) (object))->ref_count_extended)                 \
+      for (i = 0; i < n; i++)                                          \
+       m17n_object_ref (object);                                       \
+    else if (((M17NObject *) (object))->ref_count > 0)                 \
+      {                                                                        \
+       int orig_ref_count = ((M17NObject *) (object))->ref_count;      \
+                                                                       \
+       for (i = 0; i < n; i++)                                         \
+         if (! ++((M17NObject *) (object))->ref_count)                 \
+           {                                                           \
+             ((M17NObject *) (object))->ref_count = orig_ref_count;    \
+             for (i = 0; i < n; i++)                                   \
+               m17n_object_ref (object);                               \
+           }                                                           \
+      }                                                                        \
+  } while (0)
+
+
+/**en Decrement the reference count of OBJECT if the count is greater
+      than 0.  In that case, if the count becomes 0, free OBJECT.  */
+/**ja OBJECT ¤Î»²¾È¿ô¤¬ 0 ¤è¤êÂ礭¤±¤ì¤Ð 1 ¸º¤é¤¹¡£¸º¤é¤·¤Æ 0 ¤Ë¤Ê¤ì¤Ð
+      OBJECT ¤ò²òÊü¤¹¤ë.  */
+
+#define M17N_OBJECT_UNREF(object)                                      \
+  do {                                                                 \
+    if (object)                                                                \
+      {                                                                        \
+       if (((M17NObject *) (object))->ref_count_extended)              \
+         m17n_object_unref (object);                                   \
+       else if (((M17NObject *) (object))->ref_count == 0)             \
+         break;                                                        \
+       else                                                            \
+         {                                                             \
+           ((M17NObject *) (object))->ref_count--;                     \
+           if (((M17NObject *) (object))->ref_count == 0)              \
+             {                                                         \
+               if (((M17NObject *) (object))->u.freer)                 \
+                 (((M17NObject *) (object))->u.freer) (object);        \
+               else                                                    \
+                 free (object);                                        \
+               (object) = NULL;                                        \
+             }                                                         \
+         }                                                             \
+      }                                                                        \
+  } while (0)
+
+typedef struct _M17NObjectArray M17NObjectArray;
+
+struct _M17NObjectArray
+{
+  char *name;
+  int count;
+  int size, inc, used;
+  void **objects;
+  M17NObjectArray *next;
+};
+
+extern void mdebug__add_object_array (M17NObjectArray *array, char *name);
+
+#define M17N_OBJECT_ADD_ARRAY(array, name)     \
+  if (mdebug__flags[MDEBUG_FINI])              \
+    mdebug__add_object_array (&array, name);   \
+  else
+
+extern void mdebug__register_object (M17NObjectArray *array, void *object);
+
+#define M17N_OBJECT_REGISTER(array, object)    \
+  if (mdebug__flags[MDEBUG_FINI])              \
+    mdebug__register_object (&array, object);  \
+  else
+
+extern void mdebug__unregister_object (M17NObjectArray *array, void *object);
+
+#define M17N_OBJECT_UNREGISTER(array, object)  \
+  if (mdebug__flags[MDEBUG_FINI])              \
+    mdebug__unregister_object (&array, object);        \
+  else
+
+\f
+
+struct MTextPlist;
+
+enum MTextCoverage
+  {
+    MTEXT_COVERAGE_ASCII,
+    MTEXT_COVERAGE_UNICODE,
+    MTEXT_COVERAGE_FULL
+  };
+
+struct MText
+{
+  M17NObject control;
+
+  unsigned format : 16;
+  unsigned coverage : 16;
+
+  /**en Number of characters in the M-text */
+  /**ja M-text Ãæ¤Îʸ»ú¿ô */
+  int nchars;
+
+  /**en Number of bytes used to represent the characters in the M-text. */
+  /**ja M-text Ãæ¤Îʸ»ú¤òɽ¤ï¤¹¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¥Ð¥¤¥È¿ô */
+  int nbytes;
+
+  /**en Character sequence of the M-text. */
+  /**ja M-text Ãæ¤Îʸ»úÎó */
+  unsigned char *data;
+
+  /**en Number of bytes allocated for the @c data member. */
+  /**ja ¥á¥ó¥Ð @c data ¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿¥Ð¥¤¥È¿ô */
+  int allocated;
+
+  /**en Pointer to the property list of the M-text. */
+  /**ja M-text ¤Î¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤Ø¤Î¥Ý¥¤¥ó¥¿ */
+  struct MTextPlist *plist;
+
+  /**en Caches of the character position and the corresponding byte position. */
+  /**ja Ê¸»ú°ÌÃÖ¤ª¤è¤ÓÂбþ¤¹¤ë¥Ð¥¤¥È°ÌÃ֤Υ­¥ã¥Ã¥·¥å */
+  int cache_char_pos, cache_byte_pos;
+};
+
+/** short description of M_CHECK_POS */
+/** longer description of M_CHECK_POS */
+
+#define M_CHECK_POS(mt, pos, ret)              \
+  do {                                         \
+    if ((pos) < 0 || (pos) >= (mt)->nchars)    \
+      MERROR (MERROR_RANGE, (ret));            \
+  } while (0)
+
+
+/** short description of M_CHECK_POS_X */
+/** longer description of M_CHECK_POS_X */
+
+#define M_CHECK_POS_X(mt, pos, ret)            \
+  do {                                         \
+    if ((pos) < 0 || (pos) > (mt)->nchars)     \
+      MERROR (MERROR_RANGE, (ret));            \
+  } while (0)
+
+
+/** short description of M_CHECK_RANGE */
+/** longer description of M_CHECK_RANGE */
+
+#define M_CHECK_RANGE(mt, from, to, ret, ret2)                 \
+  do {                                                         \
+    if ((from) < 0 || (to) < (from) || (to) > (mt)->nchars)    \
+      MERROR (MERROR_RANGE, (ret));                            \
+    if ((from) == (to))                                                \
+      return (ret2);                                           \
+  } while (0)
+
+#define M_CHECK_RANGE_X(mt, from, to, ret)                     \
+  do {                                                         \
+    if ((from) < 0 || (to) < (from) || (to) > (mt)->nchars)    \
+      MERROR (MERROR_RANGE, (ret));                            \
+  } while (0)
+
+
+#define M_CHECK_POS_NCHARS(mt, pos, nchars, ret, ret2) \
+  do {                                                 \
+    int to = (pos) + (nchars);                 \
+                                                       \
+    M_CHECK_RANGE ((mt), (pos), (to), (ret), (ret2));  \
+  } while (0)
+
+
+#define MTEXT_READ_ONLY_P(mt) ((mt)->allocated < 0)
+
+#define M_CHECK_READONLY(mt, ret)      \
+  do {                                 \
+    if ((mt)->allocated < 0)           \
+      MERROR (MERROR_MTEXT, (ret));    \
+  } while (0)
+
+#define mtext_nchars(mt) ((mt)->nchars)
+
+#define mtext_nbytes(mt) ((mt)->nbytes)
+
+#define mtext_allocated(mt) ((mt)->allocated)
+
+#define mtext_reset(mt) (mtext_del ((mt), 0, (mt)->nchars))
+
+\f
+
+enum MDebugFlag
+  {
+    MDEBUG_INIT,
+    MDEBUG_FINI,
+    MDEBUG_CHARSET,
+    MDEBUG_CODING,
+    MDEBUG_DATABASE,
+    MDEBUG_FONT,
+    MDEBUG_FLT,
+    MDEBUG_FONTSET,
+    MDEBUG_INPUT,
+    MDEBUG_ALL,
+    MDEBUG_MAX = MDEBUG_ALL
+  };
+
+extern int mdebug__flags[MDEBUG_MAX];
+extern FILE *mdebug__output;
+extern void mdebug__push_time ();
+extern void mdebug__pop_time ();
+extern void mdebug__print_time ();
+
+#define MDEBUG_FLAG() mdebug__flags[mdebug_flag]
+
+#define MDEBUG_PRINT0(FPRINTF)         \
+  do {                                 \
+    if (MDEBUG_FLAG ())                        \
+      {                                        \
+       FPRINTF;                        \
+       fflush (mdebug__output);        \
+      }                                        \
+  } while (0)
+
+#define MDEBUG_PRINT(msg) \
+  MDEBUG_PRINT0 (fprintf (mdebug__output, "%s", (msg)))
+
+#define MDEBUG_PRINT1(fmt, arg) \
+  MDEBUG_PRINT0 (fprintf (mdebug__output, (fmt), (arg)))
+
+#define MDEBUG_PRINT2(fmt, arg1, arg2) \
+  MDEBUG_PRINT0 (fprintf (mdebug__output, (fmt), (arg1), (arg2)))
+
+#define MDEBUG_PRINT3(fmt, arg1, arg2, arg3) \
+  MDEBUG_PRINT0 (fprintf (mdebug__output, (fmt), (arg1), (arg2), (arg3)))
+
+#define MDEBUG_PRINT4(fmt, arg1, arg2, arg3, arg4)     \
+  MDEBUG_PRINT0 (fprintf (mdebug__output, (fmt), (arg1), (arg2), (arg3), (arg4)))
+
+#define MDEBUG_PRINT5(fmt, arg1, arg2, arg3, arg4, arg5)       \
+  MDEBUG_PRINT0 (fprintf (mdebug__output, (fmt), (arg1), (arg2), (arg3), (arg4), (arg5)))
+
+#define MDEBUG_DUMP(prefix, postfix, call)             \
+  do {                                                 \
+    if (MDEBUG_FLAG ())                                        \
+      {                                                        \
+       fprintf (mdebug__output, "%s", prefix);         \
+       call;                                           \
+       fprintf (mdebug__output, "%s", postfix);        \
+       fflush (mdebug__output);                        \
+      }                                                        \
+  } while (0)
+
+#define MDEBUG_PUSH_TIME()     \
+  do {                         \
+    if (MDEBUG_FLAG ())                \
+      mdebug__push_time ();    \
+  } while (0)
+
+
+#define MDEBUG_POP_TIME()      \
+  do {                         \
+    if (MDEBUG_FLAG ())                \
+      mdebug__pop_time ();     \
+  } while (0)
+
+
+#define MDEBUG_PRINT_TIME(tag, ARG_LIST)               \
+  do {                                                 \
+    if (MDEBUG_FLAG ())                                        \
+      {                                                        \
+       fprintf (mdebug__output, " [%s] ", tag);        \
+       mdebug__print_time ();                          \
+       fprintf ARG_LIST;                               \
+       fprintf (mdebug__output, "\n");                 \
+      }                                                        \
+  } while (0)
+
+
+#define SWAP_16(c) (((c) >> 8) | (((c) & 0xFF) << 8))
+
+#define SWAP_32(c)                     \
+  (((c) >> 24) | (((c) >> 8) & 0xFF00) \
+   | (((c) & 0xFF00) << 8) | (((c) & 0xFF) << 24))
+
+
+/* Initialize/finalize function.  */
+
+extern int msymbol__init ();
+extern void msymbol__fini ();
+
+extern int mplist__init ();
+extern void mplist__fini ();
+
+extern int mtext__init ();
+extern void mtext__fini ();
+
+extern int mtext__prop_init ();
+extern void mtext__prop_fini ();
+
+extern int mchartable__init ();
+extern void mchartable__fini ();
+
+extern int mcharset__init ();
+extern void mcharset__fini ();
+
+extern int mcoding__init ();
+extern void mcoding__fini ();
+
+extern int mdatabase__init (void);
+extern void mdatabase__fini (void);
+
+extern int mchar__init ();
+extern void mchar__fini ();
+
+extern int mlang__init ();
+extern void mlang__fini ();
+
+extern int mlocale__init ();
+extern void mlocale__fini ();
+
+extern int minput__init ();
+extern void minput__fini ();
+
+#endif /* _M17N_INTERNAL_H_ */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/language.c b/src/language.c
new file mode 100644 (file)
index 0000000..b31eeeb
--- /dev/null
@@ -0,0 +1,839 @@
+/* language.c -- language (and script) module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#include <config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <locale.h>
+#include "m17n.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "language.h"
+#include "symbol.h"
+#include "plist.h"
+#include "mtext.h"
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+
+static MPlist *language_list;
+static MPlist *script_list;
+static MPlist *langname_list;
+
+static MPlist *
+load_lang_script_list (MSymbol tag0, MSymbol tag1, MSymbol tag2, MSymbol tag3)
+{
+  MDatabase *mdb = mdatabase_find (tag0, tag1, tag2, tag3);
+  MPlist *plist, *pl, *p;
+
+  if (! mdb
+      || ! (plist = mdatabase_load (mdb)))
+    return NULL;
+  /* Check at least if the plist is ((SYMBOL ...) ...).  */
+  for (pl = plist; ! MPLIST_TAIL_P (pl);)
+    {
+      if (! MPLIST_PLIST_P (pl))
+       mplist__pop_unref (pl);
+      else
+       {
+         p = MPLIST_PLIST (pl);
+         if (! MPLIST_SYMBOL_P (p))
+           mplist__pop_unref (pl);
+         else
+           pl = MPLIST_NEXT (pl);
+       }
+    }
+  return plist;
+}
+
+static int
+init_language_list (void)
+{
+  language_list = load_lang_script_list (msymbol ("standard"), Mlanguage,
+                                        msymbol ("iso639"), Mnil);
+  if (! language_list)
+    {
+      language_list = mplist ();
+      MERROR (MERROR_DB, -1);
+    }
+  return 0;
+}
+
+
+static int
+init_script_list (void)
+{
+  script_list = load_lang_script_list (msymbol ("standard"), Mscript,
+                                      msymbol ("unicode"), Mnil);
+  if (! script_list)
+    {
+      script_list = mplist ();
+      MERROR (MERROR_DB, -1);
+    }
+  return 0;
+}
+
+static MPlist *
+load_lang_name (MSymbol target3, MSymbol target2)
+{
+  MPlist *plist, *pl, *p;
+
+  plist = mplist ();
+  mplist_add (plist, Msymbol, target3);
+  pl = mdatabase_list (Mlanguage, Mname, target3, Mnil);
+  if (! pl && target2 != Mnil)
+    pl = mdatabase_list (Mlanguage, Mname, target2, Mnil);
+  if (pl)
+    {
+      MPLIST_DO (p, pl)
+       {
+         MDatabase *mdb = MPLIST_VAL (p);
+         MPlist *p0 = mdatabase_load (mdb), *p1, *territories;
+         MSymbol script = mdatabase_tag (mdb)[3];
+         
+         if (MPLIST_PLIST_P (p0))
+           {
+             p1 = MPLIST_PLIST (p0);
+             if (MPLIST_SYMBOL_P (p1) && MPLIST_SYMBOL (p1) == Mlanguage)
+               {
+                 p1 = MPLIST_NEXT (MPLIST_NEXT (MPLIST_NEXT (MPLIST_NEXT (p1))));
+                 territories = p1;
+                 while (! MPLIST_TAIL_P (p1))
+                   {
+                     if (MPLIST_SYMBOL_P (p1))
+                       p1 = MPLIST_NEXT (p1);
+                     else
+                       mplist__pop_unref (p1);
+                   }
+                 M17N_OBJECT_REF (territories);
+                 mplist__pop_unref (p0);
+               }
+             else
+               territories = mplist ();
+             mplist_push (p0, Mplist, territories);
+             M17N_OBJECT_UNREF (territories);
+             mplist_push (p0, Msymbol, script);
+             mplist_add (plist, Mplist, p0);
+             M17N_OBJECT_UNREF (p0);
+           }
+       }
+      M17N_OBJECT_UNREF (pl);
+    }
+  mplist_push (langname_list, Mplist, plist);
+  M17N_OBJECT_UNREF (plist);
+  return plist;
+}
+
+\f
+/* Internal API */
+
+int
+mlang__init ()
+{
+  msymbol_put_func (Mlanguage, Mtext_prop_serializer,
+                   M17N_FUNC (msymbol__serializer));
+  msymbol_put_func (Mlanguage, Mtext_prop_deserializer,
+                   M17N_FUNC (msymbol__deserializer));
+  Miso639_2 = msymbol ("iso639-2");
+  Miso639_1 = msymbol ("iso639-1");
+
+  language_list = script_list = langname_list = NULL;
+  return 0;
+}
+
+void
+mlang__fini (void)
+{
+  M17N_OBJECT_UNREF (language_list);
+  M17N_OBJECT_UNREF (script_list);
+  M17N_OBJECT_UNREF (langname_list);
+}
+
+/*=*/
+
+/***en
+    @brief Get information about a language.
+
+    The mlanguage_info () function returns a well-formed @e plist that
+    contains information about $LANGUAGE.  $LANGUAGE is a symbol whose
+    name is an ISO639-2 3-letter language code, an ISO639-1 2-letter
+    language codes, or an English word.
+
+    The format of the plist is:
+
+@verbatim
+        (ISO639-2 [ISO639-1 | nil] ENGLISH-NAME ["NATIVE-NAME" | nil]
+                  ["REPRESENTATIVE-CHARACTERS"])
+@endverbatim
+
+    where, ISO639-2 is a symbol whose name is 3-letter language code
+    of ISO639-2, ISO639-1 is a symbol whose name is 2-letter language
+    code of ISO639-1, ENGLISH-NAME is a symbol whose name is the
+    English name of the language, "NATIVE-NAME" is an M-text written
+    by the most natural way in the language,
+    "REPRESENTATIVE-CHARACTERS" is an M-text that contains
+    representative characters used by the language.
+
+    It is assured that the formats of both M-texts are
+    #MTEXT_FORMAT_UTF_8.
+
+    @return
+    If the information is available, this function returns a plist
+    that should not be modified nor freed.  Otherwise, it returns
+    @c NULL.
+
+    @seealso
+    mlanguage_list ()  */
+
+MPlist *
+mlanguage__info (MSymbol language)
+{
+  MPlist *plist;
+
+  if (! language_list
+      && init_language_list () < 0)
+    return NULL;
+
+  MPLIST_DO (plist, language_list)
+    {
+      MPlist *pl = MPLIST_PLIST (plist);
+
+      if (MPLIST_SYMBOL (pl) == language)
+       return pl;
+      if (MPLIST_TAIL_P (pl))
+       continue;
+      pl = MPLIST_NEXT (pl);
+      if (MPLIST_SYMBOL_P (pl) && MPLIST_SYMBOL (pl) == language)
+       return MPLIST_PLIST (plist);
+      if (MPLIST_TAIL_P (pl))
+       continue;
+      pl = MPLIST_NEXT (pl);
+      if (MPLIST_MTEXT_P (pl))
+       {
+         MText *mt = MPLIST_MTEXT (pl);
+
+         if (mtext_nbytes (mt) == MSYMBOL_NAMELEN (language)
+             && strncasecmp ((char *) MTEXT_DATA (MPLIST_MTEXT (pl)),
+                             MSYMBOL_NAME (language),
+                             MSYMBOL_NAMELEN (language)) == 0)
+           return MPLIST_PLIST (plist);
+       }
+    }
+  return NULL;
+}
+
+static MPlist *
+mscript__info (MSymbol script)
+{
+  MPlist *plist;
+
+  if (! script_list
+      && init_script_list () < 0)
+    return NULL;
+  MPLIST_DO (plist, script_list)
+    {
+      MPlist *pl = MPLIST_PLIST (plist);
+
+      if (MPLIST_SYMBOL (pl) == script)
+       return pl;
+    }
+  return NULL;
+}
+
+MPlist *
+mscript__char_list (MSymbol name)
+{
+  MPlist *plist = mscript__info (name);
+
+  if (plist                    /* script name */
+      && (plist = MPLIST_NEXT (plist)) /* language list */
+      && ! MPLIST_TAIL_P (plist)
+      && (plist = MPLIST_NEXT (plist)) /* char list */
+      && MPLIST_PLIST_P (plist))
+    return MPLIST_PLIST (plist);
+  return NULL;
+}
+
+MSymbol
+mscript__otf_tag (MSymbol script)
+{
+  MPlist *plist = mscript__info (script);
+
+  if (plist                    /* script name */
+      && (plist = MPLIST_NEXT (plist)) /* language list */
+      && ! MPLIST_TAIL_P (plist)
+      && (plist = MPLIST_NEXT (plist)) /* char list */
+      && ! MPLIST_TAIL_P (plist)
+      && (plist = MPLIST_NEXT (plist)) /* otf tag */
+      && MPLIST_SYMBOL_P (plist))
+    return MPLIST_SYMBOL (plist);
+  return NULL;
+}
+
+MSymbol
+mscript__from_otf_tag (MSymbol otf_tag)
+{
+  MPlist *plist;
+  /* As it is expected that this function is called in a sequence with
+     the same argument, we use a cache.  */
+  static MSymbol last_otf_tag, script;
+
+  if (! script_list)
+    {
+      last_otf_tag = script = Mnil;
+      if (init_script_list () < 0)
+       return Mnil;
+    }
+  if (otf_tag == last_otf_tag)
+    return script;
+  last_otf_tag = otf_tag;
+  script = Mnil;
+  MPLIST_DO (plist, script_list)
+    {
+      MPlist *pl = MPLIST_PLIST (plist), *p;
+
+      if (pl                          /* script name */
+         && (p = MPLIST_NEXT (pl))    /* language tag */
+         && ! MPLIST_TAIL_P (p)
+         && (p = MPLIST_NEXT (p)) /* char list */
+         && ! MPLIST_TAIL_P (p)
+         && (p = MPLIST_NEXT (p)) /* otf tag */
+         && ! MPLIST_TAIL_P (p))
+       {
+         if (MPLIST_SYMBOL_P (p))
+           {
+             if (otf_tag == MPLIST_SYMBOL (p))
+                 return MPLIST_SYMBOL (pl);
+           }
+         else if (MPLIST_PLIST (p))
+           {
+             MPlist *p0;
+
+             MPLIST_DO (p0, MPLIST_PLIST (p))
+               if (MPLIST_SYMBOL_P (p0) && otf_tag == MPLIST_SYMBOL (p0))
+                 return MPLIST_SYMBOL (pl);
+           }
+       }
+    }
+  return script;
+}
+
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+\f
+
+/* External API */
+
+MSymbol Miso639_1, Miso639_2;
+
+/*=*/
+
+/***en
+    @brief List 3-letter language codes.
+
+    The mlanguage_list () funciton returns a well-formed plist whose
+    keys are #Msymbol and values are symbols whose names are ISO639-2
+    3-letter language codes.
+
+    @return
+    This function returns a plist.  The caller should free it by
+    m17n_object_unref ().
+
+    @seealso
+    mscript_list ().  */
+
+/***ja
+    @brief 3ʸ»ú¸À¸ì¥³¡¼¥É¤ò¥ê¥¹¥È¤¹¤ë.
+
+    ´Ø¿ô mlanguage_list () ¤Ï¡¢À°·Á¼° (well-formed) plist ¤òÊÖ¤¹¡£³Æ¥­¡¼
+    ¤Ï #Msymbol ¤Ç¤¢¤ê¡¢¸Ä¡¹¤ÎÃͤϠISO639-2 ¤ËÄê¤á¤é¤ì¤¿3ʸ»ú¸À¸ì¥³¡¼
+    ¥É¤ò̾Á°¤È¤¹¤ë¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤¬ÊÖ¤¹ plist ¤Ï¡¢¸Æ¤Ó½Ð¤·Â¦¤¬ m17n_object_unref () ¤ò»È¤Ã
+    ¤Æ²òÊü¤¹¤ëɬÍפ¬¤¢¤ë¡£
+
+    @seealso
+    mscript_list ().  */
+
+MPlist *
+mlanguage_list (void)
+{
+  MPlist *plist, *pl, *p, *p0;
+
+  if (! language_list
+      && init_language_list () < 0)
+    return NULL;
+  plist = pl = mplist ();
+  MPLIST_DO (p, language_list)
+    {
+      p0 = MPLIST_PLIST (p);
+      pl = mplist_add (pl, Msymbol, MPLIST_VAL (p0));
+    }
+  return plist;
+}
+
+/*=*/
+
+/***en
+    @brief Get a language code.
+
+    The mlanguage_code () function returns a symbol whose name is the
+    ISO639 language code of $LANGUAGE. $LANGUAGE is a symbol whose
+    name is an ISO639-2 3-letter language code, an ISO639-1 2-letter
+    language codes, or an English word.
+
+    $LEN specifies the type of the returned language code.  If it is
+    3, an ISO639-2 3-letter language code is returned.  If it is 2, an
+    ISO639-1 2-letter language code is returned when defined;
+    otherwise #Mnil is returned.  If it is 0, a 2-letter code is
+    returned when defined; otherwise a 3-letter code is returned.
+
+    @return
+    If the information is available, this function returns a non-#Mnil
+    symbol.  Otherwise, it returns #Mnil.
+
+    @seealso
+    mlanguage_name_list (), mlanguage_text ().  */
+
+/***ja
+    @brief ¸À¸ì¥³¡¼¥É¤òÆÀ¤ë.
+
+    ´Ø¿ô mlanguage_code () ¤Ï¡¢$LANGUAGE ¤ËÂбþ¤·¤¿ ISO-639 ¸À¸ì¥³¡¼¥É
+    ¤¬Ì¾Á°¤Ç¤¢¤ë¤è¤¦¤Ê¥·¥ó¥Ü¥ë¤òÊÖ¤¹¡£$LANGUAGE ¤Ï¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢¤½¤Î
+    Ì¾Á°¤Ï¡¢ISO639-2 3ʸ»ú¸À¸ì¥³¡¼¥É¡¢ISO639-1 2ʸ»ú¸À¸ì¥³¡¼¥É¡¢±Ñ¸ì̾¡¢
+    ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£
+
+    $LEN ¤ÏÊÖ¤µ¤ì¤ë¸À¸ì¥³¡¼¥É¤Î¼ïÎà¤ò·èÄꤹ¤ë¡£$LEN ¤¬3¤Î¾ì¹ç¤Ï 
+    ISO639-2 3ʸ»ú¸À¸ì¥³¡¼¥É¤¬ÊÖ¤µ¤ì¤ë¡£2¤Î¾ì¹ç¤Ï¡¢¤â¤·ÄêµÁ¤µ¤ì¤Æ¤¤¤ì
+    ¤Ð ISO639-1 2ʸ»ú¸À¸ì¥³¡¼¥É¤¬¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð #Mnil ¤¬ÊÖ¤µ¤ì¤ë¡£0 
+    ¤Î¾ì¹ç¤Ï¡¢¤â¤·ÄêµÁ¤µ¤ì¤Æ¤¤¤ì¤Ð2ʸ»ú¥³¡¼¥É¤¬¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð3ʸ»ú¥³¡¼
+    ¥É¤¬ÊÖ¤µ¤ì¤ë¡£
+
+    @return
+    ¤â¤·¾ðÊó¤¬ÆÀ¤é¤ì¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ï #Mnil °Ê³°¤Î¥·¥ó¥Ü¥ë¤òÊÖ¤¹¡£¤½¤¦
+    ¤Ç¤Ê¤±¤ì¤Ð #Mnil ¤òÊÖ¤¹¡£
+
+    @seealso
+    mlanguage_name (), mlanguage_text ().  */
+
+MSymbol
+mlanguage_code (MSymbol language, int len)
+{
+  MPlist *plist = mlanguage__info (language);
+  MSymbol code;
+
+  if (! plist)
+    return Mnil;
+  if (! MPLIST_SYMBOL_P (plist))
+    return Mnil;
+  code = MPLIST_SYMBOL (plist);
+  if (len == 3)
+    return code;
+  plist = MPLIST_NEXT (plist);
+  return ((MPLIST_SYMBOL_P (plist) && MPLIST_SYMBOL (plist) != Mnil)
+         ? MPLIST_SYMBOL (plist)
+         : len == 0 ? code : Mnil);
+}
+
+/*=*/
+
+/***en
+    @brief Return the language names written in the specified language.
+
+    The mlanguage_name_list () function returns a plist of LANGUAGE's
+    names written in TARGET language.  SCRIPT and TERRITORY, if not #Mnil,
+    specifies which script and territory to concern at first.
+
+    LANGUAGE and TARGET must be a symbol whose name is an ISO639-2
+    3-letter language code or an ISO639-1 2-letter language codes.
+    TARGET may be #Mnil, in which case, the language of the current
+    locale is used.  If locale is not set or is C, English is used.
+
+    SCRIPT and TERRITORY must be a symbol whose name is a script and
+    territory name of a locale (e.g. "TW", "SG") respectively.
+
+    @return
+    If the translation is available, this function returns a non-empty
+    plist.  The first element has key #MText and the value is an
+    M-text of a translated language name.  If the succeeding elements
+    also have key #MText, their values are M-texts of alternate
+    translations.
+
+    If no translation is available, @c NULL is returned.
+
+    The returned plist should not be modified nor freed.
+
+    @seealso
+    mlanguage_code (), mlanguage_text ().  */
+
+MPlist *
+mlanguage_name_list (MSymbol language, MSymbol target,
+                    MSymbol script, MSymbol territory)
+{
+  MPlist *plist, *pl;
+  MSymbol language2, target2;
+
+  plist = mlanguage__info (language);
+  if (! plist)
+    return NULL;
+  language = MPLIST_SYMBOL (plist);
+  language2 = MPLIST_SYMBOL (MPLIST_NEXT (plist));
+  if (target != Mnil)
+    {
+      plist = mlanguage__info (target);
+      if (! plist)
+       return NULL;
+      target = MPLIST_SYMBOL (plist);
+      target2 = MPLIST_SYMBOL (MPLIST_NEXT (plist));
+    }
+  else
+    {
+      MLocale *locale = mlocale_set (LC_MESSAGES, NULL);
+
+      if (! locale)
+       {
+         target = msymbol ("eng");
+         target2 = msymbol ("en");
+         script = territory = Mnil;
+       }
+      else
+       {
+         target = mlocale_get_prop (locale, Mlanguage);
+         plist = mlanguage__info (target);
+         if (! plist)
+           return NULL;
+         target = MPLIST_SYMBOL (plist);
+         target2 = MPLIST_SYMBOL (MPLIST_NEXT (plist));
+         script = mlocale_get_prop (locale, Mscript);
+         territory = mlocale_get_prop (locale, Mterritory);
+       }
+    }
+
+  /* Now both LANGUAGE and TARGET are 3-letter codes.  */
+  if (! langname_list)
+    langname_list = mplist ();
+  plist = mplist__assq (langname_list, target);
+  if (plist)
+    plist = MPLIST_PLIST (plist);
+  else
+    plist = load_lang_name (target, target2);
+
+  /* PLIST = (TARGET (SCRIPT (TERRITORY ...) (LANG-CODE NAME ...) ...) ...) */
+  plist = MPLIST_NEXT (plist);
+  if (MPLIST_TAIL_P (plist))
+    return NULL;
+
+  MPLIST_DO (pl, plist)
+    {
+      MPlist *p = MPLIST_PLIST (pl), *p0;
+
+      if (MPLIST_SYMBOL (p) == script
+         && (territory == Mnil
+             || mplist_find_by_value (MPLIST_PLIST (MPLIST_NEXT (p)),
+                                      territory))
+         && (p = MPLIST_NEXT (MPLIST_NEXT (p)))
+         && ((p0 = mplist__assq (p, language))
+             || (p0 = mplist__assq (p, language2))))
+       {
+         plist = p0;
+         break;
+       }
+    }
+  if (MPLIST_TAIL_P (pl))
+    {
+      MPLIST_DO (pl, plist)
+       {
+         MPlist *p = MPLIST_NEXT (MPLIST_PLIST (pl)), *p0;
+
+         if ((territory == Mnil
+              || mplist_find_by_value (MPLIST_VAL (p), territory))
+             && (p = MPLIST_NEXT (MPLIST_NEXT (p)))
+             && ((p0 = mplist__assq (p, language))
+                 || (p0 = mplist__assq (p, language2))))
+           {
+             plist = p0;
+             break;
+           }
+       }
+      if (MPLIST_TAIL_P (pl))
+       {
+         MPLIST_DO (pl, plist)
+           {
+             MPlist *p = MPLIST_NEXT (MPLIST_NEXT (MPLIST_PLIST (pl))), *p0;
+
+             if ((p0 = mplist__assq (p, language))
+                 || (p0 = mplist__assq (p, language2)))
+               {
+                 plist = p0;
+                 break;
+               }
+           }
+         if (MPLIST_TAIL_P (pl))
+           return NULL;
+       }
+    }
+
+  plist = MPLIST_NEXT (MPLIST_PLIST (plist));
+  if (territory != Mnil)
+    {
+      MPLIST_DO (pl, MPLIST_NEXT (plist))
+       if (MPLIST_SYMBOL_P (pl) && MPLIST_SYMBOL (pl) == territory)
+         break;
+      if (! MPLIST_TAIL_P (pl)
+         && (pl = MPLIST_NEXT (pl))
+         && MPLIST_MTEXT_P (pl))
+       return pl;
+    }
+  MPLIST_DO (plist, plist)
+    if (MPLIST_MTEXT_P (plist))
+      break;
+  return (MPLIST_MTEXT_P (plist) ? plist : NULL);
+}
+
+/*=*/
+
+/***en
+    @brief Return the language name written in that language.
+
+    The mlanguage_text () function returns, in the form of M-text, the
+    language name of $LANGUAGE written in $LANGUAGE.  If the
+    representative characters of the language are known, the
+    characters of the returned M-text has a text property whose key is
+    #Mtext and whose value is an M-text that contains the
+    representative characters.
+
+    @return
+    If the information is available, this function returns an M-text
+    that should not be modified nor freed.  Otherwise, it returns @c
+    NULL.
+
+    @seealso
+    mlanguage_code (), mlanguage_name ().  */
+
+/***ja
+    @brief Í¿¤¨¤é¤ì¤¿¸À¸ì¼«¿È¤Ç½ñ¤«¤ì¤¿¸À¸ì̾¤òÊÖ¤¹.
+
+    ´Ø¿ô mlanguage_text () ¤Ï¡¢¸À¸ì $LANGUAGE ¤Ç½ñ¤«¤ì¤¿ $LANGUAGE ¤Î
+    Ì¾Á°¤ò M-text ¤Î·Á¼°¤ÇÊÖ¤¹¡£¤½¤Î¸À¸ì¤ÎÂåɽŪ¤Êʸ»ú¤¬¤ï¤«¤Ã¤Æ¤¤¤ë¾ì
+    ¹ç¤Ï¡¢ÊÖ¤µ¤ì¤ë M-text ¤Î³Æʸ»ú¤Ë¡¢¥­¡¼¤¬ #Mtext ¤ÇÃͤ¬¤½¤ÎÂåɽŪ¤Ê
+    Ê¸»ú¤ò´Þ¤à M-text ¤Ç¤¢¤ë¤è¤¦¤Ê¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤¬Éղ䵤ì¤ë¡£
+
+    @return
+    µá¤á¤ë¾ðÊó¤¬ÆÀ¤é¤ì¤¿¾ì¹ç¡¢¤³¤Î´Ø¿ô¤¬ÊÖ¤¹ M-text ¤òÊѹ¹¤·¤¿¤ê²òÊü¤·
+    ¤¿¤ê¤·¤Æ¤Ï¤¤¤±¤Ê¤¤¡£¾ðÊó¤¬ÆÀ¤é¤ì¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï @c NULL ¤¬ÊÖ¤µ¤ì¤ë¡£
+
+    @seealso
+    mlanguage_code (), mlanguage_name ().  */
+
+MText *
+mlanguage_text (MSymbol language)
+{
+  MPlist *plist = mlanguage__info (language);
+  MText *mt;
+
+  if (! plist)
+    return NULL;
+  plist = MPLIST_NEXT (plist);
+  if (MPLIST_TAIL_P (plist))
+    return NULL;
+  plist = MPLIST_NEXT (plist);
+  if (MPLIST_TAIL_P (plist))
+    return NULL;
+  plist = MPLIST_NEXT (plist);           
+  if (! MPLIST_MTEXT_P (plist))
+    return NULL;
+  mt = MPLIST_MTEXT (plist);
+  if (mtext_nchars (mt) == 0)
+    return NULL;
+  plist = MPLIST_NEXT (plist);
+  if (MPLIST_MTEXT_P (plist)
+      && ! mtext_get_prop (mt, 0, Mtext))
+    mtext_put_prop (mt, 0, mtext_nchars (mt), Mtext, MPLIST_MTEXT (plist));
+  return mt;
+}
+
+/***en
+    @brief List script names.
+
+    The mscript_list () funciton returns a well-formed plist whose
+    keys are #Msymbol and values are symbols whose names are script
+    names.
+
+    @return
+    This function returns a plist.  The caller should free it by
+    m17n_object_unref ().
+
+    @seealso
+    mscript_language_list (), mlanguage_list ().  */
+
+/***ja
+    @brief ¥¹¥¯¥ê¥×¥È̾¤ò¥ê¥¹¥È¤¹¤ë.
+
+    ´Ø¿ô mscript_list () ¤Ï¡¢À°·Á¼° (well-formed) plist ¤òÊÖ¤¹¡£³Æ¥­¡¼
+    ¤Ï #Msymbol ¤Ç¤¢¤ê¡¢¸Ä¡¹¤ÎÃͤϥ¹¥¯¥ê¥×¥È̾¤ò̾Á°¤È¤¹¤ë¥·¥ó¥Ü¥ë¤Ç¤¢
+    ¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤¬ÊÖ¤¹ plist ¤Ï¡¢¸Æ¤Ó½Ð¤·Â¦¤¬ m17n_object_unref () ¤ò»È¤Ã
+    ¤Æ²òÊü¤¹¤ëɬÍפ¬¤¢¤ë¡£
+
+    @seealso
+    mscript_language_list (), mlanguage_list ().  */
+
+MPlist *
+mscript_list (void)
+{
+  MPlist *plist, *pl, *p, *p0;
+
+  if (! script_list
+      && init_script_list () < 0)
+    return NULL;
+  plist = pl = mplist ();
+  MPLIST_DO (p, script_list)
+    {
+      p0 = MPLIST_PLIST (p);
+      pl = mplist_add (pl, Msymbol, MPLIST_VAL (p0));
+    }
+  return plist;
+}
+
+/*=*/
+
+/***en
+    @brief List languages that use a specified script.
+
+    The mscript_language_list () function lists languages that use
+    $SCRIPT.  $SCRIPT is a symbol whose name is the lower-cased
+    version of a script name that appears in the Unicode Character
+    Database.
+
+    @return
+
+    This function returns a well-formed plist whose keys are #Msymbol
+    and values are symbols whose names are ISO639-1 2-letter codes (or
+    ISO639-2 3-letter codes, if the former is not available).  The
+    caller should not modify nor free it.  If the m17n library does
+    not know about $SCRIPT, it returns @ c NULL.
+
+    @seealso
+    mscript_list (), mlanguage_list ().  */
+
+/***ja
+    @brief Í¿¤¨¤é¤ì¤¿¥¹¥¯¥ê¥×¥È¤òÍѤ¤¤ë¸À¸ì¤ò¥ê¥¹¥È¤¹¤ë.
+
+    ´Ø¿ô mscript_language_list () ¤Ï¡¢$SCRIPT ¤òÍѤ¤¤ë¸À¸ì¤ò¥ê¥¹¥È¤¹¤ë¡£
+    $SCRIPT ¤Ï¥·¥ó¥Ü¥ë¤Ç¡¢¤½¤Î̾Á°¤Ï Unicode Character Database ¤Ë¼¨¤µ
+    ¤ì¤Æ¤¤¤ë¥¹¥¯¥ê¥×¥È̾¤ò¤¹¤Ù¤Æ¾®Ê¸»ú¤Ë¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
+
+    @return 
+    ¤³¤Î´Ø¿ô¤Ï¡¢À°·Á¼° (well-formed) plist ¤òÊÖ¤¹¡£³Æ¥­¡¼¤Ï 
+    #Msymbol ¤Ç¤¢¤ê¡¢¸Ä¡¹¤ÎÃͤϠISO639-1 ¤ËÄê¤á¤é¤ì¤¿2ʸ»ú¸À¸ì¥³¡¼¥É
+    (ÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï ISO639-2 ¤ËÄê¤á¤é¤ì¤¿3ʸ»ú¸À¸ì¥³¡¼¥É) ¤ò̾
+    Á°¤È¤¹¤ë¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£ÊÖ¤µ¤ì¤ë plist ¤ÏÊѹ¹¤·¤¿¤ê²òÊü¤·¤¿¤ê¤·¤Æ
+    ¤Ï¤Ê¤é¤Ê¤¤¡£$SCRIPT ¤¬Ì¤ÃΤξì¹ç¤Ï @c NULL ¤¬ÊÖ¤µ¤ì¤ë¡£
+
+    @seealso
+    mscript_list (), mlanguage_list ().  */
+    
+
+MPlist *
+mscript_language_list (MSymbol script)
+{
+  MPlist *plist = mscript__info (script);
+
+  if (plist                    /* script name */
+      && (plist = MPLIST_NEXT (plist)) /* language list */
+      && MPLIST_PLIST_P (plist))
+    return MPLIST_PLIST (plist);
+  return NULL;
+}
+
+/*** @} */
+/*=*/
+/***en
+    @name Obsolete functions
+*/
+/***ja
+    @name Obsolete ¤Ê´Ø¿ô
+*/
+/*** @{ */
+
+/***en
+    @brief Get an English language name.
+
+    This function is obsolete.  Use mlanguage_name_list () instead.
+
+    The mlanguage_name () function returns a symbol whose name is an
+    English name of $LANGUAGE.  $LANGUAGE is a symbol whose name is an
+    ISO639-2 3-letter language code, an ISO639-1 2-letter language
+    codes, or an English word.
+
+    @return
+    If the information is available, this function returns a non-#Mnil
+    symbol.  Otherwise, it returns #Mnil.
+
+    @seealso
+    mlanguage_code (), mlanguage_text ().  */
+
+/***ja
+    @brief ¸À¸ì¤Î±Ñ¸ì̾¤òÆÀ¤ë.
+
+    ´Ø¿ô mlanguage_name () ¤Ï¡¢$LANGUAGE ¤Î±Ñ¸ì̾¤ò̾Á°¤È¤¹¤ë¤è¤¦¤Ê¥·
+    ¥ó¥Ü¥ë¤òÊÖ¤¹¡£$LANGUAGE ¤Ï¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢¤½¤Î̾Á°¤Ï¡¢ISO639-2 3ʸ
+    »ú¸À¸ì¥³¡¼¥É¡¢ISO639-1 2ʸ»ú¸À¸ì¥³¡¼¥É¡¢±Ñ¸ì̾¡¢¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£
+
+    @return
+    µá¤á¤Æ¤¤¤ë¾ðÊó¤¬ÆÀ¤é¤ì¤ë¤Ê¤é¡¢¤³¤Î´Ø¿ô¤Ï #Mnil °Ê³°¤Î¥·¥ó¥Ü¥ë¤òÊÖ
+    ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð #Mnil ¤òÊÖ¤¹¡£
+
+    @seealso
+    mlanguage_code (), mlanguage_text ().  */
+
+MSymbol
+mlanguage_name (MSymbol language)
+{
+  MPlist *plist = mlanguage__info (language);
+  MText *mt;
+  char *str;
+
+  if (! plist)                 /* 3-letter code */
+    return Mnil;
+  plist = MPLIST_NEXT (plist); /* 2-letter code */
+  if (MPLIST_TAIL_P (plist))
+    return Mnil;
+  plist = MPLIST_NEXT (plist); /* english name */
+  if (! MPLIST_MTEXT_P (plist))
+    return Mnil;
+  mt = MPLIST_MTEXT (plist);
+  str = alloca (mtext_nbytes (mt));
+  memcpy (str, MTEXT_DATA (mt), mtext_nbytes (mt));
+  str[0] = tolower (str[0]);
+  return msymbol__with_len (str, mtext_nbytes (mt));
+}
+
+/*=*/
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/language.h b/src/language.h
new file mode 100644 (file)
index 0000000..ba911ef
--- /dev/null
@@ -0,0 +1,32 @@
+/* language.h -- header file for the language (and script) module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_LANGUAGE_H_
+#define _M17N_LANGUAGE_H_
+
+extern MPlist *mscript__char_list (MSymbol script);
+
+extern MSymbol mscript__otf_tag (MSymbol script);
+
+extern MSymbol mscript__from_otf_tag (MSymbol otf_tag);
+
+#endif /* _M17N_LANGUAGE_H_ */
diff --git a/src/linkcore.c b/src/linkcore.c
new file mode 100644 (file)
index 0000000..87322b1
--- /dev/null
@@ -0,0 +1,32 @@
+/* linkcore.c -- test program for linking with m17n-core.so.
+   Copyright (C) 2003
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+This file is part of the m17n library.
+
+The m17n library is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2, or (at
+your option) any later version.
+
+The m17n 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with the m17n library; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
+
+#include <stdlib.h>
+#include "m17n-core.h"
+
+int
+main ()
+{
+  M17N_INIT ();
+  M17N_FINI ();
+  exit (0);
+}
diff --git a/src/linkgui.c b/src/linkgui.c
new file mode 100644 (file)
index 0000000..5918d47
--- /dev/null
@@ -0,0 +1,33 @@
+/* linkgui.c -- test program for linking with m17n-X.so.
+   Copyright (C) 2003, 2004
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#include <stdlib.h>
+#include "m17n-gui.h"
+#include "m17n-misc.h"
+
+int
+main ()
+{
+  M17N_INIT ();
+  M17N_FINI ();
+  exit (0);
+}
diff --git a/src/linkshell.c b/src/linkshell.c
new file mode 100644 (file)
index 0000000..e2e6298
--- /dev/null
@@ -0,0 +1,32 @@
+/* linkshell.c -- test program for linking with m17n.so.
+   Copyright (C) 2003, 2004
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#include <stdlib.h>
+#include <m17n.h>
+
+int
+main ()
+{
+  M17N_INIT ();
+  M17N_FINI ();
+  exit (0);
+}
diff --git a/src/locale.c b/src/locale.c
new file mode 100644 (file)
index 0000000..f9c1f0e
--- /dev/null
@@ -0,0 +1,650 @@
+/* locale.c -- locale module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nLocale
+    @brief Locale objects and API for them.
+
+    The m17n library represents locale related information as objects
+    of type #MLocale.  */
+
+/***ja
+    @addtogroup m17nLocale
+    @brief ¥í¥±¡¼¥ë¥ª¥Ö¥¸¥§¥¯¥È¤È¤½¤ì¤Ë´Ø¤¹¤ë API.
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï¥í¥±¡¼¥ë´ØÏ¢¾ðÊó¤ò #MLocale ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Çɽ¸½¤¹¤ë¡£  */
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#define _GNU_SOURCE
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+#include <time.h>
+
+#include "m17n.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "symbol.h"
+#include "coding.h"
+#include "textprop.h"
+#include "mlocale.h"
+
+static MSymbol M_locale;
+static MSymbol M_xfrm;
+
+
+/** Structure of locales.  */
+
+struct MLocale
+{
+  M17NObject control;
+  MSymbol name;
+  MSymbol language;
+  MSymbol territory;
+  MSymbol modifier;
+  MSymbol codeset;
+  MSymbol coding;
+};
+
+
+/** The current locales of each category.  */
+MLocale *mlocale__collate, *mlocale__ctype;
+MLocale *mlocale__messages, *mlocale__time;
+
+/* These are currently not used.  */
+#if 0
+MLocale *mlocale_monetary, *mlocale_numeric, ;
+#endif
+
+/** Parse locale name NAME and return a newly created MLocale object.
+    If the locale is not supported by the system, return NULL.  */
+
+static MLocale *
+make_locale (const char *name)
+{
+  char *current, *new, *str;
+  int len;
+  MLocale *locale;
+  char c;
+
+  str = setlocale (LC_CTYPE, NULL);
+  len = strlen (str) + 1;
+  current = alloca (len);
+  memcpy (current, str, len); 
+
+  if (! (new = setlocale (LC_CTYPE, name)))
+    return NULL;
+
+
+  M17N_OBJECT (locale, NULL, MERROR_LOCALE);
+  locale->name = msymbol (new);
+  msymbol_put (locale->name, M_locale, (void *) locale);
+  M17N_OBJECT_UNREF (locale);
+
+  len = strlen (new) + 1;
+  str = alloca (len);
+  memcpy (str, new, len);
+
+  c = '\0';
+  while (1)
+    {
+      char c1;
+      int i;
+
+      for (i = 0; str[i]; i++)
+       if (str[i] == '_' || str[i] == '.' || str[i] == '@')
+         break;
+      c1 = str[i];
+      str[i] = '\0';
+      if (c == '\0')
+       /* The first field is for language.  */
+       locale->language = msymbol (str);
+      else if (c == '_')
+       /* The field following '_' is for territory.  */
+       locale->territory = msymbol (str);
+      else if (c == '.')
+       /* The field following '.' is for codeset.  */
+       locale->codeset = msymbol (str);
+      else
+       /* The other field is for modifier.  */
+       locale->modifier = msymbol (str);
+      if (! c1)
+       break;
+      c = c1;
+      str += i + 1;
+    }
+
+#ifdef HAVE_NL_LANGINFO
+#ifdef CODESET
+  /* If we can use nl_langinfo () to retrieve a codeset name, respect
+     it over the codeset name extracted from the locale name.  */
+  locale->codeset = msymbol (nl_langinfo (CODESET));
+#endif
+#endif
+
+  /* If the locale name specifies a codeset, get the corresponding
+     coding system.  */
+  if (locale->codeset != Mnil)
+    {
+      locale->coding = mconv_resolve_coding (locale->codeset);
+      if (locale->coding == Mnil)
+       locale->coding = Mcoding_us_ascii;
+    }
+  else
+    locale->coding = Mcoding_us_ascii;
+
+  setlocale (LC_CTYPE, current);
+  return locale;
+}
+
+
+/** Decode the byte sequence at BUF of length SIZE bytes by the coding
+    system associated with LOCALE, and return a generated M-text.  */
+
+static MText *
+decode_locale (unsigned char *buf, int size, MLocale *locale)
+{
+  return mconv_decode_buffer (locale->coding, buf, size);
+}
+
+
+/** Encode the M-text MT by the coding system associated with LOCALE,
+    and store the resulting bytes in the memory area at BUF of *SIZE
+    bytes.  If the area is too short, allocate a new and wider area.
+    Store the length of the generated bytes in the place pointed by
+    SIZE, and return the address of those bytes.  */
+
+static unsigned char *
+encode_locale (MText *mt, unsigned char *buf, int *size, MLocale *locale)
+{
+  int nbytes = mconv_encode_buffer (locale->coding, mt, buf, *size - 1);
+
+  if (nbytes < 0)
+    {
+      buf = NULL;
+      *size *= 2;
+      do {
+       MTABLE_REALLOC (buf, *size, MERROR_LOCALE);
+       nbytes = mconv_encode_buffer (mlocale__ctype->coding, mt, buf,
+                                     *size - 1);
+      } while (nbytes < 0);
+    }
+  buf[nbytes] = '\0';
+  *size = nbytes;
+  return buf;
+}
+
+
+/** Structure of transformed strings.  The function mtext_coll ()
+    caches this object in an M-text as a text property.  */
+
+typedef struct {
+  /* Common header for a managed object.  */
+  M17NObject control;
+
+  /* Locale corresponding to <str>.  */
+  MLocale *locale;
+
+  /** Result of strxfrm.  */
+  char *str;
+} MXfrm;
+
+
+static void
+free_xfrm (void *object)
+{
+  MXfrm *xfrm = (MXfrm *) object;
+
+  M17N_OBJECT_UNREF (xfrm->locale);
+  free (xfrm->str);
+}
+
+static char *
+get_xfrm (MText *mt)
+{
+  MTextProperty *prop = mtext_get_property (mt, 0, M_xfrm);
+  MXfrm *xfrm;
+  int size;
+  unsigned char *buf, *newbuf;
+  int request;
+
+  if (prop)
+    {
+      if (prop->end == mt->nchars)
+       {
+         xfrm = (MXfrm *) prop->val;
+         if (xfrm->locale == mlocale__ctype)
+           return xfrm->str;
+       }
+      mtext_detach_property (prop);
+    }
+
+  size = mt->nbytes;
+  buf = alloca (size);
+  newbuf = encode_locale (mt, buf, &size, mlocale__ctype);
+  M17N_OBJECT (xfrm, free_xfrm, MERROR_MTEXT);
+  xfrm->str = malloc (size);
+  request = strxfrm (xfrm->str, (char *) newbuf, size);
+  if (request >= size)
+    {
+      xfrm->str = realloc (xfrm->str, request);
+      strxfrm (xfrm->str, (char *) newbuf, size);
+    }
+  if (buf != newbuf)
+    free (newbuf);
+  prop = mtext_property (M_xfrm, xfrm, MTEXTPROP_VOLATILE_WEAK);
+  mtext_attach_property (mt, 0, mt->nchars, prop);
+  M17N_OBJECT_UNREF (prop);
+  return xfrm->str;
+}
+
+\f
+/* Internal API */
+
+int
+mlocale__init ()
+{
+  M_locale = msymbol_as_managing_key ("  locale");
+
+  Mterritory = msymbol ("territory");
+  Mcodeset = msymbol ("codeset");
+
+  mlocale__collate = mlocale_set (LC_COLLATE, NULL);
+  M17N_OBJECT_REF (mlocale__collate);
+  mlocale__ctype = mlocale_set (LC_CTYPE, NULL);
+  M17N_OBJECT_REF (mlocale__ctype);
+  mlocale__messages = mlocale_set (LC_MESSAGES, NULL);
+  M17N_OBJECT_REF (mlocale__messages);
+  mlocale__time = mlocale_set (LC_TIME, NULL);
+  M17N_OBJECT_REF (mlocale__time);
+
+  M_xfrm = msymbol_as_managing_key ("  xfrm");
+  return 0;
+}
+
+void
+mlocale__fini ()
+{
+  M17N_OBJECT_UNREF (mlocale__collate);
+  M17N_OBJECT_UNREF (mlocale__ctype);
+  M17N_OBJECT_UNREF (mlocale__messages);
+  M17N_OBJECT_UNREF (mlocale__time);
+}
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+/* External API */
+/*** @addtogroup m17nLocale */
+/*** @{ */
+
+/*=*/
+/***en The symbol whose name is "territory".  */
+/***ja  "territory" ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë. */
+MSymbol Mterritory;
+
+/*=*/
+/***en The symbol whose name is "modifier".  */
+/***ja  "modifier" ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë. */
+MSymbol Mmodifier;
+
+/*=*/
+/***en The symbol whose name is "codeset".  */
+/***ja  "codeset" ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë. */
+MSymbol Mcodeset;
+
+/*=*/
+
+/***en
+    @brief Set the current locale.
+
+    The mlocale_set () function sets or query a part of the current
+    locale.  The part is specified by $CATEGORY which must be a valid
+    first argument to <tt>setlocale ()</tt>.
+
+    If $LOCALE is not NULL, the locale of the specified part is set to
+    $LOCALE.  If $LOCALE is not supported by the system, the current
+    locale is not changed.
+
+    If $LOCALE is NULL, the current locale of the specified part is
+    queried.
+
+    @return
+    If the call is successful, mlocale_set () returns an opaque locale
+    object that corresponds to the locale.  The name of the locale can
+    be acquired by the function mlocale_get_prop ().
+    Otherwise, it returns NULL.  */
+
+/***ja
+    @brief ¸½ºß¤Î¥í¥±¡¼¥ë¤òÀßÄꤹ¤ë.
+
+    ´Ø¿ô mlocale_set () ¤Ï¸½ºß¤Î¥í¥±¡¼¥ë¤Î°ìÉô¤òÀßÄꤷ¤¿¤êÌ䤤¹ç¤ï¤»¤¿¤ê¤¹¤ë¡£¤³¤³¤Ç°ìÉô¤È¤Ï 
+    $CATEGORY ¤Ç»ØÄꤵ¤ì¡¢<tt>setlocale ()</tt> ¤ÎÍ­¸ú¤ÊÂè°ì°ú¿ô¤È¤Ê¤ë¤â¤Î¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    $LOCALE ¤¬ NULL ¤Ç¤Ê¤±¤ì¤Ð¡¢»ØÄꤷ¤¿Éôʬ¤Î¥í¥±¡¼¥ë¤¬$LOCALE ¤ËÀßÄꤵ¤ì¤ë¡£
+    $LOCALE ¤¬¥·¥¹¥Æ¥à¤Ë¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¡¢ÀßÄê¤Ï¹Ô¤ï¤ì¤º¡¢¸½ºß¤Î¥í¥±¡¼¥ë¤ÏÊѤï¤é¤Ê¤¤¡£
+
+    $LOCALE ¤¬ NULL ¤Ê¤é¤Ð¡¢¸½ºß¤Î¥í¥±¡¼¥ë¤Î»ØÄꤷ¤¿Éôʬ¤òÌ䤤¹ç¤ï¤»¤ë¡£
+
+    @return 
+
+    ¸Æ¤Ó½Ð¤·¤ËÀ®¸ù¤¹¤ì¤Ð¡¢mlocale_set () ¤Ï¥í¥±¡¼¥ë¤ËÂбþ¤¹¤ë opaque 
+    ¥í¥±¡¼¥ë¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤¹¡£¥í¥±¡¼¥ë¤Î̾Á°¤Ï´Ø¿ô
+    mlocale_get_prop () ¤Ë¤è¤Ã¤ÆÆÀ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð NULL ¤òÊÖ¤¹¡£
+     */
+
+/***
+    @errors
+    @c MERROR_LOCALE  */
+
+MLocale *
+mlocale_set (int category, const char *name)
+{
+  char *new;
+  MLocale *locale;
+
+  new = setlocale (category, name);
+  if (! new)
+    return NULL;
+
+  locale = (MLocale *) msymbol_get (msymbol (new), M_locale);
+  if (! locale)
+    locale = make_locale (new);
+  if (! locale)
+    return NULL;
+  if (name && (category == LC_ALL || category == LC_COLLATE))
+    {
+      M17N_OBJECT_REF (locale);
+      M17N_OBJECT_UNREF (mlocale__collate);
+      mlocale__collate = locale;
+    }
+  else if (name && (category == LC_ALL || category == LC_CTYPE))
+    {
+      M17N_OBJECT_REF (locale);
+      M17N_OBJECT_UNREF (mlocale__ctype);
+      mlocale__ctype = locale;
+    }
+  if (name && (category == LC_ALL || category == LC_MESSAGES))
+    {
+      M17N_OBJECT_REF (locale);
+      M17N_OBJECT_UNREF (mlocale__messages);
+      mlocale__messages = locale;
+    }
+  if (name && (category == LC_ALL || category == LC_TIME))
+    {
+      M17N_OBJECT_REF (locale);
+      M17N_OBJECT_UNREF (mlocale__time);
+      mlocale__time = locale;
+    }
+  return locale;
+}
+
+/*=*/
+
+/***en
+    @brief Get the value of a locale property.
+
+    The mlocale_get_prop () function returns the value of a property
+    $KEY of local $LOCALE.  $KEY must be #Mname, #Mlanguage,
+    #Mterritory, #Mcodeset, #Mmodifier, or #Mcoding.  */ 
+
+/***ja
+    @brief ¥í¥±¡¼¥ë¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë.
+
+    ´Ø¿ô mlocale_get_prop () ¤Ï¡¢¥í¥±¡¼¥ë $LOCALE ¤Î $KEY ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£
+    $KEY ¤Ï #Mname, #Mlanguage, #Mterritory, #Mcodeset, #Mmodifier, 
+    #Mcoding ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£ */ 
+
+MSymbol
+mlocale_get_prop (MLocale *locale, MSymbol key)
+{
+  if (key == Mcoding)
+    return locale->coding;
+  if (key == Mname)
+    return locale->name;
+  if (key == Mlanguage)
+    return locale->language;
+  if (key == Mterritory)
+    return locale->territory;
+  if (key == Mcodeset)
+    return locale->codeset;
+  if (key == Mmodifier)
+    return locale->modifier;
+  return Mnil;
+}
+
+/*=*/
+/***en
+    @brief Format date and time.
+
+    The mtext_ftime () function formats the broken-down time $TM
+    according to the format specification $FORMAT and append the
+    result to the M-text $MT.  The formating is done according to the
+    locale $LOCALE (if not NULL) or the current locale (LC_TIME).
+
+    The meaning of the arguments $TM and $FORMAT are the same as those
+    of strftime ().
+
+    @seealso
+    strftime ().
+*/
+/***ja
+    @brief ÆüÉդȻþ´Ö¤ò¥Õ¥©¡¼¥Þ¥Ã¥È¤¹¤ë.
+
+    ´Ø¿ô mtext_ftime () ¤Ï»þ¹ï¥Ç¡¼¥¿ (broken-down time) $TM ¤ò$FORMAT 
+    ¤Ç»ØÄꤵ¤ì¤¿·Á¼°¤ËÀ¶½ñ¤·¡¢·ë²Ì¤òM-text $MT ¤ËÉղ乤롣¥Õ¥©¡¼¥Þ¥Ã¥È¤Ï 
+    NULL ¤Ç¤Ê¤±¤ì¤Ð ¥í¥±¡¼¥ë $LOCALE ¤Ë¡¢¤Þ¤¿¤Ï¸½ºß¤Î¥í¥±¡¼¥ë(LC_TIME) ¤Ë½¾¤¦¡£
+
+    °ú¿ô $TM ¤È $FORMAT ¤Î°ÕÌ£¤Ï strftime () ¤Î¾ì¹ç¤ÈƱ¤¸¡£
+
+    @seealso
+    strftime ().
+*/
+
+int
+mtext_ftime (MText *mt, const char *format, const struct tm *tm,
+            MLocale *locale)
+{
+  int bufsize;
+  unsigned char *buf;
+  size_t nbytes, nchars;
+  char *current_locale = NULL;
+
+  if (locale)
+    {
+      char *str = setlocale (LC_TIME, NULL);
+      int len = strlen (str) + 1;
+
+      current_locale = alloca (len);
+      memcpy (current_locale, str, len);
+      mlocale_set (LC_TIME, msymbol_name (locale->name));
+    }
+
+  bufsize = 1024;
+  while (1)
+    {
+      MTABLE_ALLOCA (buf, bufsize, MERROR_MTEXT);
+      buf[0] = 1;
+      nbytes = strftime ((char *) buf, bufsize, format, tm);
+      if (nbytes > 0
+         || ! buf[0])
+       break;
+      bufsize *= 2;
+    }
+
+  if (nbytes > 0)
+    {
+      MText *work = decode_locale (buf, nbytes, mlocale__time);
+
+      if (work)
+       {
+         nchars = work->nchars;
+         mtext_cat (mt, work);
+         M17N_OBJECT_UNREF (work);
+       }
+      else
+       nchars = 0;
+    }
+  else
+    nchars = 0;
+
+  if (current_locale)
+    mlocale_set (LC_TIME, current_locale);
+
+  return nchars;
+}
+         
+/*=*/
+
+/***en
+    @brief Get an environment variable.
+
+    The mtext_getenv () function searches the environment variable
+    list for a string that matches the string pointed to by $NAME.
+
+    If there is a match, the function decodes the value according to
+    the current locale (LC_CTYPE) into an M-text, and return that
+    M-text.
+
+    If there is no match, the function returns NULL.  */
+/***ja
+    @brief ´Ä¶­ÊÑ¿ô¤òÆÀ¤ë.
+
+    ´Ø¿ô mtext_getenv () ¤Ï $NAME 
+    ¤Ç»Ø¤µ¤ì¤ëʸ»úÎó¤È¹çÃפ¹¤ëʸ»úÎó¤ò´Ä¶­ÊÑ¿ô¤Î¥ê¥¹¥ÈÃ椫¤éõ¤¹¡£
+
+    ¸«¤Ä¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢¤½¤ÎÃͤò¸½ºß¤Î¥í¥±¡¼¥ë(LC_CTYPE) ¤Ë½¾¤Ã¤Æ 
+    M-text ¤Ë¥Ç¥³¡¼¥É¤·¡¢¤½¤ÎM-text ¤òÊÖ¤¹¡£
+
+    ¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð¡¢NULL ¤òÊÖ¤¹¡£  */
+
+MText *
+mtext_getenv (const char *name)
+{
+  char *p = getenv (name);
+
+  if (!p)
+    return NULL;
+  return decode_locale ((unsigned char *) p, strlen (p), mlocale__ctype);
+}
+
+/*=*/
+
+/***en
+    @brief Change or add an environment variable.
+
+    The mtext_putenv () function changes or adds the value of
+    environment variables according to M-text $MT.  It calls the
+    function <tt>putenv</tt> with an argument generated by encoding
+    $MT according to the current locale (LC_CTYPE).
+
+    @return
+    This function returns zero on success, or -1 if an error
+    occurs.  */
+/***ja
+    @brief ´Ä¶­ÊÑ¿ô¤òÊѹ¹¡¿Äɲ乤ë.
+
+    ´Ø¿ô mtext_putenv () ¤Ï M-text $MT 
+    ¤Ë½¾¤Ã¤Æ¡¢´Ä¶­ÊÑ¿ô¤ÎÃͤòÊѹ¹¤·¤¿¤êÄɲä·¤¿¤ê¤¹¤ë¡£¤³¤Î´Ø¿ô¤Ï¡¢¸½ºß¤Î¥í¥±¡¼¥ë
+    (LC_CTYPE) ¤Ë½¾¤Ã¤Æ$MT ¤ò¥¨¥ó¥³¡¼¥É¤·¡¢¤½¤ì¤ò°ú¿ô¤È¤·¤Æ´Ø¿ô <tt>putenv</tt> ¤ò¸Æ¤Ö¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¡¢À®¸ù¤·¤¿¾ì¹ç¤Ë¤Ï 0 ¤ò¡¢¥¨¥é¡¼¤¬µ¯¤³¤ì¤Ð -1 ¤òÊÖ¤¹¡£
+    */
+
+
+int
+mtext_putenv (MText *mt)
+{
+  unsigned char buf[1024];
+  int size = 1024;
+  unsigned char *newbuf;
+  int result;
+
+  newbuf = encode_locale (mt, buf, &size, mlocale__ctype);
+  result = putenv ((char *) newbuf);
+  if (buf != newbuf)
+    free (newbuf);
+  return result;
+}
+
+/*=*/
+
+/***en
+    @brief Compare two M-texts using the current locale.
+
+    The mtext_coll () function compares the two M-texts $MT1 and $MT2.
+    It returns an integer less than, equal to, or greater than zero if
+    $MT1 is found, respectively, to be less than, to match, or to be
+    greater than $MT2.  The comparison is based on texts as
+    appropriate for the current locale (LC_COLLATE).
+
+    This function makes use of information that is automatically
+    cached in the M-texts as a text property.  So, the second call of
+    this function with $MT1 or $MT2 finishes faster than the first
+    call.  */
+/***ja
+    @brief ¸½ºß¤Î¥í¥±¡¼¥ë¤òÍѤ¤¤Æ£²¤Ä¤Î M-text ¤òÈæ³Ó¤¹¤ë.
+
+    ´Ø¿ô mtext_coll () ¤Ï£²¤Ä¤Î M-text $MT1 ¤È $MT2 
+    ¤òÈæ³Ó¤¹¤ë¡£Ìá¤êÃͤÏÉé¤ÎÀ°¿ôÃÍ, 0, Àµ¤ÎÀ°¿ôÃͤΤ¤¤º¤ì¤«¤Ç¤¢¤ê¡¢¤½¤ì¤¾¤ì 
+    $MT1 ¤¬ $MT2 ¤è¤ê¾®¤µ¤¤¡¢Æ±¤¸¡¢Â礭¤¤¾ì¹ç¤ËÁêÅö¤¹¤ë¡£Èæ³Ó¤Ï¸½ºß¤Î¥í¥±¡¼¥ë 
+    (LC_COLLATE) ¤Ë´ð¤Å¤¤¤Æ¹Ô¤ï¤ì¤ë¡£
+
+    ¤³¤Î´Ø¿ô¤Ï M-text 
+    ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤È¤·¤Æ¼«Æ°Åª¤Ë¥­¥ã¥Ã¥·¥å¤µ¤ì¤ë¾ðÊó¤òÍøÍѤ¹¤ë¤Î¤Ç¡¢£²ÅÙÌܰʹߤÎƱ¤¸Èæ³Ó¤Ï£±ÅÙÌܤè¤ê®¤¯¼Â¹Ô¤µ¤ì¤ë¡£  */
+
+int
+mtext_coll (MText *mt1, MText *mt2)
+{
+  char *str1, *str2;
+
+  if (mt1->nchars == 0)
+    return (mt2->nchars == 0 ? 0 : -1);
+  else if (mt2->nchars == 0)
+    return 1;
+
+  str1 = get_xfrm (mt1);
+  str2 = get_xfrm (mt2);
+  return strcoll (str1, str2);
+}
+
+/*** @} */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/m17n-X.c b/src/m17n-X.c
new file mode 100644 (file)
index 0000000..f9ce59f
--- /dev/null
@@ -0,0 +1,2685 @@
+/* m17n-X.c -- implementation of the GUI API on X Windows.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#include "config.h"
+
+#ifdef HAVE_X11
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <locale.h>
+
+#include <X11/Xlib.h>
+#include <X11/keysym.h>
+#include <X11/Xlocale.h>
+#include <X11/Xutil.h>
+#include <X11/Xresource.h>
+#include <X11/Xatom.h>
+#include <X11/StringDefs.h>
+#include <X11/Intrinsic.h>
+
+#ifdef HAVE_XFT2
+#include <X11/Xft/Xft.h>
+#include <fontconfig/fcfreetype.h>
+#endif /* HAVE_XFT2 */
+
+#include "m17n-gui.h"
+#include "m17n-X.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "internal-gui.h"
+#include "symbol.h"
+#include "input.h"
+#include "font.h"
+#include "fontset.h"
+#include "face.h"
+
+typedef struct
+{
+  /* Common header for the m17n object.  */
+  M17NObject control;
+
+  Display *display;
+
+  /* If nonzero, <display> is opened by this library.  Thus it should
+     be closed on freeing this structure.  */
+  int auto_display;
+
+  /** List of available X-core fonts on the display.  Keys are
+      registries and values are plists whose keys are families and
+      values are pointers to MFont.  */
+  MPlist *font_list;
+
+  /** Nonzero means that <font_list> already contains all available
+      fonts on the display.  */
+  int all_fonts_scaned;
+
+ /** Modifier bit masks of the display.  */
+  int meta_mask;
+  int alt_mask;
+  int super_mask;
+  int hyper_mask;
+
+  Atom MULE_BASELINE_OFFSET;
+  Atom AVERAGE_WIDTH;
+} MDisplayInfo;
+
+/* Anchor of the chain of MDisplayInfo objects.  */
+static MPlist *display_info_list;
+
+
+/* Color value and the corresponding GC.  */
+typedef struct
+{
+  unsigned int rgb;           /* (red << 16) | (green << 8) | blue */
+  GC gc;
+} RGB_GC;
+
+enum gc_index
+  {
+    GC_INVERSE,
+    GC_NORMAL = GC_INVERSE + 7,
+    GC_HLINE,
+    GC_BOX_TOP,
+    GC_BOX_BOTTOM,
+    GC_BOX_LEFT,
+    GC_BOX_RIGHT,
+    GC_MAX
+  };
+
+typedef struct
+{
+  int rgb_fore;
+  int rgb_back;
+  /* The first 8 elements are indexed by an intensity for
+     anti-aliasing.  The 2nd to 7th are created on demand.  */
+  GC gc[GC_MAX];
+#ifdef HAVE_XFT2
+  XftColor xft_color_fore, xft_color_back;
+#endif
+} GCInfo;
+
+typedef struct
+{
+  /* Common header for the m17n object.  */
+  M17NObject control;
+
+  MDisplayInfo *display_info;
+
+  int screen_num;
+
+  Drawable drawable;
+
+  unsigned depth;
+
+  Colormap cmap;
+
+  GC scratch_gc;
+
+  int resy;
+
+#ifdef HAVE_XFT2
+  XftDraw *xft_draw;
+#endif
+
+  /** List of pointers to realized faces on the frame.  */
+  MPlist *realized_face_list;
+
+  /* List of single element whose value is a root of chain of realized
+     fonts.  */
+  MPlist *realized_font_list;
+
+  /** List of pointers to realized fontsets on the frame.  */
+  MPlist *realized_fontset_list;
+
+  /** List of XColors vs GCs on the frame.  */
+  MPlist *gc_list;
+} MWDevice;
+
+static MPlist *device_list;
+
+static MSymbol M_iso8859_1, M_iso10646_1;
+
+#define FRAME_DEVICE(frame) ((MWDevice *) (frame)->device)
+#define FRAME_DISPLAY(frame) (FRAME_DEVICE (frame)->display_info->display)
+#define FRAME_SCREEN(frame) (FRAME_DEVICE (frame)->screen_num)
+#define FRAME_CMAP(frame) (FRAME_DEVICE (frame)->cmap)
+#define FRAME_VISUAL(frame) DefaultVisual (FRAME_DISPLAY (frame), \
+                                          FRAME_SCREEN (frame))
+
+#define DEFAULT_FONT "-*-*-medium-r-normal--13-*-*-*-c-*-iso8859-1"
+
+typedef struct
+{
+  String font;
+  String foreground;
+  String background;
+  Boolean reverse_video;
+} AppData, *AppDataPtr;
+
+static void
+free_display_info (void *object)
+{
+  MDisplayInfo *disp_info = (MDisplayInfo *) object;
+  MPlist *plist, *pl;
+
+  MPLIST_DO (plist, disp_info->font_list)
+    {
+      MPLIST_DO (pl, MPLIST_VAL (plist))
+       free (MPLIST_VAL (pl));
+      M17N_OBJECT_UNREF (MPLIST_VAL (plist));
+    }
+  M17N_OBJECT_UNREF (disp_info->font_list);
+
+  if (disp_info->auto_display)
+    XCloseDisplay (disp_info->display);
+
+  free (object);
+}
+
+static void
+free_device (void *object)
+{
+  MWDevice *device = object;
+  MPlist *plist;
+
+  for (plist = device->realized_fontset_list;
+       mplist_key (plist) != Mnil; plist = mplist_next (plist))
+    mfont__free_realized_fontset ((MRealizedFontset *) mplist_value (plist));
+  M17N_OBJECT_UNREF (device->realized_fontset_list);
+
+  if (MPLIST_VAL (device->realized_font_list))
+    mfont__free_realized (MPLIST_VAL (device->realized_font_list));
+  M17N_OBJECT_UNREF (device->realized_font_list);
+
+  MPLIST_DO (plist, device->realized_face_list)
+    {
+      MRealizedFace *rface = MPLIST_VAL (plist);
+
+      free (rface->info);
+      mface__free_realized (rface);
+    }
+  M17N_OBJECT_UNREF (device->realized_face_list);
+
+  MPLIST_DO (plist, device->gc_list)
+    {
+      XFreeGC (device->display_info->display,
+              ((RGB_GC *) MPLIST_VAL (plist))->gc);
+      free (MPLIST_VAL (plist));
+    }
+  M17N_OBJECT_UNREF (device->gc_list);
+  XFreeGC (device->display_info->display, device->scratch_gc);
+
+#ifdef HAVE_XFT2
+  XftDrawDestroy (device->xft_draw);
+#endif
+
+  XFreePixmap (device->display_info->display, device->drawable);
+  M17N_OBJECT_UNREF (device->display_info);
+  free (object);
+}
+
+
+static void
+find_modifier_bits (MDisplayInfo *disp_info)
+{
+  Display *display = disp_info->display;
+  XModifierKeymap *mods;
+  KeyCode meta_l = XKeysymToKeycode (display, XK_Meta_L);
+  KeyCode meta_r = XKeysymToKeycode (display, XK_Meta_R);
+  KeyCode alt_l = XKeysymToKeycode (display, XK_Alt_L);
+  KeyCode alt_r = XKeysymToKeycode (display, XK_Alt_R);
+  KeyCode super_l = XKeysymToKeycode (display, XK_Super_L);
+  KeyCode super_r = XKeysymToKeycode (display, XK_Super_R);
+  KeyCode hyper_l = XKeysymToKeycode (display, XK_Hyper_L);
+  KeyCode hyper_r = XKeysymToKeycode (display, XK_Hyper_R);
+  int i, j;
+
+  mods = XGetModifierMapping (display);
+  /* We skip the first three sets for Shift, Lock, and Control.  The
+     remaining sets are for Mod1, Mod2, Mod3, Mod4, and Mod5.  */
+  for (i = 3; i < 8; i++)
+    for (j = 0; j < mods->max_keypermod; j++)
+      {
+       KeyCode code = mods->modifiermap[i * mods->max_keypermod + j];
+
+       if (! code)
+         continue;
+       if (code == meta_l || code == meta_r)
+         disp_info->meta_mask |= (1 << i);
+       else if (code == alt_l || code == alt_r)
+         disp_info->alt_mask |= (1 << i);
+       else if (code == super_l || code == super_r)
+         disp_info->super_mask |= (1 << i);
+       else if (code == hyper_l || code == hyper_r)
+         disp_info->hyper_mask |= (1 << i);
+      }
+
+  /* If meta keys are not in any modifier, use alt keys as meta
+     keys.  */
+  if (! disp_info->meta_mask)
+    {
+      disp_info->meta_mask = disp_info->alt_mask;
+      disp_info->alt_mask = 0;
+    }
+  /* If both meta and alt are assigned to the same modifier, give meta
+     keys priority.  */
+  if (disp_info->meta_mask & disp_info->alt_mask)
+    disp_info->alt_mask &= ~disp_info->meta_mask;
+
+  XFreeModifiermap (mods);
+}
+
+static RGB_GC *
+get_rgb_gc (MWDevice *device, XColor *xcolor)
+{
+  int rgb = (((xcolor->red >> 8) << 16) | ((xcolor->green >> 8) << 8)
+            | (xcolor->blue >> 8));
+  MPlist *plist;
+  RGB_GC *rgb_gc;
+  unsigned long valuemask = GCForeground;
+  XGCValues values;
+
+  MPLIST_DO (plist, device->gc_list)
+    {
+      rgb_gc = MPLIST_VAL (plist);
+
+      if (rgb_gc->rgb == rgb)
+       return rgb_gc;
+      if (rgb_gc->rgb > rgb)
+       break;
+    }
+
+  if (! XAllocColor (device->display_info->display, device->cmap, xcolor))
+    return NULL;
+
+  rgb_gc = malloc (sizeof (RGB_GC));
+  rgb_gc->rgb = rgb;
+  values.foreground = xcolor->pixel;
+  rgb_gc->gc = XCreateGC (device->display_info->display,
+                         device->drawable, valuemask, &values);
+  mplist_push (plist, Mt, rgb_gc);
+  return rgb_gc;
+}
+
+static GC
+get_gc (MFrame *frame, MSymbol color, int for_foreground, int *rgb_ret)
+{
+  MWDevice *device = FRAME_DEVICE (frame);
+  XColor xcolor;
+  RGB_GC *rgb_gc;
+
+  if (color == Mnil)
+    {
+      if (frame->rface)
+       goto no_color;
+      color = for_foreground ? frame->foreground : frame->background;
+    }
+  if (! XParseColor (FRAME_DISPLAY (frame), device->cmap,
+                    msymbol_name (color), &xcolor))
+    goto no_color;
+  rgb_gc = get_rgb_gc (device, &xcolor);
+  if (! rgb_gc)
+    goto no_color;
+  if (rgb_ret)
+    *rgb_ret = rgb_gc->rgb;
+  return rgb_gc->gc;
+
+ no_color:
+  {
+    GCInfo *info = frame->rface->info;
+    GC gc;
+    int rgb;
+
+    if (for_foreground)
+      rgb = info->rgb_fore, gc = info->gc[GC_NORMAL];
+    else
+      rgb = info->rgb_back, gc = info->gc[GC_INVERSE];
+    if (rgb_ret)
+      *rgb_ret = rgb;
+    return gc;
+  }
+}
+
+static GC
+get_gc_for_anti_alias (MWDevice *device, GCInfo *info, int intensity)
+{
+  int rgb_fore, rgb_back;
+  XColor xcolor;
+  RGB_GC *rgb_gc;
+  GC gc;
+
+  if (info->gc[intensity])
+    return info->gc[intensity];
+
+  rgb_fore = info->rgb_fore, rgb_back = info->rgb_back;
+  xcolor.red = ((((rgb_fore & 0xFF0000) >> 16) * intensity
+                + ((rgb_back & 0xFF0000) >> 16) * (7 - intensity)) / 7) << 8;
+  xcolor.green = ((((rgb_fore & 0xFF00) >> 8) * intensity
+                  + ((rgb_back & 0xFF00) >> 8) * (7 - intensity)) / 7) << 8;
+  xcolor.blue = (((rgb_fore & 0xFF) * intensity
+                 + (rgb_back & 0xFF) * (7 - intensity)) / 7) << 8;
+  rgb_gc = get_rgb_gc (device, &xcolor);
+  if (rgb_gc)
+    gc = rgb_gc->gc;
+  else
+    gc =get_gc_for_anti_alias (device, info,
+                              intensity < 4 ? intensity - 1 : intensity + 1);
+  return (info->gc[intensity] = gc);
+}
+
+static GC
+set_region (MFrame *frame, GC gc, MDrawRegion region)
+{
+  unsigned long valuemask = GCForeground;
+
+  XCopyGC (FRAME_DISPLAY (frame), gc, valuemask,
+          FRAME_DEVICE (frame)->scratch_gc);
+  XSetRegion (FRAME_DISPLAY (frame), FRAME_DEVICE (frame)->scratch_gc, region);
+  return FRAME_DEVICE (frame)->scratch_gc;
+}
+
+\f
+/** X font handler */
+
+static MFont *xfont_select (MFrame *, MFont *, int);
+static MRealizedFont *xfont_open (MFrame *, MFont *, MFont *, MRealizedFont *);
+static void xfont_find_metric (MRealizedFont *, MGlyphString *, int, int);
+static int xfont_has_char (MFrame *, MFont *, MFont *, int, unsigned);
+static unsigned xfont_encode_char (MFrame *, MFont *, MFont *, unsigned);
+static void xfont_render (MDrawWindow, int, int, MGlyphString *,
+                         MGlyph *, MGlyph *, int, MDrawRegion);
+static int xfont_list (MFrame *, MPlist *, MFont *, int);
+static void xfont_list_family_names (MFrame *, MPlist *);
+static int xfont_check_capability (MRealizedFont *rfont, MSymbol capability);
+
+static MFontDriver xfont_driver =
+  { xfont_select, xfont_open,
+    xfont_find_metric, xfont_has_char, xfont_encode_char,
+    xfont_render, xfont_list, xfont_list_family_names, xfont_check_capability
+  };
+
+static int
+font_compare (const void *p1, const void *p2)
+{
+  return strcmp (*(char **) p1, *(char **) p2);
+}
+
+static MPlist *
+xfont_registry_list (MFrame *frame, MSymbol registry)
+{
+  MDisplayInfo *disp_info = FRAME_DEVICE (frame)->display_info;
+  MPlist *font_list = disp_info->font_list;
+  MPlist *plist, *p;
+  char pattern[1024];
+  char **font_names, **names;
+  int nfonts;
+  int i, j;
+  MFont font;
+  int for_full_width;
+
+  plist = mplist_get (font_list, registry);
+  if (plist)
+    return plist;
+  p = plist = mplist ();
+  mplist_add (font_list, registry, plist);
+  sprintf (pattern, "-*-*-*-*-*-*-*-*-*-*-*-*-%s", msymbol_name (registry));
+  font_names = XListFonts (disp_info->display, pattern, 0x8000, &nfonts);
+  if (nfonts == 0)
+    return plist;
+  {
+    char *reg_name = msymbol_name (registry);
+
+    for_full_width = (strncmp (reg_name, "jis", 3) == 0
+                     || strncmp (reg_name, "gb", 2) == 0
+                     || strncmp (reg_name, "big5", 4) == 0
+                     || strncmp (reg_name, "ksc", 3) == 0);
+  }
+  names = alloca (sizeof (char *) * nfonts);
+  memcpy (names, font_names, sizeof (char *) * nfonts);
+  qsort (names, nfonts, sizeof (char *), font_compare);
+  MFONT_INIT (&font);
+  for (i = 0; i < nfonts; i++)
+    if (mfont__parse_name_into_font (names[i], Mx, &font) == 0
+       && (font.size > 0 || font.property[MFONT_RESY] == 0))
+      {
+       MSymbol family = FONT_PROPERTY (&font, MFONT_FAMILY);
+       MFont *fontx;
+       unsigned sizes[256];
+       int nsizes = 0;
+       int limit;
+       int size, normal_size;
+       char *base_end;
+       int base_len;
+       int fields;
+       
+       /* Calculate how many bytes to compare to detect fonts of the
+          same base name.  */
+       for (base_end = names[i], fields = 0; *base_end; base_end++)
+         if (*base_end == '-'
+             && ++fields == 7  /* PIXEL_SIZE */)
+           break;
+       base_len = base_end - names[i] + 1;
+
+       size = font.size / 10;
+       sizes[nsizes++] = size;
+       normal_size = (size >= 6 && size <= 29);
+       limit = (i + 256 < nfonts ? i + 256 : nfonts);
+       for (j = i + 1; j < limit && ! memcmp (names[i], names[j], base_len);
+            i = j++)
+         if (mfont__parse_name_into_font (names[j], Mx, &font) == 0
+             && (font.size > 0 || font.property[MFONT_RESY] == 0))
+           {
+             size = font.size / 10;
+             sizes[nsizes++] = size;
+             normal_size |= (size >= 6 && size <= 29);
+           }
+
+       font.for_full_width = for_full_width;
+       font.type = MFONT_TYPE_OBJECT;
+       font.source = MFONT_SOURCE_X;
+       if (normal_size)
+         {
+           MSTRUCT_CALLOC (fontx, MERROR_WIN);
+           *fontx = font;
+           fontx->multiple_sizes = 1;
+           fontx->size = 0;
+           for (j = 0; j < nsizes; j++)
+             if (sizes[j] >= 6 && sizes[j] <= 29)
+               fontx->size |= 1 << (sizes[j] - 6);
+           p = mplist_add (p, family, fontx);
+         }
+       for (j = 0; j < nsizes; j++)
+         if (sizes[j] < 6 || sizes[j] > 29)
+           {
+             MSTRUCT_CALLOC (fontx, MERROR_WIN);
+             *fontx = font;
+             fontx->multiple_sizes = 0;
+             fontx->size = sizes[j] * 10;
+             if (sizes[j] == 0)
+               fontx->property[MFONT_RESY] = 0;
+             p = mplist_add (p, family, fontx);
+           }
+      }
+  XFreeFontNames (font_names);
+  return plist;
+}
+
+static void
+xfont_list_all (MFrame *frame)
+{
+  MDisplayInfo *disp_info = FRAME_DEVICE (frame)->display_info;
+  MPlist *font_encoding_list, *p;
+
+  if (disp_info->all_fonts_scaned)
+    return;
+  disp_info->all_fonts_scaned = 1;
+  font_encoding_list = mfont__encoding_list ();
+  if (! font_encoding_list)
+    return;
+  MPLIST_DO (p, font_encoding_list)
+    xfont_registry_list (frame, MPLIST_KEY (p));
+}
+
+typedef struct
+{
+  M17NObject control;
+  Display *display;
+  XFontStruct *xfont;
+} MRealizedFontX;
+
+/* The X font driver function SELECT.  */
+
+static MFont *
+xfont_select (MFrame *frame, MFont *font, int limited_size)
+{
+  MPlist *plist = mplist (), *pl;
+  int num = xfont_list (frame, plist, font, 0);
+  MFont *found = NULL;
+
+  if (num > 0)
+    MPLIST_DO (pl, plist)
+      {
+       font = MPLIST_VAL (pl);
+       if (limited_size == 0
+           || font->size == 0
+           || font->size <= limited_size)
+         {
+           found = font;
+           break;
+         }
+      }
+  M17N_OBJECT_UNREF (plist);
+  return found;
+}
+
+/* The X font driver function CLOSE.  */
+
+static void
+close_xfont (void *object)
+{
+  MRealizedFontX *x_rfont = object;
+
+  XFreeFont (x_rfont->display, x_rfont->xfont);
+  free (x_rfont);
+}
+
+/* The X font driver function OPEN.  */
+
+static MRealizedFont *
+xfont_open (MFrame *frame, MFont *font, MFont *spec, MRealizedFont *rfont)
+{
+  int size;
+  MRealizedFontX *x_rfont;
+  char *name;
+  Display *display = FRAME_DISPLAY (frame);
+  XFontStruct *xfont;
+  int mdebug_flag = MDEBUG_FONT;
+  MFont this;
+
+  size = spec->size;
+  if (size)
+    {
+      int ratio = mfont_resize_ratio (font);
+
+      if (ratio != 100)
+       size = size * ratio / 100;
+    }
+  else
+    size = 120;
+
+  if (font->size)
+    {
+      /* non-scalable font */
+      if (font->multiple_sizes)
+       {
+         int i;
+
+         if (size < 60)
+           size = 60;
+         else if (size > 290)
+           size = 290;
+         for (i = size / 10 - 6; i >= 0; i--)
+           if (font->size & (1 << i))
+             break;
+         if (i == 0)
+           for (i = size / 10 - 5; i < 24; i++)
+             if (font->size & (1 << i))
+               break;
+         size = (i + 6) * 10;
+       }
+      else
+       size = font->size;
+    }
+
+  if (rfont)
+    {
+      for (; rfont; rfont = rfont->next)
+       if (rfont->font == font && rfont->spec.size == size)
+         return rfont;
+    }
+
+  this = *font;
+  this.multiple_sizes = 0;
+  this.size = size;
+  /* This never fail to generate a valid fontname.  */
+  name = mfont_unparse_name (&this, Mx);
+  xfont = XLoadQueryFont (FRAME_DISPLAY (frame), name);
+  if (! xfont)
+    {
+      MDEBUG_PRINT1 (" [XFONT] x %s\n", name);
+      free (name);
+      font->type = MFONT_TYPE_FAILURE;
+      return NULL;
+    }
+  M17N_OBJECT (x_rfont, close_xfont, MERROR_FONT_X);
+  x_rfont->display = display;
+  x_rfont->xfont = xfont;
+  MSTRUCT_CALLOC (rfont, MERROR_FONT_X);
+  rfont->id = msymbol (name);
+  rfont->spec = this;
+  rfont->spec.type = MFONT_TYPE_REALIZED;
+  rfont->spec.source = MFONT_SOURCE_X;
+  rfont->frame = frame;
+  rfont->font = font;
+  rfont->driver = &xfont_driver;
+  rfont->info = x_rfont;
+  {
+    MDisplayInfo *disp_info = FRAME_DEVICE (frame)->display_info;
+    unsigned long value;
+
+    rfont->baseline_offset
+      = (XGetFontProperty (xfont, disp_info->MULE_BASELINE_OFFSET, &value)
+        ? (int) (value << 6) : 0);
+    rfont->average_width
+      = (XGetFontProperty (xfont, disp_info->AVERAGE_WIDTH, &value)
+        ? (int) (value << 6) / 10 : 0);
+  }
+  rfont->ascent = (xfont->ascent << 6) + rfont->baseline_offset;
+  rfont->descent = (xfont->descent << 6) - rfont->baseline_offset;
+  rfont->max_advance = xfont->max_bounds.width << 6;
+  rfont->x_ppem = rfont->y_ppem = size / 10;
+  rfont->fontp = xfont;
+  rfont->next = MPLIST_VAL (frame->realized_font_list);
+  MPLIST_VAL (frame->realized_font_list) = rfont;
+  MDEBUG_PRINT1 (" [XFONT] o %s\n", name);
+  free (name);
+  return rfont;
+}
+
+
+/* The X font driver function FIND_METRIC.  */
+
+static void
+xfont_find_metric (MRealizedFont *rfont, MGlyphString *gstring,
+                  int from, int to)
+{
+  XFontStruct *xfont = rfont->fontp;
+  MGlyph *g = MGLYPH (from), *gend = MGLYPH (to);
+
+  for (; g != gend; g++)
+    if (! g->g.measured)
+      {
+       if (g->g.code == MCHAR_INVALID_CODE)
+         {
+           g->g.lbearing = xfont->max_bounds.lbearing << 6;
+           g->g.rbearing = xfont->max_bounds.rbearing << 6;
+           g->g.xadv = xfont->max_bounds.width << 6;
+           g->g.ascent = xfont->ascent << 6;
+           g->g.descent = xfont->descent << 6;
+         }
+       else
+         {
+           int byte1 = g->g.code >> 8, byte2 = g->g.code & 0xFF;
+           XCharStruct *pcm = NULL;
+
+           if (xfont->per_char != NULL)
+             {
+               if (xfont->min_byte1 == 0 && xfont->max_byte1 == 0)
+                 {
+                   if (byte1 == 0
+                       && byte2 >= xfont->min_char_or_byte2
+                       && byte2 <= xfont->max_char_or_byte2)
+                     pcm = xfont->per_char + byte2 - xfont->min_char_or_byte2;
+                 }
+               else
+                 {
+                   if (byte1 >= xfont->min_byte1
+                       && byte1 <= xfont->max_byte1
+                       && byte2 >= xfont->min_char_or_byte2
+                       && byte2 <= xfont->max_char_or_byte2)
+                     {
+                       pcm = (xfont->per_char
+                              + ((xfont->max_char_or_byte2
+                                  - xfont->min_char_or_byte2 + 1)
+                                 * (byte1 - xfont->min_byte1))
+                              + (byte2 - xfont->min_char_or_byte2));
+                     }
+                 }
+             }
+
+           if (pcm)
+             {
+               g->g.lbearing = pcm->lbearing << 6;
+               g->g.rbearing = pcm->rbearing << 6;
+               g->g.xadv = pcm->width << 6;
+               g->g.ascent = pcm->ascent << 6;
+               g->g.descent = pcm->descent << 6;
+             }
+           else
+             {
+               /* If the per_char pointer is null, all glyphs between
+                  the first and last character indexes inclusive have
+                  the same information, as given by both min_bounds and
+                  max_bounds.  */
+               g->g.lbearing = 0;
+               g->g.rbearing = xfont->max_bounds.width << 6;
+               g->g.xadv = xfont->max_bounds.width << 6;
+               g->g.ascent = xfont->ascent << 6;
+               g->g.descent = xfont->descent << 6;
+             }
+         }
+       g->g.yadv = 0;
+       g->g.ascent += rfont->baseline_offset;
+       g->g.descent -= rfont->baseline_offset;
+       g->g.measured = 1;
+      }
+}
+
+
+static int
+xfont_has_char (MFrame *frame, MFont *font, MFont *spec, int c, unsigned code)
+{
+  return (xfont_encode_char (frame, font, spec, code) != MCHAR_INVALID_CODE);
+}
+
+/* The X font driver function GET_GLYPH_ID.  */
+
+static unsigned
+xfont_encode_char (MFrame *frame, MFont *font, MFont *spec, unsigned code)
+{
+  MRealizedFont *rfont;
+  XFontStruct *xfont;
+  unsigned min_byte1, max_byte1, min_byte2, max_byte2;
+  int all_chars_exist;
+
+  if (font->type == MFONT_TYPE_REALIZED)
+    rfont = (MRealizedFont *) font;
+  else if (font->type == MFONT_TYPE_OBJECT)
+    {
+      for (rfont = MPLIST_VAL (frame->realized_font_list); rfont;
+          rfont = rfont->next)
+       if (rfont->font == font)
+         break;
+      if (! rfont)
+       {
+         rfont = xfont_open (frame, font, spec, NULL);
+         if (! rfont)
+           return MCHAR_INVALID_CODE;
+       }
+    }
+  else
+    MFATAL (MERROR_FONT_X);
+  xfont = rfont->fontp;
+  all_chars_exist = (! xfont->per_char || xfont->all_chars_exist == True);
+  min_byte1 = xfont->min_byte1;
+  max_byte1 = xfont->max_byte1;
+  min_byte2 = xfont->min_char_or_byte2;
+  max_byte2 = xfont->max_char_or_byte2;
+
+  if (min_byte1 == 0 && max_byte1 == 0)
+    {
+      XCharStruct *pcm;
+
+      if (code < min_byte2 || code > max_byte2)
+       return MCHAR_INVALID_CODE;
+      if (all_chars_exist)
+       return code;
+      pcm = xfont->per_char + (code - min_byte2);
+      return ((pcm->width > 0 || pcm->rbearing != pcm->lbearing)
+             ? code : MCHAR_INVALID_CODE);
+    }
+  else
+    {
+      unsigned byte1 = code >> 8, byte2 = code & 0xFF;
+      XCharStruct *pcm;
+
+      if (byte1 < min_byte1 || byte1 > max_byte1
+         || byte2 < min_byte2 || byte2 > max_byte2)
+       return MCHAR_INVALID_CODE;
+
+      if (all_chars_exist)
+       return code;
+      pcm = xfont->per_char + ((byte1 - min_byte1) * (max_byte2 - min_byte2 + 1)
+                          + (byte2 - min_byte2));
+      return ((pcm->width > 0 || pcm->rbearing != pcm->lbearing)
+             ? code : MCHAR_INVALID_CODE);
+    }
+}
+
+/* The X font driver function RENDER.  */
+
+static void
+xfont_render (MDrawWindow win, int x, int y, MGlyphString *gstring,
+             MGlyph *from, MGlyph *to, int reverse, MDrawRegion region)
+{
+  MRealizedFace *rface = from->rface;
+  Display *display = FRAME_DISPLAY (rface->frame);
+  XChar2b *code;
+  GC gc = ((GCInfo *) rface->info)->gc[reverse ? GC_INVERSE : GC_NORMAL];
+  MGlyph *g;
+  int i;
+  int baseline_offset;
+
+  if (from == to)
+    return;
+
+  baseline_offset = rface->rfont->baseline_offset >> 6;
+  if (region)
+    gc = set_region (rface->frame, gc, region);
+  XSetFont (display, gc, ((XFontStruct *) rface->rfont->fontp)->fid);
+  code = (XChar2b *) alloca (sizeof (XChar2b) * (to - from));
+  for (i = 0, g = from; g < to; i++, g++)
+    {
+      code[i].byte1 = g->g.code >> 8;
+      code[i].byte2 = g->g.code & 0xFF;
+    }
+
+  g = from;
+  while (g < to)
+    {
+      if (g->type == GLYPH_PAD)
+       x += g++->g.xadv;
+      else if (g->type == GLYPH_SPACE)
+       for (; g < to && g->type == GLYPH_SPACE; g++)
+         x += g->g.xadv;
+      else if (! g->rface->rfont)
+       {
+         if ((g->g.c >= 0x200B && g->g.c <= 0x200F)
+             || (g->g.c >= 0x202A && g->g.c <= 0x202E))
+           x += g++->g.xadv;
+         else
+           {
+             /* As a font is not found for this character, draw an
+                empty box.  */
+             int box_width = g->g.xadv;
+             int box_height = gstring->ascent + gstring->descent;
+
+             if (box_width > 4)
+               box_width -= 2;
+             if (box_height > 4)
+               box_height -= 2;
+             XDrawRectangle (display, (Window) win, gc,
+                             x, y - gstring->ascent, box_width, box_height);
+             x += g++->g.xadv;
+           }
+       }
+      else if (g->g.xoff != 0 || g->g.yoff != 0 || g->right_padding)
+       {
+         XDrawString16 (display, (Window) win, gc,
+                        x + g->g.xoff, y + g->g.yoff - baseline_offset,
+                        code + (g - from), 1);
+         x += g->g.xadv;
+         g++;
+       }
+      else
+       {
+         int orig_x = x;
+         int code_idx = g - from;
+
+         for (i = 0;
+              g < to && g->type == GLYPH_CHAR && g->g.xoff == 0 && g->g.yoff == 0;
+              i++, g++)
+             x += g->g.xadv;
+         XDrawString16 (display, (Window) win, gc,
+                        orig_x, y - baseline_offset, code + code_idx, i);
+       }
+    }
+}
+
+static int
+xfont_list (MFrame *frame, MPlist *plist, MFont *font, int maxnum)
+{
+  MDisplayInfo *disp_info = FRAME_DEVICE (frame)->display_info;
+  MSymbol registry = font ? FONT_PROPERTY (font, MFONT_REGISTRY) : Mnil;
+  MSymbol family = font ? FONT_PROPERTY (font, MFONT_FAMILY) : Mnil;
+  int size = font ? font->size : 0;
+  MPlist *pl, *p;
+  int num = 0;
+  int mdebug_flag = MDEBUG_FONT;
+
+  MDEBUG_PRINT2 (" [X-FONT] listing %s-%s...",
+                family ? msymbol_name (family) : "*",
+                registry ? msymbol_name (registry) : "*");
+
+  if (registry == Mnil)
+    xfont_list_all (frame);
+  else
+    xfont_registry_list (frame, registry);
+
+  MPLIST_DO (pl, disp_info->font_list)
+    if (registry == Mnil || registry == MPLIST_KEY (pl))
+      {
+       MPLIST_DO (p, MPLIST_VAL (pl))
+         if (family == Mnil || family == MPLIST_KEY (p))
+           {
+             MFont *fontx = MPLIST_VAL (p);
+
+             if (! font || (mfont__match_p (fontx, font, MFONT_REGISTRY)))
+               {
+                 if (fontx->size != 0 && size)
+                   {
+                     if (fontx->multiple_sizes)
+                       {
+                         if (size < 60 || size > 290
+                             || ! (fontx->size & (1 << (size / 10 - 6))))
+                           continue;
+                       }
+                     else if (fontx->size != size)
+                       continue;
+                   }
+                 mplist_push (plist, MPLIST_KEY (p), fontx);
+                 num++;
+                 if (maxnum > 0 && maxnum == num)
+                   goto done;
+               }
+           }
+      }
+
+ done:
+  MDEBUG_PRINT1 (" %d found\n", num);
+  return num;
+}
+
+static void
+xfont_list_family_names (MFrame *frame, MPlist *plist)
+{
+  MDisplayInfo *disp_info = FRAME_DEVICE (frame)->display_info;
+  char **font_names;
+  int i, nfonts;
+  MSymbol last_family = Mnil;
+
+  font_names = XListFonts (disp_info->display,
+                          "-*-*-*-*-*-*-*-*-*-*-*-*-*-*", 0x8000, &nfonts);
+  for (i = 0; i < nfonts; i++)
+    {
+      MSymbol family;
+      char foundry[256], fam[256];
+      MPlist *p;
+      
+      if (sscanf (font_names[i], "-%s-%s-", foundry, fam) < 2)
+       continue;
+      family = msymbol (fam);
+      if (family == last_family)
+       continue;
+      last_family = family;
+
+      MPLIST_DO (p, plist)
+       {
+         MSymbol sym = MPLIST_SYMBOL (p);
+
+         if (sym == family)
+           break;
+         if (strcmp (MSYMBOL_NAME (sym), fam) > 0)
+           {
+             mplist_push (p, Msymbol, family);
+             break;
+           }
+       }
+      if (MPLIST_TAIL_P (p))
+       mplist_push (p, Msymbol, family);
+    }
+  if (font_names)
+    XFreeFontNames (font_names);
+}
+
+static int 
+xfont_check_capability (MRealizedFont *rfont, MSymbol capability)
+{
+  /* Currently X font driver doesn't support any capability.  */
+  return -1;
+}
+
+\f
+/* Xft Handler */
+
+#ifdef HAVE_XFT2
+
+typedef struct
+{
+  M17NObject control;
+  FT_Face ft_face;             /* This must be the 2nd member. */
+  Display *display;
+  XftFont *font_aa;
+  XftFont *font_no_aa;
+  /* Pointer to MRealizedFontFT */
+  void *info;
+} MRealizedFontXft;
+
+static MRealizedFont *xft_open (MFrame *frame, MFont *font, MFont *spec,
+                               MRealizedFont *);
+static int xft_has_char (MFrame *frame, MFont *font, MFont *spec,
+                        int c, unsigned code);
+static unsigned xft_encode_char (MFrame *frame, MFont *font, MFont *spec,
+                                unsigned code);
+static void xft_find_metric (MRealizedFont *, MGlyphString *, int, int);
+static void xft_render (MDrawWindow, int, int, MGlyphString *,
+                       MGlyph *, MGlyph *, int, MDrawRegion);
+static int xft_check_capability (MRealizedFont *rfont, MSymbol capability);
+static int xft_check_otf (MFLTFont *font, MFLTOtfSpec *spec);
+static int xft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
+                         MFLTGlyphString *in, int from, int to,
+                         MFLTGlyphString *out,
+                         MFLTGlyphAdjustment *adjustment);
+static int xft_try_otf (MFLTFont *font, MFLTOtfSpec *spec,
+                       MFLTGlyphString *in, int from, int to);
+static int xft_iterate_otf_feature (struct _MFLTFont *font, MFLTOtfSpec *spec,
+                                   int from, int to, unsigned char *table);
+
+
+static MFontDriver xft_driver =
+  { NULL, xft_open,
+    xft_find_metric, xft_has_char, xft_encode_char, xft_render, NULL, NULL,
+    xft_check_capability, NULL, NULL, xft_check_otf, xft_drive_otf, xft_try_otf,
+#ifdef HAVE_OTF
+    xft_iterate_otf_feature
+#endif /* HAVE_OTF */
+  };
+
+static void
+close_xft (void *object)
+{
+  MRealizedFontXft *rfont_xft = object;
+
+  if (rfont_xft->font_aa)
+    XftFontClose (rfont_xft->display, rfont_xft->font_aa);
+  if (rfont_xft->font_no_aa)
+    XftFontClose (rfont_xft->display, rfont_xft->font_no_aa);
+  M17N_OBJECT_UNREF (rfont_xft->info);
+  free (rfont_xft);
+}
+
+
+static XftFont *
+xft_open_font (Display *display, MSymbol file, double size,
+              FcBool anti_alias)
+{
+  FcPattern *pattern;
+  XftFont *font;
+
+  pattern = FcPatternCreate ();
+  FcPatternAddString (pattern, FC_FILE, (FcChar8 *) msymbol_name (file));
+  FcPatternAddDouble (pattern, FC_PIXEL_SIZE, size);
+  FcPatternAddBool (pattern, FC_ANTIALIAS, anti_alias);
+  font = XftFontOpenPattern (display, pattern);
+  return font;
+}
+
+
+static MRealizedFont *
+xft_open (MFrame *frame, MFont *font, MFont *spec, MRealizedFont *rfont)
+{
+  Display *display = FRAME_DISPLAY (frame);
+  int reg = spec->property[MFONT_REGISTRY];
+  FT_Face ft_face;
+  MRealizedFontXft *rfont_xft;
+  FcBool anti_alias = FRAME_DEVICE (frame)->depth > 1 ? FcTrue : FcFalse;
+  int size;
+  XftFont *xft_font;
+  int ascent, descent, max_advance, average_width, baseline_offset;
+
+  if (font->size)
+    /* non-scalable font */
+    size = font->size;
+  else if (spec->size)
+    {
+      int ratio = mfont_resize_ratio (font);
+
+      size = ratio == 100 ? spec->size : spec->size * ratio / 100;
+    }
+  else
+    size = 120;
+
+  if (rfont)
+    {
+      MRealizedFont *save = NULL;
+
+      for (; rfont; rfont = rfont->next)
+       if (rfont->font == font
+           && (rfont->font->size ? rfont->font->size == size
+               : rfont->spec.size == size)
+           && rfont->spec.property[MFONT_REGISTRY] == reg)
+         {
+           if (! save)
+             save = rfont;
+           if (rfont->driver == &xft_driver)
+             return rfont;
+         }
+      rfont = save;
+    }
+  rfont = (mfont__ft_driver.open) (frame, font, spec, rfont);
+  if (! rfont)
+    return NULL;
+  ascent = rfont->ascent;
+  descent = rfont->descent;
+  max_advance = rfont->max_advance;
+  average_width = rfont->average_width;
+  baseline_offset = rfont->baseline_offset;
+  spec = &rfont->spec;
+  ft_face = rfont->fontp;
+  xft_font = xft_open_font (display, font->file, size / 10, anti_alias);
+  if (! xft_font)
+    return NULL;
+  M17N_OBJECT (rfont_xft, close_xft, MERROR_WIN);
+  rfont_xft->display = display;
+  if (anti_alias == FcTrue)
+    rfont_xft->font_aa = xft_font;
+  else
+    rfont_xft->font_no_aa = xft_font;
+  rfont_xft->ft_face = ft_face;
+  rfont_xft->info = rfont->info;
+  M17N_OBJECT_REF (rfont->info);
+  MSTRUCT_CALLOC (rfont, MERROR_FONT_X);
+  rfont->id = font->file;
+  rfont->spec = *spec;
+  rfont->spec.size = size;
+  rfont->frame = frame;
+  rfont->font = font;
+  rfont->driver = &xft_driver;
+  rfont->info = rfont_xft;
+  rfont->ascent = ascent;
+  rfont->descent = descent;
+  rfont->max_advance = max_advance;
+  rfont->average_width = average_width;
+  rfont->baseline_offset = baseline_offset;
+  rfont->x_ppem = ft_face->size->metrics.x_ppem;
+  rfont->y_ppem = ft_face->size->metrics.y_ppem;
+  rfont->fontp = xft_font;
+  rfont->next = MPLIST_VAL (frame->realized_font_list);
+  MPLIST_VAL (frame->realized_font_list) = rfont;
+  return rfont;
+}
+
+static void
+xft_find_metric (MRealizedFont *rfont, MGlyphString *gstring,
+               int from, int to)
+{
+  Display *display = FRAME_DISPLAY (rfont->frame);
+  XftFont *xft_font = rfont->fontp;
+  MGlyph *g = MGLYPH (from), *gend = MGLYPH (to);
+
+  for (; g != gend; g++)
+    if (! g->g.measured)
+      {
+       if (g->g.code == MCHAR_INVALID_CODE)
+         {
+           g->g.lbearing = 0;
+           g->g.rbearing = xft_font->max_advance_width << 6;
+           g->g.xadv = g->g.rbearing << 6;
+           g->g.ascent = xft_font->ascent << 6;
+           g->g.descent = xft_font->descent << 6;
+         }
+       else
+         {
+           XGlyphInfo extents;
+
+           XftGlyphExtents (display, xft_font, &g->g.code, 1, &extents);
+           g->g.lbearing = (- extents.x) << 6;
+           g->g.rbearing = (extents.width - extents.x) << 6;
+           g->g.xadv = extents.xOff << 6;
+           g->g.ascent = extents.y << 6;
+           g->g.descent = (extents.height - extents.y) << 6;
+         }
+       g->g.yadv = 0;
+       g->g.measured = 1;
+      }
+}
+
+static int
+xft_has_char (MFrame *frame, MFont *font, MFont *spec, int c, unsigned code)
+{
+  int result;
+
+  if (font->type == MFONT_TYPE_REALIZED)
+    {
+      MRealizedFont *rfont = (MRealizedFont *) font;
+      MRealizedFontXft *rfont_xft = rfont->info;
+      
+      rfont->info = rfont_xft->info;
+      result = mfont__ft_driver.has_char (frame, font, spec, c, code);
+      rfont->info = rfont_xft;
+    }
+  else
+    result = mfont__ft_driver.has_char (frame, font, spec, c, code);
+  return result;
+}
+
+static unsigned
+xft_encode_char (MFrame *frame, MFont *font, MFont *spec, unsigned code)
+{
+  if (font->type == MFONT_TYPE_REALIZED)
+    {
+      MRealizedFont *rfont = (MRealizedFont *) font;
+      MRealizedFontXft *rfont_xft = rfont->info;
+      
+      rfont->info = rfont_xft->info;
+      code = mfont__ft_driver.encode_char (frame, font, spec, code);
+      rfont->info = rfont_xft;
+    }
+  else
+    code = mfont__ft_driver.encode_char (frame, font, spec, code);
+  return code;
+}
+
+static void 
+xft_render (MDrawWindow win, int x, int y,
+           MGlyphString *gstring, MGlyph *from, MGlyph *to,
+           int reverse, MDrawRegion region)
+{
+  MRealizedFace *rface = from->rface;
+  MFrame *frame = rface->frame;
+  Display *display = FRAME_DISPLAY (frame);
+  MRealizedFont *rfont = rface->rfont;
+  MRealizedFontXft *rfont_xft = rfont->info;
+  XftDraw *xft_draw = FRAME_DEVICE (frame)->xft_draw;
+  XftColor *xft_color = (! reverse
+                        ? &((GCInfo *) rface->info)->xft_color_fore
+                        : &((GCInfo *) rface->info)->xft_color_back);
+  int anti_alias = (gstring->control.anti_alias
+                   && FRAME_DEVICE (frame)->depth > 1);
+  XftFont *xft_font;
+  MGlyph *g;
+  FT_UInt *glyphs;
+  int last_x;
+  int nglyphs;
+
+  if (from == to)
+    return;
+
+  if (anti_alias)
+    {
+      if (rfont_xft->font_aa)
+       xft_font = rfont_xft->font_aa;
+      else
+       {
+         double size = rfont->spec.size;
+
+         xft_font = xft_open_font (display, rfont->spec.file, size / 10,
+                                   FcTrue);
+         if (xft_font)
+           rfont_xft->font_aa = xft_font;
+         else
+           xft_font = rfont->fontp;
+       }
+    }
+  else
+    {
+      if (rfont_xft->font_no_aa)
+       xft_font = rfont_xft->font_no_aa;
+      else
+       {
+         double size = rfont->spec.size;
+
+         xft_font = xft_open_font (display, rfont->spec.file, size / 10,
+                                   FcTrue);
+         if (xft_font)
+           rfont_xft->font_no_aa = xft_font;
+         else
+           xft_font = rfont->fontp;
+       }
+    }
+
+  XftDrawChange (xft_draw, (Drawable) win);
+  XftDrawSetClip (xft_draw, (Region) region);
+      
+  y -= rfont->baseline_offset >> 6;
+  glyphs = alloca (sizeof (FT_UInt) * (to - from));
+  for (last_x = x, nglyphs = 0, g = from; g < to; x += g++->g.xadv)
+    {
+      if (! g->g.adjusted && !g->left_padding && !g->right_padding)
+       glyphs[nglyphs++] = g->g.code;
+      else
+       {
+         if (nglyphs > 0)
+           XftDrawGlyphs (xft_draw, xft_color, xft_font,
+                          last_x, y, glyphs, nglyphs);
+         nglyphs = 0;
+         XftDrawGlyphs (xft_draw, xft_color, xft_font,
+                        x + g->g.xoff, y + g->g.yoff, (FT_UInt *) &g->g.code, 1);
+         last_x = x + g->g.xadv;
+       }
+    }
+  if (nglyphs > 0)
+    XftDrawGlyphs (xft_draw, xft_color, xft_font, last_x, y, glyphs, nglyphs);
+}
+
+static int
+xft_check_capability (MRealizedFont *rfont, MSymbol capability)
+{
+  MRealizedFontXft *rfont_xft = rfont->info;
+  int result;
+      
+  rfont->info = rfont_xft->info;
+  result = mfont__ft_driver.check_capability (rfont, capability);
+  rfont->info = rfont_xft;
+  return result;
+}
+
+static int
+xft_check_otf (MFLTFont *font, MFLTOtfSpec *spec)
+{
+  MRealizedFont *rfont = ((MFLTFontForRealized *) font)->rfont;
+  MRealizedFontXft *rfont_xft = rfont->info;
+  int result;
+      
+  rfont->info = rfont_xft->info;
+  result = mfont__ft_driver.check_otf (font, spec);
+  rfont->info = rfont_xft;
+  return result;
+}
+
+static int
+xft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
+              MFLTGlyphString *in, int from, int to,
+              MFLTGlyphString *out,
+              MFLTGlyphAdjustment *adjustment)
+{
+  MRealizedFont *rfont = ((MFLTFontForRealized *) font)->rfont;
+  MRealizedFontXft *rfont_xft = rfont->info;
+  int result;
+      
+  rfont->info = rfont_xft->info;
+  result = mfont__ft_driver.drive_otf (font, spec, in, from, to, out,
+                                      adjustment);
+  rfont->info = rfont_xft;
+  return result;
+}
+
+static int
+xft_try_otf (MFLTFont *font, MFLTOtfSpec *spec,
+            MFLTGlyphString *in, int from, int to)
+{
+  return xft_drive_otf (font, spec, in, from, to, NULL, NULL);
+}
+
+#ifdef HAVE_OTF
+
+static int
+xft_iterate_otf_feature (struct _MFLTFont *font, MFLTOtfSpec *spec,
+                        int from, int to, unsigned char *table)
+{
+  MRealizedFont *rfont = ((MFLTFontForRealized *) font)->rfont;
+  MRealizedFontXft *rfont_xft = rfont->info;
+  int result;
+      
+  rfont->info = rfont_xft->info;
+  result = mfont__ft_driver.iterate_otf_feature (font, spec, from, to, table);
+  rfont->info = rfont_xft;
+  return result;
+}
+#endif /* HAVE_OTF */
+
+#endif /* HAVE_XFT2 */
+
+\f
+/* Functions for the device driver.  */
+
+static void
+mwin__close_device (MFrame *frame)
+{
+  MWDevice *device = FRAME_DEVICE (frame);
+
+  M17N_OBJECT_UNREF (device);
+}
+
+static void *
+mwin__device_get_prop (MFrame *frame, MSymbol key)
+{
+  MWDevice *device = FRAME_DEVICE (frame);
+
+  if (key == Mdisplay)
+    return (void *) device->display_info->display;
+  if (key == Mscreen)
+    return (void *) ScreenOfDisplay(device->display_info->display,
+                                   device->screen_num);
+  if (key == Mcolormap)
+    return (void *) device->cmap;
+  if (key == Mdepth)
+    return (void *) device->depth;
+  return NULL;
+}
+
+static void
+mwin__realize_face (MRealizedFace *rface)
+{
+  MFrame *frame;
+  MSymbol foreground, background, videomode;
+  MFaceHLineProp *hline;
+  MFaceBoxProp *box;
+  GCInfo *info;
+
+  if (rface != rface->ascii_rface)
+    {
+      rface->info = rface->ascii_rface->info;
+      return;
+    }
+
+  frame = rface->frame;
+  MSTRUCT_CALLOC (info, MERROR_WIN);
+
+  foreground = rface->face.property[MFACE_FOREGROUND];
+  background = rface->face.property[MFACE_BACKGROUND];
+  videomode = rface->face.property[MFACE_VIDEOMODE];
+  if (! videomode)
+    videomode = frame->videomode;
+  if (videomode != Mreverse)
+    {
+      info->gc[GC_NORMAL] = get_gc (frame, foreground, 1, &info->rgb_fore);
+      info->gc[GC_INVERSE] = get_gc (frame, background, 0, &info->rgb_back);
+    }
+  else
+    {
+      info->gc[GC_NORMAL] = get_gc (frame, background, 0, &info->rgb_fore);
+      info->gc[GC_INVERSE] = get_gc (frame, foreground, 1, &info->rgb_back);
+    }
+#ifdef HAVE_XFT2
+  if (foreground == Mnil)
+    foreground = frame->foreground;
+  if (background == Mnil)
+    background = frame->background;
+  if (videomode == Mreverse)
+    {
+      MSymbol temp = foreground;
+      foreground = background;
+      background = temp;
+    }
+  if (! XftColorAllocName (FRAME_DISPLAY (frame),
+                          FRAME_VISUAL (frame),
+                          FRAME_CMAP (frame),
+                          MSYMBOL_NAME (foreground),
+                          &info->xft_color_fore))
+    mdebug_hook ();
+  if (! XftColorAllocName (FRAME_DISPLAY (frame),
+                          FRAME_VISUAL (frame),
+                          FRAME_CMAP (frame),
+                          MSYMBOL_NAME (background),
+                          &info->xft_color_back))
+    mdebug_hook ();
+#endif /* HAVE_XFT2 */
+
+  hline = rface->hline;
+  if (hline)
+    {
+      if (hline->color)
+       info->gc[GC_HLINE] = get_gc (frame, hline->color, 1, NULL);
+      else
+       info->gc[GC_HLINE] = info->gc[GC_NORMAL];
+    }
+
+  box = rface->box;
+  if (box)
+    {
+      if (box->color_top)
+       info->gc[GC_BOX_TOP] = get_gc (frame, box->color_top, 1, NULL);
+      else
+       info->gc[GC_BOX_TOP] = info->gc[GC_NORMAL];
+
+      if (box->color_left && box->color_left != box->color_top)
+       info->gc[GC_BOX_LEFT] = get_gc (frame, box->color_left, 1, NULL);
+      else
+       info->gc[GC_BOX_LEFT] = info->gc[GC_BOX_TOP];
+
+      if (box->color_bottom && box->color_bottom != box->color_top)
+       info->gc[GC_BOX_BOTTOM] = get_gc (frame, box->color_bottom, 1, NULL);
+      else
+       info->gc[GC_BOX_BOTTOM] = info->gc[GC_BOX_TOP];
+
+      if (box->color_right && box->color_right != box->color_bottom)
+       info->gc[GC_BOX_RIGHT] = get_gc (frame, box->color_right, 1, NULL);
+      else
+       info->gc[GC_BOX_RIGHT] = info->gc[GC_BOX_BOTTOM];
+    }
+
+  rface->info = info;
+}
+
+
+static void
+mwin__free_realized_face (MRealizedFace *rface)
+{
+  if (rface == rface->ascii_rface)
+    free (rface->info);
+}
+
+
+static void
+mwin__fill_space (MFrame *frame, MDrawWindow win, MRealizedFace *rface,
+                 int reverse,
+                 int x, int y, int width, int height, MDrawRegion region)
+{
+  GC gc = ((GCInfo *) rface->info)->gc[reverse ? GC_NORMAL : GC_INVERSE];
+
+  if (region)
+    gc = set_region (frame, gc, region);
+
+  XFillRectangle (FRAME_DISPLAY (frame), (Window) win, gc,
+                 x, y, width, height);
+}
+
+
+static void
+mwin__draw_empty_boxes (MDrawWindow win, int x, int y,
+                       MGlyphString *gstring, MGlyph *from, MGlyph *to,
+                       int reverse, MDrawRegion region)
+{
+  MRealizedFace *rface = from->rface;
+  Display *display = FRAME_DISPLAY (rface->frame);
+  GC gc = ((GCInfo *) rface->info)->gc[reverse ? GC_INVERSE : GC_NORMAL];
+
+  if (from == to)
+    return;
+
+  if (region)
+    gc = set_region (rface->frame, gc, region);
+  for (; from < to; from++)
+    {
+      XDrawRectangle (display, (Window) win, gc,
+                     x, y - gstring->ascent + 1, from->g.xadv - 1,
+                     gstring->ascent + gstring->descent - 2);
+      x += from->g.xadv;
+    }
+}
+
+
+static void
+mwin__draw_hline (MFrame *frame, MDrawWindow win, MGlyphString *gstring,
+                MRealizedFace *rface, int reverse,
+                int x, int y, int width, MDrawRegion region)
+{
+  enum MFaceHLineType type = rface->hline->type;
+  GCInfo *info = rface->info;
+  GC gc = gc = info->gc[GC_HLINE];
+  int i;
+
+  y = (type == MFACE_HLINE_BOTTOM
+       ? y + gstring->text_descent - rface->hline->width
+       : type == MFACE_HLINE_UNDER
+       ? y + 1
+       : type == MFACE_HLINE_STRIKE_THROUGH
+       ? y - ((gstring->ascent + gstring->descent) / 2)
+       : y - gstring->text_ascent);
+  if (region)
+    gc = set_region (frame, gc, region);
+
+  for (i = 0; i < rface->hline->width; i++)
+    XDrawLine (FRAME_DISPLAY (frame), (Window) win, gc,
+              x, y + i, x + width - 1, y + i);
+}
+
+
+static void
+mwin__draw_box (MFrame *frame, MDrawWindow win, MGlyphString *gstring,
+               MGlyph *g, int x, int y, int width, MDrawRegion region)
+{
+  Display *display = FRAME_DISPLAY (frame);
+  MRealizedFace *rface = g->rface;
+  MFaceBoxProp *box = rface->box;
+  GCInfo *info = rface->info;
+  GC gc_top, gc_left, gc_right, gc_btm;
+  int y0, y1;
+  int i;
+
+  y0 = y - (gstring->text_ascent
+           + rface->box->inner_vmargin + rface->box->width);
+  y1 = y + (gstring->text_descent
+           + rface->box->inner_vmargin + rface->box->width - 1);
+
+  gc_top = info->gc[GC_BOX_TOP];
+  if (region)
+    gc_top = set_region (frame, gc_top, region);
+  if (info->gc[GC_BOX_TOP] == info->gc[GC_BOX_BOTTOM])
+    gc_btm = gc_top;
+  else
+    gc_btm = info->gc[GC_BOX_BOTTOM];
+
+  if (g->type == GLYPH_BOX)
+    {
+      int x0, x1;
+
+      if (g->left_padding)
+       x0 = x + box->outer_hmargin, x1 = x + g->g.xadv - 1;
+      else
+       x0 = x, x1 = x + g->g.xadv - box->outer_hmargin - 1;
+
+      /* Draw the top side.  */
+      for (i = 0; i < box->width; i++)
+       XDrawLine (display, (Window) win, gc_top, x0, y0 + i, x1, y0 + i);
+
+      /* Draw the bottom side.  */
+      if (region && gc_btm != gc_top)
+       gc_btm = set_region (frame, gc_btm, region);
+      for (i = 0; i < box->width; i++)
+       XDrawLine (display, (Window) win, gc_btm, x0, y1 - i, x1, y1 - i);
+
+      if (g->left_padding > 0)
+       {
+         /* Draw the left side.  */
+         if (info->gc[GC_BOX_LEFT] == info->gc[GC_BOX_TOP])
+           gc_left = gc_top;
+         else
+           {
+             gc_left = info->gc[GC_BOX_LEFT];
+             if (region)
+               gc_left = set_region (frame, gc_left, region);
+           }
+         for (i = 0; i < rface->box->width; i++)
+           XDrawLine (display, (Window) win, gc_left,
+                      x0 + i, y0 + i, x0 + i, y1 - i);
+       }
+      else
+       {
+         /* Draw the right side.  */
+         if (info->gc[GC_BOX_RIGHT] == info->gc[GC_BOX_TOP])
+           gc_right = gc_top;
+         else
+           {
+             gc_right = info->gc[GC_BOX_RIGHT];
+             if (region)
+               gc_right = set_region (frame, gc_right, region);
+           }
+         for (i = 0; i < rface->box->width; i++)
+           XDrawLine (display, (Window) win, gc_right,
+                      x1 - i, y0 + i, x1 - i, y1 - i);
+       }
+    }
+  else
+    {
+      /* Draw the top side.  */
+      for (i = 0; i < box->width; i++)
+       XDrawLine (display, (Window) win, gc_top,
+                  x, y0 + i, x + width - 1, y0 + i);
+
+      /* Draw the bottom side.  */
+      if (region && gc_btm != gc_top)
+       gc_btm = set_region (frame, gc_btm, region);
+      for (i = 0; i < box->width; i++)
+       XDrawLine (display, (Window) win, gc_btm,
+                  x, y1 - i, x + width - 1, y1 - i);
+    }
+}
+
+
+#if 0
+static void
+mwin__draw_bitmap (MFrame *frame, MDrawWindow win, MRealizedFace *rface,
+                  int reverse, int x, int y,
+                  int width, int height, int row_bytes, unsigned char *bmp,
+                  MDrawRegion region)
+{
+  Display *display = FRAME_DISPLAY (frame);
+  int i, j;
+  GC gc = ((GCInfo *) rface->info)->gc[reverse ? GC_INVERSE : GC_NORMAL];
+
+  if (region)
+    gc = set_region (frame, gc, region);
+
+  for (i = 0; i < height; i++, bmp += row_bytes)
+    for (j = 0; j < width; j++)
+      if (bmp[j / 8] & (1 << (7 - (j % 8))))
+       XDrawPoint (display, (Window) win, gc, x + j, y + i);
+}
+#endif
+
+static void
+mwin__draw_points (MFrame *frame, MDrawWindow win, MRealizedFace *rface,
+                  int intensity, MDrawPoint *points, int num,
+                  MDrawRegion region)
+{
+  GCInfo *info = rface->info;
+  GC gc;
+
+  if (! (gc = info->gc[intensity]))
+    gc = info->gc[intensity] = get_gc_for_anti_alias (FRAME_DEVICE (frame),
+                                                     info, intensity);
+  if (region)
+    gc = set_region (frame, gc, region);
+
+  XDrawPoints (FRAME_DISPLAY (frame), (Window) win, gc,
+              (XPoint *) points, num, CoordModeOrigin);
+}
+
+
+static MDrawRegion
+mwin__region_from_rect (MDrawMetric *rect)
+{
+  MDrawRegion region1 = XCreateRegion ();
+  MDrawRegion region2 = XCreateRegion ();
+  XRectangle xrect;
+
+  xrect.x = rect->x;
+  xrect.y = rect->y;
+  xrect.width = rect->width;
+  xrect.height = rect->height;
+  XUnionRectWithRegion (&xrect, region1, region2);
+  XDestroyRegion (region1);
+  return region2;
+}
+
+static void
+mwin__union_rect_with_region (MDrawRegion region, MDrawMetric *rect)
+{
+  MDrawRegion region1 = XCreateRegion ();
+  XRectangle xrect;
+
+  xrect.x = rect->x;
+  xrect.y = rect->y;
+  xrect.width = rect->width;
+  xrect.height = rect->height;
+
+  XUnionRegion (region, region, region1);
+  XUnionRectWithRegion (&xrect, region1, region);
+  XDestroyRegion (region1);
+}
+
+static void
+mwin__intersect_region (MDrawRegion region1, MDrawRegion region2)
+{
+  MDrawRegion region = XCreateRegion ();
+
+  XUnionRegion (region1, region1, region);
+  XIntersectRegion (region, region2, region1);
+  XDestroyRegion (region);
+}
+
+static void
+mwin__region_add_rect (MDrawRegion region, MDrawMetric *rect)
+{
+  MDrawRegion region1 = XCreateRegion ();
+  XRectangle xrect;
+
+  xrect.x = rect->x;
+  xrect.y = rect->y;
+  xrect.width = rect->width;
+  xrect.height = rect->height;
+  XUnionRectWithRegion (&xrect, region1, region);
+  XDestroyRegion (region1);
+}
+
+static void
+mwin__region_to_rect (MDrawRegion region, MDrawMetric *rect)
+{
+  XRectangle xrect;
+
+  XClipBox (region, &xrect);
+  rect->x = xrect.x;
+  rect->y = xrect.y;
+  rect->width = xrect.width;
+  rect->height = xrect.height;
+}
+
+static void
+mwin__free_region (MDrawRegion region)
+{
+  XDestroyRegion (region);
+}
+
+static void
+mwin__dump_region (MDrawRegion region)
+{
+  XRectangle rect;
+  XClipBox (region, &rect);
+  fprintf (stderr, "(%d %d %d %d)\n", rect.x, rect.y, rect.width, rect.height);
+}
+
+
+static MDrawWindow
+mwin__create_window (MFrame *frame, MDrawWindow parent)
+{
+  Display *display = FRAME_DISPLAY (frame);
+  Window win;
+  XWMHints wm_hints = { InputHint, False };
+  XClassHint class_hints = { "M17N-IM", "m17n-im" };
+  XSetWindowAttributes set_attrs;
+  unsigned long mask;
+  XGCValues values;
+  GCInfo *info = frame->rface->info;
+
+  if (! parent)
+    parent = (MDrawWindow) RootWindow (display, FRAME_SCREEN (frame));
+  mask = GCForeground;
+  XGetGCValues (display, info->gc[GC_INVERSE], mask, &values);
+  set_attrs.background_pixel = values.foreground;
+  set_attrs.backing_store = Always;
+  set_attrs.override_redirect = True;
+  set_attrs.save_under = True;
+  mask = CWBackPixel | CWBackingStore | CWOverrideRedirect | CWSaveUnder;
+  win = XCreateWindow (display, (Window) parent, 0, 0, 1, 1, 0,
+                      CopyFromParent, InputOutput, CopyFromParent,
+                      mask, &set_attrs);
+  XSetWMProperties (display, (Window) win, NULL, NULL, NULL, 0,
+                   NULL, &wm_hints, &class_hints);
+  XSelectInput (display, (Window) win, StructureNotifyMask | ExposureMask);
+  return (MDrawWindow) win;
+}
+
+static void
+mwin__destroy_window (MFrame *frame, MDrawWindow win)
+{
+#ifdef HAVE_XFT2
+  XftDraw *xft_draw = FRAME_DEVICE (frame)->xft_draw;
+
+  if (XftDrawDrawable (xft_draw) == (Drawable) win)
+    XftDrawChange (xft_draw, FRAME_DEVICE (frame)->drawable);
+#endif /* HAVE_XFT2 */
+  XDestroyWindow (FRAME_DISPLAY (frame), (Window) win);
+}
+
+#if 0
+static MDrawWindow
+mwin__event_window (void *event)
+{
+  return ((MDrawWindow) ((XEvent *) event)->xany.window);
+}
+
+static void
+mwin__print_event (void *arg, char *win_name)
+{
+  char *event_name;
+  XEvent *event = (XEvent *) arg;
+
+  switch (event->xany.type)
+    {
+    case 2: event_name = "KeyPress"; break;
+    case 3: event_name = "KeyRelease"; break;
+    case 4: event_name = "ButtonPress"; break;
+    case 5: event_name = "ButtonRelease"; break;
+    case 6: event_name = "MotionNotify"; break;
+    case 7: event_name = "EnterNotify"; break;
+    case 8: event_name = "LeaveNotify"; break;
+    case 9: event_name = "FocusIn"; break;
+    case 10: event_name = "FocusOut"; break;
+    case 11: event_name = "KeymapNotify"; break;
+    case 12: event_name = "Expose"; break;
+    case 13: event_name = "GraphicsExpose"; break;
+    case 14: event_name = "NoExpose"; break;
+    case 15: event_name = "VisibilityNotify"; break;
+    case 16: event_name = "CreateNotify"; break;
+    case 17: event_name = "DestroyNotify"; break;
+    case 18: event_name = "UnmapNotify"; break;
+    case 19: event_name = "MapNotify"; break;
+    case 20: event_name = "MapRequest"; break;
+    case 21: event_name = "ReparentNotify"; break;
+    case 22: event_name = "ConfigureNotify"; break;
+    case 23: event_name = "ConfigureRequest"; break;
+    case 24: event_name = "GravityNotify"; break;
+    case 25: event_name = "ResizeRequest"; break;
+    case 26: event_name = "CirculateNotify"; break;
+    case 27: event_name = "CirculateRequest"; break;
+    case 28: event_name = "PropertyNotify"; break;
+    case 29: event_name = "SelectionClear"; break;
+    case 30: event_name = "SelectionRequest"; break;
+    case 31: event_name = "SelectionNotify"; break;
+    case 32: event_name = "ColormapNotify"; break;
+    case 33: event_name = "ClientMessage"; break;
+    case 34: event_name = "MappingNotify"; break;
+    default: event_name = "unknown";
+    }
+
+  fprintf (stderr, "%s: %s\n", win_name, event_name);
+}
+#endif
+
+static void
+mwin__map_window (MFrame *frame, MDrawWindow win)
+{
+  XMapRaised (FRAME_DISPLAY (frame), (Window) win);
+}
+
+static void
+mwin__unmap_window (MFrame *frame, MDrawWindow win)
+{
+  XUnmapWindow (FRAME_DISPLAY (frame), (Window) win);
+}
+
+static void
+mwin__window_geometry (MFrame *frame, MDrawWindow win, MDrawWindow parent_win,
+                      MDrawMetric *geometry)
+{
+  Display *display = FRAME_DISPLAY (frame);
+  XWindowAttributes attr;
+  Window parent = (Window) parent_win, root;
+
+  XGetWindowAttributes (display, (Window) win, &attr);
+  geometry->x = attr.x + attr.border_width;
+  geometry->y = attr.y + attr.border_width;
+  geometry->width = attr.width;
+  geometry->height = attr.height; 
+
+  if (! parent)
+    parent = RootWindow (display, FRAME_SCREEN (frame));
+  while (1)
+    {
+      Window this_parent, *children;
+      unsigned n;
+
+      XQueryTree (display, (Window) win, &root, &this_parent, &children, &n);
+      if (children)
+       XFree (children);
+      if (this_parent == parent || this_parent == root)
+       break;
+      win = (MDrawWindow) this_parent;
+      XGetWindowAttributes (display, (Window) win, &attr);
+      geometry->x += attr.x + attr.border_width;
+      geometry->y += attr.y + attr.border_width;
+    }
+}
+
+static void
+mwin__adjust_window (MFrame *frame, MDrawWindow win,
+                    MDrawMetric *current, MDrawMetric *new)
+{
+  Display *display = FRAME_DISPLAY (frame);
+  unsigned int mask = 0;
+  XWindowChanges values;
+
+  if (current->width != new->width)
+    {
+      mask |= CWWidth;
+      if (new->width <= 0)
+       new->width = 1;
+      values.width = current->width = new->width;
+    }
+  if (current->height != new->height)
+    {
+      mask |= CWHeight;
+      if (new->height <= 0)
+       new->height = 1;
+      values.height = current->height = new->height;
+    }
+  if (current->x != new->x)
+    {
+      mask |= CWX;
+      values.x = current->x = new->x;
+    }
+  if (current->y != new->y)
+    {
+      mask |= CWY;
+      current->y = new->y;
+      values.y = current->y = new->y;
+    }
+  if (mask)
+    XConfigureWindow (display, (Window) win, mask, &values);
+  XClearWindow (display, (Window) win);
+}
+
+static MSymbol
+mwin__parse_event (MFrame *frame, void *arg, int *modifiers)
+{
+  XEvent *event = (XEvent *) arg;
+  MDisplayInfo *disp_info = FRAME_DEVICE (frame)->display_info;
+  int len;
+  char buf[512];
+  KeySym keysym;
+  MSymbol key;
+
+  *modifiers = 0;
+  if (event->xany.type != KeyPress
+      /* && event->xany.type != KeyRelease */
+      )
+    return Mnil;
+  len = XLookupString ((XKeyEvent *) event, (char *) buf, 512, &keysym, NULL);
+  if (len > 1)
+    return Mnil;
+  if (keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
+    return Mnil;
+  if (len == 1 && keysym >= XK_space && keysym <= XK_asciitilde)
+    {
+      int c = keysym;
+
+      key = minput__char_to_key (c);
+      if (c == ' ' && ((XKeyEvent *) event)->state & ShiftMask)
+       *modifiers |= MINPUT_KEY_SHIFT_MODIFIER;
+    }
+  else
+    {
+      char *str = XKeysymToString (keysym);
+
+      if (! str)
+       return Mnil;
+      key = msymbol (str);
+      if (((XKeyEvent *) event)->state & ShiftMask)
+       *modifiers |= MINPUT_KEY_SHIFT_MODIFIER;
+    }
+  if (((XKeyEvent *) event)->state & ControlMask)
+    *modifiers |= MINPUT_KEY_CONTROL_MODIFIER;
+  if (((XKeyEvent *) event)->state & disp_info->meta_mask)
+    *modifiers |= MINPUT_KEY_META_MODIFIER;
+  if (((XKeyEvent *) event)->state & disp_info->alt_mask)
+    *modifiers |= MINPUT_KEY_ALT_MODIFIER;
+  if (((XKeyEvent *) event)->state & disp_info->super_mask)
+    *modifiers |= MINPUT_KEY_SUPER_MODIFIER;
+  if (((XKeyEvent *) event)->state & disp_info->hyper_mask)
+    *modifiers |= MINPUT_KEY_HYPER_MODIFIER;
+
+  return key;
+}
+
+
+void
+mwin__dump_gc (MFrame *frame, MRealizedFace *rface)
+{
+  unsigned long valuemask = GCForeground | GCBackground | GCClipMask;
+  XGCValues values;
+  Display *display = FRAME_DISPLAY (frame);
+  GCInfo *info = rface->info;
+  int i;
+
+  for (i = 0; i <= GC_INVERSE; i++)
+    {
+      XGetGCValues (display, info->gc[i], valuemask, &values);
+      fprintf (stderr, "GC%d: fore/#%lX back/#%lX", i,
+              values.foreground, values.background);
+      fprintf (stderr, "\n");
+    }
+}
+
+static MDeviceDriver x_driver =
+  {
+    mwin__close_device,
+    mwin__device_get_prop,
+    mwin__realize_face,
+    mwin__free_realized_face,
+    mwin__fill_space,
+    mwin__draw_empty_boxes,
+    mwin__draw_hline,
+    mwin__draw_box,
+    mwin__draw_points,
+    mwin__region_from_rect,
+    mwin__union_rect_with_region,
+    mwin__intersect_region,
+    mwin__region_add_rect,
+    mwin__region_to_rect,
+    mwin__free_region,
+    mwin__dump_region,
+    mwin__create_window,
+    mwin__destroy_window,
+    mwin__map_window,
+    mwin__unmap_window,
+    mwin__window_geometry,
+    mwin__adjust_window,
+    mwin__parse_event
+  };
+
+/* Functions to be stored in MDeviceLibraryInterface by dlsym ().  */
+
+int
+device_init ()
+{
+  M_iso8859_1 = msymbol ("iso8859-1");
+  M_iso10646_1 = msymbol ("iso10646-1");
+
+  display_info_list = mplist ();
+  device_list = mplist ();
+
+#ifdef HAVE_XFT2
+  xft_driver.select = mfont__ft_driver.select;
+  xft_driver.list = mfont__ft_driver.list;
+  xft_driver.list_family_names = mfont__ft_driver.list_family_names;
+#endif
+
+  Mxim = msymbol ("xim");
+  msymbol_put (Mxim, Minput_driver, &minput_xim_driver);
+
+  return 0;
+}
+
+int
+device_fini ()
+{
+  M17N_OBJECT_UNREF (display_info_list);
+  M17N_OBJECT_UNREF (device_list);
+  return 0;
+}
+
+
+#ifdef X_SET_ERROR_HANDLER
+static int
+x_error_handler (Display *display, XErrorEvent *error)
+{
+  mdebug_hook ();
+  return 0;
+}
+
+static int
+x_io_error_handler (Display *display)
+{
+  mdebug_hook ();
+  return 0;
+}
+#endif
+
+/** Return an MWDevice object corresponding to a display specified in
+    PLIST.
+
+    It searches device_list for a device matching the display.  If
+    found, return the found object.  Otherwise, return a newly created
+    object.  */
+
+int
+device_open (MFrame *frame, MPlist *param)
+{
+  Display *display = NULL;
+  Screen *screen = NULL;
+  int screen_num;
+  Drawable drawable = 0;
+  Widget widget = NULL;
+  Colormap cmap = 0;
+  int auto_display = 0;
+  MDisplayInfo *disp_info = NULL;
+  MWDevice *device = NULL;
+  MSymbol key;
+  XWindowAttributes attr;
+  unsigned depth = 0;
+  MPlist *plist;
+  AppData app_data;
+  MFont *font = NULL;
+  MFace *face;
+  int use_xfont = 0, use_freetype = 0, use_xft = 0;
+
+  for (plist = param; (key = mplist_key (plist)) != Mnil;
+       plist = mplist_next (plist))
+    {
+      if (key == Mdisplay)
+       display = (Display *) mplist_value (plist);
+      else if (key == Mscreen)
+       screen = mplist_value (plist);
+      else if (key == Mdrawable)
+       drawable = (Drawable) mplist_value (plist);
+      else if (key == Mdepth)
+       depth = (unsigned) mplist_value (plist);
+      else if (key == Mwidget)
+       widget = (Widget) mplist_value (plist);
+      else if (key == Mcolormap)
+       cmap = (Colormap) mplist_value (plist);
+      else if (key == Mfont)
+       {
+         MSymbol val = MPLIST_SYMBOL (plist);
+
+         if (val == Mx)
+           use_xfont = 1;
+#ifdef HAVE_FREETYPE
+         else if (val == Mfreetype)
+           use_freetype = 1;
+#ifdef HAVE_XFT2
+         else if (val == Mxft)
+           use_xft = 1;
+#endif
+#endif
+       }
+    }
+
+  /* If none of them is specified, use all of them.  */
+  if (! use_xfont && ! use_freetype && ! use_xft)
+    use_xfont = use_freetype = use_xft = 1;
+
+  if (widget)
+    {
+      display = XtDisplay (widget);
+      screen_num = XScreenNumberOfScreen (XtScreen (widget));
+      depth = DefaultDepth (display, screen_num);
+    }
+  else if (drawable)
+    {
+      Window root_window;
+      int x, y;
+      unsigned width, height, border_width;
+
+      if (! display)
+       MERROR (MERROR_WIN, -1);
+      XGetGeometry (display, drawable, &root_window,
+                   &x, &y, &width, &height, &border_width, &depth);
+      XGetWindowAttributes (display, root_window, &attr);
+      screen_num = XScreenNumberOfScreen (attr.screen);
+    }
+  else
+    {
+      if (screen)
+       display = DisplayOfScreen (screen);
+      else
+       {
+         if (! display)
+           {
+             display = XOpenDisplay (NULL);
+             if (! display)
+               MERROR (MERROR_WIN, -1);
+             auto_display = 1;
+           }
+         screen = DefaultScreenOfDisplay (display);
+       }
+      screen_num = XScreenNumberOfScreen (screen);
+      if (! depth)
+       depth = DefaultDepth (display, screen_num);
+    }
+
+  if (! cmap)
+    cmap = DefaultColormap (display, screen_num);
+
+  for (plist = display_info_list; mplist_key (plist) != Mnil;
+       plist = mplist_next (plist))
+    {
+      disp_info = (MDisplayInfo *) mplist_value (plist);
+      if (disp_info->display == display)
+       break;
+    }
+
+  if (mplist_key (plist) != Mnil)
+    M17N_OBJECT_REF (disp_info);
+  else
+    {
+      M17N_OBJECT (disp_info, free_display_info, MERROR_WIN);
+      disp_info->display = display;
+      disp_info->auto_display = auto_display;
+      disp_info->font_list = mplist ();
+      find_modifier_bits (disp_info);
+      disp_info->MULE_BASELINE_OFFSET
+       = XInternAtom (display, "_MULE_BASELINE_OFFSET", False);
+      disp_info->AVERAGE_WIDTH
+       = XInternAtom (display, "AVERAGE_WIDTH", False);
+      mplist_add (display_info_list, Mt, disp_info);
+    }  
+
+  for (plist = device_list; mplist_key (plist) != Mnil;
+       plist = mplist_next (plist))
+    {
+      device = (MWDevice *) mplist_value (plist);
+      if (device->display_info == disp_info
+         && device->depth == depth
+         && device->cmap == cmap
+         && device->screen_num == screen_num)
+       break;
+    }
+
+  if (mplist_key (plist) != Mnil)
+    M17N_OBJECT_REF (device);
+  else
+    {
+      unsigned long valuemask = GCForeground;
+      XGCValues values;
+      double pixels, mm;
+
+      M17N_OBJECT (device, free_device, MERROR_WIN);
+      device->display_info = disp_info;
+      device->screen_num = screen_num;
+      /* A drawable on which to create GCs.  */
+      device->drawable = XCreatePixmap (display,
+                                       RootWindow (display, screen_num),
+                                       1, 1, depth);
+      device->depth = depth;
+      device->cmap = cmap;
+      pixels = DisplayHeight (display, screen_num);
+      mm = DisplayHeightMM (display, screen_num);
+      device->resy = (mm < 1) ? 100 : pixels * 25.4 / mm;
+      device->realized_face_list = mplist ();
+      device->realized_font_list = mplist ();
+      mplist_add (device->realized_font_list, Mt, NULL);
+      device->realized_fontset_list = mplist ();
+      device->gc_list = mplist ();
+      values.foreground = BlackPixel (display, screen_num);
+      device->scratch_gc = XCreateGC (display, device->drawable,
+                                     valuemask, &values);
+#ifdef HAVE_XFT2
+      device->xft_draw = XftDrawCreate (display, device->drawable,
+                                       DefaultVisual (display, screen_num),
+                                       cmap);
+#endif
+    }
+
+  frame->device = device;
+  frame->device_type = MDEVICE_SUPPORT_OUTPUT | MDEVICE_SUPPORT_INPUT;
+  frame->dpi = device->resy;
+  frame->driver = &x_driver;
+  frame->font_driver_list = mplist ();
+#ifdef HAVE_XFT2
+  if (use_xft)
+    {
+      mplist_add (frame->font_driver_list, Mfreetype, &xft_driver);
+      use_freetype = 0;
+    }
+#endif /* HAVE_XFT2 */
+#ifdef HAVE_FREETYPE
+  if (use_freetype)
+    mplist_add (frame->font_driver_list, Mfreetype, &mfont__ft_driver);
+#endif /* HAVE_FREETYPE */
+  if (use_xfont || MPLIST_TAIL_P (frame->font_driver_list))
+    mplist_add (frame->font_driver_list, Mx, &xfont_driver);
+
+  frame->realized_font_list = device->realized_font_list;
+  frame->realized_face_list = device->realized_face_list;
+  frame->realized_fontset_list = device->realized_fontset_list;
+
+  if (widget)
+    {
+      XtResource resources[] = {
+       { XtNfont, XtCFont, XtRString, sizeof (String),
+         XtOffset (AppDataPtr, font), XtRString, DEFAULT_FONT },
+       { XtNforeground, XtCForeground, XtRString, sizeof (String),
+         XtOffset (AppDataPtr, foreground), XtRString, "black" },
+       { XtNbackground, XtCBackground, XtRString, sizeof (String),
+         XtOffset (AppDataPtr, background), XtRString, "white" },
+       { XtNreverseVideo, XtCReverseVideo, XtRBoolean, sizeof (Boolean),
+         XtOffset (AppDataPtr, reverse_video), XtRImmediate, (caddr_t) FALSE }
+      };
+
+      XtGetApplicationResources (widget, &app_data,
+                                resources, XtNumber (resources), NULL, 0);
+      frame->foreground = msymbol (app_data.foreground);
+      frame->background = msymbol (app_data.background);
+      frame->videomode = app_data.reverse_video == True ? Mreverse : Mnormal;
+    }
+  else
+    {
+      app_data.font = DEFAULT_FONT;
+      frame->foreground = msymbol ("black");
+      frame->background = msymbol ("white");
+      frame->videomode = Mnormal;
+    }
+
+  if (strcmp (app_data.font, DEFAULT_FONT) != 0)
+    {
+      XFontStruct *xfont = XLoadQueryFont (display, app_data.font);
+      unsigned long value;
+      char *name;
+
+      if (xfont)
+       {
+         font = mfont_parse_name (app_data.font, Mx);
+         if (! font
+             && XGetFontProperty (xfont, XA_FONT, &value)
+             && (name = ((char *) XGetAtomName (display, (Atom) value))))
+           font = mfont_parse_name (name, Mx);
+         XFreeFont (display, xfont);
+       }
+    }
+  if (! font)
+      font = mfont_parse_name (DEFAULT_FONT, Mx);
+  else if (! font->size)
+    font->size = 130;
+  face = mface_from_font (font);
+  free (font);
+  face->property[MFACE_FONTSET] = mfontset (NULL);
+  face->property[MFACE_FOREGROUND] = frame->foreground;
+  face->property[MFACE_BACKGROUND] = frame->background;
+  mface_put_prop (face, Mhline, mface_get_prop (mface__default, Mhline));
+  mface_put_prop (face, Mbox, mface_get_prop (mface__default, Mbox));
+  face->property[MFACE_VIDEOMODE] = frame->videomode;
+  mface_put_prop (face, Mhook_func, 
+                 mface_get_prop (mface__default, Mhook_func));
+  face->property[MFACE_RATIO] = (void *) 100;
+  mplist_push (param, Mface, face);
+  M17N_OBJECT_UNREF (face);
+
+#ifdef X_SET_ERROR_HANDLER
+  XSetErrorHandler (x_error_handler);
+  XSetIOErrorHandler (x_io_error_handler);
+#endif
+  return 0;
+}
+
+\f
+
+/* XIM (X Input Method) handler */
+
+typedef struct MInputXIMMethodInfo
+{
+  Display *display;
+  XIM xim;
+  MSymbol language;
+  MSymbol coding;
+} MInputXIMMethodInfo;
+
+typedef struct MInputXIMContextInfo
+{
+  XIC xic;
+  Window win;
+  MConverter *converter;
+} MInputXIMContextInfo;
+
+static int
+xim_open_im (MInputMethod *im)
+{
+  MInputXIMArgIM *arg = (MInputXIMArgIM *) im->arg;
+  MLocale *saved, *this;
+  char *save_modifier_list;
+  XIM xim;
+  MInputXIMMethodInfo *im_info;
+
+  saved = mlocale_set (LC_CTYPE, NULL);
+  this = mlocale_set (LC_CTYPE, arg->locale ? arg->locale : "");
+  if (! this)
+    /* The specified locale is not supported.  */
+    MERROR (MERROR_LOCALE, -1);
+  if (mlocale_get_prop (this, Mcoding) == Mnil)
+    {
+      /* Unable to decode the output of XIM.  */
+      mlocale_set (LC_CTYPE, msymbol_name (mlocale_get_prop (saved, Mname)));
+      MERROR (MERROR_LOCALE, -1);
+    }
+
+  if (arg->modifier_list)
+    save_modifier_list = XSetLocaleModifiers (arg->modifier_list);
+  else
+    save_modifier_list = XSetLocaleModifiers ("");
+  if (! save_modifier_list)
+    {
+      /* The specified locale is not supported by X.  */
+      mlocale_set (LC_CTYPE, msymbol_name (mlocale_get_prop (saved, Mname)));
+      MERROR (MERROR_LOCALE, -1);
+    }
+
+  xim = XOpenIM (arg->display, arg->db, arg->res_name, arg->res_class);
+  if (! xim)
+    {
+      /* No input method is available in the current locale.  */
+      XSetLocaleModifiers (save_modifier_list);
+      mlocale_set (LC_CTYPE, msymbol_name (mlocale_get_prop (saved, Mname)));
+      MERROR (MERROR_WIN, -1);
+    }
+
+  MSTRUCT_MALLOC (im_info, MERROR_WIN);
+  im_info->display = arg->display;
+  im_info->xim = xim;
+  im_info->language = mlocale_get_prop (this, Mlanguage);
+  im_info->coding = mlocale_get_prop (this, Mcoding);
+  im->info = im_info;
+
+  XSetLocaleModifiers (save_modifier_list);
+  mlocale_set (LC_CTYPE, msymbol_name (mlocale_get_prop (saved, Mname)));
+
+  return 0;
+}
+
+static void
+xim_close_im (MInputMethod *im)
+{
+  MInputXIMMethodInfo *im_info = (MInputXIMMethodInfo *) im->info;
+
+  XCloseIM (im_info->xim);
+  free (im_info);
+}
+
+static int
+xim_create_ic (MInputContext *ic)
+{
+  MInputXIMArgIC *arg = (MInputXIMArgIC *) ic->arg;
+  MInputXIMMethodInfo *im_info = (MInputXIMMethodInfo *) ic->im->info;
+  MInputXIMContextInfo *ic_info;
+  XIC xic;
+
+  if (! arg->input_style)
+    {
+      /* By default, use Root style.  */
+      arg->input_style = XIMPreeditNothing | XIMStatusNothing;
+      arg->preedit_attrs = NULL;
+      arg->status_attrs = NULL;
+    }
+
+  if (! arg->preedit_attrs && ! arg->status_attrs)
+    xic = XCreateIC (im_info->xim,
+                    XNInputStyle, arg->input_style,
+                    XNClientWindow, arg->client_win,
+                    XNFocusWindow, arg->focus_win,
+                    NULL);
+  else if (arg->preedit_attrs && ! arg->status_attrs)
+    xic = XCreateIC (im_info->xim,
+                    XNInputStyle, arg->input_style,
+                    XNClientWindow, arg->client_win,
+                    XNFocusWindow, arg->focus_win,
+                    XNPreeditAttributes, arg->preedit_attrs,
+                    NULL);
+  else if (! arg->preedit_attrs && arg->status_attrs)
+    xic = XCreateIC (im_info->xim,
+                    XNInputStyle, arg->input_style,
+                    XNClientWindow, arg->client_win,
+                    XNFocusWindow, arg->focus_win,
+                    XNStatusAttributes, arg->status_attrs,
+                    NULL);
+  else
+    xic = XCreateIC (im_info->xim,
+                    XNInputStyle, arg->input_style,
+                    XNClientWindow, arg->client_win,
+                    XNFocusWindow, arg->focus_win,
+                    XNPreeditAttributes, arg->preedit_attrs,
+                    XNStatusAttributes, arg->status_attrs,
+                    NULL);
+  if (! xic)
+    MERROR (MERROR_WIN, -1);
+
+  MSTRUCT_MALLOC (ic_info, MERROR_WIN);
+  ic_info->xic = xic;
+  ic_info->win = arg->focus_win;
+  ic_info->converter = mconv_buffer_converter (im_info->coding, NULL, 0);
+  ic->info = ic_info;
+  return 0;
+}
+
+static void
+xim_destroy_ic (MInputContext *ic)
+{
+  MInputXIMContextInfo *ic_info = (MInputXIMContextInfo *) ic->info;
+
+  XDestroyIC (ic_info->xic);
+  mconv_free_converter (ic_info->converter);
+  free (ic_info);
+  ic->info = NULL;
+}
+
+static int
+xim_filter (MInputContext *ic, MSymbol key, void *event)
+{
+  MInputXIMContextInfo *ic_info = (MInputXIMContextInfo *) ic->info;
+
+  return (XFilterEvent ((XEvent *) event, ic_info->win) == True);
+}
+
+
+static int
+xim_lookup (MInputContext *ic, MSymbol key, void *arg, MText *mt)
+{
+  MInputXIMMethodInfo *im_info = (MInputXIMMethodInfo *) ic->im->info;
+  MInputXIMContextInfo *ic_info = (MInputXIMContextInfo *) ic->info;
+  XKeyPressedEvent *ev = (XKeyPressedEvent *) arg;
+  KeySym keysym;
+  Status status;
+  char *buf;
+  int len;
+
+  buf = (char *) alloca (512);
+  len = XmbLookupString (ic_info->xic, ev, buf, 512, &keysym, &status);
+  if (status == XBufferOverflow)
+    {
+      buf = (char *) alloca (len);
+      len = XmbLookupString (ic_info->xic, ev, buf, len, &keysym, &status);
+    }
+
+  mtext_reset (ic->produced);
+  if (len == 0)
+    return 1;
+
+  mconv_reset_converter (ic_info->converter);
+  mconv_rebind_buffer (ic_info->converter, (unsigned char *) buf, len);
+  mconv_decode (ic_info->converter, ic->produced);
+  mtext_put_prop (ic->produced, 0, mtext_nchars (ic->produced),
+                 Mlanguage, (void *) im_info->language);
+  mtext_cpy (mt, ic->produced);
+  mtext_reset (ic->produced);  
+  return 0;
+}
+
+\f
+/*=*/
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+\f
+/* External API */
+
+/*** @addtogroup m17nInputMethodWin */
+
+/*** @{ */
+/*=*/
+/***en
+    @brief Input method driver for XIM.
+
+    The driver #minput_xim_driver is for the foreign input method of
+    name #Mxim.  It uses XIM (X Input Methods) as a background input
+    engine.
+
+    As the symbol #Mxim has property #Minput_driver whose value is
+    a pointer to this driver, the input method of language #Mnil
+    and name #Mxim uses this driver.
+
+    Therefore, for such input methods, the driver dependent arguments
+    to the functions whose name begin with minput_ must be as follows.
+
+    The argument $ARG of the function minput_open_im () must be a
+    pointer to the structure #MInputXIMArgIM.  See the documentation
+    of #MInputXIMArgIM for more details.
+
+    The argument $ARG of the function minput_create_ic () must be a
+    pointer to the structure #MInputXIMArgIC. See the documentation
+    of #MInputXIMArgIC for more details.
+
+    The argument $ARG of the function minput_filter () must be a
+    pointer to the structure @c XEvent.  The argument $KEY is ignored.
+
+    The argument $ARG of the function minput_lookup () must be the
+    same one as that of the function minput_filter ().  The argument
+    $KEY is ignored.  */
+
+/***ja
+    @brief XIMÍÑÆþÎϥɥ饤¥Ð.
+
+    ¥É¥é¥¤¥Ð #minput_xim_driver ¤Ï #Mxim ¤ò̾Á°¤È¤·¤Æ»ý¤Ä³°ÉôÆþÎϥ᥽¥Ã¥ÉÍѤǤ¢¤ê¡¢
+    XIM (X Input Methods) ¤ò¥Ð¥Ã¥¯¥°¥é¥¦¥ó¥É¤ÎÆþÎÏ¥¨¥ó¥¸¥ó¤È¤·¤Æ»ÈÍѤ¹¤ë¡£
+
+    ¥·¥ó¥Ü¥ë #Mxim ¤Ï¤³¤Î¥É¥é¥¤¥Ð¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÃͤȤ¹¤ë¥×¥í¥Ñ¥Æ¥£
+    #Minput_driver ¤ò»ý¤Á¡¢LANGUAGE ¤¬ #Mnil ¤Ç̾Á°¤¬ #Mxim 
+    ¤Ç¤¢¤ëÆþÎϥ᥽¥Ã¥É¤Ï¤³¤Î¥É¥é¥¤¥Ð¤òÍøÍѤ¹¤ë¡£
+
+    ¤·¤¿¤¬¤Ã¤Æ¡¢¤½¤ì¤é¤ÎÆþÎϥ᥽¥Ã¥É¤Ç¤Ï¡¢minput_ 
+    ¤Ç»Ï¤Þ¤ë̾Á°¤ò»ý¤Ä´Ø¿ô¤Î¥É¥é¥¤¥Ð¤Ë°Í¸¤¹¤ë°ú¿ô¤Ï¼¡¤Î¤è¤¦¤Ê¤â¤Î¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    ´Ø¿ô minput_open_im () ¤Î°ú¿ô $ARG ¤Ï¹½Â¤ÂΠ#MInputXIMArgIM 
+    ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï #MInputXIMArgIM ¤ÎÀâÌÀ¤ò»²¾È¡£
+
+    ´Ø¿ô minput_create_ic () ¤Î°ú¿ô $ARG ¤Ï¹½Â¤ÂΠ#MInputXIMArgIC 
+    ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï #MInputXIMArgIC ¤ÎÀâÌÀ¤ò»²¾È¡£
+
+    ´Ø¿ô minput_filter () ¤Î°ú¿ô $ARG ¤Ï¹½Â¤ÂΠ@c XEvent 
+    ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£°ú¿ô $KEY ¤Ï̵»ë¤µ¤ì¤ë¡£
+
+    ´Ø¿ô minput_lookup () ¤Î°ú¿ô $ARG ¤Ï´Ø¿ô function minput_filter () 
+    ¤Î°ú¿ô $ARG ¤ÈƱ¤¸¤â¤Î¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£ °ú¿ô $KEY ¤Ï¡¢Ìµ»ë¤µ¤ì¤ë¡£  */
+
+MInputDriver minput_xim_driver =
+  { xim_open_im, xim_close_im, xim_create_ic, xim_destroy_ic,
+    xim_filter, xim_lookup, NULL };
+/*=*/
+/*** @} */ 
+/*=*/
+#else  /* not HAVE_X11 */
+
+int device_open () { return -1; }
+
+#endif /* not HAVE_X11 */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/m17n-X.h b/src/m17n-X.h
new file mode 100644 (file)
index 0000000..78d57e6
--- /dev/null
@@ -0,0 +1,146 @@
+/* m17n-X.h -- header file for the GUI API on X Windows.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_X_H_
+#define _M17N_X_H_
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xresource.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* For inputting.  */
+
+extern MInputDriver minput_xim_driver;
+extern MSymbol Mxim;
+
+/*** @ingroup m17nInputMethodWin */
+/***en
+    @brief Structure pointed to by the argument $ARG of the function minput_open_im ().
+
+    The type #MInputXIMArgIM is the structure pointed to by the
+    argument $ARG of the function minput_open_im () for the foreign
+    input method of name #Mxim.  */
+
+/***ja
+    @brief ´Ø¿ô minput_open_im () ¤Î°ú¿ô $ARG ¤Ë¤è¤Ã¤Æ»Ø¤µ¤ì¤ë¹½Â¤ÂÎ.
+
+    #MInputXIMArgIM ·¿¤Ï¡¢´Ø¿ô minput_open_im () ¤¬Ì¾Á° #Mxim 
+    ¤ò»ý¤Ä³°ÉôÆþÎϥ᥽¥Ã¥É¤òÀ¸À®¤¹¤ëºÝ¤Ë°ú¿ô $ARG ¤Ë¤è¤Ã¤Æ»Ø¤µ¤ì¤ë¹½Â¤ÂΤǤ¢¤ë¡£  */
+
+typedef struct
+{
+  /***en The meaning of the following four members are the same as
+      arguments to XOpenIM ().  */
+  /***ja °Ê²¼¤Î£´¤Ä¤Î¥á¥ó¥Ð¤Î°ÕÌ£¤Ï¡¢XOpenIM () ¤Î°ú¿ô¤Î°ÕÌ£¤ÈƱ¤¸¤Ç¤¢¤ë.  */
+
+  /***en Display of the client.  */
+  /***ja ¥¯¥é¥¤¥¢¥ó¥È¤Î¥Ç¥£¥¹¥×¥ì¥¤.  */
+  Display *display;
+
+  /***en Pointer to the X resource database.  */
+  /***ja X ¥ê¥½¡¼¥¹¡¦¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ø¤Î¥Ý¥¤¥ó¥¿.  */
+  XrmDatabase db;
+
+  /***en Full class name of the application.  */
+  /***ja ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î´°Á´¤Ê¥¯¥é¥¹Ì¾.  */
+  char *res_class;
+
+  /***en Full resource name of the application.  */
+  /***ja ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î´°Á´¤Ê¥ê¥½¡¼¥¹Ì¾.  */
+  char *res_name;
+
+  /***en Locale name under which an XIM is opened.  */
+  /***ja XIM¤¬¥ª¡¼¥×¥ó¤µ¤ì¤¿¥í¥±¡¼¥ë̾.  */
+  char *locale;
+
+  /***en Arguments to XSetLocaleModifiers ().  */
+  /***ja XSetLocaleModifiers () ¤Î°ú¿ô.  */
+  char *modifier_list;
+} MInputXIMArgIM;
+
+/*=*/
+
+/*** @ingroup m17nInputMethodWin */
+/***en
+    @brief Structure pointed to by the argument $ARG of the function minput_create_ic ().
+
+    The type #MInputXIMArgIC is the structure pointed to by the
+    argument $ARG of the function minput_create_ic () for the foreign
+    input method of name #Mxim.  */
+
+/***ja
+    @brief ´Ø¿ô minput_create_ic () ¤Î°ú¿ô $ARG ¤Ë¤è¤Ã¤Æ»Ø¤µ¤ì¤ë¹½Â¤ÂÎ.
+
+    #MInputXIMArgIC ·¿¤Ï¡¢´Ø¿ô minput_create_ic () ¤¬Ì¾Á° #Mxim 
+    ¤ò»ý¤Ä³°ÉôÆþÎϥ᥽¥Ã¥ÉÍѤ˸ƤФì¤ëºÝ¤Ë¡¢°ú¿ô $ARG ¤Ë¤è¤Ã¤Æ»Ø¤µ¤ì¤ë¹½Â¤ÂΤǤ¢¤ë¡£ */
+
+typedef struct
+{
+  /***en Used as the arguments of @c XCreateIC following @c
+      XNInputStyle.  If this is zero, ( @c XIMPreeditNothing | @c
+      XIMStatusNothing) is used, and \<preedit_attrs\> and
+      \<status_attrs\> are set to @c NULL.  */
+  /***ja @c XCreateIC ¤Î @c XNInputStyle ¤Ë³¤¯°ú¿ô¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
+      ¥¼¥í¤Ê¤é¤Ð¡¢ ( @c XIMPreeditNothing | @c XIMStatusNothing) ¤¬ÍÑ
+      ¤¤¤é¤ì¡¢ \<preedit_attrs\> ¤È \<status_attrs\> ¤Ï @c NULL 
+      ¤ËÀßÄꤵ¤ì¤ë¡£ */
+
+  XIMStyle input_style;
+  /***en Used as the argument of @c XCreateIC following @c XNClientWindow.  */
+  /***ja @c XCreateIC ¤Î @c XNClientWindow ¤Ë³¤¯°ú¿ô¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£  */
+
+  Window client_win;
+  /***en Used as the argument of @c XCreateIC following @c XNFocusWindow.  */
+  /***ja @c XCreateIC ¤Î @c XNFocusWindow ¤Ë³¤¯°ú¿ô¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£  */
+
+  Window focus_win;
+  /***en If non- @c NULL, used as the argument of @c XCreateIC following
+      @c XNPreeditAttributes.  */
+  /***ja @c NULL ¤Ç¤Ê¤±¤ì¤Ð¡¢ @c XCreateIC following ¤Î@c
+      XNPreeditAttributes ¤Ë³¤¯°ú¿ô¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£  */
+
+  XVaNestedList preedit_attrs;
+  /***en If non- @c NULL, used as the argument of @c XCreateIC following
+      @c XNStatusAttributes.  */ 
+  /***ja @c NULL ¤Ç¤Ê¤±¤ì¤Ð¡¢ @c XCreateIC following ¤Î @c
+      XNStatusAttributes ¤Ë³¤¯°ú¿ô¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£  */
+
+  XVaNestedList status_attrs;
+} MInputXIMArgIC;
+/*=*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* not _M17N_X_H_ */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/m17n-core.c b/src/m17n-core.c
new file mode 100644 (file)
index 0000000..945745e
--- /dev/null
@@ -0,0 +1,1192 @@
+/* m17n-core.c -- body of the CORE API.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nIntro
+    @brief Introduction to the m17n library.
+
+    <em>API LEVELS</em>
+
+    The API of the m17n library is divided into these five.
+
+    <ol>
+    <li> CORE API
+
+    It provides basic modules to handle M-texts.  To use this API, an
+    application program must include <m17n-core<EM></EM>.h> and be
+    linked with -lm17n-core.
+
+    <li> SHELL API
+
+    It provides modules for character properties, character set
+    handling, code conversion, etc.  They load various kinds of
+    data from the database on demand.  To use this API, an application
+    program must include <m17n<EM></EM>.h> and be linked with
+    -lm17n-core -lm17n.
+
+    When you use this API, CORE API is also available.
+
+    <li> FLT API
+
+    It provides modules for text shaping using @ref mdbFLT.  To use
+    this API, an application program must include <m17n<EM></EM>.h>
+    and be linked with -lm17n-core -lm17n-flt.
+
+    When you use this API, CORE API is also available.
+
+    <li> GUI API
+
+    It provides GUI modules such as drawing and inputting M-texts on a
+    graphic device.  This API itself is independent of graphic
+    devices, but most functions require an argument MFrame that is
+    created for a specific type of graphic devices.  The currently
+    supported graphic devices are null device, the X Window System,
+    and image data (gdImagePtr) of the GD library.
+
+    On a frame of a null device, you cannot draw text nor use input
+    methods.  However, functions like mdraw_glyph_list (), etc. are
+    available.
+
+    On a frame of the X Window System, you can use the whole GUI API.
+
+    On a frame of the GD library, you can use all drawing API but
+    cannot use input methods.
+
+    To use this API, an application program must include
+    <m17n-gui<EM></EM>.h> and be linked with -lm17n-core -lm17n
+    -lm17n-gui.
+
+    When you use this API, CORE, SHELL, and FLT APIs are also
+    available.
+
+    <li> MISC API
+
+    It provides miscellaneous functions to support error handling and
+    debugging.  This API cannot be used standalone; it must be used
+    with one or more APIs listed above.  To use this API, an
+    application program must include <m17n-misc<EM></EM>.h> in
+    addition to one of the header files described above.
+
+    </ol>
+
+    See also the section @ref m17n-config "m17n-config(1)".
+
+    <em>ENVIRONMENT VARIABLES</em>
+
+    The m17n library pays attention to the following environment
+    variables.
+
+    <ul>
+    <li> @c M17NDIR
+
+    The name of the directory that contains data of the m17n database.
+    See @ref m17nDatabase for details.
+
+    <li> @c MDEBUG_XXX
+
+    Environment variables whose names start with "MDEBUG_" control
+    debug information output.  See @ref m17nDebug for details.
+
+    </ul>
+
+    <em>API NAMING CONVENTION</em>
+
+    The m17n library exports functions, variables, macros, and types.
+    All of them start with the letter 'm' or 'M', and are followed by
+    an object name (e.g. "symbol", "plist") or a module name
+    (e.g. draw, input).  Note that the name of M-text objects start
+    with "mtext" and not with "mmtext".
+
+    <ul>
+
+    <li> functions -- mobject () or mobject_xxx ()
+
+    They start with 'm' and are followed by an object name in lower
+    case.  Words are separated by '_'.  For example, msymbol (),
+    mtext_ref_char (), mdraw_text ().
+
+    <li> non-symbol variables -- mobject, or mobject_xxx
+    
+    The naming convention is the same as functions (e.g. mface_large).
+
+    <li> symbol variables -- Mname
+
+    Variables of the type MSymbol start with 'M' and are followed by
+    their names.  Words are separated by '_'.  For example, Mlanguage
+    (the name is "language"), Miso_2022 (the name is "iso-2022").
+
+    <li> macros -- MOBJECT_XXX
+
+    They start with 'M' and are followed by an object name in upper
+    case.  Words are separated by '_'.
+
+    <li> types -- MObject or MObjectXxx
+
+    They start with 'M' and are followed by capitalized object names.
+    Words are concatenated directly and no '_' are used.  For example,
+    MConverter, MInputDriver.
+
+    </ul>
+
+  */
+
+/***ja
+    @addtogroup m17nIntro
+    @brief m17n ¥é¥¤¥Ö¥é¥ê ¥¤¥ó¥È¥í¥À¥¯¥·¥ç¥ó.
+
+    @em API¤Î¥ì¥Ù¥ë
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Î API ¤Ï°Ê²¼¤Î£´¼ï¤ËʬÎव¤ì¤Æ¤¤¤ë¡£
+
+    <ol>
+    <li> ¥³¥¢ API
+
+    M-text ¤ò°·¤¦¤¿¤á¤Î´ðËÜŪ¤Ê¥â¥¸¥å¡¼¥ë¤òÄ󶡤¹¤ë¡£
+    ¤³¤Î API ¤òÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï
+    <m17n-core<EM></EM>.h> ¤ò include ¤·¡¢ -lm17n-core
+    ¤Ç¥ê¥ó¥¯¤µ¤ì¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    <li> ¥·¥§¥ë API
+
+    Ê¸»ú¥×¥í¥Ñ¥Æ¥£¡¢Ê¸»ú½¸¹çÁàºî¡¢¥³¡¼¥ÉÊÑ´¹Åù¤Î¤¿¤á¤Î¥â¥¸¥å¡¼¥ë¤òÄ󶡤¹¤ë¡£
+    ¤³¤ì¤é¤Î¥â¥¸¥å¡¼¥ë¤Ï¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹¤«¤éɬÍפ˱þ¤¸¤Æ¿Íͤʥǡ¼¥¿¤ò¥í¡¼¥É¤¹¤ë¡£
+    ¤³¤Î API ¤òÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï
+    <m17n<EM></EM>.h> ¤ò include ¤·¡¢ -lm17n-core -lm17n
+    ¤Ç¥ê¥ó¥¯¤µ¤ì¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    ¤³¤Î API ¤ò»ÈÍѤ¹¤ì¤Ð¡¢¥³¥¢ API ¤â¼«Æ°Åª¤Ë»ÈÍѲÄǽ¤È¤Ê¤ë¡£
+
+    <li> FLT API
+
+    Ê¸»úÎóɽ¼¨¤Ë @ref mdbFLT ¤òÍѤ¤¤ë¥â¥¸¥å¡¼¥ë¤òÄ󶡤¹¤ë¡£¤³¤Î API
+    ¤òÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï <m17n<EM></EM>.h> 
+    ¤ò include ¤·¡¢ -lm17n-core -lm17n-flt ¤Ç¥ê¥ó¥¯¤µ¤ì¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    ¤³¤Î API ¤ò»ÈÍѤ¹¤ì¤Ð¡¢¥³¥¢ API ¤â¼«Æ°Åª¤Ë»ÈÍѲÄǽ¤È¤Ê¤ë¡£
+
+    <li> GUI API
+
+    ¥°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¾å¤Ç M-text ¤òɽ¼¨¤·¤¿¤êÆþÎϤ·¤¿¤ê¤¹¤ë¤¿¤á¤Î
+    GUI ¥â¥¸¥å¡¼¥ë¤òÄ󶡤¹¤ë¡£¤³¤Î API
+    ¼«ÂΤϥ°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¤È¤ÏÆÈΩ¤Ç¤¢¤ë¤¬¡¢
+    Â¿¤¯¤Î´Ø¿ô¤ÏÆÃÄê¤Î¥°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹ÍѤ˺îÀ®¤µ¤ì¤¿ 
+    MFrame ¤ò°ú¿ô¤Ë¼è¤ë¡£
+    ¸½»þÅÀ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¤Ï¡¢¥Ì¥ë¥Ç¥Ð¥¤¥¹¡¢X
+    ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¡¢¤ª¤è¤Ó GD ¥é¥¤¥Ö¥é¥ê¤Î¥¤¥á¡¼¥¸¥Ç¡¼¥¿
+    (gdImagePtr) ¤Ç¤¢¤ë¡£
+
+    ¥Ì¥ë¥Ç¥Ð¥¤¥¹¤Î¥Õ¥ì¡¼¥à¾å¤Ç¤Ïɽ¼¨¤âÆþÎϤâ¤Ç¤­¤Ê¤¤¡£¤¿¤À¤·
+    mdraw_glyph_list () ¤Ê¤É¤Î´Ø¿ô¤Ï»ÈÍѲÄǽ¤Ç¤¢¤ë¡£
+
+    X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Î¥Õ¥ì¡¼¥à¾å¤Ç¤Ï¤¹¤Ù¤Æ¤Î GUI API ¤¬»ÈÍѤǤ­¤ë¡£
+
+    GD ¥é¥¤¥Ö¥é¥ê¤Î¥Õ¥ì¡¼¥à¾å¤Ç¤Ï¡¢ÉÁ²èÍѤΠAPI
+    ¤Ï¤¹¤Ù¤Æ»ÈÍѤǤ­¤ë¤¬¡¢ÆþÎϤϤǤ­¤Ê¤¤¡£
+
+    ¤³¤Î API ¤ò»ÈÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï
+    <m17n-gui<EM></EM>.h> ¤ò include ¤·¡¢-lm17n-core -lm17n -lm17n-gui
+    ¤Ç¥ê¥ó¥¯¤µ¤ì¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    ¤³¤Î API ¤ò»ÈÍѤ¹¤ì¤Ð¡¢¥³¥¢ API¡¢¥·¥§¥ë API¡¢¤ª¤è¤Ó FLT API
+    ¤â¼«Æ°Åª¤Ë»ÈÍѲÄǽ¤È¤Ê¤ë¡£
+
+    <li> ¤½¤Î¾¤Î API
+
+    ¥¨¥é¡¼½èÍý¡¢¥Ç¥Ð¥Ã¥°ÍѤΤ½¤Î¾¤Î´Ø¿ô¤òÄ󶡤¹¤ë¡£¤³¤Î API
+    ¤Ï¤½¤ì¤À¤±¤Ç¤Ï»ÈÍѤǤ­¤º¡¢¾åµ­¤Î¾¤Î API
+    ¤È¶¦¤Ë»È¤¦¡£ÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¾åµ­¤Î¤¤¤º¤ì¤«¤Îinclude
+    ¥Õ¥¡¥¤¥ë¤Ë²Ã¤¨¤Æ¡¢ <m17n-misc<EM></EM>.h> ¤òinclude
+    ¤·¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    </ol>
+
+    @ref m17n-config "m17n-config(1)" Àá¤â»²¾È¡£
+
+    @em ´Ä¶­ÊÑ¿ô
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï°Ê²¼¤Î´Ä¶­ÊÑ¿ô¤ò»²¾È¤¹¤ë¡£
+
+    <ul>
+    <li> @c M17NDIR
+
+    m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥Ç¡¼¥¿¤ò³ÊǼ¤·¤¿¥Ç¥£¥ì¥¯¥È¥ê¤Î̾Á°¡£¾ÜºÙ¤Ï @ref
+    m17nDatabase »²¾È¡£
+
+    <li> @c MDEBUG_XXX
+
+    "MDEBUG_" ¤Ç»Ï¤Þ¤ë̾Á°¤ò»ý¤Ä´Ä¶­ÊÑ¿ô¤Ï¥Ç¥Ð¥Ã¥°¾ðÊó¤Î½ÐÎϤòÀ©¸æ¤¹¤ë¡£
+    ¾ÜºÙ¤Ï @ref m17nDebug »²¾È¡£
+
+    </ul>
+
+    @em API @em ¤Î̿̾µ¬Â§
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï¡¢´Ø¿ô¡¢ÊÑ¿ô¡¢¥Þ¥¯¥í¡¢·¿¤ò export ¤¹¤ë¡£¤½¤ì¤é¤Ï 'm' 
+    ¤Þ¤¿¤Ï 'M' ¤Î¤¢¤È¤Ë¥ª¥Ö¥¸¥§¥¯¥È̾ ("symbol"¡¢"plist" ¤Ê¤É)
+    ¤Þ¤¿¤Ï¥â¥¸¥å¡¼¥ë̾ (draw, input ¤Ê¤É) ¤ò³¤±¤¿¤â¤Î¤Ç¤¢¤ë¡£
+    M-text ¥ª¥Ö¥¸¥§¥¯¥È¤Î̾Á°¤Ï "mmtext" ¤Ç¤Ï¤Ê¤¯¤Æ "mtext"
+    ¤Ç»Ï¤Þ¤ë¤³¤È¤ËÃí°Õ¡£
+    
+    <ul>
+
+    <li> ´Ø¿ô -- mobject () ¤Þ¤¿¤Ï mobject_xxx ()
+
+    'm' ¤Î¤¢¤È¤Ë¾®Ê¸»ú¤Ç¥ª¥Ö¥¸¥§¥¯¥È̾¤¬Â³¤¯¡£Ã±¸ì´Ö¤Ï '_'
+    ¤Ç¶èÀÚ¤é¤ì¤ë¡£¤¿¤È¤¨¤Ð¡¢msymbol (),
+     mtext_ref_char (), mdraw_text () ¤Ê¤É¡£
+
+    <li> ¥·¥ó¥Ü¥ë¤Ç¤Ê¤¤ÊÑ¿ô -- mobject,  ¤Þ¤¿¤Ï mobject_xxx
+    
+    ´Ø¿ô¤ÈƱ¤¸Ì¿Ì¾µ¬Â§¤Ë½¾¤¦¡£¤¿¤È¤¨¤Ð  mface_large ¤Ê¤É¡£
+
+    <li> ¥·¥ó¥Ü¥ëÊÑ¿ô -- Mname
+
+    MSymbol ·¿ÊÑ¿ô¤Ï¡¢'M' ¤Î¸å¤Ë̾Á°¤¬Â³¤¯¡£Ã±¸ì´Ö¤Ï '_'
+    ¤Ç¶èÀÚ¤é¤ì¤ë¡£¤¿¤È¤¨¤Ð Mlanguage (̾Á°¤Ï "language"), Miso_2022
+    (̾Á°¤Ï"iso-2022") ¤Ê¤É¡£
+
+    <li> ¥Þ¥¯¥í -- MOBJECT_XXX
+
+    'M' ¤Î¸å¤ËÂçʸ»ú¤Ç¥ª¥Ö¥¸¥§¥¯¥È̾¤¬Â³¤¯¡£Ã±¸ì´Ö¤Ï '_' ¤Ç¶èÀÚ¤é¤ì¤ë¡£
+
+    <li> ¥¿¥¤¥× -- MObject ¤Þ¤¿¤Ï MObjectXxx
+
+    'M' ¤Î¸å¤ËÂçʸ»ú¤Ç»Ï¤Þ¤ë¥ª¥Ö¥¸¥§¥¯¥È̾¤¬Â³¤¯¡£Ã±¸ì¤ÏϢ³¤·¤Æ½ñ¤«¤ì¡¢
+    '_' ¤ÏÍѤ¤¤é¤ì¤Ê¤¤¡£¤¿¤È¤¨¤Ð MConverter, MInputDriver ¤Ê¤É¡£
+
+    </ul>
+    
+    */
+/*=*/
+/*** @{ */
+#ifdef FOR_DOXYGEN
+/***en
+    The #M17NLIB_MAJOR_VERSION macro gives the major version number
+    of the m17n library.  */
+/***ja
+    ¥Þ¥¯¥í #M17NLIB_MAJOR_VERSION ¤Ï m17n 
+    ¥é¥¤¥Ö¥é¥ê¤Î¥á¥¸¥ã¡¼¥Ð¡¼¥¸¥ç¥óÈÖ¹æ¤òÍ¿¤¨¤ë.  */
+
+#define M17NLIB_MAJOR_VERSION
+
+/*=*/
+
+/***en
+    The #M17NLIB_MINOR_VERSION macro gives the minor version number
+    of the m17n library.  */
+
+/***ja
+    ¥Þ¥¯¥í #M17NLIB_MINOR_VERSION ¤Ï m17n 
+    ¥é¥¤¥Ö¥é¥ê¤Î¥Þ¥¤¥Ê¡¼¥Ð¡¼¥¸¥ç¥óÈÖ¹æ¤òÍ¿¤¨¤ë.  */
+
+#define M17NLIB_MINOR_VERSION
+
+/*=*/
+
+/***en
+    The #M17NLIB_PATCH_LEVEL macro gives the patch level number
+    of the m17n library.  */
+
+/***ja
+    ¥Þ¥¯¥í #M17NLIB_PATCH_LEVEL ¤Ï m17n 
+    ¥é¥¤¥Ö¥é¥ê¤Î¥Ñ¥Ã¥Á¥ì¥Ù¥ëÈÖ¹æ¤òÍ¿¤¨¤ë.  */
+
+#define M17NLIB_PATCH_LEVEL
+
+/*=*/
+
+/***en
+    The #M17NLIB_VERSION_NAME macro gives the version name of the
+    m17n library as a string.  */
+
+/***ja
+    ¥Þ¥¯¥í #M17NLIB_VERSION_NAME ¤Ï m17n 
+    ¥é¥¤¥Ö¥é¥ê¤Î¥Ð¡¼¥¸¥ç¥ó̾¤òʸ»úÎó¤È¤·¤ÆÍ¿¤¨¤ë.  */
+
+#define M17NLIB_VERSION_NAME
+
+/*=*/
+
+/***en
+    @brief Initialize the m17n library.
+
+    The macro M17N_INIT () initializes the m17n library.  This macro
+    must be called before any m17n functions are used.
+
+    It is safe to call this macro multiple times, but in that case,
+    the macro M17N_FINI () must be called the same times to free the
+    memory.
+
+    If the initialization was successful, the external variable
+    #merror_code is set to 0.  Otherwise it is set to -1.
+
+    @seealso
+    M17N_FINI (), m17n_status ()  */
+
+/***ja
+    @brief m17n ¥é¥¤¥Ö¥é¥ê¤ò½é´ü²½¤¹¤ë.
+
+    ¥Þ¥¯¥í M17N_INIT () ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤ò½é´ü²½¤¹¤ë¡£m17n 
+    ¤Î´Ø¿ô¤òÍøÍѤ¹¤ëÁ°¤Ë¡¢¤³¤Î¥Þ¥¯¥í¤ò¤Þ¤º¸Æ¤Ð¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+    
+    ¤³¤Î¥Þ¥¯¥í¤òÊ£¿ô²ó¸Æ¤ó¤Ç¤â°ÂÁ´¤Ç¤¢¤ë¤¬¡¢¤½¤Î¾ì¹ç¥á¥â¥ê¤ò²òÊü¤¹¤ë¤¿¤á¤Ë¥Þ¥¯¥í
+    M17N_FINI () ¤òƱ¤¸²ó¿ô¸Æ¤ÖɬÍפ¬¤¢¤ë¡£
+
+    ³°ÉôÊÑ¿ô #merror_code ¤Ï¡¢½é´ü²½¤¬À®¸ù¤¹¤ì¤Ð 0 ¤Ë¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð 
+    -1 ¤ËÀßÄꤵ¤ì¤ë¡£  
+
+    @seealso
+    M17N_FINI (), m17n_status ()  */
+
+#define M17N_INIT()
+
+/*=*/
+
+/***en
+    @brief Finalize the m17n library.
+
+    The macro M17N_FINI () finalizes the m17n library.  It frees all the
+    memory area used by the m17n library.  Once this macro is
+    called, no m17n functions should be used until the
+    macro M17N_INIT () is called again.
+
+    If the macro M17N_INIT () was called N times, the Nth call of this
+    macro actually free the memory. 
+
+    @seealso
+    M17N_INIT (), m17n_status ()  */
+/***ja
+    @brief m17n ¥é¥¤¥Ö¥é¥ê¤ò½ªÎ»¤¹¤ë. 
+
+    ¥Þ¥¯¥í M17N_FINI () ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤ò½ªÎ»¤¹¤ë¡£m17n 
+    ¥é¥¤¥Ö¥é¥ê¤¬»È¤Ã¤¿Á´¤Æ¤Î¥á¥â¥êÎΰè¤Ï²òÊü¤µ¤ì¤ë¡£°ìÅÙ¤³¤Î¥Þ¥¯¥í¤¬¸Æ¤Ð¤ì¤¿¤é¡¢¥Þ¥¯¥í
+    M17N_INIT () ¤¬ºÆÅٸƤФì¤ë¤Þ¤Ç m17n ´Ø¿ô¤Ï»È¤¦¤Ù¤­¤Ç¤Ê¤¤¡£
+
+    ¥Þ¥¯¥í M17N_INIT () ¤¬ N ²ó¸Æ¤Ð¤ì¤Æ¤¤¤¿¾ì¹ç¤Ë¤Ï¡¢¤³¤Î¥Þ¥¯¥í¤¬ N 
+    ²ó¸Æ¤Ð¤ì¤Æ½é¤á¤Æ¥á¥â¥ê¤¬²òÊü¤µ¤ì¤ë¡£
+
+    @seealso
+    M17N_INIT (), m17n_status ()  */
+
+#define M17N_FINI()
+#endif /* FOR_DOXYGEN */
+/*=*/
+/*** @} */ 
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <unistd.h>
+
+#include "m17n-core.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "symbol.h"
+
+static void
+default_error_handler (enum MErrorCode err)
+{
+  exit (err);
+}
+
+static struct timeval time_stack[16];
+static int time_stack_index;
+
+static M17NObjectArray *object_array_root;
+
+static void
+report_object_array ()
+{
+  fprintf (stderr, "%16s %7s %7s %7s\n",
+          "object", "created", "freed", "alive");
+  fprintf (stderr, "%16s %7s %7s %7s\n",
+          "------", "-------", "-----", "-----");
+  for (; object_array_root; object_array_root = object_array_root->next)
+    {
+      M17NObjectArray *array = object_array_root;
+
+      fprintf (stderr, "%16s %7d %7d %7d\n", array->name,
+              array->used, array->used - array->count, array->count);
+      if (array->count > 0)
+       {
+         int i;
+         for (i = 0; i < array->used && ! array->objects[i]; i++);
+
+         if (strcmp (array->name, "M-text") == 0)
+           {
+             MText *mt = (MText *) array->objects[i];
+
+             if (mt->format <= MTEXT_FORMAT_UTF_8)
+               fprintf (stderr, "\t\"%s\"\n", (char *) mt->data);
+           }
+         else if (strcmp (array->name, "Plist") == 0)
+           {
+             MPlist *plist = (MPlist *) array->objects[i];
+
+             mdebug_dump_plist (plist, 8);
+             fprintf (stderr, "\n");
+           }
+       }
+
+      if (array->used > 0)
+       {
+         free (array->objects);
+         array->count = array->used = 0;
+       }
+    }
+}
+
+
+\f
+/* Internal API */
+
+int m17n__core_initialized;
+int m17n__shell_initialized;
+int m17n__gui_initialized;
+
+int mdebug__flags[MDEBUG_MAX];
+FILE *mdebug__output;
+
+void
+mdebug__push_time ()
+{
+  struct timezone tz;
+
+  gettimeofday (time_stack + time_stack_index++, &tz);
+}
+
+void
+mdebug__pop_time ()
+{
+  time_stack_index--;
+}
+
+void
+mdebug__print_time ()
+{
+  struct timeval tv;
+  struct timezone tz;
+  long diff;
+
+  gettimeofday (&tv, &tz);
+  diff = ((tv.tv_sec - time_stack[time_stack_index - 1].tv_sec) * 1000000
+         + (tv.tv_usec - time_stack[time_stack_index - 1].tv_usec));
+  fprintf (stderr, "%8ld ms.", diff);
+  time_stack[time_stack_index - 1] = tv;
+}
+
+static void
+SET_DEBUG_FLAG (char *env_name, enum MDebugFlag flag)
+{
+  char *env_value = getenv (env_name);
+
+  if (env_value)
+    {
+      int int_value = atoi (env_value);
+
+      if (flag == MDEBUG_ALL)
+       {
+         int i;
+         for (i = 0; i < MDEBUG_MAX; i++)
+           mdebug__flags[i] = int_value;
+       }
+      else
+       mdebug__flags[flag] = int_value;
+    }
+}
+
+void
+mdebug__add_object_array (M17NObjectArray *array, char *name)
+{
+  array->name = name;
+  array->count = 0;
+  array->next = object_array_root;
+  object_array_root = array;
+}
+
+
+void
+mdebug__register_object (M17NObjectArray *array, void *object)
+{
+  if (array->used == 0)
+    MLIST_INIT1 (array, objects, 256);
+  array->count++;
+  MLIST_APPEND1 (array, objects, object, MERROR_OBJECT);
+}
+
+void
+mdebug__unregister_object (M17NObjectArray *array, void *object)
+{
+  array->count--;
+  if (array->count >= 0)
+    {
+      int i;
+
+      for (i = array->used - 1; i >= 0 && array->objects[i] != object; i--);
+      if (i >= 0)
+       {
+         if (i == array->used - 1)
+           array->used--;
+         array->objects[i] = NULL;
+       }
+      else
+       mdebug_hook ();
+    }
+  else                                                                 \
+    mdebug_hook ();
+}
+
+\f
+/* External API */
+
+/* The following two are actually not exposed to a user but concealed
+   by the macro M17N_INIT (). */
+
+void
+m17n_init_core (void)
+{
+  int mdebug_flag = MDEBUG_INIT;
+
+  merror_code = MERROR_NONE;
+  if (m17n__core_initialized++)
+    return;
+
+  m17n_memory_full_handler = default_error_handler;
+
+  SET_DEBUG_FLAG ("MDEBUG_ALL", MDEBUG_ALL);
+  SET_DEBUG_FLAG ("MDEBUG_INIT", MDEBUG_INIT);
+  SET_DEBUG_FLAG ("MDEBUG_FINI", MDEBUG_FINI);
+  SET_DEBUG_FLAG ("MDEBUG_CHARSET", MDEBUG_CHARSET);
+  SET_DEBUG_FLAG ("MDEBUG_CODING", MDEBUG_CODING);
+  SET_DEBUG_FLAG ("MDEBUG_DATABASE", MDEBUG_DATABASE);
+  SET_DEBUG_FLAG ("MDEBUG_FONT", MDEBUG_FONT); 
+  SET_DEBUG_FLAG ("MDEBUG_FLT", MDEBUG_FLT);
+  SET_DEBUG_FLAG ("MDEBUG_FONTSET", MDEBUG_FONTSET);
+  SET_DEBUG_FLAG ("MDEBUG_INPUT", MDEBUG_INPUT);
+  /* for backward compatibility... */
+  SET_DEBUG_FLAG ("MDEBUG_FONT_FLT", MDEBUG_FLT);
+  SET_DEBUG_FLAG ("MDEBUG_FONT_OTF", MDEBUG_FLT);
+  {
+    char *env_value = getenv ("MDEBUG_OUTPUT_FILE");
+
+    mdebug__output = NULL;
+    if (env_value)
+      {
+       if (strcmp (env_value, "stdout"))
+         mdebug__output = stdout;
+       else
+         mdebug__output = fopen (env_value, "a");
+      }
+    if (! mdebug__output)
+      mdebug__output = stderr;
+  }
+
+  MDEBUG_PUSH_TIME ();
+  MDEBUG_PUSH_TIME ();
+  if (msymbol__init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize symbol module."));
+  if  (mplist__init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize plist module."));
+  if (mchar__init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize character module."));
+  if  (mchartable__init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize chartable module."));
+  if (mtext__init () < 0 || mtext__prop_init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize mtext module."));
+  if (mdatabase__init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize database module."));
+
+#if ENABLE_NLS
+  bindtextdomain ("m17n-lib", GETTEXTDIR);
+  bindtextdomain ("m17n-db", GETTEXTDIR);
+  bindtextdomain ("m17n-contrib", GETTEXTDIR);
+  bind_textdomain_codeset ("m17n-lib", "UTF-8");
+  bind_textdomain_codeset ("m17n-db", "UTF-8");
+  bind_textdomain_codeset ("m17n-contrib", "UTF-8");
+#endif
+
+ err:
+  MDEBUG_POP_TIME ();
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the core modules."));
+  MDEBUG_POP_TIME ();
+}
+
+void
+m17n_fini_core (void)
+{
+  int mdebug_flag = MDEBUG_FINI;
+
+  if (m17n__core_initialized == 0
+      || --m17n__core_initialized > 0)
+    return;
+
+  MDEBUG_PUSH_TIME ();
+  MDEBUG_PUSH_TIME ();
+  mchartable__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize chartable module."));
+  mtext__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize mtext module."));
+  msymbol__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize symbol module."));
+  mplist__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize plist module."));
+  /* We must call this after the aboves because it frees interval
+     pools.  */
+  mtext__prop_fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize textprop module."));
+  MDEBUG_POP_TIME ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the core modules."));
+  MDEBUG_POP_TIME ();
+  if (mdebug__flags[MDEBUG_FINI])
+    report_object_array ();
+  msymbol__free_table ();
+  if (mdebug__output != stderr)
+    fclose (mdebug__output);
+}
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+/*=*/
+
+/*** @addtogroup m17nIntro */
+
+/*** @{  */
+/*=*/
+
+/***en
+    @brief Report which part of the m17n library is initialized.
+
+    The m17n_status () function returns one of these values depending
+    on which part of the m17n library is initialized:
+
+       #M17N_NOT_INITIALIZED, #M17N_CORE_INITIALIZED,
+       #M17N_SHELL_INITIALIZED, #M17N_GUI_INITIALIZED  */
+
+/***ja
+    @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î¤É¤ÎÉôʬ¤¬½é´ü²½¤µ¤ì¤¿¤«Êó¹ð¤¹¤ë.
+
+    ´Ø¿ô m17n_status () ¤Ï 
+    m17n ¥é¥¤¥Ö¥é¥ê¤Î¤É¤ÎÉôʬ¤¬½é´ü²½¤µ¤ì¤¿¤«¤Ë±þ¤¸¤Æ¡¢°Ê²¼¤ÎÃͤΤ¤¤º¤ì¤«¤òÊÖ¤¹¡£
+
+       #M17N_NOT_INITIALIZED, #M17N_CORE_INITIALIZED,
+       #M17N_SHELL_INITIALIZED, #M17N_GUI_INITIALIZED  */
+
+enum M17NStatus
+m17n_status (void)
+{
+  return (m17n__gui_initialized ? M17N_GUI_INITIALIZED
+         : m17n__shell_initialized ? M17N_SHELL_INITIALIZED
+         : m17n__core_initialized ? M17N_CORE_INITIALIZED
+         : M17N_NOT_INITIALIZED);
+}
+
+/*** @} */
+
+/*=*/
+/***en
+    @addtogroup m17nObject
+    @brief Managed objects are objects managed by the reference count.
+
+    There are some types of m17n objects that are managed by their
+    reference count.  Those objects are called @e managed @e objects.
+    When created, the reference count of a managed object is
+    initialized to one.  The m17n_object_ref () function increments
+    the reference count of a managed object by one, and the
+    m17n_object_unref () function decrements by one.  A managed
+    object is automatically freed when its reference count becomes
+    zero.
+
+    A property whose key is a managing key can have only a managed
+    object as its value.  Some functions, for instance msymbol_put ()
+    and mplist_put (), pay special attention to such a property.
+
+    In addition to the predefined managed object types, users can
+    define their own managed object types.  See the documentation of
+    the m17n_object () for more details.  */
+/***ja
+    @addtogroup m17nObject
+    @brief ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤È¤Ï»²¾È¿ô¤Ë¤è¤Ã¤Æ´ÉÍý¤µ¤ì¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë.
+
+    m17n ¥ª¥Ö¥¸¥§¥¯¥È¤Î¤¢¤ë·¿¤Î¤â¤Î¤Ï¡¢»²¾È¿ô¤Ë¤è¤Ã¤Æ´ÉÍý¤µ¤ì¤Æ¤¤¤ë¡£
+    ¤½¤ì¤é¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ï @e ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È ¤È¸Æ¤Ð¤ì¤ë¡£À¸À®¤µ¤ì¤¿»þÅÀ¤Ç¤Î»²¾È¿ô¤Ï
+    1 ¤Ë½é´ü²½¤µ¤ì¤Æ¤¤¤ë¡£´Ø¿ô m17n_object_ref () ¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Î»²¾È¿ô¤ò
+    1 Áý¤ä¤·¡¢´Ø¿ôm17n_object_unref () ¤Ï 1 ¸º¤é¤¹¡£»²¾È¿ô¤¬
+    0 ¤Ë¤Ê¤Ã¤¿´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ï¼«Æ°Åª¤Ë²òÊü¤µ¤ì¤ë¡£
+
+    ¥­¡¼¤¬´ÉÍý¥­¡¼¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤Ï¡¢ÃͤȤ·¤Æ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤À¤±¤ò¼è¤ë¡£
+    ´Ø¿ô msymbol_put () ¤ä mplist_put () ¤Ê¤É¤Ï¤½¤ì¤é¤Î¥×¥í¥Ñ¥Æ¥£¤òÆÃÊÌ°·¤¤¤¹¤ë¡£
+
+    ÄêµÁºÑ¤ß´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¥¿¥¤¥×¤Î¾¤Ë¡¢¥æ¡¼¥¶¤ÏɬÍפʴÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¥¿¥¤¥×¤ò¼«Ê¬¤ÇÄêµÁ¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£¾ÜºÙ¤Ï
+    m17n_object () ¤ÎÀâÌÀ¤ò»²¾È¡£  */
+
+/*** @{  */
+/*=*/
+/***en
+    @brief Allocate a managed object.
+
+    The m17n_object () function allocates a new managed object of
+    $SIZE bytes and sets its reference count to 1.  $FREER is the
+    function that is used to free the object when the reference count
+    becomes 0.  If $FREER is NULL, the object is freed by the free ()
+    function.
+
+    The heading bytes of the allocated object is occupied by
+    #M17NObjectHead.  That area is reserved for the m17n library and
+    application programs should never touch it.
+
+    @return
+    This function returns a newly allocated object.
+
+    @errors
+    This function never fails.  */
+
+/***ja
+    @brief ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤ò³ä¤êÅö¤Æ¤ë.
+
+    ´Ø¿ô m17n_object () ¤Ï$SIZE ¥Ð¥¤¥È¤Î¿·¤·¤¤´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤ò³ä¤êÅö¤Æ¡¢¤½¤Î»²¾È¿ô¤ò
+    1 ¤È¤¹¤ë¡£ $FREER ¤Ï»²¾È¿ô¤¬ 0 
+    ¤Ë¤Ê¤Ã¤¿ºÝ¤Ë¤½¤Î¥ª¥Ö¥¸¥§¥¯¥È¤ò²òÊü¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë´Ø¿ô¤Ç¤¢¤ë¡£$FREER
+    ¤¬ NULL¤Ê¤é¤Ð¡¢¥ª¥Ö¥¸¥§¥¯¥È¤Ï´Ø¿ô free () ¤Ë¤è¤Ã¤Æ²òÊü¤µ¤ì¤ë¡£
+
+    ³ä¤êÅö¤Æ¤é¤ì¤¿¥ª¥Ö¥¸¥§¥¯¥ÈËÁƬ¤Î¥Ð¥¤¥È¤Ï¡¢#M17NObjectHead 
+    ¤¬Àê¤á¤ë¡£¤³¤ÎÎΰè¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤¬»ÈÍѤ¹¤ë¤Î¤Ç¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï¿¨¤ì¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¿·¤·¤¯³ä¤êÅö¤Æ¤é¤ì¤¿¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤¹¡£
+
+    @errors
+    ¤³¤Î´Ø¿ô¤Ï¼ºÇÔ¤·¤Ê¤¤¡£    */
+
+#if EXAMPLE_CODE
+typedef struct
+{
+  M17NObjectHead head;
+  int mem1;
+  char *mem2;
+} MYStruct;
+
+void
+my_freer (void *obj)
+{
+  free (((MYStruct *) obj)->mem2);
+  free (obj);
+}
+
+void
+my_func (MText *mt, MSymbol key, int num, char *str)
+{
+  MYStruct *st = m17n_object (sizeof (MYStruct), my_freer);
+
+  st->mem1 = num;
+  st->mem2 = strdup (str);
+  /* KEY must be a managing key.   */
+  mtext_put_prop (mt, 0, mtext_len (mt), key, st);
+  /* This sets the reference count of ST back to 1.  */
+  m17n_object_unref (st);
+}
+#endif
+
+void *
+m17n_object (int size, void (*freer) (void *))
+{
+  M17NObject *obj = malloc (size);
+
+  obj->ref_count = 1;
+  obj->ref_count_extended = 0;
+  obj->flag = 0;
+  obj->u.freer = freer;
+  return obj;
+}
+
+/*=*/
+
+/***en
+    @brief Increment the reference count of a managed object.
+
+    The m17n_object_ref () function increments the reference count of
+    the managed object pointed to by $OBJECT.
+
+    @return
+    This function returns the resulting reference count if it fits in
+    a 16-bit unsigned integer (i.e. less than 0x10000).  Otherwise, it
+    return -1.
+
+    @errors
+    This function never fails.  */
+/***ja
+    @brief ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Î»²¾È¿ô¤ò 1 Áý¤ä¤¹.
+
+    ´Ø¿ô m17n_object_ref () ¤Ï $OBJECT 
+    ¤Ç»Ø¤µ¤ì¤ë´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Î»²¾È¿ô¤ò 1 Áý¤ä¤¹¡£
+
+    @return 
+    ¤³¤Î´Ø¿ô¤Ï¡¢Áý¤ä¤·¤¿»²¾È¿ô¤¬ 16 ¥Ó¥Ã¥È¤ÎÉä¹æ̵¤·À°¿ôÃÍ(¤¹¤Ê¤ï¤Á 
+    0x10000 Ì¤Ëþ)¤Ë¤ª¤µ¤Þ¤ì¤Ð¡¢¤½¤ì¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤¹¡£
+
+    @errors
+    ¤³¤Î´Ø¿ô¤Ï¼ºÇÔ¤·¤Ê¤¤¡£    */
+
+int
+m17n_object_ref (void *object)
+{
+  M17NObject *obj = (M17NObject *) object;
+  M17NObjectRecord *record;
+  unsigned *count;
+
+  if (! obj->ref_count_extended)
+    {
+      if (++obj->ref_count)
+       return (int) obj->ref_count;
+      MSTRUCT_MALLOC (record, MERROR_OBJECT);
+      record->freer = obj->u.freer;
+      MLIST_INIT1 (record, counts, 1);
+      MLIST_APPEND1 (record, counts, 0, MERROR_OBJECT);
+      obj->u.record = record;
+      obj->ref_count_extended = 1;
+    }
+  else
+    record = obj->u.record;
+
+  count = record->counts;
+  while (*count == 0xFFFFFFFF)
+    *(count++) = 0;
+  (*count)++;
+  if (*count == 0xFFFFFFFF)
+    MLIST_APPEND1 (record, counts, 0, MERROR_OBJECT);
+  return -1;
+}
+
+/*=*/
+
+/***en
+    @brief Decrement the reference count of a managed object.
+
+    The m17n_object_unref () function decrements the reference count
+    of the managed object pointed to by $OBJECT.  When the reference
+    count becomes zero, the object is freed by its freer function.
+
+    @return
+    This function returns the resulting reference count if it fits in
+    a 16-bit unsigned integer (i.e. less than 0x10000).  Otherwise, it
+    returns -1.  Thus, the return value zero means that $OBJECT is
+    freed.
+
+    @errors
+    This function never fails.  */
+/***ja
+    @brief ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Î»²¾È¿ô¤ò 1 ¸º¤é¤¹.
+
+    ´Ø¿ô m17n_object_unref () ¤Ï $OBJECT ¤Ç»Ø¤µ¤ì¤ë´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Î»²¾È¿ô¤ò
+    1 ¸º¤é¤¹¡£»²¾È¿ô¤¬ 0 ¤Ë¤Ê¤ì¤Ð¡¢¥ª¥Ö¥¸¥§¥¯¥È¤Ï²òÊü´Ø¿ô¤Ë¤è¤Ã¤Æ²òÊü¤µ¤ì¤ë¡£
+
+    @return 
+    ¤³¤Î´Ø¿ô¤Ï¡¢¸º¤é¤·¤¿»²¾È¿ô¤¬ 16 ¥Ó¥Ã¥È¤ÎÉä¹æ̵¤·À°¿ôÃÍ(¤¹¤Ê¤ï¤Á 
+    0x10000 Ì¤Ëþ)¤Ë¤ª¤µ¤Þ¤ì¤Ð¡¢¤½¤ì¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 
+    ¤òÊÖ¤¹¡£¤Ä¤Þ¤ê¡¢0 ¤¬Ê֤äÆÍ褿¾ì¹ç¤Ï$OBJECT ¤Ï²òÊü¤µ¤ì¤Æ¤¤¤ë¡£
+
+    @errors
+    ¤³¤Î´Ø¿ô¤Ï¼ºÇÔ¤·¤Ê¤¤¡£    */
+int
+m17n_object_unref (void *object)
+{
+  M17NObject *obj = (M17NObject *) object;
+  M17NObjectRecord *record;
+  unsigned *count;
+
+  if (! obj->ref_count_extended)
+    {
+      if (! --obj->ref_count)
+       {
+         if (obj->u.freer)
+           (obj->u.freer) (object);
+         else
+           free (object);
+         return 0;
+       }
+      return (int) obj->ref_count;
+    }
+
+  record = obj->u.record;
+  count = record->counts;
+  while (! *count)
+    *(count++) = 0xFFFFFFFF;
+  (*count)--;
+  if (! record->counts[0])
+    {
+      obj->ref_count_extended = 0;
+      obj->ref_count--;
+      obj->u.freer = record->freer;
+      MLIST_FREE1 (record, counts);
+      free (record);
+    }
+  return -1;
+}
+
+/*=*/
+
+/*** @} */
+
+/***en
+    @addtogroup m17nError Error Handling
+    @brief Error handling of the m17n library.
+
+    There are two types of errors that may happen in a function of
+    the m17n library.
+
+    The first type is argument errors.  When a library function is
+    called with invalid arguments, it returns a value that indicates
+    error and at the same time sets the external variable #merror_code
+    to a non-zero integer.
+
+    The second type is memory allocation errors.  When the required
+    amount of memory is not available on the system, m17n library
+    functions call a function pointed to by the external variable @c
+    m17n_memory_full_handler.  The default value of the variable is a
+    pointer to the default_error_handle () function, which just calls
+    <tt> exit ()</tt>.  */
+
+/***ja
+    @addtogroup m17nError ¥¨¥é¡¼½èÍý
+    @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼½èÍý.
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Î´Ø¿ô¤Ç¤Ï¡¢£²¤Ä¤Î¼ïÎà¤Î¥¨¥é¡¼¤¬µ¯¤³¤êÆÀ¤ë¡£
+
+    °ì¤Ä¤Ï°ú¿ô¤Î¥¨¥é¡¼¤Ç¤¢¤ë¡£
+    ¥é¥¤¥Ö¥é¥ê¤Î´Ø¿ô¤¬ÂÅÅö¤Ç¤Ê¤¤°ú¿ô¤È¤È¤â¤Ë¸Æ¤Ð¤ì¤¿¾ì¹ç¡¢¤½¤Î´Ø¿ô¤Ï¥¨¥é¡¼¤ò°ÕÌ£¤¹¤ëÃͤòÊÖ¤·¡¢Æ±»þ¤Ë³°ÉôÊÑ¿ô 
+    #merror_code ¤Ë¥¼¥í¤Ç¤Ê¤¤À°¿ô¤ò¥»¥Ã¥È¤¹¤ë¡£
+
+    ¤â¤¦°ì¤Ä¤Î¼ïÎà¤Ï¥á¥â¥ê³äÅö¤Æ¥¨¥é¡¼¤Ç¤¢¤ë¡£
+    ¥·¥¹¥Æ¥à¤¬É¬ÍפÊÎ̤Υá¥â¥ê¤ò³äÅö¤Æ¤ë¤³¤È¤¬¤Ç¤­¤Ê¤¤¾ì¹ç¡¢¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ï³°ÉôÊÑ¿ô 
+    @c m17n_memory_full_handler ¤¬»Ø¤¹´Ø¿ô¤ò¸Æ¤Ö¡£¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢´Ø¿ô 
+    default_error_handle () ¤ò»Ø¤·¤Æ¤ª¤ê¡¢¤³¤Î´Ø¿ô¤Ïñ¤Ë <tt>exit
+    ()</tt> ¤ò¸Æ¤Ö¡£
+*/
+
+/*** @{ */
+
+/*=*/
+
+/***en 
+    @brief External variable to hold error code of the m17n library.
+
+    The external variable #merror_code holds an error code of the
+    m17n library.  When a library function is called with an invalid
+    argument, it sets this variable to one of @c enum #MErrorCode.
+
+    This variable initially has the value 0.  */
+
+/***ja 
+    @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼¥³¡¼¥É¤òÊÝ»ý¤¹¤ë³°ÉôÊÑ¿ô.
+
+    ³°ÉôÊÑ¿ô #merror_code ¤Ï¡¢m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼¥³¡¼¥É¤òÊÝ»ý¤¹¤ë¡£
+    ¥é¥¤¥Ö¥é¥ê´Ø¿ô¤¬ÂÅÅö¤Ç¤Ê¤¤°ú¿ô¤È¤È¤â¤Ë¸Æ¤Ð¤ì¤¿ºÝ¤Ë¤Ï¡¢¤³¤ÎÊÑ¿ô¤ò 
+    @c enum #MErrorCode ¤Î°ì¤Ä¤Ë¥»¥Ã¥È¤¹¤ë¡£
+
+    ¤³¤ÎÊÑ¿ô¤Î½é´üÃͤϠ0 ¤Ç¤¢¤ë¡£  */
+
+int merror_code;
+
+/*=*/
+
+/***en 
+    @brief Memory allocation error handler.
+
+    The external variable #m17n_memory_full_handler holds a pointer
+    to the function to call when a library function failed to allocate
+    memory.  $ERR is one of @c enum #MErrorCode indicating in which
+    function the error occurred.
+
+    This variable initially points a function that simply calls the
+    <tt>exit </tt>() function with $ERR as an argument.
+
+    An application program that needs a different error handling can
+    change this variable to point a proper function.  */
+
+/***ja 
+    @brief ¥á¥â¥ê³äÅö¤Æ¥¨¥é¡¼¥Ï¥ó¥É¥é.
+
+    ÊÑ¿ô #m17n_memory_full_handler 
+    ¤Ï¡¢¥é¥¤¥Ö¥é¥ê´Ø¿ô¤¬¥á¥â¥ê³äÅö¤Æ¤Ë¼ºÇÔ¤·¤¿ºÝ¤Ë¸Æ¤Ö¤Ù¤­´Ø¿ô¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    $ERR ¤Ï @c enum #MErrorCode 
+    ¤Î¤¦¤Á¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ê¡¢¤É¤Î¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ç¥¨¥é¡¼¤¬µ¯¤Ã¤¿¤«¤ò¼¨¤¹¡£
+
+    @anchor test
+
+    ½é´üÀßÄê¤Ç¤Ï¡¢¤³¤ÎÊÑ¿ô¤Ïñ¤Ë <tt>exit ()</tt> ¤ò $ERR 
+    ¤ò°ú¿ô¤È¤·¤Æ¸Æ¤Ö´Ø¿ô¤ò»Ø¤·¤Æ¤¤¤ë¡£
+
+    ¤³¤ì¤È¤Ï°Û¤Ê¤ë¥¨¥é¡¼½èÍý¤òɬÍפȤ¹¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¡¢¤³¤ÎÊÑ¿ô¤òŬÅö¤Ê´Ø¿ô¤ËÀßÄꤹ¤ë¤³¤È¤Ç¡¢ÌÜŪ¤òãÀ®¤Ç¤­¤ë¡£  */
+
+void (*m17n_memory_full_handler) (enum MErrorCode err);
+
+/*** @} */
+
+/*=*/
+
+/***en
+    @addtogroup m17nDebug
+    @brief Support for m17n library users to debug their programs.
+
+    The m17n library provides the following facilities to support the
+    library users to debug their programs.
+
+    <ul>
+
+    <li> Environment variables to control printing of various
+    information.
+
+    <ul>
+
+    <li> MDEBUG_INIT -- If set to 1, print information about the
+    library initialization on the call of M17N_INIT ().
+
+    <li> MDEBUG_FINI -- If set to 1, print counts of objects that are
+    not yet freed on the call of M17N_FINI ().
+
+    <li> MDEBUG_CHARSET -- If set to 1, print information about
+    charsets being loaded from the m17n database.
+
+    <li> MDEBUG_CODING -- If set to 1, print information about coding
+    systems being loaded from the m17n database.
+
+    <li> MDEBUG_DATABASE -- If set to 1, print information about
+    data being loaded from the m17n database.
+
+    <li> MDEBUG_FONT -- If set to 1, print information about fonts
+    being selected and opened.
+
+    <li> MDEBUG_FLT -- If set to 1, 2, or 3, print information about
+    which command of Font Layout Table are being executed.  The bigger
+    number prints the more detailed information.
+
+    <li> MDEBUG_INPUT -- If set to 1, print information about how an
+    input method is running.
+
+    <li> MDEBUG_ALL -- Setting this variable to 1 is equivalent to
+    setting all the above variables to 1.
+
+    </ul>
+
+    <li> Functions to print various objects in a human readable way.
+    See the documentation of mdebug_dump_XXXX () functions.
+
+    <li> The hook function called on an error.  See the documentation
+    of mdebug_hook ().
+
+    </ul>
+*/
+/***ja
+    @addtogroup m17nDebug
+    @brief m17n ¥é¥¤¥Ö¥é¥ê¥æ¡¼¥¶¤Î¤¿¤á¤Î¥×¥í¥°¥é¥à¥Ç¥Ð¥Ã¥°¥µ¥Ý¡¼¥È.
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï¡¢¤½¤Î¥æ¡¼¥¶¤¬¼«Ê¬¤Î¥×¥í¥°¥é¥à¤ò¥Ç¥Ð¥Ã¥°¤¹¤ë¤¿¤á¤Ë¡¢°Ê²¼¤Îµ¡Ç½¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¡£
+
+    <ul>
+
+    <li> ¤µ¤Þ¤¶¤Þ¤Ê¾ðÊó¤Î¥×¥ê¥ó¥È¤òÀ©¸æ¤¹¤ë´Ä¶­ÊÑ¿ô¡£
+
+    <ul>
+
+    <li> MDEBUG_INIT -- 1 ¤Ê¤é¤Ð¡¢M17N_INIT () 
+    ¤¬¸Æ¤Ð¤ì¤¿»þÅÀ¤Ç¡¢¥é¥¤¥Ö¥é¥ê¤Î½é´ü²½¤Ë´Ø¤¹¤ë¾ðÊó¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
+
+    <li> MDEBUG_FINI -- 1 ¤Ê¤é¤Ð¡¢M17N_FINI () 
+    ¤¬¸Æ¤Ð¤ì¤¿»þÅÀ¤Ç¡¢¤Þ¤À²òÊü¤µ¤ì¤Æ¤¤¤Ê¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î»²¾È¿ô¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
+
+    <li> MDEBUG_CHARSET -- 1 ¤Ê¤é¤Ð¡¢m17n
+    ¥Ç¡¼¥¿¥Ù¡¼¥¹¤«¤é¥í¡¼¥É¤µ¤ì¤¿Ê¸»ú¥»¥Ã¥È¤Ë¤Ä¤¤¤Æ¤Î¾ðÊó¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
+
+    <li> MDEBUG_CODING --  1 ¤Ê¤é¤Ð¡¢m17n 
+    ¥Ç¡¼¥¿¥Ù¡¼¥¹¤«¤é¥í¡¼¥É¤µ¤ì¤¿¥³¡¼¥É·Ï¤Ë¤Ä¤¤¤Æ¤Î¾ðÊó¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
+
+    <li> MDEBUG_DATABASE -- 1 ¤Ê¤é¤Ð¡¢m17n
+    ¥Ç¡¼¥¿¥Ù¡¼¥¹¤«¤é¥í¡¼¥É¤µ¤ì¤¿¥Ç¡¼¥¿¤Ë¤Ä¤¤¤Æ¤Î¾ðÊó¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
+
+    <li> MDEBUG_FONT -- 1 ¤Ê¤é¤Ð¡¢ÁªÂò¤µ¤ì¤Æ¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥©¥ó¥È¤Ë¤Ä
+    ¤¤¤Æ¤Î¾ðÊó¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
+
+    <li> MDEBUG_FLT -- 1¡¢2¡¢¤â¤·¤¯¤Ï 3 ¤Ê¤é¤Ð¡¢Font Layout Table ¤Î¤É
+    ¤Î¥³¥Þ¥ó¥É¤¬¼Â¹ÔÃ椫¤Ë¤Ä¤¤¤Æ¤Î¤ò¥×¥ê¥ó¥È¤¹¤ë¡£¤è¤êÂ礭¤ÊÃÍÄø¤è¤ê¾Ü
+    ¤·¤¤¾ðÊó¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
+
+    <li> MDEBUG_INPUT -- 1 ¤Ê¤é¤Ð¡¢¼Â¹ÔÃæ¤ÎÆþÎϥ᥽¥Ã¥É¤Î¾õÂÖ¤ËÉÕ¤¤¤Æ¤Î
+    ¾ðÊó¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
+
+    <li> MDEBUG_ALL -- 1 ¤Ê¤é¤Ð¡¢¾åµ­¤¹¤Ù¤Æ¤ÎÊÑ¿ô¤ò 1 
+    ¤Ë¤·¤¿¤Î¤ÈƱ¤¸¸ú²Ì¤ò»ý¤Ä¡£
+
+    </ul>
+
+    <li> ¼ï¡¹¤Î¥ª¥Ö¥¸¥§¥¯¥È¤ò¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç¥×¥ê¥ó¥È¤¹¤ë´Ø¿ô¡£¾ÜºÙ¤Ï´Ø¿ô
+    mdebug_dump_XXXX () ¤ÎÀâÌÀ»²¾È¡£
+
+    <li> ¥¨¥é¡¼È¯À¸»þ¤Ë¸Æ¤Ð¤ì¤ë¥Õ¥Ã¥¯´Ø¿ô¡£mdebug_hook () ¤ÎÀâÌÀ»²¾È¡£
+
+    </ul>
+*/
+
+/*=*/
+/*** @{ */
+/*=*/
+
+/***en
+    @brief Hook function called on an error.
+
+    The mdebug_hook () function is called when an error happens.  It
+    returns -1 without doing anything.  It is useful to set a break
+    point on this function in a debugger.  */ 
+/***ja
+    @brief ¥¨¥é¡¼¤ÎºÝ¤Ë¸Æ¤Ð¤ì¤ë¥Õ¥Ã¥¯´Ø¿ô.
+
+    ´Ø¿ô mdebug_hook () ¤Ï¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿ºÝ¤Ë¸Æ¤Ð¤ì¡¢²¿¤â¤»¤º¤Ë-1 
+    ¤òÊÖ¤¹¡£¥Ç¥Ð¥Ã¥¬Æâ¤Ç¥Ö¥ì¡¼¥¯¥Ý¥¤¥ó¥È¤òÀßÄꤹ¤ë¤¿¤á¤ËÍѤ¤¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
+    */ 
+
+int
+mdebug_hook ()
+{
+  return -1;
+}
+
+/*=*/
+
+/*** @} */ 
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/m17n-core.h b/src/m17n-core.h
new file mode 100644 (file)
index 0000000..da5cdf2
--- /dev/null
@@ -0,0 +1,855 @@
+/* m17n-core.h -- header file for the CORE API of the m17n library.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_CORE_H_
+#define _M17N_CORE_H_
+
+#ifdef __cplusplus
+#define M17N_BEGIN_HEADER extern "C" {
+#define M17N_END_HEADER }
+#else
+#define M17N_BEGIN_HEADER      /* do nothing */
+#define M17N_END_HEADER                /* do nothing */
+#endif
+
+M17N_BEGIN_HEADER
+
+/*
+ * Header file for m17n library.
+ */
+
+/* (C1) Introduction */
+
+/***en @defgroup m17nIntro Introduction  */
+/***ja @defgroup m17nIntro ¤Ï¤¸¤á¤Ë  */
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+
+#define M17NLIB_MAJOR_VERSION 1
+#define M17NLIB_MINOR_VERSION 6
+#define M17NLIB_PATCH_LEVEL 1
+#define M17NLIB_VERSION_NAME "1.6.1"
+
+extern void m17n_init_core (void);
+#define M17N_INIT() m17n_init_core ()
+extern void m17n_fini_core (void);
+#define M17N_FINI() m17n_fini_core ()
+
+extern int merror_code;
+
+#endif
+
+/*=*/
+
+/*** @ingroup m17nIntro */
+/***en
+    @brief Enumeration for the status of the m17n library.
+
+    The enum #M17NStatus is used as a return value of the function
+    m17n_status ().  */
+
+/***ja
+    @brief  m17n ¥é¥¤¥Ö¥é¥ê¤Î¾õÂÖ¤ò¼¨¤¹Îóµó·¿.
+
+    Îóµó·¿ #M17NStatus ¤Ï´Ø¿ô m17n_status () ¤ÎÌá¤êÃͤȤ·¤ÆÍѤ¤¤é¤ì¤ë¡£ */
+
+enum M17NStatus
+  {
+    /***en No modules is initialized, and all modules are finalized.  */
+    M17N_NOT_INITIALIZED, 
+    /***en Only the modules in CORE API are initialized.  */
+    M17N_CORE_INITIALIZED,
+    /***en Only the modules in CORE and SHELL APIs are initialized.  */
+    M17N_SHELL_INITIALIZED, 
+    /***en All modules are initialized.  */
+    M17N_GUI_INITIALIZED
+  };
+
+/*=*/
+
+extern enum M17NStatus m17n_status (void);
+
+/***en @defgroup m17nCore CORE API
+    @brief API provided by libm17n-core.so */
+/***ja @defgroup m17nCore ¥³¥¢ API
+    @brief libm17n-core.so ¤¬Ä󶡤¹¤ë API */
+/*=*/
+/*** @ingroup m17nCore */
+/***en @defgroup m17nObject Managed Object
+    @brief Objects managed by the reference count */
+/***ja @defgroup m17nObject ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È
+    @brief »²¾È²ó¿ô¤Ç´ÉÍý¤µ¤ì¤ë¥ª¥Ö¥¸¥§¥¯¥È */
+/*=*/
+
+/*** @ingroup m17nObject  */
+/***en
+    @brief The first member of a managed object.
+
+    When an application program defines a new structure for managed
+    objects, its first member must be of the type @c struct
+    #M17NObjectHead.  Its contents are used by the m17n library, and
+    application programs should never touch them.  */
+/***ja
+    @brief ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤ÎºÇ½é¤Î¥á¥ó¥Ð.
+
+    ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤¬¿·¤·¤¤¹½Â¤ÂΤò´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤È¤·¤ÆÄêµÁ¤¹¤ëºÝ¤Ë¤Ï¡¢ºÇ½é¤Î¥á¥ó¥Ð¤Ï 
+    @c #M17NObjectHead ¹½Â¤Âη¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+    @c #M17NObjectHead ¤ÎÆâÍƤϠm17n 
+    ¥é¥¤¥Ö¥é¥ê¤¬»ÈÍѤ¹¤ë¤Î¤Ç¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï¿¨¤ì¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£    */
+
+typedef struct
+{
+  /*** Hidden from applications.  */
+  void *filler[2];
+} M17NObjectHead;
+
+/*=*/
+
+/* Return a newly allocated managed object.  */
+extern void *m17n_object (int size, void (*freer) (void *));
+
+/* Increment the reference count of managed object OBJECT.  */
+extern int m17n_object_ref (void *object);
+
+/* Decrement the reference count of managed object OBJECT.  */
+extern int m17n_object_unref (void *object);
+
+/*** @ingroup m17nCore */
+/***en
+    @brief Generic function type.
+
+    #M17NFunc is a generic function type for setting a function
+    pointer as a value of #MSymbol property or #MPlist.  */
+
+/***ja
+    @brief ÈÆ´Ø¿ô·¿.
+
+    #M17NFunc ¤ÏÈÆ´Ø¿ô·¿¤Ç¤¢¤ê¡¢´Ø¿ô¥Ý¥¤¥ó¥¿¤ò #MSymbol ¥×¥í¥Ñ¥Æ¥£¤ä
+    #MPlist ¤ÎÃͤȤ·¤ÆÀßÄꤹ¤ëºÝÍѤ¤¤ë¡£  */
+
+
+/***
+    @seealso
+    msymbol_put_func (), msymbol_get_func (),
+    mplist_put_func (), mplist_get_func ().  */
+
+typedef void (*M17NFunc) (void);
+
+/*=*/
+
+/*** @ingroup m17nCore */
+/***en
+    @brief Wrapper for a generic function type.
+
+    The macro M17N_FUNC () casts a function to the type #M17NFunc.  */
+
+/***ja
+    @brief ÈÆ´Ø¿ô·¿¤Ø¤Î¥é¥Ã¥Ñ.
+
+    ¥Þ¥¯¥í M17N_FUNC () ¤Ï´Ø¿ô¤ò #M17NFunc ·¿¤Ø¥­¥ã¥¹¥È¤¹¤ë¡£  */
+
+
+#define M17N_FUNC(func) ((M17NFunc) (func))
+
+/*=*/
+
+/* (C2) Symbol handling */
+
+/*** @ingroup m17nCore */
+/***en @defgroup m17nSymbol Symbol  */
+/***ja @defgroup m17nSymbol ¥·¥ó¥Ü¥ë */
+/*=*/
+
+/***
+    @ingroup m17nSymbol */
+/***en
+    @brief Type of symbols.
+
+    The type #MSymbol is for a @e symbol object.  Its internal
+    structure is concealed from application programs.  */
+
+/***ja
+    @brief ¥·¥ó¥Ü¥ë¤Î·¿Àë¸À.
+
+    #MSymbol ¤Ï @e ¥·¥ó¥Ü¥ë (symbol) ¥ª¥Ö¥¸¥§¥¯¥È¤Î·¿¤Ç¤¢¤ë¡£
+    ÆâÉô¹½Â¤¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤Ï¸«¤¨¤Ê¤¤¡£  */
+
+typedef struct MSymbolStruct *MSymbol;
+
+/*=*/
+
+/* Predefined symbols. */ 
+extern MSymbol Mnil;
+extern MSymbol Mt;
+extern MSymbol Mstring;
+extern MSymbol Msymbol;
+extern MSymbol Mtext;
+extern MSymbol Mcharset;
+
+/* Return a symbol of name NAME.  */
+extern MSymbol msymbol (const char *name);
+
+/* Return a managing key of name NAME.  */
+extern MSymbol msymbol_as_managing_key (const char *name);
+
+/* Check if SYMBOL is a managing key.  */
+extern int msymbol_is_managing_key (MSymbol symbol);
+
+/* Return a symbol of name NAME if it already exists.  */
+extern MSymbol msymbol_exist (const char *name);
+
+/* Return the name of SYMBOL.  */
+extern char *msymbol_name (MSymbol symbol);
+
+/* Give SYMBOL KEY property with value VALUE.  */
+extern int msymbol_put (MSymbol symbol, MSymbol key, void *val);
+
+/*** Return KEY property value of SYMBOL.  */
+extern void *msymbol_get (MSymbol symbol, MSymbol key);
+
+extern int msymbol_put_func (MSymbol symbol, MSymbol key, M17NFunc func);
+
+extern M17NFunc msymbol_get_func (MSymbol symbol, MSymbol key);
+
+/* 
+ *  (2-1) Property List
+ */
+/*=*/
+/*** @ingroup m17nCore */
+/***en @defgroup m17nPlist Property List */
+/***ja @defgroup m17nPlist ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È */
+/*=*/
+
+/***
+    @ingroup m17nPlist */ 
+/***en
+    @brief Type of property list objects.
+
+    The type #MPlist is for a @e property @e list object.  Its internal
+    structure is concealed from application programs.  */
+
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¡¦¥ª¥Ö¥¸¥§¥¯¥È¤Î·¿Àë¸À.
+
+    #MPlist ¤Ï @e ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È (Property list) ¥ª¥Ö¥¸¥§¥¯¥È¤Î·¿¤Ç¤¢¤ë¡£
+    ÆâÉô¹½Â¤¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤Ï¸«¤¨¤Ê¤¤¡£  */
+
+typedef struct MPlist MPlist;
+
+/*=*/
+
+extern MSymbol Mplist, Minteger;
+
+extern MPlist *mplist ();
+
+extern MPlist *mplist_copy (MPlist *plist);
+
+extern MPlist *mplist_add (MPlist *plist, MSymbol key, void *val);
+
+extern MPlist *mplist_push (MPlist *plist, MSymbol key, void *val);
+
+extern void *mplist_pop (MPlist *plist);
+
+extern MPlist *mplist_put (MPlist *plist, MSymbol key, void *val);
+
+extern void *mplist_get (MPlist *plist, MSymbol key);
+
+extern MPlist *mplist_put_func (MPlist *plist, MSymbol key, M17NFunc func);
+
+extern M17NFunc mplist_get_func (MPlist *plist, MSymbol key);
+
+extern MPlist *mplist_find_by_key (MPlist *plist, MSymbol key);
+
+extern MPlist *mplist_find_by_value (MPlist *plist, void *val);
+
+extern MPlist *mplist_next (MPlist *plist);
+
+extern MPlist *mplist_set (MPlist *plist, MSymbol key, void *val);
+
+extern int mplist_length (MPlist *plist);
+
+extern MSymbol mplist_key (MPlist *plist);
+
+extern void *mplist_value (MPlist *plist);
+
+/* (S1) Characters */
+
+/*=*/
+/*** @ingroup m17nCore */
+/***en @defgroup m17nCharacter Character */
+/***ja @defgroup m17nCharacter Ê¸»ú */
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+#define MCHAR_MAX 0x3FFFFF
+/*#define MCHAR_MAX 0x7FFFFFFF*/
+#endif
+
+extern MSymbol Mscript;
+extern MSymbol Mname;
+extern MSymbol Mcategory;
+extern MSymbol Mcombining_class;
+extern MSymbol Mbidi_category;
+extern MSymbol Msimple_case_folding;
+extern MSymbol Mcomplicated_case_folding;
+extern MSymbol Mcased, Msoft_dotted, Mcase_mapping;
+extern MSymbol Mblock;
+
+extern MSymbol mchar_define_property (const char *name, MSymbol type);
+
+extern void *mchar_get_prop (int c, MSymbol key);
+
+extern int mchar_put_prop (int c, MSymbol key, void *val);
+
+/* (C3) Handling chartable */
+
+/*** @ingroup m17nCore */
+/***en @defgroup m17nChartable Chartable */
+/***ja @defgroup m17nChartable Ê¸»ú¥Æ¡¼¥Ö¥ë */
+/*=*/
+extern MSymbol Mchar_table;
+
+/***
+    @ingroup m17nChartable */
+/***en
+    @brief Type of chartables.
+
+    The type #MCharTable is for a @e chartable objects.  Its
+    internal structure is concealed from application programs.  */
+
+/***ja
+    @brief Ê¸»ú¥Æ¡¼¥Ö¥ë¤Î·¿Àë¸À.
+
+    #MCharTable ¤Ï @e Ê¸»ú¥Æ¡¼¥Ö¥ë (chartable) ¥ª¥Ö¥¸¥§¥¯¥È¤Î·¿¤Ç¤¢¤ë¡£
+    ÆâÉô¹½Â¤¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤Ï¸«¤¨¤Ê¤¤¡£  */
+
+typedef struct MCharTable MCharTable;
+/*=*/
+
+extern MCharTable *mchartable (MSymbol key, void *default_value);
+
+extern int mchartable_min_char (MCharTable *table);
+
+extern int mchartable_max_char (MCharTable *table);
+
+extern void *mchartable_lookup (MCharTable *table, int c);
+
+extern int mchartable_set (MCharTable *table, int c, void *val);
+
+extern int mchartable_set_range (MCharTable *table, int from, int to,
+                                void *val);
+
+extern int mchartable_map (MCharTable *table, void *ignore,
+                          void (*func) (int, int, void *, void *), 
+                          void *func_arg);
+
+extern void mchartable_range (MCharTable *table, int *from, int *to);
+
+extern MCharTable *mchar_get_prop_table (MSymbol key, MSymbol *type);
+
+/*
+ *  (5) Handling M-text.
+ *     "M" of M-text stands for:
+ *     o Multilingual
+ *     o Metamorphic
+ *     o More than string
+ */
+
+/*** @ingroup m17nCore */
+/***en @defgroup m17nMtext M-text */
+/***ja @defgroup m17nMtext M-text */
+/*=*/
+
+/*
+ * (5-1) M-text basics
+ */
+/*=*/
+/*** @ingroup m17nMtext */
+/***en
+    @brief Type of @e M-texts.
+
+    The type #MText is for an @e M-text object.  Its internal
+    structure is concealed from application programs.  */
+
+/***ja
+    @brief @e MText ¤Î·¿Àë¸À.
+
+    #Mtext ¤Ï @e M-text ¥ª¥Ö¥¸¥§¥¯¥È¤Î·¿¤Ç¤¢¤ë¡£
+    ÆâÉô¹½Â¤¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤Ï¸«¤¨¤Ê¤¤¡£ 
+
+    @latexonly \IPAlabel{MText} @endlatexonly
+    @latexonly \IPAlabel{MText->MPlist} @endlatexonly  */
+
+typedef struct MText MText;
+
+/*=*/
+
+/*** @ingroup m17nMtext */
+/***en
+    @brief Enumeration for specifying the format of an M-text.
+
+    The enum #MTextFormat is used as an argument of the
+    mtext_from_data () function to specify the format of data from
+    which an M-text is created.  */
+
+/***ja
+    @brief M-text ¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤ò»ØÄꤹ¤ëÎóµó·¿.
+
+    Îóµó·¿ #MTextFormat ¤Ï´Ø¿ô
+    mtext_from_data () ¤Î°ú¿ô¤È¤·¤ÆÍѤ¤¤é¤ì¡¢
+    M-text ¤òÀ¸À®¤¹¤ë¸µ¤È¤Ê¤ë¥Ç¡¼¥¿¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤ò»ØÄꤹ¤ë¡£  */
+
+enum MTextFormat
+  {
+    /*** US-ASCII encoding */
+    MTEXT_FORMAT_US_ASCII,
+    /*** UTF-8 encoding */
+    MTEXT_FORMAT_UTF_8,
+    /*** UTF-16LE encoding  */
+    MTEXT_FORMAT_UTF_16LE,
+    /*** UTF-16BE encoding  */
+    MTEXT_FORMAT_UTF_16BE,
+    /*** UTF-32LE encoding  */
+    MTEXT_FORMAT_UTF_32LE,
+    /*** UTF-32BE encoding  */
+    MTEXT_FORMAT_UTF_32BE,
+    MTEXT_FORMAT_MAX
+  };
+/*=*/
+
+extern MText *mtext ();
+
+extern void *mtext_data (MText *mt, enum MTextFormat *fmt, int *nunits,
+                        int *pos_idx, int *unit_idx);
+
+/*=*/
+
+/***en @name Variables: Default Endian of UTF-16 and UTF-32 */
+/***ja @name ÊÑ¿ô: UTF-16 ¤È UTF-32 ¤Î¥Ç¥Õ¥©¥ë¥È¤Î¥¨¥ó¥Ç¥£¥¢¥ó */
+/*** @{ */
+/*=*/
+
+/*** @ingroup m17nMtext */
+/***en
+    @brief Variable of value MTEXT_FORMAT_UTF_16LE or MTEXT_FORMAT_UTF_16BE.
+
+    The global variable #MTEXT_FORMAT_UTF_16 is initialized to
+    #MTEXT_FORMAT_UTF_16LE on a "Little Endian" system (storing words
+    with the least significant byte first), and to
+    #MTEXT_FORMAT_UTF_16BE on a "Big Endian" system (storing words
+    with the most significant byte first).  */
+
+/***ja
+    @brief Ãͤ¬ MTEXT_FORMAT_UTF_16LE ¤« MTEXT_FORMAT_UTF_16BE ¤Ç¤¢¤ëÊÑ¿ô
+
+    Âç°èÊÑ¿ô #MTEXT_FORMAT_UTF_16 ¤Ï¥ê¥È¥ë¡¦¥¨¥ó¥Ç¥£¥¢¥ó¡¦¥·¥¹¥Æ¥à
+    ¡Ê¥ï¡¼¥É¤ò LSB (Least Significant Byte) ¤òÀè¤Ë¤·¤Æ³ÊǼ¡Ë¾å¤Ç¤Ï
+    #MTEXT_FORMAT_UTF_16LE ¤Ë½é´ü²½¤µ¤ì¡¢¥Ó¥Ã¥°¡¦¥¨¥ó¥Ç¥£¥¢¥ó¡¦¥·¥¹¥Æ¥à
+    ¡Ê¥ï¡¼¥É¤ò MSB (Most Significant Byte) ¤òÀè¤Ë¤·¤Æ³ÊǼ¡Ë¾å¤Ç¤Ï
+    #MTEXT_FORMAT_UTF_16BE ¤Ë½é´ü²½¤µ¤ì¤ë¡£  */
+
+/***
+    @seealso
+    mtext_from_data ()  */
+
+extern const enum MTextFormat MTEXT_FORMAT_UTF_16;
+/*=*/
+
+/*** @ingroup m17nMtext */
+/***en
+    @brief Variable of value MTEXT_FORMAT_UTF_32LE or MTEXT_FORMAT_UTF_32BE.
+
+    The global variable #MTEXT_FORMAT_UTF_32 is initialized to
+    #MTEXT_FORMAT_UTF_32LE on a "Little Endian" system (storing words
+    with the least significant byte first), and to
+    #MTEXT_FORMAT_UTF_32BE on a "Big Endian" system (storing
+    words with the most significant byte first).  */
+
+/***ja
+    @brief Ãͤ¬ MTEXT_FORMAT_UTF_32LE ¤« MTEXT_FORMAT_UTF_32BE ¤Ç¤¢¤ëÊÑ¿ô
+
+    Âç°èÊÑ¿ô #MTEXT_FORMAT_UTF_32 ¤Ï¥ê¥È¥ë¡¦¥¨¥ó¥Ç¥£¥¢¥ó¡¦¥·¥¹¥Æ¥à
+    ¡Ê¥ï¡¼¥É¤ò LSB (Least Significant Byte) ¤òÀè¤Ë¤·¤Æ³ÊǼ¡Ë¾å¤Ç¤Ï
+    #MTEXT_FORMAT_UTF_32LE ¤Ë½é´ü²½¤µ¤ì¡¢¥Ó¥Ã¥°¡¦¥¨¥ó¥Ç¥£¥¢¥ó¡¦¥·¥¹¥Æ¥à
+    ¡Ê¥ï¡¼¥É¤ò MSB (Most Significant Byte) ¤òÀè¤Ë¤·¤Æ³ÊǼ¡Ë¾å¤Ç¤Ï
+    #MTEXT_FORMAT_UTF_32BE ¤Ë½é´ü²½¤µ¤ì¤ë¡£  */
+
+/***
+    @seealso
+    mtext_from_data ()  */
+
+extern const int MTEXT_FORMAT_UTF_32;
+
+/*=*/
+/*** @} */
+/*=*/
+
+extern MText *mtext_from_data (const void *data, int nitems,
+                              enum MTextFormat format);
+
+/*=*/
+/*** @} */
+
+extern MSymbol Mlanguage;
+
+/*
+ *  (5-2) Functions to manipulate M-texts.  They correspond to string
+ *   manipulating functions in libc.
+ *   In the following functions, mtext_XXX() corresponds to strXXX().
+ */
+
+extern int mtext_len (MText *mt);
+
+extern int mtext_ref_char (MText *mt, int pos);
+
+extern int mtext_set_char (MText *mt, int pos, int c);
+
+extern MText *mtext_copy (MText *mt1, int pos, MText *mt2, int from, int to);
+
+extern int mtext_compare (MText *mt1, int from1, int to1,
+                         MText *mt2, int from2, int to2);
+
+extern int mtext_case_compare (MText *mt1, int from1, int to1,
+                              MText *mt2, int from2, int to2);
+
+extern int mtext_character (MText *mt, int from, int to, int c);
+
+extern int mtext_del (MText *mt, int from, int to);
+
+extern int mtext_ins (MText *mt1, int pos, MText *mt2);
+
+extern int mtext_insert (MText *mt1, int pos, MText *mt2, int from, int to);
+
+extern int mtext_ins_char (MText *mt, int pos, int c, int n);
+
+extern int mtext_replace (MText *mt1, int from1, int to1,
+                         MText *mt2, int from2, int to2);
+
+extern MText *mtext_cat_char (MText *mt, int c);
+
+extern MText *mtext_duplicate (MText *mt, int from, int to);
+
+extern MText *mtext_dup (MText *mt);
+
+extern MText *mtext_cat (MText *mt1, MText *mt2);
+
+extern MText *mtext_ncat (MText *mt1, MText *mt2, int n);
+
+extern MText *mtext_cpy (MText *mt1, MText *mt2);
+
+extern MText *mtext_ncpy (MText *mt1, MText *mt2, int n);
+
+extern int mtext_chr (MText *mt, int c);
+
+extern int mtext_rchr (MText *mt, int c);
+
+extern int mtext_cmp (MText *mt1, MText *mt2);
+
+extern int mtext_ncmp (MText *mt1, MText *mt2, int n);
+
+extern int mtext_spn (MText *mt1, MText *mt2);
+
+extern int mtext_cspn (MText *mt1, MText *mt2);
+
+extern int mtext_pbrk (MText *mt1, MText *mt2);
+
+extern int mtext_text (MText *mt1, int pos, MText *mt2);
+
+extern int mtext_search (MText *mt1, int from, int to, MText *mt2);
+
+extern MText *mtext_tok (MText *mt, MText *delim, int *pos);
+
+extern int mtext_casecmp (MText *mt1, MText *mt2);
+
+extern int mtext_ncasecmp (MText *mt1, MText *mt2, int n);
+
+extern int mtext_lowercase (MText *mt);
+
+extern int mtext_titlecase (MText *mt);
+
+extern int mtext_uppercase (MText *mt);
+
+/*** @ingroup m17nMtext */
+/***en
+    @brief Enumeration for specifying a set of line breaking option.
+
+    The enum #MTextLineBreakOption is to control the line breaking
+    algorithm of the function mtext_line_break () by specifying
+    logical-or of the members in the arg @e option.  */
+
+enum MTextLineBreakOption
+  {
+    /***en Specify the legacy support for space character as base for
+       combining marks.  See the section 8.3 of UAX#14. */
+    MTEXT_LBO_SP_CM = 1,
+    /***en Specify to use space characters for line breaking Korean
+       text.  */
+    MTEXT_LBO_KOREAN_SP = 2,
+    /***en Specify to treat characters of ambiguous line-breaking
+       class as of ideographic line-breaking class.  */
+    MTEXT_LBO_AI_AS_ID = 4,
+    MTEXT_LBO_MAX
+  };
+
+extern int mtext_line_break (MText *mt, int pos, int option, int *after);
+
+/*** @ingroup m17nPlist */
+extern MPlist *mplist_deserialize (MText *mt);
+
+/*
+ * (5-3) Text properties
+ */
+/*=*/
+/*** @ingroup m17nCore */
+/***en @defgroup m17nTextProperty Text Property */
+/***ja @defgroup m17nTextProperty ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ */
+/*=*/
+/*** @ingroup m17nTextProperty */
+/***en
+    @brief Flag bits to control text property.
+
+    The mtext_property () function accepts logical OR of these flag
+    bits as an argument.  They control the behaviour of the created
+    text property as described in the documentation of each flag
+    bit.  */
+
+/***ja
+    @brief ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÀ©¸æ¤¹¤ë¥Õ¥é¥°¥Ó¥Ã¥È.
+
+    ´Ø¿ô mtext_property () ¤Ï°Ê²¼¤Î¥Õ¥é¥°¥Ó¥Ã¥È¤ÎÏÀÍý
+    OR ¤ò°ú¿ô¤È¤·¤Æ¤È¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
+    ¥Õ¥é¥°¥Ó¥Ã¥È¤ÏÀ¸À®¤µ¤ì¤¿¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î¿¶Éñ¤¤¤òÀ©¸æ¤¹¤ë¡£
+    ¾ÜºÙ¤Ï³Æ¥Õ¥é¥°¥Ó¥Ã¥È¤ÎÀâÌÀ¤ò»²¾È¡£*/
+
+enum MTextPropertyControl
+  {
+    /***en If this flag bit is on, an M-text inserted at the start
+       position or at the middle of the text property inherits the
+       text property.  */
+    /***ja ¤³¤Î¥Ó¥Ã¥È¤¬ on ¤Ê¤é¤Ð¡¢¤³¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î»Ï¤Þ¤ëÅÀ¤¢¤ë¤¤¤ÏÃæ´Ö¤ËÁÞÆþ¤µ¤ì¤¿
+       M-text ¤Ï¤³¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò·Ñ¾µ¤¹¤ë¡£
+       */
+    MTEXTPROP_FRONT_STICKY = 0x01,
+
+    /***en If this flag bit is on, an M-text inserted at the end
+       position or at the middle of the text property inherits the
+       text property.  */
+    /***ja ¤³¤Î¥Ó¥Ã¥È¤¬ on ¤Ê¤é¤Ð¡¢¤³¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î½ª¤ï¤ëÅÀ¤¢¤ë¤¤¤ÏÃæ´Ö¤ËÁÞÆþ¤µ¤ì¤¿
+       M-text ¤Ï¤³¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò·Ñ¾µ¤¹¤ë¡£
+       */
+    MTEXTPROP_REAR_STICKY = 0x02,
+
+    /***en If this flag bit is on, the text property is removed if a
+       text in its region is modified.  */
+    /***ja ¤³¤Î¥Ó¥Ã¥È¤¬ on ¤Ê¤é¤Ð¡¢¤³¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ÎÈÏ°ÏÆâ¤Î¥Æ¥­¥¹¥È¤¬Êѹ¹¤µ¤ì¤¿¾ì¹ç¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¼è¤ê½ü¤«¤ì¤ë¡£  */
+    MTEXTPROP_VOLATILE_WEAK = 0x04,
+
+    /***en If this flag bit is on, the text property is removed if a
+       text or the other text property in its region is modified.  */
+    /***ja ¤³¤Î¥Ó¥Ã¥È¤¬ on ¤Ê¤é¤Ð¡¢¤³¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ÎÈÏ°ÏÆâ¤Î¥Æ¥­¥¹¥È¤¢¤ë¤¤¤ÏÊ̤Υƥ­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤¬Êѹ¹¤µ¤ì¤¿¾ì¹ç¤³¤Î¥Æ¥­
+       ¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¼è¤ê½ü¤«¤ì¤ë¡£*/
+    MTEXTPROP_VOLATILE_STRONG = 0x08,
+
+    /***en If this flag bit is on, the text property is not
+       automatically merged with the others.  */
+    /***ja ¤³¤Î¥Ó¥Ã¥È¤¬ on ¤Ê¤é¤Ð¡¢¤³¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¾¤Î¥×¥í¥Ñ¥Æ¥£¤È¼«Æ°Åª¤Ë¤Ï¥Þ¡¼¥¸¤µ¤ì¤Ê¤¤¡£ */
+    MTEXTPROP_NO_MERGE = 0x10,
+
+    MTEXTPROP_CONTROL_MAX = 0x1F
+  };
+
+/*=*/
+extern MSymbol Mtext_prop_serializer;
+extern MSymbol Mtext_prop_deserializer;
+
+
+/*** @ingroup m17nTextProperty */
+/***en
+    @brief Type of serializer functions.
+
+    This is the type of serializer functions.  If the key of a symbol
+    property is #Mtext_prop_serializer, the value must be of this
+    type.
+
+    @seealso
+    mtext_serialize (), #Mtext_prop_serializer
+*/
+/***ja
+    @brief ¥·¥ê¥¢¥é¥¤¥¶´Ø¿ô¤Î·¿Àë¸À.
+
+    ¥·¥ê¥¢¥é¥¤¥¶´Ø¿ô¤Î·¿¤Ç¤¢¤ë¡£ ¤¢¤ë¥·¥ó¥Ü¥ë¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤¬ @c
+    #Mtext_prop_serializer ¤Ç¤¢¤ë¤È¤­¡¢ ÃͤϤ³¤Î·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    @seealso
+    mtext_serialize (), #Mtext_prop_serializer
+*/
+
+typedef MPlist *(*MTextPropSerializeFunc) (void *val);
+
+/*** @ingroup m17nTextProperty */
+/***en
+    @brief Type of deserializer functions.
+
+    This is the type of deserializer functions.  If the key of a
+    symbol property is #Mtext_prop_deserializer, the value must be of
+    this type.
+
+    @seealso
+    mtext_deserialize (), #Mtext_prop_deserializer
+*/
+/***ja
+    @brief ¥Ç¥·¥ê¥¢¥é¥¤¥¶´Ø¿ô¤Î·¿Àë¸À.
+
+    ¥Ç¥·¥ê¥¢¥é¥¤¥¶´Ø¿ô¤Î·¿¤Ç¤¢¤ë¡£ ¤¢¤ë¥·¥ó¥Ü¥ë¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤¬ @c
+    #Mtext_prop_deserializer ¤Ç¤¢¤ë¤È¤­¡¢ ÃͤϤ³¤Î·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    @seealso
+    Mtext_prop_deserialize (), Mtext_prop_deserializer
+*/
+typedef void *(*MTextPropDeserializeFunc) (MPlist *plist);
+
+extern void *mtext_get_prop (MText *mt, int pos, MSymbol key);
+
+extern int mtext_get_prop_values (MText *mt, int pos, MSymbol key,
+                                 void **values, int num);
+
+extern int mtext_get_prop_keys (MText *mt, int pos, MSymbol **keys);
+
+extern int mtext_put_prop (MText *mt, int from, int to,
+                          MSymbol key, void *val);
+
+extern int mtext_put_prop_values (MText *mt, int from, int to,
+                                 MSymbol key, void **values, int num);
+
+extern int mtext_push_prop (MText *mt, int from, int to,
+                           MSymbol key, void *val);
+
+extern int mtext_pop_prop (MText *mt, int from, int to,
+                          MSymbol key);
+
+extern int mtext_prop_range (MText *mt, MSymbol key, int pos,
+                            int *from, int *to, int deeper);
+
+/*=*/
+/***
+    @ingroup m17nTextProperty */
+/***en
+    @brief Type of text properties.
+
+    The type #MTextProperty is for a @e text @e property objects.  Its
+    internal structure is concealed from application programs.  */
+/***ja
+    @brief @c ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î·¿Àë¸À.
+
+    #MTextProperty ¤Ï @e ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ ¥ª¥Ö¥¸¥§¥¯¥È¤Î·¿¤Ç¤¢¤ë¡£
+    ÆâÉô¹½Â¤¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤Ï¸«¤¨¤Ê¤¤¡£  */
+
+typedef struct MTextProperty MTextProperty;
+
+/*=*/
+
+extern MTextProperty *mtext_property (MSymbol key, void *val,
+                                     int control_bits);
+
+extern MText *mtext_property_mtext (MTextProperty *prop);
+
+extern MSymbol mtext_property_key (MTextProperty *prop);
+
+extern void *mtext_property_value (MTextProperty *prop);
+
+extern int mtext_property_start (MTextProperty *prop);
+
+extern int mtext_property_end (MTextProperty *prop);
+
+extern MTextProperty *mtext_get_property (MText *mt, int pos, MSymbol key);
+
+extern int mtext_get_properties (MText *mt, int pos, MSymbol key,
+                                MTextProperty **props, int num);
+
+extern int mtext_attach_property (MText *mt, int from, int to,
+                                 MTextProperty *prop);
+
+extern int mtext_detach_property (MTextProperty *prop);
+
+extern int mtext_push_property (MText *mt, int from, int to,
+                               MTextProperty *prop);
+
+extern MText *mtext_serialize (MText *mt, int from, int to,
+                              MPlist *property_list);
+
+extern MText *mtext_deserialize (MText *mt);
+
+/*** @ingroup m17nCore */
+/***en @defgroup m17nDatabase Database */
+/***ja @defgroup m17nDatabase ¥Ç¡¼¥¿¥Ù¡¼¥¹ */
+/*=*/
+
+/* Directory of an application specific databases.  */
+extern char *mdatabase_dir;
+/*=*/
+/***
+    @ingroup m17nDatabase  */ 
+/***en
+    @brief Type of database.
+
+    The type #MDatabase is for a database object.  Its internal
+    structure is concealed from an application program.  */
+/***ja 
+    @brief ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î·¿Àë¸À.
+
+    #MDatabase ·¿¤Ï¥Ç¡¼¥¿¥Ù¡¼¥¹¥ª¥Ö¥¸¥§¥¯¥ÈÍѤι½Â¤ÂΤǤ¢¤ë¡£
+    ÆâÉô¹½Â¤¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤Ï¸«¤¨¤Ê¤¤¡£
+    */
+
+typedef struct MDatabase MDatabase;
+
+/*=*/
+
+/* Look for a data.  */
+extern MDatabase *mdatabase_find (MSymbol tag1, MSymbol tag2,
+                                 MSymbol tag3, MSymbol tag4);
+
+extern MPlist *mdatabase_list (MSymbol tag0, MSymbol tag1,
+                              MSymbol tag2, MSymbol tag3);
+
+/* Load a data.  */
+void *mdatabase_load (MDatabase *mdb);
+
+/* Get tags of a data.  */
+extern MSymbol *mdatabase_tag (MDatabase *mdb);
+
+/* Define a data.  */
+extern MDatabase *mdatabase_define (MSymbol tag1, MSymbol tag2,
+                                   MSymbol tag3, MSymbol tag4,
+                                   void *(*loader) (MSymbol *, void *),
+                                   void *extra_info);
+
+M17N_END_HEADER
+
+#endif /* _M17N_CORE_H_ */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/m17n-flt.c b/src/m17n-flt.c
new file mode 100644 (file)
index 0000000..65970d4
--- /dev/null
@@ -0,0 +1,3235 @@
+/* m17n-flt.c -- Font Layout Table sub-module.
+   Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nFLT
+    @brief FLT support for a window system.
+
+    This section defines the m17n FLT API concerning character
+    layouting facility using FLT (Font Layout Table).  The format of
+    FLT is described in @ref mdbFLT.  */
+
+/***ja
+    @addtogroup m17nFLT
+    @brief ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Î¤¿¤á¤Î FLT ¥µ¥Ý¡¼¥È.
+
+    ¤³¤Î¥»¥¯¥·¥ç¥ó¤Ç¤Ï¡¢FLT (Font Layout Table)
+    ¤òÍѤ¤¤¿Ê¸»ú¥ì¥¤¥¢¥¦¥Èµ¡Ç½¤Ë´Ø¤¹¤ë m17n FLT API ¤òÄêµÁ¤¹¤ë¡£
+    FLT ¤Î·Á¼°¤Ï @ref mdbFLT ¤Ëµ­½Ò¤µ¤ì¤Æ¤¤¤ë¡£  */
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <regex.h>
+
+#include "m17n-core.h"
+#include "m17n-flt.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "mtext.h"
+#include "symbol.h"
+#include "plist.h"
+#include "database.h"
+#include "internal-flt.h"
+
+/* Font Layouter */
+
+/* Font Layout Table (FLT)
+
+Predefined terms: SYMBOL, INTEGER, STRING
+
+FLT ::=        '(' STAGE + ')'
+
+STAGE ::= CATEGORY-TABLE ? FONT-LAYOUT-RULE
+
+;; Each STAGE consumes a source (code sequence) and produces another
+;; code sequence that is given to the next STAGE as a source.  The
+;; source given to the first stage is a sequence of character codes
+;; that are assigned category codes by CATEGORY-TABLE.  The output of
+;; the last stage is a glyph code sequence given to the renderer.
+
+CATEGORY-TABLE ::=
+       '(' 'category' CATEGORY-SPEC + ')'
+CATEGORY-SPEC ::=
+       '(' CODE [ CODE ] CATEGORY ')'
+CODE ::= INTEGER
+CATEGORY ::= INTEGER
+;; ASCII character codes of alphabet ('A' .. 'Z' 'a' .. 'z').
+;; Ex: CATEGORY-TABLE
+;; (category
+;;   (0x0900 0x097F    ?E)     ; All Devanagari characters
+;;   (0x093C           ?N))    ; DEVANAGARI-LETTER NUKTA
+;;     Assign the category 'E' to all Devanagari characters but 0x093C,
+;;     assign the category 'N' to 0x093C.
+
+FONT-LAYOUT-RULE ::=
+       '(' 'generator' RULE MACRO-DEF * ')'
+
+RULE ::= COMMAND | REGEXP-RULE | MATCH-RULE | MAP-RULE
+        | COND-STRUCT | MACRO-NAME
+
+COMMAND ::=
+       DIRECT-CODE | COMBINING | PREDEFIND-COMMAND | OTF-COMMAND
+
+DIRECT-CODE ::= INTEGER
+;; Always succeed.  Produce the code.  Consume no source.
+
+PREDEFIND-COMMAND ::=
+       '=' | '*' | '<' | '>' | '|'
+
+;; '=': Succeed when the current run contains at least one code.
+;; Consume the first code in the current run, and produce it as is.
+
+;; '*': If the the previous command succeeded, repeat it until it
+;; fails.  
+
+;; '<': Produce a special code that indicates the start of grapheme
+;; cluster.  Succeed always, consume nothing.
+
+;; '>': Produce a special code that indicates the end of grapheme
+;; cluster.  Succeed always, consume nothing.
+
+;; '|': Produce a special code whose category is ' '.  Succeed always,
+;; consume nothing.
+
+OTF-COMMAND ::=
+       ':otf=''SCRIPT'[':'['LANGSYS'][':'[GSUB-FEATURES][':'GPOS-FEATURES]]]
+;; Run the Open Type Layout Table on the current run.  Succeed always,
+;; consume all glyphs in the current range.
+
+SCRIPT ::= OTF-TAG
+;;     OTF's ScriptTag name (four letters) listed at:
+;;     <http://www.microsoft.om/typograph/otspec/scripttags.htm>
+LANGSYS ::= OTF-TAG
+;;     OTF's Language System name (four letters) listed at:
+;;     <http://www.microsoft.om/typograph/otspec/languagetags.htm>
+
+GSUB-FEATURES ::= [FEATURE[,FEATURE]*] | ' '
+GPOS-FEATURES ::= [FEATURE[,FEATURE]*] | ' '
+FEATURE ::= OTF-TAG
+;;     OTF's Feature name (four letters) listed at:
+;;     <http://www.microsoft.om/typograph/otspec/???.htm>
+
+OTF-TAG ::= PRINTABLE-CHAR PRINTABLE-CHAR PRINTABLE-CHAR PRINTABLE-CHAR
+
+;; Ex. OTF-COMMAND
+;; 'otf:deva'
+;;     Run all features in the default langsys of 'deva' script.
+;; 'otf:deva::nukt:haln'
+;;     Run all GSUB features, run 'nukt' and 'haln' GPOS features.
+;; 'otf:deva:: :'
+;;     Run all GSUB features, run no GPOS features.
+
+REGEXP-RULE ::=
+       '(' REGEXP RULE * ')'
+
+;; Succeed if REGXP matches the head of source.  Run RULEs while
+;; limiting the source to the matching part.  Consume that part.
+
+REGEXP ::= STRING
+;; Must be composed only from ASCII characters.  'A' - 'Z', 'a' - 'z'
+;; correspond to CATEGORY.
+
+;; Ex: REGEXP-RULE
+;; ("VA?"
+;;   < | vowel * | >)
+
+MATCH-RULE ::=
+       '(' MATCH-IDX RULE * ')'
+
+;; Succeed if the previous REGEXP-RULE found a matching part for
+;; MATCH-IDX.  Run RULEs while limiting the source to the matching
+;; part.  If MATCH-IDX is zero, consume the whole part, else consume
+;; nothing.
+
+MATCH-IDX ::= INTEGER
+;; Must be 0..20.
+
+;; Ex. MATCH-RULE
+;; (2 consonant *)
+
+MAP-RULE ::=
+       '(' ( SOURCE-SEQ | SOURCE-RANGE ) RULE * ')'
+
+;; Succeed if the source matches SOURCE-SEQ or SOURCE-RANGE.  Run
+;; RULEs while limiting the source to the matching part.  Consume that
+;; part.
+
+SOURCE-SEQ ::=
+       '(' CODE + ')'
+SOURCE-RANGE ::=
+       '(' 'range' CODE CODE ')'
+;; Ex. MAP-RULE
+;; ((0x0915 0x094D)            0x43)
+;;     If the source code sequence is 0x0915 0x094D, produce 0x43.
+;; ((range 0x0F40 0x0F6A)      0x2221)
+;;     If the first source code CODE is in the range 0x0F40..0x0F6A, 
+;;     produce (0x2221 + (CODE - 0x0F40)).
+
+COND-STRUCT ::=
+       '(' 'cond' RULE + ')'
+
+;; Try each rule in sequence until one succeeds.  Succeed if one
+;; succeeds.  Consume nothing.
+
+;; Ex. COND-STRUCT
+;; (cond
+;;  ((0x0915 0x094D)           0x43)
+;;  ((range 0x0F40 0x0F6A)     0x2221)
+;;  = )
+
+COMBINING ::= 'V''H''O''V''H'
+V ::= ( 't' | 'c' | 'b' | 'B' )
+H ::= ( 'l' | 'c' | 'r' )
+O ::= ( '.' | XOFF | YOFF | XOFF YOFF )
+XOFF ::= '<'INTEGER | '>'INTEGER 
+YOFF ::= '+'INTEGER | '-'INTEGER
+;; INTEGER must be integer 0..127
+
+;; VH pair indicates 12 reference points of a glyph as below:
+;;
+;;   0----1----2 <---- ascent   0:tl (top-left)
+;;   |         |                1:tc (top-center)
+;;   |         |                2:tr (top-right)
+;;   |         |                3:Bl (base-left)
+;;   9   10   11 <---- center   4:Bc (base-center)
+;;   |         |                5:Br (base-right)
+;; --3----4----5-- <-- baseline         6:bl (bottom-left)
+;;   |         |                7:bc (bottom-center)
+;;   6----7----8 <---- descent  8:br (bottom-right)
+;;                              9:cl (center-left)
+;;   |    |    |               10:cc (center-center)
+;; left center right           11:cr (center-right)
+;;
+;; Ex. COMBINING
+;; 'tc.bc':
+;;     Align top-left point of the previous glyph and bottom-center
+;;     point of the current glyph.
+;; 'Bl<20-10Br'
+;;     Align 20% left and 10% below of base-left point of the previous
+;;     glyph and base-right point of the current glyph.
+
+MACRO-DEF ::=
+       '(' MACRO-NAME RULE + ')'
+MACRO-NAME ::= SYMBOL
+
+*/
+
+static int mdebug_flag = MDEBUG_FLT;
+
+MSymbol Mfont, Mlayouter, Mcombining;
+
+static MSymbol Mgenerator, Mend;
+
+static MPlist *flt_list;
+static int flt_min_coverage, flt_max_coverage;
+
+enum GlyphInfoMask
+{
+  CategoryCodeMask = 0x7F,
+  CombiningCodeMask = 0xFFFFFF,
+  CombinedMask = 1 << 28,
+  LeftPaddingMask = 1 << 29,
+  RightPaddingMask = 1 << 30
+};
+
+#define SET_GLYPH_INFO(g, mask, ctx, info)                     \
+  ((g)->internal = (((g)->internal & ~(mask)) | (info)),       \
+   (ctx)->check_mask |= (mask))
+
+#define GET_CATEGORY_CODE(g) ((g)->internal & CategoryCodeMask)
+#define SET_CATEGORY_CODE(g, code)                                      \
+  ((g)->internal = (((g)->internal & ~(CombiningCodeMask | CombinedMask)) \
+                   | (code)))
+#define GET_COMBINED(g) ((g)->internal & CombinedMask)
+#define GET_COMBINING_CODE(g) ((g)->internal & CombiningCodeMask)
+#define SET_COMBINING_CODE(g, ctx, code)                       \
+  SET_GLYPH_INFO (g, CombiningCodeMask | CombinedMask, ctx,    \
+                 (code) | CombinedMask)
+#define GET_LEFT_PADDING(g) ((g)->internal & LeftPaddingMask)
+#define SET_LEFT_PADDING(g, ctx, flag) \
+  SET_GLYPH_INFO (g, LeftPaddingMask, ctx, flag)
+#define GET_RIGHT_PADDING(g) ((g)->internal & RightPaddingMask)
+#define SET_RIGHT_PADDING(g, ctx, flag)        \
+  SET_GLYPH_INFO (g, RightPaddingMask, ctx, flag)
+#define GET_ENCODED(g) ((g)->encoded)
+#define SET_ENCODED(g, flag) ((g)->encoded = (flag))
+#define GET_MEASURED(g) ((g)->measured)
+#define SET_MEASURED(g, flag) ((g)->measured = (flag))
+
+#define GINIT(gstring, n)                                      \
+  do {                                                         \
+    if (! (gstring)->glyph_size)                               \
+      (gstring)->glyph_size = sizeof (MFLTGlyph);              \
+    (gstring)->glyphs = alloca ((gstring)->glyph_size * (n));  \
+    (gstring)->allocated = (n);                                        \
+    (gstring)->used = 0;                                       \
+  } while (0)
+
+#define GALLOCA (gstring)      \
+  ((MFLTGlyph *) alloca ((gstring)->glyph_size))
+
+#define GREF(gstring, idx)     \
+  ((MFLTGlyph *) ((char *) ((gstring)->glyphs) + (gstring)->glyph_size * (idx)))
+
+#define PREV(gstring, g)       \
+  ((MFLTGlyph *) ((char *) (g) - (gstring)->glyph_size))
+
+#define NEXT(gstring, g)       \
+  ((MFLTGlyph *) ((char *) (g) + (gstring)->glyph_size))
+
+#define GCPY(src, src_idx, n, tgt, tgt_idx)                            \
+  do {                                                                 \
+    memcpy ((char *) ((tgt)->glyphs) + (tgt)->glyph_size * (tgt_idx),  \
+           (char *) ((src)->glyphs) + (src)->glyph_size * (src_idx),   \
+           (src)->glyph_size * (n));                                   \
+  } while (0)
+
+#define GDUP(ctx, idx)                         \
+  do {                                         \
+    MFLTGlyphString *src = (ctx)->in;          \
+    MFLTGlyphString *tgt = (ctx)->out;         \
+    if (tgt->allocated <= tgt->used)           \
+      return -2;                               \
+    GCPY (src, (idx), 1, tgt, tgt->used);      \
+    tgt->used++;                               \
+  } while (0)
+
+static int
+GREPLACE (MFLTGlyphString *src, int src_from, int src_to,
+         MFLTGlyphString *tgt, int tgt_from, int tgt_to)
+{
+  int src_len = src_to - src_from;
+  int tgt_len = tgt_to - tgt_from;
+  int inc = src_len - tgt_len;
+
+  if (tgt->allocated < tgt->used + inc)
+    return -2;
+  if (inc != 0 && tgt_to < tgt->used)
+    memmove ((char *) tgt->glyphs + tgt->glyph_size * (tgt_from + src_len),
+            (char *) tgt->glyphs + tgt->glyph_size * tgt_to,
+            tgt->glyph_size * (tgt->used - tgt_to));
+  if (src_len)
+    memcpy ((char *) tgt->glyphs + tgt->glyph_size * tgt_from,
+           (char *) src->glyphs + src->glyph_size * src_from,
+           src->glyph_size * src_len);
+  tgt->used += inc;
+  return 0;
+}
+
+
+/* Command ID:
+                0 ...          : direct code
+                  -1           : invalid
+            -0x0F .. -2        : builtin commands
+       -0x100000F .. -0x10     : combining code
+                 ... -0x1000010: index to FontLayoutStage->cmds
+ */
+
+#define INVALID_CMD_ID -1
+#define CMD_ID_OFFSET_BUILTIN  -3
+#define CMD_ID_OFFSET_COMBINING        -0x10
+#define CMD_ID_OFFSET_INDEX    -0x1000010
+
+/* Builtin commands. */
+#define CMD_ID_COPY            -3 /* '=' */
+#define CMD_ID_REPEAT          -4 /* '*' */
+#define CMD_ID_CLUSTER_BEGIN   -5 /* '<' */
+#define CMD_ID_CLUSTER_END     -6 /* '>' */
+#define CMD_ID_SEPARATOR       -7 /* '|' */
+#define CMD_ID_LEFT_PADDING    -8 /* '[' */
+#define CMD_ID_RIGHT_PADDING   -9 /* ']' */
+
+#define CMD_ID_TO_COMBINING_CODE(id) (CMD_ID_OFFSET_COMBINING - (id))
+#define COMBINING_CODE_TO_CMD_ID(code) (CMD_ID_OFFSET_COMBINING - (code))
+
+#define CMD_ID_TO_INDEX(id) (CMD_ID_OFFSET_INDEX - (id))
+#define INDEX_TO_CMD_ID(idx) (CMD_ID_OFFSET_INDEX - (idx))
+
+static MSymbol Mcond, Mrange, Mfont_facility, Mequal;
+
+#define GLYPH_CODE_P(code)     \
+  ((code) >= GLYPH_CODE_MIN && (code) <= GLYPH_CODE_MAX)
+
+#define GLYPH_CODE_INDEX(code) ((code) - GLYPH_CODE_MIN)
+
+#define UPDATE_CLUSTER_RANGE(ctx, g)           \
+  do {                                         \
+    if (ctx->cluster_begin_pos > (g)->from)    \
+      ctx->cluster_begin_pos = (g)->from;      \
+    if (ctx->cluster_end_pos < (g)->to)                \
+      ctx->cluster_end_pos = (g)->to;          \
+  } while (0)
+
+enum FontLayoutCmdRuleSrcType
+  {
+    SRC_REGEX,
+    SRC_INDEX,
+    SRC_SEQ,
+    SRC_RANGE,
+    SRC_HAS_GLYPH,
+    SRC_OTF_SPEC
+  };
+
+typedef struct
+{
+  enum FontLayoutCmdRuleSrcType src_type;
+  union {
+    struct {
+      char *pattern;
+      regex_t preg;
+    } re;
+    int match_idx;
+    struct {
+      int n_codes;
+      int *codes;
+    } seq;
+    struct {
+      int from, to;
+    } range;
+    struct {
+      int len;
+      MPlist *codes;
+      MFLTOtfSpec otf_spec;
+    } facility;
+  } src;
+
+  int n_cmds;
+  int *cmd_ids;
+} FontLayoutCmdRule;
+
+typedef struct
+{
+  /* Beginning and end indices of series of SEQ commands.  */
+  int seq_beg, seq_end;
+  /* Range of the first character appears in the above series.  */
+  int seq_from, seq_to;
+
+  int n_cmds;
+  int *cmd_ids;
+} FontLayoutCmdCond;
+
+enum FontLayoutCmdType
+  {
+    FontLayoutCmdTypeRule,
+    FontLayoutCmdTypeCond,
+    FontLayoutCmdTypeOTF,
+    FontLayoutCmdTypeOTFCategory,
+    FontLayoutCmdTypeMAX
+  };
+
+typedef struct
+{
+  enum FontLayoutCmdType type;
+  union {
+    FontLayoutCmdRule rule;
+    FontLayoutCmdCond cond;
+    MFLTOtfSpec otf;
+  } body;
+} FontLayoutCmd;
+
+typedef struct
+{
+  int size;
+  unsigned int *tag;
+  char *code;
+} FeatureCodeTable;
+
+typedef struct
+{
+  MCharTable *table;
+  FeatureCodeTable feature_table;
+  /* Non-null if the table must be re-configured by OTF specs included
+     in the definition.  */
+  MPlist *definition;
+} FontLayoutCategory;
+
+typedef struct 
+{
+  FontLayoutCategory *category;
+  int size, inc, used;
+  FontLayoutCmd *cmds;
+} FontLayoutStage;
+
+struct _MFLT
+{
+  MSymbol name;
+  MSymbol family;
+  MSymbol registry;
+  MFLTOtfSpec otf;
+  MDatabase *mdb;
+  FontLayoutCategory *coverage;
+  MPlist *stages;
+  int need_config;
+  /* Font for which coverage or some of categories are configured.  */
+  MSymbol font_id;
+};
+
+/* Font layout table loader */
+
+static int parse_otf_command (MSymbol symbol, MFLTOtfSpec *spec);
+
+static void
+apply_otf_feature (MFLTFont *font, MFLTOtfSpec *spec,
+                  int from, int to, MCharTable *table, int category)
+{
+  unsigned char *buf;
+  int i;
+
+  if (! mflt_iterate_otf_feature)
+    return;
+  buf = alloca (to + 1 - from);
+  memset (buf, 0, to + 1 - from);
+  if (mflt_iterate_otf_feature (font, spec, from, to, buf) < 0)
+    return;
+  for (i = to - from; i >= 0; i--)
+    if (buf[i])
+      mchartable_set (table, from + i, (void *) category);
+}
+
+static unsigned int gen_otf_tag (char *p, int shift);
+
+/* Load a category table from PLIST.  PLIST has this form:
+      PLIST ::= ( FROM-CODE TO-CODE ? CATEGORY-CHAR ) *
+*/
+
+static FontLayoutCategory *
+load_category_table (MPlist *plist, MFLTFont *font)
+{
+  FontLayoutCategory *category;
+  MCharTable *table;
+  MPlist *feature_table_head = NULL;
+  int feature_table_size = 0;
+  MPlist *p;
+  int need_otf = 0;
+
+  table = mchartable (Minteger, (void *) 0);
+  MPLIST_DO (p, plist)
+    {
+      MPlist *elt;
+      int from, to, category_code;
+
+      if (! MPLIST_PLIST_P (p))
+       MERROR_GOTO (MERROR_FLT, end);
+      elt = MPLIST_PLIST (p);
+      if (MPLIST_SYMBOL_P (elt))
+       {
+         MPlist *next;
+
+         if (! mflt_enable_new_feature)
+           {
+             M17N_OBJECT_UNREF (table);
+             return NULL;
+           }
+         next = MPLIST_NEXT (elt);
+         if (! MPLIST_INTEGER_P (next))
+           MERROR_GOTO (MERROR_FLT, end);
+         if (! feature_table_head)
+           feature_table_head = p;
+         feature_table_size++;
+         continue;
+       }
+      if (! MPLIST_INTEGER_P (elt))
+       MERROR_GOTO (MERROR_FLT, end);
+      from = MPLIST_INTEGER (elt);
+      elt = MPLIST_NEXT (elt);
+      if (! MPLIST_INTEGER_P (elt))
+       MERROR_GOTO (MERROR_FLT, end);
+      to = MPLIST_INTEGER (elt);
+      elt = MPLIST_NEXT (elt);
+      if (MPLIST_TAIL_P (elt))
+       {
+         category_code = to;
+         to = from;
+       }
+      else if (MPLIST_SYMBOL_P (elt))
+       {
+         if (! mflt_enable_new_feature)
+           {
+             M17N_OBJECT_UNREF (table);
+             return NULL;
+           }
+         if (font)
+           {
+             MFLTOtfSpec spec;
+             if (parse_otf_command (MPLIST_SYMBOL (elt), &spec) < 0)
+               MERROR_GOTO (MERROR_FLT, end);
+             elt = MPLIST_NEXT (elt);
+             if (! MPLIST_INTEGER_P (elt))
+               MERROR_GOTO (MERROR_FLT, end);
+             category_code = MPLIST_INTEGER (elt);
+             if (! isalnum (category_code))
+               MERROR_GOTO (MERROR_FLT, end);
+             apply_otf_feature (font, &spec, from, to, table, category_code);
+           }
+         else
+           need_otf = 1;
+         continue;
+       }
+      else
+       {
+         if (! MPLIST_INTEGER_P (elt))
+           MERROR_GOTO (MERROR_FLT, end);
+         category_code = MPLIST_INTEGER (elt);
+       }
+      if (! isalnum (category_code))
+       MERROR_GOTO (MERROR_FLT, end);
+
+      if (from == to)
+       mchartable_set (table, from, (void *) category_code);
+      else
+       mchartable_set_range (table, from, to, (void *) category_code);
+    }
+
+ end:
+  category = calloc (1, sizeof (FontLayoutCategory));
+  category->table = table;
+  if (need_otf)
+    {
+      category->definition = plist;
+      M17N_OBJECT_REF (plist);
+    }
+  else
+    category->definition = NULL;
+  if (feature_table_head)
+    {
+      int i = 0;
+      category->feature_table.size = feature_table_size;
+      category->feature_table.tag = malloc (sizeof (unsigned int)
+                                           * feature_table_size);
+      category->feature_table.code = malloc (feature_table_size);
+
+      MPLIST_DO (p, feature_table_head)
+       {
+         MPlist *elt;
+         MSymbol feature;
+         if (! MPLIST_PLIST_P (p))
+           continue;
+         elt = MPLIST_PLIST (p);
+         if (! MPLIST_SYMBOL_P (elt))
+           continue;
+         feature = MPLIST_SYMBOL (elt);
+         elt = MPLIST_NEXT (elt);
+         if (! MPLIST_INTEGER_P (elt))
+           continue;
+         category->feature_table.tag[i]
+           = gen_otf_tag (MSYMBOL_NAME (feature), 7);
+         category->feature_table.code[i] = MPLIST_INTEGER (elt);
+         i++;
+       }
+    }
+  return category;
+}
+
+#define ref_category_table(CATEGORY) M17N_OBJECT_REF ((CATEGORY)->table)
+
+static void
+unref_category_table (FontLayoutCategory *category)
+{
+  M17N_OBJECT_UNREF (category->table);
+  if (! category->table)
+    {
+      if (category->definition)
+       M17N_OBJECT_UNREF (category->definition);
+      if (category->feature_table.size > 0)
+       {
+         free (category->feature_table.tag);
+         free (category->feature_table.code);
+       }
+      free (category);
+    }
+}
+
+static unsigned int
+gen_otf_tag (char *p, int shift)
+{
+  unsigned int tag = 0;
+  int i;
+
+  for (i = 0; i < 4 && *p; i++, p++)
+    tag = (tag << shift) | *p;
+  for (; i < 4; i++)
+    tag = (tag << shift) | 0x20;
+  return tag;
+}
+
+static char *
+otf_count_features (char *p, char *end, char stopper, int *count)
+{
+  int negative = 0;
+
+  *count = 0;
+  if (*p != stopper && *p != '\0')
+    while (1)
+      {
+       (*count)++;
+       if (*p == '*')
+         {
+           p++;
+           if (*p == stopper || *p == '\0')
+             break;
+           return NULL;
+         }
+       if (*p == '~')
+         {
+           if (negative++ == 0)
+             (*count)++;
+           p += 5;
+         }
+       else 
+         p += 4;
+       if (p > end)
+         return NULL;
+       if (*p == stopper || *p == '\0')
+         break;
+       if (*p != ',')
+         return NULL;
+       p++;
+       if (! *p)
+         return NULL;
+      }
+  return p;
+}
+
+static void
+otf_store_features (char *p, char *end, unsigned *buf)
+{
+  int negative = 0;
+  int i;
+
+  for (i = 0; p < end;)
+    {
+      if (*p == '*')
+       buf[i++] = 0xFFFFFFFF, p += 2, negative = 1;
+      else if (*p == '~')
+       {
+         if (negative++ == 0)
+           buf[i++] = 0xFFFFFFFF;
+         buf[i++] = gen_otf_tag (p + 1, 8), p += 6;
+       }
+      else
+       buf[i++] = gen_otf_tag (p, 8), p += 5;
+    }
+  buf[i] = 0;
+}
+
+static int
+parse_otf_command (MSymbol symbol, MFLTOtfSpec *spec)
+{
+  char *str = MSYMBOL_NAME (symbol);
+  char *end = str + MSYMBOL_NAMELEN (symbol);
+  unsigned int script, langsys;
+  char *gsub, *gpos;
+  int gsub_count = 0, gpos_count = 0;
+  char *p;
+
+  memset (spec, 0, sizeof (MFLTOtfSpec));
+
+  spec->sym = symbol;
+  str += 5;                    /* skip the heading ":otf=" or ":otf?" */
+  if (str[-1] == '?')
+    {
+      if (! mflt_enable_new_feature)
+       /* The client can't use this command.  */
+       return -1;
+      if (! *str)
+       /* This is a spec to reset category codes.  */
+       return 0;
+    }
+  script = gen_otf_tag (str, 8);
+  str += 4;
+  if (*str == '/')
+    {
+      langsys = gen_otf_tag (str, 8);
+      str += 4;
+    }
+  else
+    langsys = 0;
+  gsub = str;
+  if (*str != '=')
+    /* Apply all GSUB features.  */
+      gsub_count = 1;
+  else
+    {
+      p = str + 1;
+      str = otf_count_features (p, end, '+', &gsub_count);
+      if (! str)
+       MERROR (MERROR_FLT, -1);
+    }
+  gpos = str;
+  if (*str != '+')
+    /* Apply all GPOS features.  */
+    gpos_count = 1;
+  else
+    {
+      p = str + 1;
+      str = otf_count_features (p, end, '\0', &gpos_count);
+      if (! str)
+       MERROR (MERROR_FLT, -1);
+    }
+
+  spec->script = script;
+  spec->langsys = langsys;
+  if (gsub_count > 0)
+    {
+      spec->features[0] = malloc (sizeof (int) * (gsub_count + 1));
+      if (! spec->features[0])
+       return -2;
+      if (*gsub == '=')
+       otf_store_features (gsub + 1, gpos, spec->features[0]);
+      else
+       spec->features[0][0] = 0xFFFFFFFF, spec->features[0][1] = 0;
+    }
+  if (gpos_count > 0)
+    {
+      spec->features[1] = malloc (sizeof (int) * (gpos_count + 1));
+      if (! spec->features[1])
+       {
+         if (spec->features[0])
+           free (spec->features[0]);
+         return -2;
+       }
+      if (*gpos == '+')
+       otf_store_features (gpos + 1, str, spec->features[1]);
+      else
+       spec->features[1][0] = 0xFFFFFFFF, spec->features[1][1] = 0;
+    }
+  return 0;
+}
+
+
+/* Parse OTF command name NAME and store the result in CMD.
+   NAME has this form:
+       :SCRIPT[/[LANGSYS][=[GSUB-FEATURES][+GPOS-FEATURES]]]
+   where GSUB-FEATURES and GPOS-FEATURES have this form:
+       [FEATURE[,FEATURE]*] | ' '  */
+
+static int
+load_otf_command (FontLayoutCmd *cmd, MSymbol sym)
+{
+  char *name = MSYMBOL_NAME (sym);
+  int result;
+
+  if (name[0] != ':')
+    {
+      /* This is old format of "otf:...".  Change it to ":otf=...".  */
+      char *str = alloca (MSYMBOL_NAMELEN (sym) + 2);
+
+      sprintf (str, ":otf=");
+      strcat (str, name + 4);
+      sym = msymbol (str);
+    }
+
+  result = parse_otf_command (sym, &cmd->body.otf);
+  if (result == -2)
+    return result;
+  cmd->type = (name[4] == '?' ? FontLayoutCmdTypeOTFCategory
+              : FontLayoutCmdTypeOTF);
+  return 0;
+}
+
+
+/* Read a decimal number from STR preceded by one of "+-><".  '+' and
+   '>' means a plus sign, '-' and '<' means a minus sign.  If the
+   number is greater than 127, limit it to 127.  */
+
+static int
+read_decimal_number (char **str)
+{
+  char *p = *str;
+  int sign = (*p == '-' || *p == '<') ? -1 : 1;
+  int n = 0;
+
+  p++;
+  while (*p >= '0' && *p <= '9')
+    n = n * 10 + *p++ - '0';
+  *str = p;
+  if (n == 0)
+    n = 5;
+  return (n < 127 ? n * sign : 127 * sign);
+}
+
+
+/* Read a horizontal and vertical combining positions from STR, and
+   store them in the place pointed by X and Y.  The horizontal
+   position left, center, and right are represented by 0, 1, and 2
+   respectively.  The vertical position top, center, bottom, and base
+   are represented by 0, 1, 2, and 3 respectively.  If successfully
+   read, return 0, else return -1.  */
+
+static int
+read_combining_position (char *str, int *x, int *y)
+{
+  int c = *str++;
+  int i;
+
+  /* Vertical position comes first.  */
+  for (i = 0; i < 4; i++)
+    if (c == "tcbB"[i])
+      {
+       *y = i;
+       break;
+      }
+  if (i == 4)
+    return -1;
+  c = *str;
+  /* Then comse horizontal position.  */
+  for (i = 0; i < 3; i++)
+    if (c == "lcr"[i])
+      {
+       *x = i;
+       return 0;
+      }
+  return -1;
+}
+
+
+/* Return a combining code corresponding to SYM.  */
+
+static int
+get_combining_command (MSymbol sym)
+{
+  char *str = msymbol_name (sym);
+  int base_x, base_y, add_x, add_y, off_x, off_y;
+  int c;
+
+  if (read_combining_position (str, &base_x, &base_y) < 0)
+    return 0;
+  str += 2;
+  c = *str;
+  if (c == '.')
+    {
+      off_x = off_y = 128;
+      str++;
+    }
+  else
+    {
+      if (c == '+' || c == '-')
+       {
+         off_y = read_decimal_number (&str) + 128;
+         c = *str;
+       }
+      else
+       off_y = 128;
+      if (c == '<' || c == '>')
+       off_x = read_decimal_number (&str) + 128;
+      else
+       off_x = 128;
+    }
+  if (read_combining_position (str, &add_x, &add_y) < 0)
+    return 0;
+
+  c = MAKE_COMBINING_CODE (base_y, base_x, add_y, add_x, off_y, off_x);
+  return (COMBINING_CODE_TO_CMD_ID (c));
+}
+
+
+/* Load a command from PLIST into STAGE, and return that
+   identification number.  If ID is not INVALID_CMD_ID, that means we
+   are loading a top level command or a macro.  In that case, use ID
+   as the identification number of the command.  Otherwise, generate a
+   new id number for the command.  MACROS is a list of raw macros.  */
+
+static int
+load_command (FontLayoutStage *stage, MPlist *plist,
+             MPlist *macros, int id)
+{
+  int i;
+  int result;
+
+  if (MPLIST_INTEGER_P (plist))
+    {
+      int code = MPLIST_INTEGER (plist);
+
+      if (code < 0)
+       MERROR (MERROR_DRAW, INVALID_CMD_ID);
+      return code;
+    }
+  else if (MPLIST_PLIST_P (plist))
+    {
+      /* PLIST ::= ( cond ... ) | ( STRING ... ) | ( INTEGER ... )
+                  | ( ( INTEGER INTEGER ) ... )
+                  | ( ( range INTEGER INTEGER ) ... )
+                  | ( ( SYMBOL STRING ) ... )
+                  | ( ( font-facilty [ INTEGER ] ) ... )
+                  | ( ( font-facilty OTF-SPEC ) ... )  */
+      MPlist *elt = MPLIST_PLIST (plist);
+      int len = MPLIST_LENGTH (elt) - 1;
+      FontLayoutCmd *cmd;
+
+      if (id == INVALID_CMD_ID)
+       {
+         FontLayoutCmd dummy;
+         id = INDEX_TO_CMD_ID (stage->used);
+         MLIST_APPEND1 (stage, cmds, dummy, MERROR_DRAW);
+       }
+      cmd = stage->cmds + CMD_ID_TO_INDEX (id);
+
+      if (MPLIST_SYMBOL_P (elt))
+       {
+         FontLayoutCmdCond *cond;
+
+         if (MPLIST_SYMBOL (elt) != Mcond)
+           MERROR (MERROR_DRAW, INVALID_CMD_ID);
+         elt = MPLIST_NEXT (elt);
+         cmd->type = FontLayoutCmdTypeCond;
+         cond = &cmd->body.cond;
+         cond->seq_beg = cond->seq_end = -1;
+         cond->seq_from = cond->seq_to = 0;
+         cond->n_cmds = len;
+         MTABLE_CALLOC (cond->cmd_ids, len, MERROR_DRAW);
+         for (i = 0; i < len; i++, elt = MPLIST_NEXT (elt))
+           {
+             int this_id = load_command (stage, elt, macros, INVALID_CMD_ID);
+
+             if (this_id == INVALID_CMD_ID || this_id == -2)
+               MERROR (MERROR_DRAW, this_id);
+             /* The above load_command may relocate stage->cmds.  */
+             cmd = stage->cmds + CMD_ID_TO_INDEX (id);
+             cond = &cmd->body.cond;
+             cond->cmd_ids[i] = this_id;
+             if (this_id <= CMD_ID_OFFSET_INDEX)
+               {
+                 FontLayoutCmd *this_cmd
+                   = stage->cmds + CMD_ID_TO_INDEX (this_id);
+
+                 if (this_cmd->type == FontLayoutCmdTypeRule
+                     && this_cmd->body.rule.src_type == SRC_SEQ)
+                   {
+                     int first_char = this_cmd->body.rule.src.seq.codes[0];
+
+                     if (cond->seq_beg < 0)
+                       {
+                         /* The first SEQ command.  */
+                         cond->seq_beg = i;
+                         cond->seq_from = cond->seq_to = first_char;
+                       }
+                     else if (cond->seq_end < 0)
+                       {
+                         /* The following SEQ command.  */
+                         if (cond->seq_from > first_char)
+                           cond->seq_from = first_char;
+                         else if (cond->seq_to < first_char)
+                           cond->seq_to = first_char;
+                       }
+                   }
+                 else
+                   {
+                     if (cond->seq_beg >= 0 && cond->seq_end < 0)
+                       /* The previous one is the last SEQ command.  */
+                       cond->seq_end = i;
+                   }
+               }
+             else
+               {
+                 if (cond->seq_beg >= 0 && cond->seq_end < 0)
+                   /* The previous one is the last SEQ command.  */
+                   cond->seq_end = i;
+               }
+           }
+         if (cond->seq_beg >= 0 && cond->seq_end < 0)
+           /* The previous one is the last SEQ command.  */
+           cond->seq_end = i;
+       }
+      else
+       {
+         cmd->type = FontLayoutCmdTypeRule;
+         if (MPLIST_MTEXT_P (elt))
+           {
+             MText *mt = MPLIST_MTEXT (elt);
+             char *str = (char *) MTEXT_DATA (mt);
+
+             if (str[0] != '^')
+               {
+                 mtext_ins_char (mt, 0, '^', 1);
+                 str = (char *) MTEXT_DATA (mt);
+               }
+             if (regcomp (&cmd->body.rule.src.re.preg, str, REG_EXTENDED))
+               MERROR (MERROR_FONT, INVALID_CMD_ID);
+             cmd->body.rule.src_type = SRC_REGEX;
+             cmd->body.rule.src.re.pattern = strdup (str);
+           }
+         else if (MPLIST_INTEGER_P (elt))
+           {
+             cmd->body.rule.src_type = SRC_INDEX;
+             cmd->body.rule.src.match_idx = MPLIST_INTEGER (elt);
+           }
+         else if (MPLIST_PLIST_P (elt))
+           {
+             MPlist *pl = MPLIST_PLIST (elt), *p;
+             int size = MPLIST_LENGTH (pl);
+
+             if (MPLIST_INTEGER_P (pl))
+               {
+                 int i;
+
+                 cmd->body.rule.src_type = SRC_SEQ;
+                 cmd->body.rule.src.seq.n_codes = size;
+                 MTABLE_CALLOC (cmd->body.rule.src.seq.codes, size,
+                                MERROR_FONT);
+                 for (i = 0; i < size; i++, pl = MPLIST_NEXT (pl))
+                   {
+                     if (! MPLIST_INTEGER_P (pl))
+                       MERROR (MERROR_DRAW, INVALID_CMD_ID);
+                     cmd->body.rule.src.seq.codes[i]
+                       = (unsigned) MPLIST_INTEGER (pl);
+                   }
+               }
+             else if (MPLIST_SYMBOL_P (pl))
+               {
+                 if (MPLIST_SYMBOL (pl) == Mrange)
+                   {
+                     if (size != 3)
+                       MERROR (MERROR_FLT, INVALID_CMD_ID);
+                     cmd->body.rule.src_type = SRC_RANGE;
+                     pl = MPLIST_NEXT (pl);
+                     if (! MPLIST_INTEGER_P (pl))
+                       MERROR (MERROR_DRAW, INVALID_CMD_ID);
+                     cmd->body.rule.src.range.from
+                       = (unsigned) MPLIST_INTEGER (pl);
+                     pl = MPLIST_NEXT (pl);
+                     if (! MPLIST_INTEGER_P (pl))
+                       MERROR (MERROR_DRAW, INVALID_CMD_ID);
+                     cmd->body.rule.src.range.to
+                       = (unsigned) MPLIST_INTEGER (pl);
+                   }
+                 else if (MPLIST_SYMBOL (pl) == Mfont_facility)
+                   {
+                     FontLayoutCmdRule *rule = &cmd->body.rule;
+
+                     pl = MPLIST_NEXT (pl);
+                     if (MPLIST_SYMBOL_P (pl))
+                       {
+                         MSymbol sym = MPLIST_SYMBOL (pl);
+                         char *otf_spec = MSYMBOL_NAME (sym);
+
+                         if (otf_spec[0] == ':' && otf_spec[1] == 'o'
+                             && otf_spec[2] == 't' && otf_spec[3] == 'f')
+                           parse_otf_command (sym, &rule->src.facility.otf_spec);
+                         else
+                           MERROR (MERROR_FLT, INVALID_CMD_ID);
+                         rule->src_type = SRC_OTF_SPEC;
+                         pl = MPLIST_NEXT (pl);
+                       }
+                     else if (MPLIST_TAIL_P (pl))
+                       MERROR (MERROR_FLT, INVALID_CMD_ID);
+                     else
+                       rule->src_type = SRC_HAS_GLYPH;
+                     rule->src.facility.len = 0;
+                     MPLIST_DO (p, pl)
+                       {
+                         if (! MPLIST_INTEGER_P (p)
+                             && (MPLIST_SYMBOL_P (p)
+                                 ? MPLIST_SYMBOL (p) != Mequal
+                                 : 1))
+                           MERROR (MERROR_FLT, INVALID_CMD_ID);
+                         rule->src.facility.len++;
+                       }
+                     rule->src.facility.codes = pl;
+                     M17N_OBJECT_REF (pl);
+                   }
+               }
+             else
+               MERROR (MERROR_DRAW, INVALID_CMD_ID);
+           }
+         else
+           MERROR (MERROR_DRAW, INVALID_CMD_ID);
+
+         elt = MPLIST_NEXT (elt);
+         cmd->body.rule.n_cmds = len;
+         MTABLE_CALLOC (cmd->body.rule.cmd_ids, len, MERROR_DRAW);
+         for (i = 0; i < len; i++, elt = MPLIST_NEXT (elt))
+           {
+             int this_id = load_command (stage, elt, macros, INVALID_CMD_ID);
+
+             if (this_id == INVALID_CMD_ID || this_id == -2)
+               MERROR (MERROR_DRAW, this_id);
+             /* The above load_command may relocate stage->cmds.  */
+             cmd = stage->cmds + CMD_ID_TO_INDEX (id);
+             cmd->body.rule.cmd_ids[i] = this_id;
+           }
+       }
+    }
+  else if (MPLIST_SYMBOL_P (plist))
+    {
+      MPlist *elt;
+      MSymbol sym = MPLIST_SYMBOL (plist);
+      char *name = msymbol_name (sym);
+      int len = strlen (name);
+      FontLayoutCmd cmd;
+
+      if (len > 4
+         && ((name[0] == 'o' && name[1] == 't'
+              && name[2] == 'f' && name[3] == ':')
+             || (name[0] == ':' && name[1] == 'o' && name[2] == 't'
+                 && name[3] == 'f' && (name[4] == '=' || name[4] == '?'))))
+       {
+         result = load_otf_command (&cmd, sym);
+         if (result < 0)
+           return result;
+         if (id == INVALID_CMD_ID)
+           {
+             id = INDEX_TO_CMD_ID (stage->used);
+             MLIST_APPEND1 (stage, cmds, cmd, MERROR_DRAW);
+           }
+         else
+           stage->cmds[CMD_ID_TO_INDEX (id)] = cmd;
+         return id;
+       }
+
+      if (len == 1)
+       {
+         if (*name == '=')
+           return CMD_ID_COPY;
+         else if (*name == '*')
+           return CMD_ID_REPEAT;
+         else if (*name == '<')
+           return CMD_ID_CLUSTER_BEGIN;
+         else if (*name == '>')
+           return CMD_ID_CLUSTER_END;
+         else if (*name == '|')
+           return CMD_ID_SEPARATOR;
+         else if (*name == '[')
+           return CMD_ID_LEFT_PADDING;
+         else if (*name == ']')
+           return CMD_ID_RIGHT_PADDING;
+         else
+           id = 0;
+       }
+      else
+       {
+         id = get_combining_command (sym);
+         if (id)
+           return id;
+       }
+
+      i = 1;
+      MPLIST_DO (elt, macros)
+       {
+         if (sym == MPLIST_SYMBOL (MPLIST_PLIST (elt)))
+           {
+             id = INDEX_TO_CMD_ID (i);
+             if (stage->cmds[i].type == FontLayoutCmdTypeMAX)
+               id = load_command (stage, MPLIST_NEXT (MPLIST_PLIST (elt)),
+                                  macros, id);
+             return id;
+           }
+         i++;
+       }
+      MERROR (MERROR_DRAW, INVALID_CMD_ID);
+    }
+  else
+    MERROR (MERROR_DRAW, INVALID_CMD_ID);
+
+  return id;
+}
+
+static void
+free_flt_command (FontLayoutCmd *cmd)
+{
+  if (cmd->type == FontLayoutCmdTypeRule)
+    {
+      FontLayoutCmdRule *rule = &cmd->body.rule;
+
+      if (rule->src_type == SRC_REGEX)
+       {
+         free (rule->src.re.pattern);
+         regfree (&rule->src.re.preg);
+       }
+      else if (rule->src_type == SRC_SEQ)
+       free (rule->src.seq.codes);
+      free (rule->cmd_ids);
+    }
+  else if (cmd->type == FontLayoutCmdTypeCond)
+    free (cmd->body.cond.cmd_ids);
+  else if (cmd->type == FontLayoutCmdTypeOTF
+          || cmd->type == FontLayoutCmdTypeOTFCategory)
+    {
+      if (cmd->body.otf.features[0])
+       free (cmd->body.otf.features[0]);
+      if (cmd->body.otf.features[1])
+       free (cmd->body.otf.features[1]);
+    }
+}
+
+/* Load a generator from PLIST into a newly allocated FontLayoutStage,
+   and return it.  PLIST has this form:
+      PLIST ::= ( COMMAND ( CMD-NAME COMMAND ) * )
+*/
+
+static FontLayoutStage *
+load_generator (MPlist *plist)
+{
+  FontLayoutStage *stage;
+  MPlist *elt, *pl;
+  FontLayoutCmd dummy;
+  int result;
+
+  MSTRUCT_CALLOC (stage, MERROR_DRAW);
+  MLIST_INIT1 (stage, cmds, 32);
+  dummy.type = FontLayoutCmdTypeMAX;
+  MLIST_APPEND1 (stage, cmds, dummy, MERROR_FONT);
+  MPLIST_DO (elt, MPLIST_NEXT (plist))
+    {
+      if (! MPLIST_PLIST_P (elt))
+       MERROR (MERROR_FONT, NULL);
+      pl = MPLIST_PLIST (elt);
+      if (! MPLIST_SYMBOL_P (pl))
+       MERROR (MERROR_FONT, NULL);
+      MLIST_APPEND1 (stage, cmds, dummy, MERROR_FONT);
+    }
+
+  /* Load the first command from PLIST into STAGE->cmds[0].  Macros
+     called in the first command are also loaded from MPLIST_NEXT
+     (PLIST) into STAGE->cmds[n].  */
+  result = load_command (stage, plist, MPLIST_NEXT (plist),
+                        INDEX_TO_CMD_ID (0));
+  if (result == INVALID_CMD_ID || result == -2)
+    {
+      MLIST_FREE1 (stage, cmds);
+      free (stage);
+      return NULL;
+    }
+
+  return stage;
+}
+
+
+/* Load stages of the font layout table FLT.  */
+
+static int
+load_flt (MFLT *flt, MPlist *key_list)
+{
+  MPlist *top, *plist, *pl, *p;
+  FontLayoutCategory *category = NULL;
+  MSymbol sym;
+
+  if (key_list)
+    top = (MPlist *) mdatabase__load_for_keys (flt->mdb, key_list);
+  else
+    top = (MPlist *) mdatabase_load (flt->mdb);
+  if (! top)
+    return -1;
+  if (! MPLIST_PLIST_P (top))
+    {
+      M17N_OBJECT_UNREF (top);
+      MERROR (MERROR_FLT, -1);
+    }
+
+  if (key_list)
+    {
+      plist = mdatabase__props (flt->mdb);
+      if (! plist)
+       MERROR (MERROR_FLT, -1);
+      MPLIST_DO (plist, plist)
+       if (MPLIST_PLIST_P (plist))
+         {
+           pl = MPLIST_PLIST (plist);
+           if (! MPLIST_SYMBOL_P (pl)
+               || MPLIST_SYMBOL (pl) != Mfont)
+             continue;
+           pl = MPLIST_NEXT (pl);
+           if (! MPLIST_PLIST_P (pl))
+             continue;
+           p = MPLIST_PLIST (pl);
+           if (! MPLIST_SYMBOL_P (p))
+             continue;
+           p = MPLIST_NEXT (p);
+           if (! MPLIST_SYMBOL_P (p))
+             continue;
+           flt->family = MPLIST_SYMBOL (p);
+           MPLIST_DO (p, MPLIST_NEXT (p))
+             if (MPLIST_SYMBOL_P (p))
+               {
+                 sym = MPLIST_SYMBOL (p);
+                 if (MSYMBOL_NAME (sym)[0] != ':')
+                   flt->registry = sym, sym = Mnil;
+                 else
+                   break;
+               }
+           if (sym)
+             {
+               char *otf_spec = MSYMBOL_NAME (sym);
+
+               if (otf_spec[0] == ':' && otf_spec[1] == 'o'
+                   && otf_spec[2] == 't' && otf_spec[3] == 'f')
+                 parse_otf_command (sym, &flt->otf);
+             }
+           break;
+         }
+    }
+  MPLIST_DO (plist, top)
+    {
+      if (MPLIST_SYMBOL_P (plist)
+         && MPLIST_SYMBOL (plist) == Mend)
+       {
+         mplist_set (plist, Mnil, NULL);
+         break;
+       }
+      if (! MPLIST_PLIST (plist))
+       continue;
+      pl = MPLIST_PLIST (plist);
+      if (! MPLIST_SYMBOL_P (pl))
+       continue;
+      sym = MPLIST_SYMBOL (pl);
+      pl = MPLIST_NEXT (pl);
+      if (! pl)
+       continue;
+      if (sym == Mcategory)
+       {
+         if (category)
+           unref_category_table (category);
+         else if (flt->coverage)
+           {
+             category = flt->coverage;
+             ref_category_table (category);
+             continue;
+           }
+         category = load_category_table (pl, NULL);
+         if (! category)
+           goto err;
+         if (! flt->coverage)
+           {
+             flt->coverage = category;
+             ref_category_table (category);
+           }
+         if (category->definition)
+           flt->need_config = 1;
+       }
+      else if (sym == Mgenerator)
+       {
+         FontLayoutStage *stage;
+
+         if (! category)
+           break;
+         stage = load_generator (pl);
+         if (! stage)
+           break;
+         stage->category = category;
+         M17N_OBJECT_REF (category->table);
+         if (! flt->stages)
+           flt->stages = mplist ();
+         mplist_add (flt->stages, Mt, stage);
+       }
+    }
+  if (category)
+    unref_category_table (category);
+ err:
+  if (! MPLIST_TAIL_P (plist))
+    {
+      M17N_OBJECT_UNREF (top);
+      M17N_OBJECT_UNREF (flt->stages);
+      MERROR (MERROR_FLT, -1);
+    }
+  M17N_OBJECT_UNREF (top);
+  return 0;
+}
+
+
+static void
+free_flt_stage (MFLT *flt, FontLayoutStage *stage)
+{
+  int i;
+
+  unref_category_table (stage->category);
+  if (! flt->font_id)
+    {
+      for (i = 0; i < stage->used; i++)
+       free_flt_command (stage->cmds + i);
+      MLIST_FREE1 (stage, cmds);
+    }
+  free (stage);
+}
+
+static void
+free_flt_list ()
+{
+  if (flt_list)
+    {
+      MPlist *plist, *pl;
+
+      MPLIST_DO (plist, flt_list)
+       {
+         MFLT *flt = MPLIST_VAL (plist);
+
+         if (flt->coverage)
+           unref_category_table (flt->coverage);
+         if (flt->stages)
+           {
+             MPLIST_DO (pl, MPLIST_NEXT (flt->stages))
+               free_flt_stage (flt, MPLIST_VAL (pl));
+             M17N_OBJECT_UNREF (flt->stages);
+           }
+         free (flt);
+         MPLIST_VAL (plist) = NULL;
+       }
+      M17N_OBJECT_UNREF (flt_list);
+    }
+}
+
+static int
+list_flt ()
+{
+  MPlist *plist, *key_list = NULL;
+  MPlist *pl;
+  int result = 0;
+
+  if (! (plist = mdatabase_list (Mfont, Mlayouter, Mnil, Mnil)))
+    return -1;
+  if (! (flt_list = mplist ()))
+    goto err;
+  if (! (key_list = mplist ()))
+    goto err;
+  if (! mplist_add (key_list, Mcategory, Mt))
+    goto err;
+
+  MPLIST_DO (pl, plist)
+    {
+      MDatabase *mdb = MPLIST_VAL (pl);
+      MSymbol *tags = mdatabase_tag (mdb);
+      MFLT *flt;
+
+      if (! MSTRUCT_CALLOC_SAFE (flt))
+       goto err;
+      flt->name = tags[2];
+      flt->mdb = mdb;
+      if (load_flt (flt, key_list) < 0)
+       free (flt);
+      else
+       {
+         if (MPLIST_TAIL_P (flt_list))
+           {
+             flt_min_coverage = mchartable_min_char (flt->coverage->table);
+             flt_max_coverage = mchartable_max_char (flt->coverage->table);
+           }
+         else
+           {
+             int c;
+
+             c = mchartable_min_char (flt->coverage->table);
+             if (flt_min_coverage > c)
+               flt_min_coverage = c;
+             c = mchartable_max_char (flt->coverage->table);
+             if (flt_max_coverage < c)
+               flt_max_coverage = c;
+           }
+         if (! mplist_push (flt_list, flt->name, flt))
+           goto err;
+       }
+    }
+  goto end;
+
+ err:
+  free_flt_list ();
+  result = -1;
+ end:
+  M17N_OBJECT_UNREF (plist);  
+  M17N_OBJECT_UNREF (key_list);
+  return result;
+}
+
+/* FLS (Font Layout Service) */
+
+/* Structure to hold information about a context of FLS.  */
+
+typedef struct
+{
+  /* Pointer to the current stage.  */
+  FontLayoutStage *stage;
+
+  /* Pointer to the category table of the next stage or NULL if none.  */
+  FontLayoutCategory *category;
+
+  /* Pointer to the font.  */
+  MFLTFont *font;
+
+  /* Input and output glyph string.  */
+  MFLTGlyphString *in, *out;
+
+  /* Encode each character or code of a glyph by the current category
+     table into this array.  An element is a category letter used for
+     a regular expression matching.  */
+  char *encoded;
+  int encoded_offset;
+  int *match_indices;
+  int code_offset;
+  int cluster_begin_idx;
+  int cluster_begin_pos;
+  int cluster_end_pos;
+  int combining_code;
+  int left_padding;
+  int check_mask;
+} FontLayoutContext;
+
+static int run_command (int, int, int, int, FontLayoutContext *);
+static int run_otf (int, MFLTOtfSpec *, int, int, FontLayoutContext *);
+static int try_otf (int, MFLTOtfSpec *, int, int, FontLayoutContext *);
+
+#define NMATCH 20
+
+static int
+run_rule (int depth,
+         FontLayoutCmdRule *rule, int from, int to, FontLayoutContext *ctx)
+{
+  int *saved_match_indices = ctx->match_indices;
+  int match_indices[NMATCH * 2];
+  int consumed;
+  int i;
+  int orig_from = from;
+  int need_cluster_update = 0;
+
+  if (rule->src_type == SRC_REGEX)
+    {
+      regmatch_t pmatch[NMATCH];
+      char saved_code;
+      int result;
+
+      if (from > to)
+       return 0;
+      saved_code = ctx->encoded[to - ctx->encoded_offset];
+      ctx->encoded[to - ctx->encoded_offset] = '\0';
+      result = regexec (&(rule->src.re.preg),
+                       ctx->encoded + (from - ctx->encoded_offset),
+                       NMATCH, pmatch, 0);
+      if (result == 0 && pmatch[0].rm_so == 0)
+       {
+         if (MDEBUG_FLAG () > 2)
+           MDEBUG_PRINT5 ("\n [FLT] %*s(REGEX \"%s\" \"%s\" %d", depth, "",
+                          rule->src.re.pattern,
+                          ctx->encoded + (from - ctx->encoded_offset),
+                          pmatch[0].rm_eo);
+         ctx->encoded[to - ctx->encoded_offset] = saved_code;
+         for (i = 0; i < NMATCH; i++)
+           {
+             if (pmatch[i].rm_so < 0)
+               match_indices[i * 2] = match_indices[i * 2 + 1] = -1;
+             else
+               {
+                 match_indices[i * 2] = from + pmatch[i].rm_so;
+                 match_indices[i * 2 + 1] = from + pmatch[i].rm_eo;
+               }
+           }
+         ctx->match_indices = match_indices;
+         to = match_indices[1];
+       }
+      else
+       {
+         ctx->encoded[to - ctx->encoded_offset] = saved_code;
+         return 0;
+       }
+      need_cluster_update = 1;
+    }
+  else if (rule->src_type == SRC_SEQ)
+    {
+      int len;
+
+      len = rule->src.seq.n_codes;
+      if (len > (to - from))
+       return 0;
+      for (i = 0; i < len; i++)
+       if (rule->src.seq.codes[i] != GREF (ctx->in, from + i)->c)
+         break;
+      if (i < len)
+       return 0;
+      to = from + len;
+      if (MDEBUG_FLAG () > 2)
+       MDEBUG_PRINT3 ("\n [FLT] %*s(SEQ 0x%X", depth, "",
+                      rule->src.seq.codes[0]);
+      need_cluster_update = 1;
+    }
+  else if (rule->src_type == SRC_RANGE)
+    {
+      int head;
+
+      if (from >= to)
+       return 0;
+      head = GREF (ctx->in, from)->c;
+      if (head < rule->src.range.from || head > rule->src.range.to)
+       return 0;
+      ctx->code_offset = head - rule->src.range.from;
+      to = from + 1;
+      if (MDEBUG_FLAG () > 2)
+       MDEBUG_PRINT4 ("\n [FLT] %*s(RANGE 0x%X-0x%X", depth, "",
+                      rule->src.range.from, rule->src.range.to);
+      need_cluster_update = 1;
+    }
+  else if (rule->src_type == SRC_INDEX)
+    {
+      if (rule->src.match_idx >= NMATCH)
+       return 0;
+      from = ctx->match_indices[rule->src.match_idx * 2];
+      if (from < 0)
+       return 0;
+      to = ctx->match_indices[rule->src.match_idx * 2 + 1];
+      if (MDEBUG_FLAG () > 2)
+       MDEBUG_PRINT3 ("\n [FLT] %*s(SUBPART %d", depth, "",
+                      rule->src.match_idx);
+      need_cluster_update = 1;
+    }
+  else if (rule->src_type == SRC_HAS_GLYPH
+          || rule->src_type == SRC_OTF_SPEC)
+    {
+      static MFLTGlyphString gstring;
+      MPlist *p;
+      int idx;
+
+      if (rule->src.facility.len > 0)
+       {
+         if (! gstring.glyph_size)
+           {
+             gstring.glyph_size = ctx->in->glyph_size;
+             gstring.glyphs = calloc (rule->src.facility.len,
+                                      gstring.glyph_size);
+             gstring.allocated = rule->src.facility.len;
+             gstring.used = rule->src.facility.len;
+           }
+         else if (rule->src.facility.len < gstring.allocated)
+           {
+             gstring.glyphs = realloc (gstring.glyphs,
+                                       gstring.glyph_size
+                                       * rule->src.facility.len);
+             gstring.allocated = rule->src.facility.len;
+             gstring.used = rule->src.facility.len;
+           }
+
+         for (i = 0, p = rule->src.facility.codes, idx = from;
+              i < rule->src.facility.len; i++, p = MPLIST_NEXT (p))
+           {
+             if (MPLIST_INTEGER_P (p))
+               {
+                 GREF (&gstring, i)->c = MPLIST_INTEGER (p);
+                 GREF (&gstring, i)->encoded = 0;
+               }
+             else
+               {
+                 GREF (&gstring, i)->c = GREF (ctx->in, idx)->code;
+                 GREF (&gstring, i)->encoded = GREF (ctx->in, idx)->encoded;
+                 idx++;
+               }
+           }
+       }
+
+      if (MDEBUG_FLAG () > 2)
+       {
+         if (rule->src_type == SRC_HAS_GLYPH)
+           MDEBUG_PRINT2 ("\n [FLT] %*s(HAS-GLYPH", depth, "");
+         else
+           MDEBUG_PRINT2 ("\n [FLT] %*s(OTF-SPEC", depth, "");
+         for (i = 0; i < rule->src.facility.len; i++)
+           MDEBUG_PRINT1 (" %04X", GREF (&gstring, i)->code);
+       }
+      if (ctx->font->get_glyph_id (ctx->font, &gstring, 0,
+                                  rule->src.facility.len) < 0)
+       {
+         MDEBUG_PRINT (") FAIL!");
+         return 0;
+       }
+      if (rule->src_type == SRC_OTF_SPEC)
+       {
+         MFLTOtfSpec *spec = &rule->src.facility.otf_spec;
+
+         if (! ctx->font->check_otf)
+           {
+             if ((spec->features[0] && spec->features[0][0] != 0xFFFFFFFF)
+                 || (spec->features[1] && spec->features[1][0] != 0xFFFFFFFF))
+               return 0;
+           }
+         else
+           {
+             if (rule->src.facility.len == 0)
+               {
+                 if (! ctx->font->check_otf (ctx->font, spec))
+                   return 0;
+               }
+             else
+               {
+                 int prev_out_used = ctx->out->used, out_used;
+                 MFLTGlyphAdjustment *adjustment;
+
+                 adjustment = alloca ((sizeof *adjustment)
+                                      * (ctx->out->allocated - ctx->out->used));
+                 if (! adjustment)
+                   MERROR (MERROR_FLT, -1);
+                 memset (adjustment, 0,
+                         (sizeof *adjustment)
+                         * (ctx->out->allocated - ctx->out->used));
+                 ctx->font->drive_otf (ctx->font, &rule->src.facility.otf_spec,
+                                       &gstring, 0, rule->src.facility.len,
+                                       ctx->out,
+                                       adjustment);
+                 out_used = ctx->out->used;
+                 ctx->out->used = prev_out_used;
+                 if (rule->src.facility.len == out_used - prev_out_used)
+                   {
+                     for (i = prev_out_used; i < out_used; i++)
+                       {
+                         if (GREF (&gstring, i - prev_out_used)->code
+                             != GREF (ctx->out, i)->code)
+                           break;
+                         if (adjustment[i - prev_out_used].set)
+                           break;
+                       }
+                     if (i == out_used)
+                       return 0;
+                   }
+               }
+           }
+       }
+    }
+
+  if (need_cluster_update && ctx->cluster_begin_idx >= 0)
+    {
+      for (i = from; i < to; i++)
+       {
+         MFLTGlyph *g = GREF (ctx->in, i);
+         UPDATE_CLUSTER_RANGE (ctx, g);
+       }
+    }
+
+  consumed = 0;
+  depth++;
+  for (i = 0; i < rule->n_cmds; i++)
+    {
+      int pos;
+
+      if (rule->cmd_ids[i] == CMD_ID_REPEAT)
+       {
+         if (! consumed)
+           continue;
+         i--;
+       }
+      pos = run_command (depth, rule->cmd_ids[i], from, to, ctx);
+      if (pos < 0)
+       return pos;
+      consumed = pos > from;
+      if (consumed)
+       from = pos;
+    }
+
+  ctx->match_indices = saved_match_indices;
+  if (MDEBUG_FLAG () > 2)
+    MDEBUG_PRINT (")");
+  return (rule->src_type == SRC_INDEX ? orig_from : to);
+}
+
+static int
+run_cond (int depth,
+         FontLayoutCmdCond *cond, int from, int to, FontLayoutContext *ctx)
+{
+  int i, pos = 0;
+
+  if (MDEBUG_FLAG () > 2)
+    MDEBUG_PRINT2 ("\n [FLT] %*s(COND", depth, "");
+  depth++;
+  for (i = 0; i < cond->n_cmds; i++)
+    {
+      /* TODO: Write a code for optimization utilizaing the info
+        cond->seq_XXX.  */
+      if ((pos = run_command (depth, cond->cmd_ids[i], from, to, ctx))
+         != 0)
+       break;
+    }
+  if (pos < 0)
+    return pos;
+  if (MDEBUG_FLAG () > 2)
+    MDEBUG_PRINT (")");
+  return (pos);
+}
+
+static void
+decode_packed_otf_tag (FontLayoutContext *ctx, MFLTGlyphString *gstring,
+                      int from, int to, FontLayoutCategory *category)
+{
+  for (; from < to; from++)
+    {
+      MFLTGlyph *g = GREF (gstring, from);
+      unsigned int tag = g->internal & 0xFFFFFFF;
+      char enc;
+
+      if (GET_COMBINED (g))
+       continue;
+      if (! category)
+       {
+         SET_CATEGORY_CODE (g, 0);
+         continue;
+       }
+      if (tag & 0xFFFFF80)
+       {
+         int i;
+
+         /* Clear the feature tag code.  */
+         g->internal &= ~0xFFFFFFF;
+         for (i = 0, enc = '\0'; i < category->feature_table.size; i++)
+           if (category->feature_table.tag[i] == tag)
+             {
+               enc = category->feature_table.code[i];
+               if (ctx->in == gstring)
+                 ctx->encoded[from - ctx->encoded_offset] = enc;
+               break;
+             }
+       }
+      else
+       enc = '\0';
+      if (! enc)
+       enc = g->c > 0 ? (int) mchartable_lookup (category->table, g->c) : 1;
+      SET_CATEGORY_CODE (g, enc);
+    }
+}
+
+static int
+run_otf (int depth,
+        MFLTOtfSpec *otf_spec, int from, int to, FontLayoutContext *ctx)
+{
+  MFLTFont *font = ctx->font;
+  int from_idx = ctx->out->used;
+
+  if (MDEBUG_FLAG () > 2)
+    MDEBUG_PRINT3 ("\n [FLT] %*s%s", depth, "", MSYMBOL_NAME (otf_spec->sym));
+
+  font->get_glyph_id (font, ctx->in, from, to);
+  if (! font->drive_otf)
+    {
+      if (ctx->out->used + (to - from) > ctx->out->allocated)
+       return -2;
+      font->get_metrics (font, ctx->in, from, to);
+      GCPY (ctx->in, from, to - from, ctx->out, ctx->out->used);
+      ctx->out->used += to - from;
+    }
+  else
+    {
+      MFLTGlyphAdjustment *adjustment;
+      int out_len;
+      int i;
+
+      adjustment = alloca ((sizeof *adjustment)
+                          * (ctx->out->allocated - ctx->out->used));
+      if (! adjustment)
+       MERROR (MERROR_FLT, -1);
+      memset (adjustment, 0,
+             (sizeof *adjustment) * (ctx->out->allocated - ctx->out->used));
+      to = font->drive_otf (font, otf_spec, ctx->in, from, to, ctx->out,
+                           adjustment);
+      if (to < 0)
+       return to;
+      decode_packed_otf_tag (ctx, ctx->out, from_idx, ctx->out->used,
+                            ctx->category);
+      out_len = ctx->out->used - from_idx;
+      if (otf_spec->features[1])
+       {
+         MFLTGlyphAdjustment *a;
+         MFLTGlyph *g;
+         
+         for (i = 0, a = adjustment; i < out_len; i++, a++)
+           if (a->set)
+             break;
+         if (i < out_len)
+           {
+             font->get_metrics (font, ctx->out, from_idx, ctx->out->used);
+             for (g = GREF (ctx->out, from_idx + i);
+                  i < out_len; i++, a++, g = NEXT (ctx->out, g))
+               if (a->set)
+                 {
+                   if (a->advance_is_absolute)
+                     {
+                       g->xadv = a->xadv;
+                       g->yadv = a->yadv;
+                     }
+                   else if (a->xadv || a->yadv)
+                     {
+                       g->xadv += a->xadv;
+                       g->yadv += a->yadv;
+                     }
+                   if (a->xoff || a->yoff || a->back)
+                     {
+                       int j;
+                       MFLTGlyph *gg = PREV (ctx->out, g);
+                       MFLTGlyphAdjustment *aa = a;
+
+                       g->xoff = a->xoff;
+                       g->yoff = a->yoff;
+                       g->lbearing += a->xoff;
+                       g->rbearing += a->xoff;
+                       g->ascent -= a->yoff;
+                       g->descent -= a->yoff;
+                       while (aa->back > 0)
+                         {
+                           for (j = 0; j < aa->back;
+                                j++, gg = PREV (ctx->out, gg))
+                             {
+                               g->xoff -= gg->xadv;
+                               g->lbearing -= gg->xadv;
+                               g->rbearing -= gg->xadv;
+                             }
+                           aa = aa - aa->back;
+                           g->xoff += aa->xoff;
+                           g->yoff += aa->yoff;
+                           g->lbearing += aa->xoff;
+                           g->rbearing += aa->xoff;
+                           g->ascent -= aa->yoff;
+                           g->descent -= aa->yoff;
+                         }
+                     }
+                   g->adjusted = 1;
+                 }
+           }
+       }
+    }
+
+  if (ctx->cluster_begin_idx >= 0)
+    for (; from_idx < ctx->out->used; from_idx++)
+      {
+       MFLTGlyph *g = GREF (ctx->out, from_idx);
+       UPDATE_CLUSTER_RANGE (ctx, g);
+      }
+  return to;
+}
+
+static int
+try_otf (int depth, MFLTOtfSpec *otf_spec, int from, int to,
+        FontLayoutContext *ctx)
+{
+  MFLTFont *font = ctx->font;
+  int from_idx = ctx->out->used;
+
+  if (MDEBUG_FLAG () > 2)
+    MDEBUG_PRINT3 ("\n [FLT] %*s%s", depth, "", MSYMBOL_NAME (otf_spec->sym));
+
+  if (! otf_spec->features[0] && ! otf_spec->features[1])
+    {
+      /* Reset categories.  */
+      MCharTable *table = ctx->category->table;
+      int i;
+
+      for (i = from; i < to; i++)
+       {
+         MFLTGlyph *g = GREF (ctx->in, i);
+
+         if (! GET_COMBINED (g))
+           {
+             char enc = (GET_ENCODED (g)
+                         ? (g->c > 0 ? (int) mchartable_lookup (table, g->c)
+                            : 1)
+                         : g->code
+                         ? (int) mchartable_lookup (table, g->code)
+                         : ' ');
+             SET_CATEGORY_CODE (g, enc);
+             ctx->encoded[i - ctx->encoded_offset] = enc;
+           }
+       }
+      return from;
+    }
+
+  if (ctx->stage->category->feature_table.size == 0)
+    return from;
+
+  font->get_glyph_id (font, ctx->in, from, to);
+  if (mflt_try_otf)
+    {
+      int out_len;
+      int i;
+
+      to = mflt_try_otf (font, otf_spec, ctx->in, from, to);
+      if (to < 0)
+       return from;
+      decode_packed_otf_tag (ctx, ctx->in, from, to, ctx->stage->category);
+    }
+  return from;
+}
+
+static char work[16];
+
+static char *
+dump_combining_code (int code)
+{
+  char *vallign = "tcbB";
+  char *hallign = "lcr";
+  char *p;
+  int off_x, off_y;
+
+  if (! code)
+    return "none";
+  work[0] = vallign[COMBINING_CODE_BASE_Y (code)];
+  work[1] = hallign[COMBINING_CODE_BASE_X (code)];
+  off_y = COMBINING_CODE_OFF_Y (code);
+  off_x = COMBINING_CODE_OFF_X (code);
+  if (off_y > 0)
+    sprintf (work + 2, "+%d", off_y);
+  else if (off_y < 0)
+    sprintf (work + 2, "%d", off_y);
+  else if (off_x == 0)
+    sprintf (work + 2, ".");
+  p = work + strlen (work);
+  if (off_x > 0)
+    sprintf (p, ">%d", off_x);
+  else if (off_x < 0)
+    sprintf (p, "<%d", -off_x);
+  p += strlen (p);
+  p[0] = vallign[COMBINING_CODE_ADD_Y (code)];
+  p[1] = hallign[COMBINING_CODE_ADD_X (code)];
+  p[2] = '\0';
+  return work;
+}
+
+static int
+run_command (int depth, int id, int from, int to, FontLayoutContext *ctx)
+{
+  MFLTGlyph *g;
+
+  if (id >= 0)
+    {
+      int i;
+      MCharTable *table = ctx->category ? ctx->category->table : NULL;
+      char enc;
+
+      /* Direct code (== ctx->code_offset + id) output.
+        The source is not consumed.  */
+      if (MDEBUG_FLAG () > 2)
+       MDEBUG_PRINT3 ("\n [FLT] %*s(DIRECT 0x%X", depth, "",
+                      ctx->code_offset + id);
+      i = (from < to || from == 0) ? from : from - 1;
+      GDUP (ctx, i);
+      g = GREF (ctx->out, ctx->out->used - 1);
+      g->c = g->code = ctx->code_offset + id;
+      if (ctx->combining_code)
+       SET_COMBINING_CODE (g, ctx, ctx->combining_code);
+      else if (table)
+       {
+         enc = (GET_ENCODED (g)
+                ? (g->c > 0 ? (int) mchartable_lookup (table, g->c) : 1)
+                : g->code
+                ? (int) mchartable_lookup (table, g->code)
+                : ' ');
+         SET_CATEGORY_CODE (g, enc);
+       }
+      SET_ENCODED (g, 0);
+      SET_MEASURED (g, 0);
+      if (ctx->left_padding)
+       SET_LEFT_PADDING (g, ctx, LeftPaddingMask);
+      for (i = from; i < to; i++)
+       {
+         MFLTGlyph *tmp = GREF (ctx->in, i);
+
+         if (g->from > tmp->from)
+           g->from = tmp->from;
+         else if (g->to < tmp->to)
+           g->to = tmp->to;
+       }
+      if (ctx->cluster_begin_idx >= 0)
+       UPDATE_CLUSTER_RANGE (ctx, g);
+      ctx->code_offset = ctx->combining_code = ctx->left_padding = 0;
+      if (MDEBUG_FLAG () > 2)
+       MDEBUG_PRINT (")");
+      return (from);
+    }
+
+  if (id <= CMD_ID_OFFSET_INDEX)
+    {
+      int idx = CMD_ID_TO_INDEX (id);
+      FontLayoutCmd *cmd;
+
+      if (idx >= ctx->stage->used)
+       MERROR (MERROR_DRAW, -1);
+      cmd = ctx->stage->cmds + idx;
+      if (cmd->type == FontLayoutCmdTypeRule)
+       to = run_rule (depth, &cmd->body.rule, from, to, ctx);
+      else if (cmd->type == FontLayoutCmdTypeCond)
+       to = run_cond (depth, &cmd->body.cond, from, to, ctx);
+      else if (cmd->type == FontLayoutCmdTypeOTF)
+       to = run_otf (depth, &cmd->body.otf, from, to, ctx);
+      else if (cmd->type == FontLayoutCmdTypeOTFCategory)
+       to = try_otf (depth, &cmd->body.otf, from, to, ctx);
+      return to;
+    }
+
+  if (id <= CMD_ID_OFFSET_COMBINING)
+    {
+      ctx->combining_code = CMD_ID_TO_COMBINING_CODE (id);
+      if (MDEBUG_FLAG () > 2)
+       MDEBUG_PRINT3 ("\n [FLT] %*s(CMB %s)", depth, "",
+                      dump_combining_code (ctx->combining_code));
+      return from;
+    }
+
+  switch (id)
+    {
+    case CMD_ID_COPY:
+      {
+       if (from >= to)
+         return from;
+       GDUP (ctx, from);
+       g = GREF (ctx->out, ctx->out->used - 1);
+       if (ctx->combining_code)
+         SET_COMBINING_CODE (g, ctx, ctx->combining_code);
+       if (ctx->left_padding)
+         SET_LEFT_PADDING (g, ctx, LeftPaddingMask);
+       if (ctx->cluster_begin_idx >= 0)
+         UPDATE_CLUSTER_RANGE (ctx, g);
+       if (MDEBUG_FLAG () > 2)
+         {
+           if (g->c < 0)
+             MDEBUG_PRINT2 ("\n [FLT] %*s(COPY |)", depth, "");
+           else
+             MDEBUG_PRINT3 ("\n [FLT] %*s(COPY 0x%X)", depth, "", g->c);
+         }
+       ctx->code_offset = ctx->combining_code = ctx->left_padding = 0;
+       return (from + 1);
+      }
+
+    case CMD_ID_CLUSTER_BEGIN:
+      if (ctx->cluster_begin_idx < 0)
+       {
+         if (MDEBUG_FLAG () > 2)
+           MDEBUG_PRINT3 ("\n [FLT] %*s<%d", depth, "",
+                          GREF (ctx->in, from)->from);
+         ctx->cluster_begin_idx = ctx->out->used;
+         ctx->cluster_begin_pos = GREF (ctx->in, from)->from;
+         ctx->cluster_end_pos = GREF (ctx->in, from)->to;
+       }
+      return from;
+
+    case CMD_ID_CLUSTER_END:
+      if (ctx->cluster_begin_idx >= 0
+         && ctx->cluster_begin_idx < ctx->out->used)
+       {
+         int i;
+
+         if (MDEBUG_FLAG () > 2)
+           MDEBUG_PRINT1 (" %d>", ctx->cluster_end_pos + 1);
+         for (i = ctx->cluster_begin_idx; i < ctx->out->used; i++)
+           {
+             GREF (ctx->out, i)->from = ctx->cluster_begin_pos;
+             GREF (ctx->out, i)->to = ctx->cluster_end_pos;
+           }
+         ctx->cluster_begin_idx = -1;
+       }
+      return from;
+
+    case CMD_ID_SEPARATOR:
+      {
+       int i;
+
+       i = from < to ? from : from - 1;
+       GDUP (ctx, i);
+       g = GREF (ctx->out, ctx->out->used - 1);
+       g->c = -1, g->code = 0;
+       g->xadv = g->yadv = 0;
+       SET_ENCODED (g, 0);
+       SET_MEASURED (g, 0);
+       SET_CATEGORY_CODE (g, ' ');
+       return from;
+      }
+
+    case CMD_ID_LEFT_PADDING:
+      if (MDEBUG_FLAG () > 2)
+       MDEBUG_PRINT2 ("\n [FLT] %*s[", depth, "");
+      ctx->left_padding = 1;
+      return from;
+
+    case CMD_ID_RIGHT_PADDING:
+      if (ctx->out->used > 0)
+       {
+         if (MDEBUG_FLAG () > 2)
+           MDEBUG_PRINT2 ("\n [FLT] %*s]", depth, "");
+         g = GREF (ctx->out, ctx->out->used - 1);
+         SET_RIGHT_PADDING (g, ctx, RightPaddingMask);
+       }
+      return from;
+    }
+
+  MERROR (MERROR_DRAW, -1);
+}
+
+static int
+run_stages (MFLTGlyphString *gstring, int from, int to,
+           MFLT *flt, FontLayoutContext *ctx)
+{
+  MFLTGlyphString buf, *temp;
+  int stage_idx = 0;
+  int orig_from = from, orig_to = to;
+  int from_pos, to_pos, len;
+  int i, j;
+  MFLTGlyph *g;
+  MPlist *stages = flt->stages;
+  FontLayoutCategory *prev_category = NULL;
+
+  from_pos = GREF (ctx->in, from)->from;
+  to_pos = GREF (ctx->in, to - 1)->to;
+  len = to_pos - from_pos;
+
+  buf = *(ctx->in);
+  buf.glyphs = NULL;
+  GINIT (ctx->out, ctx->out->allocated);
+  ctx->encoded = alloca (ctx->out->allocated);
+  if (! ctx->out->glyphs || ! ctx->encoded)
+    return -1;
+
+  for (stage_idx = 0; 1; stage_idx++)
+    {
+      MCharTable *table;
+      int result;
+
+      ctx->stage = (FontLayoutStage *) MPLIST_VAL (stages);
+      table = ctx->stage->category->table;
+      stages = MPLIST_NEXT (stages);
+      if (MPLIST_TAIL_P (stages))
+       ctx->category = NULL;
+      else
+       ctx->category = ((FontLayoutStage *) MPLIST_VAL (stages))->category;
+      ctx->code_offset = ctx->combining_code = ctx->left_padding = 0;
+      ctx->encoded_offset = from;
+      for (i = from; i < to; i++)
+       {
+         MFLTGlyph *g = GREF (ctx->in, i);
+         char enc;
+
+         if (GET_COMBINED (g)
+             || (prev_category && prev_category != ctx->stage->category))
+           {
+             enc = (GET_ENCODED (g)
+                    ? (g->c > 0 ? (int) mchartable_lookup (table, g->c) : 1)
+                    : g->code
+                    ? (int) mchartable_lookup (table, g->code)
+                    : ' ');
+             if (! GET_COMBINED (g))
+               SET_CATEGORY_CODE (g, enc);
+           }
+         else
+           enc = GET_CATEGORY_CODE (g);
+         ctx->encoded[i - from] = enc;
+         if (! enc && stage_idx == 0)
+           {
+             to = i;
+             break;
+           }
+       }
+      ctx->encoded[i - from] = '\0';
+      ctx->match_indices[0] = from;
+      ctx->match_indices[1] = to;
+      for (i = 2; i < NMATCH; i++)
+       ctx->match_indices[i] = -1;
+
+      if (MDEBUG_FLAG () > 2)
+       {
+         MDEBUG_PRINT2 ("\n [FLT]   (STAGE %d \"%s\"", stage_idx,
+                        ctx->encoded);
+         MDEBUG_PRINT (" (");
+         for (i = from; i < to; i++)
+           {
+             g = GREF (ctx->in, i);
+             if (g->c == -1)
+               MDEBUG_PRINT2 ("%*s|", (i > 0), "");
+             else
+               MDEBUG_PRINT3 ("%*s%04X", (i > 0), "", GREF (ctx->in, i)->code);
+           }
+         MDEBUG_PRINT (")");
+       }
+      result = run_command (4, INDEX_TO_CMD_ID (0), from, to, ctx);
+      if (MDEBUG_FLAG () > 2)
+       MDEBUG_PRINT (")");
+      if (result < 0)
+       return result;
+
+      /* If this is the last stage, break the loop. */
+      if (MPLIST_TAIL_P (stages))
+       break;
+
+      /* Otherwise, prepare for the next stage.   */
+      prev_category = ctx->stage->category;
+      temp = ctx->in;
+      ctx->in = ctx->out;
+      if (buf.glyphs)
+       ctx->out = temp;
+      else
+       {
+         GINIT (&buf, ctx->out->allocated);
+         ctx->out = &buf;
+       }
+      ctx->out->used = 0;
+
+      from = 0;
+      to = ctx->in->used;
+    }
+
+  if (ctx->out->used > 0)
+    {
+      int *g_indices;
+      int x_ppem = ctx->font->x_ppem << 6, y_ppem = ctx->font->y_ppem << 6;
+
+      /* Remove separator glyphs.  */
+      for (i = 0; i < ctx->out->used;)
+       {
+         g = GREF (ctx->out, i);
+         if (g->c < 0)
+           GREPLACE (NULL, 0, 0, ctx->out, i, i + 1);
+         else
+           i++;
+       }
+
+      /* Get actual glyph IDs of glyphs.  */
+      ctx->font->get_glyph_id (ctx->font, ctx->out, 0, ctx->out->used);
+
+      /* Check if all characters in the range are covered by some
+        glyph(s).  If not, change <from> and <to> of glyphs to cover
+        uncovered characters.  */
+      g_indices = alloca (sizeof (int) * len);
+      if (! g_indices)
+       return -1;
+      for (i = 0; i < len; i++) g_indices[i] = -1;
+      for (i = 0; i < ctx->out->used; i++)
+       {
+         int pos;
+
+         g = GREF (ctx->out, i);
+         for (pos = g->from; pos <= g->to; pos++)
+           if (g_indices[pos - from_pos] < 0)
+             g_indices[pos - from_pos] = i;
+       }
+      for (i = 0; i < len; i++)
+       if (g_indices[i] < 0)
+         {
+           if (i == 0)
+             {
+               int this_from;
+
+               for (i++; i < len && g_indices[i] < 0; i++);
+               j = g_indices[i];
+               g = GREF (ctx->out, j);
+               this_from = g->from;
+               do {
+                 g->from = orig_from + i;
+               } while (++j < ctx->out->used
+                        && (g = GREF (ctx->out, j))
+                        && g->from == this_from);
+             }
+           else
+             {
+               int this_to;
+
+               j = g_indices[i - 1];
+               g = GREF (ctx->out, j);
+               this_to = g->to;
+               do {
+                 g->to = orig_from + i + 1;
+               } while (--j >= 0
+                        && (g = GREF (ctx->out, j))
+                        && g->to == this_to);
+             }
+         }
+
+      ctx->font->get_metrics (ctx->font, ctx->out, 0, ctx->out->used);
+
+      /* Handle combining.  */
+      if (ctx->check_mask & CombinedMask)
+       {
+         MFLTGlyph *base = GREF (ctx->out, 0);
+         int base_height = base->ascent + base->descent;
+         int base_width = base->rbearing - base->lbearing;
+         int combining_code;
+
+         for (i = 1; i < ctx->out->used; i++)
+           {
+             if ((g = GREF (ctx->out, i))
+                 && GET_COMBINED (g)
+                 && (combining_code = GET_COMBINING_CODE (g)))
+               {
+                 int height = g->ascent + g->descent;
+                 int width = g->rbearing - g->lbearing;
+                 int base_x, base_y, add_x, add_y, off_x, off_y;
+
+                 if (base->from > g->from)
+                   base->from = g->from;
+                 else if (base->to < g->to)
+                   base->to = g->to;
+               
+                 base_x = COMBINING_CODE_BASE_X (combining_code);
+                 base_y = COMBINING_CODE_BASE_Y (combining_code);
+                 add_x = COMBINING_CODE_ADD_X (combining_code);
+                 add_y = COMBINING_CODE_ADD_Y (combining_code);
+                 off_x = COMBINING_CODE_OFF_X (combining_code);
+                 off_y = COMBINING_CODE_OFF_Y (combining_code);
+
+                 g->xoff = ((base_width * base_x - width * add_x) / 2
+                            + x_ppem * off_x / 100
+                            - (base->xadv - base->lbearing) - g->lbearing);
+                 if (base_y < 3)
+                   g->yoff = base_height * base_y / 2 - base->ascent;
+                 else
+                   g->yoff = 0;
+                 if (add_y < 3)
+                   g->yoff -= height * add_y / 2 - g->ascent;
+                 g->yoff -= y_ppem * off_y / 100;
+                 if (base->lbearing > base->xadv + g->lbearing + g->xoff)
+                   base->lbearing = base->xadv + g->lbearing + g->xoff;
+                 if (base->rbearing < base->xadv + g->rbearing + g->xoff)
+                   base->rbearing = base->xadv + g->rbearing + g->xoff;
+                 if (base->ascent < g->ascent - g->yoff)
+                   base->ascent = g->ascent - g->yoff;
+                 if (base->descent < g->descent - g->yoff)
+                   base->descent = g->descent - g->yoff;
+                 g->xadv = g->yadv = 0;
+                 if (GET_RIGHT_PADDING (g))
+                   SET_RIGHT_PADDING (base, ctx, RightPaddingMask);
+                 g->adjusted = 1;
+               }
+             else
+               {
+                 base = g;
+                 base_height = g->ascent + g->descent;
+                 base_width = g->rbearing - g->lbearing;
+               }
+           }
+       }
+
+      /* Handle padding */
+      if (ctx->check_mask & (LeftPaddingMask | RightPaddingMask))
+       for (i = 0; i < ctx->out->used; i++)
+         {
+           g = GREF (ctx->out, i);
+           if (! GET_COMBINED (g))
+             {
+               if (GET_RIGHT_PADDING (g) && g->rbearing > g->xadv)
+                 {
+                   g->xadv = g->rbearing;
+                   g->adjusted = 1;
+                 }
+               if (GET_LEFT_PADDING (g) && g->lbearing < 0)
+                 {
+                   g->xoff += - g->lbearing;
+                   g->xadv += - g->lbearing;
+                   g->rbearing += - g->lbearing;
+                   g->lbearing = 0;
+                   g->adjusted = 1;
+                 }
+             }
+         }
+    }
+
+  GREPLACE (ctx->out, 0, ctx->out->used, gstring, orig_from, orig_to);
+  to = orig_from + ctx->out->used;
+  return to;
+}
+
+static void
+setup_combining_coverage (int from, int to, void *val, void *arg)
+{
+  int combining_class = (int) val;
+  int category = 0;
+
+  if (combining_class < 200)
+    category = 'a';
+  else if (combining_class <= 204)
+    {
+      if ((combining_class % 2) == 0)
+       category = "bcd"[(combining_class - 200) / 2];
+    }
+  else if (combining_class <= 232)
+    {
+      if ((combining_class % 2) == 0)
+       category = "efghijklmnopq"[(combining_class - 208) / 2];
+    }
+  else if (combining_class == 233)
+    category = 'r';
+  else if (combining_class == 234)
+    category = 's';
+  else if (combining_class == 240)
+    category = 't';
+  mchartable_set_range ((MCharTable *) arg, from, to, (void *) category);
+}
+
+static void
+setup_combining_flt (MFLT *flt)
+{
+  MSymbol type;
+  MCharTable *combininig_class_table
+    = mchar_get_prop_table (Mcombining_class, &type);
+
+  mchartable_set_range (flt->coverage->table, 0, 0x10FFFF, (void *) 'u');
+  if (combininig_class_table)
+    mchartable_map (combininig_class_table, (void *) 0,
+                   setup_combining_coverage, flt->coverage->table);
+}
+
+#define CHECK_FLT_STAGES(flt) ((flt)->stages || load_flt (flt, NULL) == 0)
+
+static FontLayoutCategory *
+configure_category (FontLayoutCategory *category, MFLTFont *font)
+{
+  if (! mflt_font_id || ! mflt_iterate_otf_feature)
+    {
+      FontLayoutCategory *new = malloc (sizeof (FontLayoutCategory));
+      new->definition = NULL;
+      new->table = category->table;
+      M17N_OBJECT_REF (new->table);
+      return new;
+    }
+  return load_category_table (category->definition, font);
+}
+
+static MFLT *
+configure_flt (MFLT *flt, MFLTFont *font, MSymbol font_id)
+{
+  MPlist *plist;
+  MFLT *configured;
+
+  if (! mflt_font_id || ! mflt_iterate_otf_feature)
+    return flt;
+  MPLIST_DO (plist, flt_list)
+    {
+      configured = MPLIST_VAL (plist);
+      if (! configured->font_id)
+       break;
+      if (configured->name == flt->name
+         && configured->font_id == font_id)
+       return configured;
+    }
+  if (! MSTRUCT_CALLOC_SAFE (configured))
+    return flt;
+  *configured = *flt;
+  configured->stages = mplist_copy (flt->stages);
+  MPLIST_DO (plist, configured->stages)
+    {
+      FontLayoutStage *stage = MPLIST_VAL (plist);
+      if (stage->category->definition)
+       {
+         MSTRUCT_CALLOC (stage, MERROR_FLT);
+         *stage = *((FontLayoutStage *) MPLIST_VAL (plist));
+         stage->category = configure_category (stage->category, font);
+         MPLIST_VAL (plist) = stage;
+       }
+      else
+       M17N_OBJECT_REF (stage->category->table);
+    }
+  configured->need_config = 0;
+  configured->font_id = font_id;
+  mplist_push (flt_list, flt->name, configured);
+  return configured;
+}
+\f
+/* Internal API */
+
+int m17n__flt_initialized;
+
+\f
+/* External API */
+
+/* The following two are actually not exposed to a user but concealed
+   by the macro M17N_INIT (). */
+
+void
+m17n_init_flt (void)
+{
+  int mdebug_flag = MDEBUG_INIT;
+
+  merror_code = MERROR_NONE;
+  if (m17n__flt_initialized++)
+    return;
+  m17n_init_core ();
+  if (merror_code != MERROR_NONE)
+    {
+      m17n__flt_initialized--;
+      return;
+    }
+
+  MDEBUG_PUSH_TIME ();
+
+  Mcond = msymbol ("cond");
+  Mrange = msymbol ("range");
+  Mfont = msymbol ("font");
+  Mlayouter = msymbol ("layouter");
+  Mcombining = msymbol ("combining");
+  Mfont_facility = msymbol ("font-facility");
+  Mequal = msymbol ("=");
+  Mgenerator = msymbol ("generator");
+  Mend = msymbol ("end");
+
+  mflt_enable_new_feature = 0;
+  mflt_iterate_otf_feature = NULL;
+  mflt_font_id = NULL;
+  mflt_try_otf = NULL;
+
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the flt modules."));
+  MDEBUG_POP_TIME ();
+}
+
+void
+m17n_fini_flt (void)
+{
+  int mdebug_flag = MDEBUG_FINI;
+
+  if (m17n__flt_initialized == 0
+      || --m17n__flt_initialized > 0)
+    return;
+
+  MDEBUG_PUSH_TIME ();
+  free_flt_list ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the flt modules."));
+  MDEBUG_POP_TIME ();
+  m17n_fini_core ();
+}
+
+/*** @} */ 
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+/*** @addtogroup m17nFLT */
+/*** @{ */
+/*=*/
+
+/*=*/
+/***en
+    @brief Return an FLT object that has a specified name.
+
+    The mflt_get () function returns an FLT object whose name is $NAME.
+
+    @return
+    If the operation was successful, mflt_get () returns a pointer
+    to the found FLT object.  Otherwise, it returns @c NULL.  */
+
+/***ja
+    @brief »ØÄꤵ¤ì¤¿Ì¾Á°¤ò»ý¤Ä FLT ¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤¹.
+
+    ´Ø¿ô mflt_get () ¤Ï¡¢$NAME ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä FLT ¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤¹¡£
+
+    @return
+    ¤â¤·À®¸ù¤¹¤ì¤Ð¡¢mflt_get () ¤Ï¸«¤Ä¤«¤Ã¤¿ FLT
+    ¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¼ºÇÔ¤·¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤¹¡£  */
+
+MFLT *
+mflt_get (MSymbol name)
+{
+  MFLT *flt;
+  MPlist *plist;
+
+  if (! flt_list && list_flt () < 0)
+    return NULL;
+  for (plist = flt_list; plist; plist = plist->next)
+    if (((MFLT *) MPLIST_VAL (plist))->font_id == Mnil)
+      break;
+  flt = mplist_get (plist, name);
+  if (! flt || ! CHECK_FLT_STAGES (flt))
+    return NULL;
+  if (flt->name == Mcombining
+      && ! mchartable_lookup (flt->coverage->table, 0))
+    setup_combining_flt (flt);
+
+  return flt;
+}
+
+/*=*/
+/***en
+    @brief Find an FLT suitable for the specified character and font.
+
+    The mflt_find () function returns the most appropriate FLT for
+    layouting character $C with font $FONT.
+
+    @return
+    If the operation was successful, mflt_find () returns a pointer
+    to the found FLT object.  Otherwise, it returns @c NULL.  */
+
+/***ja
+    @brief »ØÄꤵ¤ì¤¿Ê¸»ú¤È¥Õ¥©¥ó¥È¤Ë¹ç¤Ã¤¿ FLT ¤òõ¤¹.
+
+    ´Ø¿ô mflt_find () ¤Ï¡¢Ê¸»ú $C ¤ò¥Õ¥©¥ó¥È $FONT
+    ¤Ç¥ì¥¤¥¢¥¦¥È¤¹¤ë¤¿¤á¤ËºÇ¤âŬÀڤʠFLT ¤òÊÖ¤¹¡£
+
+    @return
+    ¤â¤·À®¸ù¤¹¤ì¤Ð¡¢mflt_find () ¤Ï¸«¤Ä¤«¤Ã¤¿ FLT
+    ¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¼ºÇÔ¤·¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤¹¡£  */
+
+MFLT *
+mflt_find (int c, MFLTFont *font)
+{
+  MPlist *plist, *pl;
+  MFLT *flt;
+  static MSymbol unicode_bmp = NULL, unicode_full = NULL;
+
+  if (! unicode_bmp)
+    {
+      unicode_bmp = msymbol ("unicode-bmp");
+      unicode_full = msymbol ("unicode-full");
+    }
+
+  if (! flt_list && list_flt () < 0)
+    return NULL;
+  /* Skip configured FLTs.  */
+  MPLIST_DO (plist, flt_list)
+    if (((MFLT *) MPLIST_VAL (plist))->font_id == Mnil)
+      break;
+  if (font)
+    {
+      MFLT *best = NULL;
+
+      MPLIST_DO (pl, plist)
+       {
+         flt = MPLIST_VAL (pl);
+         if (flt->registry != unicode_bmp
+             && flt->registry != unicode_full)
+           continue;
+         if (flt->family && flt->family != font->family)
+           continue;
+         if (flt->name == Mcombining
+             && ! mchartable_lookup (flt->coverage->table, 0))
+           setup_combining_flt (flt);
+         if (c >= 0
+             && ! mchartable_lookup (flt->coverage->table, c))
+           continue;
+         if (flt->otf.sym)
+           {
+             MFLTOtfSpec *spec = &flt->otf;
+
+             if (! font->check_otf)
+               {
+                 if ((spec->features[0] && spec->features[0][0] != 0xFFFFFFFF)
+                     || (spec->features[1] && spec->features[1][0] != 0xFFFFFFFF))
+                   continue;
+               }
+             else if (! font->check_otf (font, spec))
+               continue;
+             goto found;
+           }
+         best = flt;
+       }
+      if (best == NULL)
+       return NULL;
+      flt = best;
+      goto found;
+    }
+  if (c >= 0)
+    {
+      MPLIST_DO (pl, plist)
+       {
+         flt = MPLIST_VAL (pl);
+         if (mchartable_lookup (flt->coverage->table, c))
+           goto found;
+       }
+    }
+  return NULL;
+
+ found:
+  if (! CHECK_FLT_STAGES (flt))
+    return NULL;
+  if (font && flt->need_config && mflt_font_id)
+    flt = configure_flt (flt, font, mflt_font_id (font));
+  return flt;
+}
+
+/*=*/
+/***en
+    @brief Return the name of an FLT.
+
+    The mflt_name () function returns the name of $FLT.  */
+
+/***ja
+    @brief FLT ¤Î̾Á°¤òÊÖ¤¹.
+
+    ´Ø¿ô mflt_name () ¤Ï $FLT ¤Î̾Á°¤òÊÖ¤¹¡£  */
+
+const char *
+mflt_name (MFLT *flt)
+{
+  return MSYMBOL_NAME (flt->name);
+}
+
+/*=*/
+/***en
+    @brief Return a coverage of a FLT.
+
+    The mflt_coverage () function returns a char-table that contains
+    nonzero values for characters supported by $FLT.  */
+
+/***ja
+    @brief FLT ¤ÎÈϰϤòÊÖ¤¹.
+
+    ´Ø¿ô mflt_coverage () ¤Ï¡¢$FLT ¤¬¥µ¥Ý¡¼¥È¤¹¤ëʸ»ú¤ËÂФ·¤Æ
+    0 ¤Ç¤Ê¤¤Ãͤò´Þ¤àʸ»ú¥Æ¡¼¥Ö¥ë¤òÊÖ¤¹¡£  */
+
+MCharTable *
+mflt_coverage (MFLT *flt)
+{
+  return flt->coverage->table;
+}
+
+/*=*/
+/***en
+    @brief Layout characters with an FLT.
+
+    The mflt_run () function layouts characters in $GSTRING between
+    $FROM (inclusive) and $TO (exclusive) with $FONT.  If $FLT is
+    nonzero, it is used for all the charaters.  Otherwise, appropriate
+    FLTs are automatically chosen.
+
+    @retval >=0
+    The operation was successful.  The value is the index to the
+    glyph, which was previously indexed by $TO, in $GSTRING->glyphs.
+
+    @retval -2
+    $GSTRING->glyphs is too short to store the result.  The caller can
+    call this fucntion again with a longer $GSTRING->glyphs.
+
+    @retval -1
+    Some other error occurred.  */
+
+/***ja
+    @brief FLT ¤ò»È¤Ã¤Æʸ»ú¤ò¥ì¥¤¥¢¥¦¥È¤¹¤ë.
+
+    ´Ø¿ô mflt_run () ¤Ï¡¢$GSTRING Ãæ¤Î $FROM ¤«¤é $TO Ä¾Á°¤Þ¤Ç¤Îʸ»ú¤ò
+    $FONT ¤òÍѤ¤¤Æ¥ì¥¤¥¢¥¦¥È¤¹¤ë¡£¤â¤· $FLT
+    ¤¬¥¼¥í¤Ç¤Ê¤±¤ì¤Ð¡¢¤½¤ÎÃͤò¤¹¤Ù¤Æ¤Îʸ»ú¤ËÂФ·¤ÆÍѤ¤¤ë¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤ÐŬÀڤʠFLT ¤ò¼«Æ°Åª¤ËÁªÂò¤¹¤ë¡£
+
+    @retval >=0
+    ¼Â¹ÔÀ®¸ù¤ò¼¨¤¹¡£ÊÖ¤µ¤ì¤ëÃͤϡ¢$GSTRING->glyphs Ãæ¤Ç°ÊÁ° $TO
+    ¤Ë¤è¤Ã¤Æ¼¨¤µ¤ì¤Æ¤¤¤¿¥°¥ê¥Õ¤Ø¤Î¥¤¥ó¥Ç¥¯¥¹¤Ç¤¢¤ë¡£
+
+    @retval -2
+    ·ë²Ì¤ò³ÊǼ¤¹¤ë¤Ë¤Ï $GSTRING->glyphs ¤¬Ã»¤¹¤®¤ë¤³¤È¤ò¼¨¤¹¡£
+    ¸Æ¤Ó½Ð¤·Â¦¤Ï¡¢¤è¤êŤ¤ $GSTRING->glyphs
+    ¤òÍѤ¤¤ÆºÆÅÙ¤³¤Î´Ø¿ô¤ò¸Æ¤Ö¤³¤È¤¬¤Ç¤­¤ë¡£
+
+    @retval -1
+    ¤½¤Î¾¤Î¥¨¥é¡¼¤¬µ¯¤­¤¿¤³¤È¤ò¼¨¤¹¡£  */
+
+int
+mflt_run (MFLTGlyphString *gstring, int from, int to,
+         MFLTFont *font, MFLT *flt)
+{
+  FontLayoutContext ctx;
+  int match_indices[NMATCH];
+  MFLTGlyph *g;
+  MFLTGlyphString out;
+  int auto_flt = ! flt;
+  int c, i, j, k;
+  int this_from, this_to;
+  MSymbol font_id = mflt_font_id ? mflt_font_id (font) : Mnil;
+
+  out = *gstring;
+  out.glyphs = NULL;
+  /* This is usually sufficient, but if not, we retry with the larger
+     values at most 3 times.  This value is also used for the
+     allocating size of ctx.encoded.  */
+  out.allocated = (to - from) * 4;
+
+  for (i = from; i < to; i++)
+    {
+      g = GREF (gstring, i);
+      if (! g->encoded)
+       {
+         c = g->c;
+         memset (g, 0, sizeof (MFLTGlyph));
+         g->code = g->c = c;
+       }
+      g->from = g->to = i;
+    }
+
+  for (this_from = from; this_from < to;)
+    {
+      if (! auto_flt)
+       {
+         for (this_to = this_from; this_to < to; this_to++)
+           if (mchartable_lookup (flt->coverage->table,
+                                  GREF (gstring, this_to)->c))
+             break;
+       }
+      else
+       {
+         if (! flt_list && list_flt () < 0)
+           {
+             font->get_glyph_id (font, gstring, this_from, to);
+             font->get_metrics (font, gstring, this_from, to);
+             this_from = to;
+             break;
+           }
+         for (this_to = this_from; this_to < to; this_to++)
+           {
+             c = GREF (gstring, this_to)->c;
+             if (c >= flt_min_coverage && c <= flt_max_coverage)
+               break;
+           }
+         for (; this_to < to; this_to++)
+           {
+             c = GREF (gstring, this_to)->c;
+             if (font->internal
+                 && mchartable_lookup (((MFLT *) font->internal)->coverage->table, c))
+               {
+                 flt = font->internal;
+                 break;
+               }
+             flt = mflt_find (c, font);
+             if (flt)
+               {
+                 if (CHECK_FLT_STAGES (flt))
+                   {
+                     font->internal = flt;
+                     break;
+                   }
+               }
+           }
+       }
+
+      if (this_from < this_to)
+       {
+         font->get_glyph_id (font, gstring, this_from, this_to);
+         font->get_metrics (font, gstring, this_from, this_to);
+         this_from = this_to;
+       }
+      if (this_to == to)
+       break;
+
+      MDEBUG_PRINT1 (" [FLT] (%s", MSYMBOL_NAME (flt->name));
+
+      if (flt->need_config && font_id != Mnil)
+       flt = configure_flt (flt, font, font_id);
+
+      for (; this_to < to; this_to++)
+       {
+         char enc;
+         g = GREF (gstring, this_to);
+         enc = (int) mchartable_lookup (flt->coverage->table, g->c);
+         if (! enc)
+           break;
+         SET_CATEGORY_CODE (g, enc);
+       }
+
+      if (MDEBUG_FLAG ())
+       {
+         if (font->family)
+           MDEBUG_PRINT1 (" (%s)", MSYMBOL_NAME (font->family));
+         MDEBUG_PRINT ("\n [FLT]   (SOURCE");
+         for (i = this_from, j = 0; i < this_to; i++, j++)
+           {
+             if (j > 0 && j % 8 == 0)
+               MDEBUG_PRINT ("\n [FLT]          ");
+             MDEBUG_PRINT1 (" %04X", GREF (gstring, i)->c);
+           }
+         MDEBUG_PRINT (")");
+       }
+
+      for (i = 0; i < 3; i++)
+       {
+         /* Setup CTX.  */
+         memset (&ctx, 0, sizeof ctx);
+         ctx.match_indices = match_indices;
+         ctx.font = font;
+         ctx.cluster_begin_idx = -1;
+         ctx.in = gstring;
+         ctx.out = &out;
+         j = run_stages (gstring, this_from, this_to, flt, &ctx);
+         if (j != -2)
+           break;
+         out.allocated *= 2;
+       }
+
+      if (j < 0)
+       return j;
+
+      to += j - this_to;
+      this_to = j;
+
+      if (MDEBUG_FLAG ())
+       {
+         MDEBUG_PRINT ("\n [FLT]   (RESULT");
+         if (MDEBUG_FLAG () > 1)
+           for (i = 0; this_from < this_to; this_from++, i++)
+             {
+               if (i > 0 && i % 4 == 0)
+                 MDEBUG_PRINT ("\n [FLT]          ");
+               g = GREF (gstring, this_from);
+               MDEBUG_PRINT4 (" (%04X %d %d %d)",
+                              g->code, g->xadv, g->xoff, g->yoff);
+             }
+         else
+           for (; this_from < this_to; this_from++)
+             MDEBUG_PRINT1 (" %04X", GREF (gstring, this_from)->code);
+         MDEBUG_PRINT ("))\n");
+       }
+      this_from = this_to;
+    }
+
+  if (gstring->r2l)
+    {
+      int len = to - from;
+
+      GINIT (&out, len);
+      memcpy (((char *) out.glyphs),
+             ((char *) gstring->glyphs) + gstring->glyph_size * from,
+             gstring->glyph_size * len);
+      for (i = from, j = to; i < to;)
+       {
+         for (k = i + 1, j--; k < to && GREF (&out, k)->xadv == 0;
+              k++, j--);
+         GCPY (&out, i, (k - i), gstring, j);
+         i = k;
+       }
+    }
+
+  return to;
+}
+
+int mflt_enable_new_feature;
+
+int (*mflt_iterate_otf_feature) (struct _MFLTFont *font,
+                                MFLTOtfSpec *spec,
+                                int from, int to,
+                                unsigned char *table);
+
+MSymbol (*mflt_font_id) (struct _MFLTFont *font);
+
+int (*mflt_try_otf) (struct _MFLTFont *font, MFLTOtfSpec *spec,
+                    MFLTGlyphString *gstring, int from, int to);
+
+\f
+/* for debugging... */
+
+static void
+dump_flt_cmd (FontLayoutStage *stage, int id, int indent)
+{
+  char *prefix = (char *) alloca (indent + 1);
+
+  memset (prefix, 32, indent);
+  prefix[indent] = 0;
+
+  if (id >= 0)
+    fprintf (stderr, "0x%02X", id);
+  else if (id <= CMD_ID_OFFSET_INDEX)
+    {
+      int idx = CMD_ID_TO_INDEX (id);
+      FontLayoutCmd *cmd = stage->cmds + idx;
+
+      if (cmd->type == FontLayoutCmdTypeRule)
+       {
+         FontLayoutCmdRule *rule = &cmd->body.rule;
+         int i;
+
+         fprintf (stderr, "(rule ");
+         if (rule->src_type == SRC_REGEX)
+           fprintf (stderr, "\"%s\"", rule->src.re.pattern);
+         else if (rule->src_type == SRC_INDEX)
+           fprintf (stderr, "%d", rule->src.match_idx);
+         else if (rule->src_type == SRC_SEQ)
+           fprintf (stderr, "(seq)");
+         else if (rule->src_type == SRC_RANGE)
+           fprintf (stderr, "(range)");
+         else
+           fprintf (stderr, "(invalid src)");
+
+         for (i = 0; i < rule->n_cmds; i++)
+           {
+             fprintf (stderr, "\n%s  ", prefix);
+             dump_flt_cmd (stage, rule->cmd_ids[i], indent + 2);
+           }
+         fprintf (stderr, ")");
+       }
+      else if (cmd->type == FontLayoutCmdTypeCond)
+       {
+         FontLayoutCmdCond *cond = &cmd->body.cond;
+         int i;
+
+         fprintf (stderr, "(cond");
+         for (i = 0; i < cond->n_cmds; i++)
+           {
+             fprintf (stderr, "\n%s  ", prefix);
+             dump_flt_cmd (stage, cond->cmd_ids[i], indent + 2);
+           }
+         fprintf (stderr, ")");
+       }
+      else if (cmd->type == FontLayoutCmdTypeOTF)
+       {
+         fprintf (stderr, "(otf)");
+       }
+      else
+       fprintf (stderr, "(error-command)");
+    }
+  else if (id <= CMD_ID_OFFSET_COMBINING)
+    fprintf (stderr, "cominging-code");
+  else
+    fprintf (stderr, "(predefiend %d)", id);
+}
+
+/***en
+    @brief Dump a Font Layout Table.
+
+    The mdebug_dump_flt () function prints the Font Layout Table $FLT
+    in a human readable way to the stderr.  $INDENT specifies how many
+    columns to indent the lines but the first one.
+
+    @return
+    This function returns $FLT.  */
+
+MFLT *
+mdebug_dump_flt (MFLT *flt, int indent)
+{
+  char *prefix = (char *) alloca (indent + 1);
+  MPlist *plist;
+  int stage_idx = 0;
+
+  memset (prefix, 32, indent);
+  prefix[indent] = 0;
+  fprintf (stderr, "(flt");
+  MPLIST_DO (plist, flt->stages)
+    {
+      FontLayoutStage *stage = (FontLayoutStage *) MPLIST_VAL (plist);
+      int i;
+
+      fprintf (stderr, "\n%s  (stage %d", prefix, stage_idx);
+      for (i = 0; i < stage->used; i++)
+       {
+         fprintf (stderr, "\n%s    ", prefix);
+         dump_flt_cmd (stage, INDEX_TO_CMD_ID (i), indent + 4);
+       }
+      fprintf (stderr, ")");
+      stage_idx++;
+    }
+  fprintf (stderr, ")");
+  return flt;
+}
+
+void
+mflt_dump_gstring (MFLTGlyphString *gstring)
+{
+  int i;
+
+  fprintf (stderr, "(flt-gstring");
+  for (i = 0; i < gstring->used; i++)
+    {
+      MFLTGlyph *g = GREF (gstring, i);
+      fprintf (stderr, "\n  (%02d pos:%d-%d c:%04X code:%04X cat:%c)",
+              i, g->from, g->to, g->c, g->code, GET_CATEGORY_CODE (g));
+    }
+  fprintf (stderr, ")\n");
+}
+
+/*** @} */
+
+/*
+ Local Variables:
+ coding: euc-japan
+ End:
+*/
diff --git a/src/m17n-flt.h b/src/m17n-flt.h
new file mode 100644 (file)
index 0000000..f1454aa
--- /dev/null
@@ -0,0 +1,424 @@
+/* m17n-flt.h -- header file for the FLT API of the m17n library.
+   Copyright (C) 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_FLT_H_
+#define _M17N_FLT_H_
+
+#ifndef _M17N_CORE_H_
+#include <m17n-core.h>
+#endif
+
+M17N_BEGIN_HEADER
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+
+extern void m17n_init_flt (void);
+#undef M17N_INIT
+#ifdef _M17N_H_
+#define M17N_INIT()                    \
+  do {                                 \
+    m17n_init ();                      \
+    if (merror_code == MERROR_NONE)    \
+      m17n_init_flt ();                        \
+  } while (0)
+#else  /* not _M17N_H_ */
+#define M17N_INIT() m17n_init_flt ()
+#endif /* not _M17N_H_ */
+
+extern void m17n_fini_flt (void);
+#undef M17N_FINI
+#ifdef _M17N_H_
+#define M17N_FINI()    \
+  do {                 \
+    m17n_fini_flt ();  \
+    m17n_fini ();      \
+  } while (0)
+#else  /* not _M17N_H_ */
+#define M17N_FINI() m17n_fini_flt ()
+#endif /* not _M17N_H_ */
+
+#endif
+
+/***en @defgroup m17nFLT FLT API
+    @brief API provided by libm17n-flt.so */
+/***ja @defgroup m17nFLT FLT API
+    @brief libm17n-flt.so ¤¬Ä󶡤¹¤ë API */
+/*=*/
+
+/*** @addtogroup m17nFLT */
+/*** @{ */
+/*=*/
+
+/***en
+    @brief Type of information about a glyph.
+
+    The type #MFLTGlyph is the structure that contains information
+    about a glyph.  */
+
+/***ja
+    @brief ¥°¥ê¥Õ¤Ë´Ø¤¹¤ë¾ðÊó¤Î·¿.
+
+    ·¿ #MFLTGlyph ¤Ï¡¢¥°¥ê¥Õ¤Ë´Ø¤¹¤ë¾ðÊó¤ò³ÊǼ¤¹¤ë¹½Â¤ÂΤǤ¢¤ë¡£  */
+
+typedef struct
+{
+  /***en Character code (Unicode) of the glyph.  This is the sole
+      member to be set before calling the functions mflt_find () and
+      mflt_run ().  */
+  /***ja ¥°¥ê¥Õ¤Î (Unicode ¤Ë¤ª¤±¤ë) Ê¸»ú¥³¡¼¥É¡£´Ø¿ô
+      mflt_find () ¤È mflt_run ()
+      ¤ò¸Æ¤Ó½Ð¤¹Á°¥»¥Ã¥È¤¹¤Ù¤­Í£°ì¤Î¥á¥ó¥Ð¡¼¤Ç¤¢¤ë¡£  */
+  int c;
+  /***en Glyph ID of the glyph in the font.  */
+  /***ja ¥Õ¥©¥ó¥ÈÆâ¤Ë¤ª¤±¤ë¤½¤Î¥°¥ê¥Õ¤Î ID¡£  */
+  unsigned int code;
+  /***en Starting index of the run in #MFLTGlyphString that is
+      replaced by this glyph.  */
+  /***ja #MFLTGlyphString
+      ¤ÎÃæ¤Ç¡¢¤³¤Î¥°¥ê¥Õ¤Ë¤è¤Ã¤ÆÃÖ¤­´¹¤¨¤é¤ì¤ëÉôʬ¤ÎÀèƬ¤Î¥¤¥ó¥Ç¥¯¥¹¡£  */
+  int from;
+  /***en Ending index of the run in #MFLTGlyphString that is
+      replaced by this glyph.  */
+  /***ja #MFLTGlyphString
+      ¤ÎÃæ¤Ç¡¢¤³¤Î¥°¥ê¥Õ¤Ë¤è¤Ã¤ÆÃÖ¤­´¹¤¨¤é¤ì¤ëÉôʬ¤ÎËöÈø¤Î¥¤¥ó¥Ç¥¯¥¹¡£  */
+  int to;
+  /***en Advance width for horizontal layout expressed in 26.6
+      fractional pixel format.  */
+  /***ja ²£½ñ¤­»þ¤ÎÁ÷¤êÉý¤ò 26.6 fractional pixel format ¤Çɽ¸½¤·¤¿¤â¤Î¡£  */
+  int xadv;
+  /***en Advance height for vertical layout expressed in 26.6
+      fractional pixel format.  */
+  /***ja ½Ä½ñ¤­»þ¤ÎÁ÷¤ê¹â¤ò 26.6 fractional pixel format ¤Çɽ¸½¤·¤¿¤â¤Î¡£  */
+  int yadv;
+  /* @{ */
+  /***en Ink metrics of the glyph expressed in 26.6 fractional pixel
+      format.  */
+  /***ja ¤³¤Î¥°¥ê¥Õ¤Î¥¤¥ó¥¯¥á¥È¥ê¥Ã¥¯¤ò 26.6 fractional pixel format
+      ¤Çɽ¸½¤·¤¿¤â¤Î¡£  */
+  int ascent, descent, lbearing, rbearing;
+  /* @} */
+  /* @{ */
+  /***en Horizontal and vertical adjustments for the glyph positioning
+      expressed in 26.6 fractional pixel format.  */
+  /***ja ¥°¥ê¥Õ°ÌÃÖ·è¤á¤ÎºÝ¤Î¿åÊ¿¡¦¿âľĴÀ°Ãͤò¡¢
+      26.6 fractional pixel format ¤Çɽ¸½¤·¤¿¤â¤Î¡£  */
+  int xoff, yoff;
+  /* @} */
+  /***en Flag to tell whether the member \<code\> has already been set
+      to a glyph ID in the font.  */
+  /***ja ¥á¥ó¥Ð¡¼ \<code\> ¤Ë´û¤Ë¥°¥ê¥Õ ID
+      ¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¤«Èݤ«¤ò¼¨¤¹¥Õ¥é¥°¡£  */
+  unsigned encoded : 1;
+  /***en Flag to tell if the metrics of the glyph (members \<xadv\> thru
+      \<rbearing\>) are already calculated.  */
+  /***ja ¥á¥ó¥Ð¡¼ \<xadv\> ¤«¤é \<rbearing\>
+      ¤Þ¤Ç¤Î³Æ¥á¥È¥ê¥Ã¥¯¤¬´û¤Ë·×»»ºÑ¤«Èݤ«¤ò¼¨¤¹¥Õ¥é¥°¡£  */
+  unsigned measured : 1;
+  /***en Flag to tell if the metrics of the glyph is adjusted,
+      i.e. \<xadv\> or \<yadv\> is different from the normal size, or
+      \<xoff\> or \<yoff\> is nonzero.  */
+  /***ja ¥°¥ê¥Õ¤Î¥á¥È¥ê¥Ã¥¯¤¬Ä´À°ºÑ¤ß¤«Èݤ«¡¢
+      ¤¹¤Ê¤ï¤Á°Ê²¼¤Î¤¦¤Á1¤Ä°Ê¾å¤¬À®Î©¤·¤Æ¤¤¤ë¤³¤È¤ò¼¨¤¹¥Õ¥é¥°¡£
+      \<xadv\> ¤¬É¸½à¤ÎÃͤȰۤʤ롢
+      \<yadv\> ¤¬É¸½à¤ÎÃͤȰۤʤ롢
+      \<xoff\> ¤¬¥¼¥í¤Ç¤Ê¤¤¡¢
+      \<yoff\> ¤¬¥¼¥í¤Ç¤Ê¤¤¡£  */
+  unsigned adjusted : 1;
+  /***en For m17n-lib's internal use only.  */
+  /***ja m17n-lib ÆâÉôºî¶ÈÍÑ¡£  */
+  unsigned internal : 30;
+
+  /* Arbitrary data can follow.  */
+} MFLTGlyph;
+
+/*=*/
+
+/***en
+    @brief Type of information about a glyph position adjustment.
+
+    The type #MFLTGlyphAdjustment is the structure to store
+    information about a glyph metrics/position adjustment.  It is
+    given to the callback function @b drive_otf of #MFLTFont.  */
+
+/***ja
+    @brief ¥°¥ê¥Õ°ÌÃÖÄ´À°¾ðÊó¤Î¤¿¤á¤Î·¿.
+
+    ·¿ #MFLTGlyphAdjustment
+    ¤Ï¡¢¥°¥ê¥Õ¤Î¥á¥È¥ê¥Ã¥¯/°ÌÃÖ¤ÎÄ´À°¤Ë´Ø¤¹¤ë¾ðÊó¤ò³ÊǼ¤¹¤ë¤¿¤á¤Î¹½Â¤ÂΤǤ¢¤ê¡¢
+    #MFLTFont ¤Î callback ´Ø¿ô @b drive_otf ¤ËÅϤµ¤ì¤ë¡£  */
+
+typedef struct
+{
+  /* @{ */
+  /***en Adjustments for advance width for horizontal layout and
+      advance height for vertical layout expressed in 26.6 fractional
+      pixel format.  */
+  /***ja ¿åÊ¿¡¦¿âľÊý¸þ¤ÎÁ÷¤êÎ̤ÎÄ´À°Ãͤò 26.6 fractional pixel format
+      ¤Çɽ¸½¤·¤¿¤â¤Î¡£  */
+  int xadv, yadv;
+  /* @} */
+  /* @{ */
+  /***en Horizontal and vertical adjustments for glyph positioning
+      expressed in 26.6 fractional pixel format.  */
+  /***ja ¥°¥ê¥Õ°ÌÃÖ·è¤á¤¿¤á¤Î¿åÊ¿¡¦¿âľĴÀ°Ãͤò 26.6 fractional pixel
+      format ¤Çɽ¸½¤·¤¿¤â¤Î¡£  */
+  int xoff, yoff;
+  /* @} */
+  /***en Number of glyphs to go back for drawing a glyph.  */
+  /***ja ¥°¥ê¥ÕÉÁ²è¤Î¤¿¤á¤ËÌá¤ë¤Ù¤­¥°¥ê¥Õ¿ô¡£  */
+  short back;
+  /***en If nonzero, the member \<xadv\> and \<yadv\> are absolute, i.e.,
+      they should not be added to a glyph's origianl advance width and
+      height.  */
+  /***ja Èó¥¼¥í¤Î¤È¤­¡¢¥á¥ó¥Ð¡¼ \<xadv\> ¤È \<yadv\> ¤ÏÀäÂÐÃͤǤ¢¤ë¡£
+      ¤¹¤Ê¤ï¤Á¤½¤ÎÃͤò¥°¥ê¥ÕËÜÍè¤ÎÁ÷¤êÉý¤Ë²Ã»»¤·¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£  */
+  unsigned advance_is_absolute : 1;
+  /***en Should be set to 1 iff at least one of the other members has
+      a nonzero value.  */
+  /***ja Â¾¤Î¥á¥ó¥Ð¡¼¤Î¤¦¤ÁºÇÄã1¸Ä¤¬Èó¥¼¥í¤Î¤È¤­¤Î¤ß¡¢1¤Ë¥»¥Ã¥È¤µ¤ì¤ë¡£  */
+  unsigned set : 1;
+} MFLTGlyphAdjustment;
+
+/*=*/
+
+/***en
+    @brief Type of information about a glyph sequence.
+
+    The type #MFLTGlyphString is the structure that contains
+    information about a sequence of glyphs.  */
+
+/***ja
+    @brief ¥°¥ê¥ÕÎó¤Î¾ðÊó¤Î¤¿¤á¤Î·¿.
+
+    ·¿ #MFLTGlyphString ¤Ï¡¢¥°¥ê¥ÕÎó¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë¤¿¤á¤Î¹½Â¤ÂΤǤ¢¤ë¡£  */
+
+typedef struct
+{
+  /***en The actual byte size of elements of the array pointed by the
+      member #glyphs.  It must be equal to or greater than "sizeof
+      (MFLTGlyph)".  */
+  /***ja ¥á¥ó¥Ð¡¼ #glyphs ¤Î»Ø¤¹ÇÛÎó¤ÎÍ×ÁǤ¬Àê¤á¤ë¼Â¥Ð¥¤¥È¿ô¡£
+      ¤³¤ÎÃͤϠ"sizeof (MFLTGlyph)" °Ê¾å¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£  */
+  int glyph_size;
+  /***en Array of glyphs.  */
+  /***ja ¥°¥ê¥Õ¤ÎÇÛÎó¡£  */
+  MFLTGlyph *glyphs;
+  /***en Number of elements allocated in #glyphs.  */
+  /***ja #glyphs Æâ¤ËÇÛÃÖ¤µ¤ì¤Æ¤¤¤ëÍ×ÁǤοô¡£  */
+  int allocated;
+  /***en Number of elements in #glyphs in use.  */
+  /***ja #glyphs Æâ¤Ç»ÈÍÑÃæ¤ÎÍ×ÁǤοô¡£  */
+  int used;
+  /***en Flag to tell if the glyphs should be drawn from right-to-left
+      or not.  */
+  /***ja ¥°¥ê¥Õ¤¬±¦¤«¤éº¸¤Ø¤ÈÉÁ¤«¤ì¤ë¤Ù¤­¤«Èݤ«¤ò¼¨¤¹¥Õ¥é¥°¡£  */
+  unsigned int r2l;
+} MFLTGlyphString;
+
+/*=*/
+
+/***en
+    @brief Type of specification of GSUB and GPOS OpenType tables.
+
+    The type #MFLTOtfSpec is the structure that contains information
+    about the GSUB and GPOS features of a specific script and language
+    system to be applied to a glyph sequence.  */
+
+/***ja
+    @brief GSUB ¤ª¤è¤Ó GPOS OpenType ¥Æ¡¼¥Ö¥ë¤Î»ÅÍͤΤ¿¤á¤Î·¿.
+
+    ·¿ #MFLTOtfSpec ¤Ï¡¢GSUB ¤ª¤è¤Ó GPOS¥Õ¥£¡¼¥Á¥ã¡¼¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë¤¿
+    ¤á¤Î¹½Â¤ÂΤǤ¢¤ë¡£¤³¤ì¤é¥Õ¥£¡¼¥Á¥ã¡¼¤ÏÆÃÄê¤Î¥¹¥¯¥ê¥×¥È¤ª¤è¤Ó¸À¸ì¥·
+    ¥¹¥Æ¥à¤Î¤â¤Î¤Ç¤¢¤ê¡¢¥°¥ê¥ÕÎó¤ËŬÍѤµ¤ì¤ë¡£  */
+
+typedef struct
+{
+  /***en Unique symbol representing the spec.  This is the same as the
+      @ref OTF-SPEC of the FLT.  */
+  /***ja ¤³¤Î»ÅÍͤòɽ¤ï¤¹¥æ¥Ë¡¼¥¯¤Ê¥·¥ó¥Ü¥ë¡£
+      FLT ¤Î @ref OTF-SPEC ¤ÈƱ°ì¤ÎÃͤǤ¢¤ë¡£  */
+  MSymbol sym;
+
+  /* @{ */
+  /***en Tags for script and language system.  */
+  /***ja ¥¹¥¯¥ê¥×¥È¤ª¤è¤Ó¸À¸ì¥·¥¹¥Æ¥à¤Î¥¿¥°¡£  */
+  unsigned int script, langsys;
+  /* @} */
+
+  /***en Array of GSUB (1st element) and GPOS (2nd element) feature
+      tag arrays.  Each array is terminated by 0.  If the first
+      element is 0xFFFFFFFF, apply all the features except those that
+      appear in the following elements.  It may be NULL if there are
+      no features.  */
+  /***ja GSUB ¥Õ¥£¡¼¥Á¥ã¡¼¥¿¥°¤ÎÇÛÎó¤òÂè1Í×ÁÇ¡¢GPOS ¥Õ¥£¡¼¥Á¥ã¡¼¥¿¥°¤Î
+      ÇÛÎó¤òÂè2Í×ÁǤȤ¹¤ëÇÛÎó¡£³ÆÇÛÎó¤ÎËöÈø¤Ï0¤Ç¼¨¤µ¤ì¤ë¡£¤â¤·ºÇ½é¤ÎÍ×
+      ÁǤ¬ 0xFFFFFFFF¤Ê¤é¤Ð¡¢°Ê¹ß¤ÎÍ×ÁǤȤ·¤Æ¸½¤ï¤ì¤ë¥Õ¥£¥Á¥ã¡¼°Ê³°¤Î¤¹
+      ¤Ù¤Æ¤òŬÍѤ¹¤ë¡£¥Õ¥£¡¼¥Á¥ã¡¼¤¬1¤Ä¤â¤Ê¤¤¾ì¹ç¤Ï NULL ¤Ç¤â¤è¤¤¡£ */
+  unsigned int *features[2];
+} MFLTOtfSpec;
+
+/*=*/
+
+/***en
+    @brief Type of font to be used by the FLT driver.
+
+    The type #MFLTFont is the structure that contains information
+    about a font used by the FLT driver.  Usually, an application
+    should prepare a bigger structure whose first element is MFLTFont
+    and has more information about the font that is used by callback
+    funcitons, and give that structure to mflt functions by coercing
+    it to MFLTFont.  It is assured that callback functions can safely
+    coerce MFLTFont back to the original structure.  */
+
+/***ja
+    @brief FLT ¥É¥é¥¤¥Ð¤¬»È¤¦¥Õ¥©¥ó¥È¤Î·¿.
+
+    ·¿ #MFLTFont ¤Ï¡¢FLT¥É¥é¥¤¥Ð¤¬»È¤¦¥Õ¥©¥ó¥È¤Ë´Ø¤¹¤ë¾ðÊó¤ò³ÊǼ¤¹¤ë¤¿
+    ¤á¤Î¹½Â¤ÂΤǤ¢¤ë¡£Ä̾異¥×¥ê¥±¡¼¥·¥ç¥ó¤ÏºÇ½é¤ÎÍ×ÁǤ¬ MFLTFont ¤Ç¡¢
+    »Ä¤ê¤ÎÍ×ÁǤËcallback´Ø¿ô¤¬ÍøÍѤ¹¤ë¥Õ¥©¥ó¥È¾ðÊó¤ò»ý¤Ã¤¿¡¢¤è¤êÂ礭¤Ê
+    ¹½Â¤ÂΤòÍÑ°Õ¤·¡¢¤½¤ì¤ò MFLTFont ¤Ë coerce ¤·¤Æ mflt ¤Î³Æ´Ø¿ô¤ËÅϤ¹¡£
+    ³Æcallback´Ø¿ô¤Ï MFLTFont ¤ò¸µ¤Î¹½Â¤ÂΤˠcoerce ¤·Ä¾¤¹¤³¤È¤¬¤Ç¤­¤ë
+    ¤³¤È¤¬Êݾڤµ¤ì¤Æ¤¤¤ë¡£ */
+
+typedef struct _MFLTFont
+{
+  /***en Family name of the font.  It may be #Mnil if the family name
+     is not important in finding a Font Layout Table suitable for the
+     font (for instance, in the case that the font is an OpenType
+     font).  */
+  /***ja ¥Õ¥©¥ó¥È¤Î¥Õ¥¡¥ß¥ê¡¼Ì¾¡£¥Õ¥©¥ó¥È¤ËŬ¤·¤¿ FLT¤òõ¤¹ºÝ¤Ë½ÅÍפǤÊ
+      ¤¤¾ì¹ç (¤¿¤È¤¨¤Ð OpenType¥Õ¥©¥ó¥È¤Î¾ì¹ç¤Ê¤É) ¤Ï¡¢#Mnil ¤Ç¤è¤¤¡£ */
+  MSymbol family;
+
+  /***en Horizontal font sizes in pixels per EM.  */
+  /***ja ¥Õ¥©¥ó¥È¤Î¿åÊ¿¥µ¥¤¥º¤ò pixels per EM ¤Çɽ¸½¤·¤¿¤â¤Î¡£  */
+  int x_ppem;
+  /***en Vertical font sizes in pixels per EM.  */
+  /***ja ¥Õ¥©¥ó¥È¤Î¿âľ¥µ¥¤¥º¤ò pixels per EM ¤Çɽ¸½¤·¤¿¤â¤Î¡£  */
+  int y_ppem;
+
+  /***en Callback function to get glyph IDs for glyphs between FROM
+     (inclusive) and TO (exclusive) of GSTRING.  If the member \<encoded\>
+     of a glyph is zero, the member \<code\> of that glyph is a character
+     code.  The function must convert it to the glyph ID of FONT.  */
+  /***ja GSTRING Æâ¤Î FROM ¤«¤é TO Ä¾Á°¤Þ¤Ç¤Î³Æ¥°¥ê¥Õ¤ËÂбþ¤¹¤ë¥°¥ê¥Õ
+      ID¤ò¼èÆÀ¤¹¤ë¤¿¤á¤Î callback ´Ø¿ô¡£¤â¤·¤¢¤ë¥°¥ê¥Õ¤Î¥á¥ó¥Ð¡¼
+      \<encoded\>¤¬¥¼¥í¤Ê¤é¤Ð¡¢¤½¤Î¥°¥ê¥Õ¤Î¥á¥ó¥Ð¡¼ \<code\> ¤Ïʸ»ú¥³¡¼¥É¤Ç
+      ¤¢¤ë¡£¤³¤Î´Ø¿ô¤Ï¤½¤Îʸ»ú¥³¡¼¥É¤ò FONT ¤Î¥°¥ê¥Õ ID¤ËÊÑ´¹¤·¤Ê¤¯¤Æ¤Ï
+      ¤Ê¤é¤Ê¤¤¡£  */
+  int (*get_glyph_id) (struct _MFLTFont *font, MFLTGlyphString *gstring,
+                      int from, int to);
+
+  /***en Callback function to get metrics of glyphs between FROM
+     (inclusive) and TO (exclusive) of GSTRING.  If the member \<measured\>
+     of a glyph is zero, the function must set the members \<xadv\>, \<yadv\>,
+     \<ascent\>, \<descent\>, \<lbearing\>, and \<rbearing\> of the glyph.  */
+  /***ja GSTRING Æâ¤Î FROM ¤«¤é TOľÁ°¤Þ¤Ç¤Î³Æ¥°¥ê¥Õ¤ËÂбþ¤¹¤ë¥á¥È¥ê¥Ã
+      ¥¯¤ò¼èÆÀ¤¹¤ë¤¿¤á¤Î callback ´Ø¿ô¡£¤â¤·¤¢¤ë¥°¥ê¥Õ¤Î¥á¥ó¥Ð¡¼
+      \<measured\>¤¬¥¼¥í¤Ê¤é¤Ð¡¢¤³¤Î´Ø¿ô¤Ï¤½¤Î¥°¥ê¥Õ¤Î¥á¥ó¥Ð¡¼ \<xadv\>,
+      \<yadv\>, \<ascent\>, \<descent\>, \<lbearing\>, ¤ª¤è¤Ó \<rbearing\>¤ò¥»¥Ã
+      ¥È¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£  */
+  int (*get_metrics) (struct _MFLTFont *font, MFLTGlyphString *gstring,
+                    int from, int to);
+
+  /***en Callback function to check if the font has OpenType GSUB/GPOS
+     features for a specific script/language.  The function must
+     return 1, if the font satisfies SPEC, or 0.  It must be
+     NULL if the font does not have OpenType tables.  */
+  /***ja ¥Õ¥©¥ó¥È¤¬¤¢¤ëÆÃÄê¤Î¥¹¥¯¥ê¥×¥È/¸À¸ì¤ËÂФ¹¤ë GSUB/GPOS
+      OpenType¥Õ¥£¡¼¥Á¥ã¡¼¤ò»ý¤Ä¤«Èݤ«¤òÄ´¤Ù¤ë callback ´Ø¿ô¡£¤³¤Î´Ø¿ô
+      ¤Ï¥Õ¥©¥ó¥È¤¬SPEC ¤òËþ¤¿¤¹¤È¤­¤Ï 1 ¤ò¡¢¤½¤¦¤Ç¤Ê¤¤¤È¤­¤Ï 0¤òÊÖ¤µ¤Ê
+      ¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£¥Õ¥©¥ó¥È¤¬ OpenType ¥Æ¡¼¥Ö¥ë¤ò»ý¤¿¤Ê¤¤¤È¤­¤ÏNULL
+      ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£  */
+  int (*check_otf) (struct _MFLTFont *font, MFLTOtfSpec *spec);
+
+  /***en Callback function to apply OpenType features in SPEC to glyphs
+     between FROM (inclusive) and TO (exclusive) of IN.  The resulting
+     glyphs are appended to the tail of OUT.  If OUT does not
+     have a room to store all the resulting glyphs, it must return -2.
+     It must be NULL if the font does not have OpenType tables.  */
+  /***ja IN Æâ¤Î FROM ¤«¤é TO Ä¾Á°¤Þ¤Ç¤Î³Æ¥°¥ê¥Õ¤Ë SPECÆâ¤Î³Æ OpenType
+      ¥Õ¥£¡¼¥Á¥ã¡¼¤òŬÍѤ¹¤ë¤¿¤á¤Î callback ´Ø¿ô¡£Å¬ÍÑ·ë²Ì¤Î¥°¥ê¥ÕÎó¤Ï
+      OUT ¤ÎËöÈø¤ËÄɲ䵤ì¤ë¡£OUT ¤¬Ã»¤«²á¤®¤Æ·ë²Ì¤òÄɲä·ÀÚ¤ì¤Ê¤¤¾ì¹ç
+      ¤Ï -2 ¤òÊÖ¤µ¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¥Õ¥©¥ó¥È¤¬ OpenType ¥Æ¡¼¥Ö¥ë¤ò»ý¤¿
+      ¤Ê¤¤¾ì¹ç¤Ï NULL¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£  */
+  int (*drive_otf) (struct _MFLTFont *font, MFLTOtfSpec *spec,
+                   MFLTGlyphString *in, int from, int to,
+                   MFLTGlyphString *out, MFLTGlyphAdjustment *adjustment);
+
+  /***en For m17n-lib's internal use only.  It should be initialized
+      to NULL.  */
+  /***ja m17n-lib ¤ÎÆâÉôºî¶ÈÍÑ¡£NULL ¤Ë½éÃͲ½¤µ¤ì¤ë¡£  */
+  void *internal;
+} MFLTFont;
+
+/*=*/
+
+/***en
+    @brief Type of FLT (Font Layout Table).
+
+    The type #MFLT is for an FLT object.  Its internal structure is
+    concealed from application programs.  */
+
+/***ja
+    @brief FLT (Font Layout Table) ¤Î·¿.
+
+    ·¿ #MFLT ¤Ï FLT ¥ª¥Ö¥¸¥§¥¯¥È¤Î¤¿¤á¤Î·¿¤Ç¤¢¤ë¡£
+    ¤³¤ÎÆâÉô¹½Â¤¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤Ï±£Ê䵤ì¤Æ¤¤¤ë¡£  */
+
+typedef struct _MFLT MFLT;
+
+extern MFLT *mflt_get (MSymbol name);
+
+extern MFLT *mflt_find (int c, MFLTFont *font);
+
+extern const char *mflt_name (MFLT *flt);
+
+extern MCharTable *mflt_coverage (MFLT *flt);
+
+extern int mflt_run (MFLTGlyphString *gstring, int from, int to,
+                    MFLTFont *font, MFLT *flt);
+
+extern int mflt_enable_new_feature;
+
+extern MSymbol (*mflt_font_id) (MFLTFont *font);
+
+extern int (*mflt_iterate_otf_feature) (MFLTFont *font,
+                                       MFLTOtfSpec *spec,
+                                       int from, int to,
+                                       unsigned char *table);
+
+extern int (*mflt_try_otf) (struct _MFLTFont *font, MFLTOtfSpec *spec,
+                           MFLTGlyphString *gstring, int from, int to);
+
+/*=*/
+/*** @} */
+
+M17N_END_HEADER
+
+#endif /* _M17N_FLT_H_ */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/m17n-gd.c b/src/m17n-gd.c
new file mode 100644 (file)
index 0000000..99269e1
--- /dev/null
@@ -0,0 +1,884 @@
+/* m17n-gd.c -- implementation of the GUI API on GD Library.
+   Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include "config.h"
+
+#if defined (HAVE_FREETYPE) && defined (HAVE_GD)
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <gd.h>
+
+#include "m17n-gui.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "internal-gui.h"
+#include "symbol.h"
+#include "font.h"
+#include "fontset.h"
+#include "face.h"
+
+static MPlist *realized_fontset_list;
+static MPlist *realized_font_list;
+static MPlist *realized_face_list;
+
+/* The first element is for 256 color, the second for true color.  */
+static gdImagePtr scratch_images[2];
+
+enum ColorIndex
+  {
+    COLOR_NORMAL,
+    COLOR_INVERSE,
+    COLOR_HLINE,
+    COLOR_BOX_TOP,
+    COLOR_BOX_BOTTOM,
+    COLOR_BOX_LEFT,
+    COLOR_BOX_RIGHT,
+    COLOR_MAX
+  };
+
+static MSymbol M_rgb;
+
+static void
+read_rgb_txt ()
+{
+  FILE *fp;
+  int r, g, b, i;
+
+  /* At first, support HTML 4.0 color names. */
+  msymbol_put (msymbol ("black"), M_rgb, (void *) 0x000000);
+  msymbol_put (msymbol ("silver"), M_rgb, (void *) 0xC0C0C0);
+  msymbol_put (msymbol ("gray"), M_rgb, (void *) 0x808080);
+  msymbol_put (msymbol ("white"), M_rgb, (void *) 0xFFFFFF);
+  msymbol_put (msymbol ("maroon"), M_rgb, (void *) 0x800000);
+  msymbol_put (msymbol ("red"), M_rgb, (void *) 0xFF0000);
+  msymbol_put (msymbol ("purple"), M_rgb, (void *) 0x800080);
+  msymbol_put (msymbol ("fuchsia"), M_rgb, (void *) 0xFF00FF);
+  msymbol_put (msymbol ("green"), M_rgb, (void *) 0x008000);
+  msymbol_put (msymbol ("lime"), M_rgb, (void *) 0x00FF00);
+  msymbol_put (msymbol ("olive"), M_rgb, (void *) 0x808000);
+  msymbol_put (msymbol ("yellow"), M_rgb, (void *) 0xFFFF00);
+  msymbol_put (msymbol ("navy"), M_rgb, (void *) 0x000080);
+  msymbol_put (msymbol ("blue"), M_rgb, (void *) 0x0000FF);
+  msymbol_put (msymbol ("teal"), M_rgb, (void *) 0x008080);
+  msymbol_put (msymbol ("aqua"), M_rgb, (void *) 0x00FFFF);
+
+  {
+    char *rgb_path[]
+      =  {"/usr/lib/X11/rgb.txt", "/usr/X11R6/lib/X11/rgb.txt",
+         "/etc/X11/rgb.txt" };
+
+    fp = NULL;
+    for (i = 0; i < (sizeof rgb_path) / (sizeof rgb_path[0]); i++)
+      if ((fp = fopen ("/usr/lib/X11/rgb.txt", "r")))
+       break;
+    if (! fp)
+      return;
+  }
+  while (1)
+    {
+      char buf[256];
+      int c, len;
+
+      if ((c = getc (fp)) == EOF) 
+       break;
+      if (c == '!')
+       {
+         while ((c = getc (fp)) != EOF && c != '\n');
+         continue;
+       }
+      ungetc (c, fp);
+      if (fscanf (fp, "%d %d %d", &r, &g, &b) != 3)
+       break;
+      while ((c = getc (fp)) != EOF && isspace (c));
+      if (c == EOF)
+       break;
+      buf[0] = c;
+      fgets (buf + 1, 255, fp);
+      len = strlen (buf);
+      for (i = 0; i < len; i++)
+       buf[i] = tolower (buf[i]);
+      if (buf[len - 1] == '\n')
+       buf[len - 1] = '\0';
+      b |= (r << 16) | (g << 8);
+      msymbol_put (msymbol (buf), M_rgb, (void *) b);
+    }
+  fclose (fp);
+}
+   
+
+static int
+parse_color (MSymbol sym)
+{
+  char *name = MSYMBOL_NAME (sym);
+  unsigned r = 0x80, g = 0x80, b = 0x80;
+  int i;
+  
+  do {
+    if (strncmp (name , "rgb:", 4) == 0)
+      {
+       name += 4;
+       if (sscanf (name, "%x", &r) < 1)
+         break;
+       for (i = 0; *name != '/'; i++, name++);
+       r = (i == 1 ? ((r << 1) | r) : (r >> (i - 2)));
+       name++;
+       if (sscanf (name, "%x", &g) < 1)
+         break;
+       for (i = 0; *name != '/'; i++, name++);
+       g = (i == 1 ? ((g << 1) | g) : (g >> (i - 2)));
+       name += 4;
+       if (sscanf (name, "%x", &b) < 1)
+         break;
+       for (i = 0; *name; i++, name++);
+       b = (i == 1 ? ((b << 1) | b) : (b >> (i - 2)));
+      }
+    else if (*name == '#')
+      {
+       name++;
+       i = strlen (name);
+       if (i == 3)
+         {
+           if (sscanf (name, "%1x%1x%1x", &r, &g, &b) < 3)
+             break;
+           r <<= 4, g <<= 4, b <<= 4;
+         }
+       else if (i == 6)
+         {
+           if (sscanf (name, "%2x%2x%2x", &r, &g, &b) < 3)
+             break;
+         }
+       else if (i == 9)
+         {
+           if (sscanf (name, "%3x%3x%3x", &r, &g, &b) < 3)
+             break;
+           r >>= 1, g >>= 1, b >>= 1;
+         }
+       else if (i == 12)
+         {
+           if (sscanf (name, "%4x%4x%4x", &r, &g, &b) < 3)
+             break;
+           r >>= 2, g >>= 2, b >>= 2;
+         }
+      }
+    else
+      return (int) msymbol_get (sym, M_rgb);
+  } while (0);
+
+  return ((r << 16) | (g << 8) | b);
+}
+
+
+static gdImagePtr
+get_scrach_image (gdImagePtr img, int width, int height)
+{
+  int index;
+  gdImagePtr scratch;
+
+#if HAVE_GD == 1
+  index = 0;
+#else
+  index = img->trueColor ? 1 : 0;
+#endif
+  scratch = scratch_images[index];
+
+  if (scratch)
+    {
+      if (scratch->sx <= width && scratch->sy <= height)
+       return scratch;
+      gdImageDestroy (scratch);
+    }
+#if HAVE_GD > 1
+  if (img->trueColor)
+    scratch = scratch_images[1] = gdImageCreateTrueColor (width, height);
+  else
+#endif
+    scratch = scratch_images[0] = gdImageCreate (width, height);
+  return scratch;
+}  
+
+static int
+intersect_rectangle (MDrawMetric *r1, MDrawMetric *r2, MDrawMetric *rect)
+{
+  *rect = *r1;
+  if (rect->x < r2->x)
+    rect->width -= (r2->x - rect->x), rect->x = r2->x;
+  if (rect->x + rect->width > r2->x + r2->width)
+    rect->width -= (r2->x + r2->width - rect->x - rect->width);
+  if (rect->y < r2->y)
+    rect->height -= (r2->y - rect->y), rect->y = r2->y;
+  if (rect->y + rect->height > r2->y + r2->height)
+    rect->height -= (r2->y + r2->height - rect->y - rect->height);
+  return 1;
+}
+
+
+#define INTERSECT_RECTANGLE(r1, r2, rect)      \
+  (((r1)->x + (r1->width) <= (r2)->x           \
+    || (r2)->x + (r2)->width <= (r1)->x                \
+    || (r1)->y + (r1->height) <= (r2)->y       \
+    || (r2)->y + (r2)->height <= (r1)->y)      \
+   ? 0                                         \
+   : intersect_rectangle (r1, r2, rect))
+
+
+#define RESOLVE_COLOR(img, color)                                      \
+  gdImageColorResolve ((img), (color) >> 16, ((color) >> 8) & 0xFF,    \
+                      (color) & 0xFF)
+
+static MRealizedFont *gd_font_open (MFrame *, MFont *, MFont *,
+                                   MRealizedFont *);
+static void gd_render (MDrawWindow, int, int, MGlyphString *,
+                      MGlyph *, MGlyph *, int, MDrawRegion);
+
+static MFontDriver gd_font_driver =
+  { NULL, gd_font_open, NULL, NULL, NULL, gd_render, NULL };
+
+static MRealizedFont *
+gd_font_open (MFrame *frame, MFont *font, MFont *spec, MRealizedFont *rfont)
+{
+  double size = font->size ? font->size : spec->size;
+  int reg = spec->property[MFONT_REGISTRY];
+  MRealizedFont *new;
+
+  if (rfont)
+    {
+      MRealizedFont *save = NULL;
+
+      for (; rfont; rfont = rfont->next)
+       if (rfont->font == font
+           && (rfont->font->size ? rfont->font->size == size
+               : rfont->spec.size == size)
+           && rfont->spec.property[MFONT_REGISTRY] == reg)
+         {
+           if (! save)
+             save = rfont;
+           if (rfont->driver == &gd_font_driver)
+             return rfont;
+         }
+      rfont = save;
+    }
+  rfont = (mfont__ft_driver.open) (frame, font, spec, rfont);
+  if (! rfont)
+    return NULL;
+  M17N_OBJECT_REF (rfont->info);
+  MSTRUCT_CALLOC (new, MERROR_GD);
+  *new = *rfont;
+  new->driver = &gd_font_driver;
+  new->next = MPLIST_VAL (frame->realized_font_list);
+  MPLIST_VAL (frame->realized_font_list) = new;
+  return new;
+}
+
+static void
+gd_render (MDrawWindow win, int x, int y,
+          MGlyphString *gstring, MGlyph *from, MGlyph *to,
+          int reverse, MDrawRegion region)
+{
+  gdImagePtr img = (gdImagePtr) win;
+  FT_Face ft_face;
+  MRealizedFace *rface = from->rface;
+  FT_Int32 load_flags = FT_LOAD_RENDER;
+  int i, j;
+  int color, pixel;
+  int r, g, b;
+  
+  if (from == to)
+    return;
+
+  /* It is assured that the all glyphs in the current range use the
+     same realized face.  */
+  ft_face = rface->rfont->fontp;
+  color = ((int *) rface->info)[reverse ? COLOR_INVERSE : COLOR_NORMAL];
+  pixel = RESOLVE_COLOR (img, color);
+
+  if (gstring->anti_alias)
+    r = color >> 16, g = (color >> 8) & 0xFF, b = color & 0xFF;
+  else
+    {
+#ifdef FT_LOAD_TARGET_MONO
+      load_flags |= FT_LOAD_TARGET_MONO;
+#else
+      load_flags |= FT_LOAD_MONOCHROME;
+#endif
+    }
+
+  for (; from < to; x += from++->g.xadv)
+    {
+      unsigned char *bmp;
+      int xoff, yoff;
+      int width, pitch;
+
+      FT_Load_Glyph (ft_face, (FT_UInt) from->g.code, load_flags);
+      yoff = y - ft_face->glyph->bitmap_top + from->g.yoff;
+      bmp = ft_face->glyph->bitmap.buffer;
+      width = ft_face->glyph->bitmap.width;
+      pitch = ft_face->glyph->bitmap.pitch;
+      if (! gstring->anti_alias)
+       pitch *= 8;
+      if (width > pitch)
+       width = pitch;
+
+      if (gstring->anti_alias)
+       for (i = 0; i < ft_face->glyph->bitmap.rows;
+            i++, bmp += ft_face->glyph->bitmap.pitch, yoff++)
+         {
+           xoff = x + ft_face->glyph->bitmap_left + from->g.xoff;
+           for (j = 0; j < width; j++, xoff++)
+             if (bmp[j] > 0)
+               {
+                 int pixel1 = pixel;
+#if HAVE_GD > 1
+                 int alpha = gdAlphaTransparent * (255 - bmp[j]) / 255;
+
+                 if (alpha > 0)
+                   pixel1 = gdImageColorResolveAlpha (img, r, g, b, alpha);
+#else
+                 int f = bmp[j] >> 5;
+
+                 if (f < 7)
+                   {
+                     int r1, g1, b1, color1;
+
+                     pixel1 = gdImageGetPixel (img, xoff, yoff);
+                     r1 = gdImageRed (img, pixel1);
+                     g1 = gdImageGreen (img, pixel1);
+                     b1 = gdImageBlue (img, pixel1);
+                     color1 = ((((r * f + r1 * (7 - f)) / 7) << 16)
+                               | (((g * f + g1 * (7 - f)) / 7) << 8)
+                               | ((b * f + b1 * (7 - f)) / 7));
+                     pixel1 = RESOLVE_COLOR (img, color1);
+                   }
+#endif
+                 gdImageSetPixel (img, xoff, yoff, pixel1);
+               }
+         }
+      else
+       for (i = 0; i < ft_face->glyph->bitmap.rows;
+            i++, bmp += ft_face->glyph->bitmap.pitch, yoff++)
+         {
+           xoff = x + ft_face->glyph->bitmap_left + from->g.xoff;
+           for (j = 0; j < width; j++, xoff++)
+             if (bmp[j / 8] & (1 << (7 - (j % 8))))
+               gdImageSetPixel (img, xoff, yoff, pixel);
+         }
+    }
+}
+
+static void
+gd_close (MFrame *frame)
+{
+}
+
+static void *
+gd_get_prop (MFrame *frame, MSymbol key)
+{
+  return NULL;
+}
+
+static void
+gd_realize_face (MRealizedFace *rface)
+{
+  int *colors;
+  MFaceHLineProp *hline;
+  MFaceBoxProp *box;
+  MSymbol *props = (MSymbol *) rface->face.property;
+
+  if (rface != rface->ascii_rface)
+    {
+      rface->info = rface->ascii_rface->info;
+      return;
+    }
+  colors = malloc (sizeof (int) * COLOR_MAX);
+  colors[COLOR_NORMAL] = parse_color (props[MFACE_FOREGROUND]);
+  colors[COLOR_INVERSE] = parse_color (props[MFACE_BACKGROUND]);
+  if (rface->face.property[MFACE_VIDEOMODE] == Mreverse)
+    {
+      colors[COLOR_HLINE] = colors[COLOR_NORMAL];
+      colors[COLOR_NORMAL] = colors[COLOR_INVERSE];
+      colors[COLOR_INVERSE] = colors[COLOR_HLINE];
+    }
+  colors[COLOR_HLINE] = 0;
+
+  hline = rface->hline;
+  if (hline)
+    {
+      if (hline->color)
+       colors[COLOR_HLINE] = parse_color (hline->color);
+      else
+       colors[COLOR_HLINE] = colors[COLOR_NORMAL];
+    }
+
+  box = rface->box;
+  if (box)
+    {
+      if (box->color_top)
+       colors[COLOR_BOX_TOP] = parse_color (box->color_top);
+      else
+       colors[COLOR_BOX_TOP] = colors[COLOR_NORMAL];
+
+      if (box->color_left && box->color_left != box->color_top)
+       colors[COLOR_BOX_LEFT] = parse_color (box->color_left);
+      else
+       colors[COLOR_BOX_LEFT] = colors[COLOR_BOX_TOP];
+
+      if (box->color_bottom && box->color_bottom != box->color_top)
+       colors[COLOR_BOX_BOTTOM] = parse_color (box->color_bottom);
+      else
+       colors[COLOR_BOX_BOTTOM] = colors[COLOR_BOX_TOP];
+
+      if (box->color_right && box->color_right != box->color_bottom)
+       colors[COLOR_BOX_RIGHT] = parse_color (box->color_right);
+      else
+       colors[COLOR_BOX_RIGHT] = colors[COLOR_BOX_BOTTOM];
+    }
+
+  rface->info = colors;
+}
+
+static void
+gd_free_realized_face (MRealizedFace *rface)
+{
+  free (rface->info);
+}
+
+static void
+gd_fill_space (MFrame *frame, MDrawWindow win, MRealizedFace *rface,
+              int reverse,
+              int x, int y, int width, int height, MDrawRegion region)
+{
+  gdImagePtr img = (gdImagePtr) win;
+  int *colors = rface->info;
+  int color = colors[reverse ? COLOR_NORMAL : COLOR_INVERSE];
+  MPlist *region_list = region, *plist;
+
+  color = RESOLVE_COLOR (img, color);
+  if (! region)
+    gdImageFilledRectangle (img, x, y, x + width - 1, y + height - 1, color);
+  else
+    {
+      MDrawMetric rect;;
+
+      rect.x = x, rect.y = y, rect.width = width, rect.height = height;
+      MPLIST_DO (plist, region_list)
+       {
+         MDrawMetric *r = MPLIST_VAL (plist), new;
+
+         if (INTERSECT_RECTANGLE (r, &rect, &new))
+           gdImageFilledRectangle (img, new.x, new.y, new.x + new.width - 1,
+                                   new.y + new.height - 1, color);
+       }
+    }
+}
+
+static void
+gd_draw_empty_boxes (MDrawWindow win, int x, int y,
+                    MGlyphString *gstring, MGlyph *from, MGlyph *to,
+                    int reverse, MDrawRegion region)
+{
+  gdImagePtr img = (gdImagePtr) win;
+  int *colors = from->rface->info;
+  int color = colors[reverse ? COLOR_INVERSE : COLOR_NORMAL];
+  MPlist *region_list = region, *plist;
+  int height;
+
+  if (from == to)
+    return;
+
+  color = RESOLVE_COLOR (img, color);
+  y -= gstring->ascent - 1;
+  height = gstring->ascent + gstring->descent - 2;
+  if (! region)
+    for (; from < to; x += from++->g.xadv)
+      gdImageRectangle (img, x, y, x + from->g.xadv - 2, y + height - 1, color);
+  else
+    {
+      gdImagePtr cpy;
+      MGlyph *g;
+      int width, x1;
+
+      for (g = from, width = 0; g < to; width += g++->g.xadv);
+      cpy = get_scrach_image (img, width, height);
+      MPLIST_DO (plist, region_list)
+       {
+         MDrawMetric *rect = MPLIST_VAL (plist);
+         gdImageCopy (cpy, img, rect->x - x, rect->y - y, rect->x, rect->y,
+                      rect->x + rect->width, rect->y + rect->height);
+       }
+      for (x1 = 0; from < to; x1 += from++->g.xadv)
+       gdImageRectangle (cpy, x1, 0, x1 + from->g.xadv - 2, height - 1, color);
+      MPLIST_DO (plist, region_list)
+       {
+         MDrawMetric *rect = MPLIST_VAL (plist);
+         gdImageCopy (img, cpy, rect->x, rect->y, rect->x - x, rect->y - y,
+                      rect->x + rect->width, rect->y + rect->height);
+       }
+    }
+}
+
+
+static void
+gd_draw_hline (MFrame *frame, MDrawWindow win, MGlyphString *gstring,
+              MRealizedFace *rface, int reverse,
+              int x, int y, int width, MDrawRegion region)
+{
+  enum MFaceHLineType type = rface->hline->type;
+  int height = rface->hline->width;
+  gdImagePtr img = (gdImagePtr) win;
+  int *colors = rface->info;
+  int color = colors[COLOR_HLINE];
+  MPlist *region_list = region, *plist;
+
+  color = RESOLVE_COLOR (img, color);
+  y = (type == MFACE_HLINE_BOTTOM
+       ? y + gstring->text_descent - height
+       : type == MFACE_HLINE_UNDER
+       ? y + 1
+       : type == MFACE_HLINE_STRIKE_THROUGH
+       ? y - ((gstring->ascent + gstring->descent) / 2)
+       : y - gstring->text_ascent);
+  if (! region)
+    gdImageFilledRectangle (img, x, y, x + width - 1, y + height - 1, color);
+  else
+    {
+      MDrawMetric rect;
+
+      rect.x = x, rect.y = y, rect.width = width, rect.height = height;
+      MPLIST_DO (plist, region_list)
+       {
+         MDrawMetric *r = MPLIST_VAL (plist), new;
+
+         if (INTERSECT_RECTANGLE (r, &rect, &new))
+           gdImageFilledRectangle (img, new.x, new.y, new.x + new.width - 1,
+                                   new.y + new.height - 1, color);
+       }
+    }
+}
+
+
+static void
+gd_draw_box (MFrame *frame, MDrawWindow win, MGlyphString *gstring,
+            MGlyph *g, int x, int y, int width, MDrawRegion region)
+{
+  gdImagePtr img = (gdImagePtr) win;
+  int *colors = g->rface->info;
+  int color;
+  MRealizedFace *rface = g->rface;
+  MFaceBoxProp *box = rface->box;
+  MPlist *region_list = region, *plist;
+  int y0, y1;
+  int i;
+
+  y0 = y - (gstring->text_ascent
+           + rface->box->inner_vmargin + rface->box->width);
+  y1 = y + (gstring->text_descent
+           + rface->box->inner_vmargin + rface->box->width - 1);
+
+  if (region)
+    {
+      int height = y1 - y0;
+      gdImagePtr cpy;
+
+      if (g->type == GLYPH_BOX)
+       width = g->g.xadv;
+      cpy = get_scrach_image (img, width, height);
+      MPLIST_DO (plist, region_list)
+       {
+         MDrawMetric *rect = MPLIST_VAL (plist);
+         gdImageCopy (cpy, img, rect->x - x, rect->y - y, rect->x, rect->y,
+                      rect->x + rect->width, rect->y + rect->height);
+       }
+      gd_draw_box (frame, win, gstring, g, 0, y - y0, width, NULL);
+      MPLIST_DO (plist, region_list)
+       {
+         MDrawMetric *rect = MPLIST_VAL (plist);
+         gdImageCopy (img, cpy, rect->x, rect->y, rect->x - x, rect->y - y,
+                      rect->x + rect->width, rect->y + rect->height);
+       }
+      return;
+    }
+
+  if (g->type == GLYPH_BOX)
+    {
+      int x0, x1;
+
+      if (g->left_padding)
+       x0 = x + box->outer_hmargin, x1 = x + g->g.xadv - 1;
+      else
+       x0 = x, x1 = x + g->g.xadv - box->outer_hmargin - 1;
+
+      /* Draw the top side.  */
+      color = RESOLVE_COLOR (img, colors[COLOR_BOX_TOP]);
+      for (i = 0; i < box->width; i++)
+       gdImageLine (img, x0, y0 + i, x1, y0 + i, color);
+
+      /* Draw the bottom side.  */
+      color = RESOLVE_COLOR (img, colors[COLOR_BOX_BOTTOM]);
+      for (i = 0; i < box->width; i++)
+       gdImageLine (img, x0, y1 - i, x1, y1 - i, color);
+
+      if (g->left_padding > 0)
+       {
+         /* Draw the left side.  */
+         color = RESOLVE_COLOR (img, colors[COLOR_BOX_LEFT]);
+         for (i = 0; i < rface->box->width; i++)
+           gdImageLine (img, x0 + i, y0 + i, x0 + i, y1 - i, color);
+       }
+      else
+       {
+         /* Draw the right side.  */
+         color = RESOLVE_COLOR (img, colors[COLOR_BOX_RIGHT]);
+         for (i = 0; i < rface->box->width; i++)
+           gdImageLine (img, x1 - i, y0 + i, x1 - i, y1 - i, color);
+       }
+
+    }
+  else
+    {
+      /* Draw the top side.  */
+      color = RESOLVE_COLOR (img, colors[COLOR_BOX_TOP]);
+      for (i = 0; i < box->width; i++)
+       gdImageLine (img, x, y0 + i, x + width - 1, y0 + i, color);
+
+      /* Draw the bottom side.  */
+      color = RESOLVE_COLOR (img, colors[COLOR_BOX_BOTTOM]);
+      for (i = 0; i < box->width; i++)
+       gdImageLine (img, x, y1 - i, x + width - 1, y1 - i, color);
+    }
+}
+
+
+static MDrawRegion
+gd_region_from_rect (MDrawMetric *rect)
+{
+  MDrawMetric *new;
+  MPlist *plist = mplist ();
+
+  MSTRUCT_MALLOC (new, MERROR_GD);
+  *new = *rect;
+  mplist_add (plist, Mt, new);
+  return (MDrawRegion) plist;
+}
+
+static void
+gd_union_rect_with_region (MDrawRegion region, MDrawMetric *rect)
+{
+  MPlist *plist = (MPlist *) region;
+  MDrawMetric *r;
+
+  MSTRUCT_MALLOC (r, MERROR_GD);
+  *r = *rect;
+  mplist_push (plist, Mt, r);
+}
+
+static void
+gd_intersect_region (MDrawRegion region1, MDrawRegion region2)
+{
+  MPlist *plist1 = (MPlist *) region1, *p1 = plist1;
+  MPlist *plist2 = (MPlist *) region2;
+  MPlist *p2;
+  MDrawMetric rect, *rect1, *rect2, *r;
+
+  while (! MPLIST_TAIL_P (p1))
+    {
+      rect1 = mplist_pop (p1);
+      MPLIST_DO (p2, plist2)
+       {
+         rect2 = MPLIST_VAL (p2);
+         if (INTERSECT_RECTANGLE (rect1, rect2, &rect))
+           {
+             MSTRUCT_MALLOC (r, MERROR_GD);
+             *r = rect;
+             mplist_push (p1, Mt, r);
+             p1 = MPLIST_NEXT (p1);
+           }
+       }
+      free (rect1);
+    }
+}
+
+static void
+gd_region_add_rect (MDrawRegion region, MDrawMetric *rect)
+{
+  MPlist *plist = (MPlist *) region;
+  MDrawMetric *new;
+
+  MSTRUCT_MALLOC (new, MERROR_GD);
+  *new = *rect;
+  mplist_push (plist, Mt, new);
+}
+
+static void
+gd_region_to_rect (MDrawRegion region, MDrawMetric *rect)
+{
+  MPlist *plist = (MPlist *) region;
+  MDrawMetric *r = MPLIST_VAL (plist);
+  int min_x = r->x, max_x = min_x + r->width;
+  int min_y = r->y, max_y = min_y + r->height;
+  
+  MPLIST_DO (plist, MPLIST_NEXT (plist))
+    {
+      r = MPLIST_VAL (plist);
+      if (r->x < min_x)
+       min_x = r->x;
+      if (r->x + r->width > max_x)
+       max_x = r->x + r->width;
+      if (r->y < min_y)
+       min_y = r->y;
+      if (r->y + r->height > max_y)
+       max_y = r->y + r->height;
+    }
+  rect->x = min_x;
+  rect->y = min_y;
+  rect->width = max_x - min_x;
+  rect->height =max_y - min_y;
+}
+
+static void
+gd_free_region (MDrawRegion region)
+{
+  MPlist *plist = (MPlist *) region;
+
+  MPLIST_DO (plist, plist)
+    free (MPLIST_VAL (plist));
+  M17N_OBJECT_UNREF (region);
+}
+
+static void
+gd_dump_region (MDrawRegion region)
+{
+  MDrawMetric rect;
+
+  gd_region_to_rect (region, &rect);
+  fprintf (stderr, "(%d %d %d %d)\n", rect.x, rect.y, rect.width, rect.height);
+}
+
+static MDeviceDriver gd_driver =
+  {
+    gd_close,
+    gd_get_prop,
+    gd_realize_face,
+    gd_free_realized_face,
+    gd_fill_space,
+    gd_draw_empty_boxes,
+    gd_draw_hline,
+    gd_draw_box,
+    NULL,
+    gd_region_from_rect,
+    gd_union_rect_with_region,
+    gd_intersect_region,
+    gd_region_add_rect,
+    gd_region_to_rect,
+    gd_free_region,
+    gd_dump_region,
+  };
+
+/* Functions to be stored in MDeviceLibraryInterface by dlsym ().  */
+
+int
+device_init ()
+{
+  M_rgb = msymbol ("  rgb");
+  read_rgb_txt ();
+  realized_fontset_list = mplist ();
+  realized_font_list = mplist ();
+  realized_face_list = mplist ();  
+  scratch_images[0] = scratch_images[1] = NULL;
+
+  gd_font_driver.select = mfont__ft_driver.select;
+  gd_font_driver.find_metric = mfont__ft_driver.find_metric;
+  gd_font_driver.has_char = mfont__ft_driver.has_char;
+  gd_font_driver.encode_char = mfont__ft_driver.encode_char;
+  gd_font_driver.list = mfont__ft_driver.list;
+  gd_font_driver.check_otf = mfont__ft_driver.check_otf;
+  gd_font_driver.drive_otf = mfont__ft_driver.drive_otf;
+
+  return 0;
+}
+
+int
+device_fini ()
+{
+  MPlist *plist;
+  int i;
+
+  MPLIST_DO (plist, realized_fontset_list)
+    mfont__free_realized_fontset ((MRealizedFontset *) MPLIST_VAL (plist));
+  M17N_OBJECT_UNREF (realized_fontset_list);
+
+  MPLIST_DO (plist, realized_face_list)
+    {
+      MRealizedFace *rface = MPLIST_VAL (plist);
+
+      free (rface->info);
+      mface__free_realized (rface);
+    }
+  M17N_OBJECT_UNREF (realized_face_list);
+
+  if (MPLIST_VAL (realized_font_list))
+    mfont__free_realized (MPLIST_VAL (realized_font_list));
+  M17N_OBJECT_UNREF (realized_font_list);
+
+  for (i = 0; i < 2; i++)
+    if (scratch_images[i])
+      gdImageDestroy (scratch_images[i]);
+  return 0;
+}
+
+int
+device_open (MFrame *frame, MPlist *param)
+{
+  MFace *face;
+
+  frame->device = NULL;
+  frame->device_type = MDEVICE_SUPPORT_OUTPUT;
+  frame->dpi = (int) mplist_get (param, Mresolution);
+  if (frame->dpi == 0)
+    frame->dpi = 100;
+  frame->driver = &gd_driver;
+  frame->font_driver_list = mplist ();
+  mplist_add (frame->font_driver_list, Mfreetype, &gd_font_driver);
+  frame->realized_font_list = realized_font_list;
+  frame->realized_face_list = realized_face_list;
+  frame->realized_fontset_list = realized_fontset_list;
+  face = mface_copy (mface__default);
+  mface_put_prop (face, Mfoundry, Mnil);
+  mface_put_prop (face, Mfamily, Mnil);
+  mplist_push (param, Mface, face);
+  M17N_OBJECT_UNREF (face);
+  return 0;
+}
+
+#else  /* not HAVE_GD nor HAVE_FREETYPE */
+
+int device_open () { return -1; }
+
+#endif /* not HAVE_GD nor HAVE_FREETYPE */
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
diff --git a/src/m17n-gui.c b/src/m17n-gui.c
new file mode 100644 (file)
index 0000000..5903bf5
--- /dev/null
@@ -0,0 +1,821 @@
+/* m17n-gui.c -- body of the GUI API.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nGUI
+    @brief GUI support for a window system.
+
+    This section defines the m17n GUI API concerning M-text drawing
+    and inputting under a window system.
+
+    All the definitions here are independent of window systems.  An
+    actual library file, however, can depend on a specific window
+    system.  For instance, the library file m17n-X.so is an example of
+    implementation of the m17n GUI API for the X Window System.
+
+    Actually the GUI API is mainly for toolkit libraries or to
+    implement XOM, not for direct use from application programs.
+*/
+
+/***ja
+    @addtogroup m17nGUI
+    @brief ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¾å¤Î GUI ¥µ¥Ý¡¼¥È.
+
+    ¤³¤Î¥»¥¯¥·¥ç¥ó¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Î¤â¤È¤Ç¤Î M-text ¤Îɽ¼¨¤ÈÆþÎϤˤ«¤«¤ï¤ë
+    m17n GUI API ¤òÄêµÁ¤¹¤ë¡£
+
+    ¤³¤³¤Ç¤Î¤¹¤Ù¤Æ¤ÎÄêµÁ¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤È¤ÏÆÈΩ¤Ç¤¢¤ë¡£
+    ¤·¤«¤·¡¢¼ÂºÝ¤Î¥é¥¤¥Ö¥é¥ê¥Õ¥¡¥¤¥ë¤Ï¸ÄÊ̤Υ¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¾ì¹ç¤¬¤¢¤ë¡£
+    ¤¿¤È¤¨¤Ð¥é¥¤¥Ö¥é¥ê¥Õ¥¡¥¤¥ë m17n-X.so ¤Ï¡¢m17n GUI API ¤Î X 
+    ¥¦¥£¥ó¥É¥¦ÍѤμÂÁõÎã¤Ç¤¢¤ë¡£
+
+    ¸½¼Â¤Ë¤Ï¡¢GUI API ¤Ï¼ç¤Ë¥Ä¡¼¥ë¥­¥Ã¥È¥é¥¤¥Ö¥é¥ê¸þ¤±¤Ç¤¢¤ë¤«¡¢¤Þ¤¿¤Ï 
+    XOM ¤ò¼ÂÁõ¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤Æ¤ª¤ê¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤ÎľÀܤÎÍøÍѤòǰƬ¤Ë¤ª¤¤¤¿¤â¤Î¤Ç¤Ï¤Ê¤¤¡£
+*/
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "config.h"
+#ifdef HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include "m17n-gui.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "plist.h"
+#include "internal-gui.h"
+#include "font.h"
+#include "fontset.h"
+#include "face.h"
+
+#ifndef DLOPEN_SHLIB_EXT
+#define DLOPEN_SHLIB_EXT ".so"
+#endif
+
+/** Information about a dynamic library supporting a specific graphic
+    device.  */
+typedef struct
+{
+  /** Name of the dynamic library (e.g. "libm17n-X.so").  */
+  char *library;
+  /** Handle of the dynamic library.  */
+  void *handle;
+  /** Function to call just after loading the library.  */
+  int (*init) ();
+  /** Function to call to open a frame on the graphic device.  */
+  int (*open) (MFrame *frame, MPlist *param);
+  /** Function to call just before unloading the library.  */
+  int (*fini) ();
+} MDeviceLibraryInterface;
+
+
+/** Plist of device symbol vs MDeviceLibraryInterface.  */
+
+static MPlist *device_library_list;
+
+/** Close MFrame and free it.  */
+
+static void
+free_frame (void *object)
+{
+  MFrame *frame = (MFrame *) object;
+
+  (*frame->driver->close) (frame);
+  M17N_OBJECT_UNREF (frame->face);
+  M17N_OBJECT_UNREF (frame->font_driver_list);
+  free (object);
+}
+
+
+/** Register a dynamic library of name LIB by a key NAME.  */
+
+static int
+register_device_library (MSymbol name, char *lib)
+{
+  MDeviceLibraryInterface *interface;
+
+  MSTRUCT_CALLOC (interface, MERROR_WIN);
+  interface->library = malloc (strlen (M17N_MODULE_DIR) + 1
+                              + strlen (lib) 
+                              + strlen (DLOPEN_SHLIB_EXT) + 1);
+  sprintf (interface->library, "%s/%s%s", M17N_MODULE_DIR, lib,
+          DLOPEN_SHLIB_EXT);
+  if (! device_library_list)
+    device_library_list = mplist ();
+  mplist_add (device_library_list, name, interface);
+  return 0;
+}
+
+\f
+#ifdef HAVE_FREETYPE
+/** Null device support.  */
+
+static struct {
+  MPlist *realized_fontset_list;
+  MPlist *realized_font_list;
+  MPlist *realized_face_list;
+} null_device;
+
+static void
+null_device_close (MFrame *frame)
+{
+}
+
+static void *
+null_device_get_prop (MFrame *frame, MSymbol key)
+{
+  return NULL;
+}
+
+static void
+null_device_realize_face (MRealizedFace *rface)
+{
+  rface->info = NULL;
+}
+
+static void
+null_device_free_realized_face (MRealizedFace *rface)
+{
+}
+
+static MDeviceDriver null_driver =
+  {
+    null_device_close,
+    null_device_get_prop,
+    null_device_realize_face,
+    null_device_free_realized_face
+  };
+
+static int
+null_device_init ()
+{
+  null_device.realized_fontset_list = mplist ();
+  null_device.realized_font_list = mplist ();
+  null_device.realized_face_list = mplist ();  
+  return 0;
+}
+
+static int
+null_device_fini ()
+{
+  MPlist *plist;
+
+  MPLIST_DO (plist, null_device.realized_fontset_list)
+    mfont__free_realized_fontset ((MRealizedFontset *) MPLIST_VAL (plist));
+  M17N_OBJECT_UNREF (null_device.realized_fontset_list);
+
+  MPLIST_DO (plist, null_device.realized_face_list)
+    mface__free_realized ((MRealizedFace *) MPLIST_VAL (plist));
+  M17N_OBJECT_UNREF (null_device.realized_face_list);
+
+  if (MPLIST_VAL (null_device.realized_font_list))
+    mfont__free_realized (MPLIST_VAL (null_device.realized_font_list));
+  M17N_OBJECT_UNREF (null_device.realized_font_list);
+  return 0;
+}
+
+static int
+null_device_open (MFrame *frame, MPlist *param)
+{
+  MFace *face;
+
+  frame->device = NULL;
+  frame->device_type = 0;
+  frame->dpi = (int) mplist_get (param, Mresolution);
+  if (frame->dpi == 0)
+    frame->dpi = 100;
+  frame->driver = &null_driver;
+  frame->font_driver_list = mplist ();
+  mplist_add (frame->font_driver_list, Mfreetype, &mfont__ft_driver);
+  frame->realized_font_list = null_device.realized_font_list;
+  frame->realized_face_list = null_device.realized_face_list;
+  frame->realized_fontset_list = null_device.realized_fontset_list;
+  face = mface_copy (mface__default);
+  mplist_push (param, Mface, face);
+  M17N_OBJECT_UNREF (face);
+  return 0;
+}
+
+static MDeviceLibraryInterface null_interface =
+  { NULL, NULL, null_device_init, null_device_open, null_device_fini };
+
+#endif
+\f
+/* Internal API */
+
+\f
+/* External API */
+
+void
+m17n_init_win (void)
+{
+  int mdebug_flag = MDEBUG_INIT;
+
+  merror_code = MERROR_NONE;
+  if (m17n__gui_initialized++)
+    return;
+  m17n_init ();
+  m17n_init_flt ();
+  if (merror_code != MERROR_NONE)
+    {
+      m17n__gui_initialized--;
+      return;
+    }
+
+  MDEBUG_PUSH_TIME ();
+
+  Mgd = msymbol ("gd");
+
+  Mfont = msymbol ("font");
+  Mfont_width = msymbol ("font-width");
+  Mfont_ascent = msymbol ("font-ascent");
+  Mfont_descent = msymbol ("font-descent");
+  Mdevice = msymbol ("device");
+
+  Mdisplay = msymbol ("display");
+  Mscreen = msymbol ("screen");
+  Mdrawable = msymbol ("drawable");
+  Mdepth = msymbol ("depth");
+  Mwidget = msymbol ("widget");
+  Mcolormap = msymbol ("colormap");
+
+  MDEBUG_PUSH_TIME ();
+  if (mfont__init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize font module."));
+  if (mfont__fontset_init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize fontset module."));
+  if (mface__init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize face module."));
+  if (mdraw__init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize draw module."));
+  if (minput__win_init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize input-win module."));
+  mframe_default = NULL;
+
+  register_device_library (Mx, "libm17n-X");
+  register_device_library (Mgd, "libm17n-gd");
+  return;
+
+ err:
+  MDEBUG_POP_TIME ();
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the m17n GUI module."));
+  MDEBUG_POP_TIME ();
+}
+
+void
+m17n_fini_win (void)
+{
+  int mdebug_flag = MDEBUG_FINI;
+  MPlist *plist;
+
+  if (m17n__gui_initialized == 0
+      || --m17n__gui_initialized > 0)
+    return;
+
+  MDEBUG_PUSH_TIME ();
+  MDEBUG_PUSH_TIME ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize device modules."));
+  MPLIST_DO (plist, device_library_list)
+    {
+      MDeviceLibraryInterface *interface = MPLIST_VAL (plist);
+
+      if (interface->handle && interface->fini)
+       {
+         (*interface->fini) ();
+         dlclose (interface->handle);
+       }
+      free (interface->library);
+      free (interface);
+    }
+#ifdef HAVE_FREETYPE
+  if (null_interface.handle)
+    {
+      (*null_interface.fini) ();
+      null_interface.handle = NULL;
+    }
+#endif /* not HAVE_FREETYPE */
+  M17N_OBJECT_UNREF (device_library_list);
+  minput__win_fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize input-gui module."));
+  mdraw__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize draw module."));
+  mface__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize face module."));
+  mfont__fontset_fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize fontset module."));
+  mfont__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize font module."));
+  mframe_default = NULL;
+  MDEBUG_POP_TIME ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the gui modules."));
+  MDEBUG_POP_TIME ();
+  m17n_fini_flt ();
+  m17n_fini ();
+}
+
+/*** @} */ 
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+/*** @addtogroup m17nFrame */
+/***en
+    @brief A @e frame is an object corresponding to the graphic device.
+
+    A @e frame is an object of the type #MFrame to hold various
+    information about each display/input device.  Almost all m17n GUI
+    functions require a pointer to a frame as an argument.  */
+/***ja
+    @brief @e ¥Õ¥ì¡¼¥à ¤È¤Ï¥°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¤ËÂбþ¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë.
+
+    @e ¥Õ¥ì¡¼¥à ¤È¤Ï #MFrame 
+    ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ê¡¢¸Ä¡¹¤Îɽ¼¨¡¿ÆþÎϥǥХ¤¥¹¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£
+    ¤Û¤È¤ó¤É¤¹¤Ù¤Æ¤Î m17n GUI´Ø¿ô¤Ï¡¢°ú¿ô¤È¤·¤Æ¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÍ׵᤹¤ë¡£  */
+
+/*** @{ */
+/*=*/
+
+/***en
+    @name Variables: Keys of frame parameter
+
+    These are the symbols to use in a parameter to create a frame.  See
+    the function mframe () for details.
+
+    @b Mdevice, @b Mdisplay, @b Mscreen, @b Mdrawable, @b Mdepth, and
+    @b Mcolormap are also keys of a frame property.  */
+
+/***ja
+    @name ÊÑ¿ô¡§ ¥Õ¥ì¡¼¥à¥Ñ¥é¥á¡¼¥¿ÍÑ¥­¡¼
+
+    ¥Õ¥ì¡¼¥à¤òÀ¸À®¤¹¤ëºÝ¤Î¥Ñ¥é¥á¡¼¥¿¤ËÍѤ¤¤ë¥·¥ó¥Ü¥ë¡£¾Ü¤·¤¯¤Ï´Ø¿ô
+    mframe () ¤ÎÀâÌÀ»²¾È¡£
+
+    @b Mdevice¡¢ @b Mdisplay¡¢ @b Mscreen¡¢ @b Mdrawable¡¢ @b Mdepth¡¢
+    @b Mcolormap ¤Ï¥Õ¥ì¡¼¥à¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤Ç¤â¤¢¤ë¡£  */
+
+/*=*/
+
+MSymbol Mdevice, Mdisplay, Mscreen, Mdrawable, Mdepth, Mcolormap, Mwidget; 
+
+MSymbol Mgd;
+
+/*=*/
+
+/***en
+    @name Variables: Keys of frame property
+
+    These are the symbols to use as an argument to the function
+    mframe_get_prop ().  */
+/***ja
+    @name ÊÑ¿ô¡§ ¥Õ¥ì¡¼¥à¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼
+
+    ´Ø¿ô mframe_get_prop () ¤Î°ú¿ô¤ËÍѤ¤¤é¤ì¤ë¥·¥ó¥Ü¥ë¡£  */ 
+/*** @{ */ 
+/*=*/
+MSymbol Mfont;
+MSymbol Mfont_width;
+MSymbol Mfont_ascent;
+MSymbol Mfont_descent;
+
+/*=*/
+
+/*** @} */ 
+/*=*/
+
+/***en
+    @brief Create a new frame.
+
+    The mframe () function creates a new frame with parameters listed
+    in $PLIST which may be @c NULL.
+
+    The recognized keys in $PLIST are window system dependent.
+
+    The following key is always recognized.
+
+    <ul>
+
+    <li> @b Mdevice, the value must be one of #Mx, @b Mgd, and #Mnil.
+
+    If the value is #Mx, the frame is for X Window System.  The
+    argument #MDrawWindow specified together with the frame must be of
+    type @c Window.  The frame is both readable and writable, thus all
+    GUI functions can be used.
+
+    If the value is @b Mgd, the frame is for an image object of GD
+    library.  The argument #MDrawWindow specified together with the
+    frame must be of type @c gdImagePtr.  The frame is writable
+    only, thus functions minput_XXX can't be used for the frame.
+
+    If the value is #Mnil, the frame is for a null device.  The frame
+    is not writable nor readable, thus functions mdraw_XXX that
+    require the argument #MDrawWindow and functions minput_XXX can't
+    be used for the frame.
+
+    <li> #Mface, the value must be a pointer to #MFace.
+
+    The value is used as the default face of the frame.
+
+    </ul>
+
+    In addition, if the value of the key @b Mdevice is #Mx, the
+    following keys are recognized.  They are to specify the root
+    window and the depth of drawables that can be used with the frame.
+
+    <ul>
+
+    <li> @b Mdrawable, the value type must be <tt>Drawable</tt>.
+
+    A parameter of key @b Mdisplay must also be specified.  The
+    created frame can be used for drawables whose root window and
+    depth are the same as those of the specified drawable on the
+    specified display.
+
+    When this parameter is specified, the parameter of key @b Mscreen
+    is ignored.
+
+    <li> @b Mwidget, the value type must be <tt>Widget</tt>.
+
+    The created frame can be used for drawables whose root window and
+    depth are the same as those of the specified widget.
+
+    If a parameter of key #Mface is not specified, the default face
+    is created from the resources of the widget.
+
+    When this parameter is specified, the parameters of key @b Mdisplay,
+    @b Mscreen, @b Mdrawable, @b Mdepth are ignored.
+
+    <li> @b Mdepth, the value type must be <tt>unsigned</tt>.
+
+    The created frame can be used for drawables of the specified
+    depth.
+
+    <li> @b Mscreen, the value type must be <tt>(Screen *)</tt>.
+
+    The created frame can be used for drawables whose root window is
+    the same as the root window of the specified screen, and depth is
+    the same at the default depth of the screen.
+
+    When this parameter is specified, parameter of key @b Mdisplay is
+    ignored.
+
+    <li> @b Mdisplay, the value type must be <tt>(Display *)</tt>.
+
+    The created frame can be used for drawables whose root window is
+    the same as the root window for the default screen of the display,
+    and depth is the same as the default depth of the screen.
+
+    <li> @b Mcolormap, the value type must be <tt>(Colormap)</tt>.
+
+    The created frame uses the specified colormap.
+
+    <li> @b Mfont, the value must be #Mx, #Mfreetype, or #Mxft.
+
+    The created frame uses the specified font backend.  The value #Mx
+    instructs to use X core fonts, #Mfreetype to use local fonts
+    supported by FreeType fonts, and #Mxft to use local fonts via Xft
+    library.  You can specify this parameter more than once with
+    different values if you want to use multiple font backends.  This
+    is ignored if the specified font backend is not supported on the
+    device.
+    
+    When this parameter is not specified, all font backend supported
+    on the device are used.
+
+    </ul>
+
+    @return
+    If the operation was successful, mframe () returns a pointer to a
+    newly created frame.  Otherwise, it returns @c NULL.  */
+
+/***ja
+    @brief ¿·¤·¤¤¥Õ¥ì¡¼¥à¤òºî¤ë.
+
+    ´Ø¿ô mframe () ¤Ï $PLIST Ãæ¤Î¥Ñ¥é¥á¡¼¥¿¤ò»ý¤Ä¿·¤·¤¤¥Õ¥ì¡¼¥à¤òºî¤ë¡£
+    $PLIST ¤Ï @c NULL ¤Ç¤âÎɤ¤¡£
+
+    $PLIST ¤Ë¸½¤ï¤ì¤ë¥­¡¼¤Î¤¦¤Á¤É¤ì¤¬Ç§¼±¤µ¤ì¤ë¤«¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡£
+
+    °Ê²¼¤Î¥­¡¼¤Ï¾ï¤Ëǧ¼±¤µ¤ì¤ë¡£
+
+    <ul>
+
+    <li> @b Mdevice. ÃͤϠ#Mx, @b Mgd, #Mnil ¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    Ãͤ¬ #Mx ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥àÍѤǤ¢¤ë¡£
+    ¤³¤Î¥Õ¥ì¡¼¥à¤È¶¦¤Ë»ØÄꤵ¤ì¤¿°ú¿ô #MDrawWindow ¤Ï¡¢ @c Window
+    ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¥Õ¥ì¡¼¥à¤ÏÆɤ߽ñ¤­¤È¤â¤Ë²Äǽ¤Ç¤¢¤ê¡¢¤¹¤Ù¤Æ¤ÎGUI 
+    ´Ø¿ô¤¬»ÈÍѤǤ­¤ë¡£
+
+    Ãͤ¬ @b Mgd ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï GD 
+    ¥é¥¤¥Ö¥é¥ê¤Î¥¤¥á¡¼¥¸¥ª¥Ö¥¸¥§¥¯¥ÈÍѤǤ¢¤ë¡£¤³¤Î¥Õ¥ì¡¼¥à¤È¶¦¤Ë»ØÄꤵ¤ì¤¿°ú¿ô
+    #MDrawWindow ¤Ï¡¢ @c gdImagePtr ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¥Õ¥ì¡¼¥à¤Ï½ñ¤­½Ð¤·ÀìÍѤǤ¢¤ê¡¢
+    minput_ ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤Ï»ÈÍѤǤ­¤Ê¤¤¡£
+
+    Ãͤ¬ #Mnil ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï, null 
+    ¥Ç¥Ð¥¤¥¹ÍѤǤ¢¤ë¡£¤³¤Î¥Õ¥ì¡¼¥à¤ÏÆɤ߽ñ¤­¤Ç¤­¤Ê¤¤¤Î¤Ç¡¢°ú¿ô #MDrawWindow 
+    ¤òɬÍפȤ¹¤ëmdraw_ ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤ä¡¢minput_ ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤Ï»ÈÍѤǤ­¤Ê¤¤¡£
+
+    <li> #Mface. ÃͤϠ#MFace ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    ¤³¤ÎÃͤϥե졼¥à¤Î¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
+
+    </ul>
+
+    ¤³¤ì¤é¤Î¥­¡¼¤Ë²Ã¤¨¡¢@b Mdevice ¤Î¥­¡¼¤¬ #Mx 
+    ¤Ç¤¢¤ë¾ì¹ç¤Ë¸Â¤ê°Ê²¼¤Î¥­¡¼¤âǧ¼±¤µ¤ì¤ë¡£°Ê²¼¤Î¥­¡¼¤Ï¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¡¢¥Õ¥ì¡¼¥à¤ÇÍøÍѤǤ­¤ë 
+    drawable ¤Î¿¼¤µ¤ò»ØÄꤹ¤ë¡£
+
+    <ul>
+
+    <li> @b Mdrawable. ÃͤϠ<tt>Drawable</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    ¥­¡¼ @b Mdisplay ¤ò»ý¤Ä¥Ñ¥é¥á¡¼¥¿¤â»ØÄꤵ¤ì¤Æ¤¤¤ëɬÍפ¬¤¢¤ë¡£
+    À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤵ¤ì¤¿¥Ç¥£¥¹¥×¥ì¥¤¾å¤Î»ØÄꤵ¤ì¤¿ drawable 
+    ¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¿¼¤µ¤ò»ý¤Ä drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
+
+    ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢@b Mscreen ¤ò¥­¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
+
+    <li> @b Mwidget. ÃͤϠ<tt>Widget</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥¦¥£¥¸¥§¥Ã¥È¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¿¼¤µ¤ò»ý¤Ä
+    drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
+
+    ¥­¡¼ #Mface ¤ò»ý¤Ä¥Ñ¥é¥á¡¼¥¿¤¬¤Ê¤±¤ì¤Ð¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹¤Ï¤³¤Î
+    ¥¦¥£¥¸¥§¥Ã¥È¤Î¥ê¥½¡¼¥¹¤«¤éºî¤é¤ì¤ë¡£
+
+    ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢@b Mdisplay, @b Mscreen, @b Mdrawable,
+    @b Mdepth ¤ò¥­¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
+
+    <li> @b Mdepth. ÃͤϠ<tt>unsigned</tt>  ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¿¼¤µ¤Î drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
+
+    <li> @b Mscreen. ÃͤϠ<tt>(Screen *)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    À¸À®¤·¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥¹¥¯¥ê¡¼¥ó¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤ò»ý¤Á¡¢¥¹¥¯¥ê¡¼¥ó¤Î¥Ç¥Õ¥©¥ë¥È¤Î¿¼¤µ¤ÈƱ¤¸¿¼¤µ¤ò»ý¤Ä drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
+
+    ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢@b Mdisplay ¤ò¥­¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
+
+    <li> @b Mdisplay. ÃͤϠ<tt>(Display *)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥Ç¥£¥¹¥×¥ì¥¤¤Î¥Ç¥Õ¥©¥ë¥È¥¹¥¯¥ê¡¼¥ó¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤ÈƱ¤¸¿¼¤µ¤ò»ý¤Ädrawables ¤ËÍѤ¤¤é¤ì¤ë¡£
+
+    <li> @b Mcolormap. ÃͤϠ<tt>(Colormap)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥«¥é¡¼¥Þ¥Ã¥×¤ò»ÈÍѤ¹¤ë¡£
+
+    <li> #Mfont. Ãͤϡ¢#Mx, #Mfreetype, #Mxft ¤Î¤¤¤º¤ì¤«¡£
+
+    À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï»ØÄꤷ¤¿¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤ò»ÈÍѤ¹¤ë¡£Ãͤ¬ 
+    #Mx ¤Ç¤¢¤ì¤Ð X ¤Î¥³¥¢¥Õ¥©¥ó¥È¡¢#Mfreetype ¤Ç¤¢¤ì¤Ð FreeType 
+    ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥í¡¼¥«¥ë¥Õ¥©¥ó¥È¡¢#Mxft ¤Ç¤¢¤ì¤Ð Xft 
+    ¥é¥¤¥Ö¥é¥ê·Ðͳ¤ÇÍѤ¤¤ë¥í¡¼¥«¥ë¥Õ¥©¥ó¥È¤ò»ÈÍѤ¹¤ë¡£
+    Ê£¿ô¤Î¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤ò»ÈÍѤ·¤¿¤¤¾ì¹ç¤Ë¤Ï¡¢¤³¤Î¥Ñ¥é¥á¡¼¥¿¤òÊ£¿ô²ó¡¢°Û¤Ê¤ëÃͤǻØÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
+    »ØÄꤷ¤¿¥Ð¥Ã¥¯¥¨¥ó¥É¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¥Ç¥Ð¥¤¥¹¤Ç¤Ï¡¢¤³¤Î¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
+
+    ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬Ìµ¤¤¾ì¹ç¤Ë¤Ï¡¢¥Ç¥Ð¥¤¥¹¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤¹¤Ù¤Æ¤Î¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤òÍøÍѤ¹¤ë¡£
+
+    </ul>
+
+    @return
+    À®¸ù¤¹¤ì¤Ð mframe() ¤Ï¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð
+    @c NULL ¤òÊÖ¤¹¡£  */
+
+MFrame *
+mframe (MPlist *plist)
+{
+  MFrame *frame;
+  int plist_created = 0;
+  MPlist *pl;
+  MSymbol device;
+  MDeviceLibraryInterface *interface;
+
+  if (plist)
+    {
+      pl = mplist_find_by_key (plist, Mdevice);
+      if (pl)
+       device = MPLIST_VAL (pl);
+      else
+       device = Mx;
+    }
+  else
+    {
+      plist = mplist ();
+      plist_created = 1;
+      device = Mx;
+    }
+
+  if (device == Mnil)
+    {
+#ifdef HAVE_FREETYPE
+      interface = &null_interface;
+      if (! interface->handle)
+       {
+         (*interface->init) ();
+         interface->handle = (void *) 1;
+       }
+#else  /* not HAVE_FREETYPE */
+      MERROR (MERROR_WIN, NULL);
+#endif /* not HAVE_FREETYPE */
+    }
+  else
+    {
+      interface = mplist_get (device_library_list, device);
+      if (! interface)
+       MERROR (MERROR_WIN, NULL);
+      if (! interface->handle)
+       {
+         if (! (interface->handle = dlopen (interface->library, RTLD_NOW))
+             || ! (interface->init
+                   = (int (*) ()) dlsym (interface->handle, "device_init"))
+             || ! (interface->open
+                   = (int (*) (MFrame *, MPlist *)) dlsym (interface->handle,
+                                                           "device_open"))
+             || ! (interface->fini
+                   = (int (*) ()) dlsym (interface->handle, "device_fini"))
+             || (*interface->init) () < 0)
+           {
+             fprintf (stderr, "%s\n", (char *) dlerror ());
+             if (interface->handle)
+               dlclose (interface->handle);
+             MERROR (MERROR_WIN, NULL);
+           }
+       }
+    }
+
+  M17N_OBJECT (frame, free_frame, MERROR_FRAME);
+  if ((*interface->open) (frame, plist) < 0)
+    {
+      free (frame);
+      MERROR (MERROR_WIN, NULL);
+    }
+
+  if (! mframe_default)
+    mframe_default = frame;
+
+  frame->face = mface ();
+  MPLIST_DO (pl, plist)
+    if (MPLIST_KEY (pl) == Mface)
+      mface_merge (frame->face, (MFace *) MPLIST_VAL (pl));
+  mface__update_frame_face (frame);
+  frame->font
+    = frame->rface->rfont ? (MFont *) frame->rface->rfont : NULL;
+  if (plist_created)
+    M17N_OBJECT_UNREF (plist);
+  return frame;
+}
+
+/*=*/
+
+/***en
+    @brief Return property value of frame.
+
+    The mframe_get_prop () function returns a value of property $KEY
+    of frame $FRAME.  The valid keys and the corresponding return
+    values are as follows.
+
+@verbatim
+
+        key             type of value   meaning of value
+        ---             -------------   ----------------
+        Mface           MFace *         The default face.
+
+        Mfont           MFont *         The default font.
+
+        Mfont_width     int             Width of the default font.
+
+        Mfont_ascent    int             Ascent of the default font.
+
+        Mfont_descent   int             Descent of the default font.
+
+@endverbatim
+
+    In the m17n-X library, the followings are also accepted.
+
+@verbatim
+
+        key             type of value   meaning of value
+        ---             -------------   ----------------
+        Mdisplay        Display *       Display associated with the frame.
+
+        Mscreen         int             Screen number of a screen associated
+                                        with the frame.
+
+        Mcolormap       Colormap        Colormap of the frame.
+
+        Mdepth          unsigned        Depth of the frame.
+@endverbatim
+*/
+
+/***ja
+    @brief ¥Õ¥ì¡¼¥à¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹.
+
+    ´Ø¿ô mframe_get_prop () ¤Ï¥Õ¥ì¡¼¥à $FRAME ¤Î¥­¡¼ $KEY 
+    ¤ò»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£Í­¸ú¤Ê¥­¡¼¤È¤½¤ÎÃͤϰʲ¼¤ÎÄ̤ꡣ
+
+@verbatim
+
+        ¥­¡¼            Ãͤη¿          ÃͤΰÕÌ£
+        ---             -------------   ----------------
+        Mface           MFace *         ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹
+
+        Mfont           MFont *         ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È
+
+        Mfont_width     int             ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤ÎÉý
+
+        Mfont_ascent    int             ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤Î ascent
+
+        Mfont_descent   int             ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤Î descent
+
+@endverbatim
+
+     m17n-X ¥é¥¤¥Ö¥é¥ê¤Ç¤Ï¡¢°Ê²¼¤Î¥­¡¼¤â»ÈÍѤǤ­¤ë¡£
+
+@verbatim
+
+        ¥­¡¼            Ãͤη¿          ÃͤΰÕÌ£
+        ---             -------------   ----------------
+        Mdisplay        Display *       ¥Õ¥ì¡¼¥à¤È´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Ç¥£¥¹¥×¥ì¥¤
+
+        Mscreen         int             ¥Õ¥ì¡¼¥à¤È´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥¹¥¯¥ê¡¼¥ó
+                                        ¤Î¥¹¥¯¥ê¡¼¥ó¥Ê¥ó¥Ð
+
+        Mcolormap       Colormap        ¥Õ¥ì¡¼¥à¤Î¥«¥é¡¼¥Þ¥Ã¥×
+
+        Mdepth          unsigned        ¥Õ¥ì¡¼¥à¤Î¿¼¤µ
+@endverbatim
+
+*/
+
+void *
+mframe_get_prop (MFrame *frame, MSymbol key)
+{
+  if (key == Mface)
+    return frame->face;
+  if (key == Mfont)
+    return frame->font;
+  if (key == Mfont_width)
+    return (void *) (frame->average_width);
+  if (key == Mfont_ascent)
+    return (void *) (frame->ascent);
+  if (key == Mfont_descent)
+    return (void *) (frame->descent);
+  return (*frame->driver->get_prop) (frame, key);
+}
+
+/*=*/
+
+/***en
+    @brief The default frame.
+
+    The external variable #mframe_default contains a pointer to the
+    default frame that is created by the first call of mframe ().  */
+
+/***ja
+    @brief ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à.
+
+    ³°ÉôÊÑ¿ô #mframe_default ¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò»ý¤Ä¡£
+    ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à¤Ï¡¢ºÇ½é¤Ë mframe () ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿¤È¤­¤Ëºî¤é¤ì¤ë¡£  */
+
+MFrame *mframe_default;
+
+/*** @} */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/m17n-gui.h b/src/m17n-gui.h
new file mode 100644 (file)
index 0000000..7800295
--- /dev/null
@@ -0,0 +1,1061 @@
+/* m17n-gui.h -- header file for the GUI API of the m17n library.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_GUI_H_
+#define _M17N_GUI_H_
+
+#ifndef _M17N_FLT_H_
+#include <m17n-flt.h>
+#endif
+
+#ifndef _M17N_H_
+#include <m17n.h>
+#endif
+
+M17N_BEGIN_HEADER
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+
+extern void m17n_init_win (void);
+#undef M17N_INIT
+#define M17N_INIT() m17n_init_win ()
+
+extern void m17n_fini_win (void);
+#undef M17N_FINI
+#define M17N_FINI() m17n_fini_win ()
+
+#endif
+
+/***en @defgroup m17nGUI GUI API
+    @brief API provided by libm17n-gui.so */
+/***ja @defgroup m17nGUI GUI API
+    @brief libm17n-gui.so ¤¬Ä󶡤¹¤ë API */
+/*=*/
+
+/*** @ingroup m17nGUI */
+/***en @defgroup m17nFrame Frame */
+/***ja @defgroup m17nFrame ¥Õ¥ì¡¼¥à */
+/*=*/
+
+/*** @ingroup m17nFrame */
+/***en
+    @brief Type of frames.
+
+    The type #MFrame is for a @e frame object.  Each frame holds
+    various information about the corresponding physical display/input
+    device.
+
+    The internal structure of the type #MFrame is concealed from an
+    application program, and its contents depend on the window system
+    in use.  In the m17n-X library, it contains the information about
+    @e display and @e screen in the X Window System.  */
+
+/***ja
+    @brief ¥Õ¥ì¡¼¥à¤Î·¿Àë¸À.
+
+    #MFrame ¤Ï¡¢@e ¥Õ¥ì¡¼¥à ¥ª¥Ö¥¸¥§¥¯¥ÈÍѤη¿¤Ç¤¢¤ë¡£
+    ¸Ä¡¹¤Î¥Õ¥ì¡¼¥à¤Ï¡¢¤½¤ì¤¬Âбþ¤¹¤ëʪÍýŪ¤Êɽ¼¨¡¿ÆþÎϥǥХ¤¥¹¤Î³Æ¼ï¾ðÊó¤òÊÝ»ý¤¹¤ë¡£
+
+    #MFrame ·¿¤ÎÆâÉô¹½Â¤¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤Ï¸«¤¨¤Ê¤¤¡£
+    ¤Þ¤¿¤½¤ÎÆâÍƤϻÈÍѤ¹¤ë¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡£¤Þ¤¿ m17n-X 
+    ¥é¥¤¥Ö¥é¥ê¤Ë¤ª¤±¤ë¥Õ¥ì¡¼¥à¤Ï¡¢X ¥¦¥£¥ó¥É¥¦¤Î @e display ¤È @e screen 
+    ¤Ë´Ø¤¹¤ë¾ðÊó¤ò»ý¤Ä¡£      */
+
+typedef struct MFrame MFrame;
+
+/*=*/
+
+extern MSymbol Mdevice;
+
+extern MSymbol Mfont;
+extern MSymbol Mfont_width;
+extern MSymbol Mfont_ascent;
+extern MSymbol Mfont_descent;
+extern MFrame *mframe_default;
+
+extern MSymbol Mdisplay;
+extern MSymbol Mscreen;
+extern MSymbol Mdrawable;
+extern MSymbol Mwidget;
+extern MSymbol Mdepth;
+extern MSymbol Mcolormap;
+
+extern MFrame *mframe (MPlist *plist);
+
+extern void *mframe_get_prop (MFrame *frame, MSymbol key);
+
+/* end of frame module */
+/*=*/
+
+/*** @ingroup m17nGUI  */
+/***en @defgroup m17nFont Font */
+/***ja @defgroup m17nFont ¥Õ¥©¥ó¥È */
+/*=*/
+
+/*** @ingroup m17nFont */
+/***en
+    @brief Type of fonts.
+
+    The type #MFont is the structure defining fonts.  It contains
+    information about the following properties of a font: foundry,
+    family, weight, style, stretch, adstyle, registry, size, and
+    resolution.
+
+    This structure is used both for specifying a font in a fontset
+    and for storing information about available system fonts.
+
+    The internal structure is concealed from an application program.  */
+
+/***ja
+    @brief ¥Õ¥©¥ó¥È¤Î·¿Àë¸À.
+
+    #MFont ·¿¤Ï¥Õ¥©¥ó¥È»ØÄêÍѤι½Â¤ÂΤǤ¢¤ê¡¢¥Õ¥©¥ó¥È¤Î¥×¥í¥Ñ¥Æ¥£¤Ç¤¢¤ë
+    foundry, family, weight, style, stretch, adstyle, registry,
+    size, resolution ¤Ë´Ø¤¹¤ë¾ðÊó¤ò´Þ¤à¡£
+
+    ¤³¤Î¹½Â¤ÂΤϥե©¥ó¥È¥»¥Ã¥ÈÆâ¤Î¥Õ¥©¥ó¥È¤ò»ØÄꤹ¤ëºÝ¤È¡¢»ÈÍѲÄǽ¤Ê¥·¥¹¥Æ¥à¥Õ¥©¥ó¥È¤Î¾ðÊó¤ò³ÊǼ¤¹¤ëºÝ¤ÎξÊý¤ËÍѤ¤¤é¤ì¤ë¡£
+
+    ÆâÉô¹½Â¤¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤Ï¸«¤¨¤Ê¤¤¡£  */
+
+/***
+    @seealso
+    mfont (), mfont_from_name (), mfont_find ().  */
+
+typedef struct MFont MFont;
+
+/*=*/
+
+extern MSymbol Mx, Mfreetype, Mxft;
+
+extern MPlist *mfont_freetype_path;
+
+extern MFont *mfont ();
+
+extern MFont *mfont_copy (MFont *font);
+
+extern MFont *mfont_parse_name (const char *name, MSymbol format);
+
+extern char *mfont_unparse_name (MFont *font, MSymbol format);
+
+/* These two are obsolete (from 1.1.0).  */
+extern char *mfont_name (MFont *font);
+extern MFont *mfont_from_name (const char *name);
+
+extern MSymbol Mfoundry;
+extern MSymbol Mfamily;
+extern MSymbol Mweight;
+extern MSymbol Mstyle;
+extern MSymbol Mstretch;
+extern MSymbol Madstyle;
+extern MSymbol Mspacing;
+extern MSymbol Mregistry;
+extern MSymbol Msize;
+extern MSymbol Mresolution;
+extern MSymbol Mmax_advance;
+extern MSymbol Motf;
+extern MSymbol Mfontfile;
+
+extern MSymbol Mfontconfig;
+
+extern void *mfont_get_prop (MFont *font, MSymbol key);
+
+extern int mfont_put_prop (MFont *font, MSymbol key, void *val);
+
+extern int mfont_set_encoding (MFont *font,
+                              MSymbol encoding_name, MSymbol repertory_name);
+
+
+/*=*/
+
+/***en
+    @brief Find a font.
+
+    The mfont_find () function returns a pointer to the available font
+    that matches best with the specification $SPEC in frame $FRAME.
+
+    $SCORE, if not NULL, must point to a place to store the score
+    value which indicates how well the found font matches $SPEC.  The
+    smaller score means a better match.
+
+    $LIMITED_SIZE, if nonzero, forces the font selector to find a
+    font not greater than the #Msize property of $SPEC.  */
+
+/***ja
+    @brief ¥Õ¥©¥ó¥È¤òõ¤¹.
+
+    ´Ø¿ô mfont_find () ¤Ï¡¢¥Õ¥ì¡¼¥à $FRAME ¾å¤Ç¥Õ¥©¥ó¥ÈÄêµÁ $SPEC 
+    ¤Ë¤â¤Ã¤È¤â¹çÃפ¹¤ë»ÈÍѲÄǽ¤Ê¥Õ¥©¥ó¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£  
+
+    $SCORE ¤Ï NULL ¤Ç¤¢¤ë¤«¡¢¸«¤Ä¤«¤Ã¤¿¥Õ¥©¥ó¥È¤¬ $SPEC 
+    ¤Ë¤É¤ì¤Û¤É¹ç¤Ã¤Æ¤¤¤ë¤«¤ò¼¨¤¹¥¹¥³¥¢¤òÊݸ¤¹¤ë¾ì½ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    ¥¹¥³¥¢¤¬¾®¤µ¤¤¤Û¤ÉÎɤ¯¹ç¤Ã¤Æ¤¤¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
+
+    $LIMITED_SIZE ¤¬ 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢$SPEC ¤Î¥×¥í¥Ñ¥Æ¥£ #Msize 
+    ¤è¤êÂ礭¤¯¤Ê¤¤¥Õ¥©¥ó¥È¤À¤±¤¬Ãµ¤µ¤ì¤ë¡£
+*/
+
+extern MFont *mfont_find (MFrame *frame, MFont *spec,
+                         int *score, int limited_size);
+extern MSymbol *mfont_selection_priority ();
+
+extern int mfont_set_selection_priority (MSymbol *keys);
+
+extern int mfont_resize_ratio (MFont *font);
+
+extern MPlist *mfont_list (MFrame *frame, MFont *font, MSymbol language,
+                          int maxnum);
+extern MPlist *mfont_list_family_names (MFrame *frame);
+
+typedef struct MFontset MFontset;
+
+extern int mfont_check (MFrame *frame, MFontset *fontset,
+                       MSymbol script, MSymbol language, MFont *font);
+
+extern int mfont_match_p (MFont *font, MFont *spec);
+
+extern MFont *mfont_open (MFrame *frame, MFont *font);
+
+extern MFont *mfont_encapsulate (MFrame *frame, MSymbol data_type, void *data);
+
+extern int mfont_close (MFont *font);
+
+/* end of font module */
+/*=*/
+
+/*** @ingroup m17nGUI  */
+/***en @defgroup m17nFontset Fontset */
+/***ja @defgroup m17nFontset ¥Õ¥©¥ó¥È¥»¥Ã¥È */
+/*=*/
+/*** @addtogroup m17nFontset
+     @{   */
+extern MFontset *mfontset (char *name);
+
+extern MSymbol mfontset_name (MFontset *fontset);
+
+extern MFontset *mfontset_copy (MFontset *fontset, char *name);
+
+extern int mfontset_modify_entry (MFontset *fontset,
+                                 MSymbol language, MSymbol script,
+                                 MSymbol charset,
+                                 MFont *spec, MSymbol layouter_name,
+                                 int how);
+
+extern MPlist *mfontset_lookup (MFontset *fontset, MSymbol script,
+                               MSymbol language, MSymbol charset);
+/*** @}   */
+/* end of fontset module */
+/*=*/
+
+/*** @ingroup m17nGUI */
+/***en @defgroup m17nFace Face */
+/***ja @defgroup m17nFace ¥Õ¥§¡¼¥¹ */
+/*=*/
+
+/*** @ingroup m17nFace */
+/***en
+    @brief Type of faces.
+
+    The type #MFace is the structure of face objects.  The internal
+    structure is concealed from an application program.  */
+
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¤Î·¿Àë¸À.
+
+    #MFace ·¿¤Ï¥Õ¥§¡¼¥¹¥ª¥Ö¥¸¥§¥¯¥È¤Î¤¿¤á¤Î¹½Â¤ÂΤǤ¢¤ë¡£
+    ÆâÉô¹½Â¤¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤Ï¸«¤¨¤Ê¤¤¡£  */
+
+typedef struct MFace MFace;
+/*=*/
+
+extern MSymbol Mforeground;
+extern MSymbol Mbackground;
+extern MSymbol Mvideomode;
+extern MSymbol Mnormal;
+extern MSymbol Mreverse;
+extern MSymbol Mhline;
+extern MSymbol Mbox;
+extern MSymbol Mfontset;
+extern MSymbol Mratio;
+extern MSymbol Mhook_func;
+extern MSymbol Mhook_arg;
+
+/* Predefined faces.  */
+extern MFace *mface_normal_video;
+extern MFace *mface_reverse_video;
+extern MFace *mface_underline;
+extern MFace *mface_medium;
+extern MFace *mface_bold;
+extern MFace *mface_italic;
+extern MFace *mface_bold_italic;
+extern MFace *mface_xx_small;
+extern MFace *mface_x_small;
+extern MFace *mface_small;
+extern MFace *mface_normalsize;
+extern MFace *mface_large;
+extern MFace *mface_x_large;
+extern MFace *mface_xx_large;
+extern MFace *mface_black;
+extern MFace *mface_white;
+extern MFace *mface_red;
+extern MFace *mface_green;
+extern MFace *mface_blue;
+extern MFace *mface_cyan;
+extern MFace *mface_yellow;
+extern MFace *mface_magenta;
+
+/* etc */
+extern MSymbol Mface;
+
+extern MFace *mface ();
+
+extern int mface_equal (MFace *face1, MFace *face2);
+
+extern MFace *mface_copy (MFace *face);
+
+extern MFace *mface_merge (MFace *dst, MFace *src);
+
+extern MFace *mface_from_font (MFont *font);
+
+/*=*/
+
+/*** @ingroup m17nFace */
+/***en
+    @brief Type of horizontal line spec of face.
+
+    The type #MFaceHLineProp is to specify the detail of #Mhline
+    property of a face.  The value of the property must be a pointer
+    to an object of this type.  */
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¤Î¿åÊ¿Àþ»ØÄêÍÑ·¿Àë¸À.
+
+    #MFaceHLineProp ¤Ï¥Õ¥§¡¼¥¹¤Î #Mhline 
+    ¥×¥í¥Ñ¥Æ¥£¤Î¾ÜºÙ¤ò»ØÄꤹ¤ë·¿¤Ç¤¢¤ë¡£¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϤ³¤Î·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+      */
+
+typedef struct
+{
+  /***en Type of the horizontal line.  */
+  /***ja ¿åÊ¿Àþ¤Î¥¿¥¤¥×.  */
+  enum MFaceHLineType
+    {
+      MFACE_HLINE_BOTTOM,      
+      MFACE_HLINE_UNDER,
+      MFACE_HLINE_STRIKE_THROUGH,
+      MFACE_HLINE_OVER,
+      MFACE_HLINE_TOP
+    } type;
+
+  /***en Width of the line in pixels.  */
+  /***ja ÀþÉý¡Ê¥Ô¥¯¥»¥ëñ°Ì¡Ë.  */
+  unsigned width;
+
+  /***en Color of the line.  If the value is Mnil, foreground color of
+      a merged face is used.  */
+  /***ja Àþ¤Î¿§.  Mnil ¤Ê¤é¤Ð¡¢Åý¹ç¤·¤¿¥Õ¥§¡¼¥¹¤ÎÁ°·Ê¿§¤¬»È¤ï¤ì¤ë¡£  */
+  
+  MSymbol color;
+} MFaceHLineProp;
+/*=*/
+
+/*** @ingroup m17nFace */
+/***en
+    @brief Type of box spec of face.
+
+    The type #MFaceBoxProp is to specify the detail of #Mbox property
+    of a face.  The value of the property must be a pointer to an
+    object of this type.  */
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¤Î°Ï¤ßÏÈ»ØÄêÍÑ·¿Àë¸À.
+
+    #MFaceBoxProp ¤Ï¥Õ¥§¡¼¥¹¤Î #Mbox ¥×¥í¥Ñ¥Æ¥£¤Î¾ÜºÙ¤ò»ØÄꤹ¤ë·¿¤Ç¤¢¤ë¡£
+    ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϤ³¤Î·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+      */
+
+typedef struct
+{
+  /***en Width of the box line in pixels.  */
+  /***ja ÀþÉý¡Ê¥Ô¥¯¥»¥ëñ°Ì¡Ë.  */
+  unsigned width;
+
+  /* @{ */
+  /*** Colors of borders.  */
+  MSymbol color_top;
+  MSymbol color_bottom;
+  MSymbol color_left;
+  MSymbol color_right;
+  /* @} */
+
+  /* @{ */
+  /*** Margins  */
+  unsigned inner_hmargin;
+  unsigned inner_vmargin;
+  unsigned outer_hmargin;
+  unsigned outer_vmargin;
+  /* @} */
+
+} MFaceBoxProp;
+/*=*/
+
+/*** @ingroup m17nFace */
+/***en
+    @brief Type of hook function of face.
+
+    #MFaceHookFunc is a type of a hook function of a face.  */
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¤Î¥Õ¥Ã¥¯´Ø¿ô¤Î·¿Àë¸À.
+
+    #MFaceHookFunc ¤Ï¥Õ¥§¡¼¥¹¤Î¥Õ¥Ã¥¯´Ø¿ô¤Î·¿¤Ç¤¢¤ë¡£*/
+typedef void (*MFaceHookFunc) (MFace *face, void *arg, void *info);
+/*=*/
+
+extern void *mface_get_prop (MFace *face, MSymbol key);
+
+extern int mface_put_prop (MFace *face, MSymbol key, void *val);
+
+extern MFaceHookFunc mface_get_hook (MFace *face);
+
+extern int mface_put_hook (MFace *face, MFaceHookFunc func);
+
+extern void mface_update (MFrame *frame, MFace *face);
+
+/* end of face module */
+/*=*/
+
+/*** @ingroup m17nGUI */
+/***en @defgroup m17nDraw Drawing */
+/***ja @defgroup m17nDraw É½¼¨ */
+/*=*/
+
+/*** @ingroup m17nDraw */
+/***en
+    @brief Window system dependent type for a window.
+
+    The type #MDrawWindow is for a window; a rectangular area that
+    works in several ways like a miniature screen.
+
+    What it actually points depends on a window system.  A program
+    that uses the m17n-X library must coerce the type @c Drawable to
+    this type.  */
+/***ja 
+    @brief ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡¢¥¦¥£¥ó¥É¥¦¤Î·¿Àë¸À.
+
+    #MDrawWindow ¤Ï¥¦¥£¥ó¥É¥¦¡¢¤¹¤Ê¤ï¤Á´ö¤Ä¤«¤ÎÅÀ¤Ç¥¹¥¯¥ê¡¼¥ó¤Î¥ß¥Ë¥Á¥å¥¢¤È¤·¤ÆƯ¤¯¶ë·ÁÎΰèÍѤη¿¤Ç¤¢¤ë¡£
+
+    ¼ÂºÝ¤Ë²¿¤ò»Ø¤¹¤«¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡£ m17n X 
+    ¥é¥¤¥Ö¥é¥ê¤òÍøÍѤ¹¤ë¥×¥í¥°¥é¥à¤Ï @c Drawable ·¿¤ò¤³¤Î·¿¤ËÊÑ´¹¤·¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£ */
+
+typedef void *MDrawWindow;
+/*=*/
+
+/*** @ingroup m17nDraw */
+/***en
+    @brief Window system dependent type for a region.
+
+    The type #MDrawRegion is for a region; an arbitrary set of pixels
+    on the screen (typically a rectangular area).
+
+    What it actually points depends on a window system.  A program
+    that uses the m17n-X library must coerce the type @c Region to
+    this type.  */
+/***ja
+    @brief ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡¢Îΰè¤Î·¿Àë¸À.
+
+    #MDrawRegion ¤ÏÎΰ衢¤¹¤Ê¤ï¤Á¥¹¥¯¥ê¡¼¥ó¾å¤ÎǤ°Õ¤Î¥Ô¥¯¥»¥ë¤Î½¸¹ç¡Êŵ·¿Åª¤Ë¤Ï¶ë·ÁÎΰè¡ËÍѤη¿¤Ç¤¢¤ë¡£
+
+    ¼ÂºÝ¤Ë²¿¤ò»Ø¤¹¤«¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡£ m17n X 
+    ¥é¥¤¥Ö¥é¥ê¤òÍøÍѤ¹¤ë¥×¥í¥°¥é¥à¤Ï @c Region ·¿¤ò¤³¤Î·¿¤ËÊÑ´¹¤·¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£  */
+
+typedef void *MDrawRegion;
+/*=*/
+
+/*** @ingroup m17nDraw */
+/***en
+    @brief Type of a text drawing control.
+
+    The type #MDrawControl is the structure that controls how to draw
+    an M-text.  */
+/***ja
+    @brief ¥Æ¥­¥¹¥Èɽ¼¨À©¸æ¤Î·¿Àë¸À.
+
+    #MDrawControl ·¿¤Ï¡¢M-text ¤ò¤É¤¦É½¼¨¤¹¤ë¤«¤òÀ©¸æ¤¹¤ë¹½Â¤ÂΤǤ¢¤ë¡£
+      */
+
+
+typedef struct
+{
+  /***en If nonzero, draw an M-text as image, i.e. with background
+      filled with background colors of faces put on the M-text.
+      Otherwise, the background is not changed.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢ M-text ¤ò²èÁü¤È¤·¤Æ¡¢¤¹¤Ê¤ï¤ÁÇطʤò M-text 
+      ¤Î¥Õ¥§¡¼¥¹¤Ç»ØÄꤵ¤ì¤Æ¤¤¤ëÇØ·Ê¿§¤ÇËä¤á¤Æɽ¼¨¤¹¤ë¡£¤½¤¦¤Ç¤Ê¤±¤ì¤ÐÇطʤÏÊѤï¤é¤Ê¤¤¡£  */
+  unsigned as_image : 1;
+
+  /***en If nonzero and the first glyph of each line has negative
+      lbearing, shift glyphs horizontally to right so that no pixel is
+      drawn to the left of the specified position.  */
+  /***ja 0 ¤Ç¤Ê¤¯¡¢³Æ¹Ô¤ÎºÇ½é¤Î¥°¥ê¥Õ¤Î lbearing 
+      ¤¬Éé¤Ê¤é¤Ð¡¢¥°¥ê¥Õ¤ò¿åÊ¿¤Ë±¦¤Ë¤º¤é¤·¤Æ¡¢»ØÄꤷ¤¿°ÌÃÖ¤è¤êº¸¤Ë¥Ô¥¯¥»¥ë¤¬ÉÁ¤«¤ì¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¡£  */
+  unsigned align_head : 1;
+
+  /***en If nonzero, draw an M-text two-dimensionally, i.e., newlines
+      in M-text breaks lines and the following characters are drawn in
+      the next line.  If \<format\> is non-NULL, and the function
+      returns nonzero line width, a line longer than that width is
+      also broken.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢M-text ¤ò£²¼¡¸µÅª¤Ë¡¢¤¹¤Ê¤ï¤Á M-text Ãæ¤Î 
+      newline ¤Ç²þ¹Ô¤·¡¢Â³¤¯Ê¸»ú¤Ï¼¡¤Î¹Ô¤Ëɽ¼¨¤¹¤ë¡£¤â¤· \<format\> ¤¬ 
+      NULL ¤Ç¤Ê¤¯¡¢¤½¤Î´Ø¿ô¤¬ 0 ¤Ç¤Ê¤¤¹ÔÉý¤òÊÖ¤»¤Ð¡¢¤½¤ÎÉý¤è¤êŤ¤¹Ô¤â²þ¹Ô¤µ¤ì¤ë¡£  */
+  unsigned two_dimensional : 1;
+
+  /***en If nonzero, draw an M-text to the right of a specified
+      position.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢M-text ¤ò»ØÄꤷ¤¿°ÌÃ֤ᦤËɽ¼¨¤¹¤ë¡£  */
+  unsigned orientation_reversed : 1;
+
+  /***en If nonzero, reorder glyphs correctly for bidi text.  */ 
+  /***ja 0 ¤Ê¤±¤ì¤Ð¡¢bidi ¥Æ¥­¥¹¥ÈÍѤ˥°¥ê¥Õ¤òÀµ¤·¤¯À°Î󤹤롣  */
+  unsigned enable_bidi : 1;
+
+  /***en If nonzero, don't draw characters whose general category (in
+      Unicode) is Cf (Other, format).  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢¥æ¥Ë¥³¡¼¥É¤ËÃÖ¤±¤ë°ìÈÌ¥«¥Æ¥´¥ê¤¬ Cf (Other,
+      format) ¤Ç¤¢¤ëʸ»ú¤òɽ¼¨¤·¤Ê¤¤¡£  */
+  unsigned ignore_formatting_char : 1;
+
+  /***en If nonzero, draw glyphs suitable for a terminal.  Not yet
+      implemented.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢Ã¼ËöÍѤΥ°¥ê¥Õ¤òɽ¼¨¤¹¤ë¡£Ì¤¼ÂÁõ¡£  */
+  unsigned fixed_width : 1;
+
+  /***en If nonzero, draw glyphs with anti-aliasing if a backend font
+      driver supports it.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢¥¢¥ó¥Á¥¨¡¼¥ê¥¢¥¹¤Ç¥°¥ê¥Õ¤òɽ¼¨¤¹¤ë¡£
+      ¡Ê¥Ð¥Ã¥¯¥¨¥ó¥É¤Î¥Õ¥©¥ó¥È¥É¥é¥¤¥Ð¤¬¥¢¥ó¥Á¥¨¡¼¥ê¥¢¥¹µ¡Ç½¤ò»ý¤Ä¾ì¹ç¤Î¤ß¡£¡Ë */
+  unsigned anti_alias : 1;
+
+  /***en If nonzero, disable the adjustment of glyph positions to
+      avoid horizontal overlapping at font boundary.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢¥Õ¥©¥ó¥È¶­³¦¤Ç¤Î¿åÊ¿Êý¸þ¤Î¥°¥ê¥Õ¤Î½Å¤Ê¤ê¤òÈò¤±¤ë¤¿¤á¤Î¥°¥ê¥Õ°ÌÃÖ¤ÎÄ´À°¤ò̵¸ú¤Ë¤¹¤ë¡£  */
+  unsigned disable_overlapping_adjustment : 1;
+
+  /***en If nonzero, the values are minimum line ascent pixels.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢ÃͤϹԤΠascent ¤ÎºÇ¾®Ãͤò¼¨¤¹¡£  */
+  unsigned int min_line_ascent;
+  /***en If nonzero, the values are minimum line descent pixels.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢ÃͤϹԤΠdescent ¤ÎºÇ¾®Ãͤò¼¨¤¹¡£  */
+  unsigned int min_line_descent;
+
+  /***en If nonzero, the values are maximum line ascent pixels.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢ÃͤϹԤΠascent ¤ÎºÇÂçÃͤò¼¨¤¹¡£  */
+  unsigned int max_line_ascent;
+  /***en If nonzero, the values are maximum line descent pixels.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢ÃͤϹԤΠdescent ¤ÎºÇÂçÃͤò¼¨¤¹¡£  */
+  unsigned int max_line_descent;
+
+  /***en If nonzero, the value specifies how many pixels each line can
+      occupy on the display.  The value zero means that there is no
+      limit.  It is ignored if \<format\> is non-NULL.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢ÃͤϤ³¤Î¥Ç¥£¥¹¥×¥ì¥¤¾å¤Ç³Æ¹Ô¤¬Àê¤á¤ë¤³¤È¤Î¤Ç¤­¤ë¥Ô¥¯¥»¥ë¿ô¤ò¼¨¤¹¡£
+      0 ¤Ï¸ÂÄꤵ¤ì¤Ê¤¤¤³¤È¤ò°ÕÌ£¤¹¤ë¡£\<format\> ¤¬ NULL ¤Ç¤Ê¤±¤ì¤Ð̵»ë¤µ¤ì¤ë¡£   */
+  unsigned int max_line_width;
+
+  /***en If nonzero, the value specifies the distance between tab
+      stops in columns (the width of one column is the width of a
+      space in the default font of the frame).  The value zero means
+      8.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢Ãͤϥ¿¥Ö¥¹¥È¥Ã¥×´Ö¤Îµ÷Î¥¤ò¥³¥é¥àñ°Ì
+      ¡Ê¥³¥é¥à¤Ï¥Õ¥ì¡¼¥à¤Î¥Ç¥Õ¥©¥ë¥È¥Õ¥©¥ó¥È¤Ë¤ª¤±¤ë¶õÇòʸ»ú¤ÎÉý¤Ç¤¢¤ë¡Ë¤Ç¼¨¤¹¡£ 
+      0 ¤Ï 8 ¤ò°ÕÌ£¤¹¤ë¡£ */
+  unsigned int tab_width;
+
+  /***en If non-NULL, the value is a function that calculates the
+      indentation and width limit of each line based on the line
+      number LINE and the coordinate Y.  The function store the
+      indentation and width limit at the place pointed by INDENT and
+      WIDTH respectively.
+
+      The indentation specifies how many pixels the first glyph of
+      each line is shifted to the right (if the member
+      \<orientation_reversed\> is zero) or to the left (otherwise).  If
+      the value is negative, each line is shifted to the reverse
+      direction.
+
+      The width limit specifies how many pixels each line can occupy
+      on the display.  The value 0 means that there is no limit.
+
+      LINE and Y are reset to 0 when a line is broken by a newline
+      character, and incremented each time when a long line is broken
+      because of the width limit.
+
+      This has an effect only when \<two_dimensional\> is nonzero.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢Ãͤϴؿô¤Ç¤¢¤ê¡¢¤½¤Î´Ø¿ô¤Ï¹ÔÈÖ¹æ LINE ¤ÈºÂɸ Y 
+      ¤Ë´ð¤Å¤¤¤Æ³Æ¹Ô¤Î¥¤¥ó¥Ç¥ó¥È¤ÈºÇÂçÉý¤ò·×»»¤·¡¢¤½¤ì¤¾¤ì¤òINDENT ¤È
+      WIDTH ¤Ç»Ø¤µ¤ì¤ë¾ì½ê¤ËÊݸ¤¹¤ë¡£
+
+      ¥¤¥ó¥Ç¥ó¥È¤Ï¡¢³Æ¹Ô¤ÎºÇ½é¤Î¥°¥ê¥Õ¤ò±¦¡Ê¥á¥ó¥Ð 
+      \<orientation_reversed\> ¤¬ 0 
+      ¤Î»þ¡Ë¤¢¤ë¤¤¤Ïº¸¡Ê¤½¤ì°Ê³°¤Î»þ¡Ë¤Ë²¿¥Ô¥¯¥»¥ë¤º¤é¤¹¤«¤ò»ØÄꤹ¤ë¡£Ãͤ¬Éé¤Ê¤é¤ÐµÕÊý¸þ¤Ë¤º¤é¤¹¡£
+
+      ºÇÂçÉý¤Ï¡¢³Æ¹Ô¤¬¥Ç¥£¥¹¥×¥ì¥¤¾å¤ÇÀê¤á¤ë¤³¤È¤Î¤Ç¤­¤ë¥Ô¥¯¥»¥ë¿ô¤ÎºÇÂçÃͤǤ¢¤ë¡£Ãͤ¬
+      0 ¤Î¾ì¹ç¤ÏÀ©¸Â¤ò¼õ¤±¤Ê¤¤¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
+
+      LINE ¤È Y ¤Ï²þ¹Ôʸ»ú¤Ë¤è¤Ã¤Æ¹Ô¤¬²þ¤Þ¤Ã¤¿ºÝ¤Ë¤Ï 0 
+      ¤Ë¥ê¥»¥Ã¥È¤µ¤ì¡¢Ä¹¤¤¹Ô¤¬ºÇÂçÉý¤ÎÀ©¸Â¤Ë¤è¤Ã¤Æ²þ¹Ô¤µ¤ì¤ë¤¿¤Ó¤Ë 1 Áý¤ä¤µ¤ì¤ë¡£
+
+      ¤³¤ì¤Ï \<two_dimensional\> ¤¬ 0 ¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Î¤ßÍ­¸ú¤Ç¤¢¤ë¡£  */
+  void (*format) (int line, int y, int *indent, int *width);
+
+  /***en If non-NULL, the value is a function that calculates a line
+      breaking position when a line is too long to fit within the
+      width limit.  POS is the position of the character next to the
+      last one that fits within the limit.  FROM is the position of the
+      first character of the line, and TO is the position of the last
+      character displayed on the line if there were not width limit.
+      LINE and Y are the same as the arguments to \<format\>.
+
+      The function must return a character position to break the
+      line.
+
+      The function should not modify MT.
+
+      The mdraw_default_line_break () function is useful for such a
+      script that uses SPACE as a word separator.  */
+  /***ja NULL ¤Ç¤Ê¤±¤ì¤Ð¡¢ÃͤϹԤ¬ºÇÂçÉýÃæ¤Ë¼ý¤Þ¤é¤Ê¤¤¾ì¹ç¤Ë¹Ô¤ò²þ¤á¤ë°ÌÃÖ¤ò·×»»¤¹¤ë´Ø¿ô¤Ç¤¢¤ë¡£
+      POS ¤ÏºÇÂçÉý¤Ë¼ý¤Þ¤ëºÇ¸å¤Îʸ»ú¤Î¼¡¤Îʸ»ú¤Î°ÌÃ֤Ǥ¢¤ë¡£FROM
+      ¤Ï¹Ô¤ÎºÇ½é¤Îʸ»ú¤Î°ÌÃÖ¡¢TO 
+      ¤ÏºÇÂçÉý¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¤½¤Î¹Ô¤Ëɽ¼¨¤µ¤ì¤ëºÇ¸å¤Îʸ»ú¤Î°ÌÃ֤Ǥ¢¤ë¡£LINE 
+      ¤È Y ¤Ï \<format\> ¤Î°ú¿ô¤ÈƱÍͤǤ¢¤ë¡£
+
+      ¤³¤Î´Ø¿ô¤Ï¹Ô¤ò²þ¤á¤ëʸ»ú°ÌÃÖ¤òÊÖ¤µ¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤Þ¤¿ MT ¤òÊѹ¹¤·¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+      ´Ø¿ô mdraw_default_line_break ()
+      ¤Ï¡¢¶õÇò¤ò¸ì¤Î¶èÀÚ¤ê¤È¤·¤ÆÍѤ¤¤ë¥¹¥¯¥ê¥×¥ÈÍѤȤ·¤ÆÍ­ÍѤǤ¢¤ë¡£  */
+  int (*line_break) (MText *mt, int pos, int from, int to, int line, int y);
+
+  /***en If nonzero, show the cursor according to \<cursor_width\>.  */
+  /***ja ¥¼¥í¤Ç¤Ê¤±¤ì¤Ð \<cursor_width\> ¤Ë¤·¤¿¤¬¤Ã¤Æ¥«¡¼¥½¥ë¤òɽ¼¨¤¹¤ë¡£ */
+  int with_cursor;
+
+  /***en Specifies the character position to display a cursor.  If it
+      is greater than the maximum character position, the cursor is
+      displayed next to the last character of an M-text.  If the value
+      is negative, even if \<cursor_width\> is nonzero, cursor is not
+      displayed.  */
+  /***ja ¥«¡¼¥½¥ë¤òɽ¼¨¤¹¤ëʸ»ú°ÌÃÖ¤ò¼¨¤¹¡£ºÇÂç¤Îʸ»ú°ÌÃÖ¤è¤êÂ礭¤±¤ì¤Ð¡¢¥«¡¼¥½¥ë¤Ï 
+      M-text ¤ÎºÇ¸å¤Îʸ»ú¤ÎÎÙ¤Ëɽ¼¨¤µ¤ì¤ë¡£Éé¤Ê¤é¤Ð¡¢
+      \<cursor_width\> ¤¬ 0 ¤Ç¤Ê¤¯¤Æ¤â¥«¡¼¥½¥ë¤Ïɽ¼¨¤µ¤ì¤Ê¤¤¡£
+        */
+  int cursor_pos;
+
+  /***en If nonzero, display a cursor at the character position
+      \<cursor_pos\>.  If the value is positive, it is the pixel width
+      of the cursor.  If the value is negative, the cursor width is
+      the same as the underlining glyph(s).  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢\<cursor_pos\> ¤Ë¥«¡¼¥½¥ë¤òɽ¼¨¤¹¤ë¡£
+      Ãͤ¬Àµ¤Ê¤é¤Ð¡¢¥«¡¼¥½¥ë¤ÎÉý¤Ï¤½¤ÎÃÍ¡Ê¥Ô¥¯¥»¥ëñ°Ì¡Ë¤Ç¤¢¤ë¡£
+      Éé¤Ê¤é¤Ð¡¢¥«¡¼¥½¥ë¤Î¤¢¤ë¥°¥ê¥Õ¤ÈƱ¤¸Éý¤Ç¤¢¤ë¡£  */
+  int cursor_width;
+
+  /***en If nonzero and \<cursor_width\> is also nonzero, display double
+      bar cursors; at the character position \<cursor_pos\> and at the
+      logically previous character.  Both cursors have one pixel width
+      with horizontal fringes at upper or lower positions.  */
+  /***ja If 0 ¤Ç¤Ê¤¯¡¢¤«¤Ä \<cursor_width\> ¤â 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢¥Ð¡¼¥«¡¼¥½¥ë¤òʸ»ú°ÌÃÖ
+      \<cursor_pos\> ¤ÈÏÀÍýŪ¤Ë¤½¤ì¤ÎÁ°¤Ë¤¢¤ëʸ»ú¤Î£²¥ö½ê¤Ëɽ¼¨¤¹¤ë¡£
+      ÁÐÊý¤È¤â£±¥Ô¥¯¥»¥ëÉý¤Ç¡¢¾å¤«²¼¤Ë¿åÊ¿¤Î¾þ¤ê¤¬¤Ä¤¯¡£*/
+  int cursor_bidi;
+
+  /***en If nonzero, on drawing partial text, pixels of surrounding
+      texts that intrude into the drawing area are also drawn.  For
+      instance, some CVC sequence of Thai text (C is consonant, V is
+      upper vowel) is drawn so that V is placed over the middle of two
+      Cs.  If this CVC sequence is already drawn and only the last C
+      is drawn again (for instance by updating cursor position), the
+      right half of V is erased if this member is zero.  By setting
+      this member to nonzero, even with such a drawing, we can keep
+      this CVC sequence correctly displayed.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢¥Æ¥­¥¹¥È¤Î°ìÉôʬ¤òɽ¼¨¤¹¤ëºÝ¤Ë¡¢Á°¸å¤Î¥Æ¥­¥¹¥È¤Î¤¦¤Á¤½¤Îɽ¼¨Îΰè¤Ë¿¯Æþ¤¹¤ëÉôʬ¤âɽ¼¨¤¹¤ë¡£
+      ¤¿¤È¤¨¤Ð¡¢¥¿¥¤¸ì¥Æ¥­¥¹¥È »Ò²»-Êì²»-»Ò²» 
+      ¤È¤¤¤¦¥·¡¼¥¯¥¨¥ó¥¹¤Î¤¤¤¯¤Ä¤«¤Ï¡¢Êì²»¤¬Æó¤Ä¤Î»Ò²»¤Î´Ö¤Ë¾å¤Ë¤Î¤ë¤è¤¦¤ËÉÁ¤«¤ì¤ë¡£
+      ¤³¤Î¤è¤¦¤Ê¥·¡¼¥¯¥¨¥ó¥¹¤¬¤¹¤Ç¤ËÉÁ¤«¤ì¤Æ¤ª¤ê¡¢ºÇ¸å¤Î»Ò²»¤À¤±¤òÉÁ¤­Ä¾¤¹¾ì¹ç
+      ¡Ê¤¿¤È¤¨¤Ð¡¢¥«¡¼¥½¥ë°ÌÃÖ¤ò¹¹¿·¤¹¤ëºÝ¤Ê¤É¡Ë¤³¤Î¥á¥ó¥Ð¤¬ 0 
+      ¤Ç¤¢¤ì¤Ð¡¢Êì²»¤Î±¦È¾Ê¬¤¬¾Ã¤µ¤ì¤Æ¤·¤Þ¤¦¡£¤³¤ì¤ò 0 °Ê³°¤Ë¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¡¢¤½¤Î¤è¤¦¤ÊºÝ¤Ë¤â
+      »Ò²»-Êì²»-»Ò²» ¤Î¥·¡¼¥¯¥¨¥ó¥¹¤òÀµ¤·¤¯É½¼¨¤·Â³¤±¤ë¤³¤È¤¬¤Ç¤­¤ë¡£  */
+  int partial_update;
+
+  /***en If nonzero, don't cache the result of any drawing information
+      of an M-text.  */
+  /***ja 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢M-text ¤Îɽ¼¨¤Ë´Ø¤¹¤ë¾ðÊó¤ò¥­¥ã¥Ã¥·¥å¤·¤Ê¤¤¡£
+       */
+  int disable_caching;
+
+  /***en If non-NULL, limit the drawing effect to the specified region.  */
+  /***ja NULL ¤Ç¤Ê¤±¤ì¤Ðɽ¼¨¥¨¥ê¥¢¤ò»ØÄꤵ¤ì¤¿Îΰè¤Ë¸ÂÄꤹ¤ë¡£ */
+  MDrawRegion clip_region;
+
+} MDrawControl;
+
+extern int mdraw_line_break_option;
+
+/*=*/
+
+/*** @ingroup m17nDraw */
+/***en
+    @brief Type of metric for glyphs and texts.
+
+    The type #MDrawMetric is for a metric of a glyph and a drawn text.
+    It is also used to represent a rectangle area of a graphic
+    device.  */
+/***ja
+    @brief ¥°¥ê¥Õ¤È¥Æ¥­¥¹¥È¤ÎÀ£Ë¡¤Î·¿Àë¸À.
+
+    #MDrawMetric ¤Ï¥°¥ê¥Õ¤Èɽ¼¨¤µ¤ì¤¿¥Æ¥­¥¹¥È¤ÎÀ£Ë¡ÍѤη¿¤Ç¤¢¤ë¡£
+    ¤Þ¤¿¡¢É½¼¨¥Ç¥Ð¥¤¥¹¤Î¶ë·ÁÎΰè¤òɽ¤¹¤Î¤Ë¤âÍѤ¤¤é¤ì¤ë¡£ */
+
+typedef struct {
+  /*** X coordinates of a glyph or a text.  */
+  int x;
+  /*** Y coordinates of a glyph or a text.  */
+  int y;
+  /*** Pixel width of a glyph or a text.  */
+  unsigned int width;
+  /*** Pixel height of a glyph or a text.  */
+  unsigned int height;
+} MDrawMetric;
+
+/*=*/
+
+/*** @ingroup m17nDraw */
+/***en
+    @brief Type of information about a glyph.
+
+    The type #MDrawGlyphInfo is the structure that contains
+    information about a glyph.  It is used by mdraw_glyph_info ().  */
+/***ja
+    @brief ¥°¥ê¥Õ¤Ë´Ø¤¹¤ë¾ðÊó¤Î·¿Àë¸À.
+
+    #MDrawGlyphInfo ·¿¤Ï¥°¥ê¥Õ¤Ë´Ø¤¹¤ë¾ðÊó¤ò´Þ¤à¹½Â¤ÂΤǤ¢¤ë¡£
+    mdraw_glyph_info () ¤Ï¤³¤ì¤òÍѤ¤¤ë¡£  */
+
+typedef struct
+{
+  /***en Start position of character range corresponding to the glyph.  */
+  /***ja ¥°¥ê¥Õ¤ËÂбþ¤¹¤ëʸ»ú¤ÎÈϰϤγ«»Ï°ÌÃÖ.  */
+  int from;
+
+  /***en End position of character range corresponding to the glyph.  */
+  /***ja ¥°¥ê¥Õ¤ËÂбþ¤¹¤ëʸ»ú¤ÎÈϰϤνªÎ»°ÌÃÖ.  */
+  int to;
+
+  /***en Start position of character range corresponding to the line of the glyph.  */
+  /***ja °ì¹Ô¤Î¥°¥ê¥Õ¤ÎÎó¤ËÂбþ¤¹¤ëʸ»ú¤ÎÈϰϤγ«»Ï°ÌÃÖ.  */
+  int line_from;
+  /***en End position of character range corresponding to the line of the glyph.  */
+  /***ja °ì¹Ô¤Î¥°¥ê¥Õ¤ÎÎó¤ËÂбþ¤¹¤ëʸ»ú¤ÎÈϰϤνªÎ»°ÌÃÖ.  */
+  int line_to;
+
+  /***en X coordinates of the glyph.  */
+  /***ja ¥°¥ê¥Õ¤Î X ºÂɸ.  */
+  int x;
+  /***en Y coordinates of the glyph.  */
+  /***ja ¥°¥ê¥Õ¤Î Y ºÂɸ.  */
+  int y;
+
+  /***en Metric of the glyph.  */
+  /***ja ¥°¥ê¥Õ¤ÎÀ£Ë¡.  */
+  MDrawMetric metrics;
+
+  /***en Font used for the glyph.  Set to NULL if no font is found for
+      the glyph.  */
+  /***ja ¥°¥ê¥Õ¤Ë»È¤ï¤ì¤ë¥Õ¥©¥ó¥È¡£¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð NULL¡£ */
+      
+  MFont *font;
+
+  /***en Character ranges corresponding to logically previous glyphs.
+      Note that we do not need the members prev_to because it must
+      be the same as the member \<from\>.  */
+  /***ja ÏÀÍýŪ¤ÊÁ°¤Î¥°¥ê¥Õ¤ËÂбþ¤¹¤ëʸ»ú¤ÎÈÏ°Ï¡£¥á¥ó¥Ð prev_to ¤Ï¡¢¥á
+      ¥ó¥Ð from ¤ÈƱ¤¸¤Ç¤¢¤ë¤Ï¤º¤Ê¤Î¤ÇÉÔÍפǤ¢¤ë¡£  */
+  int prev_from;
+  /***en Character ranges corresponding to logically next glyphs.
+      Note that we do not need the members next_from because it must
+      be the same as the member \<to\> respectively.  */
+  /***ja ÏÀÍýŪ¤Ê¸å¤Î¥°¥ê¥Õ¤ËÂбþ¤¹¤ëʸ»ú¤ÎÈÏ°Ï¡£¥á¥ó¥Ð next_from ¤Ï
+      ¥á¥ó¥Ð to ¤ÈƱ¤¸¤Ç¤¢¤ë¤Ï¤º¤Ê¤Î¤ÇÉÔÍפǤ¢¤ë¡£  */
+  int next_to;
+
+  /***en Start position of character ranges corresponding to visually
+      left glyphs. */
+  /***ja É½¼¨¾å¤Îº¸¤Î¥°¥ê¥Õ¤ËÂбþ¤¹¤ëʸ»ú¤ÎÈϰϤγ«»Ï°ÌÃÖ¡£  */
+  int left_from;
+  /***en End position of character ranges corresponding to visually
+      left glyphs. */
+  /***ja É½¼¨¾å¤Îº¸¤Î¥°¥ê¥Õ¤ËÂбþ¤¹¤ëʸ»ú¤ÎÈϰϤνªÎ»°ÌÃÖ¡£  */
+  int left_to;
+  /***en Start position of character ranges corresponding to visually
+      right glyphs. */
+  /***ja É½¼¨¾å¤Î±¦¤Î¥°¥ê¥Õ¤ËÂбþ¤¹¤ëʸ»ú¤ÎÈϰϤγ«»Ï°ÌÃÖ¡£  */
+  int right_from;
+  /***en End position of character ranges corresponding to visually
+      left glyphs. */
+  /***ja É½¼¨¾å¤Î±¦¤Î¥°¥ê¥Õ¤ËÂбþ¤¹¤ëʸ»ú¤ÎÈϰϤνªÎ»°ÌÃÖ¡£  */
+  int right_to;
+
+  /***en Logical width of the glyph.  Nominal distance to the next
+      glyph.  */
+  /***ja ¥°¥ê¥Õ¤ÎÏÀÍýŪÉý¡£¼¡¤Î¥°¥ê¥Õ¤È¤Î̾Ìܾå¤Îµ÷Î¥¡£  */
+  int logical_width;
+} MDrawGlyphInfo;
+
+/*=*/
+
+/*** @ingroup m17nDraw */
+/***en
+    @brief Type of information about a glyph metric and font.
+
+    The type #MDrawGlyph is the structure that contains information
+    about a glyph metric and font.  It is used by the function
+    mdraw_glyph_list ().  */
+/***ja
+    @brief ¥°¥ê¥Õ¤ÎÀ£Ë¡¤È¥Õ¥©¥ó¥È¤Ë´Ø¤¹¤ë¾ðÊó¤Î·¿Àë¸À.
+
+    #MDrawGlyph ·¿¤Ï¥°¥ê¥Õ¤ÎÀ£Ë¡¤È¥Õ¥©¥ó¥È¤Ë´Ø¤¹¤ë¾ðÊó¤ò´Þ¤à¹½Â¤ÂΤǤ¢¤ë¡£
+    mdraw_glyph_list () ¤Ï¤³¤ì¤òÍѤ¤¤ë¡£  */
+
+typedef struct
+{
+  /* @{ */
+  /***en Character range corresponding to the glyph.  */
+  /***ja ¥°¥ê¥Õ¤ËÂбþ¤¹¤ëʸ»ú¤ÎÈÏ°Ï.  */
+  int from, to;
+  /* @} */
+
+  /***en Font glyph code of the glyph.  */
+  /***ja ¥Õ¥©¥ó¥ÈÆâ¤Î¥°¥ê¥Õ¥³¡¼¥É¡£  */
+  int glyph_code;
+
+  /***en Logical width of the glyph.  Nominal distance to the next
+      glyph.  */
+  /***ja ¥°¥ê¥Õ¤ÎÏÀÍýŪÉý¡£¼¡¤Î¥°¥ê¥Õ¤È¤Î̾Ìܾå¤Îµ÷Î¥¡£  */
+  int x_advance;
+  /***en Logical height of the glyph.  Nominal distance to the next
+      glyph.  */
+  /***ja ¥°¥ê¥Õ¤ÎÏÀÍýŪ¹â¤µ¡£¼¡¤Î¥°¥ê¥Õ¤È¤Î̾Ìܾå¤Îµ÷Î¥¡£  */
+  int y_advance;
+
+  /***en X offset relative to the glyph position.  */
+  /***ja ¥°¥ê¥Õ¤Î°ÌÃÖ¤ËÂФ¹¤ë X ¥ª¥Õ¥»¥Ã¥È.  */
+  int x_off;
+  /***en Y offset relative to the glyph position.  */
+  /***ja ¥°¥ê¥Õ¤Î°ÌÃÖ¤ËÂФ¹¤ë Y ¥ª¥Õ¥»¥Ã¥È.  */
+  int y_off;
+
+  /***en Metric of the glyph (left-bearing).  */
+  /***ja ¥°¥ê¥Õ¤ÎÀ£Ë¡ (left-bearing).  */
+  int lbearing;
+  /***en Metric of the glyph (right-bearing).  */
+  /***ja ¥°¥ê¥Õ¤ÎÀ£Ë¡ (right-bearing).  */
+  int rbearing;
+  /***en Metric of the glyph (ascent).  */
+  /***ja ¥°¥ê¥Õ¤ÎÀ£Ë¡ (ascent).  */
+  int ascent;
+  /***en Metric of the glyph (descent).  */
+  /***ja ¥°¥ê¥Õ¤ÎÀ£Ë¡ (descent).  */
+  int descent;
+
+  /***en Font used for the glyph.  Set to NULL if no font is found for
+      the glyph.  */
+  /***ja ¥°¥ê¥Õ¤Ë»È¤ï¤ì¤ë¥Õ¥©¥ó¥È¡£¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð NULL¡£  */
+  MFont *font;
+
+  /***en Type of the font.  One of Mx, Mfreetype, Mxft.  */
+  /***ja ¥Õ¥©¥ó¥È¤Î¥¿¥¤¥×¡£Mx¡¢Mfreetype¡¢Mxft ¤Î¤¤¤º¤ì¤«¡£  */
+  MSymbol font_type;
+
+  /***en Pointer to the font structure.  The actual type is
+      (XFontStruct *) if \<font_type\> member is Mx, FT_Face if
+      \<font_type\> member is Mfreetype, and (XftFont *) if \<font_type\>
+      member is Mxft.  */
+  /***ja ¥Õ¥©¥ó¥È¤Î¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¡£¼ÂºÝ¤Î·¿¤Ï \<font_type\> ¥á¥ó¥Ð¤¬
+      Mx ¤Ê¤é (XFontStruct *)¡¢ Mfreetype ¤Ê¤é FT_Face¡¢Mxft 
+      ¤Ê¤é (XftFont *)¡£ */
+  void *fontp;
+
+} MDrawGlyph;
+
+/*=*/
+
+/***en
+    @brief Type of textitems.
+
+    The type #MDrawTextItem is for @e textitem objects.
+    Each textitem contains an M-text and some other information to
+    control the drawing of the M-text.  */
+
+/***ja
+    @brief textitem ¤Î·¿Àë¸À.
+
+    #MDrawTextItem ¤Ï @e ¥Æ¥­¥¹¥È¥¢¥¤¥Æ¥à ¥ª¥Ö¥¸¥§¥¯¥ÈÍѤη¿¤Ç¤¢¤ë¡£
+    ³Æ¥Æ¥­¥¹¥È¥¢¥¤¥Æ¥à¤Ï¡¢ 1 ¸Ä¤Î M-text ¤È¡¢¤½¤Îɽ¼¨¤òÀ©¸æ¤¹¤ë¤¿¤á¤Î¾ðÊó¤ò´Þ¤ó¤Ç¤¤¤ë¡£
+
+    @latexonly \IPAlabel{MTextItem} @endlatexonly  */
+
+typedef struct
+{
+  /***en M-text. */
+  /***ja M-text. */
+  MText *mt;                      
+
+  /***en Optional change in the position (in the unit of pixel) along
+      the X-axis before the M-text is drawn.  */
+  /***ja M-text É½¼¨Á°¤Ë¹Ô¤Ê¤¦X¼´Êý¸þ¤Î°ÌÃÖÄ´À° (¥Ô¥¯¥»¥ëñ°Ì) */
+  int delta;                     
+
+  /***en Pointer to a face object.  Each property of the face, if not
+      Mnil, overrides the same property of face(s) specified as a text
+      property in \<mt\>.  */
+  /***ja ¥Õ¥§¡¼¥¹¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¡£¥Õ¥§¡¼¥¹¤Î³Æ¥×¥í¥Ñ¥Æ¥£¤Ï 
+      Mnil ¤Ç¤Ê¤±¤ì¤Ð \<mt\> ¤Ç»ØÄꤵ¤ì¤¿¥Õ¥§¡¼¥¹¤ÎƱ¤¸¥×¥í¥Ñ¥Æ¥£¤ËÍ¥À褹¤ë*/
+  MFace *face;
+
+  /***en Pointer to a draw control object.  The M-text \<mt\> is drawn
+      by mdraw_text_with_control () with this control object.  */
+  /***ja É½¼¨À©¸æ¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¡£ mdraw_text_with_control () 
+      ¤Ï¤³¤Î¥ª¥Ö¥¸¥§¥¯¥È¤òÍѤ¤¤Æ M-text \<mt\> ¤òɽ¼¨¤¹¤ë¡£  */
+  MDrawControl *control;
+
+} MDrawTextItem;
+
+/*=*/
+
+extern int mdraw_text (MFrame *frame, MDrawWindow win, int x, int y,
+                      MText *mt, int from, int to);
+
+extern int mdraw_image_text (MFrame *frame, MDrawWindow win, int x, int y,
+                            MText *mt, int from, int to);
+
+extern int mdraw_text_with_control (MFrame *frame, MDrawWindow win,
+                                   int x, int y, MText *mt, int from, int to,
+                                   MDrawControl *control);
+
+extern int mdraw_coordinates_position (MFrame *frame,
+                                      MText *mt, int from, int to,
+                                      int x, int y, MDrawControl *control);
+
+extern int mdraw_text_extents (MFrame *frame,
+                              MText *mt, int from, int to,
+                              MDrawControl *control,
+                              MDrawMetric *overall_ink_return,
+                              MDrawMetric *overall_logical_return,
+                              MDrawMetric *overall_line_return);
+
+extern int mdraw_text_per_char_extents (MFrame *frame,
+                                       MText *mt, int from, int to,
+                                       MDrawControl *control,
+                                       MDrawMetric *ink_array_return,
+                                       MDrawMetric *logical_array_return,
+                                       int array_size,
+                                       int *num_chars_return,
+                                       MDrawMetric *overall_ink_return,
+                                       MDrawMetric *overall_logical_return);
+
+extern int mdraw_glyph_info (MFrame *frame, MText *mt, int from, int pos,
+                            MDrawControl *control, MDrawGlyphInfo *info);
+
+extern int mdraw_glyph_list (MFrame *frame, MText *mt, int from, int to,
+                            MDrawControl *control, MDrawGlyph *glyphs,
+                            int array_size, int *num_glyphs_return);
+
+extern void mdraw_text_items (MFrame *frame, MDrawWindow win, int x, int y,
+                             MDrawTextItem *items, int nitems);
+
+extern void mdraw_per_char_extents (MFrame *frame, MText *mt,
+                                   MDrawMetric *array_return,
+                                   MDrawMetric *overall_return);
+
+extern int mdraw_default_line_break (MText *mt, int pos,
+                                    int from, int to, int line, int y);
+
+extern void mdraw_clear_cache (MText *mt);
+
+/* end of drawing module */
+/*=*/
+
+/*** @ingroup m17nGUI */
+/***en @defgroup m17nInputMethodWin Input Method (GUI) */
+/***ja @defgroup m17nInputMethodWin ÆþÎϥ᥽¥Ã¥É (GUI) */
+/*=*/
+
+extern MInputDriver minput_gui_driver;
+
+/*=*/
+/*** @ingroup m17nInputMethodWin */
+/***en 
+    @brief Type of the argument to the function minput_create_ic ().
+
+    The type #MInputGUIArgIC is for the argument $ARG of the function
+    minput_create_ic () to create an input context of an internal
+    input method.  */
+
+/***ja
+    @brief ´Ø¿ô minput_create_ic () ¤Î°ú¿ô¤Î·¿Àë¸À.
+
+    #MInputGUIArgIC ¤Ï¡¢´Ø¿ô minput_create_ic () 
+    ¤¬ÆâÉôÆþÎϥ᥽¥Ã¥É¤ÎÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤òÀ¸À®¤¹¤ëºÝ¤Î¡¢°ú¿ô $ARG ÍѤη¿¤Ç¤¢¤ë¡£  */
+
+typedef struct
+{
+  /***en Frame of the client.  */
+  /***ja ¥¯¥é¥¤¥¢¥ó¥È¤Î¥Õ¥ì¡¼¥à  */
+  MFrame *frame;
+
+  /***en Window on which to display the preedit and status text.  */
+  /***ja preedit ¥Æ¥­¥¹¥È¤È status ¥Æ¥­¥¹¥È¤òɽ¼¨¤¹¤ë¥¦¥£¥ó¥É¥¦  */
+  MDrawWindow client;
+
+  /***en Window that the input context has a focus on.  */
+  /***ja ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤¬¥Õ¥©¡¼¥«¥¹¤ò¤ª¤¤¤Æ¤¤¤ë¥¦¥£¥ó¥É¥¦  */
+  MDrawWindow focus;
+} MInputGUIArgIC;
+
+/*=*/
+
+extern MSymbol minput_event_to_key (MFrame *frame, void *event);
+
+/* end of input module */
+/*=*/
+/* end of window modules */
+/*=*/
+
+extern MFace *mdebug_dump_face (MFace *face, int indent);
+extern MFont *mdebug_dump_font (MFont *font);
+extern MFontset *mdebug_dump_fontset (MFontset *fontset, int indent);
+
+M17N_END_HEADER
+
+#endif /* _M17N_GUI_H_ */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/m17n-misc.h b/src/m17n-misc.h
new file mode 100644 (file)
index 0000000..2021dba
--- /dev/null
@@ -0,0 +1,134 @@
+/* m17n-misc.h -- header file for the MISC API.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_ERR_H_
+#define _M17N_ERR_H_
+
+#ifndef _M17N_CORE_H_
+#include <m17n-core.h>
+#endif
+
+M17N_BEGIN_HEADER
+
+/*** @defgroup m17nMisc MISC API */
+/***en @brief Miscellaneous API */
+/***ja @brief ¤½¤Î¾¤Î API */
+/*=*/
+/*** @ingroup m17nMisc  */
+/***en @defgroup m17nError Error Handling */
+/***ja @defgroup m17nError ¥¨¥é¡¼½èÍý  */
+/*=*/
+
+/*** @ingroup m17nError */
+/***en 
+    @brief Enumeration for error code of the m17n library.
+
+    Enumeration for error code of the m17n library.
+
+    When a library function is called with an invalid argument, it
+    sets the external variable #merror_code to one of these values.
+    All the error codes are positive integers.
+
+    When a memory allocation error happens, the function pointed to by
+    the external variable #m17n_memory_full_handler is called with one
+    of these values as an argument.  */
+
+/***ja 
+    @brief m17n ¥é¥¤¥Ö¥é¥ê¥¨¥é¡¼¥³¡¼¥É¤ÎÎóµó.
+
+    m17n ¥é¥¤¥Ö¥é¥ê¥¨¥é¡¼¥³¡¼¥É¤ÎÎóµó
+
+    ¥é¥¤¥Ö¥é¥ê¤Î´Ø¿ô¤¬ÂÅÅö¤Ç¤Ê¤¤°ú¿ô¤È¤È¤â¤Ë¸Æ¤Ð¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢ÊÑ¿ô 
+    #merror_code ¤ò¤³¤ì¤é¤ÎÃͤΤɤ줫¤Ë¥»¥Ã¥È¤¹¤ë¡£¤¹¤Ù¤Æ¤Î¥¨¥é¡¼¥³¡¼¥É¤ÏÀµ¤ÎÀ°¿ô¤Ç¤¢¤ë¡£
+
+    ¥á¥â¥ê³äÅö¤Æ¥¨¥é¡¼¤ÎºÝ¤Ë¤Ï¡¢³°ÉôÊÑ¿ô #m17n_memory_full_handler 
+    ¤Î»Ø¤¹´Ø¿ô¤¬¡¢¤³¤ì¤é¤ÎÃͤΤ¦¤Á¤Î¤É¤ì¤«¤ò°ú¿ô¤È¤·¤Æ¸Æ¤Ð¤ì¤ë¡£
+    */
+
+enum MErrorCode
+  {
+    MERROR_NONE,
+    MERROR_OBJECT,
+    MERROR_SYMBOL,
+    MERROR_MTEXT,
+    MERROR_TEXTPROP,
+    MERROR_CHAR,
+    MERROR_CHARTABLE,
+    MERROR_CHARSET,
+    MERROR_CODING,
+    MERROR_RANGE,
+    MERROR_LANGUAGE,
+    MERROR_LOCALE,
+    MERROR_PLIST,
+    MERROR_MISC,
+    MERROR_WIN,
+    MERROR_X,
+    MERROR_FRAME,
+    MERROR_FACE,
+    MERROR_DRAW,
+    MERROR_FLT,
+    MERROR_FONT,
+    MERROR_FONTSET,
+    MERROR_FONT_OTF,
+    MERROR_FONT_X,
+    MERROR_FONT_FT,
+    MERROR_IM,
+    MERROR_DB,
+    MERROR_IO,
+    MERROR_DEBUG,
+    MERROR_MEMORY,
+    MERROR_GD,
+    MERROR_MAX
+  };
+
+/*=*/
+
+extern void (*m17n_memory_full_handler) (enum MErrorCode err);
+
+/*=*/
+/*** @ingroup m17nMisc  */
+/***en @defgroup m17nDebug Debugging */
+/***ja @defgroup m17nDebug ¥Ç¥Ð¥Ã¥°¥µ¥Ý¡¼¥È */
+/*=*/
+
+extern int mdebug_hook (void);
+
+extern MSymbol mdebug_dump_symbol (MSymbol sym, int indent);
+extern MSymbol mdebug_dump_all_symbols (int indent);
+extern MPlist *mdebug_dump_plist (MPlist *plist, int indent);
+extern MText *mdebug_dump_mtext (MText *mt, int fullp, int indent);
+extern MCharTable *mdebug_dump_chartab (MCharTable *table, int indent);
+
+#ifdef DOXYGEN_INTERNAL_MODULE
+/***en @defgroup m17nInternal Internal */
+/***ja @defgroup m17nInternal Internal */
+#endif
+
+M17N_END_HEADER
+
+#endif /* _M17N_ERR_H_ */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/m17n.c b/src/m17n.c
new file mode 100644 (file)
index 0000000..d25a946
--- /dev/null
@@ -0,0 +1,121 @@
+/* m17n.c -- body of the SHELL API.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#include <config.h>
+#include <stdio.h>
+
+#include "m17n.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "charset.h"
+#include "coding.h"
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+
+\f
+/* Internal API */
+
+\f
+/* External API */
+
+void
+m17n_init (void)
+{
+  int mdebug_flag = MDEBUG_INIT;
+
+  merror_code = MERROR_NONE;
+  if (m17n__shell_initialized++)
+    return;
+  m17n_init_core ();
+  if (merror_code != MERROR_NONE)
+    {
+      m17n__shell_initialized--;
+      return;
+    }
+  MDEBUG_PUSH_TIME ();
+  MDEBUG_PUSH_TIME ();
+  if (mcharset__init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize charset module."));
+  if (mcoding__init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize conv module."));
+  if (mcharset__load_from_database () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to load charset definitions."));
+  if (mcoding__load_from_database () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to load coding definitions."));
+  if (mlang__init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize language module"));
+  if (mlocale__init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize locale module."));
+  if (minput__init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize input module."));
+
+ err:
+  MDEBUG_POP_TIME ();
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the shell modules."));
+  MDEBUG_POP_TIME ();
+}
+
+void
+m17n_fini (void)
+{
+  int mdebug_flag = MDEBUG_FINI;
+
+  if (m17n__shell_initialized == 0
+      || --m17n__shell_initialized > 0)
+    return;
+
+  MDEBUG_PUSH_TIME ();
+  MDEBUG_PUSH_TIME ();
+  minput__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize input module."));
+  mlocale__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize locale module."));
+  mlang__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize language module."));
+  mchar__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize character module."));
+  mdatabase__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize database module."));
+  mcoding__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize coding module."));
+  mcharset__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize charset module."));
+  MDEBUG_POP_TIME ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the shell modules."));
+  MDEBUG_POP_TIME ();
+  m17n_fini_core ();
+}
+
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/m17n.h b/src/m17n.h
new file mode 100644 (file)
index 0000000..004cbf0
--- /dev/null
@@ -0,0 +1,1402 @@
+/* m17n.h -- header file for the SHELL API of the m17n library.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_H_
+#define _M17N_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#ifndef _M17N_CORE_H_
+#include <m17n-core.h>
+#endif
+
+M17N_BEGIN_HEADER
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+extern void m17n_init (void);
+#undef M17N_INIT
+#ifdef _M17N_FLT_H_
+#define M17N_INIT()    \
+  do {                 \
+    m17n_init ();      \
+    m17n_init_flt ();  \
+  } while (0)
+#else  /* not _M17N_FLT_H_ */
+#define M17N_INIT() m17n_init ()
+#endif /* not _M17N_FLT_H_ */
+
+extern void m17n_fini (void);
+#undef M17N_FINI
+#ifdef _M17N_FLT_H_
+#define M17N_FINI()    \
+  do {                 \
+    m17n_fini_flt ();  \
+    m17n_fini ();      \
+  } while (0)
+#else  /* not _M17N_FLT_H_ */
+#define M17N_FINI() m17n_fini ()
+#endif /* not _M17N_FLT_H_ */
+
+#endif
+
+/***en @defgroup m17nShell SHELL API
+    @brief API provided by libm17n.so */
+/***ja @defgroup m17nShell ¥·¥§¥ë API
+    @brief libm17n.so ¤¬Ä󶡤¹¤ë API */
+/*=*/
+
+/*
+ *  (11) Functions related to the m17n database
+ */
+/*=*/
+
+/*=*/
+/* (S2) Charset staffs */
+/*=*/
+
+/*** @ingroup m17nShell */
+/***en @defgroup m17nCharset Charset */
+/***ja @defgroup m17nCharset Ê¸»ú¥»¥Ã¥È */
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+#define MCHAR_INVALID_CODE 0xFFFFFFFF
+#endif
+
+/* Predefined charsets */ 
+extern MSymbol Mcharset_ascii;
+extern MSymbol Mcharset_iso_8859_1;
+extern MSymbol Mcharset_unicode;
+extern MSymbol Mcharset_m17n;
+extern MSymbol Mcharset_binary;
+
+/* Predefined keys for mchar_define_charset ().  */ 
+extern MSymbol Mmethod;
+extern MSymbol Mdimension;
+extern MSymbol Mmin_range;
+extern MSymbol Mmax_range;
+extern MSymbol Mmin_code;
+extern MSymbol Mmax_code;
+extern MSymbol Mascii_compatible;
+extern MSymbol Mfinal_byte;
+extern MSymbol Mrevision;
+extern MSymbol Mmin_char;
+extern MSymbol Mmapfile;
+extern MSymbol Mparents;
+extern MSymbol Msubset_offset;
+extern MSymbol Mdefine_coding;
+extern MSymbol Maliases;
+
+/* Methods of a charset.  */
+extern MSymbol Moffset;
+extern MSymbol Mmap;
+extern MSymbol Munify;
+extern MSymbol Msubset;
+extern MSymbol Msuperset;
+
+/* etc. */
+extern MSymbol mchar_define_charset (const char *name, MPlist *plist);
+
+extern MSymbol mchar_resolve_charset (MSymbol symbol);
+
+extern int mchar_list_charset (MSymbol **symbols);
+
+extern int mchar_decode (MSymbol charset_name, unsigned code);
+
+extern unsigned mchar_encode (MSymbol charset_name, int c);
+
+extern int mchar_map_charset (MSymbol charset_name,
+                             void (*func) (int from, int to, void *arg),
+                             void *func_arg);
+
+/*=*/
+
+/* (S3) code conversion */
+/*=*/
+/*** @ingroup m17nShell */
+/***en @defgroup m17nConv Code Conversion */
+/***ja @defgroup m17nConv ¥³¡¼¥ÉÊÑ´¹ */
+/*=*/
+
+/* Predefined coding systems */
+extern MSymbol Mcoding_us_ascii;
+extern MSymbol Mcoding_iso_8859_1;
+extern MSymbol Mcoding_utf_8;
+extern MSymbol Mcoding_utf_8_full;
+extern MSymbol Mcoding_utf_16;
+extern MSymbol Mcoding_utf_16be;
+extern MSymbol Mcoding_utf_16le;
+extern MSymbol Mcoding_utf_32;
+extern MSymbol Mcoding_utf_32be;
+extern MSymbol Mcoding_utf_32le;
+extern MSymbol Mcoding_sjis;
+
+/* Parameter keys for mconv_define_coding ().  */
+extern MSymbol Mtype;
+extern MSymbol Mcharsets;
+extern MSymbol Mflags;
+extern MSymbol Mdesignation;
+extern MSymbol Minvocation;
+extern MSymbol Mcode_unit;
+extern MSymbol Mbom;
+extern MSymbol Mlittle_endian;
+
+/* Symbols representing coding system type.  */
+extern MSymbol Mutf;
+extern MSymbol Miso_2022;
+
+/* Symbols appearing in the value of Mfrag parameter.  */
+extern MSymbol Mreset_at_eol;
+extern MSymbol Mreset_at_cntl;
+extern MSymbol Meight_bit;
+extern MSymbol Mlong_form;
+extern MSymbol Mdesignation_g0;
+extern MSymbol Mdesignation_g1;
+extern MSymbol Mdesignation_ctext;
+extern MSymbol Mdesignation_ctext_ext;
+extern MSymbol Mlocking_shift;
+extern MSymbol Msingle_shift;
+extern MSymbol Msingle_shift_7;
+extern MSymbol Meuc_tw_shift;
+extern MSymbol Miso_6429;
+extern MSymbol Mrevision_number;
+extern MSymbol Mfull_support;
+
+/* etc */
+extern MSymbol Mcoding;
+extern MSymbol Mmaybe;
+
+/*** @ingroup m17nConv */
+/***en
+    @brief Codes that represent the result of code conversion.
+
+    One of these values is set in @c MConverter-\>result.   */
+
+/***ja
+    @brief ¥³¡¼¥ÉÊÑ´¹¤Î·ë²Ì¤ò¼¨¤¹¥³¡¼¥É.
+
+    ¤³¤ì¤é¤ÎÃͤΤ¦¤Á°ì¤Ä¤¬ @c MConverter-\>result ¤ËÀßÄꤵ¤ì¤ë¡£  */
+
+enum MConversionResult
+  {
+    /***en Code conversion is successful. */
+    /***ja ¥³¡¼¥ÉÊÑ´¹¤ÏÀ®¸ù. */
+    MCONVERSION_RESULT_SUCCESS,
+
+    /***en On decoding, the source contains an invalid byte. */
+    /***ja ¥Ç¥³¡¼¥É»þ¡¢¥½¡¼¥¹¤ËÉÔÀµ¤Ê¥Ð¥¤¥È¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë. */
+    MCONVERSION_RESULT_INVALID_BYTE,
+
+    /***en On encoding, the source contains a character that cannot be
+       encoded by the specified coding system. */
+    /***ja ¥¨¥ó¥³¡¼¥É»þ¡¢»ØÄê¤Î¥³¡¼¥É·Ï¤Ç¥¨¥ó¥³¡¼¥É¤Ç¤­¤Ê¤¤Ê¸»ú¤¬¥½¡¼¥¹¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë. */
+    MCONVERSION_RESULT_INVALID_CHAR,
+
+    /***en On decoding, the source ends with an incomplete byte sequence. */
+    /***ja ¥Ç¥³¡¼¥É»þ¡¢ÉÔ´°Á´¤Ê¥Ð¥¤¥ÈÎó¤Ç¥½¡¼¥¹¤¬½ª¤ï¤Ã¤Æ¤¤¤ë¡£*/
+    MCONVERSION_RESULT_INSUFFICIENT_SRC,
+
+    /***en On encoding, the destination is too short to store the result. */
+    /***ja ¥¨¥ó¥³¡¼¥É»þ¡¢·ë²Ì¤ò³ÊǼ¤¹¤ëÎΰ褬û¤«¤¹¤®¤ë¡£ */
+    MCONVERSION_RESULT_INSUFFICIENT_DST,
+
+    /***en An I/O error occurred in the conversion.  */
+    /***ja ¥³¡¼¥ÉÊÑ´¹Ãæ¤Ë I/O ¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿¡£  */
+    MCONVERSION_RESULT_IO_ERROR
+  };
+/*=*/
+
+/*** @ingroup m17nConv */
+/***en
+    @brief Structure to be used in code conversion.
+
+    Structure to be used in code conversion.  The first three members
+    are to control the conversion.  */
+
+/***ja
+    @brief ¥³¡¼¥ÉÊÑ´¹¤ËÍѤ¤¤é¤ì¤ë¹½Â¤ÂÎ.
+
+    ¥³¡¼¥ÉÊÑ´¹¤ËÍѤ¤¤é¤ì¤ë¹½Â¤ÂΡ£ºÇ½é¤Î£³¤Ä¤Î¥á¥ó¥Ð¤ÏÊÑ´¹¤òÀ©¸æ¤¹¤ë¡£
+
+    @latexonly \IPAlabel{MConverter} @endlatexonly  
+*/
+
+typedef struct
+{
+  /***en
+      Set the value to nonzero if the conversion should be lenient.
+      By default, the conversion is strict (i.e. not lenient).
+
+      If the conversion is strict, the converter stops at the first
+      invalid byte (on decoding) or at the first character not
+      supported by the coding system (on encoding).  If this happens,
+      @c MConverter-\>result is set to @c
+      MCONVERSION_RESULT_INVALID_BYTE or @c
+      MCONVERSION_RESULT_INVALID_CHAR accordingly.
+
+      If the conversion is lenient, on decoding, an invalid byte is
+      kept per se, and on encoding, an invalid character is replaced
+      with "<U+XXXX>" (if the character is a Unicode character) or
+      with "<M+XXXXXX>" (otherwise).  */
+
+  /***ja 
+      ¸·Ì©¤ÊÊÑ´¹¤¬É¬ÍפǤʤ¤¾ì¹ç¤ËÃͤò 0 °Ê³°¤Ë¤¹¤ë¡£
+      ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢ÊÑ´¹¤Ï¸·Ì©¤Ç¤¢¤ë¡£
+
+      ÊÑ´¹¤¬¸·Ì©¤È¤Ï¡¢¥Ç¥³¡¼¥É¤ÎºÝ¤Ë¤ÏºÇ½é¤ÎÉÔÀµ¤Ê¥Ð¥¤¥È¤Ç¥³¥ó¥Ð¡¼¥¿¤¬»ß¤Þ¤ë¤³¤È¡¢
+      ¥¨¥ó¥³¡¼¥É¤ÎºÝ¤Ë¤ÏÊÑ´¹¤µ¤ì¤ë¥³¡¼¥É·Ï¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Ê¤¤ºÇ½é¤Îʸ»ú¤Ç¥³¥ó¥Ð¡¼¥¿¤¬»ß¤Þ¤ë¤³¤È¤ò»Ø¤¹¡£
+      ¤³¤ì¤é¤Î¾ì¹ç¡¢@c MConverter-\>result ¤Ï¤½¤ì¤¾¤ì @c
+      MCONVERSION_RESULT_INVALID_BYTE ¤«@c
+      MCONVERSION_RESULT_INVALID_CHAR ¤È¤Ê¤ë¡£
+
+      ÊÑ´¹¤¬¸·Ì©¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢¥Ç¥³¡¼¥É¤ÎºÝ¤ÎÉÔÀµ¤Ê¥Ð¥¤¥È¤Ï¤½¤Î¥Ð¥¤¥È¤Î¤Þ¤Þ»Ä¤ë¡£
+      ¤Þ¤¿¥¨¥ó¥³¡¼¥É¤ÎºÝ¤Ë¤Ï¡¢ÉÔÀµ¤Êʸ»ú¤¬ Unicode Ê¸»ú¤Î¾ì¹ç¤Ë¤Ï "<U+XXXX>"
+      ¤Ë¡¢¤½¤¦¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Ï "<M+XXXXXX>" ¤ËÃÖ¤­´¹¤¨¤é¤ì¤ë¡£  */
+
+  int lenient;
+
+  /***en
+      Set the value to nonzero before decoding or encoding the last
+      block of the byte sequence or the character sequence
+      respectively.  The value influences the conversion as below.
+
+      On decoding, in the case that the last few bytes are too short
+      to form a valid byte sequence:
+
+       If the value is nonzero, the conversion terminates by error
+       (MCONVERSION_RESULT_INVALID_BYTE) at the first byte of the
+       sequence.
+
+       If the value is zero, the conversion terminates successfully.
+       Those bytes are stored in the converter as carryover and are
+       prepended to the byte sequence of the further conversion.
+
+      On encoding, in the case that the coding system is context
+      dependent:
+
+       If the value is nonzero, the conversion may produce a byte
+       sequence at the end to reset the context to the initial state
+       even if the source characters are zero.
+
+       If the value is zero, the conversion never produce such a byte
+       sequence at the end.  */
+
+/***ja 
+
+     ¥Ð¥¤¥ÈÎó¤Î½ªÃ¼¤Î¥Ö¥í¥Ã¥¯¤ò¥Ç¥³¡¼¥É¤¹¤ëºÝ¡¢¤Þ¤¿¤Ïʸ»úÎó¤Î½ªÃ¼¤Î¥Ö¥í¥Ã¥¯¤ò¥¨¥ó¥³¡¼¥É¤¹¤ëºÝ¤Ï¡¢Ãͤò
+     0 °Ê³°¤Ë¤¹¤ë¡£¤³¤ÎÃͤϰʲ¼¤Î¤è¤¦¤ËÊÑ´¹¤Ë±Æ¶Á¤¹¤ë¡£
+
+     ¥Ç¥³¡¼¥Ç¥£¥ó¥°¤ÎºÝ¤ËºÇ¸å¤Î¿ô¥Ð¥¤¥È¤¬Àµ¤·¤¤¥Ð¥¤¥È¥·¡¼¥¯¥¨¥ó¥¹¤ò·ÁÀ®¤¹¤ë¤Ë¤Ïû¤¹¤®¤ë¾ì¹ç¡§
+
+       Ãͤ¬ 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢ÊÑ´¹¤Ï¤½¤Î¥·¡¼¥¯¥¨¥ó¥¹¤ÎºÇ½é¤Î¥Ð¥¤¥È¤Ë¤ª¤¤¤Æ¡¢¥¨¥é¡¼
+       (MCONVERSION_RESULT_INVALID_BYTE) ¤Ç½ª¤ë¡£
+
+       Ãͤ¬ 0 ¤Ê¤é¤Ð¡¢ÊÑ´¹¤ÏÀ®¸ù¤·¤Æ½ª¤ë¡£
+       ÌäÂê¤Î¿ô¥Ð¥¤¥È¤Ï¥­¥ã¥ê¡¼¥ª¡¼¥Ð¤È¤·¤Æ¥³¥ó¥Ð¡¼¥¿¤ËÊÝ»ý¤µ¤ì¡¢ÊÑ´¹¤Î³¤­¤ò¹Ô¤¦ºÝ¤ËÊÑ´¹¤¹¤ë¥Ð¥¤¥ÈÎó¤ÎÁ°¤ËÉÕ¤±¤é¤ì¤ë¡£
+
+     ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤ÎºÝ¤Ë¥³¡¼¥É·Ï¤¬Ê¸Ì®°Í¸¤Î¾ì¹ç¡¢
+
+       Ãͤ¬ 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢¥³¥ó¥Æ¥­¥¹¥È¤òºÇ½é¤ËÌ᤹¤¿¤á¤Î¥Ð¥¤¥ÈÎ󤬥½¡¼¥¹¤Îʸ»ú¤È¤«¤«¤ï¤ê¤Ê¤¯ÊÑ´¹¤Î·ë²ÌÀ¸À®¤µ¤ì¤ë¤³¤È¤¬¤¢¤ë¡£
+
+       Ãͤ¬ 0 ¤Ê¤é¤Ð¡¢¤½¤Î¤è¤¦¤Ê¥Ð¥¤¥ÈÎó¤ÏÀ¸À®¤µ¤ì¤Ê¤¤¡£
+
+        */
+
+  int last_block;
+
+  /***en
+      If the value is nonzero, it specifies at most how many
+      characters to convert.  */
+  /***ja
+      0 ¤Ç¤Ê¤±¤ì¤Ð¡¢ÊÑ´¹¤µ¤ì¤ëºÇÂç¤Îʸ»ú¿ô¤ò»ØÄꤹ¤ë¡£
+      */
+
+  unsigned at_most;
+
+  /***en
+      The following three members are to report the result of the
+      conversion.  */
+  /***ja
+      °Ê²¼¤Î£³¤Ä¤Î¥á¥ó¥Ð¤ÏÊÑ´¹¤Î·ë²Ì¤òɽ¤¹¤¿¤á¤Î¤â¤Î¤Ç¤¢¤ë¡£  */
+
+  /***en
+      Number of characters most recently decoded or encoded. */
+  /***ja
+      ºÇ¶á¤Ë¥Ç¥³¡¼¥É/¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿Ê¸»ú¿ô¡£ */
+
+  int nchars;
+
+  /***en
+      Number of bytes recently decoded or encoded. */
+
+  /***ja
+      ºÇ¶á¤Ë¥Ç¥³¡¼¥É/¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Ð¥¤¥È¿ô¡£ */
+
+  int nbytes;
+
+  /***en
+      Result code of the conversion. */
+
+  /***ja
+      ¥³¡¼¥ÉÊÑ´¹¤Î·ë²Ì¤ò¼¨¤¹¥³¡¼¥É¡£ */
+
+  enum MConversionResult result;
+
+  /***en
+      Various information about the status of code conversion.  The
+      contents depend on the type of coding system.  It is assured
+      that @c status is aligned so that any type of casting is safe
+      and at least 256 bytes of memory space can be used.  */
+
+  /***ja
+      ¥³¡¼¥ÉÊÑ´¹¤Î¾õ¶·¤Ë´Ø¤¹¤ë¼ï¡¹¤Î¾ðÊó¡£ÆâÍƤϥ³¡¼¥É·Ï¤Î¥¿¥¤¥×¤Ë¤è¤Ã¤Æ°Û¤Ê¤ë¡£
+      @c status ¤Ï¤É¤Î¤è¤¦¤Ê·¿¤Ø¤Î¥­¥ã¥¹¥È¤ËÂФ·¤Æ¤â°ÂÁ´¤Ê¤è¤¦¤Ë¥á¥â¥ê¥¢¥é¥¤¥ó¤µ¤ì¤Æ¤ª¤ê¡¢¤Þ¤¿ºÇÄã256¥Ð¥¤¥È¤Î¥á¥â¥êÎΰ褬»È¤¨¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£  */
+
+  union {
+    void *ptr;
+    double dbl;
+    char c[256];
+  } status;
+
+  /***en
+      This member is for internally use only.  An application program
+      should never touch it.  */
+  /***ja ¤³¤Î¥á¥ó¥Ð¤ÏÆâÉôŪ¤Ë»ÈÍѤµ¤ì¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï¿¨¤ì¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£ */
+  void *internal_info;
+} MConverter;
+/*=*/
+
+/*** @ingroup m17nConv */
+/***en 
+    @brief Types of coding system.  */
+/***ja 
+    @brief ¥³¡¼¥É·Ï¤Î¥¿¥¤¥×.  */
+
+enum MCodingType
+  {
+    /***en
+       A coding system of this type supports charsets directly.
+       The dimension of each charset defines the length of bytes to
+       represent a single character of the charset, and a byte
+       sequence directly represents the code-point of a character.
+       The m17n library provides the default decoding and encoding
+       routines of this type.  */
+
+    /***ja
+       ¤³¤Î¥¿¥¤¥×¤Î¥³¡¼¥É·Ï¤Ïʸ»ú¥»¥Ã¥È¤òľÀÜ¥µ¥Ý¡¼¥È¤¹¤ë¡£
+       ³Æʸ»ú¥»¥Ã¥È¤Î¼¡¸µ¤È¤Ï¡¢¤½¤Îʸ»ú¥»¥Ã¥È¤Ç°ìʸ»ú¤òɽ¸½¤¹¤ë¤¿¤á¤ËɬÍפʥХ¤¥È¿ô¤Ç¤¢¤ê¡¢¥Ð¥¤¥ÈÎó¤Ïʸ»ú¤Î¥³¡¼¥É¥Ý¥¤¥ó¥È¤òľÀÜɽ¤¹¡£
+       m17n ¥é¥¤¥Ö¥é¥ê¤Ï¤³¤Î¥¿¥¤¥×ÍѤΥǥե©¥ë¥È¤Î¥¨¥ó¥³¡¼¥É¡¿¥Ç¥³¡¼¥É¥ë¡¼¥Æ¥£¥ó¤òÄ󶡤¹¤ë¡£  */
+
+    MCODING_TYPE_CHARSET,
+
+    /***en
+       A coding system of this type supports byte sequences of a
+       UTF (UTF-8, UTF-16, UTF-32) like structure.
+       The m17n library provides the default decoding and encoding
+       routines of this type.  */
+
+    /***ja
+       ¤³¤Î¥¿¥¤¥×¤Î¥³¡¼¥É·Ï¤Ï¡¢UTF ·Ï (UTF-8, UTF-16, UTF-32) ¤Î¥Ð¥¤¥ÈÎó¤ò¥µ¥Ý¡¼¥È¤¹¤ë¡£
+       m17n ¥é¥¤¥Ö¥é¥ê¤Ï¤³¤Î¥¿¥¤¥×ÍѤΥǥե©¥ë¥È¤Î¥¨¥ó¥³¡¼¥É¡¿¥Ç¥³¡¼¥É¥ë¡¼¥Æ¥£¥ó¤òÄ󶡤¹¤ë¡£  */
+
+    MCODING_TYPE_UTF,
+
+    /***en
+       A coding system of this type supports byte sequences of an
+       ISO-2022 like structure.  The details of each structure are
+       specified by @c MCodingInfoISO2022 .
+       The m17n library provides decoding and encoding routines of
+       this type.  */
+
+    /***ja 
+        ¤³¤Î¥¿¥¤¥×¤Î¥³¡¼¥É·Ï¤Ï¡¢ISO-2022 ·Ï¤Î¥Ð¥¤¥ÈÎó¤ò¥µ¥Ý¡¼¥È¤¹¤ë¡£
+       ³Æ¥³¡¼¥É·Ï¤Î¹½Â¤¤Î¾ÜºÙ¤Ï @c MCodingInfoISO2022 ¤Ç»ØÄꤵ¤ì¤ë¡£
+       m17n ¥é¥¤¥Ö¥é¥ê¤Ï¤³¤Î¥¿¥¤¥×ÍѤΥǥե©¥ë¥È¤Î¥¨¥ó¥³¡¼¥É¡¿¥Ç¥³¡¼¥É¥ë¡¼¥Æ¥£¥ó¤òÄ󶡤¹¤ë¡£  */
+
+    MCODING_TYPE_ISO_2022,
+
+    /***en
+       A coding system of this type is for byte sequences of
+       miscellaneous structures.
+       The m17n library does not provide decoding and encoding
+       routines of this type.  They must be provided by the
+       application program.  */
+
+    /***ja
+       ¤³¤Î¥¿¥¤¥×¤Î¥³¡¼¥É·Ï¤Ï¡¢¤½¤Î¾¤Î¹½Â¤¤Î¥Ð¥¤¥ÈÎó¤Î¤¿¤á¤Î¤â¤Î¤Ç¤¢¤ë¡£
+       m17n ¥é¥¤¥Ö¥é¥ê¤Ï¤³¤Î¥¿¥¤¥×ÍѤΥ¨¥ó¥³¡¼¥É¡¿¥Ç¥³¡¼¥É¥ë¡¼¥Æ¥£¥ó¤òÄ󶡤·¤Ê¤¤¤Î¤Ç¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¦¤Ç½àÈ÷¤¹¤ëɬÍפ¬¤¢¤ë¡£  */
+
+    MCODING_TYPE_MISC
+  };
+/*=*/
+
+/*** @ingroup m17nConv */
+/***en 
+    @brief  Bit-masks to specify the detail of coding system whose type is MCODING_TYPE_ISO_2022.  */
+/***ja 
+    @brief MCODING_TYPE_ISO_2022 ¥¿¥¤¥×¤Î¥³¡¼¥É·Ï¤Î¾ÜºÙ¤òɽ¤ï¤¹¥Ó¥Ã¥È¥Þ¥¹¥¯.  */
+
+enum MCodingFlagISO2022
+  {
+    /***en
+       On encoding, reset the invocation and designation status to
+       initial at end of line.  */
+    /***ja ¥¨¥ó¥³¡¼¥É¤ÎºÝ¡¢¹ÔËö¤Ç¸Æ¤Ó½Ð¤· (invocation) ¤È»Ø¼¨
+       (designation) ¤Î¾õÂÖ¤ò½é´üÃͤËÌ᤹¡£   */
+    MCODING_ISO_RESET_AT_EOL =         0x1,
+
+    /***en
+       On encoding, reset the invocation and designation status to
+       initial before any control codes.  */
+    /***ja
+       ¥¨¥ó¥³¡¼¥É¤ÎºÝ¡¢¤¹¤Ù¤Æ¤ÎÀ©¸æʸ»ú¤ÎÁ°¤Ç¡¢¸Æ¤Ó½Ð¤·
+       (invocation) ¤È»Ø¼¨ (designation) ¤Î¾õÂÖ¤ò½é´üÃͤËÌ᤹¡£        */
+    MCODING_ISO_RESET_AT_CNTL =                0x2,
+
+    /***en
+       Use the right graphic plane.  */
+    /***ja
+       ¿Þ·Áʸ»ú½¸¹ç¤Î±¦Â¦¤ò»È¤¦¡£  */
+    MCODING_ISO_EIGHT_BIT =            0x4,
+
+    /***en
+       Use the non-standard 4 bytes format for designation sequence
+       for charsets JISX0208-1978, GB2312, and JISX0208-1983.  */
+    /***ja
+       JISX0208-1978, GB2312, JISX0208-1983 
+       ¤Îʸ»ú½¸¹ç¤ËÂФ¹¤ë»Ø¼¨¥·¡¼¥¯¥¨¥ó¥¹¤È¤·¤Æ¡¢Èóɸ½à¤Î4¥Ð¥¤¥È·Á¼°¤òÍѤ¤¤ë¡£ */
+
+    MCODING_ISO_LONG_FORM =            0x8,
+
+    /***en
+       On encoding, unless explicitly specified, designate charsets
+       to G0.  */
+    /***ja 
+        ¥¨¥ó¥³¡¼¥É¤ÎºÝ¡¢Æä˻ØÄꤵ¤ì¤Ê¤¤¸Â¤ê¡¢Ê¸»ú½¸¹ç¤ò G0 
+       ¤Ë»Ø¼¨¤¹¤ë¡£*/
+    MCODING_ISO_DESIGNATION_G0 =               0x10,
+
+    /***en
+       On encoding, unless explicitly specified, designate charsets
+       except for ASCII to G1.  */
+    /***ja
+       ¥¨¥ó¥³¡¼¥É¤ÎºÝ¡¢Æä˻ØÄꤵ¤ì¤Ê¤¤¸Â¤ê¡¢ASCII °Ê³°¤Îʸ»ú½¸¹ç¤ò 
+       G1 ¤Ë»Ø¼¨¤¹¤ë¡£*/
+    MCODING_ISO_DESIGNATION_G1 =               0x20,
+
+    /***en
+       On encoding, unless explicitly specified, designate 94-chars
+       charsets to G0, 96-chars charsets to G1.  */
+    /***ja
+       ¥¨¥ó¥³¡¼¥É¤ÎºÝ¡¢Æä˻ØÄꤵ¤ì¤Ê¤¤¸Â¤ê¡¢94ʸ»ú½¸¹ç¤ò G0 
+       ¤Ë¡¢96ʸ»ú½¸¹ç¤ò G1 ¤Ë»Ø¼¨¤¹¤ë¡£*/
+    MCODING_ISO_DESIGNATION_CTEXT =    0x40,
+
+    /***en
+       On encoding, encode such charsets not conforming to ISO-2022
+       by ESC % / ..., and encode non-supported Unicode characters by
+       ESC % G ... ESC % @@ .  On decoding, handle those escape
+       sequences.  */
+    /***ja
+       ¥¨¥ó¥³¡¼¥É¤ÎºÝ¡¢ISO-2022 ¤Ë¹çÃפ·¤Ê¤¤Ê¸»ú½¸¹ç¤ò ESC % / ... 
+       ¤Ç¥¨¥ó¥³¡¼¥É¤¹¤ë¡£¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤¤ Unicode Ê¸»ú¤Ï ESC % G ...
+       ESC % @@ ¤Ç¥¨¥ó¥³¡¼¥É¤¹¤ë¡£
+       ¥Ç¥³¡¼¥É¤ÎºÝ¡¢¤³¤ì¤é¤Î¥¨¥¹¥±¡¼¥×¡¦¥·¡¼¥±¥ó¥¹¤ò²ò¼á¤¹¤ë¡£  */
+    MCODING_ISO_DESIGNATION_CTEXT_EXT =        0x80,
+
+    /***en
+       Use locking shift.  */
+    /***ja
+       ¥í¥Ã¥­¥ó¥°¥·¥Õ¥È¤ò»È¤¦¡£  */
+    MCODING_ISO_LOCKING_SHIFT =        0x100,
+
+    /***en
+       Use single shift (SS2 (0x8E or ESC N), SS3 (0x8F or ESC O)).  */
+    /***ja
+       ¥·¥ó¥°¥ë¥·¥Õ¥È (SS2 (0x8E or ESC N), SS3 (0x8F or ESC O)) ¤ò»È¤¦¡£  */
+    MCODING_ISO_SINGLE_SHIFT = 0x200,
+
+    /***en
+       Use 7-bit single shift 2 (SS2 (0x19)).  */
+    /***ja
+       7¥Ó¥Ã¥È¥·¥ó¥°¥ë¥·¥Õ¥È 2 (SS2 (0x19)) ¤ò»È¤¦¡£  */
+    MCODING_ISO_SINGLE_SHIFT_7 =       0x400,
+
+    /***en
+       Use EUC-TW like special shifting.  */
+    /***ja
+       EUC-TW É÷¤ÎÆÃÊ̤ʥ·¥Õ¥È¤ò»È¤¦¡£  */
+    MCODING_ISO_EUC_TW_SHIFT = 0x800,
+
+    /***en
+       Use ISO-6429 escape sequences to indicate direction.
+       Not yet implemented.  */
+    /***ja
+       ISO-6429 ¤Î¥¨¥¹¥±¡¼¥×¥·¡¼¥¯¥¨¥ó¥¹¤ÇÊý¸þ¤ò»Ø¼¨¤¹¤ë¡£Ì¤¼ÂÁõ¡£ */
+    MCODING_ISO_ISO6429 =              0x1000,
+
+    /***en
+       On encoding, if a charset has revision number, produce escape
+       sequences to specify the number.  */
+    /***ja
+       ¥¨¥ó¥³¡¼¥É¤ÎºÝ¡¢Ê¸»ú¥»¥Ã¥È¤Ë revision number 
+       ¤¬¤¢¤ì¤Ð¤½¤ì¤òɽ¤ï¤¹¥¨¥¹¥±¡¼¥×¥·¡¼¥¯¥¨¥ó¥¹¤òÀ¸À®¤¹¤ë¡£        */
+    MCODING_ISO_REVISION_NUMBER =      0x2000,
+
+    /***en
+       Support all ISO-2022 charsets.  */
+    /***ja
+       ISO-2022 ¤ÎÁ´Ê¸»ú½¸¹ç¤ò¥µ¥Ý¡¼¥È¤¹¤ë¡£  */
+    MCODING_ISO_FULL_SUPPORT =         0x3000,
+
+    MCODING_ISO_FLAG_MAX
+  };
+/*=*/
+
+/*** @ingroup m17nConv */
+/***en
+    @brief Structure for a coding system of type #MCODING_TYPE_ISO_2022.
+
+    Structure for extra information about a coding system of type
+    MCODING_TYPE_ISO_2022.  */
+
+/***ja 
+    @brief #MCODING_TYPE_ISO_2022 ¥¿¥¤¥×¤Î¥³¡¼¥É·Ï¤ÇɬÍפÊÉղþðÊóÍѹ½Â¤ÂÎ.
+
+    MCODING_TYPE_ISO_2022 ¥¿¥¤¥×¤Î¥³¡¼¥É·Ï¤ÇɬÍפÊÉղþðÊóÍѤòÊÝ»ý¤¹¤ë¤¿¤á¤Î¹½Â¤ÂΡ£
+
+    @latexonly \IPAlabel{MCodingInfoISO2022} @endlatexonly  */
+
+typedef struct
+{
+  /***en
+      Table of numbers of an ISO2022 code extension element invoked
+      to each graphic plane (Graphic Left and Graphic Right).  -1
+      means no code extension element is invoked to that plane.  */
+
+  /***ja
+      ³Æ¿Þ·Áʸ»úÎΰè (Graphic Left ¤È Graphic Right) ¤Ë¸Æ¤Ó½Ð¤µ¤ì¤Æ¤¤¤ë¡¢
+      ISO2022 Éä¹ç³ÈÄ¥Í×ÁǤÎÈÖ¹æ¤Î¥Æ¡¼¥Ö¥ë¡£-1 
+      ¤Ï¤½¤ÎÎΰè¤Ë¤É¤ÎÉä¹ç³ÈÄ¥Í×ÁǤâ¸Æ¤Ó½Ð¤µ¤ì¤Æ¤¤¤Ê¤¤¤³¤È¤ò¼¨¤¹¡£   */
+
+  int initial_invocation[2];
+
+  /***en
+      Table of code extension elements.  The Nth element corresponds
+      to the Nth charset in $CHARSET_NAMES, which is an argument given
+      to the mconv_define_coding () function.
+
+      If an element value is 0..3, it specifies a graphic register
+      number to designate the corresponds charset.  In addition, the
+      charset is initially designated to that graphic register.
+
+      If the value is -4..-1, it specifies a graphic register number
+      0..3 respectively to designate the corresponds charset.
+      Initially, the charset is not designated to any graphic
+      register.  */
+
+  /***ja
+      Éä¹ç³ÈÄ¥Í×ÁǤΥơ¼¥Ö¥ë¡£NÈÖÌܤÎÍ×ÁǤϡ¢$CHARSET_NAMES ¤Î N 
+      ÈÖÌܤÎʸ»ú¥»¥Ã¥È¤ËÂбþ¤¹¤ë¡£$CHARSET_NAMES ¤Ï´Ø¿ô 
+      mconv_define_coding () ¤Î°ú¿ô¤È¤Ê¤ë¡£
+
+      Ãͤ¬ 0..3 ¤À¤Ã¤¿¤é¡¢Âбþ¤¹¤ëʸ»ú¥»¥Ã¥È¤ò G0..G3 
+      ¤Î¤½¤ì¤¾¤ì¤Ë»Ø¼¨¤¹¤ë¤³¤È¡¢¤Þ¤¿½é´ü¾õÂ֤Ǥ¹¤Ç¤Ë G0..G3
+      ¤Ë»Ø¼¨¤µ¤ì¤Æ¤¤¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
+
+      Ãͤ¬ -4..-1 ¤À¤Ã¤¿¤é¡¢Âбþ¤¹¤ëʸ»ú¥»¥Ã¥È¤ò G0..G3 
+      ¤Î¤½¤ì¤¾¤ì¤Ë»Ø¼¨¤¹¤ë¤³¤È¡¢¤·¤«¤·½é´ü¾õÂ֤ǤϤɤ³¤Ë¤â»Ø¼¨¤µ¤ì¤Æ¤¤¤Ê¤¤¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
+        */
+
+  char designations[32];
+
+  /***en
+      Bitwise OR of @c enum @c MCodingFlagISO2022 .  */
+
+  /***ja
+      @c enum @c MCodingFlagISO2022 ¤Î¥Ó¥Ã¥Èñ°Ì¤Ç¤ÎÏÀÍý OR  */
+
+  unsigned flags;
+
+} MCodingInfoISO2022;
+/*=*/
+
+/*** @ingroup m17nConv */
+/***en
+    @brief Structure for extra information about a coding system of type #MCODING_TYPE_UTF.
+    */
+
+/***ja
+    @brief #MCODING_TYPE_UTF ¥¿¥¤¥×¤Î¥³¡¼¥É·Ï¤ÇɬÍפÊÉղþðÊóÍѤι½Â¤ÂÎ.
+
+    @latexonly \IPApage{MCodingInfoUTF} @endlatexonly
+
+    @latexonly \IPAlabel{MCodingInfoUTF} @endlatexonly  */
+
+typedef struct
+{
+  /***en
+      Specify bits of a code unit.  The value must be 8, 16, or 32.  */
+  /***ja
+      ¥³¡¼¥ÉĹ¡Ê¥Ó¥Ã¥È¿ô¡Ë¤Î»ØÄê¡£ÃͤϠ8, 16, 32 ¤Î¤¤¤º¤ì¤«¡£  */
+  int code_unit_bits;
+
+  /***en
+      Specify how to handle the heading BOM (byte order mark).  The
+      value must be 0, 1, or 2.  The meanings are as follows:
+
+      0: On decoding, check the first two byte.  If they are BOM,
+      decide endian by them. If not, decide endian by the member @c
+      endian.  On encoding, produce byte sequence according to
+      @c endian with heading BOM.
+
+      1: On decoding, do not handle the first two bytes as BOM, and
+      decide endian by @c endian.  On encoding, produce byte sequence
+      according to @c endian without BOM.
+
+      2: On decoding, handle the first two bytes as BOM and decide
+      ending by them.  On encoding, produce byte sequence according to
+      @c endian with heading BOM.
+
+      If \<code_unit_bits\> is 8, the value has no meaning.  */
+
+  /***ja
+      ÀèƬ¤Î BOM (¥Ð¥¤¥È¥ª¡¼¥À¡¼¥Þ¡¼¥¯) ¤Î¼è¤ê°·¤¤¤ò»ØÄꤹ¤ë¡£ÃͤϠ0,
+      1, 2 ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ê¡¢¤½¤ì¤¾¤ì¤Î°ÕÌ£¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤Ê¤ë¡£
+
+      0: ¥Ç¥³¡¼¥É¤ÎºÝ¤ËºÇ½é¤Î 2 ¥Ð¥¤¥È¤òÄ´¤Ù¤ë¡£¤â¤·¤½¤ì¤¬ BOM 
+      ¤Ç¤¢¤ì¤Ð¡¢¥¨¥ó¥Ç¥£¥¢¥ó¤ò¤½¤ì¤ÇȽÄꤹ¤ë¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢¥á¥ó¥Ð @c
+      endian ¤Ë½¾¤Ã¤Æ¥¨¥ó¥Ç¥£¥¢¥ó¤ò·èÄꤹ¤ë¡£¥¨¥ó¥³¡¼¥É¤ÎºÝ¤Ë¤Ï @c
+      endian ¤Ë½¾¤Ã¤¿¥Ð¥¤¥ÈÎó¤òÀèƬ¤Ë BOM ÉÕ¤ÇÀ¸À®¤¹¤ë¡£
+
+      1: ¥Ç¥³¡¼¥É¤ÎºÝ¡¢ºÇ½é¤Î 2 ¥Ð¥¤¥È¤ò BOM ¤È¤·¤Æ°·¤ï¤º¡¢¥¨¥ó¥Ç¥£¥¢¥ó¤Ï
+      @c endian ¤ÇȽÄꤹ¤ë¡£¥¨¥ó¥³¡¼¥É¤ÎºÝ¤Ë¤Ï¡¢BOM ¤ò½ÐÎϤ»¤º¡¢
+      @c endian ¤Ë±þ¤¸¤¿¥Ð¥¤¥ÈÎó¤òÀ¸À®¤¹¤ë¡£
+
+      2: ¥Ç¥³¡¼¥É¤ÎºÝ¤ËºÇ½é¤Î2¥Ð¥¤¥È¤ò BOM¤È¤·¤Æ°·¤¤¡¢¤½¤ì¤Ë½¾¤Ã¤Æ¥¨¥ó¥Ç¥£¥¢¥ó¤òȽÄꤹ¤ë¡£
+      ¥¨¥ó¥³¡¼¥É¤ÎºÝ¤Ë¤Ï @c endian ¤Ë±þ¤¸¤¿¥Ð¥¤¥ÈÎó¤òÀèƬ¤Ë BOM ÉÕ¤­¤ÇÀ¸À®¤¹¤ë¡£  */
+  int bom;
+
+  /***en
+      Specify the endian type.  The value must be 0 or 1.  0 means
+      little endian, and 1 means big endian.
+
+      If \<code_unit_bits\> is 8, the value has no meaning.  */
+  /***ja
+      ¥¨¥ó¥Ç¥£¥¢¥ó¤Î¥¿¥¤¥×¤ò»ØÄꤹ¤ë¡£ÃͤϠ0 ¤« 1 ¤Ç¤¢¤ê¡¢0 
+      ¤Ê¤é¤Ð¥ê¥È¥ë¥¨¥ó¥Ç¥£¥¢¥ó¡¢1 ¤Ê¤é¤Ð¥Ó¥Ã¥°¥¨¥ó¥Ç¥£¥¢¥ó¤Ç¤¢¤ë¡£
+
+      \<code_unit_bits\> ¤¬ 8 ¤Î¾ì¹ç¤Ë¤Ï¡¢¤³¤ÎÃͤϰÕÌ£¤ò»ý¤¿¤Ê¤¤¡£
+  */
+  int endian;
+} MCodingInfoUTF;
+/*=*/
+
+extern MSymbol mconv_define_coding (const char *name, MPlist *plist,
+                                   int (*resetter) (MConverter *),
+                                   int (*decoder) (const unsigned char *, int,
+                                                   MText *, MConverter *),
+                                   int (*encoder) (MText *, int, int,
+                                                   unsigned char *, int,
+                                                   MConverter *),
+                                   void *extra_info);
+
+extern MSymbol mconv_resolve_coding (MSymbol symbol);
+
+extern int mconv_list_codings (MSymbol **symbols);
+
+extern MConverter *mconv_buffer_converter (MSymbol coding,
+                                          const unsigned char *buf,
+                                          int n);
+
+extern MConverter *mconv_stream_converter (MSymbol coding, FILE *fp);
+
+extern int mconv_reset_converter (MConverter *converter);
+
+extern void mconv_free_converter (MConverter *converter);
+
+extern MConverter *mconv_rebind_buffer (MConverter *converter,
+                                       const unsigned char *buf, int n);
+
+extern MConverter *mconv_rebind_stream (MConverter *converter, FILE *fp);
+
+extern MText *mconv_decode (MConverter *converter, MText *mt);
+
+MText *mconv_decode_buffer (MSymbol name, const unsigned char *buf, int n);
+
+MText *mconv_decode_stream (MSymbol name, FILE *fp);   
+
+extern int mconv_encode (MConverter *converter, MText *mt);
+
+extern int mconv_encode_range (MConverter *converter, MText *mt,
+                              int from, int to);
+
+extern int mconv_encode_buffer (MSymbol name, MText *mt,
+                               unsigned char *buf, int n);
+
+extern int mconv_encode_stream (MSymbol name, MText *mt, FILE *fp);
+
+extern int mconv_getc (MConverter *converter);
+
+extern int mconv_ungetc (MConverter *converter, int c);
+
+extern int mconv_putc (MConverter *converter, int c);
+
+extern MText *mconv_gets (MConverter *converter, MText *mt);
+
+/* (S4) Locale related functions corresponding to libc functions */
+/*=*/
+/*** @ingroup m17nShell */
+/***en @defgroup m17nLocale Locale */
+/***ja @defgroup m17nLocale ¥í¥±¡¼¥ë */
+/*=*/
+
+/*** @ingroup m17nLocale */
+/***en
+    @brief @c struct @c MLocale.
+
+    The structure @c MLocale is used to hold information about name,
+    language, territory, modifier, codeset, and the corresponding
+    coding system of locales.
+
+    The contents of this structure are implementation dependent.  Its
+    internal structure is concealed from application programs.  */
+
+/***ja
+    @brief @c MLocale ¹½Â¤ÂÎ.
+
+    @c MLocale ¹½Â¤ÂΤϡ¢¥í¥±¡¼¥ë¤Î̾Á°¡¢¸À¸ì¡¢ÃÏ°è¡¢¥â¥Ç¥£¥Õ¥¡¥¤¥¢¡¢¥³¡¼¥É¥»¥Ã¥È¡¢¤ª¤è¤ÓÂбþ¤¹¤ë¥³¡¼¥É·Ï¤Ë´Ø¤¹¤ë¾ðÊó¤òÊÝ»ý¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£
+
+    ¤³¤Î¹½Â¤ÂΤÎÆâÍƤϼÂÁõ¤Ë°Í¸¤¹¤ë¡£ 
+    ÆâÉô¹½Â¤¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤Ï¸«¤¨¤Ê¤¤¡£  */
+
+/***
+    @seealso
+    mlocale_get_prop () */
+
+typedef struct MLocale MLocale;
+
+/*=*/
+
+extern MSymbol Miso639_1, Miso639_2;
+extern MSymbol Mterritory;
+extern MSymbol Mmodifier;
+extern MSymbol Mcodeset;
+
+extern MPlist *mlanguage_list (void);
+
+extern MSymbol mlanguage_code (MSymbol language, int len);
+
+extern MPlist *mlanguage_name_list (MSymbol language, MSymbol target,
+                                   MSymbol script, MSymbol territory);
+
+extern MText *mlanguage_text (MSymbol language);
+
+extern MPlist *mscript_list (void);
+
+extern MPlist *mscript_language_list (MSymbol script);
+
+extern MSymbol mlanguage_name (MSymbol language);
+
+extern MLocale *mlocale_set (int category, const char *locale);
+
+extern MSymbol mlocale_get_prop (MLocale *locale, MSymbol key);
+
+extern int mtext_ftime (MText *mt, const char *format, const struct tm *tm,
+                       MLocale *locale);
+
+extern MText *mtext_getenv (const char *name);
+
+extern int mtext_putenv (MText *mt);
+
+extern int mtext_coll (MText *mt1, MText *mt2);
+
+/*
+ *  (9) Miscellaneous functions of libc level (not yet implemented)
+ */
+
+/*
+extern int mtext_width (MText *mt, int n);
+extern MText *mtext_tolower (MText *mt);
+extern MText *mtext_toupper (MText *mt);
+*/
+
+/*
+ *  (10) Input method
+ */
+/*=*/
+/*** @ingroup m17nShell */
+/***en @defgroup m17nInputMethod Input Method (basic) */
+/***ja @defgroup m17nInputMethod ÆþÎϥ᥽¥Ã¥É (´ðËÜÉôʬ) */
+/*=*/
+
+/*** @addtogroup m17nInputMethod 
+     @{ */
+/*=*/
+/* Struct forward declaration.  */
+/***
+    @brief See struct MInputMethod */
+typedef struct MInputMethod MInputMethod;
+/*=*/
+/***
+    @brief See struct MInputContext */
+typedef struct MInputContext MInputContext;
+/*=*/
+
+/***en
+    @brief Type of input method callback functions.
+
+    This is the type of callback functions called from input method
+    drivers.  $IC is a pointer to an input context, $COMMAND is a name
+    of callback for which the function is called.   */
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤Î·¿Àë¸À.
+
+    ÆþÎϥ᥽¥Ã¥É¤«¤é¸Æ¤Ð¤ì¤ë¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤Î·¿¤Ç¤¢¤ë¡£$IC 
+    ¤ÏÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¡¢$COMMAND ¤Ï´Ø¿ô¤¬¸Æ¤Ð¤ì¤ë¥³¡¼¥ë¥Ð¥Ã¥¯¤Î̾Á°¤Ç¤¢¤ë¡£  */
+
+typedef void (*MInputCallbackFunc) (MInputContext *ic, MSymbol command);
+/*=*/
+
+/***en
+    @brief Structure of input method driver.
+
+    The type @c MInputDriver is the structure of an input method driver that
+    contains several functions to handle an input method.  */
+
+/***ja
+    @brief ÆþÎϥɥ饤¥ÐÍѹ½Â¤ÂÎ.
+
+    @c MInputDriver ¤Ï¡¢ÆþÎϥ᥽¥Ã¥É¤ò¼è¤ê°·¤¦´Ø¿ô¤ò´Þ¤àÆþÎϥ᥽¥Ã¥É¥É¥é¥¤¥Ð¤Î¹½Â¤ÂΤη¿¤Ç¤¢¤ë¡£  */
+
+typedef struct MInputDriver
+{
+  /***en
+      @brief Open an input method.
+
+      This function opens the input method $IM.  It is called from the
+      function minput_open_im () after all member of $IM but \<info\>
+      set.  If opening $IM succeeds, it returns 0.  Otherwise, it
+      returns -1.  The function can setup $IM->info to keep various
+      information that is referred by the other driver functions.  */
+
+  /***ja
+      @brief ÆþÎϥ᥽¥Ã¥É¤ò¥ª¡¼¥×¥ó¤¹¤ë.
+
+      ¤³¤Î´Ø¿ô¤Ï¡¢ÆþÎϥ᥽¥Ã¥É $IM ¤ò¥ª¡¼¥×¥ó¤¹¤ë¡£$IM ¤Î \<info\> 
+      °Ê³°¤ÎÁ´¥á¥ó¥Ð¡¼¤¬¥»¥Ã¥È¤µ¤ì¤¿¸å¤Ç¡¢´Ø¿ô minput_open_im () 
+      ¤«¤é¸Æ¤Ð¤ì¤ë¡£$IM ¤ò¥ª¡¼¥×¥ó¤Ç¤­¤ì¤Ð 0 ¤ò¡¢¤Ç¤­¤Ê¤±¤ì¤Ð -1¤òÊÖ¤¹¡£
+      ¤³¤Î´Ø¿ô¤Ï $IM->info 
+      ¤òÀßÄꤷ¤Æ¡¢Â¾¤Î¥É¥é¥¤¥Ð´Ø¿ô¤«¤é»²¾È¤µ¤ì¤ë¾ðÊó¤òÊÝ»ý¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
+      */
+
+  int (*open_im) (MInputMethod *im);
+
+  /***en
+      @brief Close an input method.
+
+      This function closes the input method $IM.  It is called from
+      the function minput_close_im ().  It frees all memory allocated
+      for $IM->info (if any) after finishing all the tasks of closing
+      the input method.  But, the other members of $IM should not be
+      touched.  */
+
+  /***ja
+      @brief ÆþÎϥ᥽¥Ã¥É¤ò¥¯¥í¡¼¥º¤¹¤ë.
+
+      ¤³¤Î´Ø¿ô¤Ï¡¢ÆþÎϥ᥽¥Ã¥É $IM ¤ò¥¯¥í¡¼¥º¤¹¤ë¡£´Ø¿ô 
+      minput_close_im () ¤«¤é¸Æ¤Ð¤ì¤ë¡£
+      ÆþÎϥ᥽¥Ã¥É¤Î¥¯¥í¡¼¥º¤¬¤¹¤Ù¤Æ½ªÎ»¤·¤¿»þÅÀ¤Ç¡¢¤³¤Î´Ø¿ô¤Ï$IM->info 
+      ¤Ë³ä¤êÅö¤Æ¤é¤ì¤Æ¤¤¤ë¥á¥â¥ê¤ò(¤¢¤ì¤Ð)¤¹¤Ù¤Æ³«Êü¤¹¤ë¡£
+      ¤¿¤À¤·¡¢$IM ¤Î¾¤Î¥á¥ó¥Ð¤Ë±Æ¶Á¤òÍ¿¤¨¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+        */
+
+  void (*close_im) (MInputMethod *im);
+
+  /***en
+      @brief Create an input context.
+
+      This function creates the input context $IC.  It is called from
+      the function minput_create_ic () after all members of $IC but
+      \<info\> are set.  If creating $IC succeeds, it returns 0.
+      Otherwise, it returns -1.  The function can setup $IC->info to
+      keep various information that is referred by the other driver
+      functions.  */
+
+  /***ja
+      @brief ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤òÀ¸À®¤¹¤ë.
+
+      ¤³¤Î´Ø¿ô¤ÏÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È $IC ¤òÀ¸À®¤¹¤ë¡£
+      $IC ¤Î \<info\> °Ê³°¤ÎÁ´¥á¥ó¥Ð¡¼¤¬¥»¥Ã¥È¤µ¤ì¤¿¸å¤Ç¡¢´Ø¿ô
+      minput_create_ic () ¤«¤é¸Æ¤Ð¤ì¤ë¡£
+      $IC ¤òÀ¸À®¤Ç¤­¤ì¤Ð 0 ¤ò¡¢¤Ç¤­¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤¹¡£
+      ¤³¤Î´Ø¿ô¤Ï $IC->info ¤òÀßÄꤷ¤Æ¡¢Â¾¤Î¥É¥é¥¤¥Ð´Ø¿ô¤«¤é»²¾È¤µ¤ì¤ë¾ðÊó¤òÊÝ»ý¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£  */
+
+
+  int (*create_ic) (MInputContext *ic);
+
+  /***en
+      @brief Destroy an input context.
+
+      This function is called from the function minput_destroy_ic ()
+      and destroys the input context $IC.  It frees all memory
+      allocated for $IC->info (if any) after finishing all the tasks
+      of destroying the input method.  But, the other members of $IC
+      should not be touched.  */
+
+  /***ja
+      @brief ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤òÇ˲õ¤¹¤ë.
+
+      ´Ø¿ô minput_destroy_ic () ¤«¤é¸Æ¤Ð¤ì¡¢ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È $IC 
+      ¤òÇ˲õ¤¹¤ë¡£ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤ÎÇ˲õ¤¬¤¹¤Ù¤Æ½ªÎ»¤·¤¿»þÅÀ¤Ç¡¢$IC->info 
+      ¤Ë³ä¤êÅö¤Æ¤é¤ì¤Æ¤¤¤ë¥á¥â¥ê¤ò(¤¢¤ì¤Ð)¤¹¤Ù¤Æ³«Êü¤¹¤ë¡£¤¿¤À¤·¡¢$IC 
+      ¤Î¾¤Î¥á¥ó¥Ð¤Ë±Æ¶Á¤òÍ¿¤¨¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£  */
+
+  void (*destroy_ic) (MInputContext *ic);
+
+  /***en
+      @brief Filter an input key.
+
+      This function is called from the function minput_filter () and
+      filters an input key.  $KEY and $ARG are the same as what given
+      to minput_filter ().
+
+      The task of the function is to handle $KEY, update the internal
+      state of $IC.  If $KEY is absorbed by the input method and no
+      text is produced, it returns 1.  Otherwise, it returns 0.
+
+      It may update $IC->status, $IC->preedit, $IC->cursor_pos,
+      $IC->ncandidates, $IC->candidates, and $IC->produced if that is
+      necessary for the member \<callback\>.
+
+      The meaning of $ARG depends on the input method river.  See the
+      documentation of @c minput_default_driver and @c
+      minput_gui_driver for instance.  */
+
+  /***ja
+      @brief ÆþÎÏ¥­¡¼¤ò¥Õ¥£¥ë¥¿¤¹¤ë.
+
+      ´Ø¿ô minput_filter () ¤«¤é¸Æ¤Ð¤ì¡¢ÆþÎÏ¥­¡¼¤ò¥Õ¥£¥ë¥¿¤¹¤ë¡£°ú¿ô 
+      $KEY, $ARG ¤Ï´Ø¿ô minput_filter () ¤Î¤â¤Î¤ÈƱ¤¸¡£
+
+      ¤³¤Î´Ø¿ô¤Ï $KEY ¤ò½èÍý¤·¡¢$IC ¤ÎÆâÉô¾õÂÖ¤ò¹¹¿·¤¹¤ë¡£ $KEY 
+      ¤¬ÆþÎϥ᥽¥Ã¥É¤ËµÛ¼ý¤µ¤ì¤Æ¥Æ¥­¥¹¥È¤¬À¸À®¤µ¤ì¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢ 
+      1 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð 0 ¤òÊÖ¤¹¡£
+
+      ¥á¥ó¥Ð \<callback\> ¤ËɬÍפǤ¢¤ì¤Ð¡¢$IC->status, $IC->preedit,
+      $IC->cursor_pos, $IC->ncandidates, $IC->candidates,
+      $IC->produced ¤ò¹¹¿·¤Ç¤­¤ë¡£
+
+      $ARG ¤Î°ÕÌ£¤ÏÆþÎϥ᥽¥Ã¥É¥É¥é¥¤¥Ð¤Ë°Í¸¤¹¤ë¡£Îã¤Ï @c
+      minput_default_driver ¤Þ¤¿¤Ï @c minput_gui_driver 
+      ¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£ */
+
+  int (*filter) (MInputContext *ic, MSymbol key, void *arg);
+
+  /***en
+      @brief  Lookup a produced text in an input context.
+
+      It is called from the function minput_lookup () and looks up a
+      produced text in the input context $IC.  This function
+      concatenate a text produced by the input key $KEY (if any) to
+      M-text $MT.  If $KEY was correctly handled by the input method
+      of $IC, it returns 0.  Otherwise, it returns 1.
+
+      The meaning of $ARG depends on the input method driver.  See the
+      documentation of @c minput_default_driver and @c
+      minput_gui_driver for instance.  */
+
+  /***ja
+      @brief ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤ÇÀ¸À®¤µ¤ì¤ë¥Æ¥­¥¹¥È¤Î³ÍÆÀ.
+
+      ´Ø¿ô minput_lookup () ¤«¤é¸Æ¤Ð¤ì¡¢ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È $IC 
+      ¤ÇÀ¸À®¤µ¤ì¤ë¥Æ¥­¥¹¥È¤ò¸¡º÷¤¹¤ë¡£ÆþÎÏ¥­¡¼ $KEY 
+      ¤Ë¤è¤Ã¤ÆÀ¸À®¤µ¤ì¤ë¥Æ¥­¥¹¥È¤¬¤¢¤ì¤Ð¡¢M-text $MT ¤ËÄɲ乤롣 $KEY
+      ¤¬ÆþÎϥ᥽¥Ã¥É $IC ¤Ë¤è¤Ã¤ÆÀµ¤·¤¯½èÍý¤µ¤ì¤ì¤Ð 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð 1 ¤òÊÖ¤¹¡£
+
+      $ARG ¤Î°ÕÌ£¤ÏÆþÎϥ᥽¥Ã¥É¥É¥é¥¤¥Ð¤Ë°Í¸¤¹¤ë¡£Îã¤Ï @c
+      minput_default_driver ¤Þ¤¿¤Ï @c minput_gui_driver ¤ÎÀâÌÀ¤ò»²¾È¤Î
+      ¤³¤È¡£ */
+
+  int (*lookup) (MInputContext *ic, MSymbol key, void *arg, MText *mt);
+
+  /***en
+      @brief List of callback functions.
+
+      List of callback functions.  Keys are one of
+      @b Minput_preedit_start, @b Minput_preedit_draw,
+      @b Minput_preedit_done, @b Minput_status_start, @b Minput_status_draw,
+      @b Minput_status_done, @b Minput_candidates_start,
+      @b Minput_candidates_draw, @b Minput_candidates_done,
+      @b Minput_set_spot, @b Minput_toggle, @b Minput_reset,
+      @b Minput_get_surrounding_text, @b Minput_delete_surrounding_text.
+      Values are functions of type #MInputCallbackFunc.  */
+  /***ja
+      @brief ¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤Î¥ê¥¹¥È.
+
+      ¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤Î¥ê¥¹¥È¡£¥­¡¼¤Ï¼¡¤Î¤¤¤º¤ì¤«¡£
+      @b Minput_preedit_start, @b Minput_preedit_draw,
+      @b Minput_preedit_done, @b Minput_status_start, @b Minput_status_draw,
+      @b Minput_status_done, @b Minput_candidates_start,
+      @b Minput_candidates_draw, @b Minput_candidates_done,
+      @b Minput_set_spot, @b Minput_toggle, @b Minput_reset,
+      @b Minput_get_surrounding_text, @b Minput_delete_surrounding_text¡£
+      ÃͤÏ#MInputCallbackFunc ·¿¤Î´Ø¿ô¡£  */
+  MPlist *callback_list;
+
+} MInputDriver;
+/*=*/
+/*** @} */
+/*=*/
+
+extern MInputDriver minput_default_driver;
+
+extern MSymbol Minput_method;
+extern MSymbol Minput_driver;
+
+extern MInputDriver *minput_driver;
+
+/** Symbols for callback commands.  */
+extern MSymbol Minput_preedit_start;
+extern MSymbol Minput_preedit_draw;
+extern MSymbol Minput_preedit_done;
+extern MSymbol Minput_status_start;
+extern MSymbol Minput_status_draw;
+extern MSymbol Minput_status_done;
+extern MSymbol Minput_candidates_start;
+extern MSymbol Minput_candidates_draw;
+extern MSymbol Minput_candidates_done;
+extern MSymbol Minput_set_spot;
+extern MSymbol Minput_toggle;
+extern MSymbol Minput_reset;
+extern MSymbol Minput_get_surrounding_text;
+extern MSymbol Minput_delete_surrounding_text;
+
+/** Symbols for special input key event.  */
+extern MSymbol Minput_focus_move;
+extern MSymbol Minput_focus_in;
+extern MSymbol Minput_focus_out;
+
+/** Symbols describing input method command/variable.  */
+extern MSymbol Minherited;
+extern MSymbol Mcustomized;
+extern MSymbol Mconfigured;
+
+/*** @addtogroup m17nInputMethod 
+     @{ */
+/*=*/
+/***en
+    @brief Structure of input method.
+
+    The type @c MInputMethod is the structure of input method
+    objects.  */
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¤Î¹½Â¤ÂÎ.
+
+    @c MInputMethod ¤Ï¡¢ÆþÎϥ᥽¥Ã¥É¥ª¥Ö¥¸¥§¥¯¥ÈÍѤι½Â¤ÂΤη¿¤Ç¤¢¤ë¡£  */
+
+struct MInputMethod
+{
+  /***en Which language this input method is for.  The value is @c
+      Mnil if the input method is foreign.  */
+  /***ja ¤É¤Î¸À¸ìÍѤÎÆþÎϥ᥽¥Ã¥É¤«¡£
+      ÆþÎϥ᥽¥Ã¥É¤¬³°Éô¤Î¤â¤Î¤Ç¤¢¤ë¾ì¹ç¤ÎÃͤϠ@c Mnil ¡£  */
+  MSymbol language;
+
+  /***en Name of the input method.  If the input method is foreign, it
+      must has a property of key @c Minput_driver and the value must be a
+      pointer to a proper input method driver.  */
+  /***ja ÆþÎϥ᥽¥Ã¥É¤Î̾Á°¡£³°Éô¥á¥½¥Ã¥É¤Ç¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢@c
+      Minput_driver ¤ò¥­¡¼¤È¤¹¤ë¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Á¡¢¤½¤ÎÃͤÏŬÀÚ¤ÊÆþÎϥ᥽¥Ã¥É¥É¥é¥¤¥Ð¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£*/
+  MSymbol name;
+
+  /***en Input method driver of the input method.  */
+  /***ja ¤½¤ÎÆþÎϥ᥽¥Ã¥ÉÍѤÎÆþÎϥ᥽¥Ã¥É¥É¥é¥¤¥Ð¡£  */
+  MInputDriver driver;
+
+  /***en The argument given to minput_open_im (). */
+  /***ja minput_open_im () ¤ËÅϤµ¤ì¤ë°ú¿ô¡£  */
+  void *arg;
+
+  /***en Pointer to extra information that \<driver\>.open_im ()
+      setups. */
+  /***ja \<driver\>.open_im () ¤¬ÀßÄꤹ¤ëÄɲþðÊó¤Ø¤Î¥Ý¥¤¥ó¥¿¡£ */
+  void *info;
+};
+
+/*=*/
+
+/***en
+    @brief Bit-masks to specify how candidates of input method is changed.  */
+
+/***ja
+    @brief ÆþÎϥ᥽¥Ã¥É¤ÎÆþÎϸõÊ䤬¤É¤¦Êѹ¹¤µ¤ì¤¿¤«¤ò¼¨¤¹¥Ó¥Ã¥È¥Þ¥¹¥¯.  */
+
+enum MInputCandidatesChanged
+  {
+    MINPUT_CANDIDATES_LIST_CHANGED = 1,
+    MINPUT_CANDIDATES_INDEX_CHANGED = 2,
+    MINPUT_CANDIDATES_SHOW_CHANGED = 4,
+    MINPUT_CANDIDATES_CHANGED_MAX
+  };
+
+
+/*=*/
+
+/***en
+    @brief Structure of input context.
+
+    The type @c MInputContext is the structure of input context
+    objects.  */
+
+/***ja
+    @brief ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥ÈÍѹ½Â¤ÂÎ.
+
+    @c MInputContext ¤Ï¡¢ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¥ª¥Ö¥¸¥§¥¯¥ÈÍѤι½Â¤ÂΤη¿¤Ç¤¢¤ë¡£  */
+
+struct MInputContext
+{
+  /***en Backward pointer to the input method.  It is set up be the
+      function minput_create_ic ().  */
+  /***ja ÆþÎϥ᥽¥Ã¥É¤Ø¤ÎµÕ¥Ý¥¤¥ó¥¿¡£´Ø¿ô minput_create_ic () 
+      ¤Ë¤è¤Ã¤ÆÀßÄꤵ¤ì¤ë¡£  */ 
+  MInputMethod *im;
+
+  /***en M-text produced by the input method.  It is set up by the
+      function minput_lookup () .  */
+  /***ja ÆþÎϥ᥽¥Ã¥É¤Ë¤è¤Ã¤ÆÀ¸À®¤µ¤ì¤ë M-text¡£´Ø¿ô minput_lookup () 
+      ¤Ë¤è¤Ã¤ÆÀßÄꤵ¤ì¤ë¡£  */
+  MText *produced;
+
+  /***en Argument given to the function minput_create_im (). */
+  /***ja ´Ø¿ô minput_create_ic () ¤ËÅϤµ¤ì¤ë°ú¿ô¡£ */
+  void *arg;
+
+  /***en Flag telling whether the input context is currently active or
+      inactive.  The value is set to 1 (active) when the input context
+      is created.  It is toggled by the function minput_toggle ().  */
+  /***ja ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤¬¥¢¥¯¥Æ¥£¥Ö¤«¤É¤¦¤«¤ò¼¨¤¹¥Õ¥é¥°¡£
+      ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤¬À¸À®¤µ¤ì¤¿»þÅÀ¤Ç¤ÏÃͤϠ1 ¡Ê¥¢¥¯¥Æ¥£¥Ö¡Ë¤Ç¤¢¤ê¡¢´Ø¿ô 
+      minput_toggle () ¤Ë¤è¤Ã¤Æ¥È¥°¥ë¤µ¤ì¤ë¡£  */
+  int active;
+
+  /***en Spot location and size of the input context.  */
+  /***ja ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤Î¥¹¥Ý¥Ã¥È¤Î°ÌÃÖ¤ÈÂ礭¤µ.  */
+  struct {
+    /***en X and Y coordinate of the spot.  */
+    /***ja ¥¹¥Ý¥Ã¥È¤Î X, Y ºÂɸ.  */
+    int x, y;
+
+    /***en Ascent and descent pixels of the line of the spot.  */
+    /***ja ¥¹¥Ý¥Ã¥È¤Î¥¢¥»¥ó¥È¤È¥Ç¥£¥»¥ó¥È¤Î¥Ô¥¯¥»¥ë¿ô.  */
+    int ascent, descent;
+
+    /***en Font size for preedit text in 1/10 point.  */
+    /***ja preedit ¥Æ¥­¥¹¥ÈÍѤΥե©¥ó¥È¥µ¥¤¥º (1/10 ¥Ý¥¤¥ó¥Èñ°Ì).  */
+    int fontsize;
+
+    /***en M-text at the spot, or NULL.  */
+    /***ja ¥¹¥Ý¥Ã¥È¾å¤Î M-text¡¢¤Þ¤¿¤Ï NULL.  */
+    MText *mt;
+
+    /***en Character position in \<mt\> at the spot.  */
+    /***ja \<mt\> ¤Ë¤ª¤±¤ë¥¹¥Ý¥Ã¥È¤Îʸ»ú°ÌÃÖ.  */
+    int pos;
+  } spot;
+
+  /***en The usage of the following members depends on the input
+      method driver.  The descriptions below are for the driver of an
+      internal input method.  They are set by the function
+      \<im\>->driver.filter ().  */
+  /***ja °Ê²¼¤Î¥á¥ó¥Ð¤Î»ÈÍÑË¡¤ÏÆþÎϥ᥽¥Ã¥É¥É¥é¥¤¥Ð¤Ë¤è¤Ã¤Æ°Û¤Ê¤ë¡£
+      °Ê²¼¤ÎÀâÌÀ¤Ï¡¢ÆâÉôÆþÎϥ᥽¥Ã¥ÉÍѤÎÆþÎϥɥ饤¥Ð¤ËÂФ¹¤ë¤â¤Î¤Ç¤¢¤ë¡£
+      ¤³¤ì¤é¤Ï´Ø¿ô \<im\>->driver.filter () ¤Ë¤è¤Ã¤ÆÀßÄꤵ¤ì¤ë¡£  */
+
+  /***en Pointer to extra information that \<im\>->driver.create_ic ()
+      setups.  It is used to record the internal state of the input
+      context.  */
+  /***ja \<im\>->driver.create_ic () ¤¬ÀßÄꤹ¤ëÄɲþðÊó¤Ø¤Î¥Ý¥¤¥ó¥¿¡£
+      ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤ÎÆâÉô¾õÂÖ¤òµ­Ï¿¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£ */
+  void *info;
+
+  /***en M-text describing the current status of the input
+      context.  */
+  /***ja ÆþÎÏ¥³¥ó¥Æ¥¯¥¹¥È¤Î¸½ºß¤Î¾õÂÖ¤òɽ¤¹ M-text  */
+  MText *status;
+
+  /***en The function \<im\>->driver.filter () sets the value to 1 when
+      it changes \<status\>.  */
+  /***ja ´Ø¿ô \<im\>->driver.filter () ¤Ï¡¢\<status\> ¤òÊѤ¨¤¿ºÝ¤Ë¤³¤ÎÃͤò 1 
+      ¤ËÀßÄꤹ¤ë¡£  */
+  int status_changed;
+
+  /***en M-text containing the current preedit text.  The function
+      \<im\>->driver.filter () sets the value.  */
+  /***ja ¸½ºß¤Î preedit ¥Æ¥­¥¹¥È¤ò´Þ¤à M-text¡£´Ø¿ô 
+      \<im\>->driver.filter () ¤Ë¤è¤Ã¤ÆÀßÄꤵ¤ì¤ë¡£  */ 
+  MText *preedit;
+
+  /***en The function \<im\>->driver.filter () sets the value to 1 when
+      it changes \<preedit\>.  */
+  /***ja ´Ø¿ô \<im\>->driver.filter () ¤Ï¡¢\<preedit\> ¤òÊѤ¨¤¿ºÝ¤Ë¤³¤ÎÃͤò 
+      1 ¤ËÀßÄꤹ¤ë¡£  */
+  int preedit_changed;
+
+  /***en Cursor position of \<preedit\>.  */
+  /***ja \<preedit\>¤Î¥«¡¼¥½¥ë°ÌÃÖ  */
+  int cursor_pos;
+
+  /***en The function \<im\>->driver.filter () sets the value to 1 when
+      it changes \<cursor_pos\>.  */
+  /***ja ´Ø¿ô \<im\>->driver.filter () ¤Ï¡¢\<cursor_pos\> ¤òÊѤ¨¤¿ºÝ¤Ë¤³¤ÎÃͤò 
+      1 ¤ËÀßÄꤹ¤ë¡£  */
+  int cursor_pos_changed;
+
+  /***en Plist of the current candidate groups.  Each element is an
+      M-text or a plist.  If an element is an M-text (i.e. the key is Mtext),
+      candidates in that group are characters in the M-text.  If it is
+      a plist (i.e. the key is Mplist), each element is an M-text, and
+      candidates in that group are those M-texts.  */
+  /***ja ¸½ºß¤Î¸õÊ䥰¥ë¡¼¥×¤Î Plist ¡£³ÆÍ×ÁǤϠM-text ¤« plist ¤Ç¤¢¤ë¡£
+      Í×ÁǤ¬ M-text ¤Î¾ì¹ç¡Ê¥­¡¼¤¬ Mtext ¤Ç¤¢¤ë¾ì¹ç¡Ë¤Ë¤Ï¡¢¤½¤Î¥°¥ë¡¼¥×¤Î¸õÊä¤Ï¤½¤Î 
+      M-text Ãæ¤Î³Æʸ»ú¤Ç¤¢¤ë¡£ Í×ÁǤ¬ plist ¤Î¾ì¹ç¡Ê¥­¡¼¤¬ Mplist
+      ¤Ç¤¢¤ë¾ì¹ç¡Ë¤Ë¤Ï¡¢¤½¤Î¥ê¥¹¥È¤Î³ÆÍ×ÁǤϠM-text ¤Ç¤¢¤ê¡¢¤½¤ì¤é¤¬¤½¤Î¥°¥ë¡¼¥×¤Î¸õÊä¤È¤Ê¤ë¡£  */
+  MPlist *candidate_list;
+
+  /***en Index number of the currently selected candidate in all the
+      candidates. The index of the first candidate is 0.  If the
+      number is 8, and the first candidate group contains 7
+      candidates, the currently selected candidate is the second element of the
+      second candidate group.  */
+  /***ja ¸½ºßÁªÂò¤µ¤ì¤Æ¤¤¤ë¸õÊ䤬Á´¸õÊäÃæ¤Ç²¿ÈÖÌܤ«¤ò¤ò¼¨¤¹¥¤¥ó¥Ç¥Ã¥¯¥¹¡£
+      ºÇ½é¤Î¸õÊä¤Î¥¤¥ó¥Ç¥Ã¥¯¥¹¤Ï 0¡£ºÇ½é¤Î¸õÊ䥰¥ë¡¼¥×¤Ë¼·¤Ä¤Î¸õÊ䤬´Þ¤Þ¤ì¤Æ¤ª¤ê¡¢¤³¤ÎÃͤ¬
+      8 ¤Ê¤é¤Ð¡¢¸½ºß¤Î¸õÊä¤ÏÆóÈÖÌܤθõÊ䥰¥ë¡¼¥×¤ÎÆóÈÖÌܤÎÍ×ÁǤȤ¤¤¦¤³¤È¤Ë¤Ê¤ë¡£
+      */
+  int candidate_index;
+
+  /* @{ */
+  /***en Start and the end positions of the preedit text where
+       \<candidate_list\> corresponds to.  */
+  /***ja preedit ¥Æ¥­¥¹¥ÈÃæ¤Ç¡¢\<candidate_list\>¤ËÂбþ¤¹¤ëºÇ½é¤ÈºÇ¸å¤Î°ÌÃÖ¡£
+       */
+  int candidate_from, candidate_to;
+  /* @} */
+
+  /***en Flag telling whether the current candidate group must be
+      shown or not.  The function \<im\>->driver.filter () sets the
+      value to 1 when an input method required to show candidates, and
+      sets the value to 0 otherwise.  */
+  /***ja ¸½ºß¤Î¸õÊ䥰¥ë¡¼¥×¤òɽ¼¨¤¹¤ë¤«¤É¤¦¤«¤ò¼¨¤¹¥Õ¥é¥°¡£
+      ´Ø¿ô \<im\>->driver.filter () ¤Ï¡¢ÆþÎϥ᥽¥Ã¥É¤¬¸õÊä¤Îɽ¼¨¤òÍ׵ᤷ¤¿»þ¤³¤ÎÃͤò
+      1 ¤Ë¡¢¤½¤ì°Ê³°¤Î»þ 0 ¤ËÀßÄꤹ¤ë¡£  */
+  int candidate_show;
+
+  /***en The function \<im\>->driver.filter () sets the value to bitwise
+      OR of @c enum @c MInputCandidatesChanged when it changed any of
+      the above members (\<candidate_XXX\>), and sets the value to 0
+      otherwise.  */
+  /***ja ´Ø¿ô \<im\>->driver.filter () ¤Ï¡¢¾åµ­¤Î¥á¥ó¥Ð \<candidate_XXX\>
+      ¤Î£±¤Ä¤Ç¤âÊѹ¹¤·¤¿ºÝ¤Ë¤Ï¡¢¤³¤ÎÃͤò @c enum @c
+      MInputCandidatesChanged ¤Î¥Ó¥Ã¥Èñ°Ì¤Ç¤ÎÏÀÍý OR ¤ËÀßÄꤹ¤ë¡£¤½¤¦
+      ¤Ç¤Ê¤±¤ì¤Ð 0 ¤ËÀßÄꤹ¤ë¡£ */
+  int candidates_changed;
+
+  /***en Plist that can be freely used by \<im\>->driver functions.
+      The driver of internal input method uses it to exchange extra
+      arguments and result for callback functions.  The function
+      \<im\>->driver.create_ic () sets this to an empty plist, and the
+      function \<im\>->driver.destroy_ic () frees it by using
+      m17n_object_unref ().  */
+  /***ja \<im\>->driver ¤Î´Ø¿ô·²¤Ë¤è¤Ã¤Æ¼«Í³¤Ë»ÈÍѤǤ­¤ë plist¡£
+      ÆâÉôÆþÎϥ᥽¥Ã¥ÉÍѥɥ饤¥Ð¤Ï¤³¤ì¤ò¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤È¤Î°ú¿ô¤äÊÖÃÍ
+      ¤Î¼õÅϤ·¤Ë»ÈÍѤ¹¤ë¡£´Ø¿ô \<im\>->driver.create_ic () ¤Ï¤³¤Î plist
+      ¤ò¶õ¤ËÀßÄꤹ¤ë¡£´Ø¿ô\<im\>->driver.destroy_ic () ¤Ï
+      m17n_object_unref () ¤òÍѤ¤¤Æ¤³¤Î plist ¤ò²òÊü¤¹¤ë¡£  */
+  MPlist *plist;
+};
+
+/*=*/
+/*** @} */
+/*=*/
+
+extern MInputMethod *minput_open_im (MSymbol language, MSymbol name,
+                                    void *arg);
+
+/*=*/
+
+extern void minput_close_im (MInputMethod *im);
+
+extern MInputContext *minput_create_ic (MInputMethod *im, void *arg);
+
+extern void minput_destroy_ic (MInputContext *ic);
+
+extern int minput_filter (MInputContext *ic, MSymbol key, void *arg);
+
+extern int minput_lookup (MInputContext *ic, MSymbol key, void *arg,
+                         MText *mt);
+extern void minput_set_spot (MInputContext *ic, int x, int y, int ascent,
+                            int descent, int fontsize, MText *mt, int pos);
+extern void minput_toggle (MInputContext *ic);
+
+extern void minput_reset_ic (MInputContext *ic);
+
+extern MText *minput_get_description (MSymbol language, MSymbol name);
+
+extern MPlist *minput_get_title_icon (MSymbol language, MSymbol name);
+
+extern MPlist *minput_get_command (MSymbol language, MSymbol name,
+                                  MSymbol command);
+extern int minput_config_command (MSymbol language, MSymbol name,
+                                 MSymbol command, MPlist *keyseq);
+extern MPlist *minput_get_variable (MSymbol language, MSymbol name,
+                                   MSymbol variable);
+extern int minput_config_variable (MSymbol language, MSymbol name,
+                                  MSymbol variable, MPlist *value);
+extern char *minput_config_file (void);
+
+extern int minput_save_config (void);
+
+extern int minput_callback (MInputContext *ic, MSymbol command);
+
+/* obsolete functions */
+extern MPlist *minput_get_commands (MSymbol language, MSymbol name);
+
+extern int minput_assign_command_keys (MSymbol language, MSymbol name,
+                                      MSymbol command, MPlist *keys);
+extern MPlist *minput_get_variables (MSymbol language, MSymbol name);
+
+extern int minput_set_variable (MSymbol language, MSymbol name,
+                               MSymbol variable, void *value);
+
+extern MInputMethod *mdebug_dump_im (MInputMethod *im, int indent);
+
+M17N_END_HEADER
+
+#endif /* _M17N_H_ */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/mlocale.h b/src/mlocale.h
new file mode 100644 (file)
index 0000000..1ba37ec
--- /dev/null
@@ -0,0 +1,30 @@
+/* mlocale.c -- header file for the locale module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_LOCAL_H_
+#define _M17N_LOCAL_H_
+
+/** The current locales of each category.  */
+extern MLocale *mlocale__collate, *mlocale__ctype;
+extern MLocale *mlocale__messages, *mlocale__time;
+
+#endif /* _M17N_LOCAL_H_ */
diff --git a/src/mtext-lbrk.c b/src/mtext-lbrk.c
new file mode 100644 (file)
index 0000000..e61efd3
--- /dev/null
@@ -0,0 +1,441 @@
+/* mtext-lbrk.c -- line break
+   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "m17n.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "mtext.h"
+
+enum LineBreakClass
+  {
+    LBC_OP, /* open */
+    LBC_CL, /* close */
+    LBC_QU, /* quotation */
+    LBC_GL, /* glue */
+    LBC_NS, /* no-start */
+    LBC_EX, /* exclamation/interrogation */
+    LBC_SY, /* Syntax (slash) */
+    LBC_IS, /* infix (numeric) separator */
+    LBC_PR, /* prefix */
+    LBC_PO, /* postfix */
+    LBC_NU, /* numeric */
+    LBC_AL, /* alphabetic */
+    LBC_ID, /* ideograph (atomic) */
+    LBC_IN, /* inseparable */
+    LBC_HY, /* hyphen */
+    LBC_BA, /* break after */
+    LBC_BB, /* break before */
+    LBC_B2, /* break both */
+    LBC_ZW, /* ZW space */
+    LBC_CM, /* combining mark */
+    LBC_WJ, /* word joiner */
+
+    /* used for 4.1 pair table */
+    LBC_H2, /* Hamgul 2 Jamo Syllable */
+    LBC_H3, /* Hangul 3 Jamo Syllable */
+    LBC_JL, /* Jamo leading consonant */
+    LBC_JV, /* Jamo vowel */
+    LBC_JT, /* Jamo trailing consonant */
+
+    /* These are not handled in the pair tables. */
+    LBC_SA, /* south (east) asian */
+    LBC_SP, /* space */
+    LBC_PS, /* paragraph and line separators */
+    LBC_BK, /* hard break (newline) */
+    LBC_CR, /* carriage return */
+    LBC_LF, /* line feed */
+    LBC_NL, /* next line */
+    LBC_CB, /* contingent break opportunity */
+    LBC_SG, /* surrogate */
+    LBC_AI, /* ambiguous */
+    LBC_XX, /* unknown */
+    LBC_MAX
+  };
+
+enum LineBreakAction
+  {
+    LBA_DIRECT =               '_',
+    LBA_INDIRECT =             '%',
+    LBA_COMBINING_INDIRECT =   '#',
+    LBA_COMBINING_PROHIBITED = '@',
+    LBA_PROHIBITED =           '^',
+    LBA_MAX
+  };
+
+/* The pair table of line break actions.  */
+static char *lba_pair_table[] =
+  /* OP GL SY PO ID BA ZW H2 JV
+      CL NS IS NU IN BB CM H3 JT
+       QU EX PR AL HY B2 WJ JL  */
+  { "^^^^^^^^^^^^^^^^^^^@^^^^^^", /* OP */
+    "_^%%^^^^_%____%%__^#^_____", /* CL */
+    "^^%%%^^^%%%%%%%%%%^#^%%%%%", /* QU */
+    "%^%%%^^^%%%%%%%%%%^#^%%%%%", /* GL */
+    "_^%%%^^^______%%__^#^_____", /* NS */
+    "_^%%%^^^______%%__^#^_____", /* EX */
+    "_^%%%^^^__%___%%__^#^_____", /* SY */
+    "_^%%%^^^__%%__%%__^#^_____", /* IS */
+    "%^%%%^^^__%%%_%%__^#^%%%%%", /* PR */
+    "_^%%%^^^______%%__^#^_____", /* PO */
+    "_^%%%^^^_%%%_%%%__^#^_____", /* NU */
+    "_^%%%^^^__%%_%%%__^#^_____", /* AL */
+    "_^%%%^^^_%___%%%__^#^_____", /* ID */
+    "_^%%%^^^_____%%%__^#^_____", /* IN */
+    "_^%%%^^^__%___%%__^#^_____", /* HY */
+    "_^%%%^^^______%%__^#^_____", /* BA */
+    "%^%%%^^^%%%%%%%%%%^#^%%%%%", /* BB */
+    "_^%%%^^^______%%_^^#^_____", /* B2 */
+    "__________________^_______", /* ZW */
+    "_^%%%^^^__%%_%%%__^#^_____", /* CM */
+    "%^%%%^^^%%%%%%%%%%^#^%%%%%", /* WJ */
+    "_^%%%^^^_%___%%%__^#^___%%", /* H2 */
+    "_^%%%^^^_%___%%%__^#^____%", /* H3 */
+    "_^%%%^^^_%___%%%__^#^%%%%_", /* JL */
+    "_^%%%^^^_%___%%%__^#^___%%", /* JV */
+    "_^%%%^^^_%___%%%__^#^____%"  /* JT */
+  };
+
+static MCharTable *lbc_table;
+
+/* Set LBC to enum LineBreakClass of the character at POS of MT
+   (length is LEN) while converting LBC_AI and LBC_XX to LBC_AL,
+   LBC_CB to LBC_B2, LBC_CR, LBC_LF, and LBC_NL to LBC_BK.  If POS is
+   out of range, set LBC to LBC_BK.  */
+
+#define GET_LBC(LBC, MT, LEN, POS, OPTION)                             \
+  do {                                                                 \
+    if ((POS) < 0 || (POS) >= (LEN))                                   \
+      (LBC) = LBC_BK;                                                  \
+    else                                                               \
+      {                                                                        \
+       int c = mtext_ref_char ((MT), (POS));                           \
+       (LBC) = (enum LineBreakClass) mchartable_lookup (lbc_table, c); \
+       if ((LBC) == LBC_NL)                                            \
+         (LBC) = LBC_BK;                                               \
+       else if ((LBC) == LBC_AI)                                       \
+         (LBC) = ((OPTION) & MTEXT_LBO_AI_AS_ID) ? LBC_ID : LBC_AL;    \
+       else if (! ((OPTION) & MTEXT_LBO_KOREAN_SP)                     \
+                && (LBC) >= LBC_H2 && (LBC) <= LBC_JT)                 \
+         (LBC) = LBC_AL;                                               \
+       else if ((LBC) == LBC_CB)                                       \
+         (LBC) = LBC_B2;                                               \
+       else if ((LBC) == LBC_XX)                                       \
+         (LBC) = LBC_AL;                                               \
+      }                                                                        \
+  } while (0)
+
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+/* External API */
+
+/*** @addtogroup m17nMtext */
+/*** @{ */
+/*=*/
+
+/***en
+    @brief Find a linebreak postion of an M-text.
+
+    The mtext_line_break () function checks if position $POS is a
+    proper linebreak position of an M-text $MT according to the
+    algorithm of The Unicode Standard 4.0 UAX#14.  It so, it returns
+    $POS.  Otherwise, it returns a proper linebreak position before
+    $POS.
+
+    If $OPTION is nonzero, it controls the algorithm by logical-or of
+    the members of #MTextLineBreakOption.
+
+    If $AFTER is not NULL, a proper linebreak position after $POS is
+    stored there.  */
+
+int
+mtext_line_break (MText *mt, int pos, int option, int *after)
+{
+  int break_before, break_after;
+  int len = mtext_len (mt);
+  enum LineBreakClass lbc;
+  enum LineBreakClass Blbc, Albc; /* B(efore) and A(fter) lbcs.  */
+  int Bpos, Apos;                /* B(efore) and A(fter) positions.  */
+  enum LineBreakAction action;
+  
+  if (pos >= len)
+    {
+      /* The end of text is an explicit break position.  */
+      if (after)
+       *after = pos;
+      return pos;
+    }
+
+  if (! lbc_table)
+    {
+      MSymbol key = mchar_define_property ("linebreak", Minteger);
+
+      lbc_table = mchar_get_prop_table (key, NULL);
+    }
+
+  GET_LBC (lbc, mt, len, pos, option);
+  Apos = pos;
+  Albc = lbc;
+  if (Albc == LBC_SP)
+    {
+      if (option & MTEXT_LBO_SP_CM)
+       {
+         GET_LBC (Albc, mt, len, Apos + 1, option);
+         Albc = (Albc == LBC_CM) ? LBC_ID : LBC_SP;
+       }
+      while (Albc == LBC_SP)
+       {
+         Apos--;
+         GET_LBC (Albc, mt, len, Apos, option);
+       }
+    }
+  if ((option & MTEXT_LBO_SP_CM) && (Albc == LBC_CM))
+    {
+      Apos--;
+      GET_LBC (Albc, mt, len, Apos, option);
+      if (Albc == LBC_SP)
+       Albc = LBC_ID;
+      else
+       Apos++, Albc = LBC_CM;
+    }
+
+  if (Albc == LBC_CR)
+    Albc = LBC_BK;
+  else if (Albc == LBC_LF)
+    {
+      GET_LBC (Albc, mt, len, Apos - 1, option);
+      if (Albc == LBC_CR)
+       Apos--;
+      Albc = LBC_BK;
+    }
+  else if (Albc == LBC_SA)
+    Albc = mtext__word_segment (mt, Apos, &Apos, NULL) > 0 ? LBC_BB : LBC_AL;
+  Bpos = Apos;
+  /* After exiting from the following loop, if Apos is positive, it is
+     the previous (including POS) break position.  */
+  while (Apos > 0)
+    {
+      int indirect;
+      int next = -1;
+
+      /* Now Bpos == Apos.  */
+      do {
+       Bpos--;
+       GET_LBC (Blbc, mt, len, Bpos, option);
+      } while (Blbc == LBC_SP);
+
+      if (Blbc == LBC_BK || Blbc == LBC_LF || Blbc == LBC_CR)
+       {
+         /* Explicit break.  */
+         break;
+       }
+
+      indirect = Bpos + 1 < Apos;
+
+      if (Blbc == LBC_CM)
+       {
+         do {
+             Bpos--;
+             GET_LBC (Blbc, mt, len, Bpos, option);
+         } while (Blbc == LBC_CM);
+         if ((option & MTEXT_LBO_SP_CM) && (Blbc == LBC_SP))
+           Blbc = LBC_ID;
+         else if (Blbc == LBC_SP || Blbc == LBC_ZW
+                  || Blbc == LBC_BK || Blbc == LBC_LF || Blbc == LBC_CR)
+           {
+             Blbc = LBC_AL;
+             Bpos++;
+           }
+       }                  
+      if (Blbc == LBC_SA)
+       {
+         mtext__word_segment (mt, Bpos, &next, NULL);
+         Blbc = LBC_AL;
+       }
+
+      if (Albc != LBC_BK)
+       {
+         action = lba_pair_table[Blbc][Albc];
+         if (action == LBA_DIRECT)
+           break;
+         else if (action == LBA_INDIRECT)
+           {
+             if (indirect)
+               break;
+           }
+         else if (action == LBA_COMBINING_INDIRECT)
+           {
+             if (indirect)
+               break;
+           }
+       }
+      if (next >= 0)
+       Apos = next, Albc = LBC_BB;
+      else
+       Apos = Bpos, Albc = Blbc;
+    }
+  break_before = Apos;
+  if (break_before > 0)
+    {
+      if (! after)
+       return break_before;
+      if (break_before == pos)
+       {
+         if (after)
+           *after = break_before;
+         return break_before;
+       }
+    }
+
+  /* Now find a break position after POS.  */
+  break_after = 0;
+  Bpos = pos;
+  Blbc = lbc;
+  if (Blbc == LBC_CM)
+    {
+      do {
+       Bpos--;
+       GET_LBC (Blbc, mt, len, Bpos, option);
+      } while (Blbc == LBC_CM);
+      if (Blbc == LBC_SP || Blbc == LBC_ZW
+         || Blbc == LBC_BK || Blbc == LBC_LF || Blbc == LBC_CR)
+       {
+         if ((Blbc == LBC_SP) && (option & MTEXT_LBO_SP_CM))
+           Blbc = LBC_ID;
+         else
+           Blbc = LBC_AL;
+       }
+      Bpos = pos;
+    }
+  if (Blbc == LBC_SA)
+    {
+      mtext__word_segment (mt, Bpos, NULL, &Bpos);
+      Blbc = LBC_AL;
+    }
+  else if (Blbc == LBC_SP)
+    {
+      if (option & MTEXT_LBO_SP_CM)
+       {
+         GET_LBC (Blbc, mt, len, Bpos + 1, option);
+         if (Blbc == LBC_CM)
+           Blbc = LBC_ID, Bpos++;
+         else
+           Blbc = LBC_SP;
+       }
+      while (Blbc == LBC_SP)
+       {
+         Bpos--;
+         GET_LBC (Blbc, mt, len, Bpos, option);
+       }
+      if (Bpos < 0)
+       Bpos = pos;
+    }
+  Apos = Bpos;
+  /* After exiting from the following loop, if Apos is positive, it is
+     the next break position.  */
+  while (1)
+    {
+      int indirect;
+      int next = -1;
+
+      /* Now Bpos == Apos.  */
+      if (Blbc == LBC_LF || Blbc == LBC_BK || Blbc == LBC_CR)
+       {
+         Apos++;
+         if (Blbc == LBC_CR)
+           {
+             GET_LBC (Blbc, mt, len, Bpos + 1, option);
+             if (Blbc == LBC_LF)
+               Apos++;
+           }
+         break;
+       }
+
+      do {
+       Apos++;
+       GET_LBC (Albc, mt, len, Apos, option);
+      } while (Albc == LBC_SP);
+      
+      if (Blbc == LBC_SP)
+       break;
+
+      if (Apos == len)
+       /* Explicit break at the end of text.  */
+       break;
+
+      indirect = Bpos + 1 < Apos;
+
+      if (Albc == LBC_SA)
+       Albc = mtext__word_segment (mt, Apos, NULL, &next) ? LBC_BB : LBC_AL;
+
+      action = lba_pair_table[Blbc][Albc];
+      if (action == LBA_DIRECT)
+       /* Direct break at Apos.  */
+       break;
+      else if (action == LBA_INDIRECT)
+       {
+         if (indirect)
+           break;
+       }
+      else if (action == LBA_COMBINING_INDIRECT)
+       {
+         if (indirect)
+           {
+             if (option & MTEXT_LBO_SP_CM)
+               Apos--;
+             break;
+           }
+       }
+      if (next >= 0)
+       Bpos = next, Blbc = LBC_AL;
+      else
+       {
+         Bpos = Apos;
+         if (Albc != LBC_CM)
+           Blbc = Albc;
+       }
+    }
+  break_after = Apos;
+  if (after)
+    *after = break_after;
+
+  return (break_before > 0 ? break_before : break_after);
+}
+
+/*** @} */ 
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/mtext-wseg.c b/src/mtext-wseg.c
new file mode 100644 (file)
index 0000000..a27469d
--- /dev/null
@@ -0,0 +1,420 @@
+/* mtext-wseg.c -- word segmentation
+   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "config.h"
+#include "m17n-core.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "textprop.h"
+#include "character.h"
+
+typedef struct _MWordseg_Function MWordseg_Function;
+
+struct _MWordseg_Function
+{
+  int initialized;
+  int (*init) (void);
+  void (*fini) (void);
+  int (*wseg) (MText *mt, int pos, int *from, int *to,
+              MWordseg_Function *wordseg);
+  MWordseg_Function *next;
+};
+
+static MWordseg_Function *wordseg_function_list;
+
+static MCharTable *wordseg_function_table;
+
+static int
+generic_wordseg (MText *mt, int pos, int *from, int *to,
+                MWordseg_Function *wordseg)
+{
+  int len = mtext_nchars (mt);
+  int c = mtext_ref_char (mt, pos);
+  MSymbol category = mchar_get_prop (c, Mcategory);
+  char cathead = msymbol_name (category)[0];
+  int in_word = (cathead == 'L' || cathead == 'M' || cathead == 'N');
+  int beg, end;
+
+  for (beg = pos; beg > 0; beg--)
+    {
+      c = mtext_ref_char (mt, beg - 1);
+      category = mchar_get_prop (c, Mcategory);
+      cathead = msymbol_name (category)[0];
+      if (in_word != (cathead == 'L' || cathead == 'M' || cathead == 'N'))
+       break;
+      if (mchartable_lookup (wordseg_function_table, c) != wordseg)
+       break;
+    }
+  for (end = pos; end < len; end++)
+    {
+      c = mtext_ref_char (mt, end);
+      category = mchar_get_prop (c, Mcategory);
+      cathead = msymbol_name (category)[0];
+      if (in_word != (cathead == 'L' || cathead == 'M' || cathead == 'N'))
+       break;
+      if (mchartable_lookup (wordseg_function_table, c) != wordseg)
+       break;
+    }
+  if (from)
+    *from = beg;
+  if (to)
+    *to = end;
+  return in_word;
+}
+
+#ifdef HAVE_THAI_WORDSEG
+
+#define THAI_BEG 0x0E01
+#define THAI_END 0x0E6F
+
+static MSymbol M_thai_wordseg;
+
+/* We have libthai, wordcut, or wordcut-old.  Each of them provides
+   the following three functions.  */
+
+static int thai_wordseg_init (void);
+static void thai_wordseg_fini (void);
+static MTextProperty *thai_wordseg_propertize (MText *mt, int pos,
+                                              int from, int to,
+                                              unsigned char *tis);
+
+#ifdef HAVE_LIBTHAI
+
+#include <thai/thbrk.h>
+
+static int
+thai_wordseg_init (void)
+{
+  return 0;
+}
+
+static void
+thai_wordseg_fini (void)
+{
+  return;
+}
+
+static MTextProperty *
+thai_wordseg_propertize (MText *mt, int pos, int from, int to,
+                        unsigned char *tis)
+{
+  int len = to - from;
+  int *breaks = alloca ((sizeof (int)) * len);
+  int count = th_brk ((thchar_t *) tis, breaks, len);
+  MTextProperty *prop = NULL;
+
+  if (count == 0)
+    {
+      prop = mtext_property (M_thai_wordseg, Mt,
+                            MTEXTPROP_VOLATILE_WEAK | MTEXTPROP_NO_MERGE);
+      mtext_attach_property (mt, from, to, prop);
+      M17N_OBJECT_UNREF (prop);
+    }
+  else
+    {
+      int last, i;
+      MTextProperty *this;
+
+      for (i = 0, last = from; i < count; i++)
+       {
+         this = mtext_property (M_thai_wordseg, Mt,
+                                MTEXTPROP_VOLATILE_WEAK | MTEXTPROP_NO_MERGE);
+         mtext_attach_property (mt, last, from + breaks[i], this);
+         if (pos >= last && pos < from + breaks[i])
+           prop = this;
+         M17N_OBJECT_UNREF (this);
+         last = from + breaks[i];
+       }
+      if (last < to)
+       {
+         this = mtext_property (M_thai_wordseg, Mt,
+                                MTEXTPROP_VOLATILE_WEAK | MTEXTPROP_NO_MERGE);
+         mtext_attach_property (mt, last, to, this);
+         if (pos >= last && pos < to)
+           prop = this;
+         M17N_OBJECT_UNREF (this);
+       }
+    }
+
+  if (! prop)
+    mdebug_hook ();
+  return prop;
+}
+
+#elif HAVE_WORDCUT
+
+#include <wordcut/wcwordcut.h>
+
+static WcWordcut wordcut;
+static WcWordVector *word_vector;
+
+static int
+thai_wordseg_init (void)
+{  
+  wc_wordcut_init (&wordcut);
+  return 0;
+}
+
+static void
+thai_wordseg_fini (void)
+{
+  if (word_vector)
+    wc_word_vector_delete (word_vector);
+  wc_wordcut_destroy (&wordcut);
+  return;
+}
+
+static MTextProperty *
+thai_wordseg_propertize (MText *mt, int pos, int from, int to,
+                        unsigned char *tis)
+{
+  gulong i, count;
+  MTextProperty *prop = NULL;
+
+  if (! word_vector)
+    word_vector = wc_word_vector_new ();
+  else
+    {
+      wc_word_vector_destroy (word_vector);
+      wc_word_vector_init (word_vector);
+    }
+
+  wc_wordcut_cut (&wordcut, (gchar *) tis, (gint) (to - from),
+                 word_vector);
+  count = wc_word_vector_get_count (word_vector);
+  for (i = 0; i < count; i++)
+    {
+      WcWord *word = wc_word_vector_get_word (word_vector, i);
+
+      if (word->type != WC_WORDTYPE_DELETED)
+       {
+         MSymbol val = ((word->type == WC_WORDTYPE_DICTIONARY
+                         || word->type == WC_WORDTYPE_WORDUNIT
+                         || word->type == WC_WORDTYPE_JOINED)
+                        ? Mt : Mnil);
+         MTextProperty *this
+           = mtext_property (M_thai_wordseg, val,
+                             MTEXTPROP_VOLATILE_WEAK | MTEXTPROP_NO_MERGE);
+
+         mtext_attach_property (mt, from, from + word->len, this);
+         if (pos >= from && pos < from + word->len)
+           prop = this;
+         M17N_OBJECT_UNREF (this);
+         from += word->len;
+       }
+    }
+  return prop;
+}
+
+#else  /* HAVE_WORDCUT_OLD */
+
+#include <wordcut/wordcut.h>
+
+static Wordcut wordcut;
+static WordcutResult wordcut_result;
+static int wordcut_result_used;
+
+static int
+thai_wordseg_init (void)
+{  
+  return (wordcut_init (&wordcut, WORDCUT_TDICT) == 0 ? 0 : -1);
+}
+
+static void
+thai_wordseg_fini (void)
+{
+  if (wordcut_result_used)
+    {
+      wordcut_result_close (&wordcut_result);
+      wordcut_result_used = 0;
+    }
+  wordcut_close (&wordcut);
+  return;
+}
+
+static MTextProperty *
+thai_wordseg_propertize (MText *mt, int pos, int from, int to,
+                        unsigned char *tis)
+{
+  int i, last;
+  MTextProperty *prop = NULL;
+
+  wordcut_cut (&wordcut, (char *) tis, &wordcut_result);
+  wordcut_result_used = 1;
+  for (i = 0, last = from; i < wordcut_result.count; i++)
+    {
+      MTextProperty *this;
+
+      if (last < from + wordcut_result.start[i])
+       {
+         this = mtext_property (M_thai_wordseg, Mnil,
+                                MTEXTPROP_VOLATILE_WEAK);
+         mtext_attach_property (mt, last, from + wordcut_result.start[i],
+                                this);
+         if (pos >= last && pos < from + wordcut_result.start[i])
+           prop = this;
+         M17N_OBJECT_UNREF (this);
+       }
+
+      this = mtext_property (M_thai_wordseg, Mt,
+                            MTEXTPROP_VOLATILE_WEAK | MTEXTPROP_NO_MERGE);
+      last = from + wordcut_result.start[i];
+      mtext_attach_property (mt, last, last + wordcut_result.offset[i], this);
+      if (pos >= last && pos < last + wordcut_result.offset[i])
+       prop = this;
+      m17n_object_unref (this);
+      last += wordcut_result.offset[i];
+    }
+  return prop;
+}
+
+#endif  /* not HAVE_LIBTHA, HAVE_WORDCUT nor HAVE_WORDCUT_OLD */
+
+int
+thai_wordseg (MText *mt, int pos, int *from, int *to,
+             MWordseg_Function *wordseg)
+{
+  MTextProperty *prop;
+
+  /* It is assured that there's a Thai character at POS.  */
+  prop = mtext_get_property (mt, pos, M_thai_wordseg);
+  if (! prop)
+    {
+      /* TIS620 code sequence.  */
+      unsigned char *tis;
+      int len = mtext_nchars (mt);
+      int beg, end;
+      int c, i;
+
+      for (beg = pos; beg > 0; beg--)
+       if ((c = mtext_ref_char (mt, beg - 1)) < THAI_BEG || c > THAI_END)
+         break;
+      for (end = pos + 1; end < len; end++)
+       if ((c = mtext_ref_char (mt, end)) < THAI_BEG || c > THAI_END)
+         break;
+
+      /* Extra 1-byte for 0 terminating.  */
+      tis = alloca ((end - beg) + 1);
+
+      for (i = beg; i < end; i++)
+       tis[i - beg] = 0xA1 + (mtext_ref_char (mt, i) - THAI_BEG);
+      tis[i - beg] = 0;
+      prop = thai_wordseg_propertize (mt, pos, beg, end, tis);
+    }
+
+  if (from)
+    *from = MTEXTPROP_START (prop);
+  if (to)
+    *to = MTEXTPROP_END (prop);
+  return (MTEXTPROP_VAL (prop) == Mt);
+}
+
+#endif /* HAVE_THAI_WORDSEG */
+
+\f
+/* Internal API */
+
+void
+mtext__wseg_fini ()
+{
+  if (wordseg_function_list)
+    {
+      while (wordseg_function_list)
+       {
+         MWordseg_Function *next = wordseg_function_list->next;
+
+         if (wordseg_function_list->initialized > 0
+             && wordseg_function_list->fini)
+           wordseg_function_list->fini ();
+         free (wordseg_function_list);
+         wordseg_function_list = next;
+       }
+      M17N_OBJECT_UNREF (wordseg_function_table);
+    }
+}
+
+/* Find word boundaries around POS of MT.  Set *FROM to the word
+   boundary position at or previous to POS, and update *TO to the word
+   boundary position after POS.
+
+   @return 
+   If word boundaries were found successfully, return 1 (if
+   the character at POS is a part of a word) or 0 (otherwise).  If the
+   operation was not successful, return -1 without setting *FROM and
+   *TO.  */
+
+int
+mtext__word_segment (MText *mt, int pos, int *from, int *to)
+{
+  int c = mtext_ref_char (mt, pos);
+  MWordseg_Function *wordseg;
+
+  if (! wordseg_function_table)
+    {
+      wordseg_function_table = mchartable (Mnil, NULL);
+
+      MSTRUCT_CALLOC (wordseg, MERROR_MTEXT);
+      wordseg->wseg = generic_wordseg;
+      wordseg->next = wordseg_function_list;
+      wordseg_function_list = wordseg;
+      mchartable_set_range (wordseg_function_table, 0, MCHAR_MAX, wordseg);
+
+#ifdef HAVE_THAI_WORDSEG
+      MSTRUCT_CALLOC (wordseg, MERROR_MTEXT);
+      wordseg->init = thai_wordseg_init;
+      wordseg->fini = thai_wordseg_fini;
+      wordseg->wseg = thai_wordseg;
+      wordseg->next = wordseg_function_list;
+      wordseg_function_list = wordseg;
+      mchartable_set_range (wordseg_function_table, THAI_BEG, THAI_END,
+                           wordseg);
+      M_thai_wordseg = msymbol ("  thai-wordseg");
+#endif
+    }
+
+  wordseg = mchartable_lookup (wordseg_function_table, c);
+  if (wordseg && wordseg->initialized >= 0)
+    {
+      if (! wordseg->initialized)
+       {
+         if (wordseg->init
+             && wordseg->init () < 0)
+           {
+             wordseg->initialized = -1;
+             return -1;
+           }
+         wordseg->initialized = 1;
+       }
+      return wordseg->wseg (mt, pos, from, to, wordseg);
+    }
+  return -1;
+}
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
diff --git a/src/mtext.c b/src/mtext.c
new file mode 100644 (file)
index 0000000..64a593c
--- /dev/null
@@ -0,0 +1,3675 @@
+/* mtext.c -- M-text module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nMtext
+    @brief M-text objects and API for them.
+
+    In the m17n library, text is represented as an object called @e
+    M-text rather than as a C-string (<tt>char *</tt> or <tt>unsigned
+    char *</tt>).  An M-text is a sequence of characters whose length
+    is equals to or more than 0, and can be coined from various
+    character sources, e.g. C-strings, files, character codes, etc.
+
+    M-texts are more useful than C-strings in the following points.
+
+    @li M-texts can handle mixture of characters of various scripts,
+    including all Unicode characters and more.  This is an
+    indispensable facility when handling multilingual text.
+
+    @li Each character in an M-text can have properties called @e text
+    @e properties. Text properties store various kinds of information
+    attached to parts of an M-text to provide application programs
+    with a unified view of those information.  As rich information can
+    be stored in M-texts in the form of text properties, functions in
+    application programs can be simple.
+
+    In addition, the library provides many functions to manipulate an
+    M-text just the same way as a C-string.  */
+
+/***ja
+    @addtogroup m17nMtext
+
+    @brief M-text ¥ª¥Ö¥¸¥§¥¯¥È¤È¤½¤ì¤Ë´Ø¤¹¤ë API.
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï¡¢ C-string¡Ê<tt>char *</tt> ¤ä <tt>unsigned
+    char *</tt>¡Ë¤Ç¤Ï¤Ê¤¯ @e M-text ¤È¸Æ¤Ö¥ª¥Ö¥¸¥§¥¯¥È¤Ç¥Æ¥­¥¹¥È¤òɽ¸½¤¹¤ë¡£
+    M-text ¤ÏŤµ 0 °Ê¾å¤Îʸ»úÎó¤Ç¤¢¤ê¡¢¼ï¡¹¤Îʸ»ú¥½¡¼¥¹¡Ê¤¿¤È¤¨¤Ð 
+    C-string¡¢¥Õ¥¡¥¤¥ë¡¢Ê¸»ú¥³¡¼¥ÉÅù¡Ë¤«¤éºîÀ®¤Ç¤­¤ë¡£
+
+    M-text ¤Ë¤Ï¡¢C-string ¤Ë¤Ê¤¤°Ê²¼¤ÎÆÃħ¤¬¤¢¤ë¡£     
+
+    @li M-text ¤ÏÈó¾ï¤Ë¿¤¯¤Î¼ïÎà¤Îʸ»ú¤ò¡¢Æ±»þ¤Ë¡¢º®ºß¤µ¤»¤Æ¡¢Æ±Åù¤Ë°·¤¦¤³¤È¤¬¤Ç¤­¤ë¡£
+    Unicode ¤ÎÁ´¤Æ¤Îʸ»ú¤Ï¤â¤Á¤í¤ó¡¢¤è¤ê¿¤¯¤Îʸ»ú¤Þ¤Ç¤â°·¤¦¤³¤È¤¬¤Ç¤­¤ë¡£
+    ¤³¤ì¤Ï¿¸À¸ì¥Æ¥­¥¹¥È¤ò°·¤¦¾å¤Ç¤Ïɬ¿Ü¤Îµ¡Ç½¤Ç¤¢¤ë¡£
+
+    @li M-text Æâ¤Î³Æʸ»ú¤Ï¡¢@e ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ 
+    ¤È¸Æ¤Ð¤ì¤ë¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Á¡¢
+    ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ë¤è¤Ã¤Æ¡¢¥Æ¥­¥¹¥È¤Î³ÆÉô°Ì¤Ë´Ø¤¹¤ëÍÍ¡¹¤Ê¾ðÊó¤ò
+    M-text Æâ¤ËÊÝ»ý¤¹¤ë¤³¤È¤¬²Äǽ¤Ë¤Ê¤ë¡£
+    ¤½¤Î¤¿¤á¡¢¤½¤ì¤é¤Î¾ðÊó¤ò¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥àÆâ¤ÇÅý°ìŪ¤Ë°·¤¦¤³¤È¤¬²Äǽ¤Ë¤Ê¤ë¡£
+    ¤Þ¤¿¡¢M-text 
+    ¼«ÂΤ¬Ë­É٤ʾðÊó¤ò»ý¤Ä¤¿¤á¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥àÃæ¤Î³Æ´Ø¿ô¤ò´ÊÁDz½¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
+
+    ¤µ¤é¤Ëm17n ¥é¥¤¥Ö¥é¥ê¤Ï¡¢ C-string 
+    ¤òÁàºî¤¹¤ë¤¿¤á¤ËÄ󶡤µ¤ì¤ë¼ï¡¹¤Î´Ø¿ô¤ÈƱÅù¤Î¤â¤Î¤ò M-text 
+    ¤òÁàºî¤¹¤ë¤¿¤á¤Ë¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¡£  */
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
+
+#include "m17n.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "textprop.h"
+#include "character.h"
+#include "mtext.h"
+#include "plist.h"
+
+static M17NObjectArray mtext_table;
+
+static MSymbol M_charbag;
+
+/** Increment character position CHAR_POS and unit position UNIT_POS
+    so that they point to the next character in M-text MT.  No range
+    check for CHAR_POS and UNIT_POS.  */
+
+#define INC_POSITION(mt, char_pos, unit_pos)                   \
+  do {                                                         \
+    int c;                                                     \
+                                                               \
+    if ((mt)->format <= MTEXT_FORMAT_UTF_8)                    \
+      {                                                                \
+       c = (mt)->data[(unit_pos)];                             \
+       (unit_pos) += CHAR_UNITS_BY_HEAD_UTF8 (c);              \
+      }                                                                \
+    else if ((mt)->format <= MTEXT_FORMAT_UTF_16BE)            \
+      {                                                                \
+       c = ((unsigned short *) ((mt)->data))[(unit_pos)];      \
+                                                               \
+       if ((mt)->format != MTEXT_FORMAT_UTF_16)                \
+         c = SWAP_16 (c);                                      \
+       (unit_pos) += CHAR_UNITS_BY_HEAD_UTF16 (c);             \
+      }                                                                \
+    else                                                       \
+      (unit_pos)++;                                            \
+    (char_pos)++;                                              \
+  } while (0)
+
+
+/** Decrement character position CHAR_POS and unit position UNIT_POS
+    so that they point to the previous character in M-text MT.  No
+    range check for CHAR_POS and UNIT_POS.  */
+
+#define DEC_POSITION(mt, char_pos, unit_pos)                           \
+  do {                                                                 \
+    if ((mt)->format <= MTEXT_FORMAT_UTF_8)                            \
+      {                                                                        \
+       unsigned char *p1 = (mt)->data + (unit_pos);                    \
+       unsigned char *p0 = p1 - 1;                                     \
+                                                                       \
+       while (! CHAR_HEAD_P (p0)) p0--;                                \
+       (unit_pos) -= (p1 - p0);                                        \
+      }                                                                        \
+    else if ((mt)->format <= MTEXT_FORMAT_UTF_16BE)                    \
+      {                                                                        \
+       int c = ((unsigned short *) ((mt)->data))[(unit_pos) - 1];      \
+                                                                       \
+       if ((mt)->format != MTEXT_FORMAT_UTF_16)                        \
+         c = SWAP_16 (c);                                              \
+       (unit_pos) -= 2 - (c < 0xD800 || c >= 0xE000);                  \
+      }                                                                        \
+    else                                                               \
+      (unit_pos)--;                                                    \
+    (char_pos)--;                                                      \
+  } while (0)
+
+#define FORMAT_COVERAGE(fmt)                                   \
+  (fmt == MTEXT_FORMAT_UTF_8 ? MTEXT_COVERAGE_FULL             \
+   : fmt == MTEXT_FORMAT_US_ASCII ? MTEXT_COVERAGE_ASCII       \
+   : fmt >= MTEXT_FORMAT_UTF_32LE ? MTEXT_COVERAGE_FULL                \
+   : MTEXT_COVERAGE_UNICODE)
+
+/* Compoare sub-texts in MT1 (range FROM1 and TO1) and MT2 (range
+   FROM2 to TO2). */
+
+static int
+compare (MText *mt1, int from1, int to1, MText *mt2, int from2, int to2)
+{
+  if (mt1->format == mt2->format
+      && (mt1->format <= MTEXT_FORMAT_UTF_8))
+    {
+      unsigned char *p1, *pend1, *p2, *pend2;
+      int unit_bytes = UNIT_BYTES (mt1->format);
+      int nbytes;
+      int result;
+
+      p1 = mt1->data + mtext__char_to_byte (mt1, from1) * unit_bytes;
+      pend1 = mt1->data + mtext__char_to_byte (mt1, to1) * unit_bytes;
+
+      p2 = mt2->data + mtext__char_to_byte (mt2, from2) * unit_bytes;
+      pend2 = mt2->data + mtext__char_to_byte (mt2, to2) * unit_bytes;
+
+      if (pend1 - p1 < pend2 - p2)
+       nbytes = pend1 - p1;
+      else
+       nbytes = pend2 - p2;
+      result = memcmp (p1, p2, nbytes);
+      if (result)
+       return result;
+      return ((pend1 - p1) - (pend2 - p2));
+    }
+  for (; from1 < to1 && from2 < to2; from1++, from2++)
+    {
+      int c1 = mtext_ref_char (mt1, from1);
+      int c2 = mtext_ref_char (mt2, from2);
+
+      if (c1 != c2)
+       return (c1 > c2 ? 1 : -1);
+    }
+  return (from2 == to2 ? (from1 < to1) : -1);
+}
+
+
+/* Return how many units are required in UTF-8 to represent characters
+   between FROM and TO of MT.  */
+
+static int
+count_by_utf_8 (MText *mt, int from, int to)
+{
+  int n, c;
+
+  for (n = 0; from < to; from++)
+    {
+      c = mtext_ref_char (mt, from);
+      n += CHAR_UNITS_UTF8 (c);
+    }
+  return n;
+}
+
+
+/* Return how many units are required in UTF-16 to represent
+   characters between FROM and TO of MT.  */
+
+static int
+count_by_utf_16 (MText *mt, int from, int to)
+{
+  int n, c;
+
+  for (n = 0; from < to; from++)
+    {
+      c = mtext_ref_char (mt, from);
+      n += CHAR_UNITS_UTF16 (c);
+    }
+  return n;
+}
+
+
+/* Insert text between FROM and TO of MT2 at POS of MT1.  */
+
+static MText *
+insert (MText *mt1, int pos, MText *mt2, int from, int to)
+{
+  int pos_unit = POS_CHAR_TO_BYTE (mt1, pos);
+  int from_unit = POS_CHAR_TO_BYTE (mt2, from);
+  int new_units = POS_CHAR_TO_BYTE (mt2, to) - from_unit;
+  int unit_bytes;
+
+  if (mt1->nchars == 0)
+    mt1->format = mt2->format, mt1->coverage = mt2->coverage;
+  else if (mt1->format != mt2->format)
+    {
+      /* Be sure to make mt1->format sufficient to contain all
+        characters in mt2.  */
+      if (mt1->format == MTEXT_FORMAT_UTF_8
+         || mt1->format == MTEXT_FORMAT_UTF_32
+         || (mt1->format == MTEXT_FORMAT_UTF_16
+             && mt2->format <= MTEXT_FORMAT_UTF_16BE
+             && mt2->format != MTEXT_FORMAT_UTF_8))
+       ;
+      else if (mt1->format == MTEXT_FORMAT_US_ASCII)
+       {
+         if (mt2->format == MTEXT_FORMAT_UTF_8)
+           mt1->format = MTEXT_FORMAT_UTF_8, mt1->coverage = mt2->coverage;
+         else if (mt2->format == MTEXT_FORMAT_UTF_16
+                  || mt2->format == MTEXT_FORMAT_UTF_32)
+           mtext__adjust_format (mt1, mt2->format);
+         else
+           mtext__adjust_format (mt1, MTEXT_FORMAT_UTF_8);
+       }
+      else
+       {
+         mtext__adjust_format (mt1, MTEXT_FORMAT_UTF_8);
+         pos_unit = POS_CHAR_TO_BYTE (mt1, pos);
+       }
+    }
+
+  unit_bytes = UNIT_BYTES (mt1->format);
+
+  if (mt1->format == mt2->format)
+    {
+      int pos_byte = pos_unit * unit_bytes;
+      int total_bytes = (mt1->nbytes + new_units) * unit_bytes;
+      int new_bytes = new_units * unit_bytes;
+
+      if (total_bytes + unit_bytes > mt1->allocated)
+       {
+         mt1->allocated = total_bytes + unit_bytes;
+         MTABLE_REALLOC (mt1->data, mt1->allocated, MERROR_MTEXT);
+       }
+      if (pos < mt1->nchars)
+       memmove (mt1->data + pos_byte + new_bytes, mt1->data + pos_byte,
+                (mt1->nbytes - pos_unit + 1) * unit_bytes);
+      memcpy (mt1->data + pos_byte, mt2->data + from_unit * unit_bytes,
+             new_bytes);
+    }
+  else if (mt1->format == MTEXT_FORMAT_UTF_8)
+    {
+      unsigned char *p;
+      int total_bytes, i, c;
+
+      new_units = count_by_utf_8 (mt2, from, to);
+      total_bytes = mt1->nbytes + new_units;
+
+      if (total_bytes + 1 > mt1->allocated)
+       {
+         mt1->allocated = total_bytes + 1;
+         MTABLE_REALLOC (mt1->data, mt1->allocated, MERROR_MTEXT);
+       }
+      p = mt1->data + pos_unit;
+      memmove (p + new_units, p, mt1->nbytes - pos_unit + 1);
+      for (i = from; i < to; i++)
+       {
+         c = mtext_ref_char (mt2, i);
+         p += CHAR_STRING_UTF8 (c, p);
+       }
+    }
+  else if (mt1->format == MTEXT_FORMAT_UTF_16)
+    {
+      unsigned short *p;
+      int total_bytes, i, c;
+
+      new_units = count_by_utf_16 (mt2, from, to);
+      total_bytes = (mt1->nbytes + new_units) * USHORT_SIZE;
+
+      if (total_bytes + USHORT_SIZE > mt1->allocated)
+       {
+         mt1->allocated = total_bytes + USHORT_SIZE;
+         MTABLE_REALLOC (mt1->data, mt1->allocated, MERROR_MTEXT);
+       }
+      p = (unsigned short *) mt1->data + pos_unit;
+      memmove (p + new_units, p,
+              (mt1->nbytes - pos_unit + 1) * USHORT_SIZE);
+      for (i = from; i < to; i++)
+       {
+         c = mtext_ref_char (mt2, i);
+         p += CHAR_STRING_UTF16 (c, p);
+       }
+    }
+  else                         /* MTEXT_FORMAT_UTF_32 */
+    {
+      unsigned int *p;
+      int total_bytes, i;
+
+      new_units = to - from;
+      total_bytes = (mt1->nbytes + new_units) * UINT_SIZE;
+
+      if (total_bytes + UINT_SIZE > mt1->allocated)
+       {
+         mt1->allocated = total_bytes + UINT_SIZE;
+         MTABLE_REALLOC (mt1->data, mt1->allocated, MERROR_MTEXT);
+       }
+      p = (unsigned *) mt1->data + pos_unit;
+      memmove (p + new_units, p,
+              (mt1->nbytes - pos_unit + 1) * UINT_SIZE);
+      for (i = from; i < to; i++)
+       *p++ = mtext_ref_char (mt2, i);
+    }
+
+  mtext__adjust_plist_for_insert
+    (mt1, pos, to - from,
+     mtext__copy_plist (mt2->plist, from, to, mt1, pos));
+  mt1->nchars += to - from;
+  mt1->nbytes += new_units;
+  if (mt1->cache_char_pos > pos)
+    {
+      mt1->cache_char_pos += to - from;
+      mt1->cache_byte_pos += new_units;
+    }
+
+  return mt1;
+}
+
+
+static MCharTable *
+get_charbag (MText *mt)
+{
+  MTextProperty *prop = mtext_get_property (mt, 0, M_charbag);
+  MCharTable *table;
+  int i;
+
+  if (prop)
+    {
+      if (prop->end == mt->nchars)
+       return ((MCharTable *) prop->val);
+      mtext_detach_property (prop);
+    }
+
+  table = mchartable (Msymbol, (void *) 0);
+  for (i = mt->nchars - 1; i >= 0; i--)
+    mchartable_set (table, mtext_ref_char (mt, i), Mt);
+  prop = mtext_property (M_charbag, table, MTEXTPROP_VOLATILE_WEAK);
+  mtext_attach_property (mt, 0, mtext_nchars (mt), prop);
+  M17N_OBJECT_UNREF (prop);
+  return table;
+}
+
+
+/* span () : Number of consecutive chars starting at POS in MT1 that
+   are included (if NOT is Mnil) or not included (if NOT is Mt) in
+   MT2.  */
+
+static int
+span (MText *mt1, MText *mt2, int pos, MSymbol not)
+{
+  int nchars = mtext_nchars (mt1);
+  MCharTable *table = get_charbag (mt2);
+  int i;
+
+  for (i = pos; i < nchars; i++)
+    if ((MSymbol) mchartable_lookup (table, mtext_ref_char (mt1, i)) == not)
+      break;
+  return (i - pos);
+}
+
+
+static int
+count_utf_8_chars (const void *data, int nitems)
+{
+  unsigned char *p = (unsigned char *) data;
+  unsigned char *pend = p + nitems;
+  int nchars = 0;
+
+  while (p < pend)
+    {
+      int i, n;
+
+      for (; p < pend && *p < 128; nchars++, p++);
+      if (p == pend)
+       return nchars;
+      if (! CHAR_HEAD_P_UTF8 (p))
+       return -1;
+      n = CHAR_UNITS_BY_HEAD_UTF8 (*p);
+      if (p + n > pend)
+       return -1;
+      for (i = 1; i < n; i++)
+       if (CHAR_HEAD_P_UTF8 (p + i))
+         return -1;
+      p += n;
+      nchars++;
+    }
+  return nchars;
+}
+
+static int
+count_utf_16_chars (const void *data, int nitems, int swap)
+{
+  unsigned short *p = (unsigned short *) data;
+  unsigned short *pend = p + nitems;
+  int nchars = 0;
+  int prev_surrogate = 0;
+
+  for (; p < pend; p++)
+    {
+      int c = *p;
+
+      if (swap)
+       c = SWAP_16 (c);
+      if (prev_surrogate)
+       {
+         if (c < 0xDC00 || c >= 0xE000)
+           /* Invalid surrogate */
+           nchars++;
+       }
+      else
+       {
+         if (c >= 0xD800 && c < 0xDC00)
+           prev_surrogate = 1;
+         nchars++;
+       }
+    }
+  if (prev_surrogate)
+    nchars++;
+  return nchars;
+}
+
+
+static int
+find_char_forward (MText *mt, int from, int to, int c)
+{
+  int from_byte = POS_CHAR_TO_BYTE (mt, from);
+
+  if (mt->format <= MTEXT_FORMAT_UTF_8)
+    {
+      unsigned char *p = mt->data + from_byte;
+
+      while (from < to && STRING_CHAR_ADVANCE_UTF8 (p) != c) from++;
+    }
+  else if (mt->format <= MTEXT_FORMAT_UTF_16BE)
+    {
+      unsigned short *p = (unsigned short *) (mt->data) + from_byte;
+
+      if (mt->format == MTEXT_FORMAT_UTF_16)
+       while (from < to && STRING_CHAR_ADVANCE_UTF16 (p) != c) from++;
+      else if (c < 0x10000)
+       {
+         c = SWAP_16 (c);
+         while (from < to && *p != c)
+           {
+             from++;
+             p += ((*p & 0xFF) < 0xD8 || (*p & 0xFF) >= 0xE0) ? 1 : 2;
+           }
+       }
+      else if (c < 0x110000)
+       {
+         int c1 = (c >> 10) + 0xD800;
+         int c2 = (c & 0x3FF) + 0xDC00;
+
+         c1 = SWAP_16 (c1);
+         c2 = SWAP_16 (c2);
+         while (from < to && (*p != c1 || p[1] != c2))
+           {
+             from++;
+             p += ((*p & 0xFF) < 0xD8 || (*p & 0xFF) >= 0xE0) ? 1 : 2;
+           }
+       }
+      else
+       from = to;
+    }
+  else
+    {
+      unsigned *p = (unsigned *) (mt->data) + from_byte;
+      unsigned c1 = c;
+
+      if (mt->format != MTEXT_FORMAT_UTF_32)
+       c1 = SWAP_32 (c1);
+      while (from < to && *p++ != c1) from++;
+    }
+
+  return (from < to ? from : -1);
+}
+
+
+static int
+find_char_backward (MText *mt, int from, int to, int c)
+{
+  int to_byte = POS_CHAR_TO_BYTE (mt, to);
+
+  if (mt->format <= MTEXT_FORMAT_UTF_8)
+    {
+      unsigned char *p = mt->data + to_byte;
+
+      while (from < to)
+       {
+         for (p--; ! CHAR_HEAD_P (p); p--);
+         if (c == STRING_CHAR (p))
+           break;
+         to--;
+       }
+    }
+  else if (mt->format <= MTEXT_FORMAT_UTF_16LE)
+    {
+      unsigned short *p = (unsigned short *) (mt->data) + to_byte;
+
+      if (mt->format == MTEXT_FORMAT_UTF_16)
+       {
+         while (from < to)
+           {
+             p--;
+             if (*p >= 0xDC00 && *p < 0xE000)
+               p--;
+             if (c == STRING_CHAR_UTF16 (p))
+               break;
+             to--;
+           }
+       }
+      else if (c < 0x10000)
+       {
+         c = SWAP_16 (c);
+         while (from < to && p[-1] != c)
+           {
+             to--;
+             p -= ((p[-1] & 0xFF) < 0xD8 || (p[-1] & 0xFF) >= 0xE0) ? 1 : 2;
+           }
+       }
+      else if (c < 0x110000)
+       {
+         int c1 = (c >> 10) + 0xD800;
+         int c2 = (c & 0x3FF) + 0xDC00;
+
+         c1 = SWAP_16 (c1);
+         c2 = SWAP_16 (c2);
+         while (from < to && (p[-1] != c2 || p[-2] != c1))
+           {
+             to--;
+             p -= ((p[-1] & 0xFF) < 0xD8 || (p[-1] & 0xFF) >= 0xE0) ? 1 : 2;
+           }
+       }
+    }
+  else
+    {
+      unsigned *p = (unsigned *) (mt->data) + to_byte;
+      unsigned c1 = c;
+
+      if (mt->format != MTEXT_FORMAT_UTF_32)
+       c1 = SWAP_32 (c1);
+      while (from < to && p[-1] != c1) to--, p--;
+    }
+
+  return (from < to ? to - 1 : -1);
+}
+
+
+static void
+free_mtext (void *object)
+{
+  MText *mt = (MText *) object;
+
+  if (mt->plist)
+    mtext__free_plist (mt);
+  if (mt->data && mt->allocated >= 0)
+    free (mt->data);
+  M17N_OBJECT_UNREGISTER (mtext_table, mt);
+  free (object);
+}
+
+/** Case handler (case-folding comparison and case conversion) */
+
+/** Structure for an iterator used in case-fold comparison.  */
+
+struct casecmp_iterator {
+  MText *mt;
+  int pos;
+  MText *folded;
+  unsigned char *foldedp;
+  int folded_len;
+};
+
+static int
+next_char_from_it (struct casecmp_iterator *it)
+{
+  int c, c1;
+
+  if (it->folded)
+    {
+      c = STRING_CHAR_AND_BYTES (it->foldedp, it->folded_len);
+      return c;
+    }
+
+  c = mtext_ref_char (it->mt, it->pos);
+  c1 = (int) mchar_get_prop (c, Msimple_case_folding);
+  if (c1 == 0xFFFF)
+    {
+      it->folded
+       = (MText *) mchar_get_prop (c, Mcomplicated_case_folding);
+      it->foldedp = it->folded->data;
+      c = STRING_CHAR_AND_BYTES (it->foldedp, it->folded_len);
+      return c;
+    }
+
+  if (c1 >= 0)
+    c = c1;
+  return c;
+}
+
+static void
+advance_it (struct casecmp_iterator *it)
+{
+  if (it->folded)
+    {
+      it->foldedp += it->folded_len;
+      if (it->foldedp == it->folded->data + it->folded->nbytes)
+       it->folded = NULL;
+    }
+  if (! it->folded)
+    {
+      it->pos++;
+    }
+}
+
+static int
+case_compare (MText *mt1, int from1, int to1, MText *mt2, int from2, int to2)
+{
+  struct casecmp_iterator it1, it2;
+
+  it1.mt = mt1, it1.pos = from1, it1.folded = NULL;
+  it2.mt = mt2, it2.pos = from2, it2.folded = NULL;
+
+  while (it1.pos < to1 && it2.pos < to2)
+    {
+      int c1 = next_char_from_it (&it1);
+      int c2 = next_char_from_it (&it2);
+
+      if (c1 != c2)
+       return (c1 > c2 ? 1 : -1);
+      advance_it (&it1);
+      advance_it (&it2);
+    }
+  return (it2.pos == to2 ? (it1.pos < to1) : -1);
+}
+
+static MCharTable *tricky_chars, *cased, *soft_dotted, *case_mapping;
+static MCharTable *combining_class;
+
+/* Languages that require special handling in case-conversion.  */
+static MSymbol Mlt, Mtr, Maz;
+
+static MText *gr03A3;
+static MText *lt0049, *lt004A, *lt012E, *lt00CC, *lt00CD, *lt0128;
+static MText *tr0130, *tr0049, *tr0069;
+
+static int
+init_case_conversion ()
+{
+  Mlt = msymbol ("lt");
+  Mtr = msymbol ("tr");
+  Maz = msymbol ("az");
+
+  gr03A3 = mtext ();
+  mtext_cat_char (gr03A3, 0x03C2);
+
+  lt0049 = mtext ();
+  mtext_cat_char (lt0049, 0x0069);
+  mtext_cat_char (lt0049, 0x0307);
+
+  lt004A = mtext ();
+  mtext_cat_char (lt004A, 0x006A);
+  mtext_cat_char (lt004A, 0x0307);
+
+  lt012E = mtext ();
+  mtext_cat_char (lt012E, 0x012F);
+  mtext_cat_char (lt012E, 0x0307);
+
+  lt00CC = mtext ();
+  mtext_cat_char (lt00CC, 0x0069);
+  mtext_cat_char (lt00CC, 0x0307);
+  mtext_cat_char (lt00CC, 0x0300);
+
+  lt00CD = mtext ();
+  mtext_cat_char (lt00CD, 0x0069);
+  mtext_cat_char (lt00CD, 0x0307);
+  mtext_cat_char (lt00CD, 0x0301);
+
+  lt0128 = mtext ();
+  mtext_cat_char (lt0128, 0x0069);
+  mtext_cat_char (lt0128, 0x0307);
+  mtext_cat_char (lt0128, 0x0303);
+
+  tr0130 = mtext ();
+  mtext_cat_char (tr0130, 0x0069);
+
+  tr0049 = mtext ();
+  mtext_cat_char (tr0049, 0x0131);
+
+  tr0069 = mtext ();
+  mtext_cat_char (tr0069, 0x0130);
+
+  if (! (cased = mchar_get_prop_table (msymbol ("cased"), NULL)))
+    return -1;
+  if (! (soft_dotted = mchar_get_prop_table (msymbol ("soft-dotted"), NULL)))
+    return -1;
+  if (! (case_mapping = mchar_get_prop_table (msymbol ("case-mapping"), NULL)))
+    return -1;
+  if (! (combining_class = mchar_get_prop_table (Mcombining_class, NULL)))
+    return -1;
+
+  tricky_chars = mchartable (Mnil, 0);
+  mchartable_set (tricky_chars, 0x0049, (void *) 1);
+  mchartable_set (tricky_chars, 0x004A, (void *) 1);
+  mchartable_set (tricky_chars, 0x00CC, (void *) 1);
+  mchartable_set (tricky_chars, 0x00CD, (void *) 1);
+  mchartable_set (tricky_chars, 0x0128, (void *) 1);
+  mchartable_set (tricky_chars, 0x012E, (void *) 1);
+  mchartable_set (tricky_chars, 0x0130, (void *) 1);
+  mchartable_set (tricky_chars, 0x0307, (void *) 1);
+  mchartable_set (tricky_chars, 0x03A3, (void *) 1);
+  return 0;
+}
+
+#define CASE_CONV_INIT(ret)            \
+  do {                                 \
+    if (! tricky_chars                 \
+       && init_case_conversion () < 0) \
+      MERROR (MERROR_MTEXT, ret);      \
+  } while (0)
+
+/* Replace the character at POS of MT with VAR and increment I and LEN.  */
+
+#define REPLACE(var)                                   \
+  do {                                                 \
+    int varlen = var->nchars;                          \
+                                                       \
+    mtext_replace (mt, pos, pos + 1, var, 0, varlen);  \
+    pos += varlen;                                     \
+    end += varlen - 1;                                 \
+  } while (0)
+
+/* Delete the character at POS of MT and decrement LEN.  */
+
+#define DELETE                         \
+  do {                                 \
+    mtext_del (mt, pos, pos + 1);      \
+    end--;                             \
+  } while (0)
+
+#define LOOKUP                                                         \
+  do {                                                                 \
+    MPlist *pl = (MPlist *) mchartable_lookup (case_mapping, c);       \
+                                                                       \
+    if (pl)                                                            \
+      {                                                                        \
+       /* Lowercase is the 1st element. */                             \
+       MText *lower = MPLIST_VAL ((MPlist *) MPLIST_VAL (pl));         \
+       int llen = mtext_nchars (lower);                                \
+                                                                       \
+       if (mtext_ref_char (lower, 0) != c || llen > 1)                 \
+         {                                                             \
+           mtext_replace (mt, pos, pos + 1, lower, 0, llen);           \
+           pos += llen;                                                \
+           end += llen - 1;                                            \
+         }                                                             \
+       else                                                            \
+         pos++;                                                        \
+      }                                                                        \
+    else                                                               \
+      pos++;                                                           \
+  } while (0)
+
+
+int
+uppercase_precheck (MText *mt, int pos, int end)
+{
+  for (; pos < end; pos++)
+    if (mtext_ref_char (mt, pos) == 0x0307 &&
+       (MSymbol) mtext_get_prop (mt, pos, Mlanguage) == Mlt)
+      return 1;
+  return 0;
+}
+
+int
+lowercase_precheck (MText *mt, int pos, int end)
+{
+  int c;
+  MSymbol lang;
+
+  for (; pos < end; pos++)
+    {
+      c = mtext_ref_char (mt, pos);
+
+      if ((int) mchartable_lookup (tricky_chars, c) == 1)
+      {
+       if (c == 0x03A3)
+         return 1;
+
+       lang = mtext_get_prop (mt, pos, Mlanguage);
+
+       if (lang == Mlt &&
+           (c == 0x0049 || c == 0x004A || c == 0x012E))
+         return 1;
+
+       if ((lang == Mtr || lang == Maz) &&
+           (c == 0x0307 || c == 0x0049))
+         return 1;
+      }
+    }
+  return 0;
+}
+
+#define CASED 1
+#define CASE_IGNORABLE 2
+
+int
+final_sigma (MText *mt, int pos)
+{
+  int i, len = mtext_len (mt);
+  int c;
+
+  for (i = pos - 1; i >= 0; i--)
+    {
+      c = (int) mchartable_lookup (cased, mtext_ref_char (mt, i));
+      if (c == -1)
+       c = 0;
+      if (c & CASED)
+       break;
+      if (! (c & CASE_IGNORABLE))
+       return 0;
+    }
+
+  if (i == -1)
+    return 0;
+
+  for (i = pos + 1; i < len; i++)
+    {
+      c = (int) mchartable_lookup (cased, mtext_ref_char (mt, i));
+      if (c == -1)
+       c = 0;
+      if (c & CASED)
+       return 0;
+      if (! (c & CASE_IGNORABLE))
+       return 1;
+    }
+
+  return 1;
+}
+
+int
+after_soft_dotted (MText *mt, int i)
+{
+  int c, class;
+
+  for (i--; i >= 0; i--)
+    {
+      c = mtext_ref_char (mt, i);
+      if ((MSymbol) mchartable_lookup (soft_dotted, c) == Mt)
+       return 1;
+      class = (int) mchartable_lookup (combining_class, c);
+      if (class == 0 || class == 230)
+       return 0;
+    }
+
+  return 0;
+}
+
+int
+more_above (MText *mt, int i)
+{
+  int class, len = mtext_len (mt);
+
+  for (i++; i < len; i++)
+    {
+      class = (int) mchartable_lookup (combining_class,
+                                      mtext_ref_char (mt, i));
+      if (class == 230)
+       return 1;
+      if (class == 0)
+       return 0;
+    }
+
+  return 0;
+}
+
+int
+before_dot (MText *mt, int i)
+{
+  int c, class, len = mtext_len (mt);
+
+  for (i++; i < len; i++)
+    {
+      c = mtext_ref_char (mt, i);
+      if (c == 0x0307)
+       return 1;
+      class = (int) mchartable_lookup (combining_class, c);
+      if (class == 230 || class == 0)
+       return 0;
+    }
+
+  return 0;
+}
+
+int
+after_i (MText *mt, int i)
+{
+  int c, class;
+
+  for (i--; i >= 0; i--)
+    {
+      c = mtext_ref_char (mt, i);
+      if (c == (int) 'I')
+       return 1;
+      class = (int) mchartable_lookup (combining_class, c);
+      if (class == 230 || class == 0)
+       return 0;
+    }
+
+  return 0;
+}
+
+\f
+/* Internal API */
+
+int
+mtext__init ()
+{
+  M17N_OBJECT_ADD_ARRAY (mtext_table, "M-text");
+  M_charbag = msymbol_as_managing_key ("  charbag");
+  mtext_table.count = 0;
+  Mlanguage = msymbol ("language");
+  return 0;
+}
+
+
+void
+mtext__fini (void)
+{
+  mtext__wseg_fini ();
+}
+
+
+int
+mtext__char_to_byte (MText *mt, int pos)
+{
+  int char_pos, byte_pos;
+  int forward;
+
+  if (pos < mt->cache_char_pos)
+    {
+      if (mt->cache_char_pos == mt->cache_byte_pos)
+       return pos;
+      if (pos < mt->cache_char_pos - pos)
+       {
+         char_pos = byte_pos = 0;
+         forward = 1;
+       }
+      else
+       {
+         char_pos = mt->cache_char_pos;
+         byte_pos = mt->cache_byte_pos;
+         forward = 0;
+       }
+    }
+  else
+    {
+      if (mt->nchars - mt->cache_char_pos == mt->nbytes - mt->cache_byte_pos)
+       return (mt->cache_byte_pos + (pos - mt->cache_char_pos));
+      if (pos - mt->cache_char_pos < mt->nchars - pos)
+       {
+         char_pos = mt->cache_char_pos;
+         byte_pos = mt->cache_byte_pos;
+         forward = 1;
+       }
+      else
+       {
+         char_pos = mt->nchars;
+         byte_pos = mt->nbytes;
+         forward = 0;
+       }
+    }
+  if (forward)
+    while (char_pos < pos)
+      INC_POSITION (mt, char_pos, byte_pos);
+  else
+    while (char_pos > pos)
+      DEC_POSITION (mt, char_pos, byte_pos);
+  mt->cache_char_pos = char_pos;
+  mt->cache_byte_pos = byte_pos;
+  return byte_pos;
+}
+
+/* mtext__byte_to_char () */
+
+int
+mtext__byte_to_char (MText *mt, int pos_byte)
+{
+  int char_pos, byte_pos;
+  int forward;
+
+  if (pos_byte < mt->cache_byte_pos)
+    {
+      if (mt->cache_char_pos == mt->cache_byte_pos)
+       return pos_byte;
+      if (pos_byte < mt->cache_byte_pos - pos_byte)
+       {
+         char_pos = byte_pos = 0;
+         forward = 1;
+       }
+      else
+       {
+         char_pos = mt->cache_char_pos;
+         byte_pos = mt->cache_byte_pos;
+         forward = 0;
+       }
+    }
+  else
+    {
+      if (mt->nchars - mt->cache_char_pos == mt->nbytes - mt->cache_byte_pos)
+       return (mt->cache_char_pos + (pos_byte - mt->cache_byte_pos));
+      if (pos_byte - mt->cache_byte_pos < mt->nbytes - pos_byte)
+       {
+         char_pos = mt->cache_char_pos;
+         byte_pos = mt->cache_byte_pos;
+         forward = 1;
+       }
+      else
+       {
+         char_pos = mt->nchars;
+         byte_pos = mt->nbytes;
+         forward = 0;
+       }
+    }
+  if (forward)
+    while (byte_pos < pos_byte)
+      INC_POSITION (mt, char_pos, byte_pos);
+  else
+    while (byte_pos > pos_byte)
+      DEC_POSITION (mt, char_pos, byte_pos);
+  mt->cache_char_pos = char_pos;
+  mt->cache_byte_pos = byte_pos;
+  return char_pos;
+}
+
+/* Estimated extra bytes that malloc will use for its own purpose on
+   each memory allocation.  */
+#define MALLOC_OVERHEAD 4
+#define MALLOC_MININUM_BYTES 12
+
+void
+mtext__enlarge (MText *mt, int nbytes)
+{
+  nbytes += MAX_UTF8_CHAR_BYTES;
+  if (mt->allocated >= nbytes)
+    return;
+  if (nbytes < MALLOC_MININUM_BYTES)
+    nbytes = MALLOC_MININUM_BYTES;
+  while (mt->allocated < nbytes)
+    mt->allocated = mt->allocated * 2 + MALLOC_OVERHEAD;
+  MTABLE_REALLOC (mt->data, mt->allocated, MERROR_MTEXT);
+}
+
+int
+mtext__takein (MText *mt, int nchars, int nbytes)
+{
+  if (mt->plist)
+    mtext__adjust_plist_for_insert (mt, mt->nchars, nchars, NULL);
+  mt->nchars += nchars;
+  mt->nbytes += nbytes;
+  mt->data[mt->nbytes] = 0;
+  return 0;
+}
+
+
+int
+mtext__cat_data (MText *mt, unsigned char *p, int nbytes,
+                enum MTextFormat format)
+{
+  int nchars = -1;
+
+  if (mt->format > MTEXT_FORMAT_UTF_8)
+    MERROR (MERROR_MTEXT, -1);
+  if (format == MTEXT_FORMAT_US_ASCII)
+    nchars = nbytes;
+  else if (format == MTEXT_FORMAT_UTF_8)
+    nchars = count_utf_8_chars (p, nbytes);
+  if (nchars < 0)
+    MERROR (MERROR_MTEXT, -1);
+  mtext__enlarge (mt, mtext_nbytes (mt) + nbytes + 1);
+  memcpy (MTEXT_DATA (mt) + mtext_nbytes (mt), p, nbytes);
+  mtext__takein (mt, nchars, nbytes);
+  return nchars;
+}
+
+MText *
+mtext__from_data (const void *data, int nitems, enum MTextFormat format,
+                 int need_copy)
+{
+  MText *mt;
+  int nchars, nbytes, unit_bytes;
+
+  if (format == MTEXT_FORMAT_US_ASCII)
+    {
+      const char *p = (char *) data, *pend = p + nitems;
+
+      while (p < pend)
+       if (*p++ < 0)
+         MERROR (MERROR_MTEXT, NULL);
+      nchars = nbytes = nitems;
+      unit_bytes = 1;
+    }
+  else if (format == MTEXT_FORMAT_UTF_8)
+    {
+      if ((nchars = count_utf_8_chars (data, nitems)) < 0)
+       MERROR (MERROR_MTEXT, NULL);
+      nbytes = nitems;
+      unit_bytes = 1;
+    }
+  else if (format <= MTEXT_FORMAT_UTF_16BE)
+    {
+      if ((nchars = count_utf_16_chars (data, nitems,
+                                       format != MTEXT_FORMAT_UTF_16)) < 0)
+       MERROR (MERROR_MTEXT, NULL);
+      nbytes = USHORT_SIZE * nitems;
+      unit_bytes = USHORT_SIZE;
+    }
+  else                         /* MTEXT_FORMAT_UTF_32XX */
+    {
+      nchars = nitems;
+      nbytes = UINT_SIZE * nitems;
+      unit_bytes = UINT_SIZE;
+    }
+
+  mt = mtext ();
+  mt->format = format;
+  mt->coverage = FORMAT_COVERAGE (format);
+  mt->allocated = need_copy ? nbytes + unit_bytes : -1;
+  mt->nchars = nchars;
+  mt->nbytes = nitems;
+  if (need_copy)
+    {
+      MTABLE_MALLOC (mt->data, mt->allocated, MERROR_MTEXT);
+      memcpy (mt->data, data, nbytes);
+      mt->data[nbytes] = 0;
+    }
+  else
+    mt->data = (unsigned char *) data;
+  return mt;
+}
+
+
+void
+mtext__adjust_format (MText *mt, enum MTextFormat format)
+{
+  int i, c;
+
+  if (mt->nchars > 0)
+    switch (format)
+      {
+      case MTEXT_FORMAT_US_ASCII:
+       {
+         unsigned char *p = mt->data;
+
+         for (i = 0; i < mt->nchars; i++)
+           *p++ = mtext_ref_char (mt, i);
+         mt->nbytes = mt->nchars;
+         mt->cache_byte_pos = mt->cache_char_pos;
+         break;
+       }
+
+      case MTEXT_FORMAT_UTF_8:
+       {
+         unsigned char *p0, *p1;
+
+         i = count_by_utf_8 (mt, 0, mt->nchars) + 1;
+         MTABLE_MALLOC (p0, i, MERROR_MTEXT);
+         mt->allocated = i;
+         for (i = 0, p1 = p0; i < mt->nchars; i++)
+           {
+             c = mtext_ref_char (mt, i);
+             p1 += CHAR_STRING_UTF8 (c, p1);
+           }
+         *p1 = '\0';
+         free (mt->data);
+         mt->data = p0;
+         mt->nbytes = p1 - p0;
+         mt->cache_char_pos = mt->cache_byte_pos = 0;
+         break;
+       }
+
+      default:
+       if (format == MTEXT_FORMAT_UTF_16)
+         {
+           unsigned short *p0, *p1;
+
+           i = (count_by_utf_16 (mt, 0, mt->nchars) + 1) * USHORT_SIZE;
+           MTABLE_MALLOC (p0, i, MERROR_MTEXT);
+           mt->allocated = i;
+           for (i = 0, p1 = p0; i < mt->nchars; i++)
+             {
+               c = mtext_ref_char (mt, i);
+               p1 += CHAR_STRING_UTF16 (c, p1);
+             }
+           *p1 = 0;
+           free (mt->data);
+           mt->data = (unsigned char *) p0;
+           mt->nbytes = p1 - p0;
+           mt->cache_char_pos = mt->cache_byte_pos = 0;
+           break;
+         }
+       else
+         {
+           unsigned int *p;
+
+           mt->allocated = (mt->nchars + 1) * UINT_SIZE;
+           MTABLE_MALLOC (p, mt->allocated, MERROR_MTEXT);
+           for (i = 0; i < mt->nchars; i++)
+             p[i] = mtext_ref_char (mt, i);
+           p[i] = 0;
+           free (mt->data);
+           mt->data = (unsigned char *) p;
+           mt->nbytes = mt->nchars;
+           mt->cache_byte_pos = mt->cache_char_pos;
+         }
+      }
+  mt->format = format;
+  mt->coverage = FORMAT_COVERAGE (format);
+}
+
+
+/* Find the position of a character at the beginning of a line of
+   M-Text MT searching backward from POS.  */
+
+int
+mtext__bol (MText *mt, int pos)
+{
+  int byte_pos;
+
+  if (pos == 0)
+    return pos;
+  byte_pos = POS_CHAR_TO_BYTE (mt, pos);
+  if (mt->format <= MTEXT_FORMAT_UTF_8)
+    {
+      unsigned char *p = mt->data + byte_pos;
+
+      if (p[-1] == '\n')
+       return pos;
+      p--;
+      while (p > mt->data && p[-1] != '\n')
+       p--;
+      if (p == mt->data)
+       return 0;
+      byte_pos = p - mt->data;
+      return POS_BYTE_TO_CHAR (mt, byte_pos);
+    }
+  else if (mt->format <= MTEXT_FORMAT_UTF_16BE)
+    {
+      unsigned short *p = ((unsigned short *) (mt->data)) + byte_pos;
+      unsigned short newline = (mt->format == MTEXT_FORMAT_UTF_16
+                               ? 0x0A00 : 0x000A);
+
+      if (p[-1] == newline)
+       return pos;
+      p--;
+      while (p > (unsigned short *) (mt->data) && p[-1] != newline)
+       p--;
+      if (p == (unsigned short *) (mt->data))
+       return 0;
+      byte_pos = p - (unsigned short *) (mt->data);
+      return POS_BYTE_TO_CHAR (mt, byte_pos);;
+    }
+  else
+    {
+      unsigned *p = ((unsigned *) (mt->data)) + byte_pos;
+      unsigned newline = (mt->format == MTEXT_FORMAT_UTF_32
+                         ? 0x0A000000 : 0x0000000A);
+
+      if (p[-1] == newline)
+       return pos;
+      p--, pos--;
+      while (p > (unsigned *) (mt->data) && p[-1] != newline)
+       p--, pos--;
+      return pos;
+    }
+}
+
+
+/* Find the position of a character at the end of a line of M-Text MT
+   searching forward from POS.  */
+
+int
+mtext__eol (MText *mt, int pos)
+{
+  int byte_pos;
+
+  if (pos == mt->nchars)
+    return pos;
+  byte_pos = POS_CHAR_TO_BYTE (mt, pos);
+  if (mt->format <= MTEXT_FORMAT_UTF_8)
+    {
+      unsigned char *p = mt->data + byte_pos;
+      unsigned char *endp;
+
+      if (*p == '\n')
+       return pos + 1;
+      p++;
+      endp = mt->data + mt->nbytes;
+      while (p < endp && *p != '\n')
+       p++;
+      if (p == endp)
+       return mt->nchars;
+      byte_pos = p + 1 - mt->data;
+      return POS_BYTE_TO_CHAR (mt, byte_pos);
+    }
+  else if (mt->format <= MTEXT_FORMAT_UTF_16BE)
+    {
+      unsigned short *p = ((unsigned short *) (mt->data)) + byte_pos;
+      unsigned short *endp;
+      unsigned short newline = (mt->format == MTEXT_FORMAT_UTF_16
+                               ? 0x0A00 : 0x000A);
+
+      if (*p == newline)
+       return pos + 1;
+      p++;
+      endp = (unsigned short *) (mt->data) + mt->nbytes;
+      while (p < endp && *p != newline)
+       p++;
+      if (p == endp)
+       return mt->nchars;
+      byte_pos = p + 1 - (unsigned short *) (mt->data);
+      return POS_BYTE_TO_CHAR (mt, byte_pos);
+    }
+  else
+    {
+      unsigned *p = ((unsigned *) (mt->data)) + byte_pos;
+      unsigned *endp;
+      unsigned newline = (mt->format == MTEXT_FORMAT_UTF_32
+                         ? 0x0A000000 : 0x0000000A);
+
+      if (*p == newline)
+       return pos + 1;
+      p++, pos++;
+      endp = (unsigned *) (mt->data) + mt->nbytes;
+      while (p < endp && *p != newline)
+       p++, pos++;
+      return pos;
+    }
+}
+
+int
+mtext__lowercase (MText *mt, int pos, int end)
+{
+  int opos = pos;
+  int c;
+  MText *orig = NULL;
+  MSymbol lang;
+
+  if (lowercase_precheck (mt, pos, end))
+    orig = mtext_dup (mt);
+
+  for (; pos < end; opos++)
+    {
+      c = mtext_ref_char (mt, pos);
+      lang = (MSymbol) mtext_get_prop (mt, pos, Mlanguage);
+
+      if (c == 0x03A3 && final_sigma (orig, opos))
+       REPLACE (gr03A3);
+
+      else if (lang == Mlt)
+       {
+         if (c == 0x00CC)
+           REPLACE (lt00CC);
+         else if (c == 0x00CD)
+           REPLACE (lt00CD);
+         else if (c == 0x0128)
+           REPLACE (lt0128);
+         else if (orig && more_above (orig, opos))
+           {
+             if (c == 0x0049)
+               REPLACE (lt0049);
+             else if (c == 0x004A)
+               REPLACE (lt004A);
+             else if (c == 0x012E)
+               REPLACE (lt012E);
+             else
+               LOOKUP;
+           }
+         else
+           LOOKUP;
+       }
+
+      else if (lang == Mtr || lang == Maz)
+       {
+         if (c == 0x0130)
+           REPLACE (tr0130);
+         else if (c == 0x0307 && after_i (orig, opos))
+           DELETE;
+         else if (c == 0x0049 && ! before_dot (orig, opos))
+           REPLACE (tr0049);
+         else
+           LOOKUP;
+       }
+
+      else
+       LOOKUP;
+    }
+
+  if (orig)
+    m17n_object_unref (orig);
+
+  return end;
+}
+
+int
+mtext__titlecase (MText *mt, int pos, int end)
+{
+  int opos = pos;
+  int c;
+  MText *orig = NULL;
+  MSymbol lang;
+  MPlist *pl;
+
+  /* Precheck for titlecase is identical to that for uppercase. */
+  if (uppercase_precheck (mt, pos, end))
+    orig = mtext_dup (mt);
+
+  for (; pos < end; opos++)
+    {
+      c = mtext_ref_char (mt, pos);
+      lang = (MSymbol) mtext_get_prop (mt, pos, Mlanguage);
+
+      if ((lang == Mtr || lang == Maz) && c == 0x0069)
+       REPLACE (tr0069);
+
+      else if (lang == Mlt && c == 0x0307 && after_soft_dotted (orig, opos))
+       DELETE;
+
+      else if ((pl = (MPlist *) mchartable_lookup (case_mapping, c)))
+       {
+         /* Titlecase is the 2nd element. */
+         MText *title
+           = (MText *) mplist_value (mplist_next (mplist_value (pl)));
+         int tlen = mtext_len (title);
+
+         if (mtext_ref_char (title, 0) != c || tlen > 1)
+           {
+             mtext_replace (mt, pos, pos + 1, title, 0, tlen);
+             pos += tlen;
+             end += tlen - 1;
+           }
+
+         else
+           pos++;
+       }
+
+      else
+       pos++;
+    }
+
+  if (orig)
+    m17n_object_unref (orig);
+
+  return end;
+}
+
+int
+mtext__uppercase (MText *mt, int pos, int end)
+{
+  int opos = pos;
+  int c;
+  MText *orig = NULL;
+  MSymbol lang;
+  MPlist *pl;
+
+  CASE_CONV_INIT (-1);
+
+  if (uppercase_precheck (mt, 0, end))
+    orig = mtext_dup (mt);
+
+  for (; pos < end; opos++)
+    {
+      c = mtext_ref_char (mt, pos);
+      lang = (MSymbol) mtext_get_prop (mt, pos, Mlanguage);
+
+      if (lang == Mlt && c == 0x0307 && after_soft_dotted (orig, opos))
+       DELETE;
+
+      else if ((lang == Mtr || lang == Maz) && c == 0x0069)
+       REPLACE (tr0069);
+              
+      else
+       {
+         if ((pl = (MPlist *) mchartable_lookup (case_mapping, c)) != NULL)
+           {
+             MText *upper;
+             int ulen;
+
+             /* Uppercase is the 3rd element. */
+             upper = (MText *) mplist_value (mplist_next (mplist_next (mplist_value (pl))));
+             ulen = mtext_len (upper);
+
+             if (mtext_ref_char (upper, 0) != c || ulen > 1)
+               {
+                 mtext_replace (mt, pos, pos + 1, upper, 0, ulen);
+                 pos += ulen;
+                 end += ulen - 1;
+               }
+
+             else
+               pos++;
+           }
+
+         else                                           /* pl == NULL */
+           pos++;
+       }
+    }
+
+  if (orig)
+    m17n_object_unref (orig);
+
+  return end;
+}
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+/* External API */
+
+#ifdef WORDS_BIGENDIAN
+const enum MTextFormat MTEXT_FORMAT_UTF_16 = MTEXT_FORMAT_UTF_16BE;
+#else
+const enum MTextFormat MTEXT_FORMAT_UTF_16 = MTEXT_FORMAT_UTF_16LE;
+#endif
+
+#ifdef WORDS_BIGENDIAN
+const int MTEXT_FORMAT_UTF_32 = MTEXT_FORMAT_UTF_32BE;
+#else
+const int MTEXT_FORMAT_UTF_32 = MTEXT_FORMAT_UTF_32LE;
+#endif
+
+/*** @addtogroup m17nMtext */
+/*** @{ */
+/*=*/
+
+/***en The symbol whose name is "language".  */
+/***ja "language" ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë.  */
+MSymbol Mlanguage;
+
+/*=*/
+
+/***en
+    @brief Allocate a new M-text.
+
+    The mtext () function allocates a new M-text of length 0 and
+    returns a pointer to it.  The allocated M-text will not be freed
+    unless the user explicitly does so with the m17n_object_unref ()
+    function.  */
+
+/***ja
+    @brief ¿·¤·¤¤M-text¤ò³ä¤êÅö¤Æ¤ë.
+
+    ´Ø¿ô mtext () ¤Ï¡¢Ä¹¤µ 0 ¤Î¿·¤·¤¤ M-text 
+    ¤ò³ä¤êÅö¤Æ¡¢¤½¤ì¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£³ä¤êÅö¤Æ¤é¤ì¤¿ M-text ¤Ï¡¢´Ø¿ô
+    m17n_object_unref () ¤Ë¤è¤Ã¤Æ¥æ¡¼¥¶¤¬ÌÀ¼¨Åª¤Ë¹Ô¤Ê¤ï¤Ê¤¤¸Â¤ê¡¢²òÊü¤µ¤ì¤Ê¤¤¡£
+
+    @latexonly \IPAlabel{mtext} @endlatexonly  */
+
+/***
+    @seealso
+    m17n_object_unref ()  */
+
+MText *
+mtext ()
+{
+  MText *mt;
+
+  M17N_OBJECT (mt, free_mtext, MERROR_MTEXT);
+  mt->format = MTEXT_FORMAT_US_ASCII;
+  mt->coverage = MTEXT_COVERAGE_ASCII;
+  M17N_OBJECT_REGISTER (mtext_table, mt);
+  return mt;
+}
+
+/***en
+    @brief Allocate a new M-text with specified data.
+
+    The mtext_from_data () function allocates a new M-text whose
+    character sequence is specified by array $DATA of $NITEMS
+    elements.  $FORMAT specifies the format of $DATA.
+
+    When $FORMAT is either #MTEXT_FORMAT_US_ASCII or
+    #MTEXT_FORMAT_UTF_8, the contents of $DATA must be of the type @c
+    unsigned @c char, and $NITEMS counts by byte.
+
+    When $FORMAT is either #MTEXT_FORMAT_UTF_16LE or
+    #MTEXT_FORMAT_UTF_16BE, the contents of $DATA must be of the type
+    @c unsigned @c short, and $NITEMS counts by unsigned short.
+
+    When $FORMAT is either #MTEXT_FORMAT_UTF_32LE or
+    #MTEXT_FORMAT_UTF_32BE, the contents of $DATA must be of the type
+    @c unsigned, and $NITEMS counts by unsigned.
+
+    The character sequence of the M-text is not modifiable.  
+    The contents of $DATA must not be modified while the M-text is alive.
+
+    The allocated M-text will not be freed unless the user explicitly
+    does so with the m17n_object_unref () function.  Even in that case,
+    $DATA is not freed.
+
+    @return
+    If the operation was successful, mtext_from_data () returns a
+    pointer to the allocated M-text.  Otherwise it returns @c NULL and
+    assigns an error code to the external variable #merror_code.  */
+/***ja
+    @brief »ØÄê¤Î¥Ç¡¼¥¿¤ò¸µ¤Ë¿·¤·¤¤ M-text ¤ò³ä¤êÅö¤Æ¤ë.
+
+    ´Ø¿ô mtext_from_data () ¤Ï¡¢Í×ÁÇ¿ô $NITEMS ¤ÎÇÛÎó $DATA 
+    ¤Ç»ØÄꤵ¤ì¤¿Ê¸»úÎó¤ò»ý¤Ä¿·¤·¤¤ M-text ¤ò³ä¤êÅö¤Æ¤ë¡£$FORMAT ¤Ï $DATA
+    ¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤ò¼¨¤¹¡£
+
+    $FORMAT ¤¬ #MTEXT_FORMAT_US_ASCII ¤« #MTEXT_FORMAT_UTF_8 ¤Ê¤é¤Ð¡¢
+    $DATA ¤ÎÆâÍƤϠ@c unsigned @c char ·¿¤Ç¤¢¤ê¡¢$NITEMS 
+    ¤Ï¥Ð¥¤¥Èñ°Ì¤Çɽ¤µ¤ì¤Æ¤¤¤ë¡£
+
+    $FORMAT ¤¬ #MTEXT_FORMAT_UTF_16LE ¤« #MTEXT_FORMAT_UTF_16BE ¤Ê¤é¤Ð¡¢
+    $DATA ¤ÎÆâÍƤϠ@c unsigned @c short ·¿¤Ç¤¢¤ê¡¢$NITEMS ¤Ï unsigned
+    short Ã±°Ì¤Ç¤¢¤ë¡£
+
+    $FORMAT ¤¬ #MTEXT_FORMAT_UTF_32LE ¤« #MTEXT_FORMAT_UTF_32BE ¤Ê¤é¤Ð¡¢
+    $DATA ¤ÎÆâÍƤϠ@c unsigned ·¿¤Ç¤¢¤ê¡¢$NITEMS ¤Ï unsigned Ã±°Ì¤Ç¤¢¤ë¡£
+
+    ³ä¤êÅö¤Æ¤é¤ì¤¿ M-text ¤Îʸ»úÎó¤ÏÊѹ¹¤Ç¤­¤Ê¤¤¡£$DATA ¤ÎÆâÍƤϠ
+    M-text ¤¬Í­¸ú¤Ê´Ö¤ÏÊѹ¹¤·¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    ³ä¤êÅö¤Æ¤é¤ì¤¿ M-text ¤Ï¡¢´Ø¿ô m17n_object_unref () 
+    ¤Ë¤è¤Ã¤Æ¥æ¡¼¥¶¤¬ÌÀ¼¨Åª¤Ë¹Ô¤Ê¤ï¤Ê¤¤¸Â¤ê¡¢²òÊü¤µ¤ì¤Ê¤¤¡£¤½¤Î¾ì¹ç¤Ç¤â $DATA ¤Ï²òÊü¤µ¤ì¤Ê¤¤¡£
+
+    @return 
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_from_data () ¤Ï³ä¤êÅö¤Æ¤é¤ì¤¿M-text 
+    ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤·³°ÉôÊÑ¿ô #merror_code 
+    ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_MTEXT  */
+
+MText *
+mtext_from_data (const void *data, int nitems, enum MTextFormat format)
+{
+  if (nitems < 0
+      || format < MTEXT_FORMAT_US_ASCII || format >= MTEXT_FORMAT_MAX)
+    MERROR (MERROR_MTEXT, NULL);
+  return mtext__from_data (data, nitems, format, 0);
+}
+
+/*=*/
+
+/***en
+    @brief Get information about the text data in M-text.
+
+    The mtext_data () function returns a pointer to the text data of
+    M-text $MT.  If $FMT is not NULL, the format of the text data is
+    stored in it.  If $NUNITS is not NULL, the number of units of the
+    text data is stored in it.
+
+    If $POS_IDX is not NULL and it points to a non-negative number,
+    what it points to is a character position.  In this case, the
+    return value is a pointer to the text data of a character at that
+    position.
+
+    Otherwise, if $UNIT_IDX is not NULL, it points to a unit position.
+    In this case, the return value is a pointer to the text data of a
+    character containing that unit.
+
+    The character position and unit position of the return value are
+    stored in $POS_IDX and $UNIT_DIX respectively if they are not
+    NULL.
+
+    <ul>
+
+    <li> If the format of the text data is MTEXT_FORMAT_US_ASCII or
+    MTEXT_FORMAT_UTF_8, one unit is unsigned char.
+
+    <li> If the format is MTEXT_FORMAT_UTF_16LE or
+    MTEXT_FORMAT_UTF_16BE, one unit is unsigned short.
+
+    <li> If the format is MTEXT_FORMAT_UTF_32LE or
+    MTEXT_FORMAT_UTF_32BE, one unit is unsigned int.
+
+    </ul> */
+
+void *
+mtext_data (MText *mt, enum MTextFormat *fmt, int *nunits,
+           int *pos_idx, int *unit_idx)
+{
+  void *data;
+  int pos = 0, unit_pos = 0;
+
+  if (fmt)
+    *fmt = mt->format;
+  data = MTEXT_DATA (mt);
+  if (pos_idx && *pos_idx >= 0)
+    {
+      pos = *pos_idx;
+      if (pos > mtext_nchars (mt))
+       MERROR (MERROR_MTEXT, NULL);
+      unit_pos = POS_CHAR_TO_BYTE (mt, pos);
+    }
+  else if (unit_idx)
+    {
+      unit_pos = *unit_idx;
+
+      if (unit_pos < 0 || unit_pos > mtext_nbytes (mt))
+       MERROR (MERROR_MTEXT, NULL);
+      pos = POS_BYTE_TO_CHAR (mt, unit_pos);
+      unit_pos = POS_CHAR_TO_BYTE (mt, pos);
+    }
+  if (nunits)
+    *nunits = mtext_nbytes (mt) - unit_pos;
+  if (pos_idx)
+    *pos_idx = pos;
+  if (unit_idx)
+    *unit_idx = unit_pos;
+  if (unit_pos > 0)
+    {
+      if (mt->format <= MTEXT_FORMAT_UTF_8)
+       data = (unsigned char *) data + unit_pos;
+      else if (mt->format <= MTEXT_FORMAT_UTF_16BE)
+       data = (unsigned short *) data + unit_pos;
+      else
+       data = (unsigned int *) data + unit_pos;
+    }
+  return data;
+}
+
+/*=*/
+
+/***en
+    @brief Number of characters in M-text.
+
+    The mtext_len () function returns the number of characters in
+    M-text $MT.  */
+
+/***ja
+    @brief M-text Ãæ¤Îʸ»ú¤Î¿ô.
+
+    ´Ø¿ô mtext_len () ¤Ï M-text $MT Ãæ¤Îʸ»ú¤Î¿ô¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mtext_len} @endlatexonly  */
+
+int
+mtext_len (MText *mt)
+{
+  return (mt->nchars);
+}
+
+/*=*/
+
+/***en
+    @brief Return the character at the specified position in an M-text.
+
+    The mtext_ref_char () function returns the character at $POS in
+    M-text $MT.  If an error is detected, it returns -1 and assigns an
+    error code to the external variable #merror_code.  */
+
+/***ja
+    @brief M-text Ãæ¤Î»ØÄꤵ¤ì¤¿°ÌÃÖ¤Îʸ»ú¤òÊÖ¤¹.
+
+    ´Ø¿ô mtext_ref_char () ¤Ï¡¢M-text $MT ¤Î°ÌÃÖ $POS 
+    ¤Îʸ»ú¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code
+    ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mtext_ref_char} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE  */
+
+int
+mtext_ref_char (MText *mt, int pos)
+{
+  int c;
+
+  M_CHECK_POS (mt, pos, -1);
+  if (mt->format <= MTEXT_FORMAT_UTF_8)
+    {
+      unsigned char *p = mt->data + POS_CHAR_TO_BYTE (mt, pos);
+
+      c = STRING_CHAR_UTF8 (p);
+    }
+  else if (mt->format <= MTEXT_FORMAT_UTF_16BE)
+    {
+      unsigned short *p
+       = (unsigned short *) (mt->data) + POS_CHAR_TO_BYTE (mt, pos);
+      unsigned short p1[2];
+
+      if (mt->format != MTEXT_FORMAT_UTF_16)
+       {
+         p1[0] = SWAP_16 (*p);
+         if (p1[0] >= 0xD800 || p1[0] < 0xDC00)
+           p1[1] = SWAP_16 (p[1]);
+         p = p1;
+       }
+      c = STRING_CHAR_UTF16 (p);
+    }
+  else
+    {
+      c = ((unsigned *) (mt->data))[pos];
+      if (mt->format != MTEXT_FORMAT_UTF_32)
+       c = SWAP_32 (c);
+    }
+  return c;
+}
+
+/*=*/
+
+/***en
+    @brief Store a character into an M-text.
+
+    The mtext_set_char () function sets character $C, which has no
+    text properties, at $POS in M-text $MT.
+
+    @return
+    If the operation was successful, mtext_set_char () returns 0.
+    Otherwise it returns -1 and assigns an error code to the external
+    variable #merror_code.  */
+
+/***ja
+    @brief M-text ¤Ë°ìʸ»ú¤òÀßÄꤹ¤ë.
+
+    ´Ø¿ô mtext_set_char () ¤Ï¡¢¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£Ìµ¤·¤Îʸ»ú $C ¤ò 
+    M-text $MT ¤Î°ÌÃÖ $POS ¤ËÀßÄꤹ¤ë¡£
+
+    @return
+    ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð mtext_set_char () ¤Ï 0 ¤òÊÖ¤¹¡£¼ºÇÔ¤¹¤ì¤Ð -1 
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mtext_set_char} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE */
+
+int
+mtext_set_char (MText *mt, int pos, int c)
+{
+  int pos_unit;
+  int old_units, new_units;
+  int delta;
+  unsigned char *p;
+  int unit_bytes;
+
+  M_CHECK_POS (mt, pos, -1);
+  M_CHECK_READONLY (mt, -1);
+
+  mtext__adjust_plist_for_change (mt, pos, 1, 1);
+
+  if (mt->format <= MTEXT_FORMAT_UTF_8)
+    {
+      if (c >= 0x80)
+       mt->format = MTEXT_FORMAT_UTF_8, mt->coverage = MTEXT_COVERAGE_FULL;
+    }
+  else if (mt->format <= MTEXT_FORMAT_UTF_16BE)
+    {
+      if (c >= 0x110000)
+       mtext__adjust_format (mt, MTEXT_FORMAT_UTF_8);
+      else if (mt->format != MTEXT_FORMAT_UTF_16)
+       mtext__adjust_format (mt, MTEXT_FORMAT_UTF_16);
+    }
+  else if (mt->format != MTEXT_FORMAT_UTF_32)
+    mtext__adjust_format (mt, MTEXT_FORMAT_UTF_32);
+
+  unit_bytes = UNIT_BYTES (mt->format);
+  pos_unit = POS_CHAR_TO_BYTE (mt, pos);
+  p = mt->data + pos_unit * unit_bytes;
+  old_units = CHAR_UNITS_AT (mt, p);
+  new_units = CHAR_UNITS (c, mt->format);
+  delta = new_units - old_units;
+
+  if (delta)
+    {
+      if (mt->cache_char_pos > pos)
+       mt->cache_byte_pos += delta;
+
+      if ((mt->nbytes + delta + 1) * unit_bytes > mt->allocated)
+       {
+         mt->allocated = (mt->nbytes + delta + 1) * unit_bytes;
+         MTABLE_REALLOC (mt->data, mt->allocated, MERROR_MTEXT);
+       }
+
+      memmove (mt->data + (pos_unit + new_units) * unit_bytes, 
+              mt->data + (pos_unit + old_units) * unit_bytes,
+              (mt->nbytes - pos_unit - old_units + 1) * unit_bytes);
+      mt->nbytes += delta;
+      mt->data[mt->nbytes * unit_bytes] = 0;
+    }
+  switch (mt->format)
+    {
+    case MTEXT_FORMAT_US_ASCII:
+      mt->data[pos_unit] = c;
+      break;
+    case MTEXT_FORMAT_UTF_8:
+      {
+       unsigned char *p = mt->data + pos_unit;
+       CHAR_STRING_UTF8 (c, p);
+       break;
+      }
+    default:
+      if (mt->format == MTEXT_FORMAT_UTF_16)
+       {
+         unsigned short *p = (unsigned short *) mt->data + pos_unit;
+
+         CHAR_STRING_UTF16 (c, p);
+       }
+      else
+       ((unsigned *) mt->data)[pos_unit] = c;
+    }
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief  Append a character to an M-text.
+
+    The mtext_cat_char () function appends character $C, which has no
+    text properties, to the end of M-text $MT.
+
+    @return
+    This function returns a pointer to the resulting M-text $MT.  If
+    $C is an invalid character, it returns @c NULL.  */
+
+/***ja
+    @brief M-text ¤Ë°ìʸ»úÄɲ乤ë.
+
+    ´Ø¿ô mtext_cat_char () ¤Ï¡¢¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£Ìµ¤·¤Îʸ»ú $C ¤ò 
+    M-text $MT ¤ÎËöÈø¤ËÄɲ乤롣
+
+    @return
+    ¤³¤Î´Ø¿ô¤ÏÊѹ¹¤µ¤ì¤¿ M-text $MT ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£$C 
+    ¤¬Àµ¤·¤¤Ê¸»ú¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Ï @c NULL ¤òÊÖ¤¹¡£  */
+
+/***
+    @seealso
+    mtext_cat (), mtext_ncat ()  */
+
+MText *
+mtext_cat_char (MText *mt, int c)
+{
+  int nunits;
+  int unit_bytes = UNIT_BYTES (mt->format);
+
+  M_CHECK_READONLY (mt, NULL);
+  if (c < 0 || c > MCHAR_MAX)
+    return NULL;
+  mtext__adjust_plist_for_insert (mt, mt->nchars, 1, NULL);
+
+  if (c >= 0x80
+      && (mt->format == MTEXT_FORMAT_US_ASCII
+         || (c >= 0x10000
+             && (mt->format == MTEXT_FORMAT_UTF_16LE
+                 || mt->format == MTEXT_FORMAT_UTF_16BE))))
+
+    {
+      mtext__adjust_format (mt, MTEXT_FORMAT_UTF_8);
+      unit_bytes = 1;
+    }
+  else if (mt->format >= MTEXT_FORMAT_UTF_32LE)
+    {
+      if (mt->format != MTEXT_FORMAT_UTF_32)
+       mtext__adjust_format (mt, MTEXT_FORMAT_UTF_32);
+    }
+  else if (mt->format >= MTEXT_FORMAT_UTF_16LE)
+    {
+      if (mt->format != MTEXT_FORMAT_UTF_16)
+       mtext__adjust_format (mt, MTEXT_FORMAT_UTF_16);
+    }
+
+  nunits = CHAR_UNITS (c, mt->format);
+  if ((mt->nbytes + nunits + 1) * unit_bytes > mt->allocated)
+    {
+      mt->allocated = (mt->nbytes + nunits * 16 + 1) * unit_bytes;
+      MTABLE_REALLOC (mt->data, mt->allocated, MERROR_MTEXT);
+    }
+  
+  if (mt->format <= MTEXT_FORMAT_UTF_8)
+    {
+      unsigned char *p = mt->data + mt->nbytes;
+      p += CHAR_STRING_UTF8 (c, p);
+      *p = 0;
+    }
+  else if (mt->format == MTEXT_FORMAT_UTF_16)
+    {
+      unsigned short *p = (unsigned short *) mt->data + mt->nbytes;
+      p += CHAR_STRING_UTF16 (c, p);
+      *p = 0;
+    }
+  else
+    {
+      unsigned *p = (unsigned *) mt->data + mt->nbytes;
+      *p++ = c;
+      *p = 0;
+    }
+
+  mt->nchars++;
+  mt->nbytes += nunits;
+  return mt;
+}
+
+/*=*/
+
+/***en
+    @brief  Create a copy of an M-text.
+
+    The mtext_dup () function creates a copy of M-text $MT while
+    inheriting all the text properties of $MT.
+
+    @return
+    This function returns a pointer to the created copy.  */
+
+/***ja
+    @brief M-text ¤Î¥³¥Ô¡¼¤òºî¤ë.
+
+    ´Ø¿ô mtext_dup () ¤Ï¡¢M-text $MT ¤Î¥³¥Ô¡¼¤òºî¤ë¡£$MT 
+    ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù¤Æ·Ñ¾µ¤µ¤ì¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ïºî¤é¤ì¤¿¥³¥Ô¡¼¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
+
+     @latexonly \IPAlabel{mtext_dup} @endlatexonly  */
+
+/***
+    @seealso
+    mtext_duplicate ()  */
+
+MText *
+mtext_dup (MText *mt)
+{
+  return mtext_duplicate (mt, 0, mtext_nchars (mt));
+}
+
+/*=*/
+
+/***en
+    @brief  Append an M-text to another.
+
+    The mtext_cat () function appends M-text $MT2 to the end of M-text
+    $MT1 while inheriting all the text properties.  $MT2 itself is not
+    modified.
+
+    @return
+    This function returns a pointer to the resulting M-text $MT1.  */
+
+/***ja
+    @brief 2¸Ä¤Î M-text¤òÏ¢·ë¤¹¤ë.
+
+    ´Ø¿ô mtext_cat () ¤Ï¡¢ M-text $MT2 ¤ò M-text $MT1 
+    ¤ÎËöÈø¤ËÉÕ¤±²Ã¤¨¤ë¡£$MT2 ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù¤Æ·Ñ¾µ¤µ¤ì¤ë¡£$MT2 ¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤ÏÊѹ¹¤µ¤ì¤¿ M-text $MT1 ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mtext_cat} @endlatexonly  */
+
+/***
+    @seealso
+    mtext_ncat (), mtext_cat_char ()  */
+
+MText *
+mtext_cat (MText *mt1, MText *mt2)
+{
+  M_CHECK_READONLY (mt1, NULL);
+
+  if (mt2->nchars > 0)
+    insert (mt1, mt1->nchars, mt2, 0, mt2->nchars);
+  return mt1;
+}
+
+
+/*=*/
+
+/***en
+    @brief Append a part of an M-text to another.
+
+    The mtext_ncat () function appends the first $N characters of
+    M-text $MT2 to the end of M-text $MT1 while inheriting all the
+    text properties.  If the length of $MT2 is less than $N, all
+    characters are copied.  $MT2 is not modified.  
+
+    @return 
+    If the operation was successful, mtext_ncat () returns a
+    pointer to the resulting M-text $MT1.  If an error is detected, it
+    returns @c NULL and assigns an error code to the global variable
+    #merror_code.  */
+
+/***ja
+    @brief M-text ¤Î°ìÉô¤òÊ̤ΠM-text ¤ËÉղ乤ë.
+
+    ´Ø¿ô mtext_ncat () ¤Ï¡¢M-text $MT2 ¤Î¤Ï¤¸¤á¤Î $N Ê¸»ú¤ò M-text
+    $MT1 ¤ÎËöÈø¤ËÉÕ¤±²Ã¤¨¤ë¡£$MT2 ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù¤Æ·Ñ¾µ¤µ¤ì¤ë¡£$MT2
+    ¤ÎŤµ¤¬ $N °Ê²¼¤Ê¤é¤Ð¡¢$MT2 ¤Î¤¹¤Ù¤Æ¤Îʸ»ú¤¬Éղ䵤ì¤ë¡£ $MT2 ¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤·¤¿¾ì¹ç¡¢mtext_ncat () ¤ÏÊѹ¹¤µ¤ì¤¿ M-text $MT1
+    ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô
+    #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mtext_ncat} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE
+
+    @seealso
+    mtext_cat (), mtext_cat_char ()  */
+
+MText *
+mtext_ncat (MText *mt1, MText *mt2, int n)
+{
+  M_CHECK_READONLY (mt1, NULL);
+  if (n < 0)
+    MERROR (MERROR_RANGE, NULL);
+  if (mt2->nchars > 0)
+    insert (mt1, mt1->nchars, mt2, 0, mt2->nchars < n ? mt2->nchars : n);
+  return mt1;
+}
+
+
+/*=*/
+
+/***en
+    @brief Copy an M-text to another.
+
+    The mtext_cpy () function copies M-text $MT2 to M-text $MT1 while
+    inheriting all the text properties.  The old text in $MT1 is
+    overwritten and the length of $MT1 is extended if necessary.  $MT2
+    is not modified.
+
+    @return
+    This function returns a pointer to the resulting M-text $MT1.  */
+
+/***ja
+    @brief M-text ¤òÊ̤ΠM-text ¤Ë¥³¥Ô¡¼¤¹¤ë.
+
+    ´Ø¿ô mtext_cpy () ¤Ï M-text $MT2 ¤ò M-text $MT1 ¤Ë¾å½ñ¤­¥³¥Ô¡¼¤¹¤ë¡£
+    $MT2 ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù¤Æ·Ñ¾µ¤µ¤ì¤ë¡£$MT1 
+    ¤ÎŤµ¤ÏɬÍפ˱þ¤¸¤Æ¿­¤Ð¤µ¤ì¤ë¡£$MT2 ¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤ÏÊѹ¹¤µ¤ì¤¿ M-text $MT1 ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mtext_cpy} @endlatexonly  */
+
+/***
+    @seealso
+    mtext_ncpy (), mtext_copy ()  */
+
+MText *
+mtext_cpy (MText *mt1, MText *mt2)
+{
+  M_CHECK_READONLY (mt1, NULL);
+  mtext_del (mt1, 0, mt1->nchars);
+  if (mt2->nchars > 0)
+    insert (mt1, 0, mt2, 0, mt2->nchars);
+  return mt1;
+}
+
+/*=*/
+
+/***en
+    @brief Copy the first some characters in an M-text to another.
+
+    The mtext_ncpy () function copies the first $N characters of
+    M-text $MT2 to M-text $MT1 while inheriting all the text
+    properties.  If the length of $MT2 is less than $N, all characters
+    of $MT2 are copied.  The old text in $MT1 is overwritten and the
+    length of $MT1 is extended if necessary.  $MT2 is not modified.
+
+    @return
+    If the operation was successful, mtext_ncpy () returns a pointer
+    to the resulting M-text $MT1.  If an error is detected, it returns
+    @c NULL and assigns an error code to the global variable 
+    #merror_code.  */
+
+/***ja
+    @brief M-text ¤Ë´Þ¤Þ¤ì¤ëºÇ½é¤Î²¿Ê¸»ú¤«¤ò¥³¥Ô¡¼¤¹¤ë.
+
+    ´Ø¿ô mtext_ncpy () ¤Ï¡¢M-text $MT2 ¤ÎºÇ½é¤Î $N Ê¸»ú¤ò M-text $MT1 
+    ¤Ë¾å½ñ¤­¥³¥Ô¡¼¤¹¤ë¡£$MT2 ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù¤Æ·Ñ¾µ¤µ¤ì¤ë¡£¤â¤· $MT2
+    ¤ÎŤµ¤¬ $N ¤è¤ê¤â¾®¤µ¤±¤ì¤Ð $MT2 ¤Î¤¹¤Ù¤Æ¤Îʸ»ú¤ò¥³¥Ô¡¼¤¹¤ë¡£$MT1 
+    ¤ÎŤµ¤ÏɬÍפ˱þ¤¸¤Æ¿­¤Ð¤µ¤ì¤ë¡£$MT2 ¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
+
+    @return 
+    ½èÍý¤¬À®¸ù¤·¤¿¾ì¹ç¡¢mtext_ncpy () ¤ÏÊѹ¹¤µ¤ì¤¿ M-text $MT1 
+    ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô 
+    #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mtext_ncpy} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE
+
+    @seealso
+    mtext_cpy (), mtext_copy ()  */
+
+MText *
+mtext_ncpy (MText *mt1, MText *mt2, int n)
+{
+  M_CHECK_READONLY (mt1, NULL);
+  if (n < 0)
+    MERROR (MERROR_RANGE, NULL);
+  mtext_del (mt1, 0, mt1->nchars);
+  if (mt2->nchars > 0)
+    insert (mt1, 0, mt2, 0, mt2->nchars < n ? mt2->nchars : n);
+  return mt1;
+}
+
+/*=*/
+
+/***en
+    @brief Create a new M-text from a part of an existing M-text.
+
+    The mtext_duplicate () function creates a copy of sub-text of
+    M-text $MT, starting at $FROM (inclusive) and ending at $TO
+    (exclusive) while inheriting all the text properties of $MT.  $MT
+    itself is not modified.
+
+    @return 
+    If the operation was successful, mtext_duplicate ()
+    returns a pointer to the created M-text.  If an error is detected,
+    it returns NULL and assigns an error code to the external variable
+    #merror_code.  */
+
+/***ja
+    @brief ´û¸¤Î M-text ¤Î°ìÉô¤«¤é¿·¤·¤¤ M-text ¤ò¤Ä¤¯¤ë.
+
+    ´Ø¿ô mtext_duplicate () ¤Ï¡¢M-text $MT ¤Î $FROM ¡Ê$FROM ¼«ÂΤâ´Þ¤à¡Ë¤«¤é
+    $TO ¡Ê$TO ¼«ÂΤϴޤޤʤ¤¡Ë¤Þ¤Ç¤ÎÉôʬ¤Î¥³¥Ô¡¼¤òºî¤ë¡£¤³¤Î¤È¤­ $MT 
+    ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù¤Æ·Ñ¾µ¤µ¤ì¤ë¡£$MT ¤½¤Î¤â¤Î¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_duplicate () ¤Ïºî¤é¤ì¤¿ M-text 
+    ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô 
+    #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mtext_duplicate} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE
+
+    @seealso
+    mtext_dup ()  */
+
+MText *
+mtext_duplicate (MText *mt, int from, int to)
+{
+  MText *new = mtext ();
+
+  M_CHECK_RANGE (mt, from, to, NULL, new);
+  new->format = mt->format;
+  new->coverage = mt->coverage;
+  insert (new, 0, mt, from, to);
+  return new;
+}
+
+/*=*/
+
+/***en
+    @brief Copy characters in the specified range into an M-text.
+
+    The mtext_copy () function copies the text between $FROM
+    (inclusive) and $TO (exclusive) in M-text $MT2 to the region
+    starting at $POS in M-text $MT1 while inheriting the text
+    properties.  The old text in $MT1 is overwritten and the length of
+    $MT1 is extended if necessary.  $MT2 is not modified.
+
+    @return
+    If the operation was successful, mtext_copy () returns a pointer
+    to the modified $MT1.  Otherwise, it returns @c NULL and assigns
+    an error code to the external variable #merror_code.  */
+
+/***ja
+    @brief M-text ¤Ë»ØÄêÈϰϤÎʸ»ú¤ò¥³¥Ô¡¼¤¹¤ë.
+
+    ´Ø¿ô mtext_copy () ¤Ï¡¢ M-text $MT2 ¤Î $FROM ¡Ê$FROM ¼«ÂΤâ´Þ¤à¡Ë¤«¤é 
+    $TO ¡Ê$TO ¼«ÂΤϴޤޤʤ¤¡Ë¤Þ¤Ç¤ÎÈϰϤΥƥ­¥¹¥È¤ò M-text $MT1 ¤Î°ÌÃÖ $POS
+    ¤«¤é¾å½ñ¤­¥³¥Ô¡¼¤¹¤ë¡£$MT2 ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù¤Æ·Ñ¾µ¤µ¤ì¤ë¡£$MT1 
+    ¤ÎŤµ¤ÏɬÍפ˱þ¤¸¤Æ¿­¤Ð¤µ¤ì¤ë¡£$MT2 ¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
+
+    @latexonly \IPAlabel{mtext_copy} @endlatexonly
+
+    @return
+    ½èÍý¤¬À®¸ù¤·¤¿¾ì¹ç¡¢mtext_copy () ¤ÏÊѹ¹¤µ¤ì¤¿ $MT1 
+    ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code 
+    ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_RANGE
+
+    @seealso
+    mtext_cpy (), mtext_ncpy ()  */
+
+MText *
+mtext_copy (MText *mt1, int pos, MText *mt2, int from, int to)
+{
+  M_CHECK_POS_X (mt1, pos, NULL);
+  M_CHECK_READONLY (mt1, NULL);
+  M_CHECK_RANGE_X (mt2, from, to, NULL);
+  mtext_del (mt1, pos, mt1->nchars);
+  return insert (mt1, pos, mt2, from, to);
+}
+
+/*=*/
+
+
+/***en
+    @brief Delete characters in the specified range destructively.
+
+    The mtext_del () function deletes the characters in the range
+    $FROM (inclusive) and $TO (exclusive) from M-text $MT
+    destructively.  As a result, the length of $MT shrinks by ($TO -
+    $FROM) characters.
+
+    @return
+    If the operation was successful, mtext_del () returns 0.
+    Otherwise, it returns -1 and assigns an error code to the external
+    variable #merror_code.  */
+
+/***ja
+    @brief »ØÄêÈϰϤÎʸ»ú¤òÇ˲õŪ¤Ë¼è¤ê½ü¤¯.
+
+    ´Ø¿ô mtext_del () ¤Ï¡¢M-text $MT ¤Î $FROM ¡Ê$FROM ¼«ÂΤâ´Þ¤à¡Ë¤«¤é
+    $TO ¡Ê$TO ¼«ÂΤϴޤޤʤ¤¡Ë¤Þ¤Ç¤Îʸ»ú¤òÇ˲õŪ¤Ë¼è¤ê½ü¤¯¡£·ë²ÌŪ¤Ë
+    $MT ¤ÏŤµ¤¬ ($TO @c - $FROM) ¤À¤±½Ì¤à¤³¤È¤Ë¤Ê¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mtext_del () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_RANGE
+
+    @seealso
+    mtext_ins ()  */
+
+int
+mtext_del (MText *mt, int from, int to)
+{
+  int from_byte, to_byte;
+  int unit_bytes = UNIT_BYTES (mt->format);
+
+  M_CHECK_READONLY (mt, -1);
+  M_CHECK_RANGE (mt, from, to, -1, 0);
+
+  from_byte = POS_CHAR_TO_BYTE (mt, from);
+  to_byte = POS_CHAR_TO_BYTE (mt, to);
+
+  if (mt->cache_char_pos >= to)
+    {
+      mt->cache_char_pos -= to - from;
+      mt->cache_byte_pos -= to_byte - from_byte;
+    }
+  else if (mt->cache_char_pos > from)
+    {
+      mt->cache_char_pos -= from;
+      mt->cache_byte_pos -= from_byte;
+    }
+
+  mtext__adjust_plist_for_delete (mt, from, to - from);
+  memmove (mt->data + from_byte * unit_bytes, 
+          mt->data + to_byte * unit_bytes,
+          (mt->nbytes - to_byte + 1) * unit_bytes);
+  mt->nchars -= (to - from);
+  mt->nbytes -= (to_byte - from_byte);
+  mt->cache_char_pos = from;
+  mt->cache_byte_pos = from_byte;
+  return 0;
+}
+
+
+/*=*/
+
+/***en
+    @brief Insert an M-text into another M-text.
+
+    The mtext_ins () function inserts M-text $MT2 into M-text $MT1, at
+    position $POS.  As a result, $MT1 is lengthen by the length of
+    $MT2.  On insertion, all the text properties of $MT2 are
+    inherited.  The original $MT2 is not modified.
+
+    @return
+    If the operation was successful, mtext_ins () returns 0.
+    Otherwise, it returns -1 and assigns an error code to the external
+    variable #merror_code.  */
+
+/***ja
+    @brief M-text ¤òÊ̤ΠM-text ¤ËÁÞÆþ¤¹¤ë.
+
+    ´Ø¿ô mtext_ins () ¤Ï M-text $MT1 ¤Î $POS ¤Î°ÌÃÖ¤ËÊ̤ΠM-text $MT2 
+    ¤òÁÞÆþ¤¹¤ë¡£¤³¤Î·ë²Ì $MT1 ¤ÎŤµ¤Ï $MT2 ¤ÎŤµÊ¬¤À¤±Áý¤¨¤ë¡£ÁÞÆþ¤ÎºÝ¡¢$MT2
+    ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù¤Æ·Ñ¾µ¤µ¤ì¤ë¡£$MT2 ¤½¤Î¤â¤Î¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mtext_ins () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_RANGE , @c MERROR_MTEXT
+
+    @seealso
+    mtext_del () , mtext_insert ()  */
+
+int
+mtext_ins (MText *mt1, int pos, MText *mt2)
+{
+  M_CHECK_READONLY (mt1, -1);
+  M_CHECK_POS_X (mt1, pos, -1);
+
+  if (mt2->nchars == 0)
+    return 0;
+  insert (mt1, pos, mt2, 0, mt2->nchars);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Insert sub-text of an M-text into another M-text.
+
+    The mtext_insert () function inserts sub-text of M-text $MT2
+    between $FROM (inclusive) and $TO (exclusive) into M-text $MT1, at
+    position $POS.  As a result, $MT1 is lengthen by ($TO - $FROM).
+    On insertion, all the text properties of the sub-text of $MT2 are
+    inherited.
+
+    @return 
+    If the operation was successful, mtext_insert () returns
+    0.  Otherwise, it returns -1 and assigns an error code to the
+    external variable #merror_code.  */
+
+/***ja
+    @brief M-text ¤Î°ìÉô¤òÊ̤ΠM-text ¤ËÁÞÆþ¤¹¤ë.
+
+    ´Ø¿ô mtext_insert () ¤Ï M-text $MT1 Ãæ¤Î $POS ¤Î°ÌÃ֤ˡ¢Ê̤Π
+    M-text $MT2 ¤Î $FROM ¡Ê$FROM ¼«ÂΤâ´Þ¤à¡Ë¤«¤é $TO ¡Ê$TO ¼«ÂΤϴޤÞ
+    ¤Ê¤¤¡Ë¤Þ¤Ç¤Îʸ»ú¤òÁÞÆþ¤¹¤ë¡£·ë²ÌŪ¤Ë $MT1 ¤ÏŤµ¤¬ ($TO - $FROM) 
+    ¤À¤±¿­¤Ó¤ë¡£ÁÞÆþ¤ÎºÝ¡¢ $MT2 Ãæ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù¤Æ·Ñ¾µ¤µ¤ì
+    ¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_insert () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_MTEXT , @c MERROR_RANGE
+
+    @seealso
+    mtext_ins ()  */
+
+int
+mtext_insert (MText *mt1, int pos, MText *mt2, int from, int to)
+{
+  M_CHECK_READONLY (mt1, -1);
+  M_CHECK_POS_X (mt1, pos, -1);
+  M_CHECK_RANGE (mt2, from, to, -1, 0);
+
+  insert (mt1, pos, mt2, from, to);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Insert a character into an M-text.
+
+    The mtext_ins_char () function inserts $N copies of character $C
+    into M-text $MT at position $POS.  As a result, $MT is lengthen by
+    $N.
+
+    @return
+    If the operation was successful, mtext_ins () returns 0.
+    Otherwise, it returns -1 and assigns an error code to the external
+    variable #merror_code.  */
+
+/***ja
+    @brief M-text ¤Ëʸ»ú¤òÁÞÆþ¤¹¤ë.
+
+    ´Ø¿ô mtext_ins_char () ¤Ï M-text $MT ¤Î $POS ¤Î°ÌÃÖ¤Ëʸ»ú $C ¤Î¥³¥Ô¡¼¤ò $N
+    ¸ÄÁÞÆþ¤¹¤ë¡£¤³¤Î·ë²Ì $MT1 ¤ÎŤµ¤Ï $N ¤À¤±Áý¤¨¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mtext_ins_char () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_RANGE
+
+    @seealso
+    mtext_ins, mtext_del ()  */
+
+int
+mtext_ins_char (MText *mt, int pos, int c, int n)
+{
+  int nunits;
+  int unit_bytes = UNIT_BYTES (mt->format);
+  int pos_unit;
+  int i;
+
+  M_CHECK_READONLY (mt, -1);
+  M_CHECK_POS_X (mt, pos, -1);
+  if (c < 0 || c > MCHAR_MAX)
+    MERROR (MERROR_MTEXT, -1);
+  if (n <= 0)
+    return 0;
+  mtext__adjust_plist_for_insert (mt, pos, n, NULL);
+
+  if (c >= 0x80
+      && (mt->format == MTEXT_FORMAT_US_ASCII
+         || (c >= 0x10000 && (mt->format == MTEXT_FORMAT_UTF_16LE
+                              || mt->format == MTEXT_FORMAT_UTF_16BE))))
+    {
+      mtext__adjust_format (mt, MTEXT_FORMAT_UTF_8);
+      unit_bytes = 1;
+    }
+  else if (mt->format >= MTEXT_FORMAT_UTF_32LE)
+    {
+      if (mt->format != MTEXT_FORMAT_UTF_32)
+       mtext__adjust_format (mt, MTEXT_FORMAT_UTF_32);
+    }
+  else if (mt->format >= MTEXT_FORMAT_UTF_16LE)
+    {
+      if (mt->format != MTEXT_FORMAT_UTF_16)
+       mtext__adjust_format (mt, MTEXT_FORMAT_UTF_16);
+    }
+
+  nunits = CHAR_UNITS (c, mt->format);
+  if ((mt->nbytes + nunits * n + 1) * unit_bytes > mt->allocated)
+    {
+      mt->allocated = (mt->nbytes + nunits * n + 1) * unit_bytes;
+      MTABLE_REALLOC (mt->data, mt->allocated, MERROR_MTEXT);
+    }
+  pos_unit = POS_CHAR_TO_BYTE (mt, pos);
+  if (mt->cache_char_pos > pos)
+    {
+      mt->cache_char_pos += n;
+      mt->cache_byte_pos += nunits * n;
+    }
+  memmove (mt->data + (pos_unit + nunits * n) * unit_bytes,
+          mt->data + pos_unit * unit_bytes,
+          (mt->nbytes - pos_unit + 1) * unit_bytes);
+  if (mt->format <= MTEXT_FORMAT_UTF_8)
+    {
+      unsigned char *p = mt->data + pos_unit;
+
+      for (i = 0; i < n; i++)
+       p += CHAR_STRING_UTF8 (c, p);
+    }
+  else if (mt->format == MTEXT_FORMAT_UTF_16)
+    {
+      unsigned short *p = (unsigned short *) mt->data + pos_unit;
+
+      for (i = 0; i < n; i++)
+       p += CHAR_STRING_UTF16 (c, p);
+    }
+  else
+    {
+      unsigned *p = (unsigned *) mt->data + pos_unit;
+
+      for (i = 0; i < n; i++)
+       *p++ = c;
+    }
+  mt->nchars += n;
+  mt->nbytes += nunits * n;
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Replace sub-text of M-text with another.
+
+    The mtext_replace () function replaces sub-text of M-text $MT1
+    between $FROM1 (inclusive) and $TO1 (exclusive) with the sub-text
+    of M-text $MT2 between $FROM2 (inclusive) and $TO2 (exclusive).
+    The new sub-text inherits text properties of the old sub-text.
+
+    @return 
+    If the operation was successful, mtext_replace () returns
+    0.  Otherwise, it returns -1 and assigns an error code to the
+    external variable #merror_code.  */
+
+/***ja
+    @brief M-text ¤Î°ìÉô¤òÊ̤ΠM-text ¤Î°ìÉô¤ÇÃÖ´¹¤¹¤ë.
+
+    ´Ø¿ô mtext_replace () ¤Ï¡¢ M-text $MT1 ¤Î $FROM1 ¡Ê$FROM1 ¼«ÂΤâ´Þ
+    ¤à¡Ë¤«¤é $TO1 ¡Ê$TO1 ¼«ÂΤϴޤޤʤ¤¡Ë¤Þ¤Ç¤ò¡¢ M-text $MT2 ¤Î 
+    $FROM2 ¡Ê$FROM2 ¼«ÂΤâ´Þ¤à¡Ë¤«¤é $TO2 ¡Ê$TO2 ¼«ÂΤϴޤޤʤ¤¡Ë¤ÇÃÖ
+    ¤­´¹¤¨¤ë¡£¿·¤·¤¯ÁÞÆþ¤µ¤ì¤¿Éôʬ¤Ï¡¢ÃÖ¤­´¹¤¨¤ëÁ°¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£
+    ¤¹¤Ù¤Æ¤ò·Ñ¾µ¤¹¤ë¡£
+
+    @return 
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢ mtext_replace () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê
+    ¤±¤ì¤Ð -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_MTEXT , @c MERROR_RANGE
+
+    @seealso
+    mtext_insert ()  */
+
+int
+mtext_replace (MText *mt1, int from1, int to1,
+              MText *mt2, int from2, int to2)
+{
+  int len1, len2;
+  int from1_byte, from2_byte, old_bytes, new_bytes;
+  int unit_bytes, total_bytes;
+  unsigned char *p;
+  int free_mt2 = 0;
+
+  M_CHECK_READONLY (mt1, -1);
+  M_CHECK_RANGE_X (mt1, from1, to1, -1);
+  M_CHECK_RANGE_X (mt2, from2, to2, -1);
+
+  if (from1 == to1)
+    {
+      struct MTextPlist *saved = mt2->plist;
+
+      mt2->plist = NULL;
+      insert (mt1, from1, mt2, from2, to2);
+      mt2->plist = saved;
+      return 0;
+    }
+
+  if (from2 == to2)
+    {
+      return mtext_del (mt1, from1, to1);
+    }
+
+  if (mt1 == mt2)
+    {
+      mt2 = mtext_duplicate (mt2, from2, to2);
+      to2 -= from2;
+      from2 = 0;
+      free_mt2 = 1;
+    }
+
+  if (mt1->format != mt2->format
+      && mt1->format == MTEXT_FORMAT_US_ASCII)
+    mt1->format = MTEXT_FORMAT_UTF_8;
+  if (mt1->format != mt2->format
+      && mt1->coverage < mt2->coverage)
+    mtext__adjust_format (mt1, mt2->format);
+  if (mt1->format != mt2->format)
+    {
+      mt2 = mtext_duplicate (mt2, from2, to2);
+      mtext__adjust_format (mt2, mt1->format);
+      to2 -= from2;
+      from2 = 0;
+      free_mt2 = 1;
+    }
+
+  len1 = to1 - from1;
+  len2 = to2 - from2;
+  mtext__adjust_plist_for_change (mt1, from1, len1, len2);
+
+  unit_bytes = UNIT_BYTES (mt1->format);
+  from1_byte = POS_CHAR_TO_BYTE (mt1, from1) * unit_bytes;
+  from2_byte = POS_CHAR_TO_BYTE (mt2, from2) * unit_bytes;
+  old_bytes = POS_CHAR_TO_BYTE (mt1, to1) * unit_bytes - from1_byte;
+  new_bytes = POS_CHAR_TO_BYTE (mt2, to2) * unit_bytes - from2_byte;
+  total_bytes = mt1->nbytes * unit_bytes + (new_bytes - old_bytes);
+  if (total_bytes + unit_bytes > mt1->allocated)
+    {
+      mt1->allocated = total_bytes + unit_bytes;
+      MTABLE_REALLOC (mt1->data, mt1->allocated, MERROR_MTEXT);
+    }
+  p = mt1->data + from1_byte;
+  if (to1 < mt1->nchars
+      && old_bytes != new_bytes)
+    memmove (p + new_bytes, p + old_bytes,
+            (mt1->nbytes + 1) * unit_bytes - (from1_byte + old_bytes));
+  memcpy (p, mt2->data + from2_byte, new_bytes);
+  mt1->nchars += len2 - len1;
+  mt1->nbytes += (new_bytes - old_bytes) / unit_bytes;
+  if (mt1->cache_char_pos >= to1)
+    {
+      mt1->cache_char_pos += len2 - len1;
+      mt1->cache_byte_pos += new_bytes - old_bytes;
+    }
+  else if (mt1->cache_char_pos > from1)
+    {
+      mt1->cache_char_pos = from1;
+      mt1->cache_byte_pos = from1_byte;
+    }
+
+  if (free_mt2)
+    M17N_OBJECT_UNREF (mt2);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Search a character in an M-text.
+
+    The mtext_character () function searches M-text $MT for character
+    $C.  If $FROM is less than $TO, the search begins at position $FROM
+    and goes forward but does not exceed ($TO - 1).  Otherwise, the search
+    begins at position ($FROM - 1) and goes backward but does not
+    exceed $TO.  An invalid position specification is regarded as both
+    $FROM and $TO being 0.
+
+    @return
+    If $C is found, mtext_character () returns the position of its
+    first occurrence.  Otherwise it returns -1 without changing the
+    external variable #merror_code.  If an error is detected, it returns -1 and
+    assigns an error code to the external variable #merror_code.  */
+
+/***ja
+    @brief M-text Ãæ¤Çʸ»ú¤òõ¤¹.
+
+    ´Ø¿ô mtext_character () ¤Ï M-text $MT Ãæ¤Çʸ»ú $C ¤òõ¤¹¡£¤â¤· 
+    $FROM ¤¬ $TO ¤è¤ê¾®¤µ¤±¤ì¤Ð¡¢Ãµº÷¤Ï°ÌÃÖ $FROM ¤«¤éËöÈøÊý¸þ¤Ø¡¢ºÇÂç 
+    ($TO - 1) ¤Þ¤Ç¿Ê¤à¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð°ÌÃÖ ($FROM - 1) ¤«¤éÀèƬÊý¸þ¤Ø¡¢ºÇÂç
+    $TO ¤Þ¤Ç¿Ê¤à¡£°ÌÃ֤λØÄê¤Ë¸í¤ê¤¬¤¢¤ë¾ì¹ç¤Ï¡¢$FROM ¤È $TO 
+    ¤ÎξÊý¤Ë 0 ¤¬»ØÄꤵ¤ì¤¿¤â¤Î¤È¤ß¤Ê¤¹¡£
+
+    @return
+    ¤â¤· $C ¤¬¸«¤Ä¤«¤ì¤Ð¡¢mtext_character () 
+    ¤Ï¤½¤ÎºÇ½é¤Î½Ð¸½°ÌÃÖ¤òÊÖ¤¹¡£¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï³°ÉôÊÑ¿ô #merror_code
+    ¤òÊѹ¹¤»¤º¤Ë -1 ¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô
+    #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @seealso
+    mtext_chr(), mtext_rchr ()  */
+
+int
+mtext_character (MText *mt, int from, int to, int c)
+{
+  if (from < to)
+    {
+      /* We do not use M_CHECK_RANGE () because this function should
+        not set merror_code.  */
+      if (from < 0 || to > mt->nchars)
+       return -1;
+      return find_char_forward (mt, from, to, c);
+    }
+  else
+    {
+      /* ditto */
+      if (to < 0 || from > mt->nchars)
+       return -1;
+      return find_char_backward (mt, to, from, c);
+    }
+}
+
+
+/*=*/
+
+/***en
+    @brief Return the position of the first occurrence of a character in an M-text.
+
+    The mtext_chr () function searches M-text $MT for character $C.
+    The search starts from the beginning of $MT and goes toward the end.
+
+    @return
+    If $C is found, mtext_chr () returns its position; otherwise it
+    returns -1.  */
+
+/***ja
+    @brief M-text Ãæ¤Ç»ØÄꤵ¤ì¤¿Ê¸»ú¤¬ºÇ½é¤Ë¸½¤ì¤ë°ÌÃÖ¤òÊÖ¤¹.
+
+    ´Ø¿ô mtext_chr () ¤Ï M-text $MT Ãæ¤Çʸ»ú $C ¤òõ¤¹¡£Ãµº÷¤Ï $MT 
+    ¤ÎÀèƬ¤«¤éËöÈøÊý¸þ¤Ë¿Ê¤à¡£
+
+    @return
+    ¤â¤· $C ¤¬¸«¤Ä¤«¤ì¤Ð¡¢mtext_chr () 
+    ¤Ï¤½¤Î½Ð¸½°ÌÃÖ¤òÊÖ¤¹¡£¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï -1 ¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mtext_chr} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE
+
+    @seealso
+    mtext_rchr (), mtext_character ()  */
+
+int
+mtext_chr (MText *mt, int c)
+{
+  return find_char_forward (mt, 0, mt->nchars, c);
+}
+
+/*=*/
+
+/***en
+    @brief Return the position of the last occurrence of a character in an M-text.
+
+    The mtext_rchr () function searches M-text $MT for character $C.
+    The search starts from the end of $MT and goes backwardly toward the
+    beginning.
+
+    @return
+    If $C is found, mtext_rchr () returns its position; otherwise it
+    returns -1.  */
+
+/***ja
+    @brief M-text Ãæ¤Ç»ØÄꤵ¤ì¤¿Ê¸»ú¤¬ºÇ¸å¤Ë¸½¤ì¤ë°ÌÃÖ¤òÊÖ¤¹.
+
+    ´Ø¿ô mtext_rchr () ¤Ï M-text $MT Ãæ¤Çʸ»ú $C ¤òõ¤¹¡£Ãµº÷¤Ï $MT 
+    ¤ÎºÇ¸å¤«¤éÀèƬÊý¸þ¤Ø¤È¸å¸þ¤­¤Ë¿Ê¤à¡£
+
+    @return
+    ¤â¤· $C ¤¬¸«¤Ä¤«¤ì¤Ð¡¢mtext_rchr () 
+    ¤Ï¤½¤Î½Ð¸½°ÌÃÖ¤òÊÖ¤¹¡£¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï -1 ¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mtext_rchr} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE
+
+    @seealso
+    mtext_chr (), mtext_character ()  */
+
+int
+mtext_rchr (MText *mt, int c)
+{
+  return find_char_backward (mt, mt->nchars, 0, c);
+}
+
+
+/*=*/
+
+/***en
+    @brief Compare two M-texts character-by-character.
+
+    The mtext_cmp () function compares M-texts $MT1 and $MT2 character
+    by character.
+
+    @return
+    This function returns 1, 0, or -1 if $MT1 is found greater than,
+    equal to, or less than $MT2, respectively.  Comparison is based on
+    character codes.  */
+
+/***ja
+    @brief Æó¤Ä¤Î M-text ¤òʸ»úñ°Ì¤ÇÈæ³Ó¤¹¤ë.
+
+    ´Ø¿ô mtext_cmp () ¤Ï¡¢ M-text $MT1 ¤È $MT2 ¤òʸ»úñ°Ì¤ÇÈæ³Ó¤¹¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¡¢$MT1 ¤È $MT2 ¤¬Åù¤·¤±¤ì¤Ð 0¡¢$MT1 ¤¬ $MT2 ¤è¤êÂ礭¤±¤ì¤Ð
+    1¡¢$MT1 ¤¬ $MT2 ¤è¤ê¾®¤µ¤±¤ì¤Ð -1 ¤òÊÖ¤¹¡£Èæ³Ó¤Ïʸ»ú¥³¡¼¥É¤Ë´ð¤Å¤¯¡£
+
+    @latexonly \IPAlabel{mtext_cmp} @endlatexonly  */
+
+/***
+    @seealso
+    mtext_ncmp (), mtext_casecmp (), mtext_ncasecmp (),
+    mtext_compare (), mtext_case_compare ()  */
+
+int
+mtext_cmp (MText *mt1, MText *mt2)
+{
+  return compare (mt1, 0, mt1->nchars, mt2, 0, mt2->nchars);
+}
+
+
+/*=*/
+
+/***en
+    @brief Compare initial parts of two M-texts character-by-character.
+
+    The mtext_ncmp () function is similar to mtext_cmp (), but
+    compares at most $N characters from the beginning.
+
+    @return
+    This function returns 1, 0, or -1 if $MT1 is found greater than,
+    equal to, or less than $MT2, respectively.  */
+
+/***ja
+    @brief Æó¤Ä¤Î M-text ¤ÎÀèƬÉôʬ¤òʸ»úñ°Ì¤ÇÈæ³Ó¤¹¤ë.
+
+    ´Ø¿ô mtext_ncmp () ¤Ï¡¢´Ø¿ô mtext_cmp () Æ±ÍͤΠM-text 
+    Æ±»Î¤ÎÈæ³Ó¤òÀèƬ¤«¤éºÇÂç $N Ê¸»ú¤Þ¤Ç¤Ë´Ø¤·¤Æ¹Ô¤Ê¤¦¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¡¢$MT1 ¤È $MT2 ¤¬Åù¤·¤±¤ì¤Ð 0¡¢$MT1 ¤¬ $MT2 ¤è¤êÂ礭¤±¤ì¤Ð 
+    1¡¢$MT1 ¤¬ $MT2 ¤è¤ê¾®¤µ¤±¤ì¤Ð -1 ¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mtext_ncmp} @endlatexonly  */
+
+/***
+    @seealso
+    mtext_cmp (), mtext_casecmp (), mtext_ncasecmp ()
+    mtext_compare (), mtext_case_compare ()  */
+
+int
+mtext_ncmp (MText *mt1, MText *mt2, int n)
+{
+  if (n < 0)
+    return 0;
+  return compare (mt1, 0, (mt1->nchars < n ? mt1->nchars : n),
+                 mt2, 0, (mt2->nchars < n ? mt2->nchars : n));
+}
+
+/*=*/
+
+/***en
+    @brief Compare specified regions of two M-texts.
+
+    The mtext_compare () function compares two M-texts $MT1 and $MT2,
+    character-by-character.  The compared regions are between $FROM1
+    and $TO1 in $MT1 and $FROM2 to $TO2 in MT2.  $FROM1 and $FROM2 are
+    inclusive, $TO1 and $TO2 are exclusive.  $FROM1 being equal to
+    $TO1 (or $FROM2 being equal to $TO2) means an M-text of length
+    zero.  An invalid region specification is regarded as both $FROM1
+    and $TO1 (or $FROM2 and $TO2) being 0.
+
+    @return
+    This function returns 1, 0, or -1 if $MT1 is found greater than,
+    equal to, or less than $MT2, respectively.  Comparison is based on
+    character codes.  */
+
+/***ja
+    @brief Æó¤Ä¤Î M-text ¤Î»ØÄꤷ¤¿ÎΰèƱ»Î¤òÈæ³Ó¤¹¤ë.
+
+    ´Ø¿ô mtext_compare () ¤ÏÆó¤Ä¤Î M-text $MT1 ¤È $MT2 
+    ¤òʸ»úñ°Ì¤ÇÈæ³Ó¤¹¤ë¡£Èæ³Ó¤ÎÂоݤϠ$MT1 ¤Î¤¦¤Á $FROM1 ¤«¤é $TO1 ¤Þ¤Ç¤È¡¢$MT2 
+    ¤Î¤¦¤Á $FROM2 ¤«¤é $TO2 ¤Þ¤Ç¤Ç¤¢¤ë¡£$FROM1 ¤È $FROM2 ¤Ï´Þ¤Þ¤ì¡¢$TO1 
+    ¤È $TO2 ¤Ï´Þ¤Þ¤ì¤Ê¤¤¡£$FROM1 ¤È $TO1 ¡Ê¤¢¤ë¤¤¤Ï $FROM2 ¤È $TO2 
+    ¡Ë¤¬Åù¤·¤¤¾ì¹ç¤ÏŤµ¥¼¥í¤Î M-text ¤ò°ÕÌ£¤¹¤ë¡£ÈÏ°Ï»ØÄê¤Ë¸í¤ê¤¬¤¢¤ë¾ì¹ç¤Ï¡¢
+    $FROM1 ¤È $TO1 ¡Ê¤¢¤ë¤¤¤Ï $FROM2 ¤È $TO2 ¡Ë Î¾Êý¤Ë 0 ¤¬»ØÄꤵ¤ì¤¿¤â¤Î¤È¤ß¤Ê¤¹¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¡¢$MT1 ¤È $MT2 ¤¬Åù¤·¤±¤ì¤Ð 0¡¢$MT1 ¤¬ $MT2 ¤è¤êÂ礭¤±¤ì¤Ð
+    1 ¡¢$MT1 ¤¬ $MT2 ¤è¤ê¾®¤µ¤±¤ì¤Ð -1 ¤òÊÖ¤¹¡£Èæ³Ó¤Ïʸ»ú¥³¡¼¥É¤Ë´ð¤Å¤¯¡£  */
+
+/***
+    @seealso
+    mtext_cmp (), mtext_ncmp (), mtext_casecmp (), mtext_ncasecmp (),
+    mtext_case_compare ()  */
+
+int
+mtext_compare (MText *mt1, int from1, int to1, MText *mt2, int from2, int to2)
+{
+  if (from1 < 0 || from1 > to1 || to1 > mt1->nchars)
+    from1 = to1 = 0;
+
+  if (from2 < 0 || from2 > to2 || to2 > mt2->nchars)
+    from2 = to2 = 0;
+
+  return compare (mt1, from1, to1, mt2, from2, to2);
+}
+
+/*=*/
+
+/***en
+    @brief Search an M-text for a set of characters.
+
+    The mtext_spn () function returns the length of the initial
+    segment of M-text $MT1 that consists entirely of characters in
+    M-text $MT2.  */
+
+/***ja
+    @brief ¤¢¤ë½¸¹ç¤Îʸ»ú¤ò M-text ¤ÎÃæ¤Çõ¤¹.
+
+    ´Ø¿ô mtext_spn () ¤Ï¡¢M-text $MT1 ¤ÎÀèƬ¤«¤é M-text $MT2 
+    ¤Ë´Þ¤Þ¤ì¤ëʸ»ú¤À¤±¤Ç¤Ç¤­¤Æ¤¤¤ëÉôʬ¤ÎŤµ¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mtext_spn} @endlatexonly  */
+
+/***
+    @seealso
+    mtext_cspn ()  */
+
+int
+mtext_spn (MText *mt, MText *accept)
+{
+  return span (mt, accept, 0, Mnil);
+}
+
+/*=*/
+
+/***en
+    @brief Search an M-text for the complement of a set of characters.
+
+    The mtext_cspn () returns the length of the initial segment of
+    M-text $MT1 that consists entirely of characters not in M-text $MT2.  */
+
+/***ja
+    @brief ¤¢¤ë½¸¹ç¤Ë°¤µ¤Ê¤¤Ê¸»ú¤ò M-text ¤ÎÃæ¤Çõ¤¹.
+
+    ´Ø¿ô mtext_cspn () ¤Ï¡¢M-text $MT1 ¤ÎÀèƬÉôʬ¤Ç M-text $MT2
+    ¤Ë´Þ¤Þ¤ì¤Ê¤¤Ê¸»ú¤À¤±¤Ç¤Ç¤­¤Æ¤¤¤ëÉôʬ¤ÎŤµ¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mtext_cspn} @endlatexonly  */
+
+/***
+    @seealso
+    mtext_spn ()  */
+
+int
+mtext_cspn (MText *mt, MText *reject)
+{
+  return span (mt, reject, 0, Mt);
+}
+
+/*=*/
+
+/***en
+    @brief Search an M-text for any of a set of characters.
+
+    The mtext_pbrk () function locates the first occurrence in M-text
+    $MT1 of any of the characters in M-text $MT2.
+
+    @return
+    This function returns the position in $MT1 of the found character.
+    If no such character is found, it returns -1. */
+
+/***ja
+    @brief ¤¢¤ë½¸¹ç¤Ë°¤¹Ê¸»ú¤ò M-text ¤ÎÃ椫¤éõ¤¹.
+
+    ´Ø¿ô mtext_pbrk () ¤Ï¡¢M-text $MT1 Ãæ¤Ç M-text $MT2 
+    ¤Îʸ»ú¤Î¤É¤ì¤«¤¬ºÇ½é¤Ë¸½¤ì¤ë°ÌÃÖ¤òÄ´¤Ù¤ë¡£
+
+    @return 
+    ¸«¤Ä¤«¤Ã¤¿Ê¸»ú¤Î¡¢$MT1 
+    Æâ¤Ë¤ª¤±¤ë½Ð¸½°ÌÃÖ¤òÊÖ¤¹¡£¤â¤·¤½¤Î¤è¤¦¤Êʸ»ú¤¬¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mtext_pbrk} @endlatexonly  */
+
+int
+mtext_pbrk (MText *mt, MText *accept)
+{
+  int nchars = mtext_nchars (mt);
+  int len = span (mt, accept, 0, Mt);
+
+  return (len == nchars ? -1 : len);
+}
+
+/*=*/
+
+/***en
+    @brief Look for a token in an M-text.
+
+    The mtext_tok () function searches a token that firstly occurs
+    after position $POS in M-text $MT.  Here, a token means a
+    substring each of which does not appear in M-text $DELIM.  Note
+    that the type of $POS is not @c int but pointer to @c int.
+
+    @return
+    If a token is found, mtext_tok () copies the corresponding part of
+    $MT and returns a pointer to the copy.  In this case, $POS is set
+    to the end of the found token.  If no token is found, it returns
+    @c NULL without changing the external variable #merror_code.  If an
+    error is detected, it returns @c NULL and assigns an error code
+    to the external variable #merror_code. */
+
+/***ja
+    @brief M-text Ãæ¤Î¥È¡¼¥¯¥ó¤òõ¤¹.
+
+    ´Ø¿ô mtext_tok () ¤Ï¡¢M-text $MT ¤ÎÃæ¤Ç°ÌÃÖ $POS 
+    °Ê¹ßºÇ½é¤Ë¸½¤ì¤ë¥È¡¼¥¯¥ó¤òõ¤¹¡£¤³¤³¤Ç¥È¡¼¥¯¥ó¤È¤Ï M-text $DELIM
+    ¤ÎÃæ¤Ë¸½¤ï¤ì¤Ê¤¤Ê¸»ú¤À¤±¤«¤é¤Ê¤ëÉôʬʸ»úÎó¤Ç¤¢¤ë¡£$POS ¤Î·¿¤¬ @c int ¤Ç¤Ï¤Ê¤¯¤Æ @c
+    int ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¤³¤È¤ËÃí°Õ¡£
+
+    @return
+    ¤â¤·¥È¡¼¥¯¥ó¤¬¸«¤Ä¤«¤ì¤Ð mtext_tok ()¤Ï¤½¤Î¥È¡¼¥¯¥ó¤ËÁêÅö¤¹¤ëÉôʬ¤Î 
+    $MT ¤ò¥³¥Ô¡¼¤·¡¢¤½¤Î¥³¥Ô¡¼¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¤³¤Î¾ì¹ç¡¢$POS 
+    ¤Ï¸«¤Ä¤«¤Ã¤¿¥È¡¼¥¯¥ó¤Î½ªÃ¼¤Ë¥»¥Ã¥È¤µ¤ì¤ë¡£¥È¡¼¥¯¥ó¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï³°ÉôÊÑ¿ô
+    #merror_code ¤òÊѤ¨¤º¤Ë @c NULL ¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï 
+    @c NULL ¤òÊÖ¤·¡¢ÊÑÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mtext_tok} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE  */
+
+MText *
+mtext_tok (MText *mt, MText *delim, int *pos)
+{
+  int nchars = mtext_nchars (mt);
+  int pos2;
+
+  M_CHECK_POS (mt, *pos, NULL);
+
+  /*
+    Skip delimiters starting at POS in MT.
+    Never do *pos += span(...), or you will change *pos
+    even though no token is found.
+   */
+  pos2 = *pos + span (mt, delim, *pos, Mnil);
+
+  if (pos2 == nchars)
+    return NULL;
+
+  *pos = pos2 + span (mt, delim, pos2, Mt);
+  return (insert (mtext (), 0, mt, pos2, *pos));
+}
+
+/*=*/
+
+/***en
+    @brief Locate an M-text in another.
+
+    The mtext_text () function finds the first occurrence of M-text
+    $MT2 in M-text $MT1 after the position $POS while ignoring
+    difference of the text properties.
+
+    @return
+    If $MT2 is found in $MT1, mtext_text () returns the position of it
+    first occurrence.  Otherwise it returns -1.  If $MT2 is empty, it
+    returns 0.  */
+
+/***ja
+    @brief M-text Ãæ¤ÇÊ̤ΠM-text ¤òõ¤¹.
+
+    ´Ø¿ô mtext_text () ¤Ï¡¢M-text $MT1 Ãæ¤Ç°ÌÃÖ $POS °Ê¹ß¤Ë¸½¤ï¤ì¤ë 
+    M-text $MT2 ¤ÎºÇ½é¤Î°ÌÃÖ¤òÄ´¤Ù¤ë¡£¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î°ã¤¤¤Ï̵»ë¤µ¤ì¤ë¡£
+
+    @return
+    $MT1 Ãæ¤Ë $MT2 ¤¬¸«¤Ä¤«¤ì¤Ð¡¢mtext_text() 
+    ¤Ï¤½¤ÎºÇ½é¤Î½Ð¸½°ÌÃÖ¤òÊÖ¤¹¡£¸«¤Ä¤«¤é¤Ê¤¤¾ì¹ç¤Ï -1 ¤òÊÖ¤¹¡£¤â¤· $MT2 ¤¬¶õ¤Ê¤é¤Ð 0 ¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mtext_text} @endlatexonly  */
+
+int
+mtext_text (MText *mt1, int pos, MText *mt2)
+{
+  int from = pos;
+  int c = mtext_ref_char (mt2, 0);
+  int nbytes2 = mtext_nbytes (mt2);
+  int limit;
+  int use_memcmp = (mt1->format == mt2->format
+                   || (mt1->format < MTEXT_FORMAT_UTF_8
+                       && mt2->format == MTEXT_FORMAT_UTF_8));
+  int unit_bytes = UNIT_BYTES (mt1->format);
+
+  if (from + mtext_nchars (mt2) > mtext_nchars (mt1))
+    return -1;
+  limit = mtext_nchars (mt1) - mtext_nchars (mt2) + 1;
+
+  while (1)
+    {
+      int pos_byte;
+
+      if ((pos = mtext_character (mt1, from, limit, c)) < 0)
+       return -1;
+      pos_byte = POS_CHAR_TO_BYTE (mt1, pos);
+      if (use_memcmp
+         ? ! memcmp (mt1->data + pos_byte * unit_bytes, 
+                     mt2->data, nbytes2 * unit_bytes)
+         : ! compare (mt1, pos, mt2->nchars, mt2, 0, mt2->nchars))
+       break;
+      from = pos + 1;
+    }
+  return pos;
+}
+
+/***en
+    @brief Locate an M-text in a specific range of another.
+
+    The mtext_search () function searches for the first occurrence of
+    M-text $MT2 in M-text $MT1 in the region $FROM and $TO while
+    ignoring difference of the text properties.  If $FROM is less than
+    $TO, the forward search starts from $FROM, otherwise the backward
+    search starts from $TO.
+
+    @return
+    If $MT2 is found in $MT1, mtext_search () returns the position of the
+    first occurrence.  Otherwise it returns -1.  If $MT2 is empty, it
+    returns 0.  */
+
+/***ja
+    @brief M-text Ãæ¤ÎÆÃÄê¤ÎÎΰè¤ÇÊ̤ΠM-text ¤òõ¤¹.
+
+    ´Ø¿ô mtext_search () ¤Ï¡¢M-text $MT1 Ãæ¤Î $FROM ¤«¤é $TO 
+    ¤Þ¤Ç¤Î´Ö¤ÎÎΰè¤ÇM-text $MT2 
+    ¤¬ºÇ½é¤Ë¸½¤ï¤ì¤ë°ÌÃÖ¤òÄ´¤Ù¤ë¡£¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î°ã¤¤¤Ï̵»ë¤µ¤ì¤ë¡£¤â¤·
+    $FROM ¤¬ $TO ¤è¤ê¾®¤µ¤±¤ì¤Ðõº÷¤Ï°ÌÃÖ $FROM ¤«¤éËöÈøÊý¸þ¤Ø¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð
+    $TO ¤«¤éÀèƬÊý¸þ¤Ø¿Ê¤à¡£
+
+    @return
+    $MT1 Ãæ¤Ë $MT2 ¤¬¸«¤Ä¤«¤ì¤Ð¡¢mtext_search() 
+    ¤Ï¤½¤ÎºÇ½é¤Î½Ð¸½°ÌÃÖ¤òÊÖ¤¹¡£¸«¤Ä¤«¤é¤Ê¤¤¾ì¹ç¤Ï -1 ¤òÊÖ¤¹¡£¤â¤· $MT2 ¤¬¶õ¤Ê¤é¤Ð 0 ¤òÊÖ¤¹¡£
+    */
+
+int
+mtext_search (MText *mt1, int from, int to, MText *mt2)
+{
+  int c = mtext_ref_char (mt2, 0);
+  int from_byte;
+  int nbytes2 = mtext_nbytes (mt2);
+
+  if (mt1->format > MTEXT_FORMAT_UTF_8
+      || mt2->format > MTEXT_FORMAT_UTF_8)
+    MERROR (MERROR_MTEXT, -1);
+
+  if (from < to)
+    {
+      to -= mtext_nchars (mt2);
+      if (from > to)
+       return -1;
+      while (1)
+       {
+         if ((from = find_char_forward (mt1, from, to, c)) < 0)
+           return -1;
+         from_byte = POS_CHAR_TO_BYTE (mt1, from);
+         if (! memcmp (mt1->data + from_byte, mt2->data, nbytes2))
+           break;
+         from++;
+       }
+    }
+  else if (from > to)
+    {
+      from -= mtext_nchars (mt2);
+      if (from < to)
+       return -1;
+      while (1)
+       {
+         if ((from = find_char_backward (mt1, to, from + 1, c)) < 0)
+           return -1;
+         from_byte = POS_CHAR_TO_BYTE (mt1, from);
+         if (! memcmp (mt1->data + from_byte, mt2->data, nbytes2))
+           break;
+         from--;
+       }
+    }
+
+  return from;
+}
+
+/*=*/
+
+/***en
+    @brief Compare two M-texts ignoring cases.
+
+    The mtext_casecmp () function is similar to mtext_cmp (), but
+    ignores cases on comparison.
+
+    @return
+    This function returns 1, 0, or -1 if $MT1 is found greater than,
+    equal to, or less than $MT2, respectively.  */
+
+/***ja
+    @brief Æó¤Ä¤Î M-text ¤òÂçʸ»ú¡¿¾®Ê¸»ú¤Î¶èÊ̤ò̵»ë¤·¤ÆÈæ³Ó¤¹¤ë.
+
+    ´Ø¿ô mtext_casecmp () ¤Ï¡¢´Ø¿ô mtext_cmp () Æ±ÍͤΠM-text 
+    Æ±»Î¤ÎÈæ³Ó¤ò¡¢Âçʸ»ú¡¿¾®Ê¸»ú¤Î¶èÊ̤ò̵»ë¤·¤Æ¹Ô¤Ê¤¦¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¡¢$MT1 ¤È $MT2 ¤¬Åù¤·¤±¤ì¤Ð 0¡¢$MT1 ¤¬ $MT2 
+    ¤è¤êÂ礭¤±¤ì¤Ð 1¡¢$MT1 ¤¬ $MT2 ¤è¤ê¾®¤µ¤±¤ì¤Ð -1 ¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mtext_casecmp} @endlatexonly  */
+
+/***
+    @seealso
+    mtext_cmp (), mtext_ncmp (), mtext_ncasecmp ()
+    mtext_compare (), mtext_case_compare ()  */
+
+int
+mtext_casecmp (MText *mt1, MText *mt2)
+{
+  return case_compare (mt1, 0, mt1->nchars, mt2, 0, mt2->nchars);
+}
+
+/*=*/
+
+/***en
+    @brief Compare initial parts of two M-texts ignoring cases.
+
+    The mtext_ncasecmp () function is similar to mtext_casecmp (), but
+    compares at most $N characters from the beginning.
+
+    @return
+    This function returns 1, 0, or -1 if $MT1 is found greater than,
+    equal to, or less than $MT2, respectively.  */
+
+/***ja
+    @brief Æó¤Ä¤Î M-text ¤ÎÀèƬÉôʬ¤òÂçʸ»ú¡¿¾®Ê¸»ú¤Î¶èÊ̤ò̵»ë¤·¤ÆÈæ³Ó¤¹¤ë.
+
+    ´Ø¿ô mtext_ncasecmp () ¤Ï¡¢´Ø¿ô mtext_casecmp () Æ±ÍͤΠM-text 
+    Æ±»Î¤ÎÈæ³Ó¤òÀèƬ¤«¤éºÇÂç $N Ê¸»ú¤Þ¤Ç¤Ë´Ø¤·¤Æ¹Ô¤Ê¤¦¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¡¢$MT1 ¤È $MT2 ¤¬Åù¤·¤±¤ì¤Ð 0¡¢$MT1 ¤¬ $MT2 
+    ¤è¤êÂ礭¤±¤ì¤Ð 1¡¢$MT1 ¤¬ $MT2 ¤è¤ê¾®¤µ¤±¤ì¤Ð -1 ¤òÊÖ¤¹¡£
+
+    @latexonly \IPAlabel{mtext_ncasecmp} @endlatexonly  */
+
+/***
+    @seealso
+    mtext_cmp (), mtext_casecmp (), mtext_casecmp ()
+    mtext_compare (), mtext_case_compare ()  */
+
+int
+mtext_ncasecmp (MText *mt1, MText *mt2, int n)
+{
+  if (n < 0)
+    return 0;
+  return case_compare (mt1, 0, (mt1->nchars < n ? mt1->nchars : n),
+                      mt2, 0, (mt2->nchars < n ? mt2->nchars : n));
+}
+
+/*=*/
+
+/***en
+    @brief Compare specified regions of two M-texts ignoring cases. 
+
+    The mtext_case_compare () function compares two M-texts $MT1 and
+    $MT2, character-by-character, ignoring cases.  The compared
+    regions are between $FROM1 and $TO1 in $MT1 and $FROM2 to $TO2 in
+    MT2.  $FROM1 and $FROM2 are inclusive, $TO1 and $TO2 are
+    exclusive.  $FROM1 being equal to $TO1 (or $FROM2 being equal to
+    $TO2) means an M-text of length zero.  An invalid region
+    specification is regarded as both $FROM1 and $TO1 (or $FROM2 and
+    $TO2) being 0.
+
+    @return
+    This function returns 1, 0, or -1 if $MT1 is found greater than,
+    equal to, or less than $MT2, respectively.  Comparison is based on
+    character codes.  */
+
+/***ja 
+    @brief Æó¤Ä¤Î M-text ¤Î»ØÄꤷ¤¿Îΰè¤ò¡¢Âçʸ»ú¡¿¾®Ê¸»ú¤Î¶èÊ̤ò̵»ë¤·¤ÆÈæ³Ó¤¹¤ë.
+
+    ´Ø¿ô mtext_compare () ¤ÏÆó¤Ä¤Î M-text $MT1 ¤È $MT2 
+    ¤ò¡¢Âçʸ»ú¡¿¾®Ê¸»ú¤Î¶èÊ̤ò̵»ë¤·¤Æʸ»úñ°Ì¤ÇÈæ³Ó¤¹¤ë¡£Èæ³Ó¤ÎÂоݤϠ$MT1 
+    ¤Î $FROM1 ¤«¤é $TO1 ¤Þ¤Ç¡¢$MT2 ¤Î $FROM2 ¤«¤é $TO2 ¤Þ¤Ç¤Ç¤¢¤ë¡£
+    $FROM1 ¤È $FROM2 ¤Ï´Þ¤Þ¤ì¡¢$TO1 ¤È $TO2 ¤Ï´Þ¤Þ¤ì¤Ê¤¤¡£$FROM1 ¤È $TO1
+    ¡Ê¤¢¤ë¤¤¤Ï $FROM2 ¤È $TO2 ¡Ë¤¬Åù¤·¤¤¾ì¹ç¤ÏŤµ¥¼¥í¤Î M-text 
+    ¤ò°ÕÌ£¤¹¤ë¡£ÈÏ°Ï»ØÄê¤Ë¸í¤ê¤¬¤¢¤ë¾ì¹ç¤Ï¡¢$FROM1 ¤È $TO1 ¡Ê¤¢¤ë¤¤¤Ï 
+    $FROM2 ¤È $TO2 ¡ËξÊý¤Ë 0 ¤¬»ØÄꤵ¤ì¤¿¤â¤Î¤È¸«¤Ê¤¹¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¡¢$MT1 ¤È $MT2 ¤¬Åù¤·¤±¤ì¤Ð 0¡¢$MT1 ¤¬ $MT2 ¤è¤êÂ礭¤±¤ì¤Ð
+    1¡¢$MT1 ¤¬ $MT2 ¤è¤ê¾®¤µ¤±¤ì¤Ð -1¤òÊÖ¤¹¡£Èæ³Ó¤Ïʸ»ú¥³¡¼¥É¤Ë´ð¤Å¤¯¡£
+
+  @latexonly \IPAlabel{mtext_case_compare} @endlatexonly
+*/
+
+/***
+    @seealso
+    mtext_cmp (), mtext_ncmp (), mtext_casecmp (), mtext_ncasecmp (),
+    mtext_compare ()  */
+
+int
+mtext_case_compare (MText *mt1, int from1, int to1,
+                   MText *mt2, int from2, int to2)
+{
+  if (from1 < 0 || from1 > to1 || to1 > mt1->nchars)
+    from1 = to1 = 0;
+
+  if (from2 < 0 || from2 > to2 || to2 > mt2->nchars)
+    from2 = to2 = 0;
+
+  return case_compare (mt1, from1, to1, mt2, from2, to2);
+}
+
+/*=*/
+
+/***en
+    @brief Lowercase an M-text.
+
+    The mtext_lowercase () function destructively converts each
+    character in M-text $MT to lowercase.  Adjacent characters in $MT
+    may affect the case conversion.  If the Mlanguage text property is
+    attached to $MT, it may also affect the conversion.  The length of
+    $MT may change.  Characters that cannot be converted to lowercase
+    is left unchanged.  All the text properties are inherited.
+
+    @return
+    This function returns the length of the updated $MT.
+*/
+
+/***ja
+    @brief M-text ¤ò¾®Ê¸»ú¤Ë¤¹¤ë.
+
+    ´Ø¿ô mtext_lowercase () ¤Ï M-text $MT Ãæ¤Î³Æʸ»ú¤òÇ˲õŪ¤Ë¾®Ê¸»ú¤ËÊÑ
+    ´¹¤¹¤ë¡£ÊÑ´¹¤ËºÝ¤·¤ÆÎÙÀܤ¹¤ëʸ»ú¤Î±Æ¶Á¤ò¼õ¤±¤ë¤³¤È¤¬¤¢¤ë¡£$MT ¤Ë¥Æ
+    ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ Mlanguage ¤¬ÉÕ¤¤¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢¤½¤ì¤âÊÑ´¹¤Ë±Æ¶Á¤ò
+    Í¿¤¨¤¦¤ë¡£$MT ¤ÎŤµ¤ÏÊѤï¤ë¤³¤È¤¬¤¢¤ë¡£¾®Ê¸»ú¤ËÊÑ´¹¤Ç¤­¤Ê¤«¤Ã¤¿Ê¸
+    »ú¤Ï¤½¤Î¤Þ¤Þ»Ä¤ë¡£¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù¤Æ·Ñ¾µ¤µ¤ì¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¹¹¿·¸å¤Î $MT ¤ÎŤµ¤òÊÖ¤¹¡£
+*/
+
+/***
+    @seealso
+     mtext_titlecase (), mtext_uppercase ()
+*/
+
+int
+mtext_lowercase (MText *mt)
+
+{
+  CASE_CONV_INIT (-1);
+
+  return mtext__lowercase (mt, 0, mtext_len (mt));
+}
+
+/*=*/
+
+/***en
+    @brief Titlecase an M-text.
+
+    The mtext_titlecase () function destructively converts the first
+    character with the cased property in M-text $MT to titlecase and
+    the others to lowercase.  The length of $MT may change.  If the
+    character cannot be converted to titlecase, it is left unchanged.
+    All the text properties are inherited.
+
+    @return
+    This function returns the length of the updated $MT.
+*/
+
+/***ja
+    @brief M-text ¤ò¥¿¥¤¥È¥ë¥±¡¼¥¹¤Ë¤¹¤ë.
+
+    ´Ø¿ô mtext_titlecase () ¤Ï M-text $MT Ãæ¤Ç cased ¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä
+    ºÇ½é¤Îʸ»ú¤ò¥¿¥¤¥È¥ë¥±¡¼¥¹¤Ë¡¢¤½¤·¤Æ¤½¤ì°Ê¹ß¤Îʸ»ú¤ò¾®Ê¸»ú¤ËÇ˲õŪ
+    ¤ËÊÑ´¹¤¹¤ë¡£$MT ¤ÎŤµ¤ÏÊѤï¤ë¤³¤È¤¬¤¢¤ë¡£¥¿¥¤¥È¥ë¥±¡¼¥¹¤Ë¤ËÊÑ´¹¤Ç
+    ¤­¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï¤½¤Î¤Þ¤Þ¤ÇÊѤï¤é¤Ê¤¤¡£¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù¤Æ·Ñ
+    ¾µ¤µ¤ì¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¹¹¿·¸å¤Î $MT ¤ÎŤµ¤òÊÖ¤¹¡£
+*/
+
+/***
+    @seealso
+     mtext_lowercase (), mtext_uppercase ()
+*/
+
+int
+mtext_titlecase (MText *mt)
+{
+  int len = mtext_len (mt), from, to;
+
+  CASE_CONV_INIT (-1);
+
+  /* Find 1st cased character. */
+  for (from = 0; from < len; from++)
+    {
+      int csd = (int) mchartable_lookup (cased, mtext_ref_char (mt, from));
+
+      if (csd > 0 && csd & CASED)
+       break;
+    }
+
+  if (from == len)
+    return len;
+
+  if (from == len - 1)
+    return (mtext__titlecase (mt, from, len));
+
+  /* Go through following combining characters. */
+  for (to = from + 1;
+       (to < len
+       && ((int) mchartable_lookup (combining_class, mtext_ref_char (mt, to))
+           > 0));
+       to++);
+
+  /* Titlecase the region and prepare for next lowercase operation.
+     MT may be shortened or lengthened. */
+  from = mtext__titlecase (mt, from, to);
+
+  return (mtext__lowercase (mt, from, mtext_len (mt)));
+}
+
+/*=*/
+
+/***en
+    @brief Uppercase an M-text.
+
+
+    The mtext_uppercase () function destructively converts each
+    character in M-text $MT to uppercase.  Adjacent characters in $MT
+    may affect the case conversion.  If the Mlanguage text property is
+    attached to $MT, it may also affect the conversion.  The length of
+    $MT may change.  Characters that cannot be converted to uppercase
+    is left unchanged.  All the text properties are inherited.
+
+    @return
+    This function returns the length of the updated $MT.
+*/
+
+/***ja
+    @brief M-text ¤òÂçʸ»ú¤Ë¤¹¤ë.
+
+    ´Ø¿ô mtext_uppercase () ¤Ï M-text $MT Ãæ¤Î³Æʸ»ú¤òÇ˲õŪ¤ËÂçʸ»ú¤ËÊÑ
+    ´¹¤¹¤ë¡£ÊÑ´¹¤ËºÝ¤·¤ÆÎÙÀܤ¹¤ëʸ»ú¤Î±Æ¶Á¤ò¼õ¤±¤ë¤³¤È¤¬¤¢¤ë¡£$MT ¤Ë¥Æ
+    ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ Mlanguage ¤¬ÉÕ¤¤¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢¤½¤ì¤âÊÑ´¹¤Ë±Æ¶Á¤ò
+    Í¿¤¨¤¦¤ë¡£$MT ¤ÎŤµ¤ÏÊѤï¤ë¤³¤È¤¬¤¢¤ë¡£Âçʸ»ú¤ËÊÑ´¹¤Ç¤­¤Ê¤«¤Ã¤¿Ê¸
+    »ú¤Ï¤½¤Î¤Þ¤Þ»Ä¤ë¡£¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù¤Æ·Ñ¾µ¤µ¤ì¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¹¹¿·¸å¤Î $MT ¤ÎŤµ¤òÊÖ¤¹¡£
+*/
+
+/***
+    @seealso
+     mtext_lowercase (), mtext_titlecase ()
+*/
+
+int
+mtext_uppercase (MText *mt)
+{
+  CASE_CONV_INIT (-1);
+
+  return (mtext__uppercase (mt, 0, mtext_len (mt)));
+}
+
+/*** @} */
+
+#include <stdio.h>
+
+/*** @addtogroup m17nDebug */
+/*=*/
+/*** @{  */
+
+/***en
+    @brief Dump an M-text.
+
+    The mdebug_dump_mtext () function prints the M-text $MT in a human
+    readable way to the stderr.  $INDENT specifies how many columns to
+    indent the lines but the first one.  If $FULLP is zero, this
+    function prints only a character code sequence.  Otherwise, it
+    prints the internal byte sequence and text properties as well.
+
+    @return
+    This function returns $MT.  */
+/***ja
+    @brief M-text ¤ò¥À¥ó¥×¤¹¤ë.
+
+    ´Ø¿ô mdebug_dump_mtext () ¤Ï M-text $MT ¤ò stderr 
+    ¤Ë¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç°õºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
+    $FULLP ¤¬ 0 ¤Ê¤é¤Ð¡¢Ê¸»ú¥³¡¼¥ÉÎó¤À¤±¤ò°õºþ¤¹¤ë¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢ÆâÉô¥Ð¥¤¥ÈÎó¤È¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤â°õºþ¤¹¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï $MT ¤òÊÖ¤¹¡£  */
+
+MText *
+mdebug_dump_mtext (MText *mt, int indent, int fullp)
+{
+  int i;
+
+  if (! fullp)
+    {
+      fprintf (stderr, "\"");
+      for (i = 0; i < mt->nchars; i++)
+       {
+         int c = mtext_ref_char (mt, i);
+
+         if (c == '"' || c == '\\')
+           fprintf (stderr, "\\%c", c);
+         else if ((c >= ' ' && c < 127) || c == '\n')
+           fprintf (stderr, "%c", c);
+         else
+           fprintf (stderr, "\\x%02X", c);
+       }
+      fprintf (stderr, "\"");
+      return mt;
+    }
+
+  fprintf (stderr,
+          "(mtext (size %d %d %d) (cache %d %d)",
+          mt->nchars, mt->nbytes, mt->allocated,
+          mt->cache_char_pos, mt->cache_byte_pos);
+
+  if (mt->nchars > 0)
+    {
+      char *prefix = (char *) alloca (indent + 1);
+      unsigned char *p;
+
+      memset (prefix, 32, indent);
+      prefix[indent] = 0;
+
+      fprintf (stderr, "\n%s (bytes \"", prefix);
+      for (i = 0; i < mt->nbytes; i++)
+       fprintf (stderr, "\\x%02x", mt->data[i]);
+      fprintf (stderr, "\")\n");
+      fprintf (stderr, "%s (chars \"", prefix);
+      p = mt->data;
+      for (i = 0; i < mt->nchars; i++)
+       {
+         int len;
+         int c = STRING_CHAR_AND_BYTES (p, len);
+
+         if (c == '"' || c == '\\')
+           fprintf (stderr, "\\%c", c);
+         else if (c >= ' ' && c < 127)
+           fputc (c, stderr);
+         else
+           fprintf (stderr, "\\x%X", c);
+         p += len;
+       }
+      fprintf (stderr, "\")");
+      if (mt->plist)
+       {
+         fprintf (stderr, "\n%s ", prefix);
+         dump_textplist (mt->plist, indent + 1);
+       }
+    }
+  fprintf (stderr, ")");
+  return mt;
+}
+
+/*** @} */ 
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/mtext.h b/src/mtext.h
new file mode 100644 (file)
index 0000000..b2a3778
--- /dev/null
@@ -0,0 +1,71 @@
+/* mtext.h -- header file for the M-text module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_MTEXT_H_
+#define _M17N_MTEXT_H_
+
+/** @file mtext.h
+    @brief Header for M-text handling.
+*/
+
+#define POS_CHAR_TO_BYTE(mt, pos)                              \
+  (mtext_nchars (mt) == mtext_nbytes (mt) ? (pos)              \
+   : (pos) == (mt)->cache_char_pos ? (mt)->cache_byte_pos      \
+   : mtext__char_to_byte ((mt), (pos)))
+
+#define POS_BYTE_TO_CHAR(mt, pos_byte)                         \
+  (mtext_nchars (mt) == mtext_nbytes (mt) ? (pos_byte)         \
+   : (pos_byte) == (mt)->cache_byte_pos ? (mt)->cache_char_pos \
+   : mtext__byte_to_char ((mt), (pos_byte)))
+
+
+#define MTEXT_DATA(mt) ((mt)->data)
+
+extern int mtext__char_to_byte (MText *mt, int pos);
+
+extern int mtext__byte_to_char (MText *mt, int pos_byte);
+
+extern void mtext__enlarge (MText *mt, int nbytes);
+
+extern int mtext__takein (MText *mt, int nchars, int nbytes);
+
+extern int mtext__cat_data (MText *mt, unsigned char *p, int nbytes,
+                           enum MTextFormat format);
+
+#define MTEXT_CAT_ASCII(mt, str)                               \
+  mtext__cat_data ((mt), (unsigned char *) (str), strlen (str),        \
+                  MTEXT_FORMAT_US_ASCII)
+
+extern MText *mtext__from_data (const void *data, int nitems,
+                               enum MTextFormat format, int need_copy);
+
+extern void mtext__adjust_format (MText *mt, enum MTextFormat format);
+
+extern int mtext__bol (MText *mt, int pos);
+
+extern int mtext__eol (MText *mt, int pos);
+
+extern void mtext__wseg_fini ();
+
+extern int mtext__word_segment (MText *mt, int pos, int *from, int *to);
+
+#endif /* _M17N_MTEXT_H_ */
diff --git a/src/plist.c b/src/plist.c
new file mode 100644 (file)
index 0000000..05dd737
--- /dev/null
@@ -0,0 +1,1682 @@
+/* plist.c -- plist module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nPlist
+
+    @brief Property List objects and API for them.
+
+    A @e property @e list (or @e plist for short) is a list of zero or
+    more properties.  A property consists of a @e key and a @e value,
+    where key is a symbol and value is anything that can be cast to
+    <tt>(void *)</tt>.
+
+    If the key of a property is a @e managing @e key, its @e value is
+    a @e managed @e object.  A property list itself is a managed
+    objects.
+
+    If each key of a plist is one of #Msymbol, #Mtext, #Minteger, and
+    #Mplist, the plist is called as @e well-formed and represented by
+    the following notation in the documentation.
+
+@verbatim
+      PLIST ::= '(' ELEMENT * ')'
+
+      ELEMENT ::= INTEGER | SYMBOL | M-TEXT | PLIST
+
+      M-TEXT ::= '"' text data ... '"'
+@endverbatim
+
+    For instance, if a plist has four elements; integer -20, symbol of
+    name "sym", M-text of contents "abc", and plist of integer 10 and
+    symbol of name "another-symbol", it is represented as this:
+
+      (-20 sym "abc" (10 another-symbol))
+
+  */
+/***ja
+    @addtogroup m17nPlist
+
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¥ª¥Ö¥¸¥§¥¯¥È¤È¤½¤ì¤Ë´Ø¤¹¤ë API.
+
+    @e ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È (¤Þ¤¿¤Ï @e plist) ¤Ï 0 
+    ¸Ä°Ê¾å¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥ê¥¹¥È¤Ç¤¢¤ë¡£¥×¥í¥Ñ¥Æ¥£¤Ï @e ¥­¡¼ ¤È @e ÃÍ 
+    ¤«¤é¤Ê¤ë¡£¥­¡¼¤Ï¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢ÃͤϠ<tt>(void *)</tt> 
+    ¤Ë¥­¥ã¥¹¥È¤Ç¤­¤ë¤â¤Î¤Ê¤é¤Ð²¿¤Ç¤âÎɤ¤¡£
+
+    ¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤¬ @e ´ÉÍý¥­¡¼ ¤Ê¤é¤Ð¡¢¤½¤Î @e ÃÍ ¤Ï @e ´ÉÍý²¼
+    @e ¥ª¥Ö¥¸¥§¥¯¥È 
+    ¤Ç¤¢¤ë¡£¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¼«ÂΤâ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë¡£  */
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "config.h"
+#include "m17n.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "character.h"
+#include "mtext.h"
+#include "symbol.h"
+#include "plist.h"
+
+static M17NObjectArray plist_table;
+
+/** Set PLIST to a newly allocated plist object.  */
+
+#define MPLIST_NEW(plist)                              \
+  do {                                                 \
+    M17N_OBJECT (plist, free_plist, MERROR_PLIST);     \
+    M17N_OBJECT_REGISTER (plist_table, plist);         \
+  } while (0)
+
+
+/** Set the element of PLIST to KEY and VAL.  If PLIST is an anchor,
+    append a new anchor.  */
+
+#define MPLIST_SET(plist, key, val)    \
+  do {                                 \
+    MPLIST_KEY (plist) = (key);                \
+    MPLIST_VAL (plist) = (val);                \
+    if (! (plist)->next)               \
+      MPLIST_NEW ((plist)->next);      \
+  } while (0)
+
+
+/** Set the element of PLIST to KEY and VAL.  PLIST must be an anchor.
+    Append a new anchor and set PLIST to that anchor.  */
+
+#define MPLIST_SET_ADVANCE(plist, key, val)    \
+  do {                                         \
+    MPLIST_KEY (plist) = (key);                        \
+    MPLIST_VAL (plist) = (val);                        \
+    MPLIST_NEW ((plist)->next);                        \
+    plist = (plist)->next;                     \
+  } while (0)
+
+
+static void
+free_plist (void *object)
+{
+  MPlist *plist = (MPlist *) object;
+
+  do {
+    MPlist *next = plist->next;
+
+    if (MPLIST_KEY (plist) != Mnil
+       && MPLIST_KEY (plist)->managing_key)
+      M17N_OBJECT_UNREF (MPLIST_VAL (plist));
+    M17N_OBJECT_UNREGISTER (plist_table, plist);
+    free (plist);
+    plist = next;
+  } while (plist && plist->control.ref_count == 1);
+  M17N_OBJECT_UNREF (plist);
+}
+
+\f
+
+/* Load a plist from a string.  */
+
+#define READ_CHUNK 0x10000
+
+typedef struct
+{
+  /* File pointer if the stream is associated with a file.  Otherwise
+     NULL.  */
+  FILE *fp;
+  int eof;
+  unsigned char buffer[READ_CHUNK];
+  unsigned char *p, *pend;
+} MStream;
+
+static int
+get_byte (MStream *st)
+{
+  int n;
+
+  if (! st->fp || st->eof)
+    return EOF;
+  n = fread (st->buffer, 1, READ_CHUNK, st->fp);
+  if (n <= 0)
+    {
+      st->eof = 1;
+      return EOF;
+    }
+  st->p = st->buffer + 1;
+  st->pend = st->buffer + n;
+  return st->buffer[0];
+}
+
+#define GETC(st) ((st)->p < (st)->pend ? *(st)->p++ : get_byte (st))
+
+#define UNGETC(c, st) (--((st)->p))
+
+/** Mapping table for reading a number.  Hexadecimal chars
+    (0..9,A..F,a..F) are mapped to the corresponding numbers.
+    Apostrophe (code 39) is mapped to 254.  All the other bytes are
+    mapped to 255.  */
+unsigned char hex_mnemonic[256];
+
+/** Mapping table for escaped characters.  Mnemonic characters (e, b,
+    f, n, r, or t) that follows '\' are mapped to the corresponding
+    character code.  All the other bytes are mapped to themselves.  */
+unsigned char escape_mnemonic[256];
+
+
+/** Read an integer from the stream ST.  It is assumed that we have
+    already read one character C.  */
+
+static int
+read_decimal (MStream *st, int c)
+{
+  int num = 0;
+
+  while (c >= '0' && c <= '9')
+    {
+      num = (num * 10) + (c - '0');
+      c = GETC (st);
+    }
+
+  if (c != EOF)
+    UNGETC (c, st);
+  return num;
+}
+
+/** Read an unsigned from the stream ST.  */
+
+static unsigned
+read_hexadesimal (MStream *st)
+{
+  int c;
+  unsigned num = 0, n;
+
+  while ((c = GETC (st)) != EOF
+        && (n = hex_mnemonic[c]) < 16)
+    num = (num << 4) | n;
+  if (c != EOF)
+    UNGETC (c, st);
+  return num;
+}
+
+
+/** Read an M-text element from ST, and add it to LIST.  Return a list
+    for the next element.  */
+
+#define READ_MTEXT_BUF_SIZE 256
+
+static MPlist *
+read_mtext_element (MPlist *plist, MStream *st, int skip)
+{
+  unsigned char buffer[READ_MTEXT_BUF_SIZE], *buf = buffer;
+  int nbytes = READ_MTEXT_BUF_SIZE;
+  int c, i;
+
+  i = 0;
+  while ((c = GETC (st)) != EOF && c != '"')
+    {
+      int is_char = 0;
+
+      if (c == '\\')
+       {
+         c = GETC (st);
+         if (c == EOF)
+           break;
+         if (c == '\n')
+           continue;
+         if (c == 'x' || c == 'u')
+           {
+             int next_c;
+
+             c = read_hexadesimal (st);
+             next_c = GETC (st);
+             if (next_c != ' ')
+               UNGETC (next_c, st);
+             if (c >= 0x80)
+               is_char = 1;
+           }
+         else
+           c = escape_mnemonic[c];
+       }
+
+      if (! skip)
+       {
+         if (i + MAX_UTF8_CHAR_BYTES >= nbytes)
+           {
+             if (buf == buffer)
+               {
+                 nbytes *= 2;
+                 buf = malloc (nbytes);
+                 memcpy (buf, buffer, i);
+               }
+             else
+               {
+                 nbytes += READ_MTEXT_BUF_SIZE;
+                 buf = realloc (buf, nbytes);
+               }
+           }
+
+         if (is_char)
+           i += CHAR_STRING_UTF8 (c, buf);
+         else
+           buf[i++] = c;
+       }
+    }
+
+  if (! skip)
+    {
+      MText *mt = mtext__from_data (buf, i, MTEXT_FORMAT_UTF_8,
+                                   (buf == buffer));
+      if (buf != buffer)
+       mt->allocated = nbytes;
+      MPLIST_SET_ADVANCE (plist, Mtext, mt);
+    }
+  return plist;
+}
+
+static int
+read_character (MStream *st, int c)
+{
+  unsigned char buf[MAX_UTF8_CHAR_BYTES + 1];
+  int len = CHAR_BYTES_BY_HEAD (c);
+  int i;
+
+  buf[0] = c;
+  for (i = 1; i < len; i++)
+    {
+      c = GETC (st);
+      if (c == EOF
+         || (c & 0xC0) != 0x80)
+       break;
+      buf[i] = c;
+    }
+  if (i == len)
+    c = STRING_CHAR_UTF8 (buf);
+  else
+    c = buf[0];
+  return c;
+}
+
+
+/** Read a symbol element from ST, and add it to LIST.  Return a list
+    for the next element.  */
+
+static MPlist *
+read_symbol_element (MPlist *plist, MStream *st, int c, int skip)
+{
+  unsigned char buffer[1024];
+  int bufsize = 1024;
+  unsigned char *buf = buffer;
+  int i;
+
+  i = 0;
+  while (c != EOF
+        && c > ' '
+        && c != ')' && c != '(' && c != '"')
+    {
+      if (i >= bufsize)
+       {
+         bufsize *= 2;
+         if (buf == buffer)
+           {
+             MTABLE_MALLOC (buf, bufsize, MERROR_PLIST);
+             memcpy (buf, buffer, i);
+           }
+         else
+           MTABLE_REALLOC (buf, bufsize, MERROR_PLIST);
+       }
+      if (c == '\\')
+       {
+         c = GETC (st);
+         if (c == EOF)
+           break;
+         c = escape_mnemonic[c];
+       }
+      if (! skip)
+       buf[i++] = c;
+      c = GETC (st);
+    }
+
+  if (c > ' ')
+    UNGETC (c, st);
+  if (! skip)
+    {
+      buf[i] = 0;
+      MPLIST_SET_ADVANCE (plist, Msymbol, msymbol ((char *) buf));
+      if (buf != buffer)
+       free (buf);
+    }
+  return plist;
+}
+
+/** Read an integer element from ST, and add it to LIST.  Return a
+    list for the next element.  It is assumed that we have already
+    read the character C. */
+
+static MPlist *
+read_integer_element (MPlist *plist, MStream *st, int c, int skip)
+{
+  int num;
+
+  if (c == '#')
+    {
+      c = GETC (st);
+      if (c != 'x')
+       {
+         UNGETC (c, st);
+         return read_symbol_element (plist, st, '#', skip);
+       }
+      num = read_hexadesimal (st);
+    }
+  else if (c == '0')
+    {
+      c = GETC (st);
+      num = (c == 'x' ? read_hexadesimal (st) : read_decimal (st, c));
+    }
+  else if (c == '?')
+    {
+      c = GETC (st);
+      if (c == EOF)
+       num = 0;
+      else if (c != '\\')
+       {
+         if (c < 128 || ! CHAR_UNITS_BY_HEAD_UTF8 (c))
+           num = c;
+         else
+           num = read_character (st, c);
+       }
+      else
+       {
+         c = GETC (st);
+         if (c == EOF)
+           num = '\\';
+         else if (c < 128 || ! CHAR_UNITS_BY_HEAD_UTF8 (c))
+           num = escape_mnemonic[c];
+         else
+           num = read_character (st, c);
+       }
+    }
+  else if (c == '-')
+    {
+      c = GETC (st);
+      if (c < '0' || c > '9')
+       {
+         UNGETC (c, st);
+         return read_symbol_element (plist, st, '-', skip);
+       }
+      num = - read_decimal (st, c);
+    }
+  else
+    num = read_decimal (st, c);
+
+  if (! skip)
+    MPLIST_SET_ADVANCE (plist, Minteger, (void *) num);
+  return plist;
+}
+
+/* Read an element of various type from stream ST, and add it to LIST.
+   Return a list for the next element.  The element type is decided by
+   the first token character found as below:
+       '(': plist
+       '"': mtext
+       '0'..'9', '-': integer
+       '?': integer representing character code
+       the other ASCII letters: symbol
+
+   If KEYS is not NULL, it is a plist contains target keys and stop
+   keys.  In this caes, read only a plist whose key has value 1 in
+   KEYS, and return NULL when we encounter a plist whose key has value
+   0 in KEYS while skipping any other elements.  */
+
+static MPlist *
+read_element (MPlist *plist, MStream *st, MPlist *keys)
+{
+  int c;
+
+  /* Skip separators and comments.  */
+  while (1)
+    {
+      while ((c = GETC (st)) != EOF && c <= ' ');
+      if (c != ';')
+       break;
+      while ((c = GETC (st)) != EOF && c != '\n');
+      if (c == EOF)
+       break;
+    }
+
+  if (c == '(')
+    {
+      MPlist *pl, *p;
+
+      MPLIST_NEW (pl);
+      p = pl;
+      p = read_element (p, st, NULL);
+      if (keys && p && MPLIST_SYMBOL_P (pl))
+       {
+         if (MPLIST_TAIL_P (keys))
+           {
+             while ((p = read_element (p, st, NULL)));
+             MPLIST_SET_ADVANCE (plist, Mplist, pl);
+             return NULL;
+           }
+         else
+           {
+             MPlist *p0 = keys;
+
+             MPLIST_FIND (p0, MPLIST_SYMBOL (pl));
+             if (! MPLIST_TAIL_P (p0) && ! MPLIST_VAL (p0))
+               {
+                 M17N_OBJECT_UNREF (pl);
+                 return NULL;
+               }
+             while ((p = read_element (p, st, NULL)));
+             if (! MPLIST_TAIL_P (p0))
+               {
+                 MPLIST_SET_ADVANCE (plist, Mplist, pl);
+                 return NULL;
+               }
+             else
+               M17N_OBJECT_UNREF (pl);
+           }
+       }
+      else
+       {
+         if (p)
+           while ((p = read_element (p, st, NULL)));
+         MPLIST_SET_ADVANCE (plist, Mplist, pl);
+       }
+      return plist;
+    }
+  if (c == '"')
+    return (read_mtext_element (plist, st, keys ? 1 : 0));
+  if ((c >= '0' && c <= '9') || c == '-' || c == '?' || c == '#')
+    return (read_integer_element (plist, st, c, keys ? 1 : 0));
+  if (c == EOF || c == ')')
+    return NULL;
+  return (read_symbol_element (plist, st, c, keys ? 1 : 0));
+}
+
+#define PUTC(MT, C)                    \
+  do {                                 \
+    if (MT)                            \
+      mtext_cat_char ((MT), (C));      \
+    else                               \
+      putc ((C), stderr);              \
+  } while (0);
+
+#define PUTS(MT, STR)                  \
+  do {                                 \
+    if (MT)                            \
+      MTEXT_CAT_ASCII ((MT), (STR));   \
+    else                               \
+      fputs ((STR), stderr);           \
+  } while (0)
+
+
+static void 
+write_symbol (MText *mt, MSymbol sym)
+{
+  if (sym == Mnil)
+    {
+      PUTS (mt, "nil");
+    }
+  else
+    {
+      char *name = MSYMBOL_NAME (sym);
+
+      if (isdigit (*name))
+       PUTC (mt, '\\');
+      while (*name)
+       {
+         if (*name <= ' ' || *name == '\\' || *name == '"'
+             || *name == '(' || *name == ')')
+           PUTC (mt, '\\');
+         PUTC (mt, *name); 
+         name++;
+       }
+    }
+}
+
+static void
+write_element (MText *mt, MPlist *plist, int indent)
+{
+  if (MPLIST_SYMBOL_P (plist))
+    {
+      write_symbol (mt, MPLIST_SYMBOL (plist));
+    }
+  else if (MPLIST_INTEGER_P (plist))
+    {
+      int num = MPLIST_INTEGER (plist);
+      char buf[128];
+
+      sprintf (buf, "%d", num);
+      PUTS (mt, buf);
+    }
+  else if (MPLIST_PLIST_P (plist)
+          || MPLIST_NESTED_P (plist))
+    {
+      MPlist *pl;
+      int newline = 0;
+
+      if (MPLIST_NESTED_P (plist))
+       {
+         write_symbol (mt, MPLIST_KEY (plist));
+         PUTC (mt, ':');
+       }
+      plist = MPLIST_PLIST (plist);
+      PUTC (mt, '(');
+      if (indent >= 0)
+       indent++;
+      MPLIST_DO (pl, plist)
+       {
+         if (pl != plist)
+           {
+             if (indent > 0 && (MPLIST_PLIST_P (pl) || MPLIST_MTEXT_P (pl)))
+               newline = 1;
+             if (newline)
+               {
+                 int i;
+
+                 PUTC (mt, '\n');
+                 for (i = 1; i < indent; i++)
+                   PUTC (mt, ' ');
+               }
+             PUTC (mt, ' ');
+           }
+         write_element (mt, pl, indent);
+         if (indent >= 0)
+           newline = (MPLIST_PLIST_P (pl) || MPLIST_MTEXT_P (pl));
+       }
+      PUTC (mt, ')');
+    }
+  else if (MPLIST_MTEXT_P (plist))
+    {
+      MText *this_mt = MPLIST_MTEXT (plist);
+      int from = 0, to = mtext_nchars (this_mt);
+      int stop1 = 0, stop2 = 0;
+
+      if (! mt && this_mt->format > MTEXT_FORMAT_UTF_8)
+       {
+         this_mt = mtext_dup (this_mt);
+         mtext__adjust_format (this_mt, MTEXT_FORMAT_UTF_8);
+       }
+
+      PUTC (mt, '"');
+      while (1)
+       {
+         int stop, escaped;
+
+         if (from == stop1)
+           {
+             if ((stop1 = mtext_character (this_mt, from, to, '"')) < 0)
+               stop1 = to;
+           }
+         if (from == stop2)
+           {
+             if ((stop2 = mtext_character (this_mt, from, to, '\\')) < 0)
+               stop2 = to;
+           }
+         if (stop1 < stop2)
+           stop = stop1++, escaped = '"';
+         else
+           stop = stop2++, escaped = '\\';
+         if (mt)
+           mtext_copy (mt, mtext_nchars (mt), this_mt, from, stop);
+         else
+           {
+             unsigned char *data = MTEXT_DATA (this_mt);
+             unsigned char *beg = data + mtext__char_to_byte (this_mt, from);
+             unsigned char *end = data + mtext__char_to_byte (this_mt, stop);
+
+             while (beg < end)
+               putc (*beg, stderr), beg++;
+           }
+         if (stop == to)
+           break;
+         PUTC (mt, '\\');
+         PUTC (mt, escaped);
+         from = stop + 1;
+       }
+      PUTC (mt, '"');
+      if (this_mt != MPLIST_MTEXT (plist))
+       M17N_OBJECT_UNREF (this_mt);
+    }
+  else if (MPLIST_STRING_P (plist))
+    {
+      char *str = MPLIST_STRING (plist);
+
+      if (mt)
+       {
+         MText *this_mt = mtext__from_data (str, strlen (str),
+                                            MTEXT_FORMAT_UTF_8, 0);
+
+         mtext_copy (mt, mtext_nchars (mt),
+                     this_mt, 0, mtext_nchars (this_mt));
+         M17N_OBJECT_UNREF (this_mt);
+       }
+      else
+       fprintf (stderr, "%s", str);
+    }
+  else 
+    {
+      char buf[128];
+
+      write_symbol (mt, MPLIST_KEY (plist));
+      PUTC (mt, ':');
+      sprintf (buf, "%04X", (unsigned) MPLIST_VAL (plist));
+      PUTS (mt, buf);
+    }
+}
+
+\f
+/* Internal API */
+int
+mplist__init ()
+{
+  int i;
+
+  M17N_OBJECT_ADD_ARRAY (plist_table, "Plist");
+
+  Minteger = msymbol ("integer");
+  Mplist = msymbol_as_managing_key ("plist");
+  Mtext = msymbol_as_managing_key ("mtext");
+
+  for (i = 0; i < 256; i++)
+    hex_mnemonic[i] = 255;
+  for (i = '0'; i <= '9'; i++)
+    hex_mnemonic[i] = i - '0';
+  for (i = 'A'; i <= 'F'; i++)
+    hex_mnemonic[i] = i - 'A' + 10;
+  for (i = 'a'; i <= 'f'; i++)
+    hex_mnemonic[i] = i - 'a' + 10;
+  for (i = 0; i < 256; i++)
+    escape_mnemonic[i] = i;
+  escape_mnemonic['e'] = 27;
+  escape_mnemonic['b'] = '\b';
+  escape_mnemonic['f'] = '\f';
+  escape_mnemonic['n'] = '\n';
+  escape_mnemonic['r'] = '\r';
+  escape_mnemonic['t'] = '\t';
+  escape_mnemonic['\\'] = '\\';
+
+  return 0;
+}
+
+void
+mplist__fini (void)
+{
+}
+
+
+/* Parse this form of PLIST:
+      (symbol:KEY1 TYPE1:VAL1 symbol:KEY2 TYPE2:VAL2 ...)
+   and return a newly created plist of this form:
+      (KEY1:VAL1 KEY2:VAL2 ...)  */
+
+MPlist *
+mplist__from_plist (MPlist *plist)
+{
+  MPlist *pl, *p;
+
+  MPLIST_NEW (pl);
+  p = pl;
+  while (! MPLIST_TAIL_P (plist))
+    {
+      MSymbol key, type;
+
+      if (! MPLIST_SYMBOL_P (plist))
+       MERROR (MERROR_PLIST, NULL);
+      key = MPLIST_SYMBOL (plist);
+      plist = MPLIST_NEXT (plist);
+      type = MPLIST_KEY (plist);
+      if (type->managing_key && MPLIST_VAL (plist))
+       M17N_OBJECT_REF (MPLIST_VAL (plist));
+      if (type == Mplist)
+       MPLIST_SET_NESTED_P (p);
+      MPLIST_SET_ADVANCE (p, key, MPLIST_VAL (plist));
+      plist = MPLIST_NEXT (plist);
+    }
+  return pl;
+}
+
+/** Parse this form of PLIST:
+      ((symbol:KEY1 ANY:VAL1 ... ) (symbol:KEY2 ANY:VAL2 ...) ...)
+    and return a newly created plist of this form:
+      (KEY1:(ANY:VAL1 ...) KEY2:(ANY:VAL2 ...) ...)
+    ANY can be any type.  */
+
+MPlist *
+mplist__from_alist (MPlist *plist)
+{
+  MPlist *pl, *p;
+
+  MPLIST_NEW (pl);
+  p = pl;
+  MPLIST_DO (plist, plist)
+    {
+      MPlist *elt;
+
+      if (! MPLIST_PLIST_P (plist))
+       MERROR (MERROR_PLIST, NULL);
+      elt = MPLIST_PLIST (plist);
+      if (! MPLIST_SYMBOL_P (elt))
+       MERROR (MERROR_PLIST, NULL);
+      MPLIST_SET_NESTED_P (p);
+      MPLIST_SET_ADVANCE (p, MPLIST_SYMBOL (elt), MPLIST_NEXT (elt));
+      M17N_OBJECT_REF (MPLIST_NEXT (elt));
+    }
+  return pl;
+}
+
+
+MPlist *
+mplist__from_file (FILE *fp, MPlist *keys)
+{
+  MPlist *plist, *pl;
+  MStream st;
+
+  st.fp = fp;
+  st.eof = 0;
+  st.p = st.pend = st.buffer;
+  MPLIST_NEW (plist);
+  pl = plist;
+  while ((pl = read_element (pl, &st, keys)));
+  return plist;
+}
+
+
+/** Parse $STR of $N bytes and return a property list object.  $FORMAT
+    must be either @c MTEXT_FORMAT_US_ASCII or @c MTEXT_FORMAT_UTF_8,
+    and controls how to produce @c STRING or @c M-TEXT in the
+    following definition.
+
+    The syntax of $STR is as follows.
+
+    PLIST ::= '(' ELEMENT * ')'
+
+    ELEMENT ::= SYMBOL | INTEGER | UNSIGNED | STRING | M-TEXT | PLIST
+
+    SYMBOL ::= ascii-character-sequence
+
+    INTEGER ::= '-' ? [ '0' | .. | '9' ]+
+
+    UNSIGNED ::= '0x' [ '0' | .. | '9' | 'A' | .. | 'F' | 'a' | .. | 'f' ]+
+
+    M-TEXT ::= '"' byte-sequence '"'
+
+    Each kind of @c ELEMENT is assigned one of these keys:
+       @c Msymbol, @c Mint, @c Munsigned, @c Mtext, @c Mplist
+
+    In an ascii-character-sequence, a backslush (\) is used as the escape
+    character, which means that, for instance, <tt>"abc\ def"</tt>
+    produces a symbol whose name is of length seven with the fourth
+    character being a space.
+
+    In a byte-sequence, "\r", "\n", "\e", and "\t" are replaced by CR,
+    NL, ESC, and TAB character respectively, "\xXX" are replaced by
+    byte 0xXX.  After this replacement, the byte-sequence is decoded
+    into M-TEXT by $CODING.  */
+
+MPlist *
+mplist__from_string (unsigned char *str, int n)
+{
+  MPlist *plist, *pl;
+  MStream st;
+
+  st.fp = NULL;
+  st.eof = 0;
+  st.p = str;
+  st.pend = str + n;
+  MPLIST_NEW (plist);
+  pl = plist;
+  while ((pl = read_element (pl, &st, NULL)));
+  return plist;
+}
+
+int
+mplist__serialize (MText *mt, MPlist *plist, int pretty)
+{
+  MPlist *pl;
+  int separator = pretty ? '\n' : ' ';
+
+  MPLIST_DO (pl, plist)
+    {
+      if (pl != plist)
+       mtext_cat_char (mt, separator);
+      write_element (mt, pl, pretty ? 0 : -1);
+    }
+  if (pretty)
+    mtext_cat_char (mt, separator);
+  return 0;
+}
+
+/**en
+    @brief Concatenate two plists.
+
+    The mplist__conc () function concatenates plist $TAIL at the end of
+    plist $PLIST and return $PLIST.  If $TAIL is empty, return $PLIST
+    without modifying it.  */
+
+MPlist *
+mplist__conc (MPlist *plist, MPlist *tail)
+{
+  MPlist *pl;
+
+  if (MPLIST_TAIL_P (tail))
+    return plist;
+  MPLIST_DO (pl, plist);
+  MPLIST_KEY (pl) = MPLIST_KEY (tail);
+  MPLIST_VAL (pl) = MPLIST_VAL (tail);
+  if (MPLIST_KEY (pl)->managing_key && MPLIST_VAL (pl))
+    M17N_OBJECT_REF (MPLIST_VAL (pl));
+  if (MPLIST_NESTED_P (tail))
+    MPLIST_SET_NESTED_P (pl);
+  tail = MPLIST_NEXT (tail);
+  MPLIST_NEXT (pl) = tail;
+  M17N_OBJECT_REF (tail);
+  return plist;
+}
+
+/*=*/
+/**en
+    @brief Discard a property at the beginning of a property list.
+
+    The mplist__pop_unref () function removes a property at the
+    beginning of property list $PLIST, and if the property value is a
+    managed object, unref it.  As a result, the second key and value
+    of the original $PLIST become the first of those of the new
+    $PLIST.  */
+
+void
+mplist__pop_unref (MPlist *plist)
+{
+  MSymbol key;
+  void *val;
+
+  if (MPLIST_TAIL_P (plist))
+    return;
+  key = MPLIST_KEY (plist);
+  val = mplist_pop (plist);
+  if (key->managing_key)
+    M17N_OBJECT_UNREF (val);
+}
+
+/**en
+    @brief Search for an element of an alist represented by a plist.
+
+    The mplist__assq () function treats $PLIST as an association list
+    (elements are plists (key is #Mplist) whose first element is a
+    symbol (key is #Msymbol)), and find an element whose first element
+    has key #Msymbol and value $KEY.
+
+    Non-plist elements of $PLIST are ignored.
+
+    @return
+    This function returns a found element or NULL if no element
+    matches with $KEY.  */
+
+MPlist *
+mplist__assq (MPlist *plist, MSymbol key)
+{
+  MPLIST_DO (plist, plist)
+    if (MPLIST_PLIST_P (plist))
+      {
+       MPlist *pl = MPLIST_PLIST (plist);
+
+       if (MPLIST_SYMBOL_P (pl) && MPLIST_SYMBOL (pl) == key)
+         return plist;
+      }
+  return NULL;
+}
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+/* External API */
+
+/*** @addtogroup m17nPlist */
+/*** @{ */
+/*=*/
+
+/***en
+    @brief Symbol whose name is "integer".
+
+    The symbol @c Minteger has the name <tt>"integer"</tt>.  The value
+    of a property whose key is @c Minteger must be an integer.  */
+/***ja
+    @brief "integer" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë @c Minteger ¤Ï <tt>"integer"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¡£¥­¡¼¤¬
+    @c Minteger ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ÎÃͤÏÀ°¿ôÃͤǤʤ¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£  */
+
+MSymbol Minteger;
+/*=*/
+
+/***en
+    @brief Symbol whose name is "plist".
+
+    The symbol @c Mplist has the name <tt>"plist"</tt>.  It is a
+    managing key.  A value of a property whose key is @c Mplist must
+    be a plist.  */
+/***ja
+    @brief "plist" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë @c Mplist ¤Ï <tt>"plist"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¡£¤³¤ì¤Ï´ÉÍý¥­¡¼¤Ç¤¢¤ë¡£¥­¡¼¤¬ @c Mplist 
+    ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϠplist ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£  */
+
+MSymbol Mplist;
+/*=*/
+
+/***en
+    @brief Symbol whose name is "mtext".
+
+    The symbol @c Mtext has the name <tt>"mtext"</tt>.  It is a
+    managing key.  A value of a property whose key is @c Mtext must be an
+    M-text.  */
+
+/***ja
+    @brief "mtext" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë @c Mtext ¤Ï <tt>"mtext"</tt>
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä´ÉÍý¥­¡¼¤Ç¤¢¤ë¡£¥­¡¼¤¬ @c Mtext 
+    ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϠM-text ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£      */
+
+MSymbol Mtext;
+
+/*=*/
+/***en
+    @brief Create a property list object.
+
+    The mplist () function returns a newly created property list
+    object of length zero.
+
+    @returns
+    This function returns a newly created property list.
+
+    @errors
+    This function never fails.  */
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¥ª¥Ö¥¸¥§¥¯¥È¤òºî¤ë.
+
+    ´Ø¿ô mplist () ¤ÏŤµ 0 ¤Î¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¥ª¥Ö¥¸¥§¥¯¥È¤ò¿·¤·¤¯ºî¤Ã¤ÆÊÖ¤¹¡£
+
+    @returns
+    ¤³¤Î´Ø¿ô¤Ï¿·¤·¤¯ºî¤é¤ì¤¿¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤¹¡£
+
+    @errors
+    ¤³¤Î´Ø¿ô¤Ï·è¤·¤Æ¼ºÇÔ¤·¤Ê¤¤¡£     */
+
+MPlist *
+mplist (void)
+{
+  MPlist *plist;
+
+  MPLIST_NEW (plist);
+  return plist;
+}  
+
+/*=*/
+/***en
+    @brief Copy a property list.
+
+    The mplist_copy () function copies property list $PLIST.  In the
+    copy, the values are the same as those of $PLIST.
+
+    @return
+    This function returns a newly created plist which is a copy of
+    $PLIST.  
+
+    @errors
+    This function never fails.  */ 
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤ò¥³¥Ô¡¼¤¹¤ë.
+
+    ´Ø¿ô mplist_copy () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST 
+    ¤ò¥³¥Ô¡¼¤¹¤ë¡£¥³¥Ô¡¼¤Î¤¹¤Ù¤Æ¤ÎÃͤϥ³¥Ô¡¼¸µ $PLIST ¤ÎÃͤÈƱ¤¸¤Ç¤¢¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¿·¤·¤¯ºî¤é¤ì¤¿¡¢$PLIST ¤Î¥³¥Ô¡¼¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤òÊÖ¤¹¡£    
+
+    @errors
+    ¤³¤Î´Ø¿ô¤Ï·è¤·¤Æ¼ºÇÔ¤·¤Ê¤¤¡£     */
+
+MPlist *
+mplist_copy (MPlist *plist)
+{
+  MPlist *copy = mplist (), *pl = copy;
+
+  MPLIST_DO (plist, plist)
+    {
+      if (MPLIST_NESTED_P (plist))
+       MPLIST_SET_NESTED_P (pl);
+      pl = mplist_add (pl, MPLIST_KEY (plist), MPLIST_VAL (plist));
+    }
+  return copy;
+}
+
+/*=*/
+
+/***en
+    @brief Set the value of a property in a property list.
+
+    The mplist_put () function searches property list $PLIST
+    from the beginning for a property whose key is $KEY.  If such a
+    property is found, its value is changed to $VALUE.  Otherwise, a
+    new property whose key is $KEY and value is $VALUE is appended at
+    the end of $PLIST.  See the documentation of mplist_add () for
+    the restriction on $KEY and $VAL.
+
+    If $KEY is a managing key, $VAL must be a managed object.  In this
+    case, the reference count of the old value, if not @c NULL, is
+    decremented by one, and that of $VAL is incremented by one.
+
+    @return
+    If the operation was successful, mplist_put () returns a sublist of
+    $PLIST whose first element is the just modified or added one.
+    Otherwise, it returns @c NULL.  */
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃæ¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÀßÄꤹ¤ë.
+
+    ´Ø¿ô mplist_put () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ò»Ï¤á¤«¤éõ¤·¤Æ¡¢¥­¡¼¤¬
+    $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò¸«¤Ä¤±¤ë¡£¸«¤Ä¤«¤ì¤Ð¡¢¤½¤ÎÃͤò $VALUE 
+    ¤ËÊѹ¹¤¹¤ë¡£¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð¡¢¥­¡¼¤¬ $KEY ¤ÇÃͤ¬ $VALUE 
+    ¤Ç¤¢¤ë¿·¤·¤¤¥×¥í¥Ñ¥Æ¥£¤¬ $PLIST ¤ÎËöÈø¤ËÄɲ䵤ì¤ë¡£$KEY ¤È $VAL
+    ¤ËÂФ¹¤ëÀ©¸Â¤Ë¤Ä¤¤¤Æ¤Ï¡¢mplist_add () ¤ÎÀâÌÀ¤ò»²¾È¡£
+
+    $KEY ¤¬´ÉÍý¥­¡¼¤Ê¤é¤Ð¡¢
+    $VAL ¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤³¤Î¾ì¹ç¡¢¸Å¤¤Ãͤλ²¾È¿ô¤Ï 
+    @c NULL ¤Ç¤Ê¤±¤ì¤Ð 1 ¸º¤é¤µ¤ì¡¢$VAL ¤Î»²¾È¿ô¤Ï 1 Áý¤ä¤µ¤ì¤ë¡£
+
+    @return 
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mplist_put () ¤ÏÊѹ¹¤µ¤ì¤¿¤«Äɲ䵤줿Í×ÁǤ«¤é»Ï¤Þ¤ë
+    $PLIST ¤ÎÉôʬ¥ê¥¹¥È¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£   */
+
+MPlist *
+mplist_put (MPlist *plist, MSymbol key, void *val)
+{
+  if (key == Mnil)
+    MERROR (MERROR_PLIST, NULL);
+  MPLIST_FIND (plist, key);
+  if (key->managing_key)
+    {
+      if (! MPLIST_TAIL_P (plist))
+       M17N_OBJECT_UNREF (MPLIST_VAL (plist));
+      if (val)
+       M17N_OBJECT_REF (val);
+    }
+  MPLIST_SET (plist, key, val);
+  return plist;
+}
+
+/*=*/
+
+/***en
+    @brief Get the value of a property in a property list.
+
+    The mplist_get () function searches property list $PLIST from the
+    beginning for a property whose key is $KEY.  If such a property is
+    found, its value is returned as the type of <tt>(void *)</tt>.  If
+    not found, @c NULL is returned.
+
+    When @c NULL is returned, there are two possibilities: one is the
+    case where no property is found (see above); the other is the case
+    where a property is found and its value is @c NULL.  In case that
+    these two cases must be distinguished, use the mplist_find_by_key ()
+    function.  */
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃæ¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë.
+
+    ´Ø¿ô mplist_get () ¤Ï¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ò»Ï¤á¤«¤éõ¤·¤Æ¡¢¥­¡¼
+    ¤¬ $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò¸«¤Ä¤±¤ë¡£¸«¤Ä¤«¤ì¤Ð¡¢¤½¤ÎÃͤò
+    <tt>(void *)</tt> ·¿¤ÇÊÖ¤¹¡£¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£
+
+    @c NULL ¤¬Ê֤俺ݤˤÏÆó¤Ä¤Î²ÄǽÀ­¤¬¤¢¤ë: 
+    ¾åµ­¤Î¤è¤¦¤Ë¥×¥í¥Ñ¥Æ¥£¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤È¡¢¥×¥í¥Ñ¥Æ¥£¤¬¸«¤Ä¤«¤ê¡¢¤½¤ÎÃͤ¬
+    @c NULL ¤Ç¤¢¤ë¾ì¹ç¤Ç¤¢¤ë¡£¤³¤ì¤é¤ò¶èÊ̤¹¤ëɬÍפ¬¤¢¤ë¾ì¹ç¤Ë¤Ï´Ø¿ô 
+    mplist_find_by_key () ¤ò»È¤¦¤³¤È¡£  */
+
+/***
+    @seealso
+    mplist_find_by_key () */
+
+void *
+mplist_get (MPlist *plist, MSymbol key)
+{
+  MPLIST_FIND (plist, key);
+  return (MPLIST_TAIL_P (plist) ? NULL : MPLIST_VAL (plist));
+}
+
+/*=*/
+
+/***en
+    @brief Set the value (function pointer) of a property in a property list.
+
+    The mplist_put_func () function is similar to mplist_put () but for
+    setting function pointer $FUNC in property list $PLIST for key
+    $KEY.  $KEY must not be a managing key.  */
+
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃæ¤Î¥×¥í¥Ñ¥Æ¥£¤Ë´Ø¿ô¥Ý¥¤¥ó¥¿¤Ç¤¢¤ëÃͤòÀßÄꤹ¤ë.
+
+    ´Ø¿ô mplist_put_func () ¤Ï´Ø¿ô mplist_put () Æ±ÍÍ¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST
+    Ãæ¤Ç¥­¡¼¤¬ $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ËÃͤòÀßÄꤹ¤ë¡£Ã¢¤·¤½¤ÎÃͤϴؿô¥Ý¥¤¥ó¥¿
+    $FUNC ¤Ç¤¢¤ë¡£$KEY ¤Ï´ÉÍý¥­¡¼¤Ç¤¢¤Ã¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£  */
+
+
+/***
+    @seealso
+    mplist_put (), M17N_FUNC ()  */
+
+MPlist *
+mplist_put_func (MPlist *plist, MSymbol key, M17NFunc func)
+{
+  if (key == Mnil || key->managing_key)
+    MERROR (MERROR_PLIST, NULL);
+  MPLIST_FIND (plist, key);
+  MPLIST_KEY (plist) = key;
+  MPLIST_FUNC (plist) = func;
+  MPLIST_SET_VAL_FUNC_P (plist);
+  if (! plist->next)
+    MPLIST_NEW ((plist)->next);
+  return plist;
+}
+
+/*=*/
+
+/***en
+    @brief Get the value (function pointer) of a property in a property list.
+
+    The mplist_get_func () function is similar to mplist_get () but for
+    getting a function pointer from property list $PLIST by key $KEY.  */
+
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤«¤é¥×¥í¥Ñ¥Æ¥£¤Î´Ø¿ô¥Ý¥¤¥ó¥¿¤Ç¤¢¤ëÃͤòÆÀ¤ë.
+
+    ´Ø¿ô mplist_get_func () ¤Ï´Ø¿ô mplist_get () ¤ÈƱÍͤˡ¢¥×¥í¥Ñ¥Æ¥£¥ê
+    ¥¹¥È $PLIST Ãæ¤Ç¥­¡¼¤¬ $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ÎÃÍ¡¢Ã¢¤·´Ø¿ô¥Ý¥¤¥ó¥¿¡¢
+    ¤òÆÀ¤ë¡£ */
+
+
+/***
+    @seealso
+    mplist_get () */
+M17NFunc
+mplist_get_func (MPlist *plist, MSymbol key)
+{
+  MPLIST_FIND (plist, key);
+  return (MPLIST_TAIL_P (plist) ? NULL : MPLIST_FUNC (plist));
+}
+
+/*=*/
+
+/***en
+    @brief Add a property at the end of a property list.
+
+    The mplist_add () function appends at the end of property list
+    $PLIST a property whose key is $KEY and value is $VAL.  $KEY can
+    be any symbol other than @c Mnil.
+
+    If $KEY is a managing key, $VAL must be a managed object.  In this
+    case, the reference count of $VAL is incremented by one.
+
+    @return
+    If the operation was successful, mplist_add () returns a sublist of
+    $PLIST whose first element is the just added one.  Otherwise, it
+    returns @c NULL.  */
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈËöÈø¤Ë¥×¥í¥Ñ¥Æ¥£¤òÄɲ乤ë.
+
+    ´Ø¿ô mplist_add () ¤Ï¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ÎËöÈø¤Ë¥­¡¼¤¬ $KEY 
+    ¤ÇÃͤ¬ $VAL ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤òÄɲ乤롣$KEY ¤Ï¡¢@c Mnil °Ê³°¤ÎǤ°Õ¤Î¥·¥ó¥Ü¥ë¤Ç¤è¤¤¡£
+
+    $KEY ¤¬´ÉÍý¥­¡¼¤Ê¤é¤Ð¡¢$VAL ¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤³¤Î¾ì¹ç¡¢
+    $VAL ¤Î»²¾È¿ô¤Ï 1 Áý¤ä¤µ¤ì¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mplist_add () ¤ÏÄɲ䵤줿Í×ÁǤ«¤é»Ï¤Þ¤ë $PLIST 
+    ¤ÎÉôʬ¥ê¥¹¥È¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£  */
+
+MPlist *
+mplist_add (MPlist *plist, MSymbol key, void *val)
+{
+  if (key == Mnil)
+    MERROR (MERROR_PLIST, NULL);
+  MPLIST_FIND (plist, Mnil);
+  if (val && key->managing_key)
+    M17N_OBJECT_REF (val);
+  MPLIST_KEY (plist) = key;
+  MPLIST_VAL (plist) = val;
+  MPLIST_NEW (plist->next);
+  return plist;
+}
+
+/*=*/
+
+/***en
+    @brief Add a property at the beginning of a property list.
+
+    The mplist_push () function inserts at the beginning of property
+    list $PLIST a property whose key is $KEY and value is $VAL.
+
+    If $KEY is a managing key, $VAL must be a managed object.  In this
+    case, the reference count of $VAL is incremented by one.
+
+    @return
+    If the operation was successful, this function returns $PLIST.
+    Otherwise, it returns @c NULL.  */
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤ÎÀèƬ¤Ë¥×¥í¥Ñ¥Æ¥£¤òÁÞÆþ¤¹¤ë.
+
+    ´Ø¿ô mplist_push () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ÎÀèƬ¤Ë¥­¡¼¤¬ $KEY 
+    ¤ÇÃͤ¬ $VAL ¤Ç¤¢¤ë¥ª¥Ö¥¸¥§¥¯¥È¤òÁÞÆþ¤¹¤ë¡£
+
+    $KEY ¤¬´ÉÍý¥­¡¼¤Ê¤é¤Ð¡¢$VAL ¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤³¤Î¾ì¹ç¡¢
+    $VAL ¤Î»²¾È¿ô¤Ï 1 Áý¤ä¤µ¤ì¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¤³¤Î´Ø¿ô¤Ï $PLIST ¤òÊÖ¤·¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð@c NULL 
+    ¤òÊÖ¤¹¡£  */
+
+MPlist *
+mplist_push (MPlist *plist, MSymbol key, void *val)
+{
+  MPlist *pl;
+
+  if (key == Mnil)
+    MERROR (MERROR_PLIST, NULL);
+  MPLIST_NEW (pl);
+  MPLIST_KEY (pl) = MPLIST_KEY (plist);
+  MPLIST_VAL (pl) = MPLIST_VAL (plist);
+  if (MPLIST_NESTED_P (plist))
+    MPLIST_SET_NESTED_P (pl);
+  MPLIST_NEXT (pl) = MPLIST_NEXT (plist);
+  plist->next = pl;
+  if (val && key->managing_key)
+    M17N_OBJECT_REF (val);
+  MPLIST_KEY (plist) = key;
+  MPLIST_VAL (plist) = val;
+  return plist;
+}
+
+/*=*/
+
+/***en
+    @brief Remove a property at the beginning of a property list.
+
+    The mplist_pop () function removes a property at the beginning of
+    property list $PLIST.  As a result, the second key and value of
+    the $PLIST become the first ones.
+
+    @return
+    If the operation was successful, this function return the value of
+    the just popped property.  Otherwise, it returns @c NULL.  */
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤ÎÀèƬ¤«¤é¥×¥í¥Ñ¥Æ¥£¤òºï½ü¤¹¤ë.
+
+    ´Ø¿ô mplist_pop () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ÎÀèƬ¤Î¥×¥í¥Ñ¥Æ¥£¤òºï
+    ½ü¤¹¤ë¡£·ë²Ì¤È¤·¤Æ¡¢¸µ¤Î2ÈÖÌܤΥ­¡¼¤ÈÃͤ¬ÀèƬ¤Î¥­¡¼¤ÈÃͤˤʤ롣
+
+    @return 
+    ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ïºï½ü¤µ¤ì¤¿¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð
+    @c NULL ¤òÊÖ¤¹¡£  */
+
+void *
+mplist_pop (MPlist *plist)
+{
+  void *val;
+  MPlist *next;
+
+  if (MPLIST_TAIL_P (plist))
+    return NULL;
+  val = MPLIST_VAL (plist);
+  next = MPLIST_NEXT (plist);
+  MPLIST_KEY (plist) = MPLIST_KEY (next);
+  MPLIST_VAL (plist) = MPLIST_VAL (next);
+  if (MPLIST_KEY (plist) != Mnil
+      && MPLIST_KEY (plist)->managing_key
+      && MPLIST_VAL (plist))
+    M17N_OBJECT_REF (MPLIST_VAL (plist));
+  MPLIST_NEXT (plist) = MPLIST_NEXT (next);
+  if (plist->next)
+    M17N_OBJECT_REF (plist->next);
+  M17N_OBJECT_UNREF (next);
+  return val;
+}
+
+/*=*/
+/***en
+    @brief Find a property of a specific key in a property list.
+
+    The mplist_find_by_key () function searches property list
+    $PLIST from the beginning for a property whose key is $KEY.  If
+    such a property is found, a sublist of $PLIST whose first element
+    is the found one is returned.  Otherwise, @c NULL is returned.
+
+    If $KEY is @c Mnil, it returns a sublist of $PLIST whose
+    first element is the last one of $PLIST.  */
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃ椫¤é»ØÄê¤Î¥­¡¼¤ò»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤òõ¤¹.
+
+    ´Ø¿ô mplist_find_by_key () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST 
+    ¤ò»Ï¤á¤«¤éõ ¤·¤Æ¡¢¥­¡¼¤¬ $KEY 
+    ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò¸«¤Ä¤±¤ë¡£¸«¤Ä¤«¤ì¤Ð¡¢¤½¤Î¥×¥í¥Ñ¥Æ¥£¤«¤é»Ï¤Þ¤ë
+    $PLIST ¤ÎÉôʬ¥ê¥¹¥È¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£
+
+    $KEY ¤¬ @c Mnil ¤Ê¤é¤Ð¡¢$PLIST ¤ÎºÇ¸å¤ÎÍ×ÁǤ«¤é»Ï¤Þ¤ëÉôʬ¥ê¥¹¥È¤òÊÖ¤¹¡£  */
+
+MPlist *
+mplist_find_by_key (MPlist *plist, MSymbol key)
+{
+  MPLIST_FIND (plist, key);
+  return (MPLIST_TAIL_P (plist)
+         ? (key == Mnil ? plist : NULL)
+         : plist);
+}
+
+/*=*/
+/***en
+    @brief Find a property of a specific value in a property list.
+
+    The mplist_find_by_value () function searches property list $PLIST
+    from the beginning for a property whose value is $VAL.  If such a
+    property is found, a sublist of $PLIST whose first element is the
+    found one is returned.  Otherwise, @c NULL is returned.  */
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃ椫¤é»ØÄê¤ÎÃͤò»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤òõ¤¹.
+
+    ´Ø¿ô mplist_find_by_value () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST 
+    ¤ò»Ï¤á¤«¤éõ¤·¤Æ¡¢Ãͤ¬ $VAL 
+    ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò¸«¤Ä¤±¤ë¡£¸«¤Ä¤«¤ì¤Ð¡¢¤½¤Î¥×¥í¥Ñ¥Æ¥£¤«¤é»Ï¤Þ¤ë
+    $PLIST ¤ÎÉôʬ¥ê¥¹¥È¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£ */
+
+MPlist *
+mplist_find_by_value (MPlist *plist, void *val)
+{
+  MPLIST_DO (plist, plist)
+    {
+      if (MPLIST_VAL (plist) == val)
+       return plist;
+    }
+  return NULL;
+}
+
+/*=*/
+
+/***en
+    @brief Return the next sublist of a property list.
+
+    The mplist_next () function returns a pointer to the sublist of
+    property list $PLIST, which begins at the second element in $PLIST.  If the
+    length of $PLIST is zero, it returns @c NULL.  */
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤Î¼¡¤ÎÉôʬ¥ê¥¹¥È¤òÊÖ¤¹.
+
+    ´Ø¿ô mplist_next () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤Î 2 
+    ÈÖÌܤÎÍ×ÁǤ«¤é»Ï¤Þ¤ëÉôʬ¥ê¥¹¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£$PLIST ¤ÎŤµ¤¬ 0 
+    ¤Ê¤é¤Ð @c NULL ¤òÊÖ¤¹¡£  */
+
+MPlist *
+mplist_next (MPlist *plist)
+{
+  return (MPLIST_TAIL_P (plist) ? NULL : plist->next);
+}
+
+/*=*/
+
+/***en
+    @brief Set the first property in a property list.
+
+    The mplist_set () function sets the key and the value of the first
+    property in property list $PLIST to $KEY and $VALUE, respectively.
+    See the documentation of mplist_add () for the restriction on $KEY
+    and $VAL.
+
+    @return
+    If the operation was successful, mplist_set () returns $PLIST.
+    Otherwise, it returns @c NULL.  */
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤ÎºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤òÀßÄꤹ¤ë.
+
+    ´Ø¿ô mplist_set () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST 
+    ¤ÎºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤ÈÃͤò¤½¤ì¤¾¤ì $KEY ¤È $VALUE ¤ËÀßÄꤹ¤ë¡£
+    $KEY ¤È $VAL ¤ËÂФ¹¤ëÀ©¸Â¤Ë¤Ä¤¤¤Æ¤Ï¡¢mplist_add () ¤ÎÀâÌÀ¤ò»²¾È¡£
+
+    @return
+    ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð mplist_set () ¤Ï $PLIST ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£  */
+
+MPlist *
+mplist_set (MPlist *plist, MSymbol key, void * val)
+{
+  if (key == Mnil)
+    {
+      if (! MPLIST_TAIL_P (plist))
+       {
+         key = MPLIST_KEY (plist);
+         M17N_OBJECT_UNREF (MPLIST_NEXT (plist));
+         MPLIST_KEY (plist) = Mnil;
+         if (key->managing_key)
+           M17N_OBJECT_UNREF (MPLIST_VAL (plist));
+         plist->next = NULL;
+       }
+    }
+  else
+    {
+      if (val && key->managing_key)
+       M17N_OBJECT_REF (val);
+      if (! MPLIST_TAIL_P (plist)
+         && MPLIST_KEY (plist)->managing_key)
+       M17N_OBJECT_UNREF (MPLIST_VAL (plist));
+      MPLIST_SET (plist, key, val);
+    }
+  return plist;
+}
+
+/*=*/
+
+/***en
+    @brief Return the length of a property list.
+
+    The mplist_length () function returns the number of properties in
+    property list  $PLIST.  */
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤ÎŤµ¤òÊÖ¤¹.
+
+    ´Ø¿ô mplist_length () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST Ãæ¤Î¥×¥í¥Ñ¥Æ¥£¤Î¿ô¤òÊÖ¤¹¡£  */
+
+int
+mplist_length (MPlist *plist)
+{
+  int n;
+
+  for (n = 0; ! (MPLIST_TAIL_P (plist)); n++, plist = plist->next);
+  return n;
+}
+
+/*=*/
+
+/***en
+    @brief Return the key of the first property in a property list.
+
+    The mplist_key () function returns the key of the first property
+    in property list $PLIST.  If the length of $PLIST is zero,
+    it returns @c Mnil.  */
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃæ¤ÎºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤òÊÖ¤¹.
+
+    ´Ø¿ô mplist_key () ¤Ï¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST 
+    Ãæ¤ÎºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤òÊÖ¤¹¡£$PLIST ¤ÎŤµ¤¬ 0 ¤Ê¤é¤Ð¡¢ @c Mnil 
+    ¤òÊÖ¤¹¡£  */
+
+MSymbol
+mplist_key (MPlist *plist)
+{
+  return MPLIST_KEY (plist);
+}
+
+/*=*/
+
+/***en
+    @brief Return the value of the first property in a property list.
+
+    The mplist_value () function returns the value of the first
+    property in property list  $PLIST.  If the length of $PLIST
+    is zero, it returns @c NULL.  */
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃæ¤ÎºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹.
+
+    ´Ø¿ô mplist_value () ¤Ï¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST Ãæ¤ÎºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£
+    $PLIST ¤ÎŤµ¤¬ 0 ¤Ê¤é¤Ð¡¢ @c Mnil ¤òÊÖ¤¹¡£  */
+
+void *
+mplist_value (MPlist *plist)
+{
+  return MPLIST_VAL (plist);
+}
+
+/***en
+    @brief Generate a property list by deserializing an M-text.
+
+    The mplist_deserialize () function parses M-text $MT and returns a
+    property list.
+
+    The syntax of $MT is as follows.
+
+    MT ::= '(' ELEMENT * ')'
+
+    ELEMENT ::= SYMBOL | INTEGER | M-TEXT | PLIST
+
+    SYMBOL ::= ascii-character-sequence
+
+    INTEGER ::= '-' ? [ '0' | .. | '9' ]+
+               | '0x' [ '0' | .. | '9' | 'A' | .. | 'F' | 'a' | .. | 'f' ]+
+
+    M-TEXT ::= '"' character-sequence '"'
+
+    Each alternatives of @c ELEMENT is assigned one of these keys: @c
+    Msymbol, @c Minteger, @c Mtext, @c Mplist
+
+    In an ascii-character-sequence, a backslash (\) is used as the escape
+    character, which means that, for instance, <tt>abc\ def</tt>
+    produces a symbol whose name is of length seven with the fourth
+    character being a space.  */
+/***ja
+    @brief M-text ¤ò¥Ç¥·¥ê¥¢¥é¥¤¥º¤·¤Æ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤òºî¤ë.
+
+    ´Ø¿ô mplist_deserialize () ¤Ï M-text $MT ¤ò²òÀϤ·¤Æ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤òÊÖ¤¹¡£
+
+    $MT ¤Î¥·¥ó¥¿¥Ã¥¯¥¹¤Ï°Ê²¼¤ÎÄ̤ꡣ
+
+    MT ::= '(' ELEMENT * ')'
+
+    ELEMENT ::= SYMBOL | INTEGER | M-TEXT | PLIST
+
+    SYMBOL ::= ¥¢¥¹¥­¡¼Ê¸»úÎó
+
+    INTEGER ::= '-' ? [ '0' | .. | '9' ]+
+               | '0x' [ '0' | .. | '9' | 'A' | .. | 'F' | 'a' | .. | 'f' ]+
+
+    M-TEXT ::= '"' character-sequence '"'
+
+    @c ELEMENT ¤Î³ÆÁªÂò»è¤Ï¥­¡¼¡§@c Msymbol, @c Minteger, @c Mtext,
+    @c Mplist ¤Î¤¤¤º¤ì¤«¤ò³ä¤êÅö¤Æ¤é¤ì¤Æ¤¤¤ë¡£
+
+    ¥¢¥¹¥­¡¼Ê¸»úÎóÆâ¤Ç¤Ï¡¢¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å (\) ¤¬¥¨¥¹¥±¡¼¥×ʸ»ú¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£¤¿¤È¤¨¤Ð
+    <tt>abc\ def</tt> ¤Ï 4 Ê¸»úÌܤ¬¶õÇòʸ»ú¤Ç¤¢¤êŤµ¤¬ 7 
+    ¤Ç¤¢¤ë»ý¤Ä̾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤òÀ¸À®¤¹¤ë¡£   */
+
+MPlist *
+mplist_deserialize (MText *mt)
+{
+  MPlist *plist;
+  MText *tmp = NULL;
+
+  if (mt->format > MTEXT_FORMAT_UTF_8)
+    {
+      if (MTEXT_READ_ONLY_P (mt))
+       mt = tmp = mtext_cpy (mtext (), mt);
+      else
+       mtext__adjust_format (mt, MTEXT_FORMAT_UTF_8);
+    }
+  plist = mplist__from_string (MTEXT_DATA (mt), mtext_nbytes (mt));
+  if (tmp)
+    M17N_OBJECT_UNREF (tmp);
+  return plist;
+}
+
+/*** @}  */
+
+/*** @addtogroup m17nDebug */
+/*=*/
+/*** @{  */
+
+/***en
+    @brief Dump a property list.
+
+    The mdebug_dump_plist () function prints a property list $PLIST in
+    a human readable way to the stderr.  $INDENT specifies how many
+    columns to indent the lines but the first one.
+
+    @return
+    This function returns $PLIST.  */
+/***ja
+    @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤ò¥À¥ó¥×¤¹¤ë.
+
+    ´Ø¿ô mdebug_dump_plist () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ò stderr 
+    ¤Ë¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç°õºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï $PLIST ¤òÊÖ¤¹¡£  */
+MPlist *
+mdebug_dump_plist (MPlist *plist, int indent)
+{
+  char *prefix = (char *) alloca (indent + 1);
+  MPlist *pl;
+
+  memset (prefix, 32, indent);
+  prefix[indent] = 0;
+
+  fprintf (stderr, "(");
+  MPLIST_DO (pl, plist)
+    {
+      if (pl != plist)
+       fprintf (stderr, "\n%s ", prefix);
+      write_element (NULL, pl, indent + 1);
+    }
+  fprintf (stderr, ")");
+  return plist;
+}
+
+/*** @} */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/plist.h b/src/plist.h
new file mode 100644 (file)
index 0000000..c6cf5aa
--- /dev/null
@@ -0,0 +1,120 @@
+/* plist.h -- header file for the plist module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_PLIST_H_
+#define _M17N_PLIST_H_
+
+struct MPlist
+{
+  /** Header for a managed object.  */
+  M17NObject control;
+
+  /**en Key of the first element of the plist.  If the value is Mnil,
+     this is the tail of the plist.  In that case, <val> and <next> is
+     NULL.  If the value is a managing key, <val> is a managed
+     object.  */
+  MSymbol key;
+
+  /**en Value of the first element of the plist.  */
+  union {
+    void *pointer;
+    M17NFunc func;
+  } val;
+
+  /**en Plist for the next element. */
+  MPlist *next;
+};
+
+/** Macros to access each member of PLIST.  */
+
+#define MPLIST_KEY(plist) ((plist)->key)
+#define MPLIST_VAL(plist) ((plist)->val.pointer)
+#define MPLIST_FUNC(plist) ((plist)->val.func)
+#define MPLIST_NEXT(plist) ((plist)->next)
+#define MPLIST_TAIL_P(plist) ((plist)->key == Mnil)
+
+#define MPLIST_SYMBOL_P(plist) (MPLIST_KEY (plist) == Msymbol)
+#define MPLIST_STRING_P(plist) (MPLIST_KEY (plist) == Mstring)
+#define MPLIST_MTEXT_P(plist) (MPLIST_KEY (plist) == Mtext)
+#define MPLIST_INTEGER_P(plist) (MPLIST_KEY (plist) == Minteger)
+#define MPLIST_PLIST_P(plist) (MPLIST_KEY (plist) == Mplist)
+
+#define MPLIST_NESTED_P(plist) \
+  ((plist)->control.flag & 1)
+#define MPLIST_SET_NESTED_P(plist)     \
+  ((plist)->control.flag |= 1)
+
+#define MPLIST_VAL_FUNC_P(plist)       \
+  ((plist)->control.flag & 2)
+#define MPLIST_SET_VAL_FUNC_P(plist)   \
+  ((plist)->control.flag |= 2)
+
+#define MPLIST_SYMBOL(plist) ((MSymbol) MPLIST_VAL (plist))
+#define MPLIST_STRING(plist) ((char *) MPLIST_VAL (plist))
+#define MPLIST_MTEXT(plist) ((MText *) MPLIST_VAL (plist))
+#define MPLIST_INTEGER(plist) ((int) MPLIST_VAL (plist))
+#define MPLIST_PLIST(plist) ((MPlist *) MPLIST_VAL (plist))
+
+#define MPLIST_FIND(plist, key)                                                \
+  do {                                                                 \
+    while (! MPLIST_TAIL_P (plist) && MPLIST_KEY (plist) != (key))     \
+      (plist) = (plist)->next;                                         \
+  } while (0)
+
+
+#define MPLIST_DO(elt, plist)  \
+  for ((elt) = (plist); ! MPLIST_TAIL_P (elt); (elt) = MPLIST_NEXT (elt))
+
+#define MPLIST_LENGTH(plist)                   \
+  (MPLIST_TAIL_P (plist) ? 0                   \
+   : MPLIST_TAIL_P ((plist)->next) ? 1         \
+   : MPLIST_TAIL_P ((plist)->next->next) ? 2   \
+   : mplist_length (plist))
+
+#define MPLIST_ADD_PLIST(PLIST, KEY, VAL) \
+  MPLIST_SET_NESTED_P (mplist_add ((PLIST), (KEY), (VAL)))
+#define MPLIST_PUSH_PLIST(PLIST, KEY, VAL) \
+  MPLIST_SET_NESTED_P (mplist_push ((PLIST), (KEY), (VAL)))
+#define MPLIST_PUT_PLIST(PLIST, KEY, VAL) \
+  MPLIST_SET_NESTED_P (mplist_put ((PLIST), (KEY), (VAL)))
+
+
+extern unsigned char hex_mnemonic[256];
+extern unsigned char escape_mnemonic[256];
+
+extern MPlist *mplist__from_file (FILE *fp, MPlist *keys);
+
+extern MPlist *mplist__from_plist (MPlist *plist);
+
+extern MPlist *mplist__from_alist (MPlist *plist);
+
+extern MPlist *mplist__from_string (unsigned char *str, int n);
+
+extern int mplist__serialize (MText *mt, MPlist *plist, int pretty);
+
+extern MPlist *mplist__conc (MPlist *plist, MPlist *tail);
+
+extern void mplist__pop_unref (MPlist *plist);
+
+extern MPlist *mplist__assq (MPlist *plist, MSymbol key);
+
+#endif  /* _M17N_PLIST_H_ */
diff --git a/src/symbol.c b/src/symbol.c
new file mode 100644 (file)
index 0000000..faf97fe
--- /dev/null
@@ -0,0 +1,844 @@
+/* symbol.c -- symbol module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nSymbol
+
+    @brief Symbol objects and API for them.
+
+    The m17n library uses objects called @e symbols as unambiguous
+    identifiers.  Symbols are similar to atoms in the X library, but a
+    symbol can have zero or more @e symbol @e properties.  A symbol
+    property consists of a @e key and a @e value, where key is also a
+    symbol and value is anything that can be cast to <tt>(void *)</tt>.  
+    "The symbol property that belongs to the symbol S and
+    whose key is K" may be shortened to "K property of S".
+
+    Symbols are used mainly in the following three ways.
+
+    @li As keys of symbol properties and other properties.
+
+    @li To represent various objects, e.g. charsets, coding systems,
+    fontsets.
+
+    @li As arguments of the m17n library functions to control
+    their behavior.
+
+    There is a special kind of symbol, a @e managing @e key.  The
+    value of a property whose key is a managing key must be a @e
+    managed @e object.  See @ref m17nObject for the detail.
+*/
+/***ja
+    @addtogroup m17nSymbol ¥·¥ó¥Ü¥ë
+
+    @brief ¥·¥ó¥Ü¥ë¥ª¥Ö¥¸¥§¥¯¥È¤È¤½¤ì¤Ë´Ø¤¹¤ë API.
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Ï°ì°Õ¤Ë·è¤Þ¤ë¼±Ê̻ҤȤ·¤Æ @e ¥·¥ó¥Ü¥ë 
+    ¤È¸Æ¤Ö¥ª¥Ö¥¸¥§¥¯¥È¤òÍѤ¤¤ë¡£¥·¥ó¥Ü¥ë¤Ï X ¥é¥¤¥Ö¥é¥ê¤Î¥¢¥È¥à¤È»÷¤Æ¤¤¤ë¤¬¡¢
+    0 ¸Ä°Ê¾å¤Î @e ¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£ ¤ò»ý¤Ä¤³¤È¤¬¤Ç¤­¤ë¡£¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤Ï
+    @e ¥­¡¼ ¤È @e ÃÍ ¤«¤é¤Ê¤ë¡£¥­¡¼¤Ï¤½¤ì¼«ÂÎ¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢ÃͤϠ
+    <tt>(void *)</tt> ·¿¤Ë¥­¥ã¥¹¥È¤Ç¤­¤ë¤â¤Î¤Ê¤é²¿¤Ç¤â¤è¤¤¡£¡Ö¥·¥ó¥Ü¥ë 
+    S ¤¬»ý¤Ä¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¥­¡¼¤¬ K ¤Î¤â¤Î¡×¤ò´Êñ¤Ë¡ÖS ¤Î K 
+    ¥×¥í¥Ñ¥Æ¥£¡×¤È¸Æ¤Ö¤³¤È¤¬¤¢¤ë¡£
+
+    ¥·¥ó¥Ü¥ë¤ÎÍÑÅӤϼç¤Ë°Ê²¼¤Î3Ä̤ê¤Ç¤¢¤ë¡£
+
+    @li ¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ª¤è¤Ó¾¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤òɽ¤¹¡£
+
+    @li Ê¸»ú¥»¥Ã¥È¡¢¥³¡¼¥É·Ï¡¢¥Õ¥©¥ó¥È¥»¥Ã¥È¤Ê¤É¤Î³Æ¼ï¥ª¥Ö¥¸¥§¥¯¥È¤òɽ¤¹¡£
+
+    @li m17n ¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Î°ú¿ô¤È¤Ê¤ê¡¢´Ø¿ô¤ÎµóÆ°¤òÀ©¸æ¤¹¤ë¡£
+
+    @e ´ÉÍý¥­¡¼ ¤È¸Æ¤Ð¤ì¤ëÆÃÊ̤ʥ·¥ó¥Ü¥ë¤¬¤¢¤ê¡¢´ÉÍý¥­¡¼¤ò¥­¡¼¤È¤·¤Æ»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤ÎÃͤÏ
+    @e ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¾ÜºÙ¤Ï @ref m17nObject »²¾È¡£
+*/
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "m17n.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "symbol.h"
+#include "character.h"
+#include "mtext.h"
+#include "plist.h"
+
+static int num_symbols;
+
+#define SYMBOL_TABLE_SIZE 1024
+
+static MSymbol symbol_table[SYMBOL_TABLE_SIZE];
+
+static unsigned
+hash_string (const char *str, int len)
+{
+  unsigned hash = 0;
+  const char *end = str + len;
+  unsigned c;
+
+  while (str < end)
+    {
+      c = *((unsigned char *) str++);
+      if (c >= 0140)
+       c -= 40;
+      hash = ((hash << 3) + (hash >> 28) + c);
+    }
+  return hash & (SYMBOL_TABLE_SIZE - 1);
+}
+
+
+static MPlist *
+serialize_symbol (void *val)
+{
+  MPlist *plist = mplist ();
+
+  mplist_add (plist, Msymbol, val);
+  return plist;
+}
+
+static void *
+deserialize_symbol (MPlist *plist)
+{
+  return (MPLIST_SYMBOL_P (plist) ? MPLIST_SYMBOL (plist) : Mnil);
+}
+
+\f
+/* Internal API */
+
+int
+msymbol__init ()
+{
+  num_symbols = 0;
+  Mnil = (MSymbol) 0;
+  Mt = msymbol ("t");
+  Msymbol = msymbol ("symbol");
+  Mstring = msymbol ("string");
+  return 0;
+}
+
+void
+msymbol__fini ()
+{
+  int i;
+  MSymbol sym;
+
+  for (i = 0; i < SYMBOL_TABLE_SIZE; i++)
+    for (sym = symbol_table[i]; sym; sym = sym->next)
+      if (! MPLIST_TAIL_P (&sym->plist))
+       {
+         if (sym->plist.key->managing_key)
+           M17N_OBJECT_UNREF (MPLIST_VAL (&sym->plist));
+         M17N_OBJECT_UNREF (sym->plist.next);
+         sym->plist.key = Mnil;
+       }
+}
+
+void
+msymbol__free_table ()
+{
+  int i;
+  MSymbol sym, next;
+  int freed_symbols = 0;
+
+  for (i = 0; i < SYMBOL_TABLE_SIZE; i++)
+    {
+      for (sym = symbol_table[i]; sym; sym = next)
+       {
+         next = sym->next;
+         free (sym->name);
+         free (sym);
+         freed_symbols++;
+       }
+      symbol_table[i] = NULL;
+    }
+  if (mdebug__flags[MDEBUG_FINI])
+    fprintf (stderr, "%16s %7d %7d %7d\n", "Symbol",
+            num_symbols, freed_symbols, num_symbols - freed_symbols);
+  num_symbols = 0;
+}
+
+
+MSymbol
+msymbol__with_len (const char *name, int len)
+{
+  char *p = alloca (len + 1);
+
+  memcpy (p, name, len);
+  p[len] = '\0';
+  return msymbol (p);
+}
+
+/** Return a plist of symbols that has non-NULL property PROP.  If
+    PROP is Mnil, return a plist of all symbols.  Values of the plist
+    is NULL.  */
+
+MPlist *
+msymbol__list (MSymbol prop)
+{
+  MPlist *plist = mplist ();
+  int i;
+  MSymbol sym;
+
+  for (i = 0; i < SYMBOL_TABLE_SIZE; i++)
+    for (sym = symbol_table[i]; sym; sym = sym->next)
+      if (prop == Mnil || msymbol_get (sym, prop))
+       mplist_push (plist, sym, NULL);
+  return plist;
+}
+
+
+/** Canonicalize the name of SYM, and return a symbol of the
+    canonicalized name.  Canonicalization is done by this rule:
+       o convert all uppercase characters to lowercase.
+       o remove all non alpha-numeric characters.
+       o change the leading "ibm" to "cp".
+       o change the leading "windows-" to "cp".
+       o change the leading "cp" to "ibm".
+       o remove the leading "iso".
+    For instance:
+       "ISO-8859-2" -> "88592"
+       "euc-JP" -> "eucjp"
+       "IBM851" -> "cp851"
+       "windows-1250" -> "cp250"
+
+    This function is used to canonicalize charset and coding system
+    names.  */
+
+MSymbol
+msymbol__canonicalize (MSymbol sym)
+{
+  char *name = sym->name;
+  /* Extra 2 bytes are for changing "cpXXX" to "ibmXXX" and
+     terminating '\0'.  */
+  char *canon = (char *) alloca (strlen (name) + 2);
+  char *p = canon;
+
+  for (; *name; name++)
+    if (ISALNUM (*name))
+      *p++ = TOLOWER (*name);
+  *p = '\0';
+  if (p - canon > 3 && canon[0] == 'i')
+    {
+      if (canon[1] == 'b' && canon[2] == 'm' && isdigit (canon[3]))
+       {
+         /* Change "ibmXXX" to "cpXXX".  */
+         canon++;
+         canon[0] = 'c';
+         canon[1] = 'p';
+       }
+      else if (canon[1] == 's' && canon[2] == 'o')
+       {
+         /* Change "isoXXX" to "XXX".  */
+         canon += 3;
+       }
+    }
+  else if (p - canon > 2
+          && canon[0] == 'c' && canon[1] == 'p' && isdigit (canon[2]))
+    {
+      /* Change "cpXXX" to "ibmXXX".  */
+      for (; p >= canon + 2; p--)
+       p[1] = p[0];
+      canon[0] = 'i';
+      canon[1] = 'b';
+      canon[2] = 'm';
+    }
+  else if (canon[0] == 'w' && p - canon > 7
+          && memcmp (canon + 1, "indows", 6) == 0
+          && isdigit (canon[7]))
+    {
+      /* Change "windowsXXX" to "cpXXX" */
+      canon += 5;
+      canon[0] = 'c';
+      canon[1] = 'p';
+    }
+  return msymbol (canon);
+}
+
+MTextPropSerializeFunc msymbol__serializer = serialize_symbol;
+MTextPropDeserializeFunc msymbol__deserializer = deserialize_symbol;
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+/* External API */
+
+/*** @addtogroup m17nSymbol */
+/*** @{ */
+
+/*=*/
+/***en
+    @brief Symbol whose name is "nil".
+
+    The symbol #Mnil has the name <tt>"nil"</tt> and, in general,
+    represents @e false or @e no.  When coerced to "int", its value is
+    zero.  #Mnil can't have any symbol property.  */
+/***ja
+    @brief "nil" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mnil ¤Ï <tt>"nil"</tt> 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢°ìÈ̤ˡֵ¶¡×¤Þ¤¿¤Ï¡ÖÈÝÄê¡×¤ò°ÕÌ£¤¹¤ë¡£
+    "int" ¤ËÊÑ´¹¤µ¤ì¤¿¾ì¹ç¡¢ÃͤϠ0 ¤Ç¤¢¤ë¡£
+    #Mnil ¼«¿È¤Ï¤¤¤«¤Ê¤ë¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤â»ý¤¿¤Ê¤¤¡£  */
+
+MSymbol Mnil;
+
+/*=*/
+
+/***en
+    @brief Symbol whose name is "t".
+
+    The symbol #Mt has the name <tt>"t"</tt> and, in general,
+    represents @e true or @e yes.  */
+/***ja
+    @brief "t" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mt ¤Ï <tt>"t"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢°ìÈ̤ˡֿ¿¡×¤Þ¤¿¤Ï¡Ö¹ÎÄê¡×¤ò°ÕÌ£¤¹¤ë¡£  */
+
+MSymbol Mt;
+
+/*=*/
+
+/***en
+    @brief Symbol whose name is "string".
+
+    The symbol #Mstring has the name <tt>"string"</tt> and is used
+    as an argument of the functions mchar_define_property (),
+    etc.  */
+/***ja
+    @brief "string" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
+
+    ¥·¥ó¥Ü¥ë #Mstring ¤Ï <tt>"string"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢´Ø¿ô 
+    mchar_define_property () ¤Ê¤É¤Î°ú¿ô¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£  */
+
+MSymbol Mstring;
+
+/*=*/
+
+/***en
+    @brief Symbol whose name is "symbol".
+
+    The symbol #Msymbol has the name <tt>"symbol"</tt> and is used
+    as an argument of the functions mchar_define_property (),
+    etc.  */
+/***ja
+    @brief "symbol" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
+
+    ÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë #Msymbol ¤Ï <tt>"symbol"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢´Ø¿ô
+    mchar_define_property () ¤Ê¤É¤Î°ú¿ô¤È¤·¤Æ»È¤ï¤ì¤ë¡£  */
+
+MSymbol Msymbol;
+
+/*=*/
+
+/***en
+    @brief Get a symbol.
+
+    The msymbol () function returns the canonical symbol whose name is
+    $NAME.  If there is none, one is created.  The created one is not
+    a managing key.
+
+    Symbols whose name starts by two spaces are reserved by the m17n
+    library, and are used by the library only internally.
+
+    @return
+    This function returns the found or created symbol.
+
+    @errors
+    This function never fails.  */
+/***ja
+    @brief ¥·¥ó¥Ü¥ë¤òÆÀ¤ë.
+
+    ´Ø¿ô msymbol () ¤Ï $NAME 
+    ¤È¤¤¤¦Ì¾Á°¤ò»ý¤ÄÀµµ¬²½¤µ¤ì¤¿¥·¥ó¥Ü¥ë¤òÊÖ¤¹¡£¤½¤Î¤è¤¦¤Ê¥·¥ó¥Ü¥ë¤¬Â¸ºß¤·¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢À¸À®¤¹¤ë¡£À¸À®¤µ¤ì¤¿¥·¥ó¥Ü¥ë¤Ï´ÉÍý¥­¡¼¤Ç¤Ï¤Ê¤¤¡£
+
+    ¶õÇòʸ»úÆó¤Ä¤Ç»Ï¤Þ¤ë¥·¥ó¥Ü¥ë¤Ï m17n ¥é¥¤¥Ö¥é¥êÍѤǤ¢¤ê¡¢ÆâÉôŪ¤Ë¤Î¤ßÍѤ¤¤é¤ì¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¸«¤Ä¤±¤¿¤«À¸À®¤·¤¿¤«¤·¤¿¥·¥ó¥Ü¥ë¤òÊÖ¤¹¡£
+
+    @errors
+    ¤³¤Î´Ø¿ô¤Ï·è¤·¤Æ¼ºÇÔ¤·¤Ê¤¤¡£
+
+    @latexonly \IPAlabel{msymbol} @endlatexonly  */
+
+/***
+    @seealso
+    msymbol_as_managing_key (), msymbol_name (), msymbol_exist ()  */
+
+MSymbol
+msymbol (const char *name)
+{
+  MSymbol sym;
+  int len;
+  unsigned hash;
+
+  len = strlen (name);
+  if (len == 3 && name[0] == 'n' && name[1] == 'i' && name[2] == 'l')
+    return Mnil;
+  hash = hash_string (name, len);
+  len++;
+  for (sym = symbol_table[hash]; sym; sym = sym->next)
+    if (len == sym->length
+       && *name == *(sym->name)
+       && ! memcmp (name, sym->name, len))
+      return sym;
+
+  num_symbols++;
+  MTABLE_CALLOC (sym, 1, MERROR_SYMBOL);
+  MTABLE_MALLOC (sym->name, len, MERROR_SYMBOL);
+  memcpy (sym->name, name, len);
+  sym->length = len;
+  sym->next = symbol_table[hash];
+  symbol_table[hash] = sym;
+  return sym;
+}
+
+/***en
+    @brief Create a managing key.
+
+    The msymbol_as_managing_key () function returns a newly created
+    managing key whose name is $NAME.  It there already exists a
+    symbol of name $NAME, it returns #Mnil.
+
+    Symbols whose name starts by two spaces are reserved by the m17n
+    library, and are used by the library only internally.
+
+    @return
+    If the operation was successful, this function returns the created
+    symbol.  Otherwise, it returns #Mnil.  */
+/***ja
+    @brief ´ÉÍý¥­¡¼¤òºî¤ë.
+
+    ´Ø¿ô msymbol_as_managing_key () ¤Ï̾Á° $NAME 
+    ¤ò»ý¤Ä¿·¤·¤¯ºî¤é¤ì¤¿´ÉÍý¥­¡¼¤òÊÖ¤¹¡£¤¹¤Ç¤Ë̾Á° $NAME ¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤¬¤¢¤ì¤Ð¡¢
+    #Mnil ¤òÊÖ¤¹¡£
+
+    ¶õÇòʸ»úÆó¤Ä¤Ç»Ï¤Þ¤ë¥·¥ó¥Ü¥ë¤Ï m17n ¥é¥¤¥Ö¥é¥êÍѤǤ¢¤ê¡¢ÆâÉôŪ¤Ë¤Î¤ßÍѤ¤¤é¤ì¤ë¡£
+
+    @return
+    ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤ÏÀ¸À®¤·¤¿¥·¥ó¥Ü¥ë¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð
+    #Mnil ¤òÊÖ¤¹¡£   */
+
+/***
+    @errors
+    MERROR_SYMBOL
+
+    @seealso
+    msymbol (), msymbol_exist ()  */
+
+MSymbol
+msymbol_as_managing_key (const char *name)
+{
+  MSymbol sym;
+  int len;
+  unsigned hash;
+
+  len = strlen (name);
+  if (len == 3 && name[0] == 'n' && name[1] == 'i' && name[2] == 'l')
+    MERROR (MERROR_SYMBOL, Mnil);
+  hash = hash_string (name, len);
+  len++;
+  for (sym = symbol_table[hash]; sym; sym = sym->next)
+    if (len == sym->length
+       && *name == *(sym->name)
+       && ! memcmp (name, sym->name, len))
+      MERROR (MERROR_SYMBOL, Mnil);
+
+  num_symbols++;
+  MTABLE_CALLOC (sym, 1, MERROR_SYMBOL);
+  sym->managing_key = 1;
+  MTABLE_MALLOC (sym->name, len, MERROR_SYMBOL);
+  memcpy (sym->name, name, len);
+  sym->length = len;
+  sym->next = symbol_table[hash];
+  symbol_table[hash] = sym;
+  return sym;
+}
+
+/*=*/
+
+/***en
+    @brief Check if a symbol is a managing key.
+
+    The msymbol_is_managing_key () function checks if the symbol
+    $SYMBOL is a managing key or not.
+
+    @return 
+    Return 1 if the symbol is a managing key.  Otherwise,
+    return 0.  */
+
+int
+msymbol_is_managing_key (MSymbol symbol)
+{
+  return (symbol->managing_key == 1);
+}
+
+/*=*/
+
+/***en
+    @brief Search for a symbol that has a specified name.
+
+    The msymbol_exist () function searches for the symbol whose name
+    is $NAME.
+
+    @return
+    If such a symbol exists, msymbol_exist () returns that symbol.
+    Otherwise it returns the predefined symbol #Mnil.
+
+    @errors
+    This function never fails.  */
+/***ja
+    @brief »ØÄꤵ¤ì¤¿Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤òõ¤¹.
+
+    ´Ø¿ô msymbol_exist () ¤Ï $NAME ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤òõ¤¹¡£
+
+    @return
+    ¤â¤·¤½¤Î¤è¤¦¤Ê¥·¥ó¥Ü¥ë¤¬Â¸ºß¤¹¤ë¤Ê¤é¤Ð¤½¤Î¥·¥ó¥Ü¥ë¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢ÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë
+    #Mnil ¤òÊÖ¤¹¡£  
+
+    @errors
+    ¤³¤Î´Ø¿ô¤Ï·è¤·¤Æ¼ºÇÔ¤·¤Ê¤¤¡£     */
+
+/***@seealso
+    msymbol_name (), msymbol ()  */
+
+MSymbol
+msymbol_exist (const char *name)
+{
+  MSymbol sym;
+  int len;
+  unsigned hash;
+
+  len = strlen (name);
+  if (len == 3 && name[0] == 'n' && name[1] == 'i' && name[2] == 'l')
+    return Mnil;
+  hash = hash_string (name, len);
+  len++;
+  for (sym = symbol_table[hash]; sym; sym = sym->next)
+    if (len == sym->length
+       && *name == *(sym->name)
+       && ! memcmp (name, sym->name, len))
+      return sym;
+  return Mnil;
+}
+
+/*=*/
+
+/***en
+    @brief Get symbol name.
+
+    The msymbol_name () function returns a pointer to a string
+    containing the name of $SYMBOL.
+
+    @errors
+    This function never fails.  */
+/***ja
+    @brief ¥·¥ó¥Ü¥ë¤Î̾Á°¤òÆÀ¤ë.
+
+    ´Ø¿ô msymbol_name () ¤Ï»ØÄꤵ¤ì¤¿¥·¥ó¥Ü¥ë $SYMBOL 
+    ¤Î̾Á°¤ò´Þ¤àʸ»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
+
+    @errors
+    ¤³¤Î´Ø¿ô¤Ï·è¤·¤Æ¼ºÇÔ¤·¤Ê¤¤¡£     */
+
+/***@seealso
+    msymbol (), msymbol_exist ()  */
+
+char *
+msymbol_name (MSymbol symbol)
+{
+  return (symbol == Mnil ? "nil" : symbol->name);
+}
+
+/*=*/
+/***en
+    @brief Set the value of a symbol property.
+
+    The msymbol_put () function assigns $VAL to the value of the
+    symbol property that belongs to $SYMBOL and whose key is $KEY.  If
+    the symbol property already has a value, $VAL overwrites the old
+    one.  Both $SYMBOL and $KEY must not be #Mnil.
+
+    If $KEY is a managing key, $VAL must be a managed object.  In this
+    case, the reference count of the old value, if not @c NULL, is
+    decremented by one, and that of $VAL is incremented by one.
+
+    @return
+    If the operation was successful, msymbol_put () returns 0.
+    Otherwise it returns -1 and assigns an error code to the external
+    variable #merror_code.  */
+/***ja
+    @brief ¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ËÃͤòÀßÄꤹ¤ë.
+
+    ´Ø¿ô msymbol_put () ¤Ï¡¢¥·¥ó¥Ü¥ë $SYMBOL Ãæ¤Ç¥­¡¼¤¬ $KEY ¤Ç¤¢¤ë¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ÎÃͤò
+    $VAL ¤ËÀßÄꤹ¤ë¡£¤½¤Î¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤Ë¤¹¤Ç¤ËÃͤ¬¤¢¤ì¤Ð¾å½ñ¤­¤¹¤ë¡£
+    $SYMBOL, $KEY ¤È¤â #Mnil ¤Ç¤¢¤Ã¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    $KEY ¤¬´ÉÍý¥­¡¼¤Ê¤é¤Ð¡¢$VAL ¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤³¤Î¾ì¹ç¡¢¸Å¤¤Ãͤλ²¾È¿ô¤Ï
+    @c NULL ¤Ç¤Ê¤±¤ì¤Ð 1 ¸º¤é¤µ¤ì¡¢$VAL ¤Î»²¾È¿ô¤Ï 1 Áý¤ä¤µ¤ì¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢msymbol_put () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_SYMBOL
+
+    @seealso
+    msymbol_get () */
+
+int
+msymbol_put (MSymbol symbol, MSymbol key, void *val)
+{
+  if (symbol == Mnil || key == Mnil)
+    MERROR (MERROR_SYMBOL, -1);
+  mplist_put (&symbol->plist, key, val);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Get the value of a symbol property.
+
+    The msymbol_get () function searches for the value of the symbol
+    property that belongs to $SYMBOL and whose key is $KEY.  If
+    $SYMBOL has such a symbol property, its value is returned.
+    Otherwise @c NULL is returned.
+
+    @return
+    If an error is detected, msymbol_get () returns @c NULL and
+    assigns an error code to the external variable #merror_code.  */
+/***ja
+    @brief ¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë.
+
+    ´Ø¿ô msymbol_get () ¤Ï¡¢¥·¥ó¥Ü¥ë $SYMBOL 
+    ¤¬»ý¤Ä¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¡¢¥­¡¼¤¬ $KEY 
+    ¤Ç¤¢¤ë¤â¤Î¤òõ¤¹¡£¤â¤·³ºÅö¤¹¤ë¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤¬Â¸ºß¤¹¤ì¤Ð¡¢¤½¤ì¤ÎÃͤòÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð
+    @c NULL ¤òÊÖ¤¹¡£
+
+    @return 
+    ¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¡¢msymbol_get () ¤Ï @c NULL 
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_SYMBOL
+
+    @seealso
+    msymbol_put () */
+
+void *
+msymbol_get (MSymbol symbol, MSymbol key)
+{
+  MPlist *plist;
+
+  if (symbol == Mnil || key == Mnil)
+    return NULL;
+  plist = &symbol->plist;
+  MPLIST_FIND (plist, key);
+  return (MPLIST_TAIL_P (plist) ? NULL : MPLIST_VAL (plist));
+}
+
+/*=*/
+/***en
+    @brief Set the value (function pointer) of a symbol property.
+
+    The msymbol_put_func () function is similar to msymbol_put () but for
+    setting function pointer $FUNC as the property value of $SYMBOL for
+    key $KEY.  */
+
+/***ja
+    @brief ¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ÎÃÍ(´Ø¿ô¥Ý¥¤¥ó¥¿)¤òÀßÄꤹ¤ë.
+
+    ´Ø¿ô msymbol_put_func () ¤Ï¡¢´Ø¿ô msymbol_put () ¤ÈƱÍͤˡ¢¥·¥ó¥Ü¥ë
+    $SYMBOL ¤Î¥­¡¼¤¬ $KEY ¤Ç¤¢¤ë¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÀßÄꤹ¤ë¡£Ã¢¤·
+    ¤½¤ÎÃͤϴؿô¥Ý¥¤¥ó¥¿ $FUNC ¤Ç¤¢¤ë¡£ */
+
+/***
+    @seealso
+     msymbol_put (), M17N_FUNC ()  */
+int
+msymbol_put_func (MSymbol symbol, MSymbol key, M17NFunc func)
+{
+  if (symbol == Mnil || key == Mnil)
+    MERROR (MERROR_SYMBOL, -1);
+  mplist_put_func (&symbol->plist, key, func);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Get the value (function pointer) of a symbol property.
+
+    The msymbol_get_func () function is similar to msymbol_get () but for
+    getting a function pointer form the property of symbol $SYMBOL.  */
+
+/***ja
+    @brief ¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ÎÃÍ (´Ø¿ô¥Ý¥¤¥ó¥¿) ¤òÆÀ¤ë.
+
+    ´Ø¿ô msymbol_get_func () ¤Ï¡¢´Ø¿ô msymbol_get () ¤ÈƱÍͤˡ¢¥·¥ó¥Ü¥ë
+    $SYMBOL ¤¬»ý¤Ä¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¡¢¥­¡¼¤¬ $KEY ¤Ç¤¢¤ë¤â¤Î¤òÆÀ¤ë¡£Ã¢¤·
+    ¤½¤ÎÃͤϴؿô¥Ý¥¤¥ó¥¿¤ò¤Ç¤¢¤ë¡£    */
+
+/***
+    @seealso
+    msymbol_get ()  */
+
+M17NFunc
+msymbol_get_func (MSymbol symbol, MSymbol key)
+{
+  if (symbol == Mnil || key == Mnil)
+    return NULL;
+  return mplist_get_func (&symbol->plist, key);
+}
+
+/*** @} */
+
+#include <stdio.h>
+
+/*** @addtogroup m17nDebug */
+/*=*/
+/*** @{ */
+
+/***en
+    @brief Dump a symbol.
+
+    The mdebug_dump_symbol () function prints symbol $SYMBOL in a human
+    readable way to the stderr.  $INDENT specifies how many columns to
+    indent the lines but the first one.
+
+    @return
+    This function returns $SYMBOL.
+
+    @errors
+    MERROR_DEBUG  */
+/***ja
+    @brief ¥·¥ó¥Ü¥ë¤ò¥À¥ó¥×¤¹¤ë.
+
+    ´Ø¿ô mdebug_dump_symbol () ¤Ï¥·¥ó¥Ü¥ë $symbol ¤ò stderr 
+    ¤Ë¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç°õºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï $SYMBOL ¤òÊÖ¤¹¡£ 
+
+    @errors
+    MERROR_DEBUG  */
+
+MSymbol
+mdebug_dump_symbol (MSymbol symbol, int indent)
+{
+  char *prefix;
+  MPlist *plist;
+  char *name;
+
+  if (indent < 0)
+    MERROR (MERROR_DEBUG, Mnil);
+  prefix = (char *) alloca (indent + 1);
+  memset (prefix, 32, indent);
+  prefix[indent] = 0;
+
+  if (symbol == Mnil)
+    plist = NULL, name = "nil";
+  else
+    plist = &symbol->plist, name = symbol->name;
+
+  fprintf (stderr, "%s%s", prefix, name);
+  while (plist && MPLIST_KEY (plist) != Mnil)
+    {
+      fprintf (stderr, ":%s", MPLIST_KEY (plist)->name);
+      plist = MPLIST_NEXT (plist);
+    }
+  return symbol;
+}
+
+/***en
+    @brief Dump all symbol names.
+
+    The mdebug_dump_all_symbols () function prints names of all
+    symbols to the stderr.  $INDENT specifies how many columns to
+    indent the lines but the first one.
+
+    @return
+    This function returns #Mnil.
+
+    @errors
+    MERROR_DEBUG  */
+/***ja
+    @brief ¤¹¤Ù¤Æ¤Î¥·¥ó¥Ü¥ë̾¤ò¥À¥ó¥×¤¹¤ë.
+
+    ´Ø¿ô mdebug_dump_all_symbols () ¤Ï¡¢¤¹¤Ù¤Æ¤Î¥·¥ó¥Ü¥ë¤Î̾Á°¤ò 
+    stderr ¤Ë°õºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï #Mnil ¤òÊÖ¤¹¡£ 
+
+    @errors
+    MERROR_DEBUG  */
+
+
+MSymbol
+mdebug_dump_all_symbols (int indent)
+{
+  char *prefix;
+  int i, n;
+  MSymbol sym;
+
+  if (indent < 0)
+    MERROR (MERROR_DEBUG, Mnil);
+  prefix = (char *) alloca (indent + 1);
+  memset (prefix, 32, indent);
+  prefix[indent] = 0;
+
+  fprintf (stderr, "(symbol-list");
+  for (i = n = 0; i < SYMBOL_TABLE_SIZE; i++)
+    if ((sym = symbol_table[i]))
+      {
+       fprintf (stderr, "\n%s  (%4d", prefix, i);
+       for (; sym; sym = sym->next, n++)
+         fprintf (stderr, " '%s'", sym->name);
+       fprintf (stderr, ")");
+      }
+  fprintf (stderr, "\n%s  (total %d)", prefix, n);
+  fprintf (stderr, ")");
+  return Mnil;
+}
+
+/*** @} */ 
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/symbol.h b/src/symbol.h
new file mode 100644 (file)
index 0000000..d412be8
--- /dev/null
@@ -0,0 +1,60 @@
+/* symbol.h -- header file for the symbol module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_SYMBOL_H_
+#define _M17N_SYMBOL_H_
+
+#include "plist.h"
+
+struct MSymbolStruct
+{
+  /** 1 iff a value of property (including text-property) whose key is
+      the symbol is a managed object.  */
+  unsigned managing_key : 1;
+
+  /* Name of the symbol. */
+  char *name;
+
+  /* Byte length of <name>.  */
+  int length;
+
+  /* Plist of the symbol.  */
+  MPlist plist;
+
+  struct MSymbolStruct *next;
+};
+
+#define MSYMBOL_NAME(sym) ((sym)->name)
+#define MSYMBOL_NAMELEN(sym) ((sym)->length - 1)
+
+extern void msymbol__free_table ();
+
+extern MSymbol msymbol__with_len (const char *name, int len);
+
+extern MPlist *msymbol__list (MSymbol prop);
+
+extern MSymbol msymbol__canonicalize (MSymbol sym);
+
+extern MTextPropSerializeFunc msymbol__serializer;
+extern MTextPropDeserializeFunc msymbol__deserializer;
+
+#endif /* _M17N_SYMBOL_H_ */
diff --git a/src/textprop.c b/src/textprop.c
new file mode 100644 (file)
index 0000000..b7f14b9
--- /dev/null
@@ -0,0 +1,3110 @@
+/* textprop.c -- text property module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+/***en
+    @addtogroup m17nTextProperty
+    @brief Function to handle text properties.
+
+    Each character in an M-text can have properties called @e text @e
+    properties.  Text properties store various kinds of information
+    attached to parts of an M-text to provide application programs
+    with a unified view of those information.  As rich information can
+    be stored in M-texts in the form of text properties, functions in
+    application programs can be simple.
+
+    A text property consists of a @e key and @e values, where key is a
+    symbol and values are anything that can be cast to <tt>(void *)
+    </tt>.  Unlike other types of properties, a text property can
+    have multiple values.  "The text property whose key is K" may be
+    shortened to "K property".  */
+
+/***ja
+    @addtogroup m17nTextProperty
+    @brief ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÁàºî¤¹¤ë¤¿¤á¤Î´Ø¿ô.
+
+    M-text Æâ¤Î³Æʸ»ú¤Ï¡¢@e ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ ¤È¸Æ¤Ð¤ì¤ë¥×¥í¥Ñ¥Æ¥£¤ò
+    »ý¤Ä¤³¤È¤¬¤Ç¤­¤ë¡£¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¡¢M-text ¤Î³ÆÉô°Ì¤ËÉղ䵤ì
+    ¤¿¤µ¤Þ¤¶¤Þ¤Ê¾ðÊó¤òÊÝ»ý¤·¤Æ¤ª¤ê¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï¤½¤ì¤é
+    ¤Î¾ðÊó¤òÅý°ìŪ¤Ë°·¤¦¤³¤È¤¬¤Ç¤­¤ë¡£M-text ¼«ÂΤ¬Ë­É٤ʾðÊó¤ò»ý¤Ä¤¿
+    ¤á¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥àÃæ¤Î´Ø¿ô¤ò´ÊÁDz½¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
+
+    ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï @e ¥­¡¼ ¤È @e ÃÍ ¤«¤é¤Ê¤ë¡£¥­¡¼¤Ï¥·¥ó¥Ü¥ë¤Ç¤¢
+    ¤ê¡¢ÃͤϠ<tt>(void *)</tt> ·¿¤Ë¥­¥ã¥¹¥È¤Ç¤­¤ë¤â¤Î¤Ê¤é²¿¤Ç¤â¤è¤¤¡£
+    Â¾¤Î¥¿¥¤¥×¤Î¥×¥í¥Ñ¥Æ¥£¤È°Û¤Ê¤ê¡¢°ì¤Ä¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤¬Ê£¿ô¤ÎÃÍ
+    ¤ò»ý¤Ä¤³¤È¤¬µö¤µ¤ì¤ë¡£¡Ö¥­¡¼¤¬ K ¤Ç¤¢¤ë¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¡×¤Î¤³¤È
+    ¤ò´Êñ¤Ë¡ÖK ¥×¥í¥Ñ¥Æ¥£¡×¤È¸Æ¤Ö¤³¤È¤¬¤¢¤ë¡£  */
+
+/*=*/
+
+#if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
+/*** @addtogroup m17nInternal
+     @{ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef HAVE_XML2
+#include <libxml/tree.h>
+#include <libxml/parser.h>
+#include <libxml/xmlmemory.h>
+#include <libxml/xpath.h>
+#endif
+
+#include "m17n.h"
+#include "m17n-misc.h"
+#include "internal.h"
+#include "symbol.h"
+#include "mtext.h"
+#include "textprop.h"
+
+#define TEXT_PROP_DEBUG
+
+#undef xassert
+#ifdef TEXT_PROP_DEBUG
+#define xassert(X)     do {if (!(X)) mdebug_hook ();} while (0)
+#else
+#define xassert(X)     (void) 0
+#endif /* not FONTSET_DEBUG */
+
+/* Hierarchy of objects (MText, MTextPlist, MInterval, MTextProperty)
+
+MText
+  |    key/a         key/b                key/x
+  +--> MTextPlist -> MTextPlist -> ... -> MTextPlist
+         |             |
+         |             +- tail <-----------------------------------------+
+         |             |                                                 |
+         |             +- head <--> MInterval <--> ... <--> MInterval <--+
+         |
+         +- tail --------------------------------------------------------+
+         |                                                               |
+         +- head --> MInterval <--> MInterval <--> ... <--> MInterval <--+
+                       |               |
+                       +---------------+------------> MTextProperty
+                       +--> MTextProperty
+                       ...
+
+
+Examples:
+
+MTextProperty a/A                    [AAAAAAAAAAAAAAAAAAAAA]
+MTextProperty a/B           [BBBBBBBBBBBBBBBBB] 
+MTextPlist a     |--intvl1--|-intvl2-|-intvl3-|---intvl4---|-intvl5-|
+               
+
+MTextProperty b/A                    [AAAAAAAAAA]
+MTextProperty b/B         [BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB] 
+MTextPlist b     |-intvl1-|--intvl2--|--intvl3--|-intvl4-|--intvl5--|
+
+    M-text       |--------------------------------------------------|
+
+    (intvl == MInterval)
+
+*/
+
+/* The structure MTextProperty is defined in textprop.h.  */
+
+/** MInterval is the structure for an interval that holds text
+    properties of the same key in a specific range of M-text.
+    All intervals are stored in MIntervalPool.  */
+
+typedef struct MInterval MInterval;
+
+struct MInterval
+{
+  /** Stack of pointers to text properties.  If the interval does not
+      have any text properties, this member is NULL or contains random
+      values.  */
+  MTextProperty **stack;
+
+  /** How many values are in <stack>.  */
+  int nprops;
+
+  /** Length of <stack>.  */
+  int stack_length;
+
+  /** Start and end character positions of the interval.  If <end> is
+      negative, this interval is not in use.  */
+  int start, end;
+
+  /** Pointers to the previous and next intervals.  If <start> is 0,
+      <prev> is NULL and this interval is pointed by MTextPlist->head.
+      If <end> is the size of the M-text, <next> is NULL, and this
+      interval is pointed by MTextPlist->tail.  */
+  MInterval *prev, *next;
+};  
+
+/** MTextPlist is a structure to hold text properties of an M-text by
+   chain.  Each element in the chain is for a specific key.  */
+
+typedef struct MTextPlist MTextPlist;
+
+struct MTextPlist
+{
+  /** Key of the property.  */
+  MSymbol key;
+
+  /** The head and tail intervals.  <head>->start is always 0.
+      <tail->end is always MText->nchars.  */
+  MInterval *head, *tail;
+
+  /** Lastly accessed interval.  */
+  MInterval *cache;
+
+  /* Not yet implemented.  */
+  int (*modification_hook) (MText *mt, MSymbol key, int from, int to);
+
+  /** Pointer to the next property in the chain, or NULL if the
+      property is the last one in the chain.  */
+  MTextPlist *next;
+};
+
+
+/** How many intervals one interval-pool can contain. */
+
+#define INTERVAL_POOL_SIZE 1024
+
+typedef struct MIntervalPool MIntervalPool;
+
+
+/** MIntervalPool is the structure for an interval-pool which store
+    intervals.  Each interval-pool contains INTERVAL_POOL_SIZE number
+    of intervals, and is chained from the root #interval_pool.  */
+
+struct MIntervalPool
+{
+  /** Array of intervals.  */
+  MInterval intervals[INTERVAL_POOL_SIZE];
+
+  /** The smallest index to an unused interval.  */
+  int free_slot;
+
+  /** Pointer to the next interval-pool.  */
+  MIntervalPool *next;
+};
+
+
+/** Root of interval-pools.  */
+
+static MIntervalPool interval_pool_root;
+
+/* For debugging. */
+
+static M17NObjectArray text_property_table;
+
+/** Return a newly allocated interval pool.  */
+
+static MIntervalPool *
+new_interval_pool ()
+{
+  MIntervalPool *pool;
+  int i;
+
+  MSTRUCT_CALLOC (pool, MERROR_TEXTPROP);
+  for (i = 0; i < INTERVAL_POOL_SIZE; i++)
+    pool->intervals[i].end = -1;
+  pool->free_slot = 0;
+  pool->next = NULL;
+  return pool;
+}
+
+
+/** Return a new interval for the region START and END.  */
+
+static MInterval *
+new_interval (int start, int end)
+{
+  MIntervalPool *pool;
+  MInterval *interval;
+
+  for (pool = &interval_pool_root;
+       pool->free_slot >= INTERVAL_POOL_SIZE;
+       pool = pool->next)
+    {
+      if (! pool->next)
+       pool->next = new_interval_pool ();
+    }
+
+  interval = &(pool->intervals[pool->free_slot]);
+  interval->stack = NULL;
+  interval->nprops = 0;
+  interval->stack_length = 0;
+  interval->prev = interval->next = NULL;
+  interval->start = start;
+  interval->end = end;
+
+  pool->free_slot++;
+  while (pool->free_slot < INTERVAL_POOL_SIZE
+        && pool->intervals[pool->free_slot].end >= 0)
+    pool->free_slot++;
+
+  return interval;
+}
+
+
+/** Free INTERVAL and return INTERVAL->next.  It assumes that INTERVAL
+    has no properties.  */
+
+static MInterval *
+free_interval (MInterval *interval)
+{
+  MIntervalPool *pool = &interval_pool_root;
+  int i;
+
+  xassert (interval->nprops == 0);
+  if (interval->stack)
+    free (interval->stack);
+  while ((interval < pool->intervals
+         || interval >= pool->intervals + INTERVAL_POOL_SIZE)
+        && pool->next)
+    pool = pool->next;
+
+  i = interval - pool->intervals;
+  interval->end = -1;
+  if (i < pool->free_slot)
+    pool->free_slot = i;
+  return interval->next;
+}
+
+
+/** If necessary, allocate a stack for INTERVAL so that it can contain
+   NUM number of text properties.  */
+
+#define PREPARE_INTERVAL_STACK(interval, num)                          \
+  do {                                                                 \
+    if ((num) > (interval)->stack_length)                              \
+      {                                                                        \
+       MTABLE_REALLOC ((interval)->stack, (num), MERROR_TEXTPROP);     \
+       (interval)->stack_length = (num);                               \
+      }                                                                        \
+  } while (0)
+
+
+/** Return a copy of INTERVAL.  The copy still shares text properties
+    with INTERVAL.  If MASK_BITS is not zero, don't copy such text
+    properties whose control flags contains bits in MASK_BITS.  */
+
+static MInterval *
+copy_interval (MInterval *interval, int mask_bits)
+{
+  MInterval *new = new_interval (interval->start, interval->end);
+  int nprops = interval->nprops;
+  MTextProperty **props = alloca (sizeof (MTextProperty *) * nprops);
+  int i, n;
+
+  for (i = n = 0; i < nprops; i++)
+    if (! (interval->stack[i]->control.flag & mask_bits))
+      props[n++] = interval->stack[i];
+  new->nprops = n;
+  if (n > 0)
+    {
+      PREPARE_INTERVAL_STACK (new, n);
+      memcpy (new->stack, props, sizeof (MTextProperty *) * n);
+    }  
+
+  return new;
+}
+
+
+/** Free text property OBJECT.  */
+
+static void
+free_text_property (void *object)
+{
+  MTextProperty *prop = (MTextProperty *) object;
+
+  if (prop->key->managing_key)
+    M17N_OBJECT_UNREF (prop->val);
+  M17N_OBJECT_UNREGISTER (text_property_table, prop);
+  free (object);
+}
+
+
+/** Return a newly allocated text property whose key is KEY and value
+    is VAL.  */
+
+static MTextProperty *
+new_text_property (MText *mt, int from, int to, MSymbol key, void *val,
+                  int control_bits)
+{
+  MTextProperty *prop;
+
+  M17N_OBJECT (prop, free_text_property, MERROR_TEXTPROP);
+  prop->control.flag = control_bits;
+  prop->attach_count = 0;
+  prop->mt = mt;
+  prop->start = from;
+  prop->end = to;
+  prop->key = key;
+  prop->val = val;
+  if (key->managing_key)
+    M17N_OBJECT_REF (val);    
+  M17N_OBJECT_REGISTER (text_property_table, prop);
+  return prop;
+}
+
+
+/** Return a newly allocated copy of text property PROP.  */
+
+#define COPY_TEXT_PROPERTY(prop)                               \
+  new_text_property ((prop)->mt, (prop)->start, (prop)->end,   \
+                    (prop)->key, (prop)->val, (prop)->control.flag)
+
+
+/** Split text property PROP at position INTERVAL->start, and make all
+    the following intervals contain the copy of PROP instead of PROP.
+    It assumes that PROP starts before INTERVAL.  */
+
+static void
+split_property (MTextProperty *prop, MInterval *interval)
+{
+  int end = prop->end;
+  MTextProperty *copy;
+  int i;
+
+  prop->end = interval->start;
+  copy = COPY_TEXT_PROPERTY (prop);
+  copy->start = interval->start;
+  copy->end = end;
+  /* Check all stacks of the following intervals, and if it contains
+     PROP, change it to the copy of it.  */
+  for (; interval && interval->start < end; interval = interval->next)
+    for (i = 0; i < interval->nprops; i++)
+      if (interval->stack[i] == prop)
+       {
+         interval->stack[i] = copy;
+         M17N_OBJECT_REF (copy);
+         copy->attach_count++;
+         prop->attach_count--;
+         M17N_OBJECT_UNREF (prop);
+       }
+  M17N_OBJECT_UNREF (copy);
+}
+
+/** Divide INTERVAL of PLIST at POS if POS is in between the range of
+    INTERVAL.  */
+
+static void
+divide_interval (MTextPlist *plist, MInterval *interval, int pos)
+{
+  MInterval *new;
+  int i;
+
+  if (pos == interval->start || pos == interval->end)
+    return;
+  new = copy_interval (interval, 0);
+  interval->end = new->start = pos;
+  new->prev = interval;
+  new->next = interval->next;
+  interval->next = new;
+  if (new->next)
+    new->next->prev = new;
+  if (plist->tail == interval)
+    plist->tail = new;
+  for (i = 0; i < new->nprops; i++)
+    {
+      new->stack[i]->attach_count++;
+      M17N_OBJECT_REF (new->stack[i]);
+    }
+}
+
+
+/** Check if INTERVAL of PLIST can be merged with INTERVAL->next.  If
+    mergeable, extend INTERVAL to the end of INTEVAL->next, free
+    INTERVAL->next, and return INTERVAL.  Otherwise, return
+    INTERVAL->next.  */
+
+static MInterval *
+maybe_merge_interval (MTextPlist *plist, MInterval *interval)
+{
+  int nprops = interval->nprops;
+  MInterval *next = interval->next;
+  int i, j;
+
+  if (! next || nprops != next->nprops)
+    return next;
+
+  for (i = 0; i < nprops; i++)
+    {
+      MTextProperty *prop = interval->stack[i];
+      MTextProperty *old = next->stack[i];
+
+      if (prop != old
+         && (prop->val != old->val
+             || prop->end != old->start
+             || prop->control.flag & MTEXTPROP_NO_MERGE
+             || old->control.flag & MTEXTPROP_NO_MERGE))
+       return interval->next;
+    }
+
+
+  for (i = 0; i < nprops; i++)
+    {
+      MTextProperty *prop = interval->stack[i];
+      MTextProperty *old = next->stack[i];
+
+      if (prop != old)
+       {
+         MInterval *tail;
+
+         for (tail = next->next; tail && tail->start < old->end;
+              tail = tail->next)
+           for (j = 0; j < tail->nprops; j++)
+             if (tail->stack[j] == old)
+               {
+                 old->attach_count--;
+                 xassert (old->attach_count);
+                 tail->stack[j] = prop;
+                 prop->attach_count++;
+                 M17N_OBJECT_REF (prop);
+               }
+         xassert (old->attach_count == 1);
+         old->mt = NULL;
+         prop->end = old->end;
+       }
+      old->attach_count--;
+      M17N_OBJECT_UNREF (old);
+    }
+
+  interval->end = next->end;
+  interval->next = next->next;
+  if (next->next)
+    next->next->prev = interval;
+  if (plist->tail == next)
+    plist->tail = interval;
+  plist->cache = interval;
+  next->nprops = 0;
+  free_interval (next);
+  return interval;
+}
+
+
+/** Adjust start and end positions of intervals between HEAD and TAIL
+     (both inclusive) by diff.  Adjust also start and end positions
+     of text properties belonging to those intervals.  */
+
+static void
+adjust_intervals (MInterval *head, MInterval *tail, int diff)
+{
+  int i;
+  MTextProperty *prop;
+
+  if (diff < 0)
+    {
+      /* Adjust end positions of properties starting before HEAD.  */
+      for (i = 0; i < head->nprops; i++)
+       {
+         prop = head->stack[i];
+         if (prop->start < head->start)
+           prop->end += diff;
+       }
+
+      /* Adjust start and end positions of properties starting at
+        HEAD, and adjust HEAD itself.  */
+      while (1)
+       {
+         for (i = 0; i < head->nprops; i++)
+           {
+             prop = head->stack[i];
+             if (prop->start == head->start)
+               prop->start += diff, prop->end += diff;
+           }
+         head->start += diff;
+         head->end += diff;
+         if (head == tail)
+           break;
+         head = head->next;
+       }
+    }
+  else
+    {
+      /* Adjust start poistions of properties ending after TAIL.  */
+      for (i = 0; i < tail->nprops; i++)
+       {
+         prop = tail->stack[i];
+         if (prop->end > tail->end)
+           prop->start += diff;
+       }
+
+      /* Adjust start and end positions of properties ending at
+        TAIL, and adjust TAIL itself.  */
+      while (1)
+       {
+         for (i = 0; i < tail->nprops; i++)
+           {
+             prop = tail->stack[i];
+             if (prop->end == tail->end)
+               prop->start += diff, prop->end += diff;
+           }
+         tail->start += diff;
+         tail->end += diff;
+         if (tail == head)
+           break;
+         tail = tail->prev;
+       }
+    }
+}
+
+/* Return an interval of PLIST that covers the position POS.  */
+
+static MInterval *
+find_interval (MTextPlist *plist, int pos)
+{
+  MInterval *interval;
+  MInterval *highest;
+
+  if (pos < plist->head->end)
+    return plist->head;
+  if (pos >= plist->tail->start)
+    return (pos < plist->tail->end ? plist->tail : NULL);
+
+  interval = plist->cache;
+
+  if (pos < interval->start)
+    highest = interval->prev, interval = plist->head->next;
+  else if (pos < interval->end)
+    return interval;
+  else
+    highest = plist->tail->prev, interval = interval->next;
+
+  if (pos - interval->start < highest->end - pos)
+    {
+      while (interval->end <= pos)
+       /* Here, we are sure that POS is not included in PLIST->tail,
+          thus, INTERVAL->next always points a valid next
+          interval.  */
+       interval = interval->next;
+    }
+  else
+    {
+      while (highest->start > pos)
+       highest = highest->prev;
+      interval = highest;
+    }
+  plist->cache = interval;
+  return interval;
+}
+
+/* Push text property PROP on the stack of INTERVAL.  */
+
+#define PUSH_PROP(interval, prop)              \
+  do {                                         \
+    int n = (interval)->nprops;                        \
+                                               \
+    PREPARE_INTERVAL_STACK ((interval), n + 1);        \
+    (interval)->stack[n] = (prop);             \
+    (interval)->nprops += 1;                   \
+    (prop)->attach_count++;                    \
+    M17N_OBJECT_REF (prop);                    \
+    if ((prop)->start > (interval)->start)     \
+      (prop)->start = (interval)->start;       \
+    if ((prop)->end < (interval)->end)         \
+      (prop)->end = (interval)->end;           \
+  } while (0)
+
+
+/* Pop the topmost text property of INTERVAL from the stack.  If it
+   ends after INTERVAL->end, split it.  */
+
+#define POP_PROP(interval)                             \
+  do {                                                 \
+    MTextProperty *prop;                               \
+                                                       \
+    (interval)->nprops--;                              \
+    prop = (interval)->stack[(interval)->nprops];      \
+    xassert (prop->control.ref_count > 0);             \
+    xassert (prop->attach_count > 0);                  \
+    if (prop->start < (interval)->start)               \
+      {                                                        \
+       if (prop->end > (interval)->end)                \
+         split_property (prop, (interval)->next);      \
+       prop->end = (interval)->start;                  \
+      }                                                        \
+    else if (prop->end > (interval)->end)              \
+      prop->start = (interval)->end;                   \
+    prop->attach_count--;                              \
+    if (! prop->attach_count)                          \
+      prop->mt = NULL;                                 \
+    M17N_OBJECT_UNREF (prop);                          \
+  } while (0)
+
+
+#define REMOVE_PROP(interval, prop)                    \
+  do {                                                 \
+    int i;                                             \
+                                                       \
+    for (i = (interval)->nprops - 1; i >= 0; i--)      \
+      if ((interval)->stack[i] == (prop))              \
+       break;                                          \
+    if (i < 0)                                         \
+      break;                                           \
+    (interval)->nprops--;                              \
+    for (; i < (interval)->nprops; i++)                        \
+      (interval)->stack[i] = (interval)->stack[i + 1]; \
+    (prop)->attach_count--;                            \
+    if (! (prop)->attach_count)                                \
+      (prop)->mt = NULL;                               \
+    M17N_OBJECT_UNREF (prop);                          \
+  } while (0)
+
+
+#ifdef TEXT_PROP_DEBUG
+static int
+check_plist (MTextPlist *plist, int start)
+{
+  MInterval *interval = plist->head;
+  MInterval *cache = plist->cache;
+  int cache_found = 0;
+
+  if (interval->start != start
+      || interval->start >= interval->end)
+    return mdebug_hook ();
+  while (interval)
+    {
+      int i;
+
+      if (interval == interval->next)
+       return mdebug_hook ();
+
+      if (interval == cache)
+       cache_found = 1;
+
+      if (interval->start >= interval->end)
+       return mdebug_hook ();
+      if ((interval->next
+          ? (interval->end != interval->next->start
+             || interval != interval->next->prev)
+          : interval != plist->tail))
+       return mdebug_hook ();
+      for (i = 0; i < interval->nprops; i++)
+       {
+         if (interval->stack[i]->start > interval->start
+             || interval->stack[i]->end < interval->end)
+           return mdebug_hook ();
+
+         if (! interval->stack[i]->attach_count)
+           return mdebug_hook ();
+         if (! interval->stack[i]->mt)
+           return mdebug_hook ();
+         if (interval->stack[i]->start == interval->start)
+           {
+             MTextProperty *prop = interval->stack[i];
+             int count = prop->attach_count - 1;
+             MInterval *interval2;
+
+             for (interval2 = interval->next;
+                  interval2 && interval2->start < prop->end;
+                  count--, interval2 = interval2->next)
+               if (count == 0)
+                 return mdebug_hook ();
+           }         
+
+         if (interval->stack[i]->end > interval->end)
+           {
+             MTextProperty *prop = interval->stack[i];
+             MInterval *interval2;
+             int j;
+
+             for (interval2 = interval->next;
+                  interval2 && interval2->start < prop->end;
+                  interval2 = interval2->next)
+               {
+                 for (j = 0; j < interval2->nprops; j++)
+                   if (interval2->stack[j] == prop)
+                     break;
+                 if (j == interval2->nprops)
+                   return mdebug_hook ();
+               }
+           }
+         if (interval->stack[i]->start < interval->start)
+           {
+             MTextProperty *prop = interval->stack[i];
+             MInterval *interval2;
+             int j;
+
+             for (interval2 = interval->prev;
+                  interval2 && interval2->end > prop->start;
+                  interval2 = interval2->prev)
+               {
+                 for (j = 0; j < interval2->nprops; j++)
+                   if (interval2->stack[j] == prop)
+                     break;
+                 if (j == interval2->nprops)
+                   return mdebug_hook ();
+               }
+           }
+       }
+      interval = interval->next;
+    }
+  if (! cache_found)
+    return mdebug_hook ();
+  if (plist->head->prev || plist->tail->next)
+    return mdebug_hook ();    
+  return 0;
+}
+#endif
+
+
+/** Return a copy of plist that contains intervals between FROM and TO
+    of PLIST.  The copy goes to the position POS of M-text MT.  */
+
+static MTextPlist *
+copy_single_property (MTextPlist *plist, int from, int to, MText *mt, int pos)
+{
+  MTextPlist *new;
+  MInterval *interval1, *interval2;
+  MTextProperty *prop;
+  int diff = pos - from;
+  int i, j;
+  int mask_bits = MTEXTPROP_VOLATILE_STRONG | MTEXTPROP_VOLATILE_WEAK;
+
+  MSTRUCT_CALLOC (new, MERROR_TEXTPROP);
+  new->key = plist->key;
+  new->next = NULL;
+
+  interval1 = find_interval (plist, from);
+  new->head = copy_interval (interval1, mask_bits);
+  for (interval1 = interval1->next, interval2 = new->head;
+       interval1 && interval1->start < to;
+       interval1 = interval1->next, interval2 = interval2->next)
+    {
+      interval2->next = copy_interval (interval1, mask_bits);
+      interval2->next->prev = interval2;
+    }
+  new->tail = interval2;
+  new->head->start = from;
+  new->tail->end = to;
+  for (interval1 = new->head; interval1; interval1 = interval1->next)
+    for (i = 0; i < interval1->nprops; i++)
+      if (interval1->start == interval1->stack[i]->start
+         || interval1 == new->head)
+       {
+         prop = interval1->stack[i];
+         interval1->stack[i] = COPY_TEXT_PROPERTY (prop);
+         interval1->stack[i]->mt = mt;
+         interval1->stack[i]->attach_count++;
+         if (interval1->stack[i]->start < from)
+           interval1->stack[i]->start = from;
+         if (interval1->stack[i]->end > to)
+           interval1->stack[i]->end = to;
+         for (interval2 = interval1->next; interval2;
+              interval2 = interval2->next)
+           for (j = 0; j < interval2->nprops; j++)
+             if (interval2->stack[j] == prop)
+               {
+                 interval2->stack[j] = interval1->stack[i];
+                 interval1->stack[i]->attach_count++;
+                 M17N_OBJECT_REF (interval1->stack[i]);
+               }
+       }
+  adjust_intervals (new->head, new->tail, diff);
+  new->cache = new->head;
+  for (interval1 = new->head; interval1 && interval1->next;
+       interval1 = maybe_merge_interval (new, interval1));
+  xassert (check_plist (new, pos) == 0);
+  if (new->head == new->tail
+      && new->head->nprops == 0)
+    {
+      free_interval (new->head);
+      free (new);
+      new = NULL;
+    }
+
+  return new;
+}
+
+/** Return a newly allocated plist whose key is KEY on M-text MT.  */
+
+static MTextPlist *
+new_plist (MText *mt, MSymbol key)
+{
+  MTextPlist *plist;
+
+  MSTRUCT_MALLOC (plist, MERROR_TEXTPROP);
+  plist->key = key;
+  plist->head = new_interval (0, mtext_nchars (mt));
+  plist->tail = plist->head;
+  plist->cache = plist->head;
+  plist->next = mt->plist;
+  mt->plist = plist;
+  return plist;
+}
+
+/* Free PLIST and return PLIST->next.  */
+
+static MTextPlist *
+free_textplist (MTextPlist *plist)
+{
+  MTextPlist *next = plist->next;
+  MInterval *interval = plist->head;
+
+  while (interval)
+    {
+      while (interval->nprops > 0)
+       POP_PROP (interval);
+      interval = free_interval (interval);
+    }
+  free (plist);
+  return next;
+}
+
+/** Return a plist that contains the property KEY of M-text MT.  If
+    such a plist does not exist and CREATE is nonzero, create a new
+    plist and return it.  */
+
+static MTextPlist *
+get_plist_create (MText *mt, MSymbol key, int create)
+{
+  MTextPlist *plist;
+
+  plist = mt->plist;
+  while (plist && plist->key != key)
+    plist = plist->next;
+
+  /* If MT does not have PROP, make one.  */
+  if (! plist && create)
+    plist = new_plist (mt, key);
+  return plist;
+}
+
+/* Detach PROP.  INTERVAL (if not NULL) contains PROP.  */
+
+static void
+detach_property (MTextPlist *plist, MTextProperty *prop, MInterval *interval)
+{
+  MInterval *head;
+  int to = prop->end;
+
+  xassert (prop->mt);
+  xassert (plist);
+
+  M17N_OBJECT_REF (prop);
+  if (interval)
+    while (interval->start > prop->start)
+      interval = interval->prev;
+  else
+    interval = find_interval (plist, prop->start);
+  head = interval;
+  while (1)
+    {
+      REMOVE_PROP (interval, prop);
+      if (interval->end == to)
+       break;
+      interval = interval->next;
+    }
+  xassert (prop->attach_count == 0 && prop->mt == NULL);
+  M17N_OBJECT_UNREF (prop);
+
+  while (head && head->end <= to)
+    head = maybe_merge_interval (plist, head);
+  xassert (check_plist (plist, 0) == 0);
+}
+
+/* Delete text properties of PLIST between FROM and TO.  MASK_BITS
+   specifies what kind of properties to delete.  If DELETING is
+   nonzero, delete such properties too that are completely included in
+   the region.
+
+   If the resulting PLIST still has any text properties, return 1,
+   else return 0.  */
+
+static int
+delete_properties (MTextPlist *plist, int from, int to,
+                  int mask_bits, int deleting)
+{
+  MInterval *interval;
+  int modified = 0;
+  int modified_from = from;
+  int modified_to = to;
+  int i;
+
+ retry:
+  for (interval = find_interval (plist, from);
+       interval && interval->start < to;
+       interval = interval->next)
+    for (i = 0; i < interval->nprops; i++)
+      {
+       MTextProperty *prop = interval->stack[i];
+
+       if (prop->control.flag & mask_bits)
+         {
+           if (prop->start < modified_from)
+             modified_from = prop->start;
+           if (prop->end > modified_to)
+             modified_to = prop->end;
+           detach_property (plist, prop, interval);
+           modified++;
+           goto retry;
+         }
+       else if (deleting && prop->start >= from && prop->end <= to)
+         {
+           detach_property (plist, prop, interval);
+           modified++;
+           goto retry;
+         }
+      }
+
+  if (modified)
+    {
+      interval = find_interval (plist, modified_from);
+      while (interval && interval->start < modified_to)
+       interval = maybe_merge_interval (plist, interval);
+    }
+
+  return (plist->head != plist->tail || plist->head->nprops > 0);
+}
+
+static void
+pop_interval_properties (MInterval *interval)
+{
+  while (interval->nprops > 0)
+    POP_PROP (interval);
+}
+
+
+MInterval *
+pop_all_properties (MTextPlist *plist, int from, int to)
+{
+  MInterval *interval;
+
+  /* Be sure to have interval boundary at TO.  */
+  interval = find_interval (plist, to);
+  if (interval && interval->start < to)
+    divide_interval (plist, interval, to);
+
+  /* Be sure to have interval boundary at FROM.  */
+  interval = find_interval (plist, from);
+  if (interval->start < from)
+    {
+      divide_interval (plist, interval, from);
+      interval = interval->next;
+    }
+
+  pop_interval_properties (interval);
+  while (interval->end < to)
+    {
+      MInterval *next = interval->next;
+
+      pop_interval_properties (next);
+      interval->end = next->end;
+      interval->next = next->next;
+      if (interval->next)
+       interval->next->prev = interval;
+      if (next == plist->tail)
+       plist->tail = interval;
+      if (plist->cache == next)
+       plist->cache = interval;
+      free_interval (next);
+    }
+  return interval;
+}
+
+
+/* Delete volatile text properties between FROM and TO.  If DELETING
+   is nonzero, we are going to delete text, thus both strongly and
+   weakly volatile properties must be deleted.  Otherwise we are going
+   to modify a text property KEY, thus only strongly volatile
+   properties whose key is not KEY must be deleted.  */
+
+static void
+prepare_to_modify (MText *mt, int from, int to, MSymbol key, int deleting)
+{
+  MTextPlist *plist = mt->plist, *prev = NULL;
+  int mask_bits = MTEXTPROP_VOLATILE_STRONG;
+
+  if (deleting)
+    mask_bits |= MTEXTPROP_VOLATILE_WEAK;
+  while (plist)
+    {
+      if (plist->key != key
+         && ! delete_properties (plist, from, to, mask_bits, deleting))
+       {
+         if (prev)
+           plist = prev->next = free_textplist (plist);
+         else
+           plist = mt->plist = free_textplist (plist);
+       }
+      else
+       prev = plist, plist = plist->next;
+    }
+}
+
+void
+extract_text_properties (MText *mt, int from, int to, MSymbol key,
+                        MPlist *plist)
+{
+  MPlist *top;
+  MTextPlist *list = get_plist_create (mt, key, 0);
+  MInterval *interval;
+
+  if (! list)
+    return;
+  interval = find_interval (list, from);
+  if (interval->nprops == 0
+      && interval->start <= from && interval->end >= to)
+    return;
+  top = plist;
+  while (interval && interval->start < to)
+    {
+      if (interval->nprops == 0)
+       top = mplist_find_by_key (top, Mnil);
+      else
+       {
+         MPlist *current = top, *place;
+         int i;
+
+         for (i = 0; i < interval->nprops; i++)
+           {
+             MTextProperty *prop = interval->stack[i];
+
+             place = mplist_find_by_value (current, prop);
+             if (place)
+               current = MPLIST_NEXT (place);
+             else
+               {
+                 place = mplist_find_by_value (top, prop);
+                 if (place)
+                   {
+                     mplist_pop (place);
+                     if (MPLIST_NEXT (place) == MPLIST_NEXT (current))
+                       current = place;
+                   }
+                 mplist_push (current, Mt, prop);
+                 current = MPLIST_NEXT (current);
+               }
+           }
+       }
+      interval = interval->next;
+    }
+  return;
+}
+
+#define XML_TEMPLATE "<?xml version=\"1.0\" ?>\n\
+<!DOCTYPE mtext [\n\
+  <!ELEMENT mtext (property*,body+)>\n\
+  <!ELEMENT property EMPTY>\n\
+  <!ELEMENT body (#PCDATA)>\n\
+  <!ATTLIST property key CDATA #REQUIRED>\n\
+  <!ATTLIST property value CDATA #REQUIRED>\n\
+  <!ATTLIST property from CDATA #REQUIRED>\n\
+  <!ATTLIST property to CDATA #REQUIRED>\n\
+  <!ATTLIST property control CDATA #REQUIRED>\n\
+ ]>\n\
+<mtext>\n\
+</mtext>"
+
+\f
+/* for debugging... */
+#include <stdio.h>
+
+void
+dump_interval (MInterval *interval, int indent)
+{
+  char *prefix = (char *) alloca (indent + 1);
+  int i;
+
+  memset (prefix, 32, indent);
+  prefix[indent] = 0;
+
+  fprintf (stderr, "(interval %d-%d (%d)", interval->start, interval->end,
+          interval->nprops);
+  for (i = 0; i < interval->nprops; i++)
+    fprintf (stderr, "\n%s (%d %d/%d %d-%d 0x%x)",
+            prefix, i,
+            interval->stack[i]->control.ref_count,
+            interval->stack[i]->attach_count,
+            interval->stack[i]->start, interval->stack[i]->end,
+            (unsigned) interval->stack[i]->val);
+  fprintf (stderr, ")");
+}
+
+void
+dump_textplist (MTextPlist *plist, int indent)
+{
+  char *prefix = (char *) alloca (indent + 1);
+
+  memset (prefix, 32, indent);
+  prefix[indent] = 0;
+
+  fprintf (stderr, "(properties");
+  if (! plist)
+    fprintf (stderr, ")\n");
+  else
+    {
+      fprintf (stderr, "\n");
+      while (plist)
+       {
+         MInterval *interval = plist->head;
+
+         fprintf (stderr, "%s (%s", prefix, msymbol_name (plist->key));
+         while (interval)
+           {
+             fprintf (stderr, " (%d %d", interval->start, interval->end);
+             if (interval->nprops > 0)
+               {
+                 int i;
+
+                 for (i = 0; i < interval->nprops; i++)
+                   fprintf (stderr, " 0x%x", (int) interval->stack[i]->val);
+               }
+             fprintf (stderr, ")");
+             interval = interval->next;
+           }
+         fprintf (stderr, ")\n");
+         xassert (check_plist (plist, 0) == 0);
+         plist = plist->next;
+       }
+    }
+}
+
+\f
+/* Internal API */
+
+int
+mtext__prop_init ()
+{
+  M17N_OBJECT_ADD_ARRAY (text_property_table, "Text property");
+  Mtext_prop_serializer = msymbol ("text-prop-serializer");
+  Mtext_prop_deserializer = msymbol ("text-prop-deserializer");
+  return 0;
+}
+
+void
+mtext__prop_fini ()
+{
+  MIntervalPool *pool = interval_pool_root.next;
+
+  while (pool)
+    {
+      MIntervalPool *next = pool->next;
+      free (pool);
+      pool = next;
+    }
+  interval_pool_root.next = NULL;  
+}
+
+
+/** Free all plists.  */
+
+void
+mtext__free_plist (MText *mt){
+
+  MTextPlist *plist = mt->plist;
+
+  while (plist)
+    plist = free_textplist (plist);
+  mt->plist = NULL;
+}
+
+
+/** Extract intervals between FROM and TO of all properties (except
+    for volatile ones) in PLIST, and make a new plist from them for
+    M-text MT.  */
+
+MTextPlist *
+mtext__copy_plist (MTextPlist *plist, int from, int to, MText *mt, int pos)
+{
+  MTextPlist *copy, *this;
+
+  if (from == to)
+    return NULL;
+  for (copy = NULL; plist && ! copy; plist = plist->next)
+    copy = copy_single_property (plist, from, to, mt, pos);
+  if (! plist)
+    return copy;
+  for (; plist; plist = plist->next)
+    if ((this = copy_single_property (plist, from, to, mt, pos)))
+      {
+       this->next = copy;
+       copy = this;
+      }
+
+  return copy;
+}
+
+void
+mtext__adjust_plist_for_delete (MText *mt, int pos, int len)
+{
+  MTextPlist *plist;
+  int to;
+
+  if (len == 0 || pos == mt->nchars)
+    return;
+  if (len == mt->nchars)
+    {
+      mtext__free_plist (mt);
+      return;
+    }      
+
+  to = pos + len;
+  prepare_to_modify (mt, pos, to, Mnil, 1);
+  for (plist = mt->plist; plist; plist = plist->next)
+    {
+      MInterval *interval = pop_all_properties (plist, pos, to);
+      MInterval *prev = interval->prev, *next = interval->next;
+
+      if (prev)
+       prev->next = next;
+      else
+       plist->head = next;
+      if (next)
+       {
+         adjust_intervals (next, plist->tail, -len);
+         next->prev = prev;
+       }
+      else
+       plist->tail = prev;
+      if (prev && next)
+       next = maybe_merge_interval (plist, prev);
+      plist->cache = next ? next : prev;
+      free_interval (interval);
+      xassert (check_plist (plist, 0) == 0);
+    }
+}
+
+void
+mtext__adjust_plist_for_insert (MText *mt, int pos, int nchars,
+                               MTextPlist *plist)
+{
+  MTextPlist *pl, *pl_last, *pl2, *p;
+  int i;
+  MInterval *interval;
+
+  if (mt->nchars == 0)
+    {
+      mtext__free_plist (mt);
+      mt->plist = plist;
+      return;
+    }
+  if (pos > 0 && pos < mtext_nchars (mt))
+    prepare_to_modify (mt, pos, pos, Mnil, 0);
+
+  for (pl_last = NULL, pl = mt->plist; pl; pl_last = pl, pl = pl->next)
+    {
+      MInterval *interval, *prev, *next, *head, *tail;
+
+      if (pos == 0)
+       prev = NULL, next = pl->head;
+      else if (pos == mtext_nchars (mt))
+       prev = pl->tail, next = NULL;
+      else
+       {
+         next = find_interval (pl, pos);
+         if (next->start < pos)
+           {
+             divide_interval (pl, next, pos);
+             next = next->next;
+           }
+         for (i = 0; i < next->nprops; i++)
+           if (next->stack[i]->start < pos)
+             split_property (next->stack[i], next);
+         prev = next->prev;
+       }
+
+      xassert (check_plist (pl, 0) == 0);
+      for (p = NULL, pl2 = plist; pl2 && pl->key != pl2->key;
+          p = pl2, pl2 = p->next);
+      if (pl2)
+       {
+         xassert (check_plist (pl2, pl2->head->start) == 0);
+         if (p)
+           p->next = pl2->next;
+         else
+           plist = plist->next;
+
+         head = pl2->head;
+         tail = pl2->tail;
+         free (pl2);
+       }
+      else
+       {
+         head = tail = new_interval (pos, pos + nchars);
+       }
+      head->prev = prev;
+      tail->next = next;
+      if (prev)
+       prev->next = head;
+      else
+       pl->head = head;
+      if (next)
+       next->prev = tail;
+      else
+       pl->tail = tail;
+      if (next)
+       adjust_intervals (next, pl->tail, nchars);
+
+      xassert (check_plist (pl, 0) == 0);
+      if (prev && prev->nprops > 0)
+       {
+         for (interval = prev;
+              interval->next != next && interval->next->nprops == 0;
+              interval = interval->next)
+           for (i = 0; i < interval->nprops; i++)
+             {
+               MTextProperty *prop = interval->stack[i];
+
+               if (prop->control.flag & MTEXTPROP_REAR_STICKY)
+                 PUSH_PROP (interval->next, prop);
+             }
+       }
+      xassert (check_plist (pl, 0) == 0);
+      if (next && next->nprops > 0)
+       {
+         for (interval = next;
+              interval->prev != prev && interval->prev->nprops == 0;
+              interval = interval->prev)
+           for (i = 0; i < interval->nprops; i++)
+             {
+               MTextProperty *prop = interval->stack[i];
+
+               if (prop->control.flag & MTEXTPROP_FRONT_STICKY)
+                 PUSH_PROP (interval->prev, prop);
+             }
+       }
+
+      interval = prev ? prev : pl->head;
+      pl->cache = interval;
+      while (interval && interval->start <= pos + nchars)
+       interval = maybe_merge_interval (pl, interval);
+      xassert (check_plist (pl, 0) == 0);
+    }
+
+  if (pl_last)
+    pl_last->next = plist;
+  else
+    mt->plist = plist;
+
+  for (; plist; plist = plist->next)
+    {
+      plist->cache = plist->head;
+      if (pos > 0)
+       {
+         if (plist->head->nprops)
+           {
+             interval = new_interval (0, pos);
+             interval->next = plist->head;
+             plist->head->prev = interval;
+             plist->head = interval;
+           }
+         else
+           plist->head->start = 0;
+       }
+      if (pos < mtext_nchars (mt))
+       {
+         if (plist->tail->nprops)
+           {
+             interval = new_interval (pos + nchars,
+                                      mtext_nchars (mt) + nchars);
+             interval->prev = plist->tail;
+             plist->tail->next = interval;
+             plist->tail = interval;
+           }
+         else
+           plist->tail->end = mtext_nchars (mt) + nchars;
+       }
+      xassert (check_plist (plist, 0) == 0);
+    }
+}
+
+/* len1 > 0 && len2 > 0 */
+
+void
+mtext__adjust_plist_for_change (MText *mt, int pos, int len1, int len2)
+{
+  int pos2 = pos + len1;
+
+  prepare_to_modify (mt, pos, pos2, Mnil, 0);
+
+  if (len1 < len2)
+    {
+      int diff = len2 - len1;
+      MTextPlist *plist;
+
+      for (plist = mt->plist; plist; plist = plist->next)
+       {
+         MInterval *head = find_interval (plist, pos2);
+         MInterval *tail = plist->tail;
+         MTextProperty *prop;
+         int i;
+
+         if (head)
+           {
+             if (head->start == pos2)
+               head = head->prev;
+             while (tail != head)
+               {
+                 for (i = 0; i < tail->nprops; i++)
+                   {
+                     prop = tail->stack[i];
+                     if (prop->start == tail->start)
+                       prop->start += diff, prop->end += diff;
+                   }
+                 tail->start += diff;
+                 tail->end += diff;
+                 tail = tail->prev;
+               }
+           }
+         for (i = 0; i < tail->nprops; i++)
+           tail->stack[i]->end += diff;
+         tail->end += diff;
+       }
+    }
+  else if (len1 > len2)
+    {
+      mtext__adjust_plist_for_delete (mt, pos + len2, len1 - len2);
+    }
+}
+
+
+/*** @} */
+#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
+
+\f
+/** External API */
+
+/*** @addtogroup m17nTextProperty */
+/*** @{  */
+
+/*=*/
+/***en
+    @brief Get the value of the topmost text property.
+
+    The mtext_get_prop () function searches the character at $POS in
+    M-text $MT for the text property whose key is $KEY.
+
+    @return
+    If a text property is found, mtext_get_prop () returns the value
+    of the property.  If the property has multiple values, it returns
+    the topmost one.  If no such property is found, it returns @c NULL
+    without changing the external variable #merror_code.
+
+    If an error is detected, mtext_get_prop () returns @c NULL and
+    assigns an error code to the external variable #merror_code.
+
+    @note If @c NULL is returned without an error, there are two
+    possibilities:
+
+    @li  the character at $POS does not have a property whose key is $KEY, or 
+
+    @li  the character does have such a property and its value is @c NULL.  
+
+    If you need to distinguish these two cases, use the
+    mtext_get_prop_values () function instead.  */
+
+/***ja
+    @brief ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î°ìÈÖ¾å¤ÎÃͤòÆÀ¤ë.
+
+    ´Ø¿ô mtext_get_prop () ¤Ï¡¢M-text $MT Æâ¤Î°ÌÃÖ $POS ¤Ë¤¢¤ëʸ»ú¤Î¥Æ
+    ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¡¢¥­¡¼¤¬ $KEY ¤Ç¤¢¤ë¤â¤Î¤òõ¤¹¡£
+
+    @return
+    ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤¬¤ß¤Ä¤«¤ì¤Ð¡¢mtext_get_prop () ¤Ï¤½¤Î¥×¥í¥Ñ¥Æ¥£
+    ¤ÎÃͤòÊÖ¤¹¡£Ãͤ¬Ê£¿ô¸ºß¤¹¤ë¤È¤­¤Ï¡¢°ìÈÖ¾å¤ÎÃͤòÊÖ¤¹¡£¸«¤Ä¤«¤é¤Ê¤±
+    ¤ì¤Ð³°ÉôÊÑ¿ô #merror_code ¤òÊѹ¹¤¹¤ë¤³¤È¤Ê¤¯ @c NULL ¤òÊÖ¤¹¡£
+
+    ¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç mtext_get_prop () ¤Ï @c NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ
+    ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @note ¥¨¥é¡¼¤Ê¤·¤Ç @c NULL ¤¬ÊÖ¤µ¤ì¤¿¾ì¹ç¤Ë¤ÏÆó¤Ä¤Î²ÄǽÀ­¤¬¤¢¤ë¡£
+
+    @li $POS ¤Î°ÌÃÖ¤Îʸ»ú¤Ï $KEY ¤ò¥­¡¼¤È¤¹¤ë¥×¥í¥Ñ¥Æ¥£¤ò»ý¤¿¤Ê¤¤¡£
+
+    @li ¤½¤Îʸ»ú¤Ï¤½¤Î¤è¤¦¤Ê¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Á¡¢¤½¤ÎÃͤ¬ @c NULL ¤Ç¤¢¤ë¡£
+
+    ¤³¤ÎÆó¤Ä¤ò¶èÊ̤¹¤ëɬÍפ¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢´Ø¿ô mtext_get_prop_values ()
+    ¤òÂå¤ï¤ê¤Ë»ÈÍѤ¹¤ë¤³¤È¡£
+
+     @latexonly \IPAlabel{mtext_get_prop} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE, @c MERROR_SYMBOL
+
+    @seealso
+    mtext_get_prop_values (), mtext_put_prop (), mtext_put_prop_values (),
+    mtext_push_prop (), mtext_pop_prop (), mtext_prop_range ()  */
+
+void *
+mtext_get_prop (MText *mt, int pos, MSymbol key)
+{
+  MTextPlist *plist;
+  MInterval *interval;
+  void *val;
+
+  M_CHECK_POS (mt, pos, NULL);
+
+  plist = get_plist_create (mt, key, 0);
+  if (! plist)
+    return NULL;
+
+  interval = find_interval (plist, pos);
+  val = (interval->nprops
+        ? interval->stack[interval->nprops - 1]->val : NULL);
+  return val;
+}
+
+/*=*/
+
+/***en
+    @brief Get multiple values of a text property.
+
+    The mtext_get_prop_values () function searches the character at
+    $POS in M-text $MT for the property whose key is $KEY.  If such
+    a property is found, its values are stored in the memory area
+    pointed to by $VALUES.  $NUM limits the maximum number of stored
+    values.
+
+    @return
+    If the operation was successful, mtext_get_prop_values () returns
+    the number of actually stored values.  If the character at $POS
+    does not have a property whose key is $KEY, the return value is
+    0. If an error is detected, mtext_get_prop_values () returns -1 and
+    assigns an error code to the external variable #merror_code.  */
+
+/***ja
+    @brief ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊ£¿ô¸ÄÆÀ¤ë.
+
+    ´Ø¿ô mtext_get_prop_values () ¤Ï¡¢M-text $MT Æâ¤Ç $POS ¤È¤¤¤¦°ÌÃÖ
+    ¤Ë¤¢¤ëʸ»ú¤Î¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¡¢¥­¡¼¤¬ $KEY ¤Ç¤¢¤ë¤â¤Î¤òõ¤¹¡£¤â¤·¤½
+    ¤Î¤è¤¦¤Ê¥×¥í¥Ñ¥Æ¥£¤¬¸«¤Ä¤«¤ì¤Ð¡¢¤½¤ì¤¬»ý¤ÄÃÍ (Ê£¿ô²Ä) ¤ò $VALUES 
+    ¤Î»Ø¤¹¥á¥â¥êÎΰè¤Ë³ÊǼ¤¹¤ë¡£$NUM ¤Ï³ÊǼ¤¹¤ëÃͤοô¤Î¾å¸Â¤Ç¤¢¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_get_prop_values () ¤Ï¼ÂºÝ¤Ë¥á¥â¥ê¤Ë³ÊǼ¤µ
+    ¤ì¤¿Ãͤοô¤òÊÖ¤¹¡£$POS ¤Î°ÌÃÖ¤Îʸ»ú¤¬ $KEY ¤ò¥­¡¼¤È¤¹¤ë¥×¥í¥Ñ¥Æ¥£
+    ¤ò»ý¤¿¤Ê¤±¤ì¤Ð 0 ¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï -1 ¤òÊÖ¤·¡¢³°Éô
+    ÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mtext_get_prop_values} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE, @c MERROR_SYMBOL
+
+    @seealso
+    mtext_get_prop (), mtext_put_prop (), mtext_put_prop_values (),
+    mtext_push_prop (), mtext_pop_prop (), mtext_prop_range ()  */
+
+int
+mtext_get_prop_values (MText *mt, int pos, MSymbol key,
+                      void **values, int num)
+{
+  MTextPlist *plist;
+  MInterval *interval;
+  int nprops;
+  int i;
+  int offset;
+
+  M_CHECK_POS (mt, pos, -1);
+
+  plist = get_plist_create (mt, key, 0);
+  if (! plist)
+    return 0;
+
+  interval = find_interval (plist, pos);
+  /* It is assured that INTERVAL is not NULL.  */
+  nprops = interval->nprops;
+  if (nprops == 0 || num <= 0)
+    return 0;
+  if (nprops == 1 || num == 1)
+    {
+      values[0] = interval->stack[nprops - 1]->val;
+      return 1;
+    }
+
+  if (nprops <= num)
+    num = nprops, offset = 0;
+  else
+    offset = nprops - num;
+  for (i = 0; i < num; i++)
+    values[i] = interval->stack[offset + i]->val;
+  return num;
+}
+
+/*=*/
+
+/***en
+    @brief Get a list of text property keys at a position of an M-text.
+
+    The mtext_get_prop_keys () function creates an array whose
+    elements are the keys of text properties found at position $POS in
+    M-text $MT, and sets *$KEYS to the address of the created array.
+    The user is responsible to free the memory allocated for
+    the array.
+
+    @returns
+    If the operation was successful, mtext_get_prop_keys () returns
+    the length of the key list.  Otherwise it returns -1 and assigns
+    an error code to the external variable #merror_code.
+
+*/
+
+/***ja
+    @brief M-text ¤Î»ØÄꤷ¤¿°ÌÃ֤Υƥ­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤Î¥ê¥¹¥È¤òÆÀ¤ë.
+
+    ´Ø¿ô mtext_get_prop_keys () ¤Ï¡¢M-text $MT Æâ¤Ç $POS ¤Î°ÌÃ֤ˤ¢¤ë
+    ¤¹¤Ù¤Æ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤òÍ×ÁǤȤ¹¤ëÇÛÎó¤òºî¤ê¡¢¤½¤ÎÇÛÎó¤Î
+    ¥¢¥É¥ì¥¹¤ò *$KEYS ¤ËÀßÄꤹ¤ë¡£¤³¤ÎÇÛÎó¤Î¤¿¤á¤Ë³ÎÊݤµ¤ì¤¿¥á¥â¥ê¤ò²ò
+    Êü¤¹¤ë¤Î¤Ï¥æ¡¼¥¶¤ÎÀÕǤ¤Ç¤¢¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mtext_get_prop_keys () ¤ÏÆÀ¤é¤ì¤¿¥ê¥¹¥È¤ÎŤµ¤òÊÖ
+    ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤ò
+    ÀßÄꤹ¤ë¡£
+*/
+
+/***
+    @errors
+    @c MERROR_RANGE
+
+    @seealso
+    mtext_get_prop (), mtext_put_prop (), mtext_put_prop_values (),
+    mtext_get_prop_values (), mtext_push_prop (), mtext_pop_prop ()  */
+
+int
+mtext_get_prop_keys (MText *mt, int pos, MSymbol **keys)
+{
+  MTextPlist *plist;
+  int i;
+
+  M_CHECK_POS (mt, pos, -1);
+  for (i = 0, plist = mt->plist; plist; i++, plist = plist->next);
+  if (i == 0)
+    {
+      *keys = NULL;
+      return 0;
+    }
+  MTABLE_MALLOC (*keys, i, MERROR_TEXTPROP);
+  for (i = 0, plist = mt->plist; plist; plist = plist->next)
+    {
+      MInterval *interval = find_interval (plist, pos);
+
+      if (interval->nprops)
+       (*keys)[i++] = plist->key;
+    }
+  return i;
+}
+
+/*=*/
+
+/***en
+    @brief Set a text property.
+
+    The mtext_put_prop () function sets a text property to the
+    characters between $FROM (inclusive) and $TO (exclusive) in M-text
+    $MT.  $KEY and $VAL specify the key and the value of the text
+    property.  With this function,
+
+@verbatim
+                     FROM                   TO
+M-text: |<------------|-------- MT ---------|------------>|
+PROP  :  <------------------ OLD_VAL -------------------->
+@endverbatim
+
+   becomes
+
+@verbatim
+                     FROM                   TO
+M-text: |<------------|-------- MT ---------|------------>|
+PROP  :  <-- OLD_VAL-><-------- VAL -------><-- OLD_VAL-->
+@endverbatim
+
+    @return
+    If the operation was successful, mtext_put_prop () returns 0.
+    Otherwise it returns -1 and assigns an error code to the external
+    variable #merror_code.  */
+
+/***ja
+    @brief ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÀßÄꤹ¤ë.
+
+    ´Ø¿ô mtext_put_prop () ¤Ï¡¢M-text $MT ¤Î $FROM ¡Ê´Þ¤Þ¤ì¤ë¡Ë¤«¤é 
+    $TO ¡Ê´Þ¤Þ¤ì¤Ê¤¤¡Ë¤ÎÈϰϤÎʸ»ú¤Ë¡¢¥­¡¼¤¬ $KEY ¤ÇÃͤ¬ $VAL ¤Ç¤¢¤ë¤è
+    ¤¦¤Ê¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÀßÄꤹ¤ë¡£¤³¤Î´Ø¿ô¤Ë¤è¤Ã¤Æ
+
+
+@verbatim
+                         FROM                    TO
+M-text:      |<------------|-------- MT ---------|------------>|
+PROP:         <------------------ OLD_VAL -------------------->
+@endverbatim
+
+¤Ï¼¡¤Î¤è¤¦¤Ë¤Ê¤ë¡£
+
+@verbatim
+                         FROM                    TO
+M-text:       |<------------|-------- MT ---------|------------>|
+PROP:          <-- OLD_VAL-><-------- VAL -------><-- OLD_VAL-->
+@endverbatim
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mtext_put_prop () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mtext_put_prop} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE, @c MERROR_SYMBOL
+
+    @seealso
+    mtext_put_prop_values (), mtext_get_prop (),
+    mtext_get_prop_values (), mtext_push_prop (),
+    mtext_pop_prop (), mtext_prop_range ()  */
+
+int
+mtext_put_prop (MText *mt, int from, int to, MSymbol key, void *val)
+{
+  MTextPlist *plist;
+  MTextProperty *prop;
+  MInterval *interval;
+
+  M_CHECK_RANGE (mt, from, to, -1, 0);
+
+  prepare_to_modify (mt, from, to, key, 0);
+  plist = get_plist_create (mt, key, 1);
+  interval = pop_all_properties (plist, from, to);
+  prop = new_text_property (mt, from, to, key, val, 0);
+  PUSH_PROP (interval, prop);
+  M17N_OBJECT_UNREF (prop);
+  if (interval->next)
+    maybe_merge_interval (plist, interval);
+  if (interval->prev)
+    maybe_merge_interval (plist, interval->prev);
+  xassert (check_plist (plist, 0) == 0);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Set multiple text properties with the same key.
+
+    The mtext_put_prop_values () function sets a text property to the
+    characters between $FROM (inclusive) and $TO (exclusive) in M-text
+    $MT.  $KEY and $VALUES specify the key and the values of the text
+    property.  $NUM specifies the number of property values to be set.
+
+    @return
+    If the operation was successful, mtext_put_prop_values () returns
+    0.  Otherwise it returns -1 and assigns an error code to the
+    external variable #merror_code.  */
+
+/***ja
+    @brief Æ±¤¸¥­¡¼¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÊ£¿ôÀßÄꤹ¤ë.
+
+    ´Ø¿ô mtext_put_prop_values () ¤Ï¡¢M-Text $MT ¤Î$FROM ¡Ê´Þ¤Þ¤ì¤ë¡Ë
+    ¤«¤é $TO ¡Ê´Þ¤Þ¤ì¤Ê¤¤¡Ë¤ÎÈϰϤÎʸ»ú¤Ë¡¢¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÀßÄꤹ
+    ¤ë¡£¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤Ï $KEY ¤Ë¤è¤Ã¤Æ¡¢ÃÍ(Ê£¿ô²Ä)¤Ï $VALUES 
+    ¤Ë¤è¤Ã¤Æ»ØÄꤵ¤ì¤ë¡£$NUM ¤ÏÀßÄꤵ¤ì¤ëÃͤθĿô¤Ç¤¢¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_put_prop_values () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±
+    ¤ì¤Ð -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mtext_put_prop_values} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE, @c MERROR_SYMBOL
+
+    @seealso
+    mtext_put_prop (), mtext_get_prop (), mtext_get_prop_values (),
+    mtext_push_prop (), mtext_pop_prop (), mtext_prop_range ()  */
+
+int
+mtext_put_prop_values (MText *mt, int from, int to,
+                      MSymbol key, void **values, int num)
+{
+  MTextPlist *plist;
+  MInterval *interval;
+  int i;
+
+  M_CHECK_RANGE (mt, from, to, -1, 0);
+
+  prepare_to_modify (mt, from, to, key, 0);
+  plist = get_plist_create (mt, key, 1);
+  interval = pop_all_properties (plist, from, to);
+  if (num > 0)
+    {
+      PREPARE_INTERVAL_STACK (interval, num);
+      for (i = 0; i < num; i++)
+       {
+         MTextProperty *prop
+           = new_text_property (mt, from, to, key, values[i], 0);
+         PUSH_PROP (interval, prop);
+         M17N_OBJECT_UNREF (prop);
+       }
+    }
+  if (interval->next)
+    maybe_merge_interval (plist, interval);
+  if (interval->prev)
+    maybe_merge_interval (plist, interval->prev);
+  xassert (check_plist (plist, 0) == 0);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Push a text property.
+
+    The mtext_push_prop () function pushes a text property whose key
+    is $KEY and value is $VAL to the characters between $FROM
+    (inclusive) and $TO (exclusive) in M-text $MT.  With this
+    function,
+
+@verbatim
+                    FROM                    TO
+M-text: |<------------|-------- MT ---------|------------>|
+PROP  :  <------------------ OLD_VAL -------------------->
+@endverbatim
+
+    becomes
+
+@verbatim 
+                    FROM                    TO
+M-text: |<------------|-------- MT ---------|------------>|
+PROP  :  <------------------- OLD_VAL ------------------->
+PROP  :               <-------- VAL ------->
+@endverbatim
+
+    @return
+    If the operation was successful, mtext_push_prop () returns 0.
+    Otherwise it returns -1 and assigns an error code to the external
+    variable #merror_code.  */
+
+/***ja
+    @brief ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥×¥Ã¥·¥å¤¹¤ë.
+
+    ´Ø¿ô mtext_push_prop () ¤Ï¡¢¥­¡¼¤¬ $KEY ¤ÇÃͤ¬ $VAL ¤Ç¤¢¤ë¥Æ¥­¥¹¥È
+    ¥×¥í¥Ñ¥Æ¥£¤ò¡¢M-text $MT Ãæ¤Î $FROM ¡Ê´Þ¤Þ¤ì¤ë¡Ë¤«¤é $TO ¡Ê´Þ¤Þ¤ì¤Ê
+    ¤¤¡Ë¤ÎÈϰϤÎʸ»ú¤Ë¥×¥Ã¥·¥å¤¹¤ë¡£¤³¤Î´Ø¿ô¤Ë¤è¤Ã¤Æ
+
+@verbatim
+                    FROM                    TO
+M-text: |<------------|-------- MT ---------|------------>|
+PROP  :  <------------------ OLD_VAL -------------------->
+@endverbatim
+ ¤Ï¼¡¤Î¤è¤¦¤Ë¤Ê¤ë¡£
+@verbatim 
+                    FROM                    TO
+M-text: |<------------|-------- MT ---------|------------>|
+PROP  :  <------------------- OLD_VAL ------------------->
+PROP  :               <-------- VAL ------->
+@endverbatim
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_push_prop () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð 
+    -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mtext_push_prop} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE, @c MERROR_SYMBOL
+
+    @seealso
+    mtext_put_prop (), mtext_put_prop_values (),
+    mtext_get_prop (), mtext_get_prop_values (),
+    mtext_pop_prop (), mtext_prop_range ()  */
+
+int
+mtext_push_prop (MText *mt, int from, int to,
+                MSymbol key, void *val)
+{
+  MTextPlist *plist;
+  MInterval *head, *tail, *interval;
+  MTextProperty *prop;
+  int check_head, check_tail;
+
+  M_CHECK_RANGE (mt, from, to, -1, 0);
+
+  prepare_to_modify (mt, from, to, key, 0);
+  plist = get_plist_create (mt, key, 1);
+
+  /* Find an interval that covers the position FROM.  */
+  head = find_interval (plist, from);
+
+  /* If the found interval starts before FROM, divide it at FROM.  */
+  if (head->start < from)
+    {
+      divide_interval (plist, head, from);
+      head = head->next;
+      check_head = 0;
+    }
+  else
+    check_head = 1;
+
+  /* Find an interval that ends at TO.  If TO is not at the end of an
+     interval, make one that ends at TO.  */
+  if (head->end == to)
+    {
+      tail = head;
+      check_tail = 1;
+    }
+  else if (head->end > to)
+    {
+      divide_interval (plist, head, to);
+      tail = head;
+      check_tail = 0;
+    }
+  else
+    {
+      tail = find_interval (plist, to);
+      if (! tail)
+       {
+         tail = plist->tail;
+         check_tail = 0;
+       }
+      else if (tail->start == to)
+       {
+         tail = tail->prev;
+         check_tail = 1;
+       }
+      else
+       {
+         divide_interval (plist, tail, to);
+         check_tail = 0;
+       }
+    }
+
+  prop = new_text_property (mt, from, to, key, val, 0);
+
+  /* Push PROP to the current values of intervals between HEAD and TAIL
+     (both inclusive).  */
+  for (interval = head; ; interval = interval->next)
+    {
+      PUSH_PROP (interval, prop);
+      if (interval == tail)
+       break;
+    }
+
+  M17N_OBJECT_UNREF (prop);
+
+  /* If there is a possibility that TAIL now has the same value as the
+     next one, check it and concatenate them if necessary.  */
+  if (tail->next && check_tail)
+    maybe_merge_interval (plist, tail);
+
+  /* If there is a possibility that HEAD now has the same value as the
+     previous one, check it and concatenate them if necessary.  */
+  if (head->prev && check_head)
+    maybe_merge_interval (plist, head->prev);
+
+  xassert (check_plist (plist, 0) == 0);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Pop a text property.
+
+    The mtext_pop_prop () function removes the topmost text property
+    whose key is $KEY from the characters between $FROM (inclusive)
+    and and $TO (exclusive) in $MT.
+
+    This function does nothing if characters in the region have no
+    such text property. With this function,
+
+@verbatim
+                    FROM                    TO
+M-text: |<------------|-------- MT ---------|------------>|
+PROP  :  <------------------ OLD_VAL -------------------->
+@endverbatim
+
+    becomes
+
+@verbatim 
+                    FROM                    TO
+M-text: |<------------|-------- MT ---------|------------>|
+PROP  :  <--OLD_VAL-->|                     |<--OLD_VAL-->|
+@endverbatim
+
+    @return
+    If the operation was successful, mtext_pop_prop () return 0.
+    Otherwise it returns -1 and assigns an error code to the external
+    variable #merror_code.  */
+
+/***ja
+    @brief ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥Ý¥Ã¥×¤¹¤ë.
+
+    ´Ø¿ô mtext_pop_prop () ¤Ï¡¢¥­¡¼¤¬ $KEY ¤Ç¤¢¤ë¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î
+    ¤¦¤Á°ìÈÖ¾å¤Î¤â¤Î¤ò¡¢M-text $MT ¤Î $FROM ¡Ê´Þ¤Þ¤ì¤ë¡Ë¤«¤é $TO¡Ê´Þ¤Þ
+    ¤ì¤Ê¤¤¡Ë¤ÎÈϰϤÎʸ»ú¤«¤é¼è¤ê½ü¤¯¡£
+
+    »ØÄêÈϰϤÎʸ»ú¤¬¤½¤Î¤è¤¦¤Ê¥×¥í¥Ñ¥Æ¥£¤ò»ý¤¿¤Ê¤¤¤Ê¤é¤Ð¡¢¤³¤Î´Ø¿ô¤Ï²¿
+    ¤â¤·¤Ê¤¤¡£¤³¤Î´Ø¿ô¤Ë¤è¤Ã¤Æ¡¢
+
+@verbatim
+                    FROM                    TO
+M-text: |<------------|-------- MT ---------|------------>|
+PROP  :  <------------------ OLD_VAL -------------------->
+@endverbatim
+ ¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤Ê¤ë¡£
+@verbatim 
+                    FROM                    TO
+M-text: |<------------|-------- MT ---------|------------>|
+PROP  :  <--OLD_VAL-->|                     |<--OLD_VAL-->|
+@endverbatim
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_pop_prop () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mtext_pop_prop} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE, @c MERROR_SYMBOL
+
+    @seealso
+    mtext_put_prop (), mtext_put_prop_values (),
+    mtext_get_prop (), mtext_get_prop_values (),
+    mtext_push_prop (), mtext_prop_range ()  */
+
+int
+mtext_pop_prop (MText *mt, int from, int to, MSymbol key)
+{
+  MTextPlist *plist;
+  MInterval *head, *tail;
+  int check_head = 1;
+
+  if (key == Mnil)
+    MERROR (MERROR_TEXTPROP, -1);
+  M_CHECK_RANGE (mt, from, to, -1, 0);
+  plist = get_plist_create (mt, key, 0);
+  if (! plist)
+    return 0;
+
+  /* Find an interval that covers the position FROM.  */
+  head = find_interval (plist, from);
+  if (head->end >= to
+      && head->nprops == 0)
+    /* No property to pop.  */
+    return 0;
+
+  prepare_to_modify (mt, from, to, key, 0);
+
+  /* If the found interval starts before FROM and has value(s), divide
+     it at FROM.  */
+  if (head->start < from)
+    {
+      if (head->nprops > 0)
+       {
+         divide_interval (plist, head, from);
+         check_head = 0;
+       }
+      else
+       from = head->end;
+      head = head->next;
+    }
+
+  /* Pop the topmost text property from each interval following HEAD.
+     Stop at an interval that ends after TO.  */
+  for (tail = head; tail && tail->end <= to; tail = tail->next)
+    if (tail->nprops > 0)
+      POP_PROP (tail);
+
+  if (tail)
+    {
+      if (tail->start < to)
+       {
+         if (tail->nprops > 0)
+           {
+             divide_interval (plist, tail, to);
+             POP_PROP (tail);
+           }
+         to = tail->start;
+       }
+      else
+       to = tail->end;
+    }
+  else
+    to = plist->tail->start;
+
+  /* If there is a possibility that HEAD now has the same text
+     properties as the previous one, check it and concatenate them if
+     necessary.  */
+  if (head->prev && check_head)
+    head = head->prev;
+  while (head && head->end <= to)
+    head = maybe_merge_interval (plist, head);
+
+  xassert (check_plist (plist, 0) == 0);
+  return 0;
+}
+
+/*=*/
+
+/***en
+    @brief Find the range where the value of a text property is the same.
+
+    The mtext_prop_range () function investigates the extent where all
+    characters have the same value for a text property.  It first
+    finds the value of the property specified by $KEY of the character
+    at $POS in M-text $MT.  Then it checks if adjacent characters have
+    the same value for the property $KEY.  The beginning and the end
+    of the found range are stored to the variable pointed to by $FROM
+    and $TO.  The character position stored in $FROM is inclusive but
+    that in $TO is exclusive; this fashion is compatible with the
+    range specification in the mtext_put_prop () function, etc.
+
+    If $DEEPER is not 0, not only the topmost but also all the stacked
+    properties whose key is $KEY are compared.
+
+    If $FROM is @c NULL, the beginning of range is not searched for.  If
+    $TO is @c NULL, the end of range is not searched for.
+
+    @return
+
+    If the operation was successful, mtext_prop_range () returns the
+    number of values the property $KEY has at pos.  Otherwise it
+    returns -1 and assigns an error code to the external variable @c
+    merror_code.  */
+
+/***ja
+    @brief ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤¬Æ±¤¸Ãͤò¤È¤ëÈϰϤòÄ´¤Ù¤ë.
+
+    ´Ø¿ô mtext_prop_range () ¤Ï¡¢»ØÄꤷ¤¿¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬Æ±¤¸
+    ¤Ç¤¢¤ëϢ³¤·¤¿Ê¸»ú¤ÎÈϰϤòÄ´¤Ù¤ë¡£¤Þ¤º M-text $MT ¤Î $POS ¤Î°ÌÃÖ¤Ë
+    ¤¢¤ëʸ»ú¤Î¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¡¢¥­¡¼ $KEY ¤Ç»ØÄꤵ¤ì¤¿¤â¤ÎÃͤò¸«¤Ä¤±
+    ¤ë¡£¤½¤·¤ÆÁ°¸å¤Îʸ»ú¤â $KEY ¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬Æ±¤¸¤Ç¤¢¤ë¤«¤É¤¦¤«¤ò
+    Ä´¤Ù¤ë¡£¸«¤Ä¤±¤¿ÈϰϤκǽé¤ÈºÇ¸å¤ò¡¢¤½¤ì¤¾¤ì $FROM ¤È $TO ¤Ë¥Ý¥¤¥ó
+    ¥È¤µ¤ì¤ëÊÑ¿ô¤ËÊݸ¤¹¤ë¡£$FROM ¤ËÊݸ¤µ¤ì¤ëʸ»ú¤Î°ÌÃ֤ϸ«¤Ä¤±¤¿ÈÏ°Ï
+    ¤Ë´Þ¤Þ¤ì¤ë¤¬¡¢$TO ¤Ï´Þ¤Þ¤ì¤Ê¤¤¡£¡Ê$TO ¤ÎÁ°¤ÇƱ¤¸Ãͤò¤È¤ëÈϰϤϽª¤ï
+    ¤ë¡£¡Ë¤³¤ÎÈÏ°Ï»ØÄêË¡¤Ï¡¢´Ø¿ô mtext_put_prop () ¤Ê¤É¤È¶¦Ä̤Ǥ¢¤ë¡£
+
+    $DEEPER ¤¬ 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢$KEY ¤È¤¤¤¦¥­¡¼¤ò»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á°ìÈÖ
+    ¾å¤Î¤â¤Î¤À¤±¤Ç¤Ê¤¯¡¢¥¹¥¿¥Ã¥¯Ãæ¤Î¤¹¤Ù¤Æ¤Î¤â¤Î¤¬Èæ³Ó¤µ¤ì¤ë¡£
+
+    $FROM ¤¬ @c NULL ¤Ê¤é¤Ð¡¢ÈϰϤλϤޤê¤Ïõº÷¤·¤Ê¤¤¡£$TO ¤¬ @c NULL 
+    ¤Ê¤é¤Ð¡¢ÈϰϤνª¤ê¤Ïõº÷¤·¤Ê¤¤¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_prop_range () ¤Ï $KEY ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤοô¤ò
+    ÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð-1 ¤òÊÖ¤·¡¢ ³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼
+    ¥É¤òÀßÄꤹ¤ë¡£
+
+    @latexonly \IPAlabel{mtext_prop_range} @endlatexonly  */
+
+/***
+    @errors
+    @c MERROR_RANGE, @c MERROR_SYMBOL
+
+    @seealso
+    mtext_put_prop (), mtext_put_prop_values (),
+    mtext_get_prop (), mtext_get_prop_values (), 
+    mtext_pop_prop (), mtext_push_prop ()  */
+
+int
+mtext_prop_range (MText *mt, MSymbol key, int pos,
+                 int *from, int *to, int deeper)
+{
+  MTextPlist *plist;
+  MInterval *interval, *temp;
+  void *val;
+  int nprops;
+
+  M_CHECK_POS (mt, pos, -1);
+
+  plist = get_plist_create (mt, key, 0);
+  if (! plist)
+    {
+      if (from) *from = 0;
+      if (to) *to = mtext_nchars (mt);
+      return 0;
+    }
+
+  interval = find_interval (plist, pos);
+  nprops = interval->nprops;
+  if (deeper || ! nprops)
+    {
+      if (from) *from = interval->start;
+      if (to) *to = interval->end;
+      return interval->nprops;
+    }
+
+  val = nprops ? interval->stack[nprops - 1] : NULL;
+
+  if (from)
+    {
+      for (temp = interval;
+          temp->prev
+            && (temp->prev->nprops
+                ? (nprops
+                   && (val == temp->prev->stack[temp->prev->nprops - 1]))
+                : ! nprops);
+          temp = temp->prev);
+      *from = temp->start;
+    }
+
+  if (to)
+    {
+      for (temp = interval;
+          temp->next
+            && (temp->next->nprops
+                ? (nprops
+                   && val == temp->next->stack[temp->next->nprops - 1])
+                : ! nprops);
+          temp = temp->next);
+      *to = temp->end;
+    }
+
+  return nprops;
+}
+
+/***en
+    @brief Create a text property.
+
+    The mtext_property () function returns a newly allocated text
+    property whose key is $KEY and value is $VAL.  The created text 
+    property is not attached to any M-text, i.e. it is detached.
+
+    $CONTROL_BITS must be 0 or logical OR of @c enum @c
+    MTextPropertyControl.  */
+
+/***ja
+    @brief ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÀ¸À®¤¹¤ë.
+
+    ´Ø¿ô mtext_property () ¤Ï $KEY ¤ò¥­¡¼¡¢$VAL ¤òÃͤȤ¹¤ë¿·¤·¤¯³ä¤êÅö
+    ¤Æ¤é¤ì¤¿¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÊÖ¤¹¡£À¸À®¤·¤¿¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¤¤«
+    ¤Ê¤ë M-text ¤Ë¤âÉղ䵤ì¤Æ¤¤¤Ê¤¤¡¢¤¹¤Ê¤ï¤ÁʬΥ¤·¤Æ (detached) ¤¤¤ë¡£
+
+    $CONTROL_BITS ¤Ï 0 ¤Ç¤¢¤ë¤« @c enum @c MTextPropertyControl ¤ÎÏÀÍý 
+    OR ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£  */
+
+MTextProperty *
+mtext_property (MSymbol key, void *val, int control_bits)
+{
+  return new_text_property (NULL, 0, 0, key, val, control_bits);
+}
+
+/***en
+    @brief Return the M-text of a text property.
+
+    The mtext_property_mtext () function returns the M-text to which
+    text property $PROP is attached.  If $PROP is currently detached,
+    NULL is returned.  */
+
+/***ja
+    @brief ¤¢¤ë¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä M-text ¤òÊÖ¤¹.
+
+    ´Ø¿ô mtext_property_mtext () ¤Ï¡¢¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£$PROP ¤¬Éղäµ
+    ¤ì¤Æ¤¤¤ë M-text ¤òÊÖ¤¹¡£¤½¤Î»þÅÀ¤Ç $PROP ¤¬Ê¬Î¥¤·¤Æ¤¤¤ì¤Ð NULL ¤ò
+    ÊÖ¤¹¡£  */
+
+MText *
+mtext_property_mtext (MTextProperty *prop)
+{
+  return prop->mt;
+}
+
+/***en
+    @brief Return the key of a text property.
+
+    The mtext_property_key () function returns the key (symbol) of
+    text property $PROP.  */
+
+/***ja
+    @brief ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤òÊÖ¤¹.
+
+    ´Ø¿ô mtext_property_key () ¤Ï¡¢¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ $PROP ¤Î¥­¡¼¡Ê¥·
+    ¥ó¥Ü¥ë¡Ë¤òÊÖ¤¹¡£  */
+
+MSymbol
+mtext_property_key (MTextProperty *prop)
+{
+  return prop->key;
+}
+
+/***en
+    @brief Return the value of a text property.
+
+    The mtext_property_value () function returns the value of text
+    property $PROP.  */
+
+/***ja
+    @brief ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹.
+
+    ´Ø¿ô mtext_property_value () ¤Ï¡¢¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ $PROP ¤ÎÃͤòÊÖ
+    ¤¹¡£  */
+
+void *
+mtext_property_value (MTextProperty *prop)
+{
+  return prop->val;
+}
+
+/***en
+    @brief Return the start position of a text property.
+
+    The mtext_property_start () function returns the start position of
+    text property $PROP.  The start position is a character position
+    of an M-text where $PROP begins.  If $PROP is detached, it returns
+    -1.  */
+
+/***ja
+    @brief ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î³«»Ï°ÌÃÖ¤òÊÖ¤¹.
+
+    ´Ø¿ô mtext_property_start () ¤Ï¡¢¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ $PROP ¤Î³«»Ï°Ì
+    ÃÖ¤òÊÖ¤¹¡£³«»Ï°ÌÃ֤ȤϠM-text Ãæ¤Ç $PROP ¤¬»Ï¤Þ¤ëʸ»ú°ÌÃ֤Ǥ¢¤ë¡£
+    $PROP ¤¬Ê¬Î¥¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢-1 ¤òÊÖ¤¹¡£  */
+
+int
+mtext_property_start (MTextProperty *prop)
+{
+  return (prop->mt ? prop->start : -1);
+}
+
+/***en
+    @brief Return the end position of a text property.
+
+    The mtext_property_end () function returns the end position of
+    text property $PROP.  The end position is a character position of
+    an M-text where $PROP ends.  If $PROP is detached, it returns
+    -1.  */
+
+/***ja
+    @brief ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î½ªÎ»°ÌÃÖ¤òÊÖ¤¹.
+
+    ´Ø¿ô mtext_property_end () ¤Ï¡¢¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ $PROP ¤Î½ªÎ»°ÌÃÖ
+    ¤òÊÖ¤¹¡£½ªÎ»°ÌÃ֤ȤϠM-text Ãæ¤Ç $PROP ¤¬½ª¤ëʸ»ú°ÌÃ֤Ǥ¢¤ë¡£$PROP 
+    ¤¬Ê¬Î¥¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢-1 ¤òÊÖ¤¹¡£  */
+
+int
+mtext_property_end (MTextProperty *prop)
+{
+  return (prop->mt ? prop->end : -1);
+}
+
+/***en
+    @brief Get the topmost text property.
+
+    The mtext_get_property () function searches the character at
+    position $POS in M-text $MT for a text property whose key is $KEY.
+
+    @return
+    If a text property is found, mtext_get_property () returns it.  If
+    there are multiple text properties, it returns the topmost one.
+    If no such property is found, it returns @c NULL without changing
+    the external variable #merror_code.
+
+    If an error is detected, mtext_get_property () returns @c NULL and
+    assigns an error code to the external variable #merror_code.  */
+
+/***ja
+    @brief °ìÈÖ¾å¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÆÀ¤ë.
+
+    ´Ø¿ô mtext_get_property () ¤Ï M-text $MT ¤Î°ÌÃÖ $POS ¤Îʸ»ú¤¬¥­¡¼
+    ¤¬ $KEY ¤Ç¤¢¤ë¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¤«¤É¤¦¤«¤òÄ´¤Ù¤ë¡£
+
+    @return 
+    ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤¬¸«¤Ä¤«¤ì¤Ð¡¢mtext_get_property () ¤Ï¤½¤ì¤òÊÖ¤¹¡£
+    Ê£¿ô¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢°ìÈÖ¾å¤Î¤â¤Î¤òÊÖ¤¹¡£¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð¡¢³°ÉôÊÑ¿ô 
+    #merror_code ¤òÊѤ¨¤ë¤³¤È¤Ê¤¯ @c NULL ¤òÊÖ¤¹¡£
+
+    ¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç mtext_get_property () ¤Ï @c NULL ¤òÊÖ¤·¡¢³°
+    ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£    */
+
+MTextProperty *
+mtext_get_property (MText *mt, int pos, MSymbol key)
+{
+  MTextPlist *plist;
+  MInterval *interval;
+
+  M_CHECK_POS (mt, pos, NULL);
+
+  plist = get_plist_create (mt, key, 0);
+  if (! plist)
+    return NULL;
+
+  interval = find_interval (plist, pos);
+  if (! interval->nprops)
+    return NULL;
+  return interval->stack[interval->nprops - 1];
+}
+
+/***en
+    @brief Get multiple text properties.
+
+    The mtext_get_properties () function searches the character at
+    $POS in M-text $MT for properties whose key is $KEY.  If such
+    properties are found, they are stored in the memory area pointed
+    to by $PROPS.  $NUM limits the maximum number of stored
+    properties.
+
+    @return
+    If the operation was successful, mtext_get_properties () returns
+    the number of actually stored properties.  If the character at
+    $POS does not have a property whose key is $KEY, the return value
+    is 0. If an error is detected, mtext_get_properties () returns -1
+    and assigns an error code to the external variable #merror_code.  */
+
+/***ja
+    @brief Ê£¿ô¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÆÀ¤ë.
+
+    ´Ø¿ô mtext_get_properties () ¤Ï M-text $MT ¤Î°ÌÃÖ $POS ¤Îʸ»ú¤¬¥­¡¼
+    ¤¬ $KEY ¤Ç¤¢¤ë¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¤«¤É¤¦¤«¤òÄ´¤Ù¤ë¡£¤½¤Î¤è¤¦¤Ê
+    ¥×¥í¥Ñ¥Æ¥£¤¬¤ß¤Ä¤«¤ì¤Ð¡¢$PROPS ¤¬»Ø¤¹¥á¥â¥êÎΰè¤ËÊݸ¤¹¤ë¡£$NUM ¤Ï
+    Êݸ¤µ¤ì¤ë¥×¥í¥Ñ¥Æ¥£¤Î¿ô¤Î¾å¸Â¤Ç¤¢¤ë¡£
+
+    @return 
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_get_properties () ¤Ï¼ÂºÝ¤ËÊݸ¤·¤¿¥×¥í¥Ñ¥Æ¥£
+    ¤Î¿ô¤òÊÖ¤¹¡£$POS ¤Î°ÌÃÖ¤Îʸ»ú¤¬¥­¡¼¤¬ $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò»ý¤¿
+    ¤Ê¤±¤ì¤Ð¡¢0 ¤¬Ê֤롣¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
+    mtext_get_properties () ¤Ï -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼
+    ¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+int
+mtext_get_properties (MText *mt, int pos, MSymbol key,
+                     MTextProperty **props, int num)
+{
+  MTextPlist *plist;
+  MInterval *interval;
+  int nprops;
+  int i;
+  int offset;
+
+  M_CHECK_POS (mt, pos, -1);
+
+  plist = get_plist_create (mt, key, 0);
+  if (! plist)
+    return 0;
+
+  interval = find_interval (plist, pos);
+  /* It is assured that INTERVAL is not NULL.  */
+  nprops = interval->nprops;
+  if (nprops == 0 || num <= 0)
+    return 0;
+  if (nprops == 1 || num == 1)
+    {
+      props[0] = interval->stack[nprops - 1];
+      return 1;
+    }
+
+  if (nprops <= num)
+    num = nprops, offset = 0;
+  else
+    offset = nprops - num;
+  for (i = 0; i < num; i++)
+    props[i] = interval->stack[offset + i];
+  return num;
+}
+
+/***en
+    @brief Attach a text property to an M-text.
+
+    The mtext_attach_property () function attaches text property $PROP
+    to the range between $FROM and $TO in M-text $MT.  If $PROP is
+    already attached to an M-text, it is detached before attached to
+    $MT.
+
+    @return
+    If the operation was successful, mtext_attach_property () returns
+    0.  Otherwise it returns -1 and assigns an error code to the
+    external variable #merror_code.  */
+
+/***ja
+    @brief  M-text¤Ë¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÉղ乤ë.
+
+    ´Ø¿ô mtext_attach_property () ¤Ï¡¢M-text $MT ¤Î $FROM ¤«¤é $TO ¤Þ
+    ¤Ç¤ÎÎΰè¤Ë¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ $PROP ¤òÉղ乤롣¤â¤· $PROP ¤¬´û¤Ë
+    M-text ¤ËÉղ䵤ì¤Æ¤¤¤ì¤Ð¡¢$MT ¤ËÉղ乤ëÁ°¤ËʬΥ¤µ¤ì¤ë¡£
+
+    @return 
+    ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð¡¢mtext_attach_property () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±
+    ¤ì¤Ð -1 ¤òÊÖ¤·¤Æ³°ÉôÊÑ¿ô#merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£      */
+
+
+int
+mtext_attach_property (MText *mt, int from, int to, MTextProperty *prop)
+{     
+  MTextPlist *plist;
+  MInterval *interval;
+
+  M_CHECK_RANGE (mt, from, to, -1, 0);
+
+  M17N_OBJECT_REF (prop);
+  if (prop->mt)
+    mtext_detach_property (prop);
+  prepare_to_modify (mt, from, to, prop->key, 0);
+  plist = get_plist_create (mt, prop->key, 1);
+  xassert (check_plist (plist, 0) == 0);
+  interval = pop_all_properties (plist, from, to);
+  xassert (check_plist (plist, 0) == 0);
+  prop->mt = mt;
+  prop->start = from;
+  prop->end = to;
+  PUSH_PROP (interval, prop);
+  M17N_OBJECT_UNREF (prop);
+  xassert (check_plist (plist, 0) == 0);
+  if (interval->next)
+    maybe_merge_interval (plist, interval);
+  if (interval->prev)
+    maybe_merge_interval (plist, interval->prev);
+  xassert (check_plist (plist, 0) == 0);
+  return 0;
+}
+
+/***en
+    @brief Detach a text property from an M-text.
+
+    The mtext_detach_property () function makes text property $PROP
+    detached.
+
+    @return
+    This function always returns 0.  */
+
+/***ja
+    @brief  M-text ¤«¤é¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òʬΥ¤¹¤ë.
+
+    ´Ø¿ô mtext_detach_property () ¤Ï¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ $PROP ¤òʬΥ¤¹¤ë¡£
+
+    @return
+    ¤³¤Î´Ø¿ô¤Ï¾ï¤Ë 0 ¤òÊÖ¤¹¡£  */
+
+int
+mtext_detach_property (MTextProperty *prop)
+{
+  MTextPlist *plist;
+  int start = prop->start, end = prop->end;
+
+  if (! prop->mt)
+    return 0;
+  prepare_to_modify (prop->mt, start, end, prop->key, 0);
+  plist = get_plist_create (prop->mt, prop->key, 0);
+  xassert (plist);
+  detach_property (plist, prop, NULL);
+  return 0;
+}
+
+/***en
+    @brief Push a text property onto an M-text.
+
+    The mtext_push_property () function pushes text property $PROP to
+    the characters between $FROM (inclusive) and $TO (exclusive) in
+    M-text $MT.
+
+    @return
+    If the operation was successful, mtext_push_property () returns
+    0.  Otherwise it returns -1 and assigns an error code to the
+    external variable #merror_code.  */
+
+/***ja
+    @brief M-text ¤Ë¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥×¥Ã¥·¥å¤¹¤ë.
+
+    ´Ø¿ô mtext_push_property () ¤Ï¡¢¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ $PROP ¤ò¡¢
+    M-text $MT Ãæ¤Î $FROM ¡Ê´Þ¤Þ¤ì¤ë¡Ë¤«¤é $TO ¡Ê´Þ¤Þ¤ì¤Ê¤¤¡Ë¤ÎÈϰϤÎ
+    Ê¸»ú¤Ë¥×¥Ã¥·¥å¤¹¤ë¡£
+
+    @return
+    ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð¡¢mtext_push_property () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±
+    ¤ì¤Ð -1 ¤òÊÖ¤·¤Æ³°ÉôÊÑ¿ô#merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£      */
+
+
+int
+mtext_push_property (MText *mt, int from, int to, MTextProperty *prop)
+{
+  MTextPlist *plist;
+  MInterval *head, *tail, *interval;
+  int check_head, check_tail;
+
+  M_CHECK_RANGE (mt, from, to, -1, 0);
+
+  M17N_OBJECT_REF (prop);
+  if (prop->mt)
+    mtext_detach_property (prop);
+  prepare_to_modify (mt, from, to, prop->key, 0);
+  plist = get_plist_create (mt, prop->key, 1);
+  prop->mt = mt;
+  prop->start = from;
+  prop->end = to;
+
+  /* Find an interval that covers the position FROM.  */
+  head = find_interval (plist, from);
+
+  /* If the found interval starts before FROM, divide it at FROM.  */
+  if (head->start < from)
+    {
+      divide_interval (plist, head, from);
+      head = head->next;
+      check_head = 0;
+    }
+  else
+    check_head = 1;
+
+  /* Find an interval that ends at TO.  If TO is not at the end of an
+     interval, make one that ends at TO.  */
+  if (head->end == to)
+    {
+      tail = head;
+      check_tail = 1;
+    }
+  else if (head->end > to)
+    {
+      divide_interval (plist, head, to);
+      tail = head;
+      check_tail = 0;
+    }
+  else
+    {
+      tail = find_interval (plist, to);
+      if (! tail)
+       {
+         tail = plist->tail;
+         check_tail = 0;
+       }
+      else if (tail->start == to)
+       {
+         tail = tail->prev;
+         check_tail = 1;
+       }
+      else
+       {
+         divide_interval (plist, tail, to);
+         check_tail = 0;
+       }
+    }
+
+  /* Push PROP to the current values of intervals between HEAD and TAIL
+     (both inclusive).  */
+  for (interval = head; ; interval = interval->next)
+    {
+      PUSH_PROP (interval, prop);
+      if (interval == tail)
+       break;
+    }
+
+  /* If there is a possibility that TAIL now has the same value as the
+     next one, check it and concatenate them if necessary.  */
+  if (tail->next && check_tail)
+    maybe_merge_interval (plist, tail);
+
+  /* If there is a possibility that HEAD now has the same value as the
+     previous one, check it and concatenate them if necessary.  */
+  if (head->prev && check_head)
+    maybe_merge_interval (plist, head->prev);
+
+  M17N_OBJECT_UNREF (prop);
+  xassert (check_plist (plist, 0) == 0);
+  return 0;
+}
+
+/***en
+    @brief Symbol for specifying serializer functions.
+
+    To serialize a text property, the user must supply a serializer
+    function for that text property.  This is done by giving a symbol
+    property whose key is #Mtext_prop_serializer and value is a
+    pointer to an appropriate serializer function.
+
+    @seealso
+    mtext_serialize (), #MTextPropSerializeFunc
+  */
+
+/***ja
+    @brief ¥·¥ê¥¢¥é¥¤¥¶´Ø¿ô¤ò»ØÄꤹ¤ë¥·¥ó¥Ü¥ë.
+
+    ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥·¥ê¥¢¥é¥¤¥º¤¹¤ë¤¿¤á¤Ë¤Ï¡¢¤½¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ
+    ¥Æ¥£ÍѤΥ·¥ê¥¢¥é¥¤¥¶´Ø¿ô¤òÍ¿¤¨¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¶ñÂÎŪ¤Ë¤Ï¡¢
+    #Mtext_prop_serializer ¤ò¥­¡¼¤È¤·¡¢Å¬Àڤʥ·¥ê¥¢¥é¥¤¥º´Ø¿ô¤Ø¤Î¥Ý¥¤
+    ¥ó¥¿¤òÃͤȤ¹¤ë¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤹ¤ë¡£
+
+    @seealso
+    mtext_serialize (), #MTextPropSerializeFunc
+  */
+MSymbol Mtext_prop_serializer;
+
+/***en
+    @brief Symbol for specifying deserializer functions.
+
+    To deserialize a text property, the user must supply a deserializer
+    function for that text property.  This is done by giving a symbol
+    property whose key is #Mtext_prop_deserializer and value is a
+    pointer to an appropriate deserializer function.
+
+    @seealso
+    mtext_deserialize (), #MTextPropSerializeFunc
+  */
+
+/***ja
+    @brief ¥Ç¥·¥ê¥¢¥é¥¤¥¶´Ø¿ô¤ò»ØÄꤹ¤ë¥·¥ó¥Ü¥ë.
+
+    ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥Ç¥·¥ê¥¢¥é¥¤¥º¤¹¤ë¤¿¤á¤Ë¤Ï¡¢¤½¤Î¥Æ¥­¥¹¥È¥×¥í
+    ¥Ñ¥Æ¥£ÍѤΥǥ·¥ê¥¢¥é¥¤¥¶´Ø¿ô¤òÍ¿¤¨¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¶ñÂÎŪ¤Ë¤Ï¡¢
+    #Mtext_prop_deserializer ¤ò¥­¡¼¤È¤·¡¢Å¬Àڤʥǥ·¥ê¥¢¥é¥¤¥º´Ø¿ô¤Ø¤Î
+    ¥Ý¥¤¥ó¥¿¤òÃͤȤ¹¤ë¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤹ¤ë¡£
+
+    @seealso
+    mtext_deserialize (), #MTextPropSerializeFunc
+  */
+MSymbol Mtext_prop_deserializer;
+
+/***en
+    @brief Serialize text properties in an M-text.
+
+    The mtext_serialize () function serializes the text between $FROM
+    and $TO in M-text $MT.  The serialized result is an M-text in a
+    form of XML.  $PROPERTY_LIST limits the text properties to be
+    serialized. Only those text properties whose key 
+
+    @li appears as the value of an element in $PROPERTY_LIST, and
+    @li has the symbol property #Mtext_prop_serializer
+
+    are serialized as a "property" element in the resulting XML
+    representation.
+
+    The DTD of the generated XML is as follows:
+
+@verbatim
+<!DOCTYPE mtext [
+  <!ELEMENT mtext (property*,body+)>
+  <!ELEMENT property EMPTY>
+  <!ELEMENT body (#PCDATA)>
+  <!ATTLIST property key CDATA #REQUIRED>
+  <!ATTLIST property value CDATA #REQUIRED>
+  <!ATTLIST property from CDATA #REQUIRED>
+  <!ATTLIST property to CDATA #REQUIRED>
+  <!ATTLIST property control CDATA #REQUIRED>
+ ]>
+@endverbatim
+
+    This function depends on the libxml2 library.  If the m17n library
+    is configured without libxml2, this function always fails.
+
+    @return
+    If the operation was successful, mtext_serialize () returns an
+    M-text in the form of XML.  Otherwise it returns @c NULL and assigns an
+    error code to the external variable #merror_code.
+
+    @seealso
+    mtext_deserialize (), #Mtext_prop_serializer  */
+
+/***ja
+    @brief M-text Ãæ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥·¥ê¥¢¥é¥¤¥º¤¹¤ë.
+
+    ´Ø¿ô mtext_serialize () ¤Ï M-text $MT ¤Î $FROM ¤«¤é $TO ¤Þ¤Ç¤Î¥Æ¥­
+    ¥¹¥È¤ò¥·¥ê¥¢¥é¥¤¥º¤¹¤ë¡£¥·¥ê¥¢¥é¥¤¥º¤·¤¿·ë²Ì¤Ï XML ·Á¼°¤Î M-text ¤Ç
+    ¤¢¤ë¡£ $PROPERTY_LIST ¤Ï¥·¥ê¥¢¥é¥¤¥º¤µ¤ì¤ë¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¸ÂÄê
+    ¤¹¤ë¡£ÂоݤȤʤë¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¡¢¤½¤Î¥­¡¼¤¬
+
+    @li $PROPERTY_LIST ¤ÎÍ×ÁǤÎÃͤȤ·¤Æ¸½¤ï¤ì¡¢¤«¤Ä
+    @li ¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£ #Mtext_prop_serializer ¤ò»ý¤Ä
+    
+    ¤â¤Î¤Î¤ß¤Ç¤¢¤ë¡£¤³¤Î¾ò·ï¤òËþ¤¿¤¹¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¡¢À¸À®¤µ¤ì¤ë 
+    XML É½¸½Ãæ¤Ç "property" Í×ÁǤ˥·¥ê¥¢¥é¥¤¥º¤µ¤ì¤ë¡£
+
+    À¸À®¤µ¤ì¤ë XML ¤Î DTD ¤Ï°Ê²¼¤ÎÄ̤ê:
+
+@verbatim
+<!DOCTYPE mtext [
+  <!ELEMENT mtext (property*,body+)>
+  <!ELEMENT property EMPTY>
+  <!ELEMENT body (#PCDATA)>
+  <!ATTLIST property key CDATA #REQUIRED>
+  <!ATTLIST property value CDATA #REQUIRED>
+  <!ATTLIST property from CDATA #REQUIRED>
+  <!ATTLIST property to CDATA #REQUIRED>
+  <!ATTLIST property control CDATA #REQUIRED>
+ ]>
+@endverbatim
+
+    ¤³¤Î´Ø¿ô¤Ï libxml2 ¥é¥¤¥Ö¥é¥ê¤Ë°Í¸¤¹¤ë¡£m17n ¥é¥¤¥Ö¥é¥ê¤¬libxml2 
+    Ìµ¤·¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢¤³¤Î´Ø¿ô¤Ï¾ï¤Ë¼ºÇÔ¤¹¤ë¡£
+
+    @return 
+    ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð¡¢mtext_serialize () ¤Ï XML ·Á¼°¤Ç M-text ¤òÊÖ¤¹¡£
+    ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤·¤Æ³°ÉôÊÑ¿ô#merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É
+    ¤òÀßÄꤹ¤ë¡£
+
+    @seealso
+    mtext_deserialize (), #Mtext_prop_serializer  */
+
+MText *
+mtext_serialize (MText *mt, int from, int to, MPlist *property_list)
+{
+#ifdef HAVE_XML2
+  MPlist *plist, *pl;
+  MTextPropSerializeFunc func;
+  MText *work;
+  xmlDocPtr doc;
+  xmlNodePtr node;
+  unsigned char *ptr;
+  int n;
+
+  M_CHECK_RANGE (mt, from, to, NULL, NULL);
+  if (mt->format != MTEXT_FORMAT_US_ASCII
+      && mt->format != MTEXT_FORMAT_UTF_8)
+    mtext__adjust_format (mt, MTEXT_FORMAT_UTF_8);
+  if (MTEXT_DATA (mt)[mtext_nbytes (mt)] != 0)
+    MTEXT_DATA (mt)[mtext_nbytes (mt)] = 0;
+  doc = xmlParseMemory (XML_TEMPLATE, strlen (XML_TEMPLATE) + 1);
+  node = xmlDocGetRootElement (doc);
+
+  plist = mplist ();
+  MPLIST_DO (pl, property_list)
+    {
+      MSymbol key = MPLIST_VAL (pl);
+
+      func = ((MTextPropSerializeFunc)
+             msymbol_get_func (key, Mtext_prop_serializer));
+      if (func)
+       extract_text_properties (mt, from, to, key, plist);
+    }
+
+  work = mtext ();
+  MPLIST_DO (pl, plist)
+    {
+      MTextProperty *prop = MPLIST_VAL (pl);
+      char buf[256];
+      MPlist *serialized_plist;
+      xmlNodePtr child;
+
+      func = ((MTextPropSerializeFunc)
+             msymbol_get_func (prop->key, Mtext_prop_serializer));
+      serialized_plist = (func) (prop->val);
+      if (! serialized_plist)
+       continue;
+      mtext_reset (work);
+      mplist__serialize (work, serialized_plist, 0);
+      child = xmlNewChild (node, NULL, (xmlChar *) "property", NULL);
+      xmlSetProp (child, (xmlChar *) "key",
+                 (xmlChar *) MSYMBOL_NAME (prop->key));
+      xmlSetProp (child, (xmlChar *) "value", (xmlChar *) MTEXT_DATA (work));
+      sprintf (buf, "%d", prop->start - from);
+      xmlSetProp (child, (xmlChar *) "from", (xmlChar *) buf);
+      sprintf (buf, "%d", prop->end - from);
+      xmlSetProp (child, (xmlChar *) "to", (xmlChar *) buf);
+      sprintf (buf, "%d", prop->control.flag);
+      xmlSetProp (child, (xmlChar *) "control", (xmlChar *) buf);
+      xmlAddChild (node, xmlNewText ((xmlChar *) "\n"));
+
+      M17N_OBJECT_UNREF (serialized_plist);
+    }
+  M17N_OBJECT_UNREF (plist);
+
+  if (from > 0 || to < mtext_nchars (mt))
+    mtext_copy (work, 0, mt, from, to);
+  else
+    {
+      M17N_OBJECT_UNREF (work);
+      work = mt;
+    }
+  for (from = 0, to = mtext_nchars (mt); from <= to; from++)
+    {
+      ptr = MTEXT_DATA (mt) + POS_CHAR_TO_BYTE (mt, from);
+      xmlNewTextChild (node, NULL, (xmlChar *) "body", (xmlChar *) ptr);
+      from = mtext_character (mt, from, to, 0);
+      if (from < 0)
+       from = to;
+    }
+
+  xmlDocDumpMemoryEnc (doc, (xmlChar **) &ptr, &n, "UTF-8");
+  if (work == mt)
+    work = mtext ();
+  mtext__cat_data (work, ptr, n, MTEXT_FORMAT_UTF_8);
+  return work;
+#else  /* not HAVE_XML2 */
+  MERROR (MERROR_TEXTPROP, NULL);
+#endif /* not HAVE_XML2 */
+}
+
+/***en
+    @brief Deserialize text properties in an M-text.
+
+    The mtext_deserialize () function deserializes M-text $MT.  $MT
+    must be an XML having the following DTD.
+
+@verbatim
+<!DOCTYPE mtext [
+  <!ELEMENT mtext (property*,body+)>
+  <!ELEMENT property EMPTY>
+  <!ELEMENT body (#PCDATA)>
+  <!ATTLIST property key CDATA #REQUIRED>
+  <!ATTLIST property value CDATA #REQUIRED>
+  <!ATTLIST property from CDATA #REQUIRED>
+  <!ATTLIST property to CDATA #REQUIRED>
+  <!ATTLIST property control CDATA #REQUIRED>
+ ]>
+@endverbatim
+
+    This function depends on the libxml2 library.  If the m17n library
+    is configured without libxml2, this function always fail.
+
+    @return
+    If the operation was successful, mtext_deserialize () returns the
+    resulting M-text.  Otherwise it returns @c NULL and assigns an error
+    code to the external variable #merror_code.
+
+    @seealso
+    mtext_serialize (), #Mtext_prop_deserializer  */
+
+/***ja
+    @brief M-text Ãæ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥Ç¥·¥ê¥¢¥é¥¤¥º¤¹¤ë.
+
+    ´Ø¿ô mtext_deserialize () ¤Ï M-text $MT ¤ò¥Ç¥·¥ê¥¢¥é¥¤¥º¤¹¤ë¡£$MT
+    ¤Ï¼¡¤Î DTD ¤ò»ý¤Ä XML ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+@verbatim
+<!DOCTYPE mtext [
+  <!ELEMENT mtext (property*,body+)>
+  <!ELEMENT property EMPTY>
+  <!ELEMENT body (#PCDATA)>
+  <!ATTLIST property key CDATA #REQUIRED>
+  <!ATTLIST property value CDATA #REQUIRED>
+  <!ATTLIST property from CDATA #REQUIRED>
+  <!ATTLIST property to CDATA #REQUIRED>
+  <!ATTLIST property control CDATA #REQUIRED>
+ ]>
+@endverbatim
+
+    ¤³¤Î´Ø¿ô¤Ï libxml2 ¥é¥¤¥Ö¥é¥ê¤Ë°Í¸¤¹¤ë¡£m17n ¥é¥¤¥Ö¥é¥ê¤¬libxml2 
+    Ìµ¤·¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢¤³¤Î´Ø¿ô¤Ï¾ï¤Ë¼ºÇÔ¤¹¤ë¡£
+
+    @return 
+    ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð¡¢mtext_serialize () ¤ÏÆÀ¤é¤ì¤¿ M-text ¤ò
+    ÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤·¤Æ³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼
+    ¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+
+    @seealso
+    mtext_serialize (), #Mtext_prop_deserializer  */
+
+MText *
+mtext_deserialize (MText *mt)
+{
+#ifdef HAVE_XML2
+  xmlDocPtr doc;
+  xmlNodePtr node;
+  xmlXPathContextPtr context;
+  xmlXPathObjectPtr result;
+  xmlChar *body_str, *key_str, *val_str, *from_str, *to_str, *ctl_str;
+  int i;
+
+  if (mt->format > MTEXT_FORMAT_UTF_8)
+    MERROR (MERROR_TEXTPROP, NULL);
+  doc = xmlParseMemory ((char *) MTEXT_DATA (mt), mtext_nbytes (mt));
+  if (! doc)
+    MERROR (MERROR_TEXTPROP, NULL);
+  node = xmlDocGetRootElement (doc);
+  if (! node)
+    {
+      xmlFreeDoc (doc);
+      MERROR (MERROR_TEXTPROP, NULL);
+    }
+  if (xmlStrcmp (node->name, (xmlChar *) "mtext"))
+    {
+      xmlFreeDoc (doc);
+      MERROR (MERROR_TEXTPROP, NULL);
+    }
+
+  context = xmlXPathNewContext (doc);
+  result = xmlXPathEvalExpression ((xmlChar *) "//body", context);
+  if (xmlXPathNodeSetIsEmpty (result->nodesetval))
+    {
+      xmlFreeDoc (doc);
+      MERROR (MERROR_TEXTPROP, NULL);
+    }
+  for (i = 0, mt = mtext (); i < result->nodesetval->nodeNr; i++)
+    {
+      if (i > 0)
+       mtext_cat_char (mt, 0);
+      node = (xmlNodePtr) result->nodesetval->nodeTab[i];
+      body_str = xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
+      if (body_str)
+       {
+         mtext__cat_data (mt, body_str, strlen ((char *) body_str),
+                          MTEXT_FORMAT_UTF_8);
+         xmlFree (body_str);
+       }
+    }
+
+  result = xmlXPathEvalExpression ((xmlChar *) "//property", context);
+  if (! xmlXPathNodeSetIsEmpty (result->nodesetval))
+    for (i = 0; i < result->nodesetval->nodeNr; i++)
+      {
+       MSymbol key;
+       MTextPropDeserializeFunc func;
+       MTextProperty *prop;
+       MPlist *plist;
+       int from, to, control;
+       void *val;
+
+       key_str = xmlGetProp (result->nodesetval->nodeTab[i],
+                             (xmlChar *) "key");
+       val_str = xmlGetProp (result->nodesetval->nodeTab[i],
+                             (xmlChar *) "value");
+       from_str = xmlGetProp (result->nodesetval->nodeTab[i],
+                              (xmlChar *) "from");
+       to_str = xmlGetProp (result->nodesetval->nodeTab[i],
+                            (xmlChar *) "to");
+       ctl_str = xmlGetProp (result->nodesetval->nodeTab[i],
+                             (xmlChar *) "control");
+
+       key = msymbol ((char *) key_str);
+       func = ((MTextPropDeserializeFunc)
+               msymbol_get_func (key, Mtext_prop_deserializer));
+       if (! func)
+         continue;
+       plist = mplist__from_string (val_str, strlen ((char *) val_str));
+       if (! plist)
+         continue;
+       if (sscanf ((char *) from_str, "%d", &from) != 1
+           || from < 0 || from >= mtext_nchars (mt))
+         continue;
+       if (sscanf ((char *) to_str, "%d", &to) != 1
+           || to <= from || to > mtext_nchars (mt))
+         continue;
+       if (sscanf ((char *) ctl_str, "%d", &control) != 1
+           || control < 0 || control > MTEXTPROP_CONTROL_MAX)
+         continue;
+       val = (func) (plist);
+       M17N_OBJECT_UNREF (plist);
+       prop = mtext_property (key, val, control);
+       if (key->managing_key)
+         M17N_OBJECT_UNREF (val);
+       mtext_push_property (mt, from, to, prop);
+       M17N_OBJECT_UNREF (prop);
+
+       xmlFree (key_str);
+       xmlFree (val_str);
+       xmlFree (from_str);
+       xmlFree (to_str);
+       xmlFree (ctl_str);
+      }
+  xmlXPathFreeContext (context);
+  xmlFreeDoc (doc);
+  return mt;
+#else  /* not HAVE_XML2 */
+  MERROR (MERROR_TEXTPROP, NULL);
+#endif /* not HAVE_XML2 */
+}
+
+/*** @} */
+
+/*
+  Local Variables:
+  coding: euc-japan
+  End:
+*/
diff --git a/src/textprop.h b/src/textprop.h
new file mode 100644 (file)
index 0000000..12b9638
--- /dev/null
@@ -0,0 +1,74 @@
+/* textproc.h -- header file for the text property module.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H15PRO112
+
+   This file is part of the m17n library.
+
+   The m17n 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.1 of
+   the License, or (at your option) any later version.
+
+   The m17n 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 the m17n library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   02111-1307, USA.  */
+
+#ifndef _M17N_TEXTPROP_H_
+#define _M17N_TEXTPROP_H_
+
+/** MTextProperty is the structure for a text property object.  While
+    attached, it is stored in the stacks of intervals covering the
+    range from MTextProperty->start to MTextProperty->end.  */
+
+struct MTextProperty
+{
+  /** Common header for a managed object.  */
+  M17NObject control;
+
+  /** Number of intervals the property is attached.  When it becomes
+      zero, the property is detached.  */
+  unsigned attach_count;
+
+  /** M-text to which the property is attaced.  The value NULL means
+      that the property is detached.  */
+  MText *mt;
+
+  /** Region of <mt> if the property is attached to it.  */
+  int start, end;
+
+  /** Key of the property.  */
+  MSymbol key;
+
+  /** Value of the property.  */
+  void *val;
+};
+
+#define MTEXTPROP_START(prop) (prop)->start
+#define MTEXTPROP_END(prop) (prop)->end
+#define MTEXTPROP_KEY(prop) (prop)->key
+#define MTEXTPROP_VAL(prop) (prop)->val
+
+extern struct MTextPlist *mtext__copy_plist (struct MTextPlist *, 
+                                            int from, int to,
+                                            MText *mt, int pos);
+
+extern void mtext__free_plist (MText *mt);
+
+extern void mtext__adjust_plist_for_delete (MText *, int, int);
+
+extern void mtext__adjust_plist_for_insert (MText *, int, int,
+                                           struct MTextPlist *);
+
+extern void mtext__adjust_plist_for_change (MText *mt, int pos,
+                                           int len1, int len2);
+
+extern void dump_textplist (struct MTextPlist *plist, int indent);
+
+#endif /* _M17N_TEXTPROP_H_ */