00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_CONFIG_H
00021 # include <config.h>
00022 #endif
00023
00024 #include <stdio.h>
00025 #include <sys/types.h>
00026 #include <stdlib.h>
00027 #include <string.h>
00028
00029 #if defined HAVE_UNISTD_H || defined _LIBC
00030 # include <unistd.h>
00031 #endif
00032
00033 #include "gettextP.h"
00034 #ifdef _LIBC
00035 # include <libintl.h>
00036 #else
00037 # include "libgnuintl.h"
00038 #endif
00039
00040
00041
00042 static struct loaded_l10nfile *_nl_loaded_domains;
00043
00044
00045
00046
00047
00048 struct loaded_l10nfile *
00049 internal_function
00050 _nl_find_domain (dirname, locale, domainname, domainbinding)
00051 const char *dirname;
00052 char *locale;
00053 const char *domainname;
00054 struct binding *domainbinding;
00055 {
00056 struct loaded_l10nfile *retval;
00057 const char *language;
00058 const char *modifier;
00059 const char *territory;
00060 const char *codeset;
00061 const char *normalized_codeset;
00062 const char *special;
00063 const char *sponsor;
00064 const char *revision;
00065 const char *alias_value;
00066 int mask;
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
00092 strlen (dirname) + 1, 0, locale, NULL, NULL,
00093 NULL, NULL, NULL, NULL, NULL, domainname, 0);
00094 if (retval != NULL)
00095 {
00096
00097 int cnt;
00098
00099 if (retval->decided == 0)
00100 _nl_load_domain (retval, domainbinding);
00101
00102 if (retval->data != NULL)
00103 return retval;
00104
00105 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
00106 {
00107 if (retval->successor[cnt]->decided == 0)
00108 _nl_load_domain (retval->successor[cnt], domainbinding);
00109
00110 if (retval->successor[cnt]->data != NULL)
00111 break;
00112 }
00113 return cnt >= 0 ? retval : NULL;
00114
00115 }
00116
00117
00118
00119
00120 alias_value = _nl_expand_alias (locale);
00121 if (alias_value != NULL)
00122 {
00123 #if defined _LIBC || defined HAVE_STRDUP
00124 locale = strdup (alias_value);
00125 if (locale == NULL)
00126 return NULL;
00127 #else
00128 size_t len = strlen (alias_value) + 1;
00129 locale = (char *) malloc (len);
00130 if (locale == NULL)
00131 return NULL;
00132
00133 memcpy (locale, alias_value, len);
00134 #endif
00135 }
00136
00137
00138
00139
00140 mask = _nl_explode_name (locale, &language, &modifier, &territory,
00141 &codeset, &normalized_codeset, &special,
00142 &sponsor, &revision);
00143
00144
00145
00146 retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
00147 strlen (dirname) + 1, mask, language, territory,
00148 codeset, normalized_codeset, modifier, special,
00149 sponsor, revision, domainname, 1);
00150 if (retval == NULL)
00151
00152 return NULL;
00153
00154 if (retval->decided == 0)
00155 _nl_load_domain (retval, domainbinding);
00156 if (retval->data == NULL)
00157 {
00158 int cnt;
00159 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
00160 {
00161 if (retval->successor[cnt]->decided == 0)
00162 _nl_load_domain (retval->successor[cnt], domainbinding);
00163 if (retval->successor[cnt]->data != NULL)
00164 break;
00165 }
00166 }
00167
00168
00169 if (alias_value != NULL)
00170 free (locale);
00171
00172
00173 if (mask & XPG_NORM_CODESET)
00174 free ((void *) normalized_codeset);
00175
00176 return retval;
00177 }
00178
00179
00180 #ifdef _LIBC
00181 static void __attribute__ ((unused))
00182 free_mem (void)
00183 {
00184 struct loaded_l10nfile *runp = _nl_loaded_domains;
00185
00186 while (runp != NULL)
00187 {
00188 struct loaded_l10nfile *here = runp;
00189 if (runp->data != NULL)
00190 _nl_unload_domain ((struct loaded_domain *) runp->data);
00191 runp = runp->next;
00192 free ((char *) here->filename);
00193 free (here);
00194 }
00195 }
00196
00197 text_set_element (__libc_subfreeres, free_mem);
00198 #endif