1 /* finddomain.c -- handle list of needed message catalogs
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
3 Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
27 #include <sys/types.h>
29 #if defined STDC_HEADERS || defined _LIBC
39 #if defined HAVE_STRING_H || defined _LIBC
44 #if !HAVE_STRCHR && !defined _LIBC
50 #if defined HAVE_UNISTD_H || defined _LIBC
59 # include "libgettext.h"
62 /* @@ end of prolog @@ */
65 /* Rename the non ANSI C functions. This is required by the standard
66 because some ANSI C functions will require linking with this object
67 file and the name space must not be polluted. */
68 # define stpcpy(dest, src) __stpcpy(dest, src)
71 /* List of already loaded domains. */
72 static struct loaded_l10nfile *_nl_loaded_domains;
74 /* Substitution for systems lacking this function in their C library. */
75 #if !_LIBC && !HAVE_STPCPY
76 static char *stpcpy__ PARAMS ((char *dest, const char *src));
77 # define stpcpy(dest, src) stpcpy__ (dest, src)
81 /* Return a data structure describing the message catalog described by
82 the DOMAINNAME and CATEGORY parameters with respect to the currently
83 established bindings. */
84 struct loaded_l10nfile *
85 _nl_find_domain (dirname, locale, domainname)
88 const char *domainname;
90 struct loaded_l10nfile *retval;
93 const char *territory;
95 const char *normalized_codeset;
99 const char *alias_value;
102 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
104 language[_territory[.codeset]][@modifier]
106 and six parts for the CEN syntax:
108 language[_territory][+audience][+special][,sponsor][_revision]
110 Beside the first all of them are allowed to be missing. If the
111 full specified locale is not found, the less specific one are
112 looked for. The various part will be stripped of according to
118 (5) normalized codeset
120 (7) audience/modifier
123 /* If we have already tested for this locale entry there has to
124 be one data set in the list of loaded domains. */
125 retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
126 strlen (dirname) + 1, 0, locale, NULL, NULL,
127 NULL, NULL, NULL, NULL, NULL, domainname, 0);
130 /* We know something about this locale. */
133 if (retval->decided == 0)
134 _nl_load_domain (retval);
136 if (retval->data != NULL)
139 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
141 if (retval->successor[cnt]->decided == 0)
142 _nl_load_domain (retval->successor[cnt]);
144 if (retval->successor[cnt]->data != NULL)
147 return cnt >= 0 ? retval : NULL;
151 /* See whether the locale value is an alias. If yes its value
152 *overwrites* the alias name. No test for the original value is
154 alias_value = _nl_expand_alias (locale);
155 if (alias_value != NULL)
157 size_t len = strlen (alias_value) + 1;
158 locale = (char *) malloc (len);
162 memcpy (locale, alias_value, len);
165 /* Now we determine the single parts of the locale name. First
166 look for the language. Termination symbols are `_' and `@' if
167 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
168 mask = _nl_explode_name (locale, &language, &modifier, &territory,
169 &codeset, &normalized_codeset, &special,
170 &sponsor, &revision);
172 /* Create all possible locale entries which might be interested in
174 retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
175 strlen (dirname) + 1, mask, language, territory,
176 codeset, normalized_codeset, modifier, special,
177 sponsor, revision, domainname, 1);
179 /* This means we are out of core. */
182 if (retval->decided == 0)
183 _nl_load_domain (retval);
184 if (retval->data == NULL)
187 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
189 if (retval->successor[cnt]->decided == 0)
190 _nl_load_domain (retval->successor[cnt]);
191 if (retval->successor[cnt]->data != NULL)
196 /* The room for an alias was dynamically allocated. Free it now. */
197 if (alias_value != NULL)
203 /* @@ begin of epilog @@ */
205 /* We don't want libintl.a to depend on any other library. So we
206 avoid the non-standard function stpcpy. In GNU C Library this
207 function is available, though. Also allow the symbol HAVE_STPCPY
209 #if !_LIBC && !HAVE_STPCPY
215 while ((*dest++ = *src++) != '\0')