1 /* finddomain.c -- 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 file is part of the GNU C Library. Its master source is NOT part of
6 the C library, however. The master source lives in /gd/gnu/lib.
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 The GNU C Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with the GNU C Library; see the file COPYING.LIB. If not,
20 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
30 #include <sys/types.h>
32 #if defined STDC_HEADERS || defined _LIBC
42 #if defined HAVE_STRING_H || defined _LIBC
47 #if !HAVE_STRCHR && !defined _LIBC
53 #if defined HAVE_UNISTD_H || defined _LIBC
62 # include "libgettext.h"
65 /* @@ end of prolog @@ */
66 /* List of already loaded domains. */
67 static struct loaded_l10nfile
*_nl_loaded_domains
;
70 /* Return a data structure describing the message catalog described by
71 the DOMAINNAME and CATEGORY parameters with respect to the currently
72 established bindings. */
73 struct loaded_l10nfile
*
74 _nl_find_domain (dirname
, locale
, domainname
)
77 const char *domainname
;
79 struct loaded_l10nfile
*retval
;
82 const char *territory
;
84 const char *normalized_codeset
;
88 const char *alias_value
;
91 /* LOCALE can consist of up to four recognized parts for the XPG syntax:
93 language[_territory[.codeset]][@modifier]
95 and six parts for the CEN syntax:
97 language[_territory][+audience][+special][,[sponsor][_revision]]
99 Beside the first all of them are allowed to be missing. If the
100 full specified locale is not found, the less specific one are
101 looked for. The various part will be stripped of according to
107 (5) normalized codeset
109 (7) audience/modifier
112 /* If we have already tested for this locale entry there has to
113 be one data set in the list of loaded domains. */
114 retval
= _nl_make_l10nflist (&_nl_loaded_domains
, dirname
,
115 strlen (dirname
) + 1, 0, locale
, NULL
, NULL
,
116 NULL
, NULL
, NULL
, NULL
, NULL
, domainname
, 0);
119 /* We know something about this locale. */
122 if (retval
->decided
== 0)
123 _nl_load_domain (retval
);
125 if (retval
->data
!= NULL
)
128 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
)
130 if (retval
->successor
[cnt
]->decided
== 0)
131 _nl_load_domain (retval
->successor
[cnt
]);
133 if (retval
->successor
[cnt
]->data
!= NULL
)
136 return cnt
>= 0 ? retval
: NULL
;
140 /* See whether the locale value is an alias. If yes its value
141 *overwrites* the alias name. No test for the original value is
143 alias_value
= _nl_expand_alias (locale
);
144 if (alias_value
!= NULL
)
146 size_t len
= strlen (alias_value
) + 1;
147 locale
= (char *) malloc (len
);
151 memcpy (locale
, alias_value
, len
);
154 /* Now we determine the single parts of the locale name. First
155 look for the language. Termination symbols are `_' and `@' if
156 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
157 mask
= _nl_explode_name (locale
, &language
, &modifier
, &territory
,
158 &codeset
, &normalized_codeset
, &special
,
159 &sponsor
, &revision
);
161 /* Create all possible locale entries which might be interested in
163 retval
= _nl_make_l10nflist (&_nl_loaded_domains
, dirname
,
164 strlen (dirname
) + 1, mask
, language
, territory
,
165 codeset
, normalized_codeset
, modifier
, special
,
166 sponsor
, revision
, domainname
, 1);
168 /* This means we are out of core. */
171 if (retval
->decided
== 0)
172 _nl_load_domain (retval
);
173 if (retval
->data
== NULL
)
176 for (cnt
= 0; retval
->successor
[cnt
] != NULL
; ++cnt
)
178 if (retval
->successor
[cnt
]->decided
== 0)
179 _nl_load_domain (retval
->successor
[cnt
]);
180 if (retval
->successor
[cnt
]->data
!= NULL
)
185 /* The room for an alias was dynamically allocated. Free it now. */
186 if (alias_value
!= NULL
)