1 /* Copyright (C) 1995-1998, 2000, 2001 Free Software Foundation, Inc.
2 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published
6 by the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 #include <sys/types.h>
29 /* On some strange systems still no definition of NULL is found. Sigh! */
31 # if defined __STDC__ && __STDC__
32 # define NULL ((void *) 0)
38 /* @@ end of prolog @@ */
41 _nl_find_language (name
)
44 while (name
[0] != '\0' && name
[0] != '_' && name
[0] != '@'
45 && name
[0] != '+' && name
[0] != ',')
53 _nl_explode_name (name
, language
, modifier
, territory
, codeset
,
54 normalized_codeset
, special
, sponsor
, revision
)
56 const char **language
;
57 const char **modifier
;
58 const char **territory
;
60 const char **normalized_codeset
;
63 const char **revision
;
65 enum { undecided
, xpg
, cen
} syntax
;
72 *normalized_codeset
= NULL
;
77 /* Now we determine the single parts of the locale name. First
78 look for the language. Termination symbols are `_' and `@' if
79 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
82 *language
= cp
= name
;
83 cp
= _nl_find_language (*language
);
86 /* This does not make sense: language has to be specified. Use
87 this entry as it is without exploding. Perhaps it is an alias. */
88 cp
= strchr (*language
, '\0');
89 else if (cp
[0] == '_')
91 /* Next is the territory. */
95 while (cp
[0] != '\0' && cp
[0] != '.' && cp
[0] != '@'
96 && cp
[0] != '+' && cp
[0] != ',' && cp
[0] != '_')
103 /* Next is the codeset. */
108 while (cp
[0] != '\0' && cp
[0] != '@')
113 if (*codeset
!= cp
&& (*codeset
)[0] != '\0')
115 *normalized_codeset
= _nl_normalize_codeset (*codeset
,
117 if (strcmp (*codeset
, *normalized_codeset
) == 0)
118 free ((char *) *normalized_codeset
);
120 mask
|= XPG_NORM_CODESET
;
125 if (cp
[0] == '@' || (syntax
!= xpg
&& cp
[0] == '+'))
127 /* Next is the modifier. */
128 syntax
= cp
[0] == '@' ? xpg
: cen
;
132 while (syntax
== cen
&& cp
[0] != '\0' && cp
[0] != '+'
133 && cp
[0] != ',' && cp
[0] != '_')
136 mask
|= XPG_MODIFIER
| CEN_AUDIENCE
;
139 if (syntax
!= xpg
&& (cp
[0] == '+' || cp
[0] == ',' || cp
[0] == '_'))
145 /* Next is special application (CEN syntax). */
149 while (cp
[0] != '\0' && cp
[0] != ',' && cp
[0] != '_')
157 /* Next is sponsor (CEN syntax). */
161 while (cp
[0] != '\0' && cp
[0] != '_')
169 /* Next is revision (CEN syntax). */
173 mask
|= CEN_REVISION
;
177 /* For CEN syntax values it might be important to have the
178 separator character in the file name, not for XPG syntax. */
181 if (*territory
!= NULL
&& (*territory
)[0] == '\0')
184 if (*codeset
!= NULL
&& (*codeset
)[0] == '\0')
185 mask
&= ~XPG_CODESET
;
187 if (*modifier
!= NULL
&& (*modifier
)[0] == '\0')
188 mask
&= ~XPG_MODIFIER
;