1 /* language.c -- language module.
2 Copyright (C) 2003, 2004
3 National Institute of Advanced Industrial Science and Technology (AIST)
4 Registration Number H15PRO112
6 This file is part of the m17n library.
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.
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.
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
26 #include "m17n-misc.h"
32 #if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
34 static MSymbol M_script_lang_list;
45 Mlanguage = msymbol ("language");
46 msymbol_put (Mlanguage, Mtext_prop_serializer,
47 (void *) msymbol__serializer);
48 msymbol_put (Mlanguage, Mtext_prop_deserializer,
49 (void *) msymbol__deserializer);
50 Miso639_2 = msymbol ("iso639-2");
51 Miso639_1 = msymbol ("iso639-1");
52 M_script_lang_list = msymbol_as_managing_key (" script-lang-list");
54 mdb = mdatabase_find (msymbol ("standard"), Mlanguage,
55 msymbol ("iso639"), Mnil);
58 if (! (plist = mdatabase_load (mdb)))
59 MERROR (MERROR_DB, -1);
64 MSymbol code3, code2, lang;
65 MText *native, *extra;
67 if (! MPLIST_PLIST_P (pl))
69 p = MPLIST_PLIST (pl);
70 if (! MPLIST_SYMBOL_P (p))
72 code3 = MPLIST_SYMBOL (p);
74 if (! MPLIST_SYMBOL_P (p))
76 code2 = MPLIST_SYMBOL (p);
78 if (! MPLIST_SYMBOL_P (p))
80 lang = MPLIST_SYMBOL (p);
81 msymbol_put (code3, Mlanguage, lang);
83 native = MPLIST_MTEXT_P (p) ? MPLIST_MTEXT (p) : NULL;
86 msymbol_put (code3, Mtext, native);
88 extra = MPLIST_MTEXT_P (p) ? MPLIST_MTEXT (p) : NULL;
90 mtext_put_prop (native, 0, mtext_nchars (native), Mtext, extra);
94 msymbol_put (code3, Miso639_1, code2);
95 msymbol_put (code2, Mlanguage, lang);
96 msymbol_put (code2, Miso639_2, code3);
98 msymbol_put (code2, Mtext, native);
101 M17N_OBJECT_UNREF (plist);
111 /** Return a plist of languages that use SCRIPT. If SCRIPT is Mnil,
112 return a plist of all languages. Each element of the plist has
113 3-letter language code as a key and 2-letter language code as a
114 value. A caller must unref the returned value when finished. */
117 mlanguage__list (MSymbol script)
120 MPlist *language_list, *plist, *pl;
124 if ((language_list = msymbol_get (script, M_script_lang_list)))
126 M17N_OBJECT_REF (language_list);
127 return language_list;
129 mdb = mdatabase_find (msymbol ("unicode"), Mscript, Mlanguage, Mnil);
131 || ! (plist = mdatabase_load (mdb)))
132 MERROR (MERROR_DB, NULL);
133 MPLIST_DO (pl, plist)
135 MPlist *p, *lang_list;
136 MSymbol code3, code2;
138 if (! MPLIST_PLIST_P (pl))
140 p = MPLIST_PLIST (pl);
141 if (! MPLIST_SYMBOL_P (p))
143 lang_list = mplist ();
144 if (MPLIST_SYMBOL (p) == script)
145 language_list = lang_list;
146 msymbol_put (MPLIST_SYMBOL (p), M_script_lang_list, lang_list);
147 MPLIST_DO (p, MPLIST_NEXT (p))
148 if (MPLIST_SYMBOL_P (p))
150 code2 = MPLIST_SYMBOL (p);
151 if (MSYMBOL_NAMELEN (code2) == 2)
152 code3 = msymbol_get (code2, Miso639_2);
154 code3 = code2, code2 = Mnil;
156 mplist_push (lang_list, code3, code2);
158 M17N_OBJECT_UNREF (lang_list);
160 M17N_OBJECT_UNREF (plist);
162 M17N_OBJECT_REF (language_list);
165 language_list = mplist ();
166 msymbol_put (script, M_script_lang_list, language_list);
171 mdb = mdatabase_find (msymbol ("standard"), Mlanguage,
172 msymbol ("iso639"), Mnil);
174 || ! (plist = mdatabase_load (mdb)))
175 MERROR (MERROR_DB, NULL);
176 MPLIST_DO (pl, plist)
179 MSymbol code3, code2;
181 if (! MPLIST_PLIST_P (pl))
183 p = MPLIST_PLIST (pl);
184 if (! MPLIST_SYMBOL_P (p))
186 code3 = MPLIST_SYMBOL (p);
188 if (! MPLIST_SYMBOL_P (p))
190 code2 = MPLIST_SYMBOL (p);
191 mplist_push (language_list, code3, code2);
193 M17N_OBJECT_UNREF (plist);
195 return language_list;
198 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
203 MSymbol Miso639_1, Miso639_2;