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 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
*
77 _nl_find_domain (dirname
, locale
, domainname
)
80 const char *domainname
;
82 struct loaded_l10nfile
*retval
;
85 const char *territory
;
87 const char *normalized_codeset
;
91 const char *alias_value
;
94 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
96 language[_territory[.codeset]][@modifier]
98 and six parts for the CEN syntax:
100 language[_territory][+audience][+special][,[sponsor][_revision]]
102 Beside the first part all of them are allowed to be missing. If
103 the full specified locale is not found, the less specific one are
104 looked for. The various parts will be stripped off according to
110 (5) normalized codeset
112 (7) audience/modifier
115 /* If we have already tested for this locale entry there has to
116 be one data set in the list of loaded domains. */
117 retval
= _nl_make_l10nflist (&_nl_loaded_domains
, dirname
,
118 strlen (dirname
) + 1, 0, locale
, NULL
, NULL
,
119 NULL
, NULL
, NULL
, NULL
, NULL
, domainname
, 0);
122 /* We know something about this locale. */
125 if (retval
->decided
== 0)
126 _nl_load_domain (retval
);
128 if (retval
->data
!= NULL
)
131 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
)
133 if (retval
->successor
[cnt
]->decided
== 0)
134 _nl_load_domain (retval
->successor
[cnt
]);
136 if (retval
->successor
[cnt
]->data
!= NULL
)
139 return cnt
>= 0 ? retval
: NULL
;
143 /* See whether the locale value is an alias. If yes its value
144 *overwrites* the alias name. No test for the original value is
146 alias_value
= _nl_expand_alias (locale
);
147 if (alias_value
!= NULL
)
149 #if defined _LIBC || defined HAVE_STRDUP
150 locale
= strdup (alias_value
);
154 size_t len
= strlen (alias_value
) + 1;
155 locale
= (char *) malloc (len
);
159 memcpy (locale
, alias_value
, len
);
163 /* Now we determine the single parts of the locale name. First
164 look for the language. Termination symbols are `_' and `@' if
165 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
166 mask
= _nl_explode_name (locale
, &language
, &modifier
, &territory
,
167 &codeset
, &normalized_codeset
, &special
,
168 &sponsor
, &revision
);
170 /* Create all possible locale entries which might be interested in
172 retval
= _nl_make_l10nflist (&_nl_loaded_domains
, dirname
,
173 strlen (dirname
) + 1, mask
, language
, territory
,
174 codeset
, normalized_codeset
, modifier
, special
,
175 sponsor
, revision
, domainname
, 1);
177 /* This means we are out of core. */
180 if (retval
->decided
== 0)
181 _nl_load_domain (retval
);
182 if (retval
->data
== NULL
)
185 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
)
187 if (retval
->successor
[cnt
]->decided
== 0)
188 _nl_load_domain (retval
->successor
[cnt
]);
189 if (retval
->successor
[cnt
]->data
!= NULL
)
194 /* The room for an alias was dynamically allocated. Free it now. */
195 if (alias_value
!= NULL
)
203 static void __attribute__ ((unused
))
206 struct loaded_l10nfile
*runp
= _nl_loaded_domains
;
210 struct loaded_l10nfile
*here
= runp
;
211 if (runp
->data
!= NULL
)
212 _nl_unload_domain ((struct loaded_domain
*) runp
->data
);
218 text_set_element (__libc_subfreeres
, free_mem
);