(shell_initialized): Delete this variable.
[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., 59 Temple Place, Suite 330, Boston, MA
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 \f
33 /* Internal API */
34
35 \f
36 /* External API */
37
38 void
39 m17n_init (void)
40 {
41   int mdebug_mask = MDEBUG_INIT;
42
43   if (m17n__shell_initialized++)
44     return;
45   m17n_init_core ();
46   if (merror_code != MERROR_NONE)
47     {
48       m17n__shell_initialized--;
49       return;
50     }
51   MDEBUG_PUSH_TIME ();
52   MDEBUG_PUSH_TIME ();
53   if (mcharset__init () < 0)
54     goto err;
55   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize charset module."));
56   if (mcoding__init () < 0)
57     goto err;
58   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize conv module."));
59   if (mdatabase__init () < 0)
60     goto err;
61   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize database module."));
62   if (mcharset__load_from_database () < 0)
63     goto err;
64   MDEBUG_PRINT_TIME ("INIT", (stderr, " to load charset definitions."));
65   if (mcoding__load_from_database () < 0)
66     goto err;
67   MDEBUG_PRINT_TIME ("INIT", (stderr, " to load coding definitions."));
68   if (mchar__init () < 0)
69     goto err;
70   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize character module."));
71   if (mlang__init () < 0)
72     goto err;
73   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize language module"));
74   if (mlocale__init () < 0)
75     goto err;
76   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize locale module."));
77   if (minput__init () < 0)
78     goto err;
79   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize input module."));
80
81  err:
82   MDEBUG_POP_TIME ();
83   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the shell modules."));
84   MDEBUG_POP_TIME ();
85 }
86
87 void
88 m17n_fini (void)
89 {
90   int mdebug_mask = MDEBUG_FINI;
91
92   if (m17n__shell_initialized == 0
93       || --m17n__shell_initialized > 0)
94     return;
95
96   MDEBUG_PUSH_TIME ();
97   MDEBUG_PUSH_TIME ();
98   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize input module."));
99   minput__fini ();
100   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize locale module."));
101   mlocale__fini ();
102   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize language module."));
103   mlang__fini ();
104   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize character module."));
105   mchar__fini ();
106   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize database module."));
107   mdatabase__fini ();
108   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize coding module."));
109   mcoding__fini ();
110   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize charset module."));
111   mcharset__fini ();
112   MDEBUG_POP_TIME ();
113   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the shell modules."));
114   MDEBUG_POP_TIME ();
115   m17n_fini_core ();
116 }
117
118 /*
119   Local Variables:
120   coding: euc-japan
121   End:
122 */