1 /* Handle list of needed message catalogs
2 Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc.
3 Written by Ulrich Drepper <drepper@gnu.org>, 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 not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
25 #include <sys/types.h>
27 #if defined STDC_HEADERS || defined _LIBC
37 #if defined HAVE_STRING_H || defined _LIBC
42 # define memcpy(Dst, Src, Num) (bcopy (Src, Dst, Num), (Dst))
46 #if defined HAVE_UNISTD_H || defined _LIBC
55 # include "libgettext.h"
58 /* @@ end of prolog @@ */
59 /* List of already loaded domains. */
60 static struct loaded_l10nfile
*_nl_loaded_domains
;
63 /* Return a data structure describing the message catalog described by
64 the DOMAINNAME and CATEGORY parameters with respect to the currently
65 established bindings. */
66 struct loaded_l10nfile
*
68 _nl_find_domain (dirname
, locale
, domainname
, domainbinding
)
71 const char *domainname
;
72 struct binding
*domainbinding
;
74 struct loaded_l10nfile
*retval
;
77 const char *territory
;
79 const char *normalized_codeset
;
83 const char *alias_value
;
86 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
88 language[_territory[.codeset]][@modifier]
90 and six parts for the CEN syntax:
92 language[_territory][+audience][+special][,[sponsor][_revision]]
94 Beside the first part all of them are allowed to be missing. If
95 the full specified locale is not found, the less specific one are
96 looked for. The various parts will be stripped off according to
102 (5) normalized codeset
104 (7) audience/modifier
107 /* If we have already tested for this locale entry there has to
108 be one data set in the list of loaded domains. */
109 retval
= _nl_make_l10nflist (&_nl_loaded_domains
, dirname
,
110 strlen (dirname
) + 1, 0, locale
, NULL
, NULL
,
111 NULL
, NULL
, NULL
, NULL
, NULL
, domainname
,
115 /* We know something about this locale. */
118 if (retval
->decided
== 0)
119 _nl_load_domain (retval
);
121 if (retval
->data
!= NULL
)
124 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
)
126 if (retval
->successor
[cnt
]->decided
== 0)
127 _nl_load_domain (retval
->successor
[cnt
]);
129 if (retval
->successor
[cnt
]->data
!= NULL
)
132 return cnt
>= 0 ? retval
: NULL
;
136 /* See whether the locale value is an alias. If yes its value
137 *overwrites* the alias name. No test for the original value is
139 alias_value
= _nl_expand_alias (locale
);
140 if (alias_value
!= NULL
)
142 #if defined _LIBC || defined HAVE_STRDUP
143 locale
= strdup (alias_value
);
147 size_t len
= strlen (alias_value
) + 1;
148 locale
= (char *) malloc (len
);
152 memcpy (locale
, alias_value
, len
);
156 /* Now we determine the single parts of the locale name. First
157 look for the language. Termination symbols are `_' and `@' if
158 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
159 mask
= _nl_explode_name (locale
, &language
, &modifier
, &territory
,
160 &codeset
, &normalized_codeset
, &special
,
161 &sponsor
, &revision
);
163 /* Create all possible locale entries which might be interested in
165 retval
= _nl_make_l10nflist (&_nl_loaded_domains
, dirname
,
166 strlen (dirname
) + 1, mask
, language
, territory
,
167 codeset
, normalized_codeset
, modifier
, special
,
168 sponsor
, revision
, domainname
, domainbinding
,
171 /* This means we are out of core. */
174 if (retval
->decided
== 0)
175 _nl_load_domain (retval
);
176 if (retval
->data
== NULL
)
179 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
)
181 if (retval
->successor
[cnt
]->decided
== 0)
182 _nl_load_domain (retval
->successor
[cnt
]);
183 if (retval
->successor
[cnt
]->data
!= NULL
)
188 /* The room for an alias was dynamically allocated. Free it now. */
189 if (alias_value
!= NULL
)
192 /* The space for normalized_codeset is dynamically allocated. Free it. */
193 if (mask
& XPG_NORM_CODESET
)
194 free ((void *) normalized_codeset
);
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
);
212 free ((char *) here
->filename
);
217 text_set_element (__libc_subfreeres
, free_mem
);