Update.
[glibc.git] / intl / explodename.c
blob5561017876ce1682a5e606061105dde59d45ff3a
1 /* Copyright (C) 1995-1998, 2000, 2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
24 #if defined STDC_HEADERS || defined _LIBC
25 # include <stdlib.h>
26 #endif
28 #if defined HAVE_STRING_H || defined _LIBC
29 # include <string.h>
30 #else
31 # include <strings.h>
32 #endif
33 #include <sys/types.h>
35 #include "loadinfo.h"
37 /* On some strange systems still no definition of NULL is found. Sigh! */
38 #ifndef NULL
39 # if defined __STDC__ && __STDC__
40 # define NULL ((void *) 0)
41 # else
42 # define NULL 0
43 # endif
44 #endif
46 /* @@ end of prolog @@ */
48 char *
49 _nl_find_language (name)
50 const char *name;
52 while (name[0] != '\0' && name[0] != '_' && name[0] != '@'
53 && name[0] != '+' && name[0] != ',')
54 ++name;
56 return (char *) name;
60 int
61 _nl_explode_name (name, language, modifier, territory, codeset,
62 normalized_codeset, special, sponsor, revision)
63 char *name;
64 const char **language;
65 const char **modifier;
66 const char **territory;
67 const char **codeset;
68 const char **normalized_codeset;
69 const char **special;
70 const char **sponsor;
71 const char **revision;
73 enum { undecided, xpg, cen } syntax;
74 char *cp;
75 int mask;
77 *modifier = NULL;
78 *territory = NULL;
79 *codeset = NULL;
80 *normalized_codeset = NULL;
81 *special = NULL;
82 *sponsor = NULL;
83 *revision = NULL;
85 /* Now we determine the single parts of the locale name. First
86 look for the language. Termination symbols are `_' and `@' if
87 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
88 mask = 0;
89 syntax = undecided;
90 *language = cp = name;
91 cp = _nl_find_language (*language);
93 if (*language == cp)
94 /* This does not make sense: language has to be specified. Use
95 this entry as it is without exploding. Perhaps it is an alias. */
96 cp = strchr (*language, '\0');
97 else if (cp[0] == '_')
99 /* Next is the territory. */
100 cp[0] = '\0';
101 *territory = ++cp;
103 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
104 && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
105 ++cp;
107 mask |= TERRITORY;
109 if (cp[0] == '.')
111 /* Next is the codeset. */
112 syntax = xpg;
113 cp[0] = '\0';
114 *codeset = ++cp;
116 while (cp[0] != '\0' && cp[0] != '@')
117 ++cp;
119 mask |= XPG_CODESET;
121 if (*codeset != cp && (*codeset)[0] != '\0')
123 *normalized_codeset = _nl_normalize_codeset (*codeset,
124 cp - *codeset);
125 if (strcmp (*codeset, *normalized_codeset) == 0)
126 free ((char *) *normalized_codeset);
127 else
128 mask |= XPG_NORM_CODESET;
133 if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
135 /* Next is the modifier. */
136 syntax = cp[0] == '@' ? xpg : cen;
137 cp[0] = '\0';
138 *modifier = ++cp;
140 while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
141 && cp[0] != ',' && cp[0] != '_')
142 ++cp;
144 mask |= XPG_MODIFIER | CEN_AUDIENCE;
147 if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
149 syntax = cen;
151 if (cp[0] == '+')
153 /* Next is special application (CEN syntax). */
154 cp[0] = '\0';
155 *special = ++cp;
157 while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
158 ++cp;
160 mask |= CEN_SPECIAL;
163 if (cp[0] == ',')
165 /* Next is sponsor (CEN syntax). */
166 cp[0] = '\0';
167 *sponsor = ++cp;
169 while (cp[0] != '\0' && cp[0] != '_')
170 ++cp;
172 mask |= CEN_SPONSOR;
175 if (cp[0] == '_')
177 /* Next is revision (CEN syntax). */
178 cp[0] = '\0';
179 *revision = ++cp;
181 mask |= CEN_REVISION;
185 /* For CEN syntax values it might be important to have the
186 separator character in the file name, not for XPG syntax. */
187 if (syntax == xpg)
189 if (*territory != NULL && (*territory)[0] == '\0')
190 mask &= ~TERRITORY;
192 if (*codeset != NULL && (*codeset)[0] == '\0')
193 mask &= ~XPG_CODESET;
195 if (*modifier != NULL && (*modifier)[0] == '\0')
196 mask &= ~XPG_MODIFIER;
199 return mask;