3 /* Copyright (C) 1995-1998, 2000, 2001, 2005-2009 Free Software Foundation, Inc.
4 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
6 This file is part of GNU Bash.
8 Bash is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 Bash is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Bash. If not, see <http://www.gnu.org/licenses/>.
28 #include <sys/types.h>
32 /* On some strange systems still no definition of NULL is found. Sigh! */
34 # if defined __STDC__ && __STDC__
35 # define NULL ((void *) 0)
41 /* @@ end of prolog @@ */
44 _nl_find_language (name)
47 while (name[0] != '\0' && name[0] != '_' && name[0] != '@'
48 && name[0] != '+' && name[0] != ',')
56 _nl_explode_name (name, language, modifier, territory, codeset,
57 normalized_codeset, special, sponsor, revision)
59 const char **language;
60 const char **modifier;
61 const char **territory;
63 const char **normalized_codeset;
66 const char **revision;
68 enum { undecided, xpg, cen } syntax;
75 *normalized_codeset = NULL;
80 /* Now we determine the single parts of the locale name. First
81 look for the language. Termination symbols are `_' and `@' if
82 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
85 *language = cp = name;
86 cp = _nl_find_language (*language);
89 /* This does not make sense: language has to be specified. Use
90 this entry as it is without exploding. Perhaps it is an alias. */
91 cp = strchr (*language, '\0');
92 else if (cp[0] == '_')
94 /* Next is the territory. */
98 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
99 && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
106 /* Next is the codeset. */
111 while (cp[0] != '\0' && cp[0] != '@')
116 if (*codeset != cp && (*codeset)[0] != '\0')
118 *normalized_codeset = _nl_normalize_codeset (*codeset,
120 if (strcmp (*codeset, *normalized_codeset) == 0)
121 free ((char *) *normalized_codeset);
123 mask |= XPG_NORM_CODESET;
128 if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
130 /* Next is the modifier. */
131 syntax = cp[0] == '@' ? xpg : cen;
135 while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
136 && cp[0] != ',' && cp[0] != '_')
139 mask |= XPG_MODIFIER | CEN_AUDIENCE;
142 if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
148 /* Next is special application (CEN syntax). */
152 while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
160 /* Next is sponsor (CEN syntax). */
164 while (cp[0] != '\0' && cp[0] != '_')
172 /* Next is revision (CEN syntax). */
176 mask |= CEN_REVISION;
180 /* For CEN syntax values it might be important to have the
181 separator character in the file name, not for XPG syntax. */
184 if (*territory != NULL && (*territory)[0] == '\0')
187 if (*codeset != NULL && (*codeset)[0] == '\0')
188 mask &= ~XPG_CODESET;
190 if (*modifier != NULL && (*modifier)[0] == '\0')
191 mask &= ~XPG_MODIFIER;