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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include <sys/types.h>
28 #if defined STDC_HEADERS || defined _LIBC
38 #if defined HAVE_STRING_H || defined _LIBC
43 # define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num)
46 #if !HAVE_STRCHR && !defined _LIBC
52 #if defined HAVE_UNISTD_H || defined _LIBC
61 # include "libgettext.h"
64 /* @@ end of prolog @@ */
65 /* List of already loaded domains. */
67 static struct loaded_l10nfile *_nl_loaded_domains;
70 /* Return a data structure describing the message catalog described by
71 the DOMAINNAME and CATEGORY parameters with respect to the currently
72 established bindings. */
73 struct loaded_l10nfile *
75 _nl_find_domain (dirname, locale, domainname)
78 const char *domainname;
80 struct loaded_l10nfile *retval;
83 const char *territory;
85 const char *normalized_codeset;
89 const char *alias_value;
92 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
94 language[_territory[.codeset]][@modifier]
96 and six parts for the CEN syntax:
98 language[_territory][+audience][+special][,[sponsor][_revision]]
100 Beside the first part all of them are allowed to be missing. If
101 the full specified locale is not found, the less specific one are
102 looked for. The various parts will be stripped off according to
108 (5) normalized codeset
110 (7) audience/modifier
113 /* If we have already tested for this locale entry there has to
114 be one data set in the list of loaded domains. */
115 retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
116 strlen (dirname) + 1, 0, locale, NULL, NULL,
117 NULL, NULL, NULL, NULL, NULL, domainname, 0);
120 /* We know something about this locale. */
123 if (retval->decided == 0)
124 _nl_load_domain (retval);
126 if (retval->data != NULL)
129 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
131 if (retval->successor[cnt]->decided == 0)
132 _nl_load_domain (retval->successor[cnt]);
134 if (retval->successor[cnt]->data != NULL)
137 return cnt >= 0 ? retval : NULL;
141 /* See whether the locale value is an alias. If yes its value
142 *overwrites* the alias name. No test for the original value is
144 alias_value = _nl_expand_alias (locale);
145 if (alias_value != NULL)
147 #if defined _LIBC || defined HAVE_STRDUP
148 locale = strdup (alias_value);
152 size_t len = strlen (alias_value) + 1;
153 locale = (char *) malloc (len);
157 memcpy (locale, alias_value, len);
161 /* Now we determine the single parts of the locale name. First
162 look for the language. Termination symbols are `_' and `@' if
163 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
164 mask = _nl_explode_name (locale, &language, &modifier, &territory,
165 &codeset, &normalized_codeset, &special,
166 &sponsor, &revision);
168 /* Create all possible locale entries which might be interested in
170 retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
171 strlen (dirname) + 1, mask, language, territory,
172 codeset, normalized_codeset, modifier, special,
173 sponsor, revision, domainname, 1);
175 /* This means we are out of core. */
178 if (retval->decided == 0)
179 _nl_load_domain (retval);
180 if (retval->data == NULL)
183 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
185 if (retval->successor[cnt]->decided == 0)
186 _nl_load_domain (retval->successor[cnt]);
187 if (retval->successor[cnt]->data != NULL)
192 /* The room for an alias was dynamically allocated. Free it now. */
193 if (alias_value != NULL)
201 static void __attribute__ ((unused))
204 struct loaded_l10nfile *runp = _nl_loaded_domains;
208 struct loaded_l10nfile *here = runp;
209 if (runp->data != NULL)
210 _nl_unload_domain ((struct loaded_domain *) runp->data);
216 text_set_element (__libc_subfreeres, free_mem);