1 /* Copyright (C) 1995-1998, 2000, 2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 #if defined STDC_HEADERS || defined _LIBC
28 #if defined HAVE_STRING_H || defined _LIBC
33 #include <sys/types.h>
37 /* On some strange systems still no definition of NULL is found. Sigh! */
39 # if defined __STDC__ && __STDC__
40 # define NULL ((void *) 0)
46 /* @@ end of prolog @@ */
49 _nl_find_language (name
)
52 while (name
[0] != '\0' && name
[0] != '_' && name
[0] != '@'
53 && name
[0] != '+' && name
[0] != ',')
61 _nl_explode_name (name
, language
, modifier
, territory
, codeset
,
62 normalized_codeset
, special
, sponsor
, revision
)
64 const char **language
;
65 const char **modifier
;
66 const char **territory
;
68 const char **normalized_codeset
;
71 const char **revision
;
73 enum { undecided
, xpg
, cen
} syntax
;
80 *normalized_codeset
= NULL
;
85 /* Now we determine the single parts of the locale name. First
86 look for the language. Termination symbols are `_' and `@' if
87 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
90 *language
= cp
= name
;
91 cp
= _nl_find_language (*language
);
94 /* This does not make sense: language has to be specified. Use
95 this entry as it is without exploding. Perhaps it is an alias. */
96 cp
= strchr (*language
, '\0');
97 else if (cp
[0] == '_')
99 /* Next is the territory. */
103 while (cp
[0] != '\0' && cp
[0] != '.' && cp
[0] != '@'
104 && cp
[0] != '+' && cp
[0] != ',' && cp
[0] != '_')
111 /* Next is the codeset. */
116 while (cp
[0] != '\0' && cp
[0] != '@')
121 if (*codeset
!= cp
&& (*codeset
)[0] != '\0')
123 *normalized_codeset
= _nl_normalize_codeset (*codeset
,
125 if (strcmp (*codeset
, *normalized_codeset
) == 0)
126 free ((char *) *normalized_codeset
);
128 mask
|= XPG_NORM_CODESET
;
133 if (cp
[0] == '@' || (syntax
!= xpg
&& cp
[0] == '+'))
135 /* Next is the modifier. */
136 syntax
= cp
[0] == '@' ? xpg
: cen
;
140 while (syntax
== cen
&& cp
[0] != '\0' && cp
[0] != '+'
141 && cp
[0] != ',' && cp
[0] != '_')
144 mask
|= XPG_MODIFIER
| CEN_AUDIENCE
;
147 if (syntax
!= xpg
&& (cp
[0] == '+' || cp
[0] == ',' || cp
[0] == '_'))
153 /* Next is special application (CEN syntax). */
157 while (cp
[0] != '\0' && cp
[0] != ',' && cp
[0] != '_')
165 /* Next is sponsor (CEN syntax). */
169 while (cp
[0] != '\0' && cp
[0] != '_')
177 /* Next is revision (CEN syntax). */
181 mask
|= CEN_REVISION
;
185 /* For CEN syntax values it might be important to have the
186 separator character in the file name, not for XPG syntax. */
189 if (*territory
!= NULL
&& (*territory
)[0] == '\0')
192 if (*codeset
!= NULL
&& (*codeset
)[0] == '\0')
193 mask
&= ~XPG_CODESET
;
195 if (*modifier
!= NULL
&& (*modifier
)[0] == '\0')
196 mask
&= ~XPG_MODIFIER
;