1 /* Copyright (C) 1995, 1996, 1997 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #if defined STDC_HEADERS || defined _LIBC
26 #include <sys/types.h>
30 /* On some strange systems still no definition of NULL is found. Sigh! */
32 # if defined __STDC__ && __STDC__
33 # define NULL ((void *) 0)
39 /* @@ end of prolog @@ */
42 _nl_explode_name (name, language, modifier, territory, codeset,
43 normalized_codeset, special, sponsor, revision)
45 const char **language;
46 const char **modifier;
47 const char **territory;
49 const char **normalized_codeset;
52 const char **revision;
54 enum { undecided, xpg, cen } syntax;
61 *normalized_codeset = NULL;
66 /* Now we determine the single parts of the locale name. First
67 look for the language. Termination symbols are `_' and `@' if
68 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
71 *language = cp = name;
72 while (cp[0] != '\0' && cp[0] != '_' && cp[0] != '@'
73 && cp[0] != '+' && cp[0] != ',')
77 /* This does not make sense: language has to be specified. Use
78 this entry as it is without exploding. Perhaps it is an alias. */
79 cp = strchr (*language, '\0');
80 else if (cp[0] == '_')
82 /* Next is the territory. */
86 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
87 && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
94 /* Next is the codeset. */
99 while (cp[0] != '\0' && cp[0] != '@')
104 if (*codeset != cp && (*codeset)[0] != '\0')
106 *normalized_codeset = _nl_normalize_codeset (*codeset,
108 if (strcmp (*codeset, *normalized_codeset) == 0)
109 free ((char *) *normalized_codeset);
111 mask |= XPG_NORM_CODESET;
116 if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
118 /* Next is the modifier. */
119 syntax = cp[0] == '@' ? xpg : cen;
123 while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
124 && cp[0] != ',' && cp[0] != '_')
127 mask |= XPG_MODIFIER | CEN_AUDIENCE;
130 if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
136 /* Next is special application (CEN syntax). */
140 while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
148 /* Next is sponsor (CEN syntax). */
152 while (cp[0] != '\0' && cp[0] != '_')
160 /* Next is revision (CEN syntax). */
164 mask |= CEN_REVISION;
168 /* For CEN syntax values it might be important to have the
169 separator character in the file name, not for XPG syntax. */
172 if (*territory != NULL && (*territory)[0] == '\0')
175 if (*codeset != NULL && (*codeset)[0] == '\0')
176 mask &= ~XPG_CODESET;
178 if (*modifier != NULL && (*modifier)[0] == '\0')
179 mask &= ~XPG_MODIFIER;