*** empty log message ***
[m17n/m17n-lib.git] / src / m17n-core.c
index c22da2e..efccca6 100644 (file)
 
     <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.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
-    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 funciton 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.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
-    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.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.h> in addition to one of a header file
+    described above.
 
     </ol>
 
     <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
-    printing of debug information.  See @ref m17nDebug for the detail.
+    printing of debug information.  See @ref m17nDebug for more
+    details.
 
     </ul>
 
 
     <li> ¥·¥§¥ë API
 
-    m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤òÍøÍѤ¹¤ë¥â¥¸¥å¡¼¥ë¤òÄ󶡤¹¤ë¡£¥â¥¸¥å¡¼¥ë¤Ï¥Ç¡¼
-    ¥¿¥Ù¡¼¥¹¤«¤éɬÍפ˱þ¤¸¤Æ¿Íͤʥǡ¼¥¿¤ò¥í¡¼¥É¤¹¤ë¡£ÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢
-    ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï <m17n.h> ¤ò include ¤·¡¢ -lm17n-core
-    -lm17n ¤Ç¥ê¥ó¥¯¤µ¤ì¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤³¤¦¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¥³¥¢ API 
-    ¤â»ÈÍѤǤ­¤ë¡£
+    m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤òÍøÍѤ¹¤ë¥â¥¸¥å¡¼¥ë¡Ê¥³¡¼¥ÉÊÑ´¹¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£
+    Åù¡Ë¤òÄ󶡤¹¤ë¡£¥â¥¸¥å¡¼¥ë¤Ï¥Ç¡¼¥¿¥Ù¡¼¥¹¤«¤éɬÍפ˱þ¤¸¤Æ¿Íͤʥǡ¼
+    ¥¿¤ò¥í¡¼¥É¤¹¤ë¡£ÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï
+    <m17n.h> ¤ò include ¤·¡¢ -lm17n-core -lm17n ¤Ç¥ê¥ó¥¯¤µ¤ì¤Ê¤¯¤Æ¤Ï¤Ê
+    ¤é¤Ê¤¤¡£
+
+    ¤³¤Î API ¤ò»ÈÍѤ¹¤ëºÝ¤Ë¤Ï¥³¥¢ API ¤â»ÈÍѤǤ­¤ë¡£
 
     <li> GUI API
 
-    M-texts ¤ò¥¦¥£¥ó¥É¥¦¾å¤Çɽ¼¨¤·¤¿¤êÆþÎϤ·¤¿¤ê¤¹¤ë¤È¤¤¤Ã¤¿¡¢¥°¥é¥Õ¥£¥Ã
-    ¥¯¥æ¡¼¥¶¥¤¥ó¥¿¥Õ¥§¡¼¥¹¥â¥¸¥å¡¼¥ë¤òÄ󶡤¹¤ë¡£API ¼«ÂΤϥ¦¥£¥ó¥É¥¦¥·
-    ¥¹¥Æ¥à¤È¤ÏÆÈΩ¤Ç¤¢¤ë¤¬¡¢ m17n ¥é¥¤¥Ö¥é¥ê¤ÏÆÃÄê¤Î¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à
-    ¤ò»ÈÍѤ¹¤ë¤è¤¦¤ËÀßÄꤷ¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¸½»þÅÀ¤Ç¤Ï¡¢X ¥¦¥£¥ó¥É¥¦¥·
-    ¥¹¥Æ¥à¤À¤±¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¡£ÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×
-    ¥í¥°¥é¥à¤Ï<m17n-gui.h> ¤È <m17n-X.h> ¤ò include ¤·¡¢-lm17n-core
-    -lm17n -lm17n-X ¤Ç¥ê¥ó¥¯¤µ¤ì¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£ ¤³¤¦¤¹¤ë¤³¤È¤Ë¤è¤Ã
-    ¤Æ¥³¥¢ API ¤È¥·¥§¥ë API ¤â»ÈÍѤǤ­¤ë¡£
+    M-texts ¤ò¥°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¾å¤Çɽ¼¨¤·¤¿¤êÆþÎϤ·¤¿¤ê¤¹¤ë¤È¤¤¤Ã¤¿¡¢
+    ¥°¥é¥Õ¥£¥Ã¥¯¥æ¡¼¥¶¥¤¥ó¥¿¥Õ¥§¡¼¥¹¥â¥¸¥å¡¼¥ë¤òÄ󶡤¹¤ë¡£API ¼«ÂΤϥ°
+    ¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¤È¤ÏÆÈΩ¤Ç¤¢¤ë¤¬¡¢Â¿¤¯¤Î´Ø¿ô¤ÏÆÃÄê¤Î¥°¥é¥Õ¥£¥Ã¥¯
+    ¥Ç¥Ð¥¤¥¹¾å¤ËºîÀ®¤µ¤ì¤¿ MFrame ¤ò°ú¿ô¤Ë¼è¤ë¡£¸½»þÅÀ¤Ç¤Ï¡¢¥Ì¥ë¥Ç¥Ð¥¤
+    ¥¹¡¢X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¡¢GD ¥é¥¤¥Ö¥é¥ê¤Î¥¤¥á¡¼¥¸¡ÊgdImagePtr¡Ë¡¢¤¬
+    ¥°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¤È¤·¤Æ¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¡£
+
+    ¥Ì¥ë¥Ç¥Ð¥¤¥¹¾å¤Ç¤Ïɽ¼¨¤âÆþÎϤâ¤Ç¤­¤Ê¤¤¡Ê¤¿¤À¤·¤¿¤È¤¨¤Ð
+    mdraw_glyph_list () ¤Ê¤É¤Î´Ø¿ô¤Ï»ÈÍѲÄǽ¡Ë¡£
+
+    X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¾å¤Ç¤Ï¤¹¤Ù¤Æ¤Î GUI API ¤¬»È¤¨¤ë¡£
+
+    GD ¥é¥¤¥Ö¥é¥ê¤Î¥¤¥á¡¼¥¸¾å¤Ç¤Ï¡¢ÉÁ²èÍѤΠAPI ¤Ï¤¹¤Ù¤Æ»È¤¨¤ë¤¬ÆþÎϤÏ
+    ¤Ç¤­¤Ê¤¤¡£
+
+    ¤³¤Î¥Ç¥Ð¥¤¥¹¤ò»ÈÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï
+    <m17n-gui.h> ¤ò include ¤·¡¢-lm17n-core -lm17n -lm17n-gui ¤Ç¥ê¥ó¥¯
+    ¤µ¤ì¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    ¤³¤Î API ¤ò»ÈÍѤ¹¤ëºÝ¤Ë¤Ï¡¢¥³¥¢ API ¤È¥·¥§¥ë API ¤â»ÈÍѤǤ­¤ë¡£
 
     <li> ¤½¤Î¾¤Î API
 
