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