| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifdef HAVE_CONFIG_H |
| 21 |
# include <config.h> |
| 22 |
#endif |
| 23 |
|
| 24 |
#include <stdio.h> |
| 25 |
#include <sys/types.h> |
| 26 |
#include <stdlib.h> |
| 27 |
#include <string.h> |
| 28 |
|
| 29 |
#if defined HAVE_UNISTD_H || defined _LIBC |
| 30 |
# include <unistd.h> |
| 31 |
#endif |
| 32 |
|
| 33 |
#include "gettextP.h" |
| 34 |
#ifdef _LIBC |
| 35 |
# include <libintl.h> |
| 36 |
#else |
| 37 |
# include "libgnuintl.h" |
| 38 |
#endif |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
static struct loaded_l10nfile *_nl_loaded_domains; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
struct loaded_l10nfile * |
| 49 |
internal_function |
| 50 |
_nl_find_domain (dirname, locale, domainname, domainbinding) |
| 51 |
const char *dirname; |
| 52 |
char *locale; |
| 53 |
const char *domainname; |
| 54 |
struct binding *domainbinding; |
| 55 |
{ |
| 56 |
struct loaded_l10nfile *retval; |
| 57 |
const char *language; |
| 58 |
const char *modifier; |
| 59 |
const char *territory; |
| 60 |
const char *codeset; |
| 61 |
const char *normalized_codeset; |
| 62 |
const char *special; |
| 63 |
const char *sponsor; |
| 64 |
const char *revision; |
| 65 |
const char *alias_value; |
| 66 |
int mask; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 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); |
| 94 |
if (retval != NULL) |
| 95 |
{ |
| 96 |
|
| 97 |
int cnt; |
| 98 |
|
| 99 |
if (retval->decided == 0) |
| 100 |
_nl_load_domain (retval, domainbinding); |
| 101 |
|
| 102 |
if (retval->data != NULL) |
| 103 |
return retval; |
| 104 |
|
| 105 |
for (cnt = 0; retval->successor[cnt] != NULL; ++cnt) |
| 106 |
{ |
| 107 |
if (retval->successor[cnt]->decided == 0) |
| 108 |
_nl_load_domain (retval->successor[cnt], domainbinding); |
| 109 |
|
| 110 |
if (retval->successor[cnt]->data != NULL) |
| 111 |
break; |
| 112 |
} |
| 113 |
return cnt >= 0 ? retval : NULL; |
| 114 |
|
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
alias_value = _nl_expand_alias (locale); |
| 121 |
if (alias_value != NULL) |
| 122 |
{ |
| 123 |
#if defined _LIBC || defined HAVE_STRDUP |
| 124 |
locale = strdup (alias_value); |
| 125 |
if (locale == NULL) |
| 126 |
return NULL; |
| 127 |
#else |
| 128 |
size_t len = strlen (alias_value) + 1; |
| 129 |
locale = (char *) malloc (len); |
| 130 |
if (locale == NULL) |
| 131 |
return NULL; |
| 132 |
|
| 133 |
memcpy (locale, alias_value, len); |
| 134 |
#endif |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
mask = _nl_explode_name (locale, &language, &modifier, &territory, |
| 141 |
&codeset, &normalized_codeset, &special, |
| 142 |
&sponsor, &revision); |
| 143 |
|
| 144 |
|
| 145 |
|
| 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); |
| 150 |
if (retval == NULL) |
| 151 |
|
| 152 |
return NULL; |
| 153 |
|
| 154 |
if (retval->decided == 0) |
| 155 |
_nl_load_domain (retval, domainbinding); |
| 156 |
if (retval->data == NULL) |
| 157 |
{ |
| 158 |
int cnt; |
| 159 |
for (cnt = 0; retval->successor[cnt] != NULL; ++cnt) |
| 160 |
{ |
| 161 |
if (retval->successor[cnt]->decided == 0) |
| 162 |
_nl_load_domain (retval->successor[cnt], domainbinding); |
| 163 |
if (retval->successor[cnt]->data != NULL) |
| 164 |
break; |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
if (alias_value != NULL) |
| 170 |
free (locale); |
| 171 |
|
| 172 |
|
| 173 |
if (mask & XPG_NORM_CODESET) |
| 174 |
free ((void *) normalized_codeset); |
| 175 |
|
| 176 |
return retval; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
#ifdef _LIBC |
| 181 |
static void __attribute__ ((unused)) |
| 182 |
free_mem (void) |
| 183 |
{ |
| 184 |
struct loaded_l10nfile *runp = _nl_loaded_domains; |
| 185 |
|
| 186 |
while (runp != NULL) |
| 187 |
{ |
| 188 |
struct loaded_l10nfile *here = runp; |
| 189 |
if (runp->data != NULL) |
| 190 |
_nl_unload_domain ((struct loaded_domain *) runp->data); |
| 191 |
runp = runp->next; |
| 192 |
free ((char *) here->filename); |
| 193 |
free (here); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
text_set_element (__libc_subfreeres, free_mem); |
| 198 |
#endif |