3 /* Copyright (C) 1995-1998, 2000-2001, 2003 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 (const char *name
)
45 while (name
[0] != '\0' && name
[0] != '_' && name
[0] != '@'
46 && name
[0] != '+' && name
[0] != ',')
54 _nl_explode_name (char *name
,
55 const char **language
, const char **modifier
,
56 const char **territory
, const char **codeset
,
57 const char **normalized_codeset
, const char **special
,
58 const char **sponsor
, const char **revision
)
60 enum { undecided
, xpg
, cen
} syntax
;
67 *normalized_codeset
= NULL
;
72 /* Now we determine the single parts of the locale name. First
73 look for the language. Termination symbols are `_' and `@' if
74 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
77 *language
= cp
= name
;
78 cp
= _nl_find_language (*language
);
81 /* This does not make sense: language has to be specified. Use
82 this entry as it is without exploding. Perhaps it is an alias. */
83 cp
= strchr (*language
, '\0');
84 else if (cp
[0] == '_')
86 /* Next is the territory. */
90 while (cp
[0] != '\0' && cp
[0] != '.' && cp
[0] != '@'
91 && cp
[0] != '+' && cp
[0] != ',' && cp
[0] != '_')
98 /* Next is the codeset. */
103 while (cp
[0] != '\0' && cp
[0] != '@')
108 if (*codeset
!= cp
&& (*codeset
)[0] != '\0')
110 *normalized_codeset
= _nl_normalize_codeset (*codeset
,
112 if (strcmp (*codeset
, *normalized_codeset
) == 0)
113 free ((char *) *normalized_codeset
);
115 mask
|= XPG_NORM_CODESET
;
120 if (cp
[0] == '@' || (syntax
!= xpg
&& cp
[0] == '+'))
122 /* Next is the modifier. */
123 syntax
= cp
[0] == '@' ? xpg
: cen
;
127 while (syntax
== cen
&& cp
[0] != '\0' && cp
[0] != '+'
128 && cp
[0] != ',' && cp
[0] != '_')
131 mask
|= XPG_MODIFIER
| CEN_AUDIENCE
;
134 if (syntax
!= xpg
&& (cp
[0] == '+' || cp
[0] == ',' || cp
[0] == '_'))
140 /* Next is special application (CEN syntax). */
144 while (cp
[0] != '\0' && cp
[0] != ',' && cp
[0] != '_')
152 /* Next is sponsor (CEN syntax). */
156 while (cp
[0] != '\0' && cp
[0] != '_')
164 /* Next is revision (CEN syntax). */
168 mask
|= CEN_REVISION
;
172 /* For CEN syntax values it might be important to have the
173 separator character in the file name, not for XPG syntax. */
176 if (*territory
!= NULL
&& (*territory
)[0] == '\0')
179 if (*codeset
!= NULL
&& (*codeset
)[0] == '\0')
180 mask
&= ~XPG_CODESET
;
182 if (*modifier
!= NULL
&& (*modifier
)[0] == '\0')
183 mask
&= ~XPG_MODIFIER
;