efccca622ee50911ecc519d306b26d428eabd710
[m17n/m17n-lib.git] / src / m17n-core.c
1 /* m17n-core.c -- body of the CORE API.
2    Copyright (C) 2003, 2004
3      National Institute of Advanced Industrial Science and Technology (AIST)
4      Registration Number H15PRO112
5
6    This file is part of the m17n library.
7
8    The m17n library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public License
10    as published by the Free Software Foundation; either version 2.1 of
11    the License, or (at your option) any later version.
12
13    The m17n library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Lesser General Public License for more details.
17
18    You should have received a copy of the GNU Lesser General Public
19    License along with the m17n library; if not, write to the Free
20    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21    02111-1307, USA.  */
22
23 /***en
24     @addtogroup m17nIntro
25     @brief Introduction to the m17n library.
26
27     <em>API LEVELS</em>
28
29     The API of the m17n library is divided into these four.
30
31     <ol>
32     <li> CORE API
33
34     It provides basic modules to handle M-texts.  They do not require
35     the m17n database.  To use this API, an application program must
36     include <m17n-core.h> and be linked by -lm17n-core.
37
38     <li> SHELL API
39
40     It provides modules that utilize the m17n database (code
41     conversion, character property, etc).  They load various kinds of
42     data from the database on demand.  To use this API, an application
43     program must include <m17n.h> and be linked by -lm17n-core -lm17n.
44
45     When you use this API, CORE API is also available.
46
47     <li> GUI API
48
49     It provides GUI modules such as drawing and inputting M-texts on a
50     graphic device.  The API itself is independent on a graphic device
51     but most functions require an argument MFrame which is created for
52     a specific type of graphic device.  Currently, a null device, X
53     Window System, and an image date (gdImagePtr) of GD library are
54     supported as a graphic device.
55
56     On a frame of the null device, you can't draw text nor use an
57     input method (but, for instance, the funciton mdraw_glyph_list ()
58     is available).
59
60     On a frame of the X Window System, you can use the whole GUI API.
61
62     On a frame of GD library, you can use all drawing API but can't
63     use input method.
64
65     To use this device, an application program must include
66     <m17n-gui.h> and be linked by -lm17n-core -lm17n -lm17n-gui.
67
68     When you use this API, CORE and SHELL API are also available.
69
70     <li> MISC API
71
72     It provides miscellaneous functions to support error handling and
73     debugging.  This API cannot be used by itself, but with one or
74     more APIs listed above.  To use the API, an application program
75     must include <m17n-misc.h> in addition to one of a header file
76     described above.
77
78     </ol>
79
80     See also the section @ref m17n-config "m17n-config(1)".
81
82     <em>ENVIRONMENT VARIABLE</em>
83
84     The m17n library pays attention to these environment variables.
85
86     <ul>
87     <li> @c M17NDIR
88
89     Name of a directory that contains data of the m17n database.  See
90     @ref m17nDatabase for more details.
91
92     <li> @c MDEBUG_XXXX
93
94     Environment variables whose name start by "MDEBUG_" controls
95     printing of debug information.  See @ref m17nDebug for more
96     details.
97
98     </ul>
99
100     <em>API NAMING CONVENTION</em>
101
102     The library exports functions, variables, macros, and types.  All
103     of them start by the letter 'm' or 'M' followed by an object name
104     (e.g. "symbol" and "plist", but "mtext" object is given the name
105     "text" to avoid double 'm' at the head) or a module name
106     (e.g. draw, input).
107     
108     <ul>
109
110     <li> functions -- mobject () or mobject_xxx ()
111
112     They start with 'm' followed by lower case object name.  For
113     example, msymbol (), mtext_ref_char (), mdraw_text ().
114
115     <li> non-symbol variables -- mobject, or mobject_xxx
116     
117     The naming convention is the same as functions (e.g. mface_large).
118
119     <li> symbol variables -- Mname
120
121     Variables of type MSymbol start with 'M' followed by their names
122     (e.g. Mlanguage (name is "language"), Miso_2022 (name is
123     "iso-2022").
124
125     <li> macros -- MOBJECT_XXX
126
127     They start by 'M' followed by upper case object names.
128
129     <li> types -- MObject or MObjectXxx
130
131     They start by 'M' followed by capitalized object names (e.g.
132     MConverter, MInputDriver).
133
134     </ul>
135
136   */
137
138 /***ja
139     @addtogroup m17nIntro
140     @brief m17n ¥é¥¤¥Ö¥é¥ê ¥¤¥ó¥È¥í¥À¥¯¥·¥ç¥ó.
141
142     @em API¤Î¥ì¥Ù¥ë
143
144     m17n ¥é¥¤¥Ö¥é¥ê¤Î API ¤Ï°Ê²¼¤Î£´¼ï¤ËʬÎव¤ì¤Æ¤¤¤ë¡£
145
146     <ol>
147     <li> ¥³¥¢ API
148
149     M-text ¤ò°·¤¦¤¿¤á¤Î´ðËÜŪ¤Ê¥â¥¸¥å¡¼¥ë¤òÄ󶡤¹¤ë¡£¤³¤ÎʬÎà¤Î API ¤Ï
150     m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤òɬÍפȤ·¤Ê¤¤¡£ÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç
151     ¥ó¥×¥í¥°¥é¥à¤Ï<m17n-core.h> ¤ò include ¤·¡¢ -lm17n-core ¤Ç¥ê¥ó¥¯¤µ
152     ¤ì¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
153
154     <li> ¥·¥§¥ë API
155
156     m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤òÍøÍѤ¹¤ë¥â¥¸¥å¡¼¥ë¡Ê¥³¡¼¥ÉÊÑ´¹¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£
157     Åù¡Ë¤òÄ󶡤¹¤ë¡£¥â¥¸¥å¡¼¥ë¤Ï¥Ç¡¼¥¿¥Ù¡¼¥¹¤«¤éɬÍפ˱þ¤¸¤Æ¿Íͤʥǡ¼
158     ¥¿¤ò¥í¡¼¥É¤¹¤ë¡£ÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï
159     <m17n.h> ¤ò include ¤·¡¢ -lm17n-core -lm17n ¤Ç¥ê¥ó¥¯¤µ¤ì¤Ê¤¯¤Æ¤Ï¤Ê
160     ¤é¤Ê¤¤¡£
161
162     ¤³¤Î API ¤ò»ÈÍѤ¹¤ëºÝ¤Ë¤Ï¥³¥¢ API ¤â»ÈÍѤǤ­¤ë¡£
163
164     <li> GUI API
165
166     M-texts ¤ò¥°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¾å¤Çɽ¼¨¤·¤¿¤êÆþÎϤ·¤¿¤ê¤¹¤ë¤È¤¤¤Ã¤¿¡¢
167     ¥°¥é¥Õ¥£¥Ã¥¯¥æ¡¼¥¶¥¤¥ó¥¿¥Õ¥§¡¼¥¹¥â¥¸¥å¡¼¥ë¤òÄ󶡤¹¤ë¡£API ¼«ÂΤϥ°
168     ¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¤È¤ÏÆÈΩ¤Ç¤¢¤ë¤¬¡¢Â¿¤¯¤Î´Ø¿ô¤ÏÆÃÄê¤Î¥°¥é¥Õ¥£¥Ã¥¯
169     ¥Ç¥Ð¥¤¥¹¾å¤ËºîÀ®¤µ¤ì¤¿ MFrame ¤ò°ú¿ô¤Ë¼è¤ë¡£¸½»þÅÀ¤Ç¤Ï¡¢¥Ì¥ë¥Ç¥Ð¥¤
170     ¥¹¡¢X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¡¢GD ¥é¥¤¥Ö¥é¥ê¤Î¥¤¥á¡¼¥¸¡ÊgdImagePtr¡Ë¡¢¤¬
171     ¥°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¤È¤·¤Æ¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¡£
172
173     ¥Ì¥ë¥Ç¥Ð¥¤¥¹¾å¤Ç¤Ïɽ¼¨¤âÆþÎϤâ¤Ç¤­¤Ê¤¤¡Ê¤¿¤À¤·¤¿¤È¤¨¤Ð
174     mdraw_glyph_list () ¤Ê¤É¤Î´Ø¿ô¤Ï»ÈÍѲÄǽ¡Ë¡£
175
176     X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¾å¤Ç¤Ï¤¹¤Ù¤Æ¤Î GUI API ¤¬»È¤¨¤ë¡£
177
178     GD ¥é¥¤¥Ö¥é¥ê¤Î¥¤¥á¡¼¥¸¾å¤Ç¤Ï¡¢ÉÁ²èÍѤΠAPI ¤Ï¤¹¤Ù¤Æ»È¤¨¤ë¤¬ÆþÎϤÏ
179     ¤Ç¤­¤Ê¤¤¡£
180
181     ¤³¤Î¥Ç¥Ð¥¤¥¹¤ò»ÈÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï
182     <m17n-gui.h> ¤ò include ¤·¡¢-lm17n-core -lm17n -lm17n-gui ¤Ç¥ê¥ó¥¯
183     ¤µ¤ì¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
184
185     ¤³¤Î API ¤ò»ÈÍѤ¹¤ëºÝ¤Ë¤Ï¡¢¥³¥¢ API ¤È¥·¥§¥ë API ¤â»ÈÍѤǤ­¤ë¡£
186
187     <li> ¤½¤Î¾¤Î API
188
189     ¥¨¥é¡¼½èÍý¡¢¥Ç¥Ð¥Ã¥°ÍѤΤ½¤Î¾¤Î´Ø¿ô¤òÄ󶡤¹¤ë¡£¤³¤Î API ¤Ï¤½¤ì¤À¤±
190     ¤Ç¤Ï»ÈÍѤǤ­¤º¡¢¾åµ­¤Î¾¤Î¤â¤Î¤È¶¦¤Ë»È¤¦¡£ÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¾åµ­¤Î
191     ¤¤¤º¤ì¤«¤Î include ¥Õ¥¡¥¤¥ë¤Ë²Ã¤¨¤Æ¡¢ <m17n-misc.h> ¤ò include ¤·¤Ê
192     ¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
193
194     </ol>
195
196     @ref m17n-config "m17n-config(1)" Àá¤â»²¾È¡£
197
198     @em ´Ä¶­ÊÑ¿ô
199
200     m17n ¥é¥¤¥Ö¥é¥ê¤Ï¼¡¤Î´Ä¶­ÊÑ¿ô¤ò¹Íθ¤¹¤ë¡£
201
202     <ul>
203     <li> @c M17NDIR
204
205     m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥Ç¡¼¥¿¤ò´Þ¤à¥Ç¥£¥ì¥¯¥È¥ê¤Î̾Á°¡£¾ÜºÙ¤Ï@ref
206     m17nDatabase »²¾È¡£
207
208     <li> @c MDEBUG_XXXX
209
210     "MDEBUG_" ¤Ç»Ï¤Þ¤ë̾Á°¤ò»ý¤Ä´Ä¶­ÊÑ¿ô¤Ï¥Ç¥Ð¥Ã¥°¾ðÊó¤òÀ©¸æ¤¹¤ë¡£¾ÜºÙ
211     ¤Ï@ref m17nDebug »²¾È¡£
212
213     </ul>
214
215     @em API @em ¤Î̿̾µ¬Â§ ¥³¥Þ¥ó¥É
216
217     ¥é¥¤¥Ö¥é¥ê¤Ï¡¢´Ø¿ô¡¢ÊÑ¿ô¡¢¥Þ¥¯¥í¡¢·¿¤ò export ¤¹¤ë¡£¤½¤ì¤é¤Ï'm' ¤Þ
218     ¤¿¤Ï 'M' ¤Î¤¢¤È¤Ë¥ª¥Ö¥¸¥§¥¯¥È̾("symbol" ¤ä "plist" ¤Ê¤É¡£¤¿¤À¤· 
219     "mtext" ¥ª¥Ö¥¸¥§¥¯¥È¤Ï¤Ï¤¸¤á¤Î 'm' ¤Î½ÅÊ£¤òÈò¤±¤ë¤¿¤á "text" ¤òÍÑ
220     ¤¤¤ë¡£) ¤Þ¤¿¤Ï¥â¥¸¥å¡¼¥ë̾(draw, input ¤Ê¤É) ¤ò³¤±¤¿¤â¤Î¤Ç¤¢¤ë¡£
221     
222     <ul>
223
224     <li> ´Ø¿ô -- mobject () ¤Þ¤¿¤Ï mobject_xxx ()
225
226     'm' ¤Î¤¢¤È¤Ë¾®Ê¸»ú¤Ç¥ª¥Ö¥¸¥§¥¯¥È̾¤¬Â³¤¯¡£¤¿¤È¤¨¤Ð¡¢msymbol (),
227      mtext_ref_char (), mdraw_text () ¤Ê¤É¡£
228
229     <li> ¥·¥ó¥Ü¥ë¤Ç¤Ê¤¤ÊÑ¿ô -- mobject,  ¤Þ¤¿¤Ï mobject_xxx
230     
231     ´Ø¿ô¤ÈƱ¤¸Ì¿Ì¾µ¬Â§¤Ë½¾¤¦¡£(¤¿¤È¤¨¤Ð  mface_large)
232
233     <li> ¥·¥ó¥Ü¥ëÊÑ¿ô -- Mname
234
235     MSymbol ·¿ÊÑ¿ô¤Ï¡¢'M' ¤Î¸å¤Ë̾Á°¤¬Â³¤¯¡£¤¿¤È¤¨¤Ð Mlanguage (̾Á°¤Ï 
236     "language"), Miso_2022 (̾Á°¤Ï"iso-2022")¤Ê¤É¡£
237
238     <li> ¥Þ¥¯¥í -- MOBJECT_XXX
239
240     'M' ¤Î¸å¤ËÂçʸ»ú¤Ç¥ª¥Ö¥¸¥§¥¯¥È̾¤¬Â³¤¯¡£
241
242     <li> ¥¿¥¤¥× -- MObject ¤Þ¤¿¤Ï MObjectXxx
243
244     'M' ¤Î¸å¤ËÂçʸ»ú¤Ç»Ï¤á¤Æ¥ª¥Ö¥¸¥§¥¯¥È̾¤ò¤¬Â³¤¯¡£ (¤¿¤È¤¨¤Ð
245     MConverter, MInputDriver)
246
247     </ul>
248     
249     */
250 /*=*/
251 /*** @{ */
252 #ifdef FOR_DOXYGEN
253 /***en
254     The #M17NLIB_MAJOR_VERSION macro gives the major version number
255     of the m17n library.  */
256
257 /***ja
258     ¥Þ¥¯¥í #M17NLIB_MAJOR_VERSION ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤Î¥á¥¸¥ã¡¼¥Ð¡¼¥¸¥ç
259     ¥óÈÖ¹æ¤òÍ¿¤¨¤ë¡£  */
260
261 #define M17NLIB_MAJOR_VERSION
262
263 /*=*/
264
265 /***en
266     The #M17NLIB_MINOR_VERSION macro gives the minor version number
267     of the m17n library.  */
268
269 /***ja
270     ¥Þ¥¯¥í #M17NLIB_MINOR_VERSION ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤Î¥Þ¥¤¥Ê¡¼¥Ð¡¼¥¸¥ç
271     ¥óÈÖ¹æ¤òÍ¿¤¨¤ë¡£  */
272
273 #define M17NLIB_MINOR_VERSION
274
275 /*=*/
276
277 /***en
278     The #M17NLIB_PATCH_LEVEL macro gives the patch level number
279     of the m17n library.  */
280
281 /***ja
282     ¥Þ¥¯¥í #M17NLIB_PATCH_LEVEL ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤Î¥Ñ¥Ã¥Á¥ì¥Ù¥ëÈÖ¹æ¤ò
283     Í¿¤¨¤ë¡£  */
284
285 #define M17NLIB_PATCH_LEVEL
286
287 /*=*/
288
289 /***en
290     The #M17NLIB_VERSION_NAME macro gives the version name of the
291     m17n library as a string.  */
292
293 /***ja
294     ¥Þ¥¯¥í #M17NLIB_VERSION_NAME ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤Î¥Ð¡¼¥¸¥ç¥ó̾¤ò
295     Ê¸»úÎó¤È¤·¤ÆÍ¿¤¨¤ë¡£  */
296
297 #define M17NLIB_VERSION_NAME
298
299 /*=*/
300
301 /***en
302     @brief Initialize the m17n library.
303
304     The macro M17N_INIT () initializes the m17n library.  This macro
305     must be called before any m17n functions are used.
306
307     If the initialization was successful, the external variable
308     #merror_code is set to 0.  Otherwise it is set to -1.  */
309
310 /***ja
311     @brief m17n ¥é¥¤¥Ö¥é¥ê¤ò½é´ü²½¤¹¤ë.
312
313     ¥Þ¥¯¥í M17N_INIT () ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤ò½é´ü²½¤¹¤ë¡£m17n ¤Î´Ø¿ô¤ò
314     ÍøÍѤ¹¤ëÁ°¤Ë¡¢¤³¤Î¥Þ¥¯¥í¤ò¤Þ¤º¸Æ¤Ð¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
315     
316     ³°ÉôÊÑ¿ô #merror_code ¤Ï¡¢½é´ü²½¤¬À®¸ù¤¹¤ì¤Ð 0 ¤Ë¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð 
317     -1 ¤ËÀßÄꤵ¤ì¤ë¡£  */
318
319 #define M17N_INIT()
320
321 /*=*/
322
323 /***en
324     @brief Finalize the m17n library.
325
326     The macro M17N_FINI () finalizes the m17n library.  It frees all the
327     memory area used by the m17n library.  Once this macro is
328     called, no m17n functions should be used until the
329     macro M17N_INIT () is called again.  */
330 /***ja
331     @brief m17n ¥é¥¤¥Ö¥é¥ê¤ò½ªÎ»¤¹¤ë. 
332
333     ¥Þ¥¯¥í M17N_FINI () ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤ò½ªÎ»¤¹¤ë¡£m17n ¥é¥¤¥Ö¥é¥ê
334     ¤¬»È¤Ã¤¿Á´¤Æ¤Î¥á¥â¥êÎΰè¤Ï²òÊü¤µ¤ì¤ë¡£°ìÅÙ¤³¤Î¥Þ¥¯¥í¤¬¸Æ¤Ð¤ì¤¿¤é¡¢
335     ¥Þ¥¯¥í M17N_INIT () ¤¬ºÆÅٸƤФì¤ë¤Þ¤Ç m17n ´Ø¿ô¤Ï»È¤¦¤Ù¤­¤Ç¤Ê¤¤¡£
336  */
337
338 #define M17N_FINI()
339 #endif /* FOR_DOXYGEN */
340 /*=*/
341 /*** @} */ 
342 /*=*/
343
344 #if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
345 /*** @addtogroup m17nInternal
346      @{ */
347
348 #include <config.h>
349 #include <stdio.h>
350 #include <stdlib.h>
351 #include <sys/time.h>
352 #include <sys/resource.h>
353 #include <unistd.h>
354
355 #include "m17n-core.h"
356 #include "m17n-misc.h"
357 #include "internal.h"
358
359 static int core_initialized;
360
361 static void
362 default_error_handler (enum MErrorCode err)
363 {
364   exit (err);
365 }
366
367 static struct timeval time_stack[16];
368 static int time_stack_index;
369
370 static int report_header_printed;
371
372 \f
373 /* Internal API */
374
375 void
376 mdebug__report_object (char *name, M17NObjectArray *array)
377 {
378   if (! (mdebug__flag & MDEBUG_FINI))
379     return;
380   if (! report_header_printed)
381     {
382       fprintf (stderr, "%16s %7s %7s %7s\n",
383                "object", "created", "freed", "alive");
384       fprintf (stderr, "%16s %7s %7s %7s\n",
385                "------", "-------", "-----", "-----");
386       report_header_printed = 1;
387     }
388   fprintf (stderr, "%16s %7d %7d %7d\n", name,
389            array->used, array->used - array->count, array->count);
390   if (array->used > 0)
391     {
392       free (array->objects);
393       array->count = array->used = 0;
394     }
395 }
396
397
398 void *(*mdatabase__finder) (MSymbol tag1, MSymbol tag2,
399                            MSymbol tag3, MSymbol tag4);
400 void *(*mdatabase__loader) (void *);
401
402 int mdebug__flag;
403
404 void
405 mdebug__push_time ()
406 {
407   struct timezone tz;
408
409   gettimeofday (time_stack + time_stack_index++, &tz);
410 }
411
412 void
413 mdebug__pop_time ()
414 {
415   time_stack_index--;
416 }
417
418 void
419 mdebug__print_time ()
420 {
421   struct timeval tv;
422   struct timezone tz;
423   long diff;
424
425   gettimeofday (&tv, &tz);
426   diff = ((tv.tv_sec - time_stack[time_stack_index - 1].tv_sec) * 1000000
427           + (tv.tv_usec - time_stack[time_stack_index - 1].tv_usec));
428   fprintf (stderr, "%8ld ms.", diff);
429   time_stack[time_stack_index - 1] = tv;
430 }
431
432 #define SET_DEBUG_FLAG(env_name, mask)          \
433   do {                                          \
434     char *env_value = getenv (env_name);        \
435                                                 \
436     if (env_value && env_value[0] == '1')       \
437       mdebug__flag |= (mask);                   \
438   } while (0)
439
440
441 void
442 mdebug__register_object (M17NObjectArray *array, void *object)
443 {
444   if (array->used == 0)
445     MLIST_INIT1 (array, objects, 256);
446   array->count++;
447   MLIST_APPEND1 (array, objects, object, MERROR_OBJECT);
448 }
449
450 void
451 mdebug__unregister_object (M17NObjectArray *array, void *object)
452 {
453   array->count--;
454   if (array->count >= 0)
455     {
456       int i = 0;
457
458       while (i < array->used && array->objects[i] != object) i++;
459       if (i < array->used)
460         array->objects[i] = NULL;
461       else
462         mdebug_hook ();
463     }
464   else                                                                  \
465     mdebug_hook ();
466 }
467
468 \f
469 /* External API */
470
471 /* The following two are actually not exposed to a user but concealed
472    by the macro M17N_INIT (). */
473
474 void
475 m17n_init_core (void)
476 {
477   int mdebug_mask = MDEBUG_INIT;
478
479   if (core_initialized++)
480     return;
481
482   merror_code = MERROR_NONE;
483   m17n_memory_full_handler = default_error_handler;
484
485   mdebug__flag = 0;
486   SET_DEBUG_FLAG ("MDEBUG_INIT", MDEBUG_INIT);
487   SET_DEBUG_FLAG ("MDEBUG_FINI", MDEBUG_FINI);
488   SET_DEBUG_FLAG ("MDEBUG_CHARSET", MDEBUG_CHARSET);
489   SET_DEBUG_FLAG ("MDEBUG_CODING", MDEBUG_CODING);
490   SET_DEBUG_FLAG ("MDEBUG_DATABASE", MDEBUG_DATABASE);
491   SET_DEBUG_FLAG ("MDEBUG_FONT", MDEBUG_FONT); 
492   SET_DEBUG_FLAG ("MDEBUG_FONT_FLT", MDEBUG_FONT_FLT);
493   SET_DEBUG_FLAG ("MDEBUG_FONT_OTF", MDEBUG_FONT_OTF);
494   SET_DEBUG_FLAG ("MDEBUG_INPUT", MDEBUG_INPUT);
495
496   MDEBUG_PUSH_TIME ();
497   MDEBUG_PUSH_TIME ();
498   if (msymbol__init () < 0)
499     goto err;
500   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize symbol module."));
501   if  (mplist__init () < 0)
502     goto err;
503   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize plist module."));
504   if (mtext__init () < 0)
505     goto err;
506   if (mtext__prop_init () < 0)
507     goto err;
508   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize mtext module."));
509   if  (mchartable__init () < 0)
510     goto err;
511   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize chartable module."));
512
513   mdatabase__finder = NULL;
514   mdatabase__loader = NULL;
515
516  err:
517   MDEBUG_POP_TIME ();
518   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the core modules."));
519   MDEBUG_POP_TIME ();
520 }
521
522 void
523 m17n_fini_core (void)
524 {
525   int mdebug_mask = MDEBUG_FINI;
526
527   if (core_initialized > 1)
528     core_initialized--;
529   else
530     {
531       core_initialized = 0;
532       MDEBUG_PUSH_TIME ();
533       MDEBUG_PUSH_TIME ();
534       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize chartable module."));
535       mchartable__fini ();
536       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize textprop module."));
537       mtext__prop_fini ();
538       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize mtext module."));
539       mtext__fini ();
540       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize symbol module."));
541       msymbol__fini ();
542       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize plist module."));
543       mplist__fini ();
544       MDEBUG_POP_TIME ();
545       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the core modules."));
546       MDEBUG_POP_TIME ();
547     }
548   report_header_printed = 0;
549 }
550
551 /*** @} */
552 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
553 /*=*/
554
555 /***en
556     @addtogroup m17nObject
557     @brief Managed objects are objects managed by the reference count.
558
559     There are some types of m17n objects that are managed by their
560     reference count.  Those objects are called @e managed @e objects.
561     When created, the reference count of a managed object is
562     initialized to one.  The m17n_object_ref () function increments
563     the reference count of a managed object by one, and the
564     m17n_object_unref () function decrements by one.  A managed
565     object is automatically freed when its reference count becomes
566     zero.
567
568     A property whose key is a managing key can have only a managed
569     object as its value.  Such functions as msymbol_put () and
570     mplist_put () pay special attention to such a property.
571
572     In addition to the predefined managed object types, users can
573     define their own managed object types.  See the documentation of
574     the m17n_object () for more details.  */
575 /***ja
576     @addtogroup m17nObject
577     @brief ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤È¤Ï»²¾È¿ô¤Ë¤è¤Ã¤Æ´ÉÍý¤µ¤ì¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë.
578
579     m17n ¥ª¥Ö¥¸¥§¥¯¥È¤Î¤¢¤ë·¿¤Î¤â¤Î¤Ï¡¢»²¾È¿ô¤Ë¤è¤Ã¤Æ´ÉÍý¤µ¤ì¤Æ¤¤¤ë¡£
580     ¤½¤ì¤é¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ï @e ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È ¤È¸Æ¤Ð¤ì¤ë¡£À¸À®¤µ¤ì
581     ¤¿»þÅÀ¤Ç¤Î»²¾È¿ô¤Ï 0 ¤Ë½é´ü²½¤µ¤ì¤Æ¤¤¤ë¡£´Ø¿ô m17n_object_ref () 
582     ¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Î»²¾È¿ô¤ò 1 Áý¤ä¤·¡¢´Ø¿ôm17n_object_unref () 
583     ¤Ï 1 ¸º¤é¤¹¡£»²¾È¿ô¤¬ 0 ¤Ë¤Ê¤Ã¤¿´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ï¼«Æ°Åª¤Ë²òÊü¤µ
584     ¤ì¤ë¡£
585
586     ¥­¡¼¤¬´ÉÍý¥­¡¼¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤Ï¡¢ÃͤȤ·¤Æ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤À¤±¤ò
587     ¼è¤ë¡£´Ø¿ô msymbol_put () ¤ä mplist_put () ¤Ê¤É¤Ï¤½¤ì¤é¤Î¥×¥í¥Ñ¥Æ¥£
588     ¤òÆÃÊÌ°·¤¤¤¹¤ë¡£
589
590     ÄêµÁºÑ¤ß´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¥¿¥¤¥×¤Î¾¤Ë¡¢¥æ¡¼¥¶¤ÏɬÍפʴÉÍý²¼¥ª¥Ö¥¸¥§
591     ¥¯¥È¥¿¥¤¥×¤ò¼«Ê¬¤ÇÄêµÁ¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£¾ÜºÙ¤Ïm17n_object () ¤ÎÀâ
592     ÌÀ¤ò»²¾È¡£  */
593
594 /*** @{  */
595 /*=*/
596 /***en
597     @brief Allocate a managed object.
598
599     The m17n_object () function allocates a new managed object of
600     $SIZE bytes and sets its reference count to 1.  $FREER is the
601     function that is used to free the object when the reference count
602     becomes 0.  If $FREER is NULL, the object is freed by the free ()
603     function.
604
605     The heading bytes of the allocated object is occupied by
606     #M17NObjectHead.  That area is reserved for the m17n library and
607     application programs should never touch it.
608
609     @return
610     This function returns a newly allocated object.
611
612     @errors
613     This function never fails.  */
614
615 /***ja
616     @brief ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤ò³ä¤êÅö¤Æ¤ë.
617
618     ´Ø¿ô m17n_object () ¤Ï$SIZE ¥Ð¥¤¥È¤Î¿·¤·¤¤´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤ò³ä¤ê
619     Åö¤Æ¡¢¤½¤Î»²¾È¿ô¤ò 1 ¤È¤¹¤ë¡£ $FREER ¤Ï»²¾È¿ô¤¬ 0 ¤Ë¤Ê¤Ã¤¿ºÝ¤Ë¤½¤Î
620     ¥ª¥Ö¥¸¥§¥¯¥È¤ò²òÊü¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë´Ø¿ô¤Ç¤¢¤ë¡£$FREER ¤¬ NULL¤Ê
621     ¤é¤Ð¡¢¥ª¥Ö¥¸¥§¥¯¥È¤Ï´Ø¿ô free () ¤Ë¤è¤Ã¤Æ²òÊü¤µ¤ì¤ë¡£
622
623     ³ä¤êÅö¤Æ¤é¤ì¤¿¥ª¥Ö¥¸¥§¥¯¥ÈËÁƬ¤Î¥Ð¥¤¥È¤Ï¡¢#M17NObjectHead ¤¬Àê¤á¤ë¡£ 
624     ¤³¤ÎÎΰè¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤¬»ÈÍѤ¹¤ë¤Î¤Ç¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é
625     ¥à¤Ï¿¨¤ì¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
626
627     @return
628     ¤³¤Î´Ø¿ô¤Ï¿·¤·¤¯³ä¤êÅö¤Æ¤é¤ì¤¿¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤¹¡£
629
630     @errors
631     ¤³¤Î´Ø¿ô¤Ï¼ºÇÔ¤·¤Ê¤¤¡£    */
632
633 #if EXAMPLE_CODE
634 typedef struct
635 {
636   M17NObjectHead head;
637   int mem1;
638   char *mem2;
639 } MYStruct;
640
641 void
642 my_freer (void *obj)
643 {
644   free (((MYStruct *) obj)->mem2);
645   free (obj);
646 }
647
648 void
649 my_func (MText *mt, MSymbol key, int num, char *str)
650 {
651   MYStruct *st = m17n_object (sizeof (MYStruct), my_freer);
652
653   st->mem1 = num;
654   st->mem2 = strdup (str);
655   /* KEY must be a managing key.   */
656   mtext_put_prop (mt, 0, mtext_len (mt), key, st);
657   /* This sets the reference count of ST back to 1.  */
658   m17n_object_unref (st);
659 }
660 #endif
661
662 void *
663 m17n_object (int size, void (*freer) (void *))
664 {
665   M17NObject *obj = malloc (size);
666
667   obj->ref_count = 1;
668   obj->u.freer = freer;
669   return obj;
670 }
671
672 /*=*/
673
674 /***en
675     @brief Increment the reference count of a managed object.
676
677     The m17n_object_ref () function increments the reference count of
678     the managed object pointed to by $OBJECT.
679
680     @return
681     This function returns the resulting reference count if it fits in
682     a 16-bit unsigned integer (i.e. less than 0x10000).  Otherwise, it
683     return -1.
684
685     @errors
686     This function never fails.  */
687 /***ja
688     @brief ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Î»²¾È¿ô¤ò 1 Áý¤ä¤¹.
689
690     ´Ø¿ô m17n_object_ref () ¤Ï $OBJECT ¤Ç»Ø¤µ¤ì¤ë´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Î
691     »²¾È¿ô¤ò 1 Áý¤ä¤¹¡£
692
693     @return 
694     ¤³¤Î´Ø¿ô¤Ï¡¢Áý¤ä¤·¤¿»²¾È¿ô¤¬ 16 ¥Ó¥Ã¥È¤ÎÉä¹æ̵¤·À°¿ôÃÍ(¤¹¤Ê¤ï¤Á 
695     0x10000 Ì¤Ëþ)¤Ë¤ª¤µ¤Þ¤ì¤Ð¡¢¤½¤ì¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤¹¡£
696
697     @errors
698     ¤³¤Î´Ø¿ô¤Ï¼ºÇÔ¤·¤Ê¤¤¡£    */
699
700 int
701 m17n_object_ref (void *object)
702 {
703   M17NObject *obj = (M17NObject *) object;
704   M17NObjectRecord *record;
705   unsigned *count;
706
707   if (! obj->ref_count_extended)
708     {
709       if (++obj->ref_count)
710         return (int) obj->ref_count;
711       MSTRUCT_MALLOC (record, MERROR_OBJECT);
712       record->freer = obj->u.freer;
713       MLIST_INIT1 (record, counts, 1);
714       MLIST_APPEND1 (record, counts, 0, MERROR_OBJECT);
715       obj->u.record = record;
716       obj->ref_count_extended = 1;
717     }
718   else
719     record = obj->u.record;
720
721   count = record->counts;
722   while (*count == 0xFFFFFFFF)
723     *(count++) = 0;
724   (*count)++;
725   if (*count == 0xFFFFFFFF)
726     MLIST_APPEND1 (record, counts, 0, MERROR_OBJECT);
727   return -1;
728 }
729
730 /*=*/
731
732 /***en
733     @brief Decrement the reference count of a managed object.
734
735     The m17n_object_unref () function decrements the reference count
736     of the managed object pointed to by $OBJECT.  When the reference
737     count becomes zero, the object is freed by its freer function.
738
739     @return
740     This function returns the resulting reference count if it fits in
741     a 16-bit unsigned integer (i.e. less than 0x10000).  Otherwise, it
742     returns -1.  Thus, the return value zero means that $OBJECT is
743     freed.
744
745     @errors
746     This function never fails.  */
747 /***ja
748     @brief ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Î»²¾È¿ô¤ò 1 ¸º¤é¤¹.
749
750     ´Ø¿ô m17n_object_unref () ¤Ï $OBJECT ¤Ç»Ø¤µ¤ì¤ë´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È
751     ¤Î»²¾È¿ô¤ò 1 ¸º¤é¤¹¡£»²¾È¿ô¤¬ 0 ¤Ë¤Ê¤ì¤Ð¡¢¥ª¥Ö¥¸¥§¥¯¥È¤Ï²òÊü´Ø¿ô¤Ë
752     ¤è¤Ã¤Æ²òÊü¤µ¤ì¤ë¡£
753
754     @return 
755     ¤³¤Î´Ø¿ô¤Ï¡¢¸º¤é¤·¤¿»²¾È¿ô¤¬ 16 ¥Ó¥Ã¥È¤ÎÉä¹æ̵¤·À°¿ôÃÍ(¤¹¤Ê¤ï¤Á 
756     0x10000 Ì¤Ëþ)¤Ë¤ª¤µ¤Þ¤ì¤Ð¡¢¤½¤ì¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤¹¡£
757     ¤Ä¤Þ¤ê¡¢0 ¤¬Ê֤äÆÍ褿¾ì¹ç¤Ï$OBJECT ¤Ï²òÊü¤µ¤ì¤Æ¤¤¤ë¡£
758
759     @errors
760     ¤³¤Î´Ø¿ô¤Ï¼ºÇÔ¤·¤Ê¤¤¡£    */
761 int
762 m17n_object_unref (void *object)
763 {
764   M17NObject *obj = (M17NObject *) object;
765   M17NObjectRecord *record;
766   unsigned *count;
767
768   if (! obj->ref_count_extended)
769     {
770       if (! --obj->ref_count)
771         {
772           if (obj->u.freer)
773             (obj->u.freer) (object);
774           else
775             free (object);
776           return 0;
777         }
778       return (int) obj->ref_count;
779     }
780
781   record = obj->u.record;
782   count = record->counts;
783   while (! *count)
784     *(count++) = 0xFFFFFFFF;
785   (*count)--;
786   if (! record->counts[0])
787     {
788       obj->ref_count_extended = 0;
789       obj->ref_count--;
790       obj->u.freer = record->freer;
791       MLIST_FREE1 (record, counts);
792       free (record);
793     }
794   return -1;
795 }
796
797 /*=*/
798
799 /*** @} */
800
801 /***en
802     @addtogroup m17nError Error handling
803     @brief Error handling of the m17n library.
804
805     There are two types of errors that may happen in a function of
806     the m17n library.
807
808     The first type is argument errors.  When a library function is
809     called with invalid arguments, it returns a value that indicates
810     error and at the same time sets the external variable #merror_code
811     to a non-zero integer.
812
813     The second type is memory allocation errors.  When the required
814     amount of memory is not available on the system, m17n library
815     functions call a function pointed to by the external variable @c
816     m17n_memory_full_handler.  The default value of the variable is a
817     pointer to the default_error_handle () function, which just calls
818     <tt> exit ()</tt>.  */
819
820 /***ja
821     @addtogroup m17nError ¥¨¥é¡¼½èÍý
822     @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼½èÍý.
823
824     m17n ¥é¥¤¥Ö¥é¥ê¤Î´Ø¿ô¤Ç¤Ï¡¢£²¤Ä¤Î¼ïÎà¤Î¥¨¥é¡¼¤¬µ¯¤³¤êÆÀ¤ë¡£
825
826     °ì¤Ä¤Ï°ú¿ô¤Î¥¨¥é¡¼¤Ç¤¢¤ë¡£¥é¥¤¥Ö¥é¥ê¤Î´Ø¿ô¤¬ÂÅÅö¤Ç¤Ê¤¤°ú¿ô¤È¤È¤â¤Ë
827     ¸Æ¤Ð¤ì¤¿¾ì¹ç¡¢¤½¤Î´Ø¿ô¤Ï¥¨¥é¡¼¤ò°ÕÌ£¤¹¤ëÃͤòÊÖ¤·¡¢Æ±»þ¤Ë³°ÉôÊÑ¿ô 
828     #merror_code ¤Ë¥¼¥í¤Ç¤Ê¤¤À°¿ô¤ò¥»¥Ã¥È¤¹¤ë¡£
829
830     ¤â¤¦°ì¤Ä¤Î¼ïÎà¤Ï¥á¥â¥ê³äÅö¤Æ¥¨¥é¡¼¤Ç¤¢¤ë¡£¥·¥¹¥Æ¥à¤¬É¬ÍפÊÎ̤Υá¥â
831     ¥ê¤ò³äÅö¤Æ¤ë¤³¤È¤¬¤Ç¤­¤Ê¤¤¾ì¹ç¡¢¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ï³°ÉôÊÑ¿ô @c
832     m17n_memory_full_handler ¤¬»Ø¤¹´Ø¿ô¤ò¸Æ¤Ö¡£¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢´Ø¿ô 
833     default_error_handle () ¤ò»Ø¤·¤Æ¤ª¤ê¡¢¤³¤Î´Ø¿ô¤Ïñ¤Ë <tt>exit
834     ()</tt> ¤ò¸Æ¤Ö¡£
835 */
836
837 /*** @{ */
838
839 /*=*/
840
841 /***en 
842     @brief External variable to hold error code of the m17n library.
843
844     The external variable #merror_code holds an error code of the
845     m17n library.  When a library function is called with an invalid
846     argument, it sets this variable to one of @c enum #MErrorCode.
847
848     This variable initially has the value 0.  */
849
850 /***ja 
851     @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼¥³¡¼¥É¤òÊÝ»ý¤¹¤ë³°ÉôÊÑ¿ô.
852
853     ³°ÉôÊÑ¿ô #merror_code ¤Ï¡¢m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼¥³¡¼¥É¤òÊÝ»ý¤¹¤ë¡£
854     ¥é¥¤¥Ö¥é¥ê´Ø¿ô¤¬ÂÅÅö¤Ç¤Ê¤¤°ú¿ô¤È¤È¤â¤Ë¸Æ¤Ð¤ì¤¿ºÝ¤Ë¤Ï¡¢¤³¤ÎÊÑ¿ô¤ò 
855     @c enum #MErrorCode ¤Î°ì¤Ä¤Ë¥»¥Ã¥È¤¹¤ë¡£
856
857     ¤³¤ÎÊÑ¿ô¤Î½é´üÃͤϠ0 ¤Ç¤¢¤ë¡£  */
858
859 enum MErrorCode merror_code;
860
861 /*=*/
862
863 /***en 
864     @brief Memory allocation error handler.
865
866     The external variable #m17n_memory_full_handler holds a pointer
867     to the function to call when a library function failed to allocate
868     memory.  $ERR is one of @c enum #MErrorCode indicating in which
869     function the error occurred.
870
871     This variable initially points a function that simply calls the
872     <tt>exit </tt>() function with $ERR as an argument.
873
874     An application program that needs a different error handling can
875     change this variable to point a proper function.  */
876
877 /***ja 
878     @brief ¥á¥â¥ê³äÅö¤Æ¥¨¥é¡¼¥Ï¥ó¥É¥é.
879
880     ÊÑ¿ô #m17n_memory_full_handler ¤Ï¡¢¥é¥¤¥Ö¥é¥ê´Ø¿ô¤¬¥á¥â¥ê³äÅö¤Æ
881     ¤Ë¼ºÇÔ¤·¤¿ºÝ¤Ë¸Æ¤Ö¤Ù¤­´Ø¿ô¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£$ERR ¤Ï @c enum
882     #MErrorCode ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ê¡¢¤É¤Î¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ç¥¨¥é¡¼¤¬µ¯¤Ã¤¿
883     ¤«¤ò¼¨¤¹¡£
884
885     @anchor test
886
887     ½é´üÀßÄê¤Ç¤Ï¡¢¤³¤ÎÊÑ¿ô¤Ïñ¤Ë <tt>exit ()</tt> ¤ò $ERR ¤ò°ú¿ô¤È¤·¤Æ
888     ¸Æ¤Ö´Ø¿ô¤ò»Ø¤·¤Æ¤¤¤ë¡£
889
890     ¤³¤ì¤È¤Ï°Û¤Ê¤ë¥¨¥é¡¼½èÍý¤òɬÍפȤ¹¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¡¢¤³¤ÎÊÑ¿ô¤ò
891     Å¬Åö¤Ê´Ø¿ô¤ËÀßÄꤹ¤ë¤³¤È¤Ç¡¢ÌÜŪ¤òãÀ®¤Ç¤­¤ë¡£  */
892
893 void (*m17n_memory_full_handler) (enum MErrorCode err);
894
895 /*** @} */
896
897 /*=*/
898
899 /***en
900     @addtogroup m17nDebug
901     @brief Support for m17n library users to debug their programs.
902
903     The m17n library provides the following facilities to support the
904     library users to debug their programs.
905
906     <ul>
907
908     <li> Environment variables to control printing of various
909     information.
910
911     <ul>
912
913     <li> MDEBUG_INIT -- If set to 1, print information about the
914     library initialization on the call of M17N_INIT ().
915
916     <li> MDEBUG_FINI -- If set to 1, print counts of objects that are
917     not yet freed on the call of M17N_FINI ().
918
919     <li> MDEBUG_CHARSET -- If set to 1, print information about
920     charsets being loaded from the m17n database.
921
922     <li> MDEBUG_CODING -- If set to 1, print information about coding
923     systems being loaded from the m17n database.
924
925     <li> MDEBUG_DATABASE -- If set to 1, print information about
926     data being loaded from the m17n database.
927
928     <li> MDEBUG_FONT -- If set to 1, print information about fonts
929     being selected and opened.
930
931     <li> MDEBUG_FONT_FLT -- If set to 1, print information about which
932     command of Font Layout Table are being executed.
933
934     <li> MDEBUG_FONT_OTF -- If set to 1, print information about which
935     feature of OpenType Layout Table are being executed.
936
937     <li> MDEBUG_INPUT -- If set to 1, print information about how an
938     input method is running.
939
940     <li> MDEBUG_ALL -- Setting this variable to 1 is equivalent to
941     setting all the above variables to 1.
942
943     </ul>
944
945     <li> Functions to print various objects in a human readable way.
946     See the documentation of mdebug_dump_XXXX () functions.
947
948     <li> The hook function called on an error.  See the documentation
949     of mdebug_hook ().
950
951     </ul>
952 */
953 /***ja
954     @addtogroup m17nDebug
955     @brief m17n ¥é¥¤¥Ö¥é¥ê¥æ¡¼¥¶¤Î¤¿¤á¤Î¥×¥í¥°¥é¥à¥Ç¥Ð¥Ã¥°¥µ¥Ý¡¼¥È.
956
957     m17n ¥é¥¤¥Ö¥é¥ê¤Ï¡¢¤½¤Î¥æ¡¼¥¶¤¬¼«Ê¬¤Î¥×¥í¥°¥é¥à¤ò¥Ç¥Ð¥Ã¥°¤¹¤ë¤¿¤á
958     ¤Ë¡¢°Ê²¼¤Îµ¡Ç½¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¡£
959
960     <ul>
961
962     <li> ¤µ¤Þ¤¶¤Þ¤Ê¾ðÊó¤Î¥×¥ê¥ó¥È¤òÀ©¸æ¤¹¤ë´Ä¶­ÊÑ¿ô¡£
963
964     <ul>
965
966     <li> MDEBUG_INIT -- 1 ¤Ê¤é¤Ð¡¢M17N_INIT () ¤¬¸Æ¤Ð¤ì¤¿»þÅÀ¤Ç¡¢¥é¥¤
967     ¥Ö¥é¥ê¤Î½é´ü²½¤Ë´Ø¤¹¤ë¾ðÊó¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
968
969     <li> MDEBUG_FINI -- 1 ¤Ê¤é¤Ð¡¢M17N_FINI () ¤¬¸Æ¤Ð¤ì¤¿»þÅÀ¤Ç¡¢¤Þ¤À
970     ²òÊü¤µ¤ì¤Æ¤¤¤Ê¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î»²¾È¿ô¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
971
972     <li> MDEBUG_CHARSET -- 1 ¤Ê¤é¤Ð¡¢m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤«¤é¥í¡¼¥É¤µ¤ì¤¿
973     Ê¸»ú¥»¥Ã¥È¤Ë¤Ä¤¤¤Æ¤Î¾ðÊó¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
974
975     <li> MDEBUG_CODING --  1 ¤Ê¤é¤Ð¡¢m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤«¤é¥í¡¼¥É¤µ¤ì¤¿
976     ¥³¡¼¥É·Ï¤Ë¤Ä¤¤¤Æ¤Î¾ðÊó¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
977
978     <li> MDEBUG_DATABASE -- 1 ¤Ê¤é¤Ð¡¢m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤«¤é¥í¡¼¥É¤µ¤ì
979     ¤¿¥Ç¡¼¥¿¤Ë¤Ä¤¤¤Æ¤Î¾ðÊó¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
980
981     <li> MDEBUG_FONT -- 1 ¤Ê¤é¤Ð¡¢ÁªÂò¤µ¤ì¤Æ¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥©¥ó¥È¤Ë¤Ä
982     ¤¤¤Æ¤Î¾ðÊó¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
983
984     <li> MDEBUG_FONT_FLT -- 1 ¤Ê¤é¤Ð¡¢Font Layout Table ¤Î¤É¤Î¥³¥Þ¥ó¥É
985     ¤¬¼Â¹ÔÃ椫¤Ë¤Ä¤¤¤Æ¤Î¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
986
987     <li> MDEBUG_FONT_OTF -- 1 ¤Ê¤é¤Ð¡¢OpenType Layout Table ¤Î¤É¤Î°À­
988     ¤¬¼Â¹ÔÃ椫¤Ë¤Ä¤¤¤Æ¤Î¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
989
990     <li> MDEBUG_INPUT -- 1 ¤Ê¤é¤Ð¡¢¼Â¹ÔÃæ¤ÎÆþÎϥ᥽¥Ã¥É¤Î¾õÂÖ¤ËÉÕ¤¤¤Æ
991     ¤Î¾ðÊó¤ò¥×¥ê¥ó¥È¤¹¤ë¡£
992
993     <li> MDEBUG_ALL -- 1 ¤Ê¤é¤Ð¡¢¾åµ­¤¹¤Ù¤Æ¤ÎÊÑ¿ô¤ò 1 ¤Ë¤·¤¿¤Î¤ÈƱ¤¸¸ú
994     ²Ì¤ò»ý¤Ä¡£
995
996     </ul>
997
998     <li> ¼ï¡¹¤Î¥ª¥Ö¥¸¥§¥¯¥È¤ò¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç¥×¥ê¥ó¥È¤¹¤ë´Ø¿ô¡£¾ÜºÙ¤Ï
999     ´Ø¿ô mdebug_dump_XXXX () ¤ÎÀâÌÀ»²¾È¡£
1000
1001     <li> ¥¨¥é¡¼È¯À¸»þ¤Ë¸Æ¤Ð¤ì¤ë¥Õ¥Ã¥¯´Ø¿ô¡£mdebug_hook () ¤ÎÀâÌÀ»²¾È¡£
1002
1003     </ul>
1004 */
1005
1006 /*=*/
1007 /*** @{ */
1008 /*=*/
1009
1010 /***en
1011     @brief Hook function called on an error.
1012
1013     The mdebug_hook () function is called when an error happens.  It
1014     returns -1 without doing anything.  It is useful to set a break
1015     point on this function in a debugger.  */ 
1016 /***ja
1017     @brief ¥¨¥é¡¼¤ÎºÝ¤Ë¸Æ¤Ð¤ì¤ë¥Õ¥Ã¥¯´Ø¿ô.
1018
1019     ´Ø¿ô mdebug_hook () ¤Ï¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿ºÝ¤Ë¸Æ¤Ð¤ì¡¢²¿¤â¤»¤º¤Ë-1 ¤ò
1020     ÊÖ¤¹¡£¥Ç¥Ð¥Ã¥¬Æâ¤Ç¥Ö¥ì¡¼¥¯¥Ý¥¤¥ó¥È¤òÀßÄꤹ¤ë¤¿¤á¤ËÍѤ¤¤ë¤³¤È¤¬¤Ç¤­
1021     ¤ë¡£
1022     */ 
1023
1024 int
1025 mdebug_hook ()
1026 {
1027   return -1;
1028 }
1029
1030 /*=*/
1031
1032 /*** @} */ 
1033
1034 /*
1035   Local Variables:
1036   coding: euc-japan
1037   End:
1038 */