-    ¥¨¥é¡¼½èÍý¡¢¥Ç¥Ð¥Ã¥°ÍѤΤ½¤Î¾¤Î´Ø¿ô¤òÄ󶡤¹¤ë¡£¤³¤Î API ¤Ï¤½¤ì¤À
-    ¤±¤Ç¤Ï»ÈÍѤǤ­¤º¡¢¾åµ­¤Î¾¤Î¤â¤Î¤È¶¦¤Ë»È¤¦¡£ÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï
-    <m17n-core.h>, <m17n.h>, <m17n-gui.h> ¤Î¤¤¤º¤ì¤«¤Ë²Ã¤¨¤Æ¡¢ 
-    <m17n-misc.h> ¤ò include ¤·¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+    ¥¨¥é¡¼½èÍý¡¢¥Ç¥Ð¥Ã¥°ÍѤΤ½¤Î¾¤Î´Ø¿ô¤òÄ󶡤¹¤ë¡£¤³¤Î API ¤Ï¤½¤ì¤À¤±
+    ¤Ç¤Ï»ÈÍѤǤ­¤º¡¢¾åµ­¤Î¾¤Î¤â¤Î¤È¶¦¤Ë»È¤¦¡£ÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¾åµ­¤Î
+    ¤¤¤º¤ì¤«¤Î include ¥Õ¥¡¥¤¥ë¤Ë²Ã¤¨¤Æ¡¢ <m17n-misc.h> ¤ò include ¤·¤Ê
+    ¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
 
     </ol>
 
@@ -408,6 +438,33 @@ mdebug__print_time ()
   } while (0)
 
 
+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 */
 
@@ -419,7 +476,7 @@ m17n_init_core (void)
 {
   int mdebug_mask = MDEBUG_INIT;
 
-  if (core_initialized)
+  if (core_initialized++)
     return;
 
   merror_code = MERROR_NONE;
@@ -455,7 +512,6 @@ m17n_init_core (void)
 
   mdatabase__finder = NULL;
   mdatabase__loader = NULL;
-  core_initialized = 1;
 
  err:
   MDEBUG_POP_TIME ();
@@ -468,8 +524,11 @@ m17n_fini_core (void)
 {
   int mdebug_mask = MDEBUG_FINI;
 
-  if (core_initialized)
+  if (core_initialized > 1)
+    core_initialized--;
+  else
     {
+      core_initialized = 0;
       MDEBUG_PUSH_TIME ();
       MDEBUG_PUSH_TIME ();
       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize chartable module."));
@@ -482,7 +541,6 @@ m17n_fini_core (void)
       msymbol__fini ();
       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize plist module."));
       mplist__fini ();
-      core_initialized = 0;
       MDEBUG_POP_TIME ();
       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the core modules."));
       MDEBUG_POP_TIME ();
@@ -513,7 +571,7 @@ m17n_fini_core (void)
 
     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 ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤È¤Ï»²¾È¿ô¤Ë¤è¤Ã¤Æ´ÉÍý¤µ¤ì¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë.