1 /* Copyright (C) 1995, 1996, 1997, 1998 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 General Public License as published by
6 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. */
18 #include "intlconfig.h"
20 #if defined STDC_HEADERS || defined _LIBC
24 #if defined HAVE_STRING_H || defined _LIBC
29 #include <sys/types.h>
33 /* On some strange systems still no definition of NULL is found. Sigh! */
35 # if defined __STDC__ && __STDC__
36 # define NULL ((void *) 0)
42 /* @@ end of prolog @@ */
45 _nl_explode_name (name, language, modifier, territory, codeset,
46 normalized_codeset, special, sponsor, revision)
48 const char **language;
49 const char **modifier;
50 const char **territory;
52 const char **normalized_codeset;
55 const char **revision;
57 enum { undecided, xpg, cen } syntax;
64 *normalized_codeset = NULL;
69 /* Now we determine the single parts of the locale name. First
70 look for the language. Termination symbols are `_' and `@' if
71 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
74 *language = cp = name;
75 while (cp[0] != '\0' && cp[0] != '_' && cp[0] != '@'
76 && cp[0] != '+' && cp[0] != ',')
80 /* This does not make sense: language has to be specified. Use
81 this entry as it is without exploding. Perhaps it is an alias. */
82 cp = strchr (*language, '\0');
83 else if (cp[0] == '_')
85 /* Next is the territory. */
89 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
90 && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
97 /* Next is the codeset. */
102 while (cp[0] != '\0' && cp[0] != '@')
107 if (*codeset != cp && (*codeset)[0] != '\0')
109 *normalized_codeset = _nl_normalize_codeset (*codeset,
111 if (strcmp (*codeset, *normalized_codeset) == 0)
112 free ((char *) *normalized_codeset);
114 mask |= XPG_NORM_CODESET;
119 if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
121 /* Next is the modifier. */
122 syntax = cp[0] == '@' ? xpg : cen;
126 while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
127 && cp[0] != ',' && cp[0] != '_')
130 mask |= XPG_MODIFIER | CEN_AUDIENCE;
133 if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
139 /* Next is special application (CEN syntax). */
143 while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
151 /* Next is sponsor (CEN syntax). */
155 while (cp[0] != '\0' && cp[0] != '_')
163 /* Next is revision (CEN syntax). */
167 mask |= CEN_REVISION;
171 /* For CEN syntax values it might be important to have the
172 separator character in the file name, not for XPG syntax. */
175 if (*territory != NULL && (*territory)[0] == '\0')
178 if (*codeset != NULL && (*codeset)[0] == '\0')
179 mask &= ~XPG_CODESET;
181 if (*modifier != NULL && (*modifier)[0] == '\0')
182 mask &= ~XPG_MODIFIER;