update from main arhive 970119
[glibc.git] / intl / explodename.c
blobe938ff234bd16a37056e398aae58cbb6a867a113
1 /* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
2 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
4 This file is part of the GNU C Library. Its master source is NOT part of
5 the C library, however. The master source lives in /gd/gnu/lib.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the GNU C Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
26 #include <stdlib.h>
27 #include <string.h>
28 #include <sys/types.h>
30 #include "loadinfo.h"
32 /* On some strange systems still no definition of NULL is found. Sigh! */
33 #ifndef NULL
34 # if defined __STDC__ && __STDC__
35 # define NULL ((void *) 0)
36 # else
37 # define NULL 0
38 # endif
39 #endif
41 /* @@ end of prolog @@ */
43 int
44 _nl_explode_name (name, language, modifier, territory, codeset,
45 normalized_codeset, special, sponsor, revision)
46 char *name;
47 const char **language;
48 const char **modifier;
49 const char **territory;
50 const char **codeset;
51 const char **normalized_codeset;
52 const char **special;
53 const char **sponsor;
54 const char **revision;
56 enum { undecided, xpg, cen } syntax;
57 char *cp;
58 int mask;
60 *modifier = NULL;
61 *territory = NULL;
62 *codeset = NULL;
63 *normalized_codeset = NULL;
64 *special = NULL;
65 *sponsor = NULL;
66 *revision = NULL;
68 /* Now we determine the single parts of the locale name. First
69 look for the language. Termination symbols are `_' and `@' if
70 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
71 mask = 0;
72 syntax = undecided;
73 *language = cp = name;
74 while (cp[0] != '\0' && cp[0] != '_' && cp[0] != '@'
75 && cp[0] != '+' && cp[0] != ',')
76 ++cp;
78 if (*language == cp)
79 /* This does not make sense: language has to be specified. Use
80 this entry as it is without exploding. Perhaps it is an alias. */
81 cp = strchr (*language, '\0');
82 else if (cp[0] == '_')
84 /* Next is the territory. */
85 cp[0] = '\0';
86 *territory = ++cp;
88 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
89 && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
90 ++cp;
92 mask |= TERRITORY;
94 if (cp[0] == '.')
96 /* Next is the codeset. */
97 syntax = xpg;
98 cp[0] = '\0';
99 *codeset = ++cp;
101 while (cp[0] != '\0' && cp[0] != '@')
102 ++cp;
104 mask |= XPG_CODESET;
106 if (*codeset != cp && (*codeset)[0] != '\0')
108 *normalized_codeset = _nl_normalize_codeset (*codeset,
109 cp - *codeset);
110 if (strcmp (*codeset, *normalized_codeset) == 0)
111 free ((char *) *normalized_codeset);
112 else
113 mask |= XPG_NORM_CODESET;
118 if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
120 /* Next is the modifier. */
121 syntax = cp[0] == '@' ? xpg : cen;
122 cp[0] = '\0';
123 *modifier = ++cp;
125 while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
126 && cp[0] != ',' && cp[0] != '_')
127 ++cp;
129 mask |= XPG_MODIFIER | CEN_AUDIENCE;
132 if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
134 syntax = cen;
136 if (cp[0] == '+')
138 /* Next is special application (CEN syntax). */
139 cp[0] = '\0';
140 *special = ++cp;
142 while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
143 ++cp;
145 mask |= CEN_SPECIAL;
148 if (cp[0] == ',')
150 /* Next is sponsor (CEN syntax). */
151 cp[0] = '\0';
152 *sponsor = ++cp;
154 while (cp[0] != '\0' && cp[0] != '_')
155 ++cp;
157 mask |= CEN_SPONSOR;
160 if (cp[0] == '_')
162 /* Next is revision (CEN syntax). */
163 cp[0] = '\0';
164 *revision = ++cp;
166 mask |= CEN_REVISION;
170 /* For CEN syntax values it might be important to have the
171 separator character in the file name, not for XPG syntax. */
172 if (syntax == xpg)
174 if (*territory != NULL && (*territory)[0] == '\0')
175 mask &= ~TERRITORY;
177 if (*codeset != NULL && (*codeset)[0] == '\0')
178 mask &= ~XPG_CODESET;
180 if (*modifier != NULL && (*modifier)[0] == '\0')
181 mask &= ~XPG_MODIFIER;
184 return mask;