Update.
[glibc.git] / intl / explodename.c
blobf89c7c93f9bab052a3c12210a53d966c5a8727f1
1 /* Copyright (C) 1995, 1996, 1997, 1998, 2000 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 (const char *name)
50 while (name[0] != '\0' && name[0] != '_' && name[0] != '@'
51 && name[0] != '+' && name[0] != ',')
52 ++name;
54 return (char *) name;
58 int
59 _nl_explode_name (name, language, modifier, territory, codeset,
60 normalized_codeset, special, sponsor, revision)
61 char *name;
62 const char **language;
63 const char **modifier;
64 const char **territory;
65 const char **codeset;
66 const char **normalized_codeset;
67 const char **special;
68 const char **sponsor;
69 const char **revision;
71 enum { undecided, xpg, cen } syntax;
72 char *cp;
73 int mask;
75 *modifier = NULL;
76 *territory = NULL;
77 *codeset = NULL;
78 *normalized_codeset = NULL;
79 *special = NULL;
80 *sponsor = NULL;
81 *revision = NULL;
83 /* Now we determine the single parts of the locale name. First
84 look for the language. Termination symbols are `_' and `@' if
85 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
86 mask = 0;
87 syntax = undecided;
88 *language = cp = name;
89 cp = _nl_find_language (*language);
91 if (*language == cp)
92 /* This does not make sense: language has to be specified. Use
93 this entry as it is without exploding. Perhaps it is an alias. */
94 cp = strchr (*language, '\0');
95 else if (cp[0] == '_')
97 /* Next is the territory. */
98 cp[0] = '\0';
99 *territory = ++cp;
101 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
102 && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
103 ++cp;
105 mask |= TERRITORY;
107 if (cp[0] == '.')
109 /* Next is the codeset. */
110 syntax = xpg;
111 cp[0] = '\0';
112 *codeset = ++cp;
114 while (cp[0] != '\0' && cp[0] != '@')
115 ++cp;
117 mask |= XPG_CODESET;
119 if (*codeset != cp && (*codeset)[0] != '\0')
121 *normalized_codeset = _nl_normalize_codeset (*codeset,
122 cp - *codeset);
123 if (strcmp (*codeset, *normalized_codeset) == 0)
124 free ((char *) *normalized_codeset);
125 else
126 mask |= XPG_NORM_CODESET;
131 if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
133 /* Next is the modifier. */
134 syntax = cp[0] == '@' ? xpg : cen;
135 cp[0] = '\0';
136 *modifier = ++cp;
138 while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
139 && cp[0] != ',' && cp[0] != '_')
140 ++cp;
142 mask |= XPG_MODIFIER | CEN_AUDIENCE;
145 if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
147 syntax = cen;
149 if (cp[0] == '+')
151 /* Next is special application (CEN syntax). */
152 cp[0] = '\0';
153 *special = ++cp;
155 while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
156 ++cp;
158 mask |= CEN_SPECIAL;
161 if (cp[0] == ',')
163 /* Next is sponsor (CEN syntax). */
164 cp[0] = '\0';
165 *sponsor = ++cp;
167 while (cp[0] != '\0' && cp[0] != '_')
168 ++cp;
170 mask |= CEN_SPONSOR;
173 if (cp[0] == '_')
175 /* Next is revision (CEN syntax). */
176 cp[0] = '\0';
177 *revision = ++cp;
179 mask |= CEN_REVISION;
183 /* For CEN syntax values it might be important to have the
184 separator character in the file name, not for XPG syntax. */
185 if (syntax == xpg)
187 if (*territory != NULL && (*territory)[0] == '\0')
188 mask &= ~TERRITORY;
190 if (*codeset != NULL && (*codeset)[0] == '\0')
191 mask &= ~XPG_CODESET;
193 if (*modifier != NULL && (*modifier)[0] == '\0')
194 mask &= ~XPG_MODIFIER;
197 return mask;