Add field ``name'' to floatformat.
[binutils.git] / intl / finddomain.c
blobec85d4de4d129a3c41dbbd29338a4d4ce3428b24
1 /* Handle list of needed message catalogs
2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
3 Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 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 <ctype.h>
24 #include <errno.h>
25 #include <stdio.h>
26 #include <sys/types.h>
28 #if defined STDC_HEADERS || defined _LIBC
29 # include <stdlib.h>
30 #else
31 # ifdef HAVE_MALLOC_H
32 # include <malloc.h>
33 # else
34 void free ();
35 # endif
36 #endif
38 #if defined HAVE_STRING_H || defined _LIBC
39 # include <string.h>
40 #else
41 # include <strings.h>
42 # ifndef memcpy
43 # define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num)
44 # endif
45 #endif
46 #if !HAVE_STRCHR && !defined _LIBC
47 # ifndef strchr
48 # define strchr index
49 # endif
50 #endif
52 #if defined HAVE_UNISTD_H || defined _LIBC
53 # include <unistd.h>
54 #endif
56 #include "gettext.h"
57 #include "gettextP.h"
58 #ifdef _LIBC
59 # include <libintl.h>
60 #else
61 # include "libgettext.h"
62 #endif
64 /* @@ end of prolog @@ */
65 /* List of already loaded domains. */
66 static struct loaded_l10nfile *_nl_loaded_domains;
69 /* Return a data structure describing the message catalog described by
70 the DOMAINNAME and CATEGORY parameters with respect to the currently
71 established bindings. */
72 struct loaded_l10nfile *
73 _nl_find_domain (dirname, locale, domainname)
74 const char *dirname;
75 char *locale;
76 const char *domainname;
78 struct loaded_l10nfile *retval;
79 const char *language;
80 const char *modifier;
81 const char *territory;
82 const char *codeset;
83 const char *normalized_codeset;
84 const char *special;
85 const char *sponsor;
86 const char *revision;
87 const char *alias_value;
88 int mask;
90 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
92 language[_territory[.codeset]][@modifier]
94 and six parts for the CEN syntax:
96 language[_territory][+audience][+special][,[sponsor][_revision]]
98 Beside the first all of them are allowed to be missing. If the
99 full specified locale is not found, the less specific one are
100 looked for. The various part will be stripped of according to
101 the following order:
102 (1) revision
103 (2) sponsor
104 (3) special
105 (4) codeset
106 (5) normalized codeset
107 (6) territory
108 (7) audience/modifier
111 /* If we have already tested for this locale entry there has to
112 be one data set in the list of loaded domains. */
113 retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
114 strlen (dirname) + 1, 0, locale, NULL, NULL,
115 NULL, NULL, NULL, NULL, NULL, domainname, 0);
116 if (retval != NULL)
118 /* We know something about this locale. */
119 int cnt;
121 if (retval->decided == 0)
122 _nl_load_domain (retval);
124 if (retval->data != NULL)
125 return retval;
127 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
129 if (retval->successor[cnt]->decided == 0)
130 _nl_load_domain (retval->successor[cnt]);
132 if (retval->successor[cnt]->data != NULL)
133 break;
135 return cnt >= 0 ? retval : NULL;
136 /* NOTREACHED */
139 /* See whether the locale value is an alias. If yes its value
140 *overwrites* the alias name. No test for the original value is
141 done. */
142 alias_value = _nl_expand_alias (locale);
143 if (alias_value != NULL)
145 size_t len = strlen (alias_value) + 1;
146 locale = (char *) malloc (len);
147 if (locale == NULL)
148 return NULL;
150 memcpy (locale, alias_value, len);
153 /* Now we determine the single parts of the locale name. First
154 look for the language. Termination symbols are `_' and `@' if
155 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
156 mask = _nl_explode_name (locale, &language, &modifier, &territory,
157 &codeset, &normalized_codeset, &special,
158 &sponsor, &revision);
160 /* Create all possible locale entries which might be interested in
161 generalization. */
162 retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
163 strlen (dirname) + 1, mask, language, territory,
164 codeset, normalized_codeset, modifier, special,
165 sponsor, revision, domainname, 1);
166 if (retval == NULL)
167 /* This means we are out of core. */
168 return NULL;
170 if (retval->decided == 0)
171 _nl_load_domain (retval);
172 if (retval->data == NULL)
174 int cnt;
175 for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
177 if (retval->successor[cnt]->decided == 0)
178 _nl_load_domain (retval->successor[cnt]);
179 if (retval->successor[cnt]->data != NULL)
180 break;
184 /* The room for an alias was dynamically allocated. Free it now. */
185 if (alias_value != NULL)
186 free (locale);
188 return retval;