1 /* Handle list of needed message catalogs
2 Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
3 Written by Ulrich Drepper <drepper@gnu.org>, 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. */
24 #include <sys/types.h>
28 #if defined HAVE_UNISTD_H
34 #include "intl/gettext/gettextP.h"
35 #include "intl/gettext/libintl.h"
36 #include "util/string.h"
38 /* List of already loaded domains. */
39 static struct loaded_l10nfile
*_nl_loaded_domains
;
41 /* Return a data structure describing the message catalog described by
42 the DOMAINNAME and CATEGORY parameters with respect to the currently
43 established bindings. */
44 struct loaded_l10nfile
*
45 _nl_find_domain(const unsigned char *dirname
, unsigned char *locale
, const unsigned char *domainname
,
46 struct binding
*domainbinding
)
48 struct loaded_l10nfile
*retval
;
49 const unsigned char *language
;
50 const unsigned char *modifier
;
51 const unsigned char *territory
;
52 const unsigned char *codeset
;
53 const unsigned char *normalized_codeset
;
54 const unsigned char *special
;
55 const unsigned char *sponsor
;
56 const unsigned char *revision
;
57 const unsigned char *alias_value
;
60 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
62 language[_territory[.codeset]][@modifier]
64 and six parts for the CEN syntax:
66 language[_territory][+audience][+special][,[sponsor][_revision]]
68 Beside the first part all of them are allowed to be missing. If
69 the full specified locale is not found, the less specific one are
70 looked for. The various parts will be stripped off according to
76 (5) normalized codeset
81 /* If we have already tested for this locale entry there has to
82 be one data set in the list of loaded domains. */
83 retval
= _nl_make_l10nflist(&_nl_loaded_domains
, dirname
,
84 strlen(dirname
) + 1, 0, locale
, NULL
, NULL
,
85 NULL
, NULL
, NULL
, NULL
, NULL
, domainname
,
88 /* We know something about this locale. */
91 if (retval
->decided
== 0)
92 _nl_load_domain(retval
, domainbinding
);
94 if (retval
->data
!= NULL
)
97 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
) {
98 if (retval
->successor
[cnt
]->decided
== 0)
99 _nl_load_domain(retval
->successor
[cnt
],
102 if (retval
->successor
[cnt
]->data
!= NULL
)
105 return cnt
>= 0 ? retval
: NULL
;
109 /* See whether the locale value is an alias. If yes its value
110 *overwrites* the alias name. No test for the original value is
112 alias_value
= _nl_expand_alias(locale
);
113 if (alias_value
!= NULL
) {
114 locale
= strdup(alias_value
);
119 /* Now we determine the single parts of the locale name. First
120 look for the language. Termination symbols are `_' and `@' if
121 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
122 mask
= _nl_explode_name(locale
, &language
, &modifier
, &territory
,
123 &codeset
, &normalized_codeset
, &special
,
124 &sponsor
, &revision
);
126 /* Create all possible locale entries which might be interested in
128 retval
= _nl_make_l10nflist(&_nl_loaded_domains
, dirname
,
129 strlen(dirname
) + 1, mask
, language
,
130 territory
, codeset
, normalized_codeset
,
131 modifier
, special
, sponsor
, revision
,
134 /* This means we are out of core. */
137 if (retval
->decided
== 0)
138 _nl_load_domain(retval
, domainbinding
);
139 if (retval
->data
== NULL
) {
142 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
) {
143 if (retval
->successor
[cnt
]->decided
== 0)
144 _nl_load_domain(retval
->successor
[cnt
],
146 if (retval
->successor
[cnt
]->data
!= NULL
)
151 /* The room for an alias was dynamically allocated. Free it now. */
152 if (alias_value
!= NULL
)
155 /* The space for normalized_codeset is dynamically allocated. Free it. */
156 if (mask
& XPG_NORM_CODESET
)
157 free((void *) normalized_codeset
);