1 /* Handle list of needed message catalogs
2 Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
3 Written by Ulrich Drepper <drepper@gnu.org>, 1995.
5 This file is part of the GNU C Library. Its master source is NOT part of
6 the C library, however.
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 The GNU C 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 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with the GNU C Library; see the file COPYING.LIB. If not,
20 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
30 #include <sys/types.h>
32 #if defined STDC_HEADERS || defined _LIBC
42 #if defined HAVE_STRING_H || defined _LIBC
47 # define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num)
50 #if !HAVE_STRCHR && !defined _LIBC
56 #if defined HAVE_UNISTD_H || defined _LIBC
65 # include "libgettext.h"
68 /* @@ end of prolog @@ */
69 /* List of already loaded domains. */
70 static struct loaded_l10nfile
*_nl_loaded_domains
;
73 /* Return a data structure describing the message catalog described by
74 the DOMAINNAME and CATEGORY parameters with respect to the currently
75 established bindings. */
76 struct loaded_l10nfile
*
78 _nl_find_domain (dirname
, locale
, domainname
)
81 const char *domainname
;
83 struct loaded_l10nfile
*retval
;
86 const char *territory
;
88 const char *normalized_codeset
;
92 const char *alias_value
;
95 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
97 language[_territory[.codeset]][@modifier]
99 and six parts for the CEN syntax:
101 language[_territory][+audience][+special][,[sponsor][_revision]]
103 Beside the first part all of them are allowed to be missing. If
104 the full specified locale is not found, the less specific one are
105 looked for. The various parts will be stripped off according to
111 (5) normalized codeset
113 (7) audience/modifier
116 /* If we have already tested for this locale entry there has to
117 be one data set in the list of loaded domains. */
118 retval
= _nl_make_l10nflist (&_nl_loaded_domains
, dirname
,
119 strlen (dirname
) + 1, 0, locale
, NULL
, NULL
,
120 NULL
, NULL
, NULL
, NULL
, NULL
, domainname
, 0);
123 /* We know something about this locale. */
126 if (retval
->decided
== 0)
127 _nl_load_domain (retval
);
129 if (retval
->data
!= NULL
)
132 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
)
134 if (retval
->successor
[cnt
]->decided
== 0)
135 _nl_load_domain (retval
->successor
[cnt
]);
137 if (retval
->successor
[cnt
]->data
!= NULL
)
140 return cnt
>= 0 ? retval
: NULL
;
144 /* See whether the locale value is an alias. If yes its value
145 *overwrites* the alias name. No test for the original value is
147 alias_value
= _nl_expand_alias (locale
);
148 if (alias_value
!= NULL
)
150 #if defined _LIBC || defined HAVE_STRDUP
151 locale
= strdup (alias_value
);
155 size_t len
= strlen (alias_value
) + 1;
156 locale
= (char *) malloc (len
);
160 memcpy (locale
, alias_value
, len
);
164 /* Now we determine the single parts of the locale name. First
165 look for the language. Termination symbols are `_' and `@' if
166 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
167 mask
= _nl_explode_name (locale
, &language
, &modifier
, &territory
,
168 &codeset
, &normalized_codeset
, &special
,
169 &sponsor
, &revision
);
171 /* Create all possible locale entries which might be interested in
173 retval
= _nl_make_l10nflist (&_nl_loaded_domains
, dirname
,
174 strlen (dirname
) + 1, mask
, language
, territory
,
175 codeset
, normalized_codeset
, modifier
, special
,
176 sponsor
, revision
, domainname
, 1);
178 /* This means we are out of core. */
181 if (retval
->decided
== 0)
182 _nl_load_domain (retval
);
183 if (retval
->data
== NULL
)
186 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
)
188 if (retval
->successor
[cnt
]->decided
== 0)
189 _nl_load_domain (retval
->successor
[cnt
]);
190 if (retval
->successor
[cnt
]->data
!= NULL
)
195 /* The room for an alias was dynamically allocated. Free it now. */
196 if (alias_value
!= NULL
)
204 static void __attribute__ ((unused
))
207 struct loaded_l10nfile
*runp
= _nl_loaded_domains
;
211 struct loaded_l10nfile
*here
= runp
;
212 if (runp
->data
!= NULL
)
213 _nl_unload_domain ((struct loaded_domain
*) runp
->data
);
215 free ((char *) here
->filename
);
220 text_set_element (__libc_subfreeres
, free_mem
);