(shift_state): Don't reset ic_info->vars.
[m17n/m17n-lib.git] / src / m17n-core.c
index eeee07f..ec250ca 100644 (file)
@@ -22,7 +22,7 @@
 
 /***en
     @addtogroup m17nIntro
 
 /***en
     @addtogroup m17nIntro
-    @brief Introduction to the m17n library
+    @brief Introduction to the m17n library.
 
     <em>API LEVELS</em>
 
 
     <em>API LEVELS</em>
 
     <ol>
     <li> CORE API
 
     <ol>
     <li> CORE API
 
-    It provides basic modules to handle M-texts.  They don't require
+    It provides basic modules to handle M-texts.  They do not require
     the m17n database.  To use this API, an application program must
     the m17n database.  To use this API, an application program must
-    include <m17n-core.h> and be linked by -lm17n-core.
+    include <m17n-core<EM></EM>.h> and be linked by -lm17n-core.
 
     <li> SHELL API
 
 
     <li> SHELL API
 
-    It provides modules that utilize the m17n database.  They load
-    various kinds of data from the database on demand.  To use this
-    API, an application program must include <m17n.h> and be linked by
-    -lm17n-core -lm17n.  With that, CORE API is also available.
+    It provides modules that utilize the m17n database (code
+    conversion, character property, 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 by
+    -lm17n-core -lm17n.
+
+    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
 
     <li> GUI API
 
     It provides GUI modules such as drawing and inputting M-texts on a
-    window system.  The API itself is independent on a window system,
-    but the m17n library must be configured to use a specific window
-    system.  Currently, we support only the X Window System.  To use
-    this API, an application program must include <m17n-gui.h> and
-    <m17n-X.h>, and be linked by -lm17n-core -lm17n -lm17n-X.  With
-    that, CORE and SHELL APIs are also available.
+    graphic device.  The API itself is independent on a graphic device
+    but most functions require an argument MFrame which is created for
+    a specific type of graphic device.  Currently, a null device, X
+    Window System, and an image date (gdImagePtr) of GD library are
+    supported as a graphic device.
+
+    On a frame of the null device, you can't draw text nor use an
+    input method (but, for instance, the function mdraw_glyph_list ()
+    is available).
+
+    On a frame of the X Window System, you can use the whole GUI API.
+
+    On a frame of GD library, you can use all drawing API but can't
+    use input method.
+
+    To use this device, an application program must include
+    <m17n-gui<EM></EM>.h> and be linked by -lm17n-core -lm17n
+    -lm17n-gui.
+
+    When you use this API, CORE and SHELL API are also available.
 
     <li> MISC API
 
     It provides miscellaneous functions to support error handling and
 
     <li> MISC API
 
     It provides miscellaneous functions to support error handling and
-    debugging.  This API can't be used by itself, but with one or more
-    APIs listed above.  To use the API, an application program must
-    include <m17n-misc.h> in addition to one of <m17n-core.h>,
-    <m17n.h>, and <m17n-gui.h>.
+    debugging.  This API cannot be used by itself, but with one or
+    more APIs listed above.  To use the API, an application program
+    must include <m17n-misc<EM></EM>.h> in addition to one of a header
+    file described above.
 
     </ol>
 
 
     </ol>
 
     <li> @c M17NDIR
 
     Name of a directory that contains data of the m17n database.  See
     <li> @c M17NDIR
 
     Name of a directory that contains data of the m17n database.  See
-    @ref m17nDatabase for the detail.
+    @ref m17nDatabase for more details.
 
     <li> @c MDEBUG_XXXX
 
     Environment variables whose name start by "MDEBUG_" controls
 
     <li> @c MDEBUG_XXXX
 
     Environment variables whose name start by "MDEBUG_" controls
-    printing of debug information.  See @ref m17nDebug for the detail.
+    printing of debug information.  See @ref m17nDebug for more
+    details.
 
     </ul>
 
 
     </ul>
 
     <li> symbol variables -- Mname
 
     Variables of type MSymbol start with 'M' followed by their names
     <li> symbol variables -- Mname
 
     Variables of type MSymbol start with 'M' followed by their names
-    (e.g. Mlanguage (name is "langauge"), Miso_2022 (name is
+    (e.g. Mlanguage (name is "language"), Miso_2022 (name is
     "iso-2022").
 
     "iso-2022").
 
-    <li> macross -- MOBJECT_XXX
+    <li> macros -- MOBJECT_XXX
 
     They start by 'M' followed by upper case object names.
 
 
     They start by 'M' followed by upper case object names.
 
 
 /***ja
     @addtogroup m17nIntro
 
 /***ja
     @addtogroup m17nIntro
+    @brief m17n ¥é¥¤¥Ö¥é¥ê ¥¤¥ó¥È¥í¥À¥¯¥·¥ç¥ó.
+
+    @em API¤Î¥ì¥Ù¥ë
+
+    m17n ¥é¥¤¥Ö¥é¥ê¤Î API ¤Ï°Ê²¼¤Î£´¼ï¤ËʬÎव¤ì¤Æ¤¤¤ë¡£
+
+    <ol>
+    <li> ¥³¥¢ API
+
+    M-text ¤ò°·¤¦¤¿¤á¤Î´ðËÜŪ¤Ê¥â¥¸¥å¡¼¥ë¤òÄ󶡤¹¤ë¡£¤³¤ÎʬÎà¤Î API ¤Ï
+    m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤òɬÍפȤ·¤Ê¤¤¡£ÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï
+    <m17n-core<EM></EM>.h> ¤ò include ¤·¡¢ -lm17n-core ¤Ç¥ê¥ó¥¯¤µ¤ì¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    <li> ¥·¥§¥ë API
+
+    m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤òÍøÍѤ¹¤ë¥â¥¸¥å¡¼¥ë¡Ê¥³¡¼¥ÉÊÑ´¹¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£Åù¡Ë
+    ¤òÄ󶡤¹¤ë¡£¥â¥¸¥å¡¼¥ë¤Ï¥Ç¡¼¥¿¥Ù¡¼¥¹¤«¤éɬÍפ˱þ¤¸¤Æ¿Íͤʥǡ¼¥¿¤ò¥í¡¼¥É¤¹¤ë¡£
+    ÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï <m17n<EM></EM>.h> ¤ò include
+    ¤·¡¢ -lm17n-core -lm17n ¤Ç¥ê¥ó¥¯¤µ¤ì¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    ¤³¤Î API ¤ò»ÈÍѤ¹¤ëºÝ¤Ë¤Ï¥³¥¢ API ¤â»ÈÍѤǤ­¤ë¡£
+
+    <li> GUI API
+
+    M-text ¤ò¥°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¾å¤Çɽ¼¨¤·¤¿¤êÆþÎϤ·¤¿¤ê¤¹¤ë¤È¤¤¤Ã¤¿¡¢¥°¥é¥Õ¥£¥Ã¥¯¥æ¡¼¥¶¥¤¥ó¥¿¥Õ¥§¡¼¥¹¥â¥¸¥å¡¼¥ë¤òÄ󶡤¹¤ë¡£
+    API ¼«ÂΤϥ°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¤È¤ÏÆÈΩ¤Ç¤¢¤ë¤¬¡¢Â¿¤¯¤Î´Ø¿ô¤ÏÆÃÄê¤Î¥°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¾å¤ËºîÀ®¤µ¤ì¤¿ 
+    MFrame ¤ò°ú¿ô¤Ë¼è¤ë¡£¸½»þÅÀ¤Ç¤Ï¡¢¥Ì¥ë¥Ç¥Ð¥¤¥¹¡¢X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¡¢
+    GD ¥é¥¤¥Ö¥é¥ê¤Î¥¤¥á¡¼¥¸¡ÊgdImagePtr¡Ë¡¢¤¬¥°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¤È¤·¤Æ¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¡£
+
+    ¥Ì¥ë¥Ç¥Ð¥¤¥¹¾å¤Ç¤Ïɽ¼¨¤âÆþÎϤâ¤Ç¤­¤Ê¤¤¡Ê¤¿¤À¤·¤¿¤È¤¨¤Ð
+    mdraw_glyph_list () ¤Ê¤É¤Î´Ø¿ô¤Ï»ÈÍѲÄǽ¡Ë¡£
+
+    X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¾å¤Ç¤Ï¤¹¤Ù¤Æ¤Î GUI API ¤¬»ÈÍѤǤ­¤ë¡£
+
+    GD ¥é¥¤¥Ö¥é¥ê¤Î¥¤¥á¡¼¥¸¾å¤Ç¤Ï¡¢ÉÁ²èÍѤΠAPI ¤Ï¤¹¤Ù¤Æ»ÈÍѤǤ­¤ë¤¬ÆþÎϤϤǤ­¤Ê¤¤¡£
+
+    ¤³¤Î¥Ç¥Ð¥¤¥¹¤ò»ÈÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï
+    <m17n-gui<EM></EM>.h> ¤ò include ¤·¡¢-lm17n-core -lm17n -lm17n-gui
+    ¤Ç¥ê¥ó¥¯¤µ¤ì¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    ¤³¤Î API ¤ò»ÈÍѤ¹¤ëºÝ¤Ë¤Ï¡¢¥³¥¢ API ¤È¥·¥§¥ë API ¤â»ÈÍѤǤ­¤ë¡£
+
+    <li> ¤½¤Î¾¤Î API
 
 
-    @e m17n¥é¥¤¥Ö¥é¥ê ¤Ï C ¸À¸ìÍÑ¿¸À¸ì¾ðÊó½èÍý¥é¥¤¥Ö¥é¥ê¤Ç¤¢¤ë¡£
-    ¤³¤Î¥é¥¤¥Ö¥é¥ê¤Ï¡¢Â¿¸À¸ìʸ½ñ¤ò°·¤¦¤¿¤á¤ËɬÍפʰʲ¼¤Î´ðËܵ¡Ç½¤ò¥¢¥×
-    ¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤ËÄ󶡤¹¤ë¡£
+    ¥¨¥é¡¼½èÍý¡¢¥Ç¥Ð¥Ã¥°ÍѤΤ½¤Î¾¤Î´Ø¿ô¤òÄ󶡤¹¤ë¡£¤³¤Î 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_XXXX
+
+    "MDEBUG_" ¤Ç»Ï¤Þ¤ë̾Á°¤ò»ý¤Ä´Ä¶­ÊÑ¿ô¤Ï¥Ç¥Ð¥Ã¥°¾ðÊó¤òÀ©¸æ¤¹¤ë¡£¾ÜºÙ¤Ï @ref m17nDebug »²¾È¡£
+
+    </ul>
+
+    @em API @em ¤Î̿̾µ¬Â§ ¥³¥Þ¥ó¥É
+
+    ¥é¥¤¥Ö¥é¥ê¤Ï¡¢´Ø¿ô¡¢ÊÑ¿ô¡¢¥Þ¥¯¥í¡¢·¿¤ò export ¤¹¤ë¡£¤½¤ì¤é¤Ï'm' 
+    ¤Þ¤¿¤Ï 'M' ¤Î¤¢¤È¤Ë¥ª¥Ö¥¸¥§¥¯¥È̾("symbol" ¤ä "plist" ¤Ê¤É¡£¤¿¤À¤· 
+    "mtext" ¥ª¥Ö¥¸¥§¥¯¥È¤Ï¤Ï¤¸¤á¤Î 'm' ¤Î½ÅÊ£¤òÈò¤±¤ë¤¿¤á "text" 
+    ¤òÍѤ¤¤ë¡£) ¤Þ¤¿¤Ï¥â¥¸¥å¡¼¥ë̾(draw, input ¤Ê¤É) ¤ò³¤±¤¿¤â¤Î¤Ç¤¢¤ë¡£
+    
+    <ul>
+
+    <li> ´Ø¿ô -- mobject () ¤Þ¤¿¤Ï mobject_xxx ()
+
+    'm' ¤Î¤¢¤È¤Ë¾®Ê¸»ú¤Ç¥ª¥Ö¥¸¥§¥¯¥È̾¤¬Â³¤¯¡£¤¿¤È¤¨¤Ð¡¢msymbol (),
+     mtext_ref_char (), mdraw_text () ¤Ê¤É¡£
+
+    <li> ¥·¥ó¥Ü¥ë¤Ç¤Ê¤¤ÊÑ¿ô -- mobject,  ¤Þ¤¿¤Ï mobject_xxx
+    
+    ´Ø¿ô¤ÈƱ¤¸Ì¿Ì¾µ¬Â§¤Ë½¾¤¦¡£(¤¿¤È¤¨¤Ð  mface_large)
 
 
-    @li Â¿¸À¸ì¥Æ¥­¥¹¥ÈÍÑ¥ª¥Ö¥¸¥§¥¯¥È¤È¤·¤Æ¤Î¹½Â¤ÂΠ@e M-text
+    <li> ¥·¥ó¥Ü¥ëÊÑ¿ô -- Mname
 
 
-    @li M-text ¤ò°·¤¦¤¿¤á¤Î¿¤¯¤Î´Ø¿ô¡¦¥Þ¥¯¥í·²
+    MSymbol ·¿ÊÑ¿ô¤Ï¡¢'M' ¤Î¸å¤Ë̾Á°¤¬Â³¤¯¡£¤¿¤È¤¨¤Ð Mlanguage (̾Á°¤Ï 
+    "language"), Miso_2022 (̾Á°¤Ï"iso-2022")¤Ê¤É¡£
 
 
-    @li ¼ï¡¹¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Æ¥­¥¹¥È¤È M-text ´Ö¤ÎÊÑ´¹
-    ¤ò¹Ô¤Ê¤¦¥Ç¥³¡¼¥À¡¿¥¨¥ó¥³¡¼¥À
+    <li> ¥Þ¥¯¥í -- MOBJECT_XXX
 
 
-    @li Unicode ¤ÎÁ´¤Æ¤Îʸ»ú¤Ë²Ã¤¨¡¢¤½¤ì¤ÈƱ¤¸¿ô¤ÎÈó Unicode Ê¸»ú¤ò°·
-    ¤¨¤ëµðÂç¤Êʸ»ú¶õ´Ö
+    'M' ¤Î¸å¤ËÂçʸ»ú¤Ç¥ª¥Ö¥¸¥§¥¯¥È̾¤¬Â³¤¯¡£
 
 
-    @li Ê¸»úËè¤Î¾ðÊó¤ò¸úΨÎɤ¯³ÊǼ¤¹¤ë¹½Â¤ÂΠ@e Ê¸»ú¥Æ¡¼¥Ö¥ë (CharTable)
+    <li> ¥¿¥¤¥× -- MObject ¤Þ¤¿¤Ï MObjectXxx
 
 
-    @li ¥ª¥×¥·¥ç¥ó¡§M-text¤Î¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¾å¤Ç¤Îɽ¼¨¡¦ÆþÎÏ¥·¥¹¥Æ¥à¡£
-    ¡Ê¤³¤Î¤¿¤á¤Î API ¤Ï m17n-win.h ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë¡£¡Ë  */
+    'M' ¤Î¸å¤ËÂçʸ»ú¤Ç»Ï¤á¤Æ¥ª¥Ö¥¸¥§¥¯¥È̾¤ò¤¬Â³¤¯¡£ (¤¿¤È¤¨¤Ð
+    MConverter, MInputDriver)
+
+    </ul>
+    
+    */
 /*=*/
 /*** @{ */
 #ifdef FOR_DOXYGEN
 /***en
     The #M17NLIB_MAJOR_VERSION macro gives the major version number
     of the m17n library.  */
 /*=*/
 /*** @{ */
 #ifdef FOR_DOXYGEN
 /***en
     The #M17NLIB_MAJOR_VERSION macro gives the major version number
     of the m17n library.  */
