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 it
6 under the terms of the GNU Library General Public License as published
7 by 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 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 this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 #include <sys/types.h>
29 #if defined HAVE_UNISTD_H || defined _LIBC
37 # include "libgnuintl.h"
40 /* @@ end of prolog @@ */
41 /* List of already loaded domains. */
42 static struct loaded_l10nfile
*_nl_loaded_domains
;
45 /* Return a data structure describing the message catalog described by
46 the DOMAINNAME and CATEGORY parameters with respect to the currently
47 established bindings. */
48 struct loaded_l10nfile
*
50 _nl_find_domain (dirname
, locale
, domainname
, domainbinding
)
53 const char *domainname
;
54 struct binding
*domainbinding
;
56 struct loaded_l10nfile
*retval
;
59 const char *territory
;
61 const char *normalized_codeset
;
65 const char *alias_value
;
68 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
70 language[_territory[.codeset]][@modifier]
72 and six parts for the CEN syntax:
74 language[_territory][+audience][+special][,[sponsor][_revision]]
76 Beside the first part all of them are allowed to be missing. If
77 the full specified locale is not found, the less specific one are
78 looked for. The various parts will be stripped off according to
84 (5) normalized codeset
89 /* If we have already tested for this locale entry there has to
90 be one data set in the list of loaded domains. */
91 retval
= _nl_make_l10nflist (&_nl_loaded_domains
, dirname
,
92 strlen (dirname
) + 1, 0, locale
, NULL
, NULL
,
93 NULL
, NULL
, NULL
, NULL
, NULL
, domainname
, 0);
96 /* We know something about this locale. */
99 if (retval
->decided
== 0)
100 _nl_load_domain (retval
, domainbinding
);
102 if (retval
->data
!= NULL
)
105 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
)
107 if (retval
->successor
[cnt
]->decided
== 0)
108 _nl_load_domain (retval
->successor
[cnt
], domainbinding
);
110 if (retval
->successor
[cnt
]->data
!= NULL
)
113 return cnt
>= 0 ? retval
: NULL
;
117 /* See whether the locale value is an alias. If yes its value
118 *overwrites* the alias name. No test for the original value is
120 alias_value
= _nl_expand_alias (locale
);
121 if (alias_value
!= NULL
)
123 #if defined _LIBC || defined HAVE_STRDUP
124 locale
= strdup (alias_value
);
128 size_t len
= strlen (alias_value
) + 1;
129 locale
= (char *) malloc (len
);
133 memcpy (locale
, alias_value
, len
);
137 /* Now we determine the single parts of the locale name. First
138 look for the language. Termination symbols are `_' and `@' if
139 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
140 mask
= _nl_explode_name (locale
, &language
, &modifier
, &territory
,
141 &codeset
, &normalized_codeset
, &special
,
142 &sponsor
, &revision
);
144 /* Create all possible locale entries which might be interested in
146 retval
= _nl_make_l10nflist (&_nl_loaded_domains
, dirname
,
147 strlen (dirname
) + 1, mask
, language
, territory
,
148 codeset
, normalized_codeset
, modifier
, special
,
149 sponsor
, revision
, domainname
, 1);
151 /* This means we are out of core. */
154 if (retval
->decided
== 0)
155 _nl_load_domain (retval
, domainbinding
);
156 if (retval
->data
== NULL
)
159 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
)
161 if (retval
->successor
[cnt
]->decided
== 0)
162 _nl_load_domain (retval
->successor
[cnt
], domainbinding
);
163 if (retval
->successor
[cnt
]->data
!= NULL
)
168 /* The room for an alias was dynamically allocated. Free it now. */
169 if (alias_value
!= NULL
)
172 /* The space for normalized_codeset is dynamically allocated. Free it. */
173 if (mask
& XPG_NORM_CODESET
)
174 free ((void *) normalized_codeset
);
181 libc_freeres_fn (free_mem
)
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
);