| 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 (const char *dirname, char *locale, |
|---|
| 51 | const char *domainname, struct binding *domainbinding) |
|---|
| 52 | { |
|---|
| 53 | struct loaded_l10nfile *retval; |
|---|
| 54 | const char *language; |
|---|
| 55 | const char *modifier; |
|---|
| 56 | const char *territory; |
|---|
| 57 | const char *codeset; |
|---|
| 58 | const char *normalized_codeset; |
|---|
| 59 | const char *special; |
|---|
| 60 | const char *sponsor; |
|---|
| 61 | const char *revision; |
|---|
| 62 | const char *alias_value; |
|---|
| 63 | int mask; |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname, |
|---|
| 89 | strlen (dirname) + 1, 0, locale, NULL, NULL, |
|---|
| 90 | NULL, NULL, NULL, NULL, NULL, domainname, 0); |
|---|
| 91 | if (retval != NULL) |
|---|
| 92 | { |
|---|
| 93 | |
|---|
| 94 | int cnt; |
|---|
| 95 | |
|---|
| 96 | if (retval->decided == 0) |
|---|
| 97 | _nl_load_domain (retval, domainbinding); |
|---|
| 98 | |
|---|
| 99 | if (retval->data != NULL) |
|---|
| 100 | return retval; |
|---|
| 101 | |
|---|
| 102 | for (cnt = 0; retval->successor[cnt] != NULL; ++cnt) |
|---|
| 103 | { |
|---|
| 104 | if (retval->successor[cnt]->decided == 0) |
|---|
| 105 | _nl_load_domain (retval->successor[cnt], domainbinding); |
|---|
| 106 | |
|---|
| 107 | if (retval->successor[cnt]->data != NULL) |
|---|
| 108 | break; |
|---|
| 109 | } |
|---|
| 110 | return cnt >= 0 ? retval : NULL; |
|---|
| 111 | |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | alias_value = _nl_expand_alias (locale); |
|---|
| 118 | if (alias_value != NULL) |
|---|
| 119 | { |
|---|
| 120 | #if defined _LIBC || defined HAVE_STRDUP |
|---|
| 121 | locale = strdup (alias_value); |
|---|
| 122 | if (locale == NULL) |
|---|
| 123 | return NULL; |
|---|
| 124 | #else |
|---|
| 125 | size_t len = strlen (alias_value) + 1; |
|---|
| 126 | locale = (char *) malloc (len); |
|---|
| 127 | if (locale == NULL) |
|---|
| 128 | return NULL; |
|---|
| 129 | |
|---|
| 130 | memcpy (locale, alias_value, len); |
|---|
| 131 | #endif |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | mask = _nl_explode_name (locale, &language, &modifier, &territory, |
|---|
| 138 | &codeset, &normalized_codeset, &special, |
|---|
| 139 | &sponsor, &revision); |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname, |
|---|
| 144 | strlen (dirname) + 1, mask, language, territory, |
|---|
| 145 | codeset, normalized_codeset, modifier, special, |
|---|
| 146 | sponsor, revision, domainname, 1); |
|---|
| 147 | if (retval == NULL) |
|---|
| 148 | |
|---|
| 149 | return NULL; |
|---|
| 150 | |
|---|
| 151 | if (retval->decided == 0) |
|---|
| 152 | _nl_load_domain (retval, domainbinding); |
|---|
| 153 | if (retval->data == NULL) |
|---|
| 154 | { |
|---|
| 155 | int cnt; |
|---|
| 156 | for (cnt = 0; retval->successor[cnt] != NULL; ++cnt) |
|---|
| 157 | { |
|---|
| 158 | if (retval->successor[cnt]->decided == 0) |
|---|
| 159 | _nl_load_domain (retval->successor[cnt], domainbinding); |
|---|
| 160 | if (retval->successor[cnt]->data != NULL) |
|---|
| 161 | break; |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | if (alias_value != NULL) |
|---|
| 167 | free (locale); |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | if (mask & XPG_NORM_CODESET) |
|---|
| 171 | free ((void *) normalized_codeset); |
|---|
| 172 | |
|---|
| 173 | return retval; |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | #ifdef _LIBC |
|---|
| 178 | libc_freeres_fn (free_mem) |
|---|
| 179 | { |
|---|
| 180 | struct loaded_l10nfile *runp = _nl_loaded_domains; |
|---|
| 181 | |
|---|
| 182 | while (runp != NULL) |
|---|
| 183 | { |
|---|
| 184 | struct loaded_l10nfile *here = runp; |
|---|
| 185 | if (runp->data != NULL) |
|---|
| 186 | _nl_unload_domain ((struct loaded_domain *) runp->data); |
|---|
| 187 | runp = runp->next; |
|---|
| 188 | free ((char *) here->filename); |
|---|
| 189 | free (here); |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | #endif |
|---|