-
 /***ja
 /***ja
-    ¥Þ¥¯¥í #M17NLIB_MAJOR_VERSION ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤Î¥á¥¸¥ã¡¼¥Ð¡¼¥¸¥ç
-    ¥óÈÖ¹æ¤òÍ¿¤¨¤ë¡£  */
+    ¥Þ¥¯¥í #M17NLIB_MAJOR_VERSION ¤Ï m17n 
+    ¥é¥¤¥Ö¥é¥ê¤Î¥á¥¸¥ã¡¼¥Ð¡¼¥¸¥ç¥óÈÖ¹æ¤òÍ¿¤¨¤ë¡£  */
 
 #define M17NLIB_MAJOR_VERSION
 
 
 #define M17NLIB_MAJOR_VERSION
 
     of the m17n library.  */
 
 /***ja
     of the m17n library.  */
 
 /***ja
-    ¥Þ¥¯¥í #M17NLIB_MINOR_VERSION ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤Î¥Þ¥¤¥Ê¡¼¥Ð¡¼¥¸¥ç
-    ¥óÈÖ¹æ¤òÍ¿¤¨¤ë¡£  */
+    ¥Þ¥¯¥í #M17NLIB_MINOR_VERSION ¤Ï m17n 
+    ¥é¥¤¥Ö¥é¥ê¤Î¥Þ¥¤¥Ê¡¼¥Ð¡¼¥¸¥ç¥óÈÖ¹æ¤òÍ¿¤¨¤ë¡£  */
 
 #define M17NLIB_MINOR_VERSION
 
 /*=*/
 
 /***en
 
 #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
     The #M17NLIB_VERSION_NAME macro gives the version name of the
     m17n library as a string.  */
 
 /***ja
-    ¥Þ¥¯¥í #M17NLIB_VERSION_NAME ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤Î¥Ð¡¼¥¸¥ç¥ó̾¤ò
-    C-string ¤Î·Á¤ÇÍ¿¤¨¤ë¡£  */
+    ¥Þ¥¯¥í #M17NLIB_VERSION_NAME ¤Ï m17n 
+    ¥é¥¤¥Ö¥é¥ê¤Î¥Ð¡¼¥¸¥ç¥ó̾¤òʸ»úÎó¤È¤·¤ÆÍ¿¤¨¤ë¡£  */
 
 #define M17NLIB_VERSION_NAME
 
 
 #define M17NLIB_VERSION_NAME
 
 /***en
     @brief Initialize the m17n library.
 
 /***en
     @brief Initialize the m17n library.
 
-    The macro M17N_INIT () initializes the m17n library.  This
-    function must be called before any m17n functions are used.
+    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.
 
 
-    If the initialization was successful, the external variable @c
-    merror_code is set to 0.  Otherwise it is set to -1.  */
+    @seealso
+    M17N_FINI (), m17n_status ()  */
 
 /***ja
 
 /***ja
-    @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î½é´ü²½
+    @brief m17n ¥é¥¤¥Ö¥é¥ê¤ò½é´ü²½¤¹¤ë.
 
 
-    ¥Þ¥¯¥í M17N_INIT () ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤ò½é´ü²½¤¹¤ë¡£m17n ¥é¥¤¥Ö¥é
-    ¥ê¤ò»È¤¦¤È¤­¤Ï¡¢ºÇ½é¤Ë¤³¤Î´Ø¿ô¤ò¸Æ¤Ð¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+    ¥Þ¥¯¥í M17N_INIT () ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤ò½é´ü²½¤¹¤ë¡£m17n 
+    ¤Î´Ø¿ô¤òÍøÍѤ¹¤ëÁ°¤Ë¡¢¤³¤Î¥Þ¥¯¥í¤ò¤Þ¤º¸Æ¤Ð¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+    
+    ¤³¤Î¥Þ¥¯¥í¤òÊ£¿ô²ó¸Æ¤ó¤Ç¤â°ÂÁ´¤Ç¤¢¤ë¤¬¡¢¤½¤Î¾ì¹ç¥á¥â¥ê¤ò²òÊü¤¹¤ë¤¿¤á¤Ë¥Þ¥¯¥í
+    M17N_FINI () ¤òƱ¤¸²ó¿ô¸Æ¤ÖɬÍפ¬¤¢¤ë¡£
+
+    ³°ÉôÊÑ¿ô #merror_code ¤Ï¡¢½é´ü²½¤¬À®¸ù¤¹¤ì¤Ð 0 ¤Ë¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð 
+    -1 ¤ËÀßÄꤵ¤ì¤ë¡£  
 
 
-    ÊÑ¿ô #merror_code ¤Ï¡¢½é´ü²½¤¬À®¸ù¤¹¤ì¤Ð 0 ¤Ë¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 
-    ¤ËÀßÄꤵ¤ì¤ë¡£  */
+    @seealso
+    M17N_FINI (), m17n_status ()  */
 
 #define M17N_INIT()
 
 
 #define M17N_INIT()
 
     @brief Finalize the m17n library.
 
     The macro M17N_FINI () finalizes the m17n library.  It frees all the
     @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 function is
