1 /* Handle list of needed message catalogs
2 Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
3 Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. */
19 #include "intlconfig.h"
24 #include <sys/types.h>
26 #if defined STDC_HEADERS || defined _LIBC
36 #if defined HAVE_STRING_H || defined _LIBC
41 # define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num)
44 #if !HAVE_STRCHR && !defined _LIBC
50 #if defined HAVE_UNISTD_H || defined _LIBC
59 # include "libgettext.h"
62 /* @@ end of prolog @@ */
63 /* List of already loaded domains. */
64 static struct loaded_l10nfile *_nl_loaded_domains;
67 /* Return a data structure describing the message catalog described by
68 the DOMAINNAME and CATEGORY parameters with respect to the currently
69 established bindings. */
70 struct loaded_l10nfile *
72 _nl_find_domain (dirname, locale, domainname)
75 const char *domainname;
77 struct loaded_l10nfile *retval;
80 const char *territory;
82 const char *normalized_codeset;
86 const char *alias_value;
89 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
91 language[_territory[.codeset]][@modifier]
93 and six parts for the CEN syntax:
95 language[_territory][+audience][+special][,[sponsor][_revision]]
97 Beside the first part all of them are allowed to be missing. If
98 the full specified locale is not found, the less specific one are
99 looked for. The various parts will be stripped off according to
105 (5) normalized codeset
107 (7) audience/modifier
110 /* If we have already tested for this locale entry there has to
111 be one data set in the list of loaded domains. */
112 retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
113 strlen (dirname) + 1, 0, locale, NULL, NULL,
114 NULL, NULL, NULL, NULL, NULL, domainname, 0);
117 /* We know something about this locale. */
120 if (retval->decided == 0)
121 _nl_load_domain (retval);
123 if (retval->data != NULL)
126 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
128 if (retval->successor[cnt]->decided == 0)
129 _nl_load_domain (retval->successor[cnt]);
131 if (retval->successor[cnt]->data != NULL)
134 return cnt >= 0 ? retval : NULL;
138 /* See whether the locale value is an alias. If yes its value
139 *overwrites* the alias name. No test for the original value is
141 alias_value = _nl_expand_alias (locale);
142 if (alias_value != NULL)
144 #if defined _LIBC || defined HAVE_STRDUP
145 locale = strdup (alias_value);
149 size_t len = strlen (alias_value) + 1;
150 locale = (char *) malloc (len);
154 memcpy (locale, alias_value, len);
158 /* Now we determine the single parts of the locale name. First
159 look for the language. Termination symbols are `_' and `@' if
160 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
161 mask = _nl_explode_name (locale, &language, &modifier, &territory,
162 &codeset, &normalized_codeset, &special,
163 &sponsor, &revision);
165 /* Create all possible locale entries which might be interested in
167 retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
168 strlen (dirname) + 1, mask, language, territory,
169 codeset, normalized_codeset, modifier, special,
170 sponsor, revision, domainname, 1);
172 /* This means we are out of core. */
175 if (retval->decided == 0)
176 _nl_load_domain (retval);
177 if (retval->data == NULL)
180 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
182 if (retval->successor[cnt]->decided == 0)
183 _nl_load_domain (retval->successor[cnt]);
184 if (retval->successor[cnt]->data != NULL)
189 /* The room for an alias was dynamically allocated. Free it now. */
190 if (alias_value != NULL)
198 static void __attribute__ ((unused))
201 struct loaded_l10nfile *runp = _nl_loaded_domains;
205 struct loaded_l10nfile *here = runp;
206 if (runp->data != NULL)
207 _nl_unload_domain ((struct loaded_domain *) runp->data);
213 text_set_element (__libc_subfreeres, free_mem);