Update.
[glibc.git] / intl / explodename.c
blobe62128d12ecc4afbb0c224fd4b770dd7e75c80f6
1 /* Copyright (C) 1995-1998, 2000, 2001 Free Software Foundation, Inc.
2 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library 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 GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
23 #if defined STDC_HEADERS || defined _LIBC
24 # include <stdlib.h>
25 #endif
27 #if defined HAVE_STRING_H || defined _LIBC
28 # include <string.h>
29 #else
30 # include <strings.h>
31 #endif
32 #include <sys/types.h>
34 #include "loadinfo.h"
36 /* On some strange systems still no definition of NULL is found. Sigh! */
37 #ifndef NULL
38 # if defined __STDC__ && __STDC__
39 # define NULL ((void *) 0)
40 # else
41 # define NULL 0
42 # endif
43 #endif
45 /* @@ end of prolog @@ */
47 char *
48 _nl_find_language (name)
49 const char *name;
51 while (name[0] != '\0' && name[0] != '_' && name[0] != '@'
52 && name[0] != '+' && name[0] != ',')
53 ++name;
55 return (char *) name;
59 int
60 _nl_explode_name (name, language, modifier, territory, codeset,
61 normalized_codeset, special, sponsor, revision)
62 char *name;
63 const char **language;
64 const char **modifier;
65 const char **territory;
66 const char **codeset;
67 const char **normalized_codeset;
68 const char **special;
69 const char **sponsor;
70 const char **revision;
72 enum { undecided, xpg, cen } syntax;
73 char *cp;
74 int mask;
76 *modifier = NULL;
77 *territory = NULL;
78 *codeset = NULL;
79 *normalized_codeset = NULL;
80 *special = NULL;
81 *sponsor = NULL;
82 *revision = NULL;
84 /* Now we determine the single parts of the locale name. First
85 look for the language. Termination symbols are `_' and `@' if
86 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
87 mask = 0;
88 syntax = undecided;
89 *language = cp = name;
90 cp = _nl_find_language (*language);
92 if (*language == cp)
93 /* This does not make sense: language has to be specified. Use
94 this entry as it is without exploding. Perhaps it is an alias. */
95 cp = strchr (*language, '\0');
96 else if (cp[0] == '_')
98 /* Next is the territory. */
99 cp[0] = '\0';
100 *territory = ++cp;
102 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
103 && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
104 ++cp;
106 mask |= TERRITORY;
108 if (cp[0] == '.')
110 /* Next is the codeset. */
111 syntax = xpg;
112 cp[0] = '\0';
113 *codeset = ++cp;
115 while (cp[0] != '\0' && cp[0] != '@')
116 ++cp;
118 mask |= XPG_CODESET;
120 if (*codeset != cp && (*codeset)[0] != '\0')
122 *normalized_codeset = _nl_normalize_codeset (*codeset,
123 cp - *codeset);
124 if (strcmp (*codeset, *normalized_codeset) == 0)
125 free ((char *) *normalized_codeset);
126 else
127 mask |= XPG_NORM_CODESET;
132 if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
134 /* Next is the modifier. */
135 syntax = cp[0] == '@' ? xpg : cen;
136 cp[0] = '\0';
137 *modifier = ++cp;
139 while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
140 && cp[0] != ',' && cp[0] != '_')
141 ++cp;
143 mask |= XPG_MODIFIER | CEN_AUDIENCE;
146 if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
148 syntax = cen;
150 if (cp[0] == '+')
152 /* Next is special application (CEN syntax). */
153 cp[0] = '\0';
154 *special = ++cp;
156 while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
157 ++cp;
159 mask |= CEN_SPECIAL;
162 if (cp[0] == ',')
164 /* Next is sponsor (CEN syntax). */
165 cp[0] = '\0';
166 *sponsor = ++cp;
168 while (cp[0] != '\0' && cp[0] != '_')
169 ++cp;
171 mask |= CEN_SPONSOR;
174 if (cp[0] == '_')
176 /* Next is revision (CEN syntax). */
177 cp[0] = '\0';
178 *revision = ++cp;
180 mask |= CEN_REVISION;
184 /* For CEN syntax values it might be important to have the
185 separator character in the file name, not for XPG syntax. */
186 if (syntax == xpg)
188 if (*territory != NULL && (*territory)[0] == '\0')
189 mask &= ~TERRITORY;
191 if (*codeset != NULL && (*codeset)[0] == '\0')
192 mask &= ~XPG_CODESET;
194 if (*modifier != NULL && (*modifier)[0] == '\0')
195 mask &= ~XPG_MODIFIER;
198 return mask;