(mdebug__report_object): Free array->objectes if
[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 don't 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.  They load
41     various kinds of data from the database on demand.  To use this
42     API, an application program must include <m17n.h> and be linked by
43     -lm17n-core -lm17n.  With that, CORE API is also available.
44
45     <li> GUI API
46
47     It provides GUI modules such as drawing and inputting M-texts on a
48     window system.  The API itself is independent on a window system,
49     but the m17n library must be configured to use a specific window
50     system.  Currently, we support only the X Window System.  To use
51     this API, an application program must include <m17n-gui.h> and
52     <m17n-X.h>, and be linked by -lm17n-core -lm17n -lm17n-X.  With
53     that, CORE and SHELL APIs are also available.
54
55     <li> MISC API
56
57     It provides miscellaneous functions to support error handling and
58     debugging.  This API can't be used by itself, but with one or more
59     APIs listed above.  To use the API, an application program must
60     include <m17n-misc.h> in addition to one of <m17n-core.h>,
61     <m17n.h>, and <m17n-gui.h>.
62
63     </ol>
64
65     See also the section @ref m17n-config "m17n-config(1)".
66
67     <em>ENVIRONMENT VARIABLE</em>
68
69     The m17n library pays attention to these environment variables.
70
71     <ul>
72     <li> @c M17NDIR
73
74     Name of a directory that contains data of the m17n database.  See
75     @ref m17nDatabase for the detail.
76
77     <li> @c MDEBUG_XXXX
78
79     Environment variables whose name start by "MDEBUG_" controls
80     printing of debug information.  See @ref m17nDebug for the detail.
81
82     </ul>
83
84     <em>API NAMING CONVENTION</em>
85
86     The library exports functions, variables, macros, and types.  All
87     of them start by the letter 'm' or 'M' followed by an object name
88     (e.g. "symbol" and "plist", but "mtext" object is given the name
89     "text" to avoid double 'm' at the head) or a module name
90     (e.g. draw, input).
91     
92     <ul>
93
94     <li> functions -- mobject () or mobject_xxx ()
95
96     They start with 'm' followed by lower case object name.  For
97     example, msymbol (), mtext_ref_char (), mdraw_text ().
98
99     <li> non-symbol variables -- mobject, or mobject_xxx
100     
101     The naming convention is the same as functions (e.g. mface_large).
102
103     <li> symbol variables -- Mname
104
105     Variables of type MSymbol start with 'M' followed by their names
106     (e.g. Mlanguage (name is "langauge"), Miso_2022 (name is
107     "iso-2022").
108
109     <li> macross -- MOBJECT_XXX
110
111     They start by 'M' followed by upper case object names.
112
113     <li> types -- MObject or MObjectXxx
114
115     They start by 'M' followed by capitalized object names (e.g.
116     MConverter, MInputDriver).
117
118     </ul>
119
120   */
121
122 /***ja
123     @addtogroup m17nIntro
124
125     @e m17n¥é¥¤¥Ö¥é¥ê ¤Ï C ¸À¸ìÍÑ¿¸À¸ì¾ðÊó½èÍý¥é¥¤¥Ö¥é¥ê¤Ç¤¢¤ë¡£
126     ¤³¤Î¥é¥¤¥Ö¥é¥ê¤Ï¡¢Â¿¸À¸ìʸ½ñ¤ò°·¤¦¤¿¤á¤ËɬÍפʰʲ¼¤Î´ðËܵ¡Ç½¤ò¥¢¥×
127     ¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤ËÄ󶡤¹¤ë¡£
128
129     @li Â¿¸À¸ì¥Æ¥­¥¹¥ÈÍÑ¥ª¥Ö¥¸¥§¥¯¥È¤È¤·¤Æ¤Î¹½Â¤ÂΠ@e M-text
130
131     @li M-text ¤ò°·¤¦¤¿¤á¤Î¿¤¯¤Î´Ø¿ô¡¦¥Þ¥¯¥í·²
132
133     @li ¼ï¡¹¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Æ¥­¥¹¥È¤È M-text ´Ö¤ÎÊÑ´¹
134     ¤ò¹Ô¤Ê¤¦¥Ç¥³¡¼¥À¡¿¥¨¥ó¥³¡¼¥À
135
136     @li Unicode ¤ÎÁ´¤Æ¤Îʸ»ú¤Ë²Ã¤¨¡¢¤½¤ì¤ÈƱ¤¸¿ô¤ÎÈó Unicode Ê¸»ú¤ò°·
137     ¤¨¤ëµðÂç¤Êʸ»ú¶õ´Ö
138
139     @li Ê¸»úËè¤Î¾ðÊó¤ò¸úΨÎɤ¯³ÊǼ¤¹¤ë¹½Â¤ÂΠ@e Ê¸»ú¥Æ¡¼¥Ö¥ë (CharTable)
140
141     @li ¥ª¥×¥·¥ç¥ó¡§M-text¤Î¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¾å¤Ç¤Îɽ¼¨¡¦ÆþÎÏ¥·¥¹¥Æ¥à¡£
142     ¡Ê¤³¤Î¤¿¤á¤Î API ¤Ï m17n-win.h ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë¡£¡Ë  */
143 /*=*/
144 /*** @{ */
145 #ifdef FOR_DOXYGEN
146 /***en
147     The #M17NLIB_MAJOR_VERSION macro gives the major version number
148     of the m17n library.  */
149
150 /***ja
151     ¥Þ¥¯¥í #M17NLIB_MAJOR_VERSION ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤Î¥á¥¸¥ã¡¼¥Ð¡¼¥¸¥ç
152     ¥óÈÖ¹æ¤òÍ¿¤¨¤ë¡£  */
153
154 #define M17NLIB_MAJOR_VERSION
155
156 /*=*/
157
158 /***en
159     The #M17NLIB_MINOR_VERSION macro gives the minor version number
160     of the m17n library.  */
161
162 /***ja
163     ¥Þ¥¯¥í #M17NLIB_MINOR_VERSION ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤Î¥Þ¥¤¥Ê¡¼¥Ð¡¼¥¸¥ç
164     ¥óÈÖ¹æ¤òÍ¿¤¨¤ë¡£  */
165
166 #define M17NLIB_MINOR_VERSION
167
168 /*=*/
169
170 /***en
171     The #M17NLIB_PATCH_LEVEL macro gives the patch level number
172     of the m17n library.  */
173
174 /***ja
175     ¥Þ¥¯¥í #M17NLIB_PATCH_LEVEL ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤Î¥Ñ¥Ã¥Á¥ì¥Ù¥ëÈÖ¹æ¤ò
176     Í¿¤¨¤ë¡£  */
177
178 #define M17NLIB_PATCH_LEVEL
179
180 /*=*/
181
182 /***en
183     The #M17NLIB_VERSION_NAME macro gives the version name of the
184     m17n library as a string.  */
185
186 /***ja
187     ¥Þ¥¯¥í #M17NLIB_VERSION_NAME ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤Î¥Ð¡¼¥¸¥ç¥ó̾¤ò
188     C-string ¤Î·Á¤ÇÍ¿¤¨¤ë¡£  */
189
190 #define M17NLIB_VERSION_NAME
191
192 /*=*/
193
194 /***en
195     @brief Initialize the m17n library.
196
197     The macro M17N_INIT () initializes the m17n library.  This
198     function must be called before any m17n functions are used.
199
200     If the initialization was successful, the external variable @c
201     merror_code is set to 0.  Otherwise it is set to -1.  */
202
203 /***ja
204     @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î½é´ü²½
205
206     ¥Þ¥¯¥í M17N_INIT () ¤Ï m17n ¥é¥¤¥Ö¥é¥ê¤ò½é´ü²½¤¹¤ë¡£m17n ¥é¥¤¥Ö¥é
207     ¥ê¤ò»È¤¦¤È¤­¤Ï¡¢ºÇ½é¤Ë¤³¤Î´Ø¿ô¤ò¸Æ¤Ð¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
208
209     ÊÑ¿ô #merror_code ¤Ï¡¢½é´ü²½¤¬À®¸ù¤¹¤ì¤Ð 0 ¤Ë¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 
210     ¤ËÀßÄꤵ¤ì¤ë¡£  */
211
212 #define M17N_INIT()
213
214 /*=*/
215
216 /***en
217     @brief Finalize the m17n library.
218
219     The macro M17N_FINI () finalizes the m17n library.  It frees all the
220     memory area used by the m17n library.  Once this function is
221     called, no m17n functions should be used until the
222     macro M17N_INIT () is called again.  */
223
224 /***ja
225     @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î½ªÎ»  */
226
227 #define M17N_FINI()
228 #endif /* FOR_DOXYGEN */
229 /*=*/
230 /*** @} */ 
231 /*=*/
232
233 #if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
234 /*** @addtogroup m17nInternal
235      @{ */
236
237 #include <config.h>
238 #include <stdio.h>
239 #include <stdlib.h>
240 #include <sys/time.h>
241 #include <sys/resource.h>
242 #include <unistd.h>
243
244 #include "m17n-core.h"
245 #include "m17n-misc.h"
246 #include "internal.h"
247
248 static int core_initialized;
249
250 static void
251 default_error_handler (enum MErrorCode err)
252 {
253   exit (err);
254 }
255
256 static struct timeval time_stack[16];
257 static int time_stack_index;
258
259 static int report_header_printed;
260
261 \f
262 /* Internal API */
263
264 void
265 mdebug__report_object (char *name, M17NObjectArray *array)
266 {
267   if (! (mdebug__flag & MDEBUG_FINI))
268     return;
269   if (! report_header_printed)
270     {
271       fprintf (stderr, "%16s %7s %7s %7s\n",
272                "object", "created", "freed", "alive");
273       fprintf (stderr, "%16s %7s %7s %7s\n",
274                "------", "-------", "-----", "-----");
275       report_header_printed = 1;
276     }
277   fprintf (stderr, "%16s %7d %7d %7d\n", name,
278            array->used, array->used - array->count, array->count);
279   if (array->used > 0)
280     {
281       free (array->objects);
282       array->count = array->used = 0;
283     }
284 }
285
286
287 void *(*mdatabase__finder) (MSymbol tag1, MSymbol tag2,
288                            MSymbol tag3, MSymbol tag4);
289 void *(*mdatabase__loader) (void *);
290
291 int mdebug__flag;
292
293 void
294 mdebug__push_time ()
295 {
296   struct timezone tz;
297
298   gettimeofday (time_stack + time_stack_index++, &tz);
299 }
300
301 void
302 mdebug__pop_time ()
303 {
304   time_stack_index--;
305 }
306
307 void
308 mdebug__print_time ()
309 {
310   struct timeval tv;
311   struct timezone tz;
312   long diff;
313
314   gettimeofday (&tv, &tz);
315   diff = ((tv.tv_sec - time_stack[time_stack_index - 1].tv_sec) * 1000000
316           + (tv.tv_usec - time_stack[time_stack_index - 1].tv_usec));
317   fprintf (stderr, "%8ld ms.", diff);
318   time_stack[time_stack_index - 1] = tv;
319 }
320
321 #define SET_DEBUG_FLAG(env_name, mask)          \
322   do {                                          \
323     char *env_value = getenv (env_name);        \
324                                                 \
325     if (env_value && env_value[0] == '1')       \
326       mdebug__flag |= (mask);                   \
327   } while (0)
328
329
330 \f
331 /* External API */
332
333 /* The following two are actually not exposed to a user but concealed
334    by the macro M17N_INIT (). */
335
336 void
337 m17n_init_core (void)
338 {
339   int mdebug_mask = MDEBUG_INIT;
340
341   if (core_initialized)
342     return;
343
344   merror_code = MERROR_NONE;
345   m17n_memory_full_handler = default_error_handler;
346
347   mdebug__flag = 0;
348   SET_DEBUG_FLAG ("MDEBUG_INIT", MDEBUG_INIT);
349   SET_DEBUG_FLAG ("MDEBUG_FINI", MDEBUG_FINI);
350   SET_DEBUG_FLAG ("MDEBUG_CHARSET", MDEBUG_CHARSET);
351   SET_DEBUG_FLAG ("MDEBUG_CODING", MDEBUG_CODING);
352   SET_DEBUG_FLAG ("MDEBUG_DATABASE", MDEBUG_DATABASE);
353   SET_DEBUG_FLAG ("MDEBUG_FONT", MDEBUG_FONT); 
354   SET_DEBUG_FLAG ("MDEBUG_FONT_FLT", MDEBUG_FONT_FLT);
355   SET_DEBUG_FLAG ("MDEBUG_FONT_OTF", MDEBUG_FONT_OTF);
356   SET_DEBUG_FLAG ("MDEBUG_INPUT", MDEBUG_INPUT);
357
358   MDEBUG_PUSH_TIME ();
359   MDEBUG_PUSH_TIME ();
360   if (msymbol__init () < 0)
361     goto err;
362   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize symbol module."));
363   if  (mplist__init () < 0)
364     goto err;
365   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize plist module."));
366   if (mtext__init () < 0)
367     goto err;
368   if (mtext__prop_init () < 0)
369     goto err;
370   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize mtext module."));
371   if  (mchartable__init () < 0)
372     goto err;
373   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize chartable module."));
374
375   mdatabase__finder = NULL;
376   mdatabase__loader = NULL;
377   core_initialized = 1;
378
379  err:
380   MDEBUG_POP_TIME ();
381   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the core modules."));
382   MDEBUG_POP_TIME ();
383 }
384
385 void
386 m17n_fini_core (void)
387 {
388   int mdebug_mask = MDEBUG_FINI;
389
390   if (core_initialized)
391     {
392       MDEBUG_PUSH_TIME ();
393       MDEBUG_PUSH_TIME ();
394       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize chartable module."));
395       mchartable__fini ();
396       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize textprop module."));
397       mtext__prop_fini ();
398       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize mtext module."));
399       mtext__fini ();
400       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize symbol module."));
401       msymbol__fini ();
402       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize plist module."));
403       mplist__fini ();
404       core_initialized = 0;
405       MDEBUG_POP_TIME ();
406       MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the core modules."));
407       MDEBUG_POP_TIME ();
408     }
409   report_header_printed = 0;
410 }
411
412 /*** @} */
413 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
414 /*=*/
415
416 /***en
417     @addtogroup m17nObject
418     @brief Managed objects are objects managed by the reference count.
419
420     There are some types of m17n objects that are managed by their
421     reference count.  Those objects are called @e managed @e objects.
422     When created, the reference count of a managed object is
423     initialized to one.  The m17n_object_ref () function increments
424     the reference count of a managed object by one, and the
425     m17n_object_unref () function decrements by one.  A managed
426     object is automatically freed when its reference count becomes
427     zero.
428
429     A property whose key is a managing key can have only a managed
430     object as its value.  Such functions as msymbol_put () and
431     mplist_put () pay special attention to such a property.
432
433     In addition to the predefined managed object types, users can
434     define their own managed object types.  See the documentation of
435     the m17n_object () for the details.  */
436
437 /*** @{  */
438 /*=*/
439 /***en
440     @brief Allocate a managed object.
441
442     The m17n_object () function allocates a new managed object of
443     $SIZE bytes and sets its reference count to 1.  $FREER is the
444     function that is used to free the object when the reference count
445     becomes 0.  If $FREER is NULL, the object is freed by the free ()
446     function.
447
448     The heading bytes of the allocated object is occupied by
449     #M17NObjectHead.  That area is reserved for the m17n library and
450     application programs should never touch it.
451
452     @return
453     This function returns a newly allocated object.
454
455     @errors
456     This function never fails.  */
457
458 #if EXAMPLE_CODE
459 typedef struct
460 {
461   M17NObjectHead head;
462   int mem1;
463   char *mem2;
464 } MYStruct;
465
466 void
467 my_freer (void *obj)
468 {
469   free (((MYStruct *) obj)->mem2);
470   free (obj);
471 }
472
473 void
474 my_func (MText *mt, MSymbol key, int num, char *str)
475 {
476   MYStruct *st = m17n_object (sizeof (MYStruct), my_freer);
477
478   st->mem1 = num;
479   st->mem2 = strdup (str);
480   /* KEY must be a managing key.   */
481   mtext_put_prop (mt, 0, mtext_len (mt), key, st);
482   /* This sets the reference count of ST back to 1.  */
483   m17n_object_unref (st);
484 }
485 #endif
486
487 void *
488 m17n_object (int size, void (*freer) (void *))
489 {
490   M17NObject *obj = malloc (size);
491
492   obj->ref_count = 1;
493   obj->u.freer = freer;
494   return obj;
495 }
496
497 /*=*/
498
499 /***en
500     @brief Increment the reference count of a managed object.
501
502     The m17n_object_ref () function increments the reference count of
503     the managed object pointed to by $OBJECT.
504
505     @return
506     This function returns the resulting reference count if it fits in
507     a 16-bit unsigned integer (i.e. less than 0x10000).  Otherwise, it
508     return -1.
509
510     @errors
511     This function never fails.  */
512
513 int
514 m17n_object_ref (void *object)
515 {
516   M17NObject *obj = (M17NObject *) object;
517   M17NObjectRecord *record;
518   unsigned *count;
519
520   if (! obj->ref_count_extended)
521     {
522       if (++obj->ref_count)
523         return (int) obj->ref_count;
524       MSTRUCT_MALLOC (record, MERROR_OBJECT);
525       record->freer = obj->u.freer;
526       MLIST_INIT1 (record, counts, 1);
527       MLIST_APPEND1 (record, counts, 0, MERROR_OBJECT);
528       obj->u.record = record;
529       obj->ref_count_extended = 1;
530     }
531   else
532     record = obj->u.record;
533
534   count = record->counts;
535   while (*count == 0xFFFFFFFF)
536     *(count++) = 0;
537   (*count)++;
538   if (*count == 0xFFFFFFFF)
539     MLIST_APPEND1 (record, counts, 0, MERROR_OBJECT);
540   return -1;
541 }
542
543 /*=*/
544
545 /***en
546     @brief Decrement the reference count of a managed object.
547
548     The m17n_object_unref () function decrements the reference count
549     of the managed object pointed to by $OBJECT.  When the reference
550     count becomes zero, the object is freed by its freer function.
551
552     @return
553     This function returns the resulting reference count if it fits in
554     a 16-bit unsigned integer (i.e. less than 0x10000).  Otherwise, it
555     returns -1.  Thus, the return value zero means that $OBJECT is
556     freed.
557
558     @errors
559     This function never fails.  */
560
561 int
562 m17n_object_unref (void *object)
563 {
564   M17NObject *obj = (M17NObject *) object;
565   M17NObjectRecord *record;
566   unsigned *count;
567
568   if (! obj->ref_count_extended)
569     {
570       if (! --obj->ref_count)
571         {
572           if (obj->u.freer)
573             (obj->u.freer) (object);
574           else
575             free (object);
576           return 0;
577         }
578       return (int) obj->ref_count;
579     }
580
581   record = obj->u.record;
582   count = record->counts;
583   while (! *count)
584     *(count++) = 0xFFFFFFFF;
585   (*count)--;
586   if (! record->counts[0])
587     {
588       obj->ref_count_extended = 0;
589       obj->ref_count--;
590       obj->u.freer = record->freer;
591       MLIST_FREE1 (record, counts);
592       free (record);
593     }
594   return -1;
595 }
596
597 /*=*/
598
599 /*** @} */
600
601 /***en
602     @addtogroup m17nError Error handling
603     @brief Error handling of the m17n library.
604
605     There are two types of errors that may happen in a function of
606     the m17n library.
607
608     The first type is argument errors.  When a library function is
609     called with invalid arguments, it returns a value that indicates
610     error and at the same time sets the external variable @e
611     merror_code to a non-zero integer.
612
613     The second type is memory allocation errors.  When the required
614     amount of memory is not available on the system, m17n library
615     functions call a function pointed to by the external variable @c
616     m17n_memory_full_handler.  The default value of the variable is a
617     pointer to the default_error_handle () function, which just calls
618     exit ().  */
619
620 /***ja
621     @addtogroup m17nError ¥¨¥é¡¼½èÍý
622     @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼½èÍý
623
624     m17n ¥é¥¤¥Ö¥é¥ê¤Î´Ø¿ô¤Ç¤Ï¡¢£²¤Ä¤Î¼ïÎà¤Î¥¨¥é¡¼¤¬µ¯¤³¤êÆÀ¤ë¡£
625
626     °ì¤Ä¤Ï°ú¿ô¤Î¥¨¥é¡¼¤Ç¤¢¤ë¡£¥é¥¤¥Ö¥é¥ê¤Î´Ø¿ô¤¬ÂÅÅö¤Ç¤Ê¤¤°ú¿ô¤È¤È¤â¤Ë
627     ¸Æ¤Ð¤ì¤¿¾ì¹ç¡¢¤½¤Î´Ø¿ô¤Ï¥¨¥é¡¼¤ò°ÕÌ£¤¹¤ëÃͤòÊÖ¤·¡¢Æ±»þ¤Ë³°ÉôÊÑ¿ô 
628     #merror_code ¤Ë¥¼¥í¤Ç¤Ê¤¤À°¿ô¤ò¥»¥Ã¥È¤¹¤ë¡£
629
630     ¤â¤¦°ì¤Ä¤Î¼ïÎà¤Ï¥á¥â¥ê³äÅö¤Æ¥¨¥é¡¼¤Ç¤¢¤ë¡£¥·¥¹¥Æ¥à¤¬É¬ÍפÊÎ̤Υá¥â
631     ¥ê¤ò³äÅö¤Æ¤ë¤³¤È¤¬¤Ç¤­¤Ê¤¤¾ì¹ç¡¢¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ï³°ÉôÊÑ¿ô @c
632     m17n_memory_full_handler ¤¬»Ø¤¹´Ø¿ô¤ò¸Æ¤Ö¡£¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢Ã±¤Ë
633     <tt>exit ()</tt> ¤ò¸Æ¤Ö¤³¤È¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
634 */
635
636 /*** @{ */
637
638 /*=*/
639
640 /***en @brief External variable to hold error code of the m17n library
641
642     The external variable #merror_code holds an error code of the
643     m17n library.  When a library function is called with an invalid
644     argument, it sets this variable to one of @c enum #MErrorCode.
645
646     This variable initially has the value 0.  */
647
648 /***ja @brief m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼¥³¡¼¥É¤òÊÝ»ý¤¹¤ë³°ÉôÊÑ¿ô
649
650     ³°ÉôÊÑ¿ô #merror_code ¤Ï¡¢m17n ¥é¥¤¥Ö¥é¥ê¤Î¥¨¥é¡¼¥³¡¼¥É¤òÊÝ»ý¤¹¤ë¡£
651     ¥é¥¤¥Ö¥é¥ê´Ø¿ô¤¬ÂÅÅö¤Ç¤Ê¤¤°ú¿ô¤È¤È¤â¤Ë¸Æ¤Ð¤ì¤¿ºÝ¤Ë¤Ï¡¢
652     ¤³¤ÎÊÑ¿ô¤ò @c enum #MErrorCode ¤Î°ì¤Ä¤Ë¥»¥Ã¥È¤¹¤ë¡£
653
654     ¤³¤ÎÊÑ¿ô¤Î½é´üÃͤϣ°¤Ç¤¢¤ë¡£  */
655
656 enum MErrorCode merror_code;
657
658 /*=*/
659
660 /***en @brief Memory allocation error handler
661
662     The external variable #m17n_memory_full_handler holds a pointer
663     to the function to call when a library function failed to allocate
664     memory.  $ERR is one of @c enum #MErrorCode indicating in which
665     function the error occurred.
666
667     This variable initially points a function that simply calls the
668     exit () function with $ERR as an argument.
669
670     An application program that needs a different error handling can
671     change this variable to point a proper function.  */
672
673 /***ja @brief ¥á¥â¥ê³äÅö¤Æ¥¨¥é¡¼¥Ï¥ó¥É¥é
674
675     ÊÑ¿ô #m17n_memory_full_handler ¤Ï¡¢¥é¥¤¥Ö¥é¥ê´Ø¿ô¤¬¥á¥â¥ê³äÅö¤Æ
676     ¤Ë¼ºÇÔ¤·¤¿ºÝ¤Ë¸Æ¤Ö¤Ù¤­´Ø¿ô¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£$ERR ¤Ï @c enum
677     #MErrorCode ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ê¡¢¤É¤Î¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ç¥¨¥é¡¼¤¬µ¯¤Ã¤¿
678     ¤«¤ò¼¨¤¹¡£
679
680     @anchor test
681
682     ½é´üÀßÄê¤Ç¤Ï¡¢¤³¤ÎÊÑ¿ô¤Ïñ¤Ë <tt>exit ()</tt> ¤ò $ERR ¤ò°ú¿ô¤È¤·¤Æ
683     ¸Æ¤Ö´Ø¿ô¤ò»Ø¤·¤Æ¤¤¤ë¡£
684
685     ¤³¤ì¤È¤Ï°Û¤Ê¤ë¥¨¥é¡¼½èÍý¤òɬÍפȤ¹¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¡¢¤³¤ÎÊÑ¿ô¤ò
686     Å¬Åö¤Ê´Ø¿ô¤ËÀßÄꤹ¤ë¤³¤È¤Ç¡¢ÌÜŪ¤òãÀ®¤Ç¤­¤ë¡£  */
687
688 void (*m17n_memory_full_handler) (enum MErrorCode err);
689
690 /*** @} */
691
692 /*=*/
693
694 /***en
695     @addtogroup m17nDebug
696     @brief Support for m17n library users to debug their programs.
697
698     The m17n library provides the following facilities to support the
699     library users to debug their programs.
700
701     <ul>
702
703     <li> Environment variables to control printing of various
704     information.
705
706     <ul>
707
708     <li> MDEBUG_INIT -- If set to 1, print information about the
709     library initialization on the call of M17N_INIT ().
710
711     <li> MDEBUG_FINI -- If set to 1, print counts of objects that are
712     not yet freed on the call of M17N_FINI ().
713
714     <li> MDEBUG_CHARSET -- If set to 1, print information about
715     charsets being loaded from the m17n database.
716
717     <li> MDEBUG_CODING -- If set to 1, print information about coding
718     systems being loaded from the m17n database.
719
720     <li> MDEBUG_DATABASE -- If set to 1, print information about
721     data being loaded from the m17n database.
722
723     <li> MDEBUG_FONT -- If set to 1, print information about fonts
724     being selected and opened.
725
726     <li> MDEBUG_FONT_FLT -- If set to 1, print information about which
727     command of Font Layout Table are being executed.
728
729     <li> MDEBUG_FONT_OTF -- If set to 1, print information about which
730     feature of OpenType Layout Table are being executed.
731
732     <li> MDEBUG_INPUT -- If set to 1, print information about how an
733     input method is running.
734
735     <li> MDEBUG_ALL -- Setting this variable to 1 is equivalent to
736     setting all the above variables to 1.
737
738     </ul>
739
740     <li> Functions to print various objects in a human readable way.
741     See the documentation of mdebug_dump_XXXX () functions.
742
743     <li> The hook function called on an error.  See the documentation
744     of mdebug_hook ().
745
746     </ul>
747 */
748
749 /*=*/
750 /*** @{ */
751 /*=*/
752
753 /***en
754     @brief Hook function called on an error.
755
756     The mdebug_hook () function is called when an error happens.  It
757     returns -1q without doing anything.  It is useful to set a break
758     point on this function in a debugger.  */ 
759
760 int
761 mdebug_hook ()
762 {
763   return -1;
764 }
765
766 /*=*/
767
768 /*** @} */ 
769
770 /*
771   Local Variables:
772   coding: euc-japan
773   End:
774 */