+    memory area used by the m17n library.  Once this macro is
     called, no m17n functions should be used until the
     called, no m17n functions should be used until the
-    macro M17N_INIT () is called again.  */
+    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
 /***ja
-    @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î½ªÎ»  */
+    @brief m17n ¥é¥¤¥Ö¥é¥ê¤ò½ªÎ»¤¹¤ë. 
+
+    ¥Þ¥¯¥í M17N_FINI () ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤ò½ªÎ»¤¹¤ë¡£m17n 
+    ¥é¥¤¥Ö¥é¥ê¤¬»È¤Ã¤¿Á´¤Æ¤Î¥á¥â¥êÎΰè¤Ï²òÊü¤µ¤ì¤ë¡£°ìÅÙ¤³¤Î¥Þ¥¯¥í¤¬¸Æ¤Ð¤ì¤¿¤é¡¢¥Þ¥¯¥í
+    M17N_INIT () ¤¬ºÆÅٸƤФì¤ë¤Þ¤Ç m17n ´Ø¿ô¤Ï»È¤¦¤Ù¤­¤Ç¤Ê¤¤¡£
+
+    ¥Þ¥¯¥í M17N_INIT () ¤¬ N ²ó¸Æ¤Ð¤ì¤Æ¤¤¤¿¾ì¹ç¤Ë¤Ï¡¢¤³¤Î¥Þ¥¯¥í¤¬ N 
+    ²ó¸Æ¤Ð¤ì¤Æ½é¤á¤Æ¥á¥â¥ê¤¬²òÊü¤µ¤ì¤ë¡£
+
+    @seealso
+    M17N_INIT (), m17n_status ()  */
 
 #define M17N_FINI()
 #endif /* FOR_DOXYGEN */
 
 #define M17N_FINI()
 #endif /* FOR_DOXYGEN */
 #include "m17n-core.h"
 #include "m17n-misc.h"
 #include "internal.h"
 #include "m17n-core.h"
 #include "m17n-misc.h"
 #include "internal.h"
