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