annotate intl/finddomain.c @ 449:bf803441d49e trunk

[svn] new pango-based skin selection sexyness.
author nenolod
date Mon, 16 Jan 2006 14:37:05 -0800
parents cb178e5ad177
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* Handle list of needed message catalogs
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 Written by Ulrich Drepper <drepper@gnu.org>, 1995.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify it
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 under the terms of the GNU Library General Public License as published
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 by the Free Software Foundation; either version 2, or (at your option)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 Library General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 License along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 USA. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 #ifdef HAVE_CONFIG_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 # include <config.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #include <stdio.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 #include <sys/types.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #include <stdlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 #if defined HAVE_UNISTD_H || defined _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 # include <unistd.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 #include "gettextP.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 #ifdef _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 # include <libintl.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 # include "libgnuintl.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 /* @@ end of prolog @@ */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 /* List of already loaded domains. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 static struct loaded_l10nfile *_nl_loaded_domains;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 /* Return a data structure describing the message catalog described by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 the DOMAINNAME and CATEGORY parameters with respect to the currently
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 established bindings. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 struct loaded_l10nfile *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 internal_function
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 _nl_find_domain (dirname, locale, domainname, domainbinding)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 const char *dirname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 char *locale;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 const char *domainname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 struct binding *domainbinding;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 struct loaded_l10nfile *retval;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 const char *language;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 const char *modifier;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 const char *territory;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 const char *codeset;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 const char *normalized_codeset;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 const char *special;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 const char *sponsor;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 const char *revision;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 const char *alias_value;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 int mask;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 language[_territory[.codeset]][@modifier]
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 and six parts for the CEN syntax:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 language[_territory][+audience][+special][,[sponsor][_revision]]
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 Beside the first part all of them are allowed to be missing. If
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 the full specified locale is not found, the less specific one are
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 looked for. The various parts will be stripped off according to
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 the following order:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 (1) revision
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 (2) sponsor
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 (3) special
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 (4) codeset
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 (5) normalized codeset
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 (6) territory
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 (7) audience/modifier
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 /* If we have already tested for this locale entry there has to
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 be one data set in the list of loaded domains. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 strlen (dirname) + 1, 0, locale, NULL, NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 NULL, NULL, NULL, NULL, NULL, domainname, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 if (retval != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 /* We know something about this locale. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 int cnt;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 if (retval->decided == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 _nl_load_domain (retval, domainbinding);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 if (retval->data != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 return retval;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 if (retval->successor[cnt]->decided == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 _nl_load_domain (retval->successor[cnt], domainbinding);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 if (retval->successor[cnt]->data != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 return cnt >= 0 ? retval : NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 /* NOTREACHED */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 /* See whether the locale value is an alias. If yes its value
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 *overwrites* the alias name. No test for the original value is
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 done. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 alias_value = _nl_expand_alias (locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 if (alias_value != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 #if defined _LIBC || defined HAVE_STRDUP
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 locale = strdup (alias_value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 if (locale == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 size_t len = strlen (alias_value) + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 locale = (char *) malloc (len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 if (locale == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 memcpy (locale, alias_value, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 /* Now we determine the single parts of the locale name. First
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 look for the language. Termination symbols are `_' and `@' if
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 mask = _nl_explode_name (locale, &language, &modifier, &territory,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 &codeset, &normalized_codeset, &special,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 &sponsor, &revision);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 /* Create all possible locale entries which might be interested in
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 generalization. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 strlen (dirname) + 1, mask, language, territory,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 codeset, normalized_codeset, modifier, special,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 sponsor, revision, domainname, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 if (retval == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 /* This means we are out of core. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 if (retval->decided == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 _nl_load_domain (retval, domainbinding);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 if (retval->data == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 int cnt;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 if (retval->successor[cnt]->decided == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 _nl_load_domain (retval->successor[cnt], domainbinding);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 if (retval->successor[cnt]->data != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 /* The room for an alias was dynamically allocated. Free it now. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 if (alias_value != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 free (locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 /* The space for normalized_codeset is dynamically allocated. Free it. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 if (mask & XPG_NORM_CODESET)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 free ((void *) normalized_codeset);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 return retval;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 #ifdef _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 libc_freeres_fn (free_mem)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 struct loaded_l10nfile *runp = _nl_loaded_domains;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 while (runp != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 struct loaded_l10nfile *here = runp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 if (runp->data != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 _nl_unload_domain ((struct loaded_domain *) runp->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 runp = runp->next;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 free ((char *) here->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 free (here);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 #endif