1 /* Copyright (C) 1995-2024 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
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
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
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
23 #include <sys/types.h>
27 /* On some strange systems still no definition of NULL is found. Sigh! */
29 # if defined __STDC__ && __STDC__
30 # define NULL ((void *) 0)
36 /* @@ end of prolog @@ */
38 /* Split a locale name NAME into a leading language part and all the
39 rest. Return a pointer to the first character after the language,
40 i.e. to the first byte of the rest. */
41 static char *_nl_find_language (const char *name
);
44 _nl_find_language (const char *name
)
46 while (name
[0] != '\0' && name
[0] != '_' && 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
)
65 *normalized_codeset
= NULL
;
67 /* Now we determine the single parts of the locale name. First
68 look for the language. Termination symbols are `_', '.', and `@'. */
70 *language
= cp
= name
;
71 cp
= _nl_find_language (*language
);
74 /* This does not make sense: language has to be specified. Use
75 this entry as it is without exploding. Perhaps it is an alias. */
76 cp
= strchr (*language
, '\0');
81 /* Next is the territory. */
85 while (cp
[0] != '\0' && cp
[0] != '.' && cp
[0] != '@')
88 mask
|= XPG_TERRITORY
;
93 /* Next is the codeset. */
97 while (cp
[0] != '\0' && cp
[0] != '@')
102 if (*codeset
!= cp
&& (*codeset
)[0] != '\0')
104 *normalized_codeset
= _nl_normalize_codeset (*codeset
,
106 if (*normalized_codeset
== NULL
)
108 else if (strcmp (*codeset
, *normalized_codeset
) == 0)
109 free ((char *) *normalized_codeset
);
111 mask
|= XPG_NORM_CODESET
;
118 /* Next is the modifier. */
123 mask
|= XPG_MODIFIER
;
126 if (*territory
!= NULL
&& (*territory
)[0] == '\0')
127 mask
&= ~XPG_TERRITORY
;
129 if (*codeset
!= NULL
&& (*codeset
)[0] == '\0')
130 mask
&= ~XPG_CODESET
;