Sat Jul 13 02:47:53 1996 David Mosberger-Tang <davidm@azstarnet.com>
[glibc/history.git] / intl / explodename.c
blob7a0d015f3e05480d72ce6653b1a885a2ae701366
1 /* Copyright (C) 1995, 1996 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
19 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
20 Cambridge, MA 02139, USA. */
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
26 #include <stdlib.h>
27 #include <string.h>
29 #include "loadinfo.h"
31 /* On some strange systems still no definition of NULL is found. Sigh! */
32 #ifndef NULL
33 # if defined __STDC__ && __STDC__
34 # define NULL ((void *) 0)
35 # else
36 # define NULL 0
37 # endif
38 #endif
40 /* @@ end of prolog @@ */
42 int
43 _nl_explode_name (name, language, modifier, territory, codeset,
44 normalized_codeset, special, sponsor, revision)
45 char *name;
46 const char **language;
47 const char **modifier;
48 const char **territory;
49 const char **codeset;
50 const char **normalized_codeset;
51 const char **special;
52 const char **sponsor;
53 const char **revision;
55 enum { undecided, xpg, cen } syntax;
56 char *cp;
57 int mask;
59 *modifier = NULL;
60 *territory = NULL;
61 *codeset = NULL;
62 *normalized_codeset = NULL;
63 *special = NULL;
64 *sponsor = NULL;
65 *revision = NULL;
67 /* Now we determine the single parts of the locale name. First
68 look for the language. Termination symbols are `_' and `@' if
69 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
70 mask = 0;
71 syntax = undecided;
72 *language = cp = name;
73 while (cp[0] != '\0' && cp[0] != '_' && cp[0] != '@'
74 && cp[0] != '+' && cp[0] != ',')
75 ++cp;
77 if (*language == cp)
78 /* This does not make sense: language has to be specified. Use
79 this entry as it is without exploding. Perhaps it is an alias. */
80 cp = strchr (*language, '\0');
81 else if (cp[0] == '_')
83 /* Next is the territory. */
84 cp[0] = '\0';
85 *territory = ++cp;
87 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
88 && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
89 ++cp;
91 mask |= TERRITORY;
93 if (cp[0] == '.')
95 /* Next is the codeset. */
96 syntax = xpg;
97 cp[0] = '\0';
98 *codeset = ++cp;
100 while (cp[0] != '\0' && cp[0] != '@')
101 ++cp;
103 mask |= XPG_CODESET;
105 if (*codeset != cp && (*codeset)[0] != '\0')
107 *normalized_codeset = _nl_normalize_codeset (*codeset,
108 cp - *codeset);
109 if (strcmp (*codeset, *normalized_codeset) == 0)
110 free ((char *) *normalized_codeset);
111 else
112 mask |= XPG_NORM_CODESET;
117 if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
119 /* Next is the modifier. */
120 syntax = cp[0] == '@' ? xpg : cen;
121 cp[0] = '\0';
122 *modifier = ++cp;
124 while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
125 && cp[0] != ',' && cp[0] != '_')
126 ++cp;
128 mask |= XPG_MODIFIER | CEN_AUDIENCE;
131 if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
133 syntax = cen;
135 if (cp[0] == '+')
137 /* Next is special application (CEN syntax). */
138 cp[0] = '\0';
139 *special = ++cp;
141 while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
142 ++cp;
144 mask |= CEN_SPECIAL;
147 if (cp[0] == ',')
149 /* Next is sponsor (CEN syntax). */
150 cp[0] = '\0';
151 *sponsor = ++cp;
153 while (cp[0] != '\0' && cp[0] != '_')
154 ++cp;
156 mask |= CEN_SPONSOR;
159 if (cp[0] == '_')
161 /* Next is revision (CEN syntax). */
162 cp[0] = '\0';
163 *revision = ++cp;
165 mask |= CEN_REVISION;
169 /* For CEN sytnax values it might be important to have the
170 separator character in the file name, not for XPG syntax. */
171 if (syntax == xpg)
173 if (*territory != NULL && (*territory)[0] == '\0')
174 mask &= ~TERRITORY;
176 if (*codeset != NULL && (*codeset)[0] == '\0')
177 mask &= ~XPG_CODESET;
179 if (*modifier != NULL && (*modifier)[0] == '\0')
180 mask &= ~XPG_MODIFIER;
183 return mask;