Added gitignore entries needed to ignore derived objects generated from full build...
[bash.git] / lib / intl / explodename.c
blobadc36402bb91547d840b4608a086a7a73d527bc1
1 /* explodename.c */
3 /* Copyright (C) 1995-1998, 2000, 2001, 2005-2009 Free Software Foundation, Inc.
4 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
6 This file is part of GNU Bash.
8 Bash is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 Bash is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Bash. If not, see <http://www.gnu.org/licenses/>.
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 char *
44 _nl_find_language (name)
45 const char *name;
47 while (name[0] != '\0' && name[0] != '_' && name[0] != '@'
48 && name[0] != '+' && name[0] != ',')
49 ++name;
51 return (char *) name;
55 int
56 _nl_explode_name (name, language, modifier, territory, codeset,
57 normalized_codeset, special, sponsor, revision)
58 char *name;
59 const char **language;
60 const char **modifier;
61 const char **territory;
62 const char **codeset;
63 const char **normalized_codeset;
64 const char **special;
65 const char **sponsor;
66 const char **revision;
68 enum { undecided, xpg, cen } syntax;
69 char *cp;
70 int mask;
72 *modifier = NULL;
73 *territory = NULL;
74 *codeset = NULL;
75 *normalized_codeset = NULL;
76 *special = NULL;
77 *sponsor = NULL;
78 *revision = NULL;
80 /* Now we determine the single parts of the locale name. First
81 look for the language. Termination symbols are `_' and `@' if
82 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
83 mask = 0;
84 syntax = undecided;
85 *language = cp = name;
86 cp = _nl_find_language (*language);
88 if (*language == cp)
89 /* This does not make sense: language has to be specified. Use
90 this entry as it is without exploding. Perhaps it is an alias. */
91 cp = strchr (*language, '\0');
92 else if (cp[0] == '_')
94 /* Next is the territory. */
95 cp[0] = '\0';
96 *territory = ++cp;
98 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
99 && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
100 ++cp;
102 mask |= TERRITORY;
104 if (cp[0] == '.')
106 /* Next is the codeset. */
107 syntax = xpg;
108 cp[0] = '\0';
109 *codeset = ++cp;
111 while (cp[0] != '\0' && cp[0] != '@')
112 ++cp;
114 mask |= XPG_CODESET;
116 if (*codeset != cp && (*codeset)[0] != '\0')
118 *normalized_codeset = _nl_normalize_codeset (*codeset,
119 cp - *codeset);
120 if (strcmp (*codeset, *normalized_codeset) == 0)
121 free ((char *) *normalized_codeset);
122 else
123 mask |= XPG_NORM_CODESET;
128 if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
130 /* Next is the modifier. */
131 syntax = cp[0] == '@' ? xpg : cen;
132 cp[0] = '\0';
133 *modifier = ++cp;
135 while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
136 && cp[0] != ',' && cp[0] != '_')
137 ++cp;
139 mask |= XPG_MODIFIER | CEN_AUDIENCE;
142 if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
144 syntax = cen;
146 if (cp[0] == '+')
148 /* Next is special application (CEN syntax). */
149 cp[0] = '\0';
150 *special = ++cp;
152 while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
153 ++cp;
155 mask |= CEN_SPECIAL;
158 if (cp[0] == ',')
160 /* Next is sponsor (CEN syntax). */
161 cp[0] = '\0';
162 *sponsor = ++cp;
164 while (cp[0] != '\0' && cp[0] != '_')
165 ++cp;
167 mask |= CEN_SPONSOR;
170 if (cp[0] == '_')
172 /* Next is revision (CEN syntax). */
173 cp[0] = '\0';
174 *revision = ++cp;
176 mask |= CEN_REVISION;
180 /* For CEN syntax values it might be important to have the
181 separator character in the file name, not for XPG syntax. */
182 if (syntax == xpg)
184 if (*territory != NULL && (*territory)[0] == '\0')
185 mask &= ~TERRITORY;
187 if (*codeset != NULL && (*codeset)[0] == '\0')
188 mask &= ~XPG_CODESET;
190 if (*modifier != NULL && (*modifier)[0] == '\0')
191 mask &= ~XPG_MODIFIER;
194 return mask;