3 /* Copyright (C) 1995-1998, 2000, 2001 Free Software Foundation, Inc.
4 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published
8 by the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <sys/types.h>
31 /* On some strange systems still no definition of NULL is found. Sigh! */
33 # if defined __STDC__ && __STDC__
34 # define NULL ((void *) 0)
40 /* @@ end of prolog @@ */
43 _nl_find_language (name
)
46 while (name
[0] != '\0' && name
[0] != '_' && name
[0] != '@'
47 && name
[0] != '+' && name
[0] != ',')
55 _nl_explode_name (name
, language
, modifier
, territory
, codeset
,
56 normalized_codeset
, special
, sponsor
, revision
)
58 const char **language
;
59 const char **modifier
;
60 const char **territory
;
62 const char **normalized_codeset
;
65 const char **revision
;
67 enum { undecided
, xpg
, cen
} syntax
;
74 *normalized_codeset
= NULL
;
79 /* Now we determine the single parts of the locale name. First
80 look for the language. Termination symbols are `_' and `@' if
81 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
84 *language
= cp
= name
;
85 cp
= _nl_find_language (*language
);
88 /* This does not make sense: language has to be specified. Use
89 this entry as it is without exploding. Perhaps it is an alias. */
90 cp
= strchr (*language
, '\0');
91 else if (cp
[0] == '_')
93 /* Next is the territory. */
97 while (cp
[0] != '\0' && cp
[0] != '.' && cp
[0] != '@'
98 && cp
[0] != '+' && cp
[0] != ',' && cp
[0] != '_')
105 /* Next is the codeset. */
110 while (cp
[0] != '\0' && cp
[0] != '@')
115 if (*codeset
!= cp
&& (*codeset
)[0] != '\0')
117 *normalized_codeset
= _nl_normalize_codeset (*codeset
,
119 if (strcmp (*codeset
, *normalized_codeset
) == 0)
120 free ((char *) *normalized_codeset
);
122 mask
|= XPG_NORM_CODESET
;
127 if (cp
[0] == '@' || (syntax
!= xpg
&& cp
[0] == '+'))
129 /* Next is the modifier. */
130 syntax
= cp
[0] == '@' ? xpg
: cen
;
134 while (syntax
== cen
&& cp
[0] != '\0' && cp
[0] != '+'
135 && cp
[0] != ',' && cp
[0] != '_')
138 mask
|= XPG_MODIFIER
| CEN_AUDIENCE
;
141 if (syntax
!= xpg
&& (cp
[0] == '+' || cp
[0] == ',' || cp
[0] == '_'))
147 /* Next is special application (CEN syntax). */
151 while (cp
[0] != '\0' && cp
[0] != ',' && cp
[0] != '_')
159 /* Next is sponsor (CEN syntax). */
163 while (cp
[0] != '\0' && cp
[0] != '_')
171 /* Next is revision (CEN syntax). */
175 mask
|= CEN_REVISION
;
179 /* For CEN syntax values it might be important to have the
180 separator character in the file name, not for XPG syntax. */
183 if (*territory
!= NULL
&& (*territory
)[0] == '\0')
186 if (*codeset
!= NULL
&& (*codeset
)[0] == '\0')
187 mask
&= ~XPG_CODESET
;
189 if (*modifier
!= NULL
&& (*modifier
)[0] == '\0')
190 mask
&= ~XPG_MODIFIER
;