-
-static int core_initialized;
+#include "symbol.h"
 
 static void
 default_error_handler (enum MErrorCode err)
 
 static void
 default_error_handler (enum MErrorCode err)
@@ -244,29 +384,37 @@ default_error_handler (enum MErrorCode err)
 static struct timeval time_stack[16];
 static int time_stack_index;
 
 static struct timeval time_stack[16];
 static int time_stack_index;
 
-static int report_header_printed;
-
-\f
-/* Internal API */
+static M17NObjectArray *object_array_root;
 
 
-void
-mdebug__report_object (char *name, M17NObjectArray *array)
+static void
+report_object_array ()
 {
 {
-  if (! (mdebug__flag & MDEBUG_FINI))
-    return;
-  if (! report_header_printed)
+  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)
     {
     {
-      fprintf (stderr, "%16s %7s %7s %7s\n",
-              "object", "created", "freed", "alive");
-      fprintf (stderr, "%16s %7s %7s %7s\n",
-              "------", "-------", "-----", "-----");
-      report_header_printed = 1;
+      M17NObjectArray *array = object_array_root;
+
+      fprintf (stderr, "%16s %7d %7d %7d\n", array->name,
+              array->used, array->used - array->count, array->count);
+      if (array->used > 0)
+       {
+         free (array->objects);
+         array->count = array->used = 0;
+       }
     }
     }
-  fprintf (stderr, "%16s %7d %7d %7d\n", name,
-          array->used, array->used - array->count, array->count);
 }
 
 
 }
 
 
