Update FSF postal address.
[m17n/m17n-lib.git] / src / m17n.c
1 /* m17n.c -- body of the SHELL 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., 51 Franklin Street, Fifth Floor,
21    02111-1307, USA.  */
22
23 #include <config.h>
24 #include <stdio.h>
25
26 #include "m17n.h"
27 #include "m17n-misc.h"
28 #include "internal.h"
29 #include "charset.h"
30 #include "coding.h"
31
32 #if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
33
34 \f
35 /* Internal API */
36
37 \f
38 /* External API */
39
40 void
41 m17n_init (void)
42 {
43   int mdebug_mask = MDEBUG_INIT;
44
45   merror_code = MERROR_NONE;
46   if (m17n__shell_initialized++)
47     return;
48   m17n_init_core ();
49   if (merror_code != MERROR_NONE)
50     {
51       m17n__shell_initialized--;
52       return;
53     }
54   MDEBUG_PUSH_TIME ();
55   MDEBUG_PUSH_TIME ();
56   if (mcharset__init () < 0)
57     goto err;
58   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize charset module."));
59   if (mcoding__init () < 0)
60     goto err;
61   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize conv module."));
62   if (mdatabase__init () < 0)
63     goto err;
64   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize database module."));
65   if (mcharset__load_from_database () < 0)
66     goto err;
67   MDEBUG_PRINT_TIME ("INIT", (stderr, " to load charset definitions."));
68   if (mcoding__load_from_database () < 0)
69     goto err;
70   MDEBUG_PRINT_TIME ("INIT", (stderr, " to load coding definitions."));
71   if (mchar__init () < 0)
72     goto err;
73   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize character module."));
74   if (mlang__init () < 0)
75     goto err;
76   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize language module"));
77   if (mlocale__init () < 0)
78     goto err;
79   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize locale module."));
80   if (minput__init () < 0)
81     goto err;
82   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize input module."));
83
84  err:
85   MDEBUG_POP_TIME ();
86   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the shell modules."));
87   MDEBUG_POP_TIME ();
88 }
89
90 void
91 m17n_fini (void)
92 {
93   int mdebug_mask = MDEBUG_FINI;
94
95   if (m17n__shell_initialized == 0
96       || --m17n__shell_initialized > 0)
97     return;
98
99   MDEBUG_PUSH_TIME ();
100   MDEBUG_PUSH_TIME ();
101   minput__fini ();
102   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize input module."));
103   mlocale__fini ();
104   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize locale module."));
105   mlang__fini ();
106   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize language module."));
107   mchar__fini ();
108   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize character module."));
109   mdatabase__fini ();
110   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize database module."));
111   mcoding__fini ();
112   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize coding module."));
113   mcharset__fini ();
114   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize charset module."));
115   MDEBUG_POP_TIME ();
116   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the shell modules."));
117   MDEBUG_POP_TIME ();
118   m17n_fini_core ();
119 }
120
121 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
122
123 /*
124   Local Variables:
125   coding: euc-japan
126   End:
127 */