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