*** empty log message ***
[glibc.git] / intl / explodename.c
blob2fd8be014d5ccc21758abe84b12377d0442e1735
1 /* Copyright (C) 1995, 1996 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <stdlib.h>
21 #include <string.h>
23 #include "loadinfo.h"
25 int
26 _nl_explode_name (name, language, modifier, territory, codeset,
27 normalized_codeset, special, sponsor, revision)
28 char *name;
29 const char **language;
30 const char **modifier;
31 const char **territory;
32 const char **codeset;
33 const char **normalized_codeset;
34 const char **special;
35 const char **sponsor;
36 const char **revision;
38 enum { undecided, xpg, cen } syntax;
39 char *cp;
40 int mask;
42 *modifier = NULL;
43 *territory = NULL;
44 *codeset = NULL;
45 *normalized_codeset = NULL;
46 *special = NULL;
47 *sponsor = NULL;
48 *revision = NULL;
50 /* Now we determine the single parts of the locale name. First
51 look for the language. Termination symbols are `_' and `@' if
52 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
53 mask = 0;
54 syntax = undecided;
55 *language = cp = name;
56 while (cp[0] != '\0' && cp[0] != '_' && cp[0] != '@'
57 && cp[0] != '+' && cp[0] != ',')
58 ++cp;
60 if (*language == cp)
61 /* This does not make sense: language has to be specified. Use
62 this entry as it is without exploding. Perhaps it is an alias. */
63 cp = strchr (*language, '\0');
64 else if (cp[0] == '_')
66 /* Next is the territory. */
67 cp[0] = '\0';
68 *territory = ++cp;
70 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
71 && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
72 ++cp;
74 mask |= TERRITORY;
76 if (cp[0] == '.')
78 /* Next is the codeset. */
79 syntax = xpg;
80 cp[0] = '\0';
81 *codeset = ++cp;
83 while (cp[0] != '\0' && cp[0] != '@')
84 ++cp;
86 mask |= XPG_CODESET;
88 if (*codeset != cp && (*codeset)[0] != '\0')
90 *normalized_codeset = _nl_normalize_codeset (*codeset,
91 cp - *codeset);
92 if (strcmp (*codeset, *normalized_codeset) == 0)
93 free ((char *) *normalized_codeset);
94 else
95 mask |= XPG_NORM_CODESET;
100 if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
102 /* Next is the modifier. */
103 syntax = cp[0] == '@' ? xpg : cen;
104 cp[0] = '\0';
105 *modifier = ++cp;
107 while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
108 && cp[0] != ',' && cp[0] != '_')
109 ++cp;
111 mask |= XPG_MODIFIER | CEN_AUDIENCE;
114 if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
116 syntax = cen;
118 if (cp[0] == '+')
120 /* Next is special application (CEN syntax). */
121 cp[0] = '\0';
122 *special = ++cp;
124 while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
125 ++cp;
127 mask |= CEN_SPECIAL;
130 if (cp[0] == ',')
132 /* Next is sponsor (CEN syntax). */
133 cp[0] = '\0';
134 *sponsor = ++cp;
136 while (cp[0] != '\0' && cp[0] != '_')
137 ++cp;
139 mask |= CEN_SPONSOR;
142 if (cp[0] == '_')
144 /* Next is revision (CEN syntax). */
145 cp[0] = '\0';
146 *revision = ++cp;
148 mask |= CEN_REVISION;
152 /* For CEN sytnax values it might be important to have the
153 separator character in the file name, not for XPG syntax. */
154 if (syntax == xpg)
156 if (*territory != NULL && (*territory)[0] == '\0')
157 mask &= ~TERRITORY;
159 if (*codeset != NULL && (*codeset)[0] == '\0')
160 mask &= ~XPG_CODESET;
162 if (*modifier != NULL && (*modifier)[0] == '\0')
163 mask &= ~XPG_MODIFIER;
166 return mask;