Retry only for https protocol
[elinks.git] / src / intl / gettext / finddomain.c
blobcfd9d2cf448ba5cad2e8963f77c2f06437b18629
1 /* Handle list of needed message catalogs
2 Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
3 Written by Ulrich Drepper <drepper@gnu.org>, 1995.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
23 #include <stdio.h>
24 #include <sys/types.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #if defined HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
32 #include "elinks.h"
34 #include "intl/gettext/gettextP.h"
35 #include "intl/gettext/libintl.h"
36 #include "util/string.h"
38 /* List of already loaded domains. */
39 static struct loaded_l10nfile *_nl_loaded_domains;
41 /* Return a data structure describing the message catalog described by
42 the DOMAINNAME and CATEGORY parameters with respect to the currently
43 established bindings. */
44 struct loaded_l10nfile *
45 _nl_find_domain(const unsigned char *dirname, unsigned char *locale, const unsigned char *domainname,
46 struct binding *domainbinding)
48 struct loaded_l10nfile *retval;
49 const unsigned char *language;
50 const unsigned char *modifier;
51 const unsigned char *territory;
52 const unsigned char *codeset;
53 const unsigned char *normalized_codeset;
54 const unsigned char *special;
55 const unsigned char *sponsor;
56 const unsigned char *revision;
57 const unsigned char *alias_value;
58 int mask;
60 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
62 language[_territory[.codeset]][@modifier]
64 and six parts for the CEN syntax:
66 language[_territory][+audience][+special][,[sponsor][_revision]]
68 Beside the first part all of them are allowed to be missing. If
69 the full specified locale is not found, the less specific one are
70 looked for. The various parts will be stripped off according to
71 the following order:
72 (1) revision
73 (2) sponsor
74 (3) special
75 (4) codeset
76 (5) normalized codeset
77 (6) territory
78 (7) audience/modifier
81 /* If we have already tested for this locale entry there has to
82 be one data set in the list of loaded domains. */
83 retval = _nl_make_l10nflist(&_nl_loaded_domains, dirname,
84 strlen(dirname) + 1, 0, locale, NULL, NULL,
85 NULL, NULL, NULL, NULL, NULL, domainname,
86 0);
87 if (retval != NULL) {
88 /* We know something about this locale. */
89 int cnt;
91 if (retval->decided == 0)
92 _nl_load_domain(retval, domainbinding);
94 if (retval->data != NULL)
95 return retval;
97 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt) {
98 if (retval->successor[cnt]->decided == 0)
99 _nl_load_domain(retval->successor[cnt],
100 domainbinding);
102 if (retval->successor[cnt]->data != NULL)
103 break;
105 return cnt >= 0 ? retval : NULL;
106 /* NOTREACHED */
109 /* See whether the locale value is an alias. If yes its value
110 *overwrites* the alias name. No test for the original value is
111 done. */
112 alias_value = _nl_expand_alias(locale);
113 if (alias_value != NULL) {
114 locale = strdup(alias_value);
115 if (locale == NULL)
116 return NULL;
119 /* Now we determine the single parts of the locale name. First
120 look for the language. Termination symbols are `_' and `@' if
121 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
122 mask = _nl_explode_name(locale, &language, &modifier, &territory,
123 &codeset, &normalized_codeset, &special,
124 &sponsor, &revision);
126 /* Create all possible locale entries which might be interested in
127 generalization. */
128 retval = _nl_make_l10nflist(&_nl_loaded_domains, dirname,
129 strlen(dirname) + 1, mask, language,
130 territory, codeset, normalized_codeset,
131 modifier, special, sponsor, revision,
132 domainname, 1);
133 if (retval == NULL)
134 /* This means we are out of core. */
135 return NULL;
137 if (retval->decided == 0)
138 _nl_load_domain(retval, domainbinding);
139 if (retval->data == NULL) {
140 int cnt;
142 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt) {
143 if (retval->successor[cnt]->decided == 0)
144 _nl_load_domain(retval->successor[cnt],
145 domainbinding);
146 if (retval->successor[cnt]->data != NULL)
147 break;
151 /* The room for an alias was dynamically allocated. Free it now. */
152 if (alias_value != NULL)
153 free(locale);
155 /* The space for normalized_codeset is dynamically allocated. Free it. */
156 if (mask & XPG_NORM_CODESET)
157 free((void *) normalized_codeset);
159 return retval;