]>
Commit | Line | Data |
---|---|---|
8f2ece69 | 1 | /* Handle list of needed message catalogs |
d0fc4041 | 2 | Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. |
92f3773b RM |
3 | Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. |
4 | ||
e4cf5070 | 5 | This file is part of the GNU C Library. Its master source is NOT part of |
40a55d20 | 6 | the C library, however. |
24906b43 | 7 | |
e4cf5070 UD |
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. | |
0393dfd6 | 12 | |
e4cf5070 UD |
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. | |
24906b43 | 17 | |
e4cf5070 UD |
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. */ | |
24906b43 RM |
22 | |
23 | #ifdef HAVE_CONFIG_H | |
24 | # include <config.h> | |
25 | #endif | |
26 | ||
0393dfd6 | 27 | #include <ctype.h> |
24906b43 RM |
28 | #include <errno.h> |
29 | #include <stdio.h> | |
30 | #include <sys/types.h> | |
31 | ||
32 | #if defined STDC_HEADERS || defined _LIBC | |
33 | # include <stdlib.h> | |
34 | #else | |
35 | # ifdef HAVE_MALLOC_H | |
36 | # include <malloc.h> | |
37 | # else | |
38 | void free (); | |
39 | # endif | |
40 | #endif | |
41 | ||
42 | #if defined HAVE_STRING_H || defined _LIBC | |
43 | # include <string.h> | |
44 | #else | |
45 | # include <strings.h> | |
8f2ece69 UD |
46 | # ifndef memcpy |
47 | # define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num) | |
48 | # endif | |
24906b43 RM |
49 | #endif |
50 | #if !HAVE_STRCHR && !defined _LIBC | |
51 | # ifndef strchr | |
52 | # define strchr index | |
53 | # endif | |
54 | #endif | |
55 | ||
56 | #if defined HAVE_UNISTD_H || defined _LIBC | |
57 | # include <unistd.h> | |
58 | #endif | |
59 | ||
60 | #include "gettext.h" | |
61 | #include "gettextP.h" | |
62 | #ifdef _LIBC | |
63 | # include <libintl.h> | |
64 | #else | |
65 | # include "libgettext.h" | |
66 | #endif | |
67 | ||
68 | /* @@ end of prolog @@ */ | |
24906b43 | 69 | /* List of already loaded domains. */ |
7a12c6bb | 70 | static struct loaded_l10nfile *_nl_loaded_domains; |
857fa1b8 | 71 | |
24906b43 RM |
72 | |
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. */ | |
7a12c6bb | 76 | struct loaded_l10nfile * |
d0fc4041 | 77 | internal_function |
24906b43 RM |
78 | _nl_find_domain (dirname, locale, domainname) |
79 | const char *dirname; | |
80 | char *locale; | |
81 | const char *domainname; | |
82 | { | |
7a12c6bb | 83 | struct loaded_l10nfile *retval; |
24906b43 | 84 | const char *language; |
7a12c6bb RM |
85 | const char *modifier; |
86 | const char *territory; | |
87 | const char *codeset; | |
88 | const char *normalized_codeset; | |
89 | const char *special; | |
90 | const char *sponsor; | |
91 | const char *revision; | |
92 | const char *alias_value; | |
24906b43 RM |
93 | int mask; |
94 | ||
7a12c6bb | 95 | /* LOCALE can consist of up to four recognized parts for the XPG syntax: |
24906b43 RM |
96 | |
97 | language[_territory[.codeset]][@modifier] | |
98 | ||
99 | and six parts for the CEN syntax: | |
100 | ||
e4cf5070 | 101 | language[_territory][+audience][+special][,[sponsor][_revision]] |
24906b43 | 102 | |
f41c8091 UD |
103 | Beside the first part all of them are allowed to be missing. If |
104 | the full specified locale is not found, the less specific one are | |
105 | looked for. The various parts will be stripped off according to | |
24906b43 RM |
106 | the following order: |
107 | (1) revision | |
108 | (2) sponsor | |
109 | (3) special | |
110 | (4) codeset | |
857fa1b8 RM |
111 | (5) normalized codeset |
112 | (6) territory | |
113 | (7) audience/modifier | |
24906b43 RM |
114 | */ |
115 | ||
116 | /* If we have already tested for this locale entry there has to | |
117 | be one data set in the list of loaded domains. */ | |
7a12c6bb RM |
118 | retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname, |
119 | strlen (dirname) + 1, 0, locale, NULL, NULL, | |
120 | NULL, NULL, NULL, NULL, NULL, domainname, 0); | |
24906b43 RM |
121 | if (retval != NULL) |
122 | { | |
123 | /* We know something about this locale. */ | |
124 | int cnt; | |
125 | ||
126 | if (retval->decided == 0) | |
7a12c6bb | 127 | _nl_load_domain (retval); |
24906b43 RM |
128 | |
129 | if (retval->data != NULL) | |
130 | return retval; | |
131 | ||
75914335 | 132 | for (cnt = 0; retval->successor[cnt] != NULL; ++cnt) |
24906b43 | 133 | { |
75914335 | 134 | if (retval->successor[cnt]->decided == 0) |
24906b43 RM |
135 | _nl_load_domain (retval->successor[cnt]); |
136 | ||
137 | if (retval->successor[cnt]->data != NULL) | |
138 | break; | |
139 | } | |
24906b43 RM |
140 | return cnt >= 0 ? retval : NULL; |
141 | /* NOTREACHED */ | |
142 | } | |
143 | ||
144 | /* See whether the locale value is an alias. If yes its value | |
145 | *overwrites* the alias name. No test for the original value is | |
146 | done. */ | |
147 | alias_value = _nl_expand_alias (locale); | |
148 | if (alias_value != NULL) | |
149 | { | |
40a55d20 UD |
150 | #if defined _LIBC || defined HAVE_STRDUP |
151 | locale = strdup (alias_value); | |
152 | if (locale == NULL) | |
153 | return NULL; | |
154 | #else | |
24906b43 RM |
155 | size_t len = strlen (alias_value) + 1; |
156 | locale = (char *) malloc (len); | |
157 | if (locale == NULL) | |
158 | return NULL; | |
159 | ||
160 | memcpy (locale, alias_value, len); | |
40a55d20 | 161 | #endif |
24906b43 RM |
162 | } |
163 | ||
164 | /* Now we determine the single parts of the locale name. First | |
165 | look for the language. Termination symbols are `_' and `@' if | |
166 | we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */ | |
7a12c6bb RM |
167 | mask = _nl_explode_name (locale, &language, &modifier, &territory, |
168 | &codeset, &normalized_codeset, &special, | |
169 | &sponsor, &revision); | |
24906b43 RM |
170 | |
171 | /* Create all possible locale entries which might be interested in | |
6d52618b | 172 | generalization. */ |
7a12c6bb RM |
173 | retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname, |
174 | strlen (dirname) + 1, mask, language, territory, | |
175 | codeset, normalized_codeset, modifier, special, | |
176 | sponsor, revision, domainname, 1); | |
24906b43 RM |
177 | if (retval == NULL) |
178 | /* This means we are out of core. */ | |
179 | return NULL; | |
180 | ||
181 | if (retval->decided == 0) | |
182 | _nl_load_domain (retval); | |
183 | if (retval->data == NULL) | |
184 | { | |
185 | int cnt; | |
186 | for (cnt = 0; retval->successor[cnt] != NULL; ++cnt) | |
187 | { | |
188 | if (retval->successor[cnt]->decided == 0) | |
189 | _nl_load_domain (retval->successor[cnt]); | |
190 | if (retval->successor[cnt]->data != NULL) | |
191 | break; | |
24906b43 | 192 | } |
24906b43 RM |
193 | } |
194 | ||
195 | /* The room for an alias was dynamically allocated. Free it now. */ | |
196 | if (alias_value != NULL) | |
197 | free (locale); | |
198 | ||
199 | return retval; | |
200 | } | |
a5a0310d UD |
201 | |
202 | ||
203 | #ifdef _LIBC | |
204 | static void __attribute__ ((unused)) | |
205 | free_mem (void) | |
206 | { | |
207 | struct loaded_l10nfile *runp = _nl_loaded_domains; | |
208 | ||
209 | while (runp != NULL) | |
210 | { | |
211 | struct loaded_l10nfile *here = runp; | |
212 | if (runp->data != NULL) | |
213 | _nl_unload_domain ((struct loaded_domain *) runp->data); | |
214 | runp = runp->next; | |
215 | free (here); | |
216 | } | |
217 | } | |
218 | ||
219 | text_set_element (__libc_subfreeres, free_mem); | |
220 | #endif |