1 /* finddomain.c - Handle list of needed message catalogs */
3 /* Copyright (C) 1995-1999, 2000, 2001, 2005-2009 Free Software Foundation, Inc.
4 Written by Ulrich Drepper <drepper@gnu.org>, 1995.
6 This file is part of GNU Bash.
8 Bash is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 Bash 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
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Bash. If not, see <http://www.gnu.org/licenses/>.
27 #include <sys/types.h>
31 #if defined HAVE_UNISTD_H || defined _LIBC
39 # include "libgnuintl.h"
42 /* @@ end of prolog @@ */
43 /* List of already loaded domains. */
44 static struct loaded_l10nfile
*_nl_loaded_domains
;
47 /* Return a data structure describing the message catalog described by
48 the DOMAINNAME and CATEGORY parameters with respect to the currently
49 established bindings. */
50 struct loaded_l10nfile
*
52 _nl_find_domain (dirname
, locale
, domainname
, domainbinding
)
55 const char *domainname
;
56 struct binding
*domainbinding
;
58 struct loaded_l10nfile
*retval
;
61 const char *territory
;
63 const char *normalized_codeset
;
67 const char *alias_value
;
70 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
72 language[_territory[.codeset]][@modifier]
74 and six parts for the CEN syntax:
76 language[_territory][+audience][+special][,[sponsor][_revision]]
78 Beside the first part all of them are allowed to be missing. If
79 the full specified locale is not found, the less specific one are
80 looked for. The various parts will be stripped off according to
86 (5) normalized codeset
91 /* If we have already tested for this locale entry there has to
92 be one data set in the list of loaded domains. */
93 retval
= _nl_make_l10nflist (&_nl_loaded_domains
, dirname
,
94 strlen (dirname
) + 1, 0, locale
, NULL
, NULL
,
95 NULL
, NULL
, NULL
, NULL
, NULL
, domainname
, 0);
98 /* We know something about this locale. */
101 if (retval
->decided
== 0)
102 _nl_load_domain (retval
, domainbinding
);
104 if (retval
->data
!= NULL
)
107 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
)
109 if (retval
->successor
[cnt
]->decided
== 0)
110 _nl_load_domain (retval
->successor
[cnt
], domainbinding
);
112 if (retval
->successor
[cnt
]->data
!= NULL
)
115 return cnt
>= 0 ? retval
: NULL
;
119 /* See whether the locale value is an alias. If yes its value
120 *overwrites* the alias name. No test for the original value is
122 alias_value
= _nl_expand_alias (locale
);
123 if (alias_value
!= NULL
)
125 #if defined _LIBC || defined HAVE_STRDUP
126 locale
= strdup (alias_value
);
130 size_t len
= strlen (alias_value
) + 1;
131 locale
= (char *) malloc (len
);
135 memcpy (locale
, alias_value
, len
);
139 /* Now we determine the single parts of the locale name. First
140 look for the language. Termination symbols are `_' and `@' if
141 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
142 mask
= _nl_explode_name (locale
, &language
, &modifier
, &territory
,
143 &codeset
, &normalized_codeset
, &special
,
144 &sponsor
, &revision
);
146 /* Create all possible locale entries which might be interested in
148 retval
= _nl_make_l10nflist (&_nl_loaded_domains
, dirname
,
149 strlen (dirname
) + 1, mask
, language
, territory
,
150 codeset
, normalized_codeset
, modifier
, special
,
151 sponsor
, revision
, domainname
, 1);
153 /* This means we are out of core. */
156 if (retval
->decided
== 0)
157 _nl_load_domain (retval
, domainbinding
);
158 if (retval
->data
== NULL
)
161 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
)
163 if (retval
->successor
[cnt
]->decided
== 0)
164 _nl_load_domain (retval
->successor
[cnt
], domainbinding
);
165 if (retval
->successor
[cnt
]->data
!= NULL
)
170 /* The room for an alias was dynamically allocated. Free it now. */
171 if (alias_value
!= NULL
)
174 /* The space for normalized_codeset is dynamically allocated. Free it. */
175 if (mask
& XPG_NORM_CODESET
)
176 free ((void *) normalized_codeset
);
183 libc_freeres_fn (free_mem
)
185 struct loaded_l10nfile
*runp
= _nl_loaded_domains
;
189 struct loaded_l10nfile
*here
= runp
;
190 if (runp
->data
!= NULL
)
191 _nl_unload_domain ((struct loaded_domain
*) runp
->data
);
193 free ((char *) here
->filename
);