+\f
+/* Internal API */
+
+int m17n__core_initialized;
+int m17n__shell_initialized;
+int m17n__gui_initialized;
+
 void *(*mdatabase__finder) (MSymbol tag1, MSymbol tag2,
                           MSymbol tag3, MSymbol tag4);
 void *(*mdatabase__loader) (void *);
 void *(*mdatabase__finder) (MSymbol tag1, MSymbol tag2,
                           MSymbol tag3, MSymbol tag4);
 void *(*mdatabase__loader) (void *);
@@ -310,6 +458,43 @@ mdebug__print_time ()
   } while (0)
 
 
   } while (0)
 
 
+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 = 0;
+
+      while (i < array->used && array->objects[i] != object) i++;
+      if (i < array->used)
+       array->objects[i] = NULL;
+      else
+       mdebug_hook ();
+    }
+  else                                                                 \
+    mdebug_hook ();
+}
+
 \f
 /* External API */
 
 \f
 /* External API */
 
@@ -321,10 +506,10 @@ m17n_init_core (void)
 {
   int mdebug_mask = MDEBUG_INIT;
 
 {
   int mdebug_mask = MDEBUG_INIT;
 
-  if (core_initialized)
+  merror_code = MERROR_NONE;
+  if (m17n__core_initialized++)
     return;
 
     return;
 
-  merror_code = 0;
   m17n_memory_full_handler = default_error_handler;
 
   mdebug__flag = 0;
   m17n_memory_full_handler = default_error_handler;
 
   mdebug__flag = 0;
@@ -346,25 +531,22 @@ m17n_init_core (void)
   if  (mplist__init () < 0)
     goto err;
   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize plist module."));
   if  (mplist__init () < 0)
     goto err;
   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize plist module."));
+  if  (mchartable__init () < 0)
+    goto err;
+  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize chartable module."));
   if (mtext__init () < 0)
     goto err;
   if (mtext__prop_init () < 0)
     goto err;
   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize mtext module."));
   if (mtext__init () < 0)
     goto err;
   if (mtext__prop_init () < 0)
     goto err;
   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize mtext module."));
-  if  (mchartable__init () < 0)
-    goto err;
-  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize chartable module."));
 
   mdatabase__finder = NULL;
   mdatabase__loader = NULL;
 
   mdatabase__finder = NULL;
   mdatabase__loader = NULL;
-  core_initialized = 1;
 
  err:
   MDEBUG_POP_TIME ();
   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the core modules."));
   MDEBUG_POP_TIME ();
 
  err:
   MDEBUG_POP_TIME ();
   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the core modules."));
   MDEBUG_POP_TIME ();
-
-  report_header_printed = 0;
 }
 
 void
 }
 
 void
@@ -372,31 +554,69 @@ m17n_fini_core (void)
 {
   int mdebug_mask = MDEBUG_FINI;
 
 {
   int mdebug_mask = MDEBUG_FINI;
 
-  if (core_initialized)
-    {
-      MDEBUG_PUSH_TIME ();
-      MDEBUG_PUSH_TIME ();
-      MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize chartable module."));
-      mchartable__fini ();
-      MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize textprop module."));
-      mtext__prop_fini ();
-      MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize mtext module."));
-      mtext__fini ();
-      MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize symbol module."));
-      msymbol__fini ();
-      MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize plist module."));
-      mplist__fini ();
-      core_initialized = 0;
-      MDEBUG_POP_TIME ();
-      MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize the core modules."));
-      MDEBUG_POP_TIME ();
-    }
+  if (m17n__core_initialized == 0
+      || --m17n__core_initialized > 0)
+    return;
+
+  MDEBUG_PUSH_TIME ();
+  MDEBUG_PUSH_TIME ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize chartable module."));
+  mchartable__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize textprop module."));
+  mtext__prop_fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize mtext module."));
+  mtext__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize symbol module."));
+  msymbol__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize plist module."));
+  mplist__fini ();
+  MDEBUG_POP_TIME ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the core modules."));
+  MDEBUG_POP_TIME ();
+  if (mdebug__flag & MDEBUG_FINI)
+    report_object_array ();
+  msymbol__free_table ();
 }
 
 /*** @} */
 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
 /*=*/
 
 }
 
 /*** @} */
 #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.
 /***en
     @addtogroup m17nObject
     @brief Managed objects are objects managed by the reference count.
@@ -416,7 +636,22 @@ m17n_fini_core (void)
 
     In addition to the predefined managed object types, users can
     define their own managed object types.  See the documentation of
 
     In addition to the predefined managed object types, users can
     define their own managed object types.  See the documentation of
-    the m17n_object () for the details.  */
+    the m17n_object () for more details.  */
+/***ja
+    @addtogroup m17nObject
+    @brief ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤È¤Ï»²¾È¿ô¤Ë¤è¤Ã¤Æ´ÉÍý¤µ¤ì¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë.
+
+    m17n ¥ª¥Ö¥¸¥§¥¯¥È¤Î¤¢¤ë·¿¤Î¤â¤Î¤Ï¡¢»²¾È¿ô¤Ë¤è¤Ã¤Æ´ÉÍý¤µ¤ì¤Æ¤¤¤ë¡£
+    ¤½¤ì¤é¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ï @e ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È ¤È¸Æ¤Ð¤ì¤ë¡£À¸À®¤µ¤ì¤¿»þÅÀ¤Ç¤Î»²¾È¿ô¤Ï
+    0 ¤Ë½é´ü²½¤µ¤ì¤Æ¤¤¤ë¡£´Ø¿ô m17n_object_ref () ¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Î»²¾È¿ô¤ò
+    1 Áý¤ä¤·¡¢´Ø¿ôm17n_object_unref () ¤Ï 1 ¸º¤é¤¹¡£»²¾È¿ô¤¬
+    0 ¤Ë¤Ê¤Ã¤¿´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ï¼«Æ°Åª¤Ë²òÊü¤µ¤ì¤ë¡£
+
+    ¥­¡¼¤¬´ÉÍý¥­¡¼¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤Ï¡¢ÃͤȤ·¤Æ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤À¤±¤ò¼è¤ë¡£
+    ´Ø¿ô msymbol_put () ¤ä mplist_put () ¤Ê¤É¤Ï¤½¤ì¤é¤Î¥×¥í¥Ñ¥Æ¥£¤òÆÃÊÌ°·¤¤¤¹¤ë¡£
+
+    ÄêµÁºÑ¤ß´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¥¿¥¤¥×¤Î¾¤Ë¡¢¥æ¡¼¥¶¤ÏɬÍפʴÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¥¿¥¤¥×¤ò¼«Ê¬¤ÇÄêµÁ¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£¾ÜºÙ¤Ï
+    m17n_object () ¤ÎÀâÌÀ¤ò»²¾È¡£  */
 
 /*** @{  */
 /*=*/
 
 /*** @{  */
 /*=*/
