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 || defined _LIBC
36 # include "libgnuintl.h"
39 /* @@ end of prolog @@ */
40 /* List of already loaded domains. */
41 static struct loaded_l10nfile
*_nl_loaded_domains
;
44 /* Return a data structure describing the message catalog described by
45 the DOMAINNAME and CATEGORY parameters with respect to the currently
46 established bindings. */
47 struct loaded_l10nfile
*
49 _nl_find_domain (dirname
, locale
, domainname
, domainbinding
)
52 const char *domainname
;
53 struct binding
*domainbinding
;
55 struct loaded_l10nfile
*retval
;
58 const char *territory
;
60 const char *normalized_codeset
;
64 const char *alias_value
;
67 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
69 language[_territory[.codeset]][@modifier]
71 and six parts for the CEN syntax:
73 language[_territory][+audience][+special][,[sponsor][_revision]]
75 Beside the first part all of them are allowed to be missing. If
76 the full specified locale is not found, the less specific one are
77 looked for. The various parts will be stripped off according to
83 (5) normalized codeset
88 /* If we have already tested for this locale entry there has to
89 be one data set in the list of loaded domains. */
90 retval
= _nl_make_l10nflist (&_nl_loaded_domains
, dirname
,
91 strlen (dirname
) + 1, 0, locale
, NULL
, NULL
,
92 NULL
, NULL
, NULL
, NULL
, NULL
, domainname
, 0);
95 /* We know something about this locale. */
98 if (retval
->decided
== 0)
99 _nl_load_domain (retval
, domainbinding
);
101 if (retval
->data
!= NULL
)
104 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
)
106 if (retval
->successor
[cnt
]->decided
== 0)
107 _nl_load_domain (retval
->successor
[cnt
], domainbinding
);
109 if (retval
->successor
[cnt
]->data
!= NULL
)
112 return cnt
>= 0 ? retval
: NULL
;
116 /* See whether the locale value is an alias. If yes its value
117 *overwrites* the alias name. No test for the original value is
119 alias_value
= _nl_expand_alias (locale
);
120 if (alias_value
!= NULL
)
122 #if defined _LIBC || defined HAVE_STRDUP
123 locale
= strdup (alias_value
);
127 size_t len
= strlen (alias_value
) + 1;
128 locale
= (char *) malloc (len
);
132 memcpy (locale
, alias_value
, len
);
136 /* Now we determine the single parts of the locale name. First
137 look for the language. Termination symbols are `_' and `@' if
138 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
139 mask
= _nl_explode_name (locale
, &language
, &modifier
, &territory
,
140 &codeset
, &normalized_codeset
, &special
,
141 &sponsor
, &revision
);
143 /* Create all possible locale entries which might be interested in
145 retval
= _nl_make_l10nflist (&_nl_loaded_domains
, dirname
,
146 strlen (dirname
) + 1, mask
, language
, territory
,
147 codeset
, normalized_codeset
, modifier
, special
,
148 sponsor
, revision
, domainname
, 1);
150 /* This means we are out of core. */
153 if (retval
->decided
== 0)
154 _nl_load_domain (retval
, domainbinding
);
155 if (retval
->data
== NULL
)
158 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
)
160 if (retval
->successor
[cnt
]->decided
== 0)
161 _nl_load_domain (retval
->successor
[cnt
], domainbinding
);
162 if (retval
->successor
[cnt
]->data
!= NULL
)
167 /* The room for an alias was dynamically allocated. Free it now. */
168 if (alias_value
!= NULL
)
171 /* The space for normalized_codeset is dynamically allocated. Free it. */
172 if (mask
& XPG_NORM_CODESET
)
173 free ((void *) normalized_codeset
);
180 static void __attribute__ ((unused
))
183 struct loaded_l10nfile
*runp
= _nl_loaded_domains
;
187 struct loaded_l10nfile
*here
= runp
;
188 if (runp
->data
!= NULL
)
189 _nl_unload_domain ((struct loaded_domain
*) runp
->data
);
191 free ((char *) here
->filename
);
196 text_set_element (__libc_subfreeres
, free_mem
);