1 /* Handle list of needed message catalogs
2 Copyright (C) 1995, 1996, 1997 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. */
66 static struct loaded_l10nfile *_nl_loaded_domains;
69 /* Return a data structure describing the message catalog described by
70 the DOMAINNAME and CATEGORY parameters with respect to the currently
71 established bindings. */
72 struct loaded_l10nfile *
73 _nl_find_domain (dirname, locale, domainname)
76 const char *domainname;
78 struct loaded_l10nfile *retval;
81 const char *territory;
83 const char *normalized_codeset;
87 const char *alias_value;
90 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
92 language[_territory[.codeset]][@modifier]
94 and six parts for the CEN syntax:
96 language[_territory][+audience][+special][,[sponsor][_revision]]
98 Beside the first all of them are allowed to be missing. If the
99 full specified locale is not found, the less specific one are
100 looked for. The various part will be stripped of according to
106 (5) normalized codeset
108 (7) audience/modifier
111 /* If we have already tested for this locale entry there has to
112 be one data set in the list of loaded domains. */
113 retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
114 strlen (dirname) + 1, 0, locale, NULL, NULL,
115 NULL, NULL, NULL, NULL, NULL, domainname, 0);
118 /* We know something about this locale. */
121 if (retval->decided == 0)
122 _nl_load_domain (retval);
124 if (retval->data != NULL)
127 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
129 if (retval->successor[cnt]->decided == 0)
130 _nl_load_domain (retval->successor[cnt]);
132 if (retval->successor[cnt]->data != NULL)
135 return cnt >= 0 ? retval : NULL;
139 /* See whether the locale value is an alias. If yes its value
140 *overwrites* the alias name. No test for the original value is
142 alias_value = _nl_expand_alias (locale);
143 if (alias_value != NULL)
145 size_t len = strlen (alias_value) + 1;
146 locale = (char *) malloc (len);
150 memcpy (locale, alias_value, len);
153 /* Now we determine the single parts of the locale name. First
154 look for the language. Termination symbols are `_' and `@' if
155 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
156 mask = _nl_explode_name (locale, &language, &modifier, &territory,
157 &codeset, &normalized_codeset, &special,
158 &sponsor, &revision);
160 /* Create all possible locale entries which might be interested in
162 retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
163 strlen (dirname) + 1, mask, language, territory,
164 codeset, normalized_codeset, modifier, special,
165 sponsor, revision, domainname, 1);
167 /* This means we are out of core. */
170 if (retval->decided == 0)
171 _nl_load_domain (retval);
172 if (retval->data == NULL)
175 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
177 if (retval->successor[cnt]->decided == 0)
178 _nl_load_domain (retval->successor[cnt]);
179 if (retval->successor[cnt]->data != NULL)
184 /* The room for an alias was dynamically allocated. Free it now. */
185 if (alias_value != NULL)