@@ -439,6 +674,23 @@ m17n_fini_core (void)
     @errors
     This function never fails.  */
 
     @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
 {
 #if EXAMPLE_CODE
 typedef struct
 {
@@ -474,6 +726,8 @@ m17n_object (int size, void (*freer) (void *))
   M17NObject *obj = malloc (size);
 
   obj->ref_count = 1;
   M17NObject *obj = malloc (size);
 
   obj->ref_count = 1;
+  obj->ref_count_extended = 0;
+  obj->flag = 0;
   obj->u.freer = freer;
   return obj;
 }
   obj->u.freer = freer;
   return obj;
 }
@@ -493,6 +747,18 @@ m17n_object (int size, void (*freer) (void *))
 
     @errors
     This function never fails.  */
 
     @errors
     This function never fails.  */
+/***ja
+    @brief ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Î»²¾È¿ô¤ò 1 Áý¤ä¤¹.
+
+    ´Ø¿ô m17n_object_ref () ¤Ï $OBJECT 
+    ¤Ç»Ø¤µ¤ì¤ë´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Î»²¾È¿ô¤ò 1 Áý¤ä¤¹¡£
+
+    @return 
+    ¤³¤Î´Ø¿ô¤Ï¡¢Áý¤ä¤·¤¿»²¾È¿ô¤¬ 16 ¥Ó¥Ã¥È¤ÎÉä¹æ̵¤·À°¿ôÃÍ(¤¹¤Ê¤ï¤Á 
+    0x10000 Ì¤Ëþ)¤Ë¤ª¤µ¤Þ¤ì¤Ð¡¢¤½¤ì¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤¹¡£
+
+    @errors
+    ¤³¤Î´Ø¿ô¤Ï¼ºÇÔ¤·¤Ê¤¤¡£    */
 
 int
 m17n_object_ref (void *object)
 
 int
 m17n_object_ref (void *object)
@@ -541,7 +807,19 @@ m17n_object_ref (void *object)
 
     @errors
     This function never fails.  */
 
     @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)
 {
 int
 m17n_object_unref (void *object)
 {
@@ -591,37 +869,39 @@ m17n_object_unref (void *object)
 
     The first type is argument errors.  When a library function is
     called with invalid arguments, it returns a value that indicates
 
     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 @e
-    merror_code to a non-zero integer.
+    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
 
     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
-    exit ().  */
+    <tt> exit ()</tt>.  */
 
 /***ja
     @addtogroup m17nError ¥¨¥é¡¼½èÍý
 
 /***ja
     @addtogroup m17nError ¥¨¥é¡¼½èÍý
-    @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼½èÍý
+    @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼½èÍý.
 
     m17n ¥é¥¤¥Ö¥é¥ê¤Î´Ø¿ô¤Ç¤Ï¡¢£²¤Ä¤Î¼ïÎà¤Î¥¨¥é¡¼¤¬µ¯¤³¤êÆÀ¤ë¡£
 
 
     m17n ¥é¥¤¥Ö¥é¥ê¤Î´Ø¿ô¤Ç¤Ï¡¢£²¤Ä¤Î¼ïÎà¤Î¥¨¥é¡¼¤¬µ¯¤³¤êÆÀ¤ë¡£
 
-    °ì¤Ä¤Ï°ú¿ô¤Î¥¨¥é¡¼¤Ç¤¢¤ë¡£¥é¥¤¥Ö¥é¥ê¤Î´Ø¿ô¤¬ÂÅÅö¤Ç¤Ê¤¤°ú¿ô¤È¤È¤â¤Ë
-    ¸Æ¤Ð¤ì¤¿¾ì¹ç¡¢¤½¤Î´Ø¿ô¤Ï¥¨¥é¡¼¤ò°ÕÌ£¤¹¤ëÃͤòÊÖ¤·¡¢Æ±»þ¤Ë³°ÉôÊÑ¿ô 
+    °ì¤Ä¤Ï°ú¿ô¤Î¥¨¥é¡¼¤Ç¤¢¤ë¡£
+    ¥é¥¤¥Ö¥é¥ê¤Î´Ø¿ô¤¬ÂÅÅö¤Ç¤Ê¤¤°ú¿ô¤È¤È¤â¤Ë¸Æ¤Ð¤ì¤¿¾ì¹ç¡¢¤½¤Î´Ø¿ô¤Ï¥¨¥é¡¼¤ò°ÕÌ£¤¹¤ëÃͤòÊÖ¤·¡¢Æ±»þ¤Ë³°ÉôÊÑ¿ô 
     #merror_code ¤Ë¥¼¥í¤Ç¤Ê¤¤À°¿ô¤ò¥»¥Ã¥È¤¹¤ë¡£
 
     #merror_code ¤Ë¥¼¥í¤Ç¤Ê¤¤À°¿ô¤ò¥»¥Ã¥È¤¹¤ë¡£
 
-    ¤â¤¦°ì¤Ä¤Î¼ïÎà¤Ï¥á¥â¥ê³äÅö¤Æ¥¨¥é¡¼¤Ç¤¢¤ë¡£¥·¥¹¥Æ¥à¤¬É¬ÍפÊÎ̤Υá¥â
-    ¥ê¤ò³äÅö¤Æ¤ë¤³¤È¤¬¤Ç¤­¤Ê¤¤¾ì¹ç¡¢¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ï³°ÉôÊÑ¿ô @c
-    m17n_memory_full_handler ¤¬»Ø¤¹´Ø¿ô¤ò¸Æ¤Ö¡£¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢Ã±¤Ë
-    <tt>exit ()</tt> ¤ò¸Æ¤Ö¤³¤È¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
+    ¤â¤¦°ì¤Ä¤Î¼ïÎà¤Ï¥á¥â¥ê³äÅö¤Æ¥¨¥é¡¼¤Ç¤¢¤ë¡£
+    ¥·¥¹¥Æ¥à¤¬É¬ÍפÊÎ̤Υá¥â¥ê¤ò³äÅö¤Æ¤ë¤³¤È¤¬¤Ç¤­¤Ê¤¤¾ì¹ç¡¢¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ï³°ÉôÊÑ¿ô 
+    @c m17n_memory_full_handler ¤¬»Ø¤¹´Ø¿ô¤ò¸Æ¤Ö¡£¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢´Ø¿ô 
+    default_error_handle () ¤ò»Ø¤·¤Æ¤ª¤ê¡¢¤³¤Î´Ø¿ô¤Ïñ¤Ë <tt>exit
+    ()</tt> ¤ò¸Æ¤Ö¡£
 */
 
 /*** @{ */
 
 /*=*/
 
 */
 
 /*** @{ */
 
 /*=*/
 
-/***en @brief External variable to hold error code of the m17n library
+/***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
 
     The external variable #merror_code holds an error code of the
     m17n library.  When a library function is called with an invalid
@@ -629,19 +909,21 @@ m17n_object_unref (void *object)
 
     This variable initially has the value 0.  */
 
 
     This variable initially has the value 0.  */
 
-/***ja @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼¥³¡¼¥É¤òÊÝ»ý¤¹¤ë³°ÉôÊÑ¿ô
+/***ja 
+    @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼¥³¡¼¥É¤òÊÝ»ý¤¹¤ë³°ÉôÊÑ¿ô.
 
     ³°ÉôÊÑ¿ô #merror_code ¤Ï¡¢m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼¥³¡¼¥É¤òÊÝ»ý¤¹¤ë¡£
 
     ³°ÉôÊÑ¿ô #merror_code ¤Ï¡¢m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼¥³¡¼¥É¤òÊÝ»ý¤¹¤ë¡£
-    ¥é¥¤¥Ö¥é¥ê´Ø¿ô¤¬ÂÅÅö¤Ç¤Ê¤¤°ú¿ô¤È¤È¤â¤Ë¸Æ¤Ð¤ì¤¿ºÝ¤Ë¤Ï¡¢
-    ¤³¤ÎÊÑ¿ô¤ò @c enum #MErrorCode ¤Î°ì¤Ä¤Ë¥»¥Ã¥È¤¹¤ë¡£
+    ¥é¥¤¥Ö¥é¥ê´Ø¿ô¤¬ÂÅÅö¤Ç¤Ê¤¤°ú¿ô¤È¤È¤â¤Ë¸Æ¤Ð¤ì¤¿ºÝ¤Ë¤Ï¡¢¤³¤ÎÊÑ¿ô¤ò 
+    @c enum #MErrorCode ¤Î°ì¤Ä¤Ë¥»¥Ã¥È¤¹¤ë¡£
 
 
-    ¤³¤ÎÊÑ¿ô¤Î½é´üÃͤϣ°¤Ç¤¢¤ë¡£  */
+    ¤³¤ÎÊÑ¿ô¤Î½é´üÃͤϠ0 ¤Ç¤¢¤ë¡£  */
 
 
-enum MErrorCode merror_code;
+int merror_code;
 
 /*=*/
 
 
 /*=*/
 
-/***en @brief Memory allocation error handler
+/***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
 
     The external variable #m17n_memory_full_handler holds a pointer
     to the function to call when a library function failed to allocate
@@ -649,25 +931,25 @@ enum MErrorCode merror_code;
     function the error occurred.
 
     This variable initially points a function that simply calls the
     function the error occurred.
 
     This variable initially points a function that simply calls the
-    exit () function with $ERR as an argument.
+    <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.  */
 
 
     An application program that needs a different error handling can
     change this variable to point a proper function.  */
 
-/***ja @brief ¥á¥â¥ê³äÅö¤Æ¥¨¥é¡¼¥Ï¥ó¥É¥é
+/***ja 
+    @brief ¥á¥â¥ê³äÅö¤Æ¥¨¥é¡¼¥Ï¥ó¥É¥é.
 
 
-    ÊÑ¿ô #m17n_memory_full_handler ¤Ï¡¢¥é¥¤¥Ö¥é¥ê´Ø¿ô¤¬¥á¥â¥ê³äÅö¤Æ
-    ¤Ë¼ºÇÔ¤·¤¿ºÝ¤Ë¸Æ¤Ö¤Ù¤­´Ø¿ô¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£$ERR ¤Ï @c enum
-    #MErrorCode ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ê¡¢¤É¤Î¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ç¥¨¥é¡¼¤¬µ¯¤Ã¤¿
-    ¤«¤ò¼¨¤¹¡£
+    ÊÑ¿ô #m17n_memory_full_handler 
+    ¤Ï¡¢¥é¥¤¥Ö¥é¥ê´Ø¿ô¤¬¥á¥â¥ê³äÅö¤Æ¤Ë¼ºÇÔ¤·¤¿ºÝ¤Ë¸Æ¤Ö¤Ù¤­´Ø¿ô¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
+    $ERR ¤Ï @c enum #MErrorCode 
+    ¤Î¤¦¤Á¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ê¡¢¤É¤Î¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ç¥¨¥é¡¼¤¬µ¯¤Ã¤¿¤«¤ò¼¨¤¹¡£
 
     @anchor test
 
 
     @anchor test
 
-    ½é´üÀßÄê¤Ç¤Ï¡¢¤³¤ÎÊÑ¿ô¤Ïñ¤Ë <tt>exit ()</tt> ¤ò $ERR ¤ò°ú¿ô¤È¤·¤Æ
-    ¸Æ¤Ö´Ø¿ô¤ò»Ø¤·¤Æ¤¤¤ë¡£
+    ½é´üÀßÄê¤Ç¤Ï¡¢¤³¤ÎÊÑ¿ô¤Ïñ¤Ë <tt>exit ()</tt> ¤ò $ERR 
+    ¤ò°ú¿ô¤È¤·¤Æ¸Æ¤Ö´Ø¿ô¤ò»Ø¤·¤Æ¤¤¤ë¡£
 
 
-    ¤³¤ì¤È¤Ï°Û¤Ê¤ë¥¨¥é¡¼½èÍý¤òɬÍפȤ¹¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¡¢¤³¤ÎÊÑ¿ô¤ò
-    Å¬Åö¤Ê´Ø¿ô¤ËÀßÄꤹ¤ë¤³¤È¤Ç¡¢ÌÜŪ¤òãÀ®¤Ç¤­¤ë¡£  */
+    ¤³¤ì¤È¤Ï°Û¤Ê¤ë¥¨¥é¡¼½èÍý¤òɬÍפȤ¹¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¡¢¤³¤ÎÊÑ¿ô¤òŬÅö¤Ê´Ø¿ô¤ËÀßÄꤹ¤ë¤³¤È¤Ç¡¢ÌÜŪ¤òãÀ®¤Ç¤­¤ë¡£  */
 
 void (*m17n_memory_full_handler) (enum MErrorCode err);
 
 
 void (*m17n_memory_full_handler) (enum MErrorCode err);
 
@@ -729,6 +1011,55 @@ void (*m17n_memory_full_handler) (enum MErrorCode err);
 
     </ul>
 */
 
     </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_FONT_FLT -- 1 ¤Ê¤é¤Ð¡¢Font Layout Table 
+    ¤Î¤É¤Î¥³¥Þ¥ó¥É¤¬¼Â¹ÔÃ椫¤Ë¤Ä¤¤¤Æ¤Î¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
+
+    <li> MDEBUG_FONT_OTF -- 1 ¤Ê¤é¤Ð¡¢OpenType Layout Table 
+    ¤Î¤É¤Î°À­¤¬¼Â¹ÔÃ椫¤Ë¤Ä¤¤¤Æ¤Î¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
+
+    <li> MDEBUG_INPUT -- 1 ¤Ê¤é¤Ð¡¢¼Â¹ÔÃæ¤ÎÆþÎϥ᥽¥Ã¥É¤Î¾õÂÖ¤ËÉÕ¤¤¤Æ¤Î¾ðÊó¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
+
+    <li> MDEBUG_ALL -- 1 ¤Ê¤é¤Ð¡¢¾åµ­¤¹¤Ù¤Æ¤ÎÊÑ¿ô¤ò 1 
+    ¤Ë¤·¤¿¤Î¤ÈƱ¤¸¸ú²Ì¤ò»ý¤Ä¡£
+
+    </ul>
+
+    <li> ¼ï¡¹¤Î¥ª¥Ö¥¸¥§¥¯¥È¤ò¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç¥×¥ê¥ó¥È¤¹¤ë´Ø¿ô¡£¾ÜºÙ¤Ï´Ø¿ô
+    mdebug_dump_XXXX () ¤ÎÀâÌÀ»²¾È¡£
+
+    <li> ¥¨¥é¡¼È¯À¸»þ¤Ë¸Æ¤Ð¤ì¤ë¥Õ¥Ã¥¯´Ø¿ô¡£mdebug_hook () ¤ÎÀâÌÀ»²¾È¡£
+
+    </ul>
+*/
 
 /*=*/
 /*** @{ */
 
 /*=*/
 /*** @{ */
@@ -738,8 +1069,14 @@ void (*m17n_memory_full_handler) (enum MErrorCode err);
     @brief Hook function called on an error.
 
     The mdebug_hook () function is called when an error happens.  It
     @brief Hook function called on an error.
 
     The mdebug_hook () function is called when an error happens.  It
-    returns -1q without doing anything.  It is useful to set a break
+    returns -1 without doing anything.  It is useful to set a break
     point on this function in a debugger.  */ 
     point on this function in a debugger.  */ 
+/***ja
+    @brief ¥¨¥é¡¼¤ÎºÝ¤Ë¸Æ¤Ð¤ì¤ë¥Õ¥Ã¥¯´Ø¿ô.
+
+    ´Ø¿ô mdebug_hook () ¤Ï¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿ºÝ¤Ë¸Æ¤Ð¤ì¡¢²¿¤â¤»¤º¤Ë-1 
+    ¤òÊÖ¤¹¡£¥Ç¥Ð¥Ã¥¬Æâ¤Ç¥Ö¥ì¡¼¥¯¥Ý¥¤¥ó¥È¤òÀßÄꤹ¤ë¤¿¤á¤ËÍѤ¤¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
+    */ 
 
 int
 mdebug_hook ()
 
 int
 mdebug_hook ()