]> git.saurik.com Git - bison.git/blob - intl/explodename.c
Add.
[bison.git] / intl / explodename.c
1 /* Copyright (C) 1995-1998, 2000, 2001 Free Software Foundation, Inc.
2 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program 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
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/types.h>
25
26 #include "loadinfo.h"
27
28 /* On some strange systems still no definition of NULL is found. Sigh! */
29 #ifndef NULL
30 # if defined __STDC__ && __STDC__
31 # define NULL ((void *) 0)
32 # else
33 # define NULL 0
34 # endif
35 #endif
36
37 /* @@ end of prolog @@ */
38
39 char *
40 _nl_find_language (name)
41 const char *name;
42 {
43 while (name[0] != '\0' && name[0] != '_' && name[0] != '@'
44 && name[0] != '+' && name[0] != ',')
45 ++name;
46
47 return (char *) name;
48 }
49
50
51 int
52 _nl_explode_name (name, language, modifier, territory, codeset,
53 normalized_codeset, special, sponsor, revision)
54 char *name;
55 const char **language;
56 const char **modifier;
57 const char **territory;
58 const char **codeset;
59 const char **normalized_codeset;
60 const char **special;
61 const char **sponsor;
62 const char **revision;
63 {
64 enum { undecided, xpg, cen } syntax;
65 char *cp;
66 int mask;
67
68 *modifier = NULL;
69 *territory = NULL;
70 *codeset = NULL;
71 *normalized_codeset = NULL;
72 *special = NULL;
73 *sponsor = NULL;
74 *revision = NULL;
75
76 /* Now we determine the single parts of the locale name. First
77 look for the language. Termination symbols are `_' and `@' if
78 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
79 mask = 0;
80 syntax = undecided;
81 *language = cp = name;
82 cp = _nl_find_language (*language);
83
84 if (*language == cp)
85 /* This does not make sense: language has to be specified. Use
86 this entry as it is without exploding. Perhaps it is an alias. */
87 cp = strchr (*language, '\0');
88 else if (cp[0] == '_')
89 {
90 /* Next is the territory. */
91 cp[0] = '\0';
92 *territory = ++cp;
93
94 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
95 && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
96 ++cp;
97
98 mask |= TERRITORY;
99
100 if (cp[0] == '.')
101 {
102 /* Next is the codeset. */
103 syntax = xpg;
104 cp[0] = '\0';
105 *codeset = ++cp;
106
107 while (cp[0] != '\0' && cp[0] != '@')
108 ++cp;
109
110 mask |= XPG_CODESET;
111
112 if (*codeset != cp && (*codeset)[0] != '\0')
113 {
114 *normalized_codeset = _nl_normalize_codeset (*codeset,
115 cp - *codeset);
116 if (strcmp (*codeset, *normalized_codeset) == 0)
117 free ((char *) *normalized_codeset);
118 else
119 mask |= XPG_NORM_CODESET;
120 }
121 }
122 }
123
124 if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
125 {
126 /* Next is the modifier. */
127 syntax = cp[0] == '@' ? xpg : cen;
128 cp[0] = '\0';
129 *modifier = ++cp;
130
131 while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
132 && cp[0] != ',' && cp[0] != '_')
133 ++cp;
134
135 mask |= XPG_MODIFIER | CEN_AUDIENCE;
136 }
137
138 if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
139 {
140 syntax = cen;
141
142 if (cp[0] == '+')
143 {
144 /* Next is special application (CEN syntax). */
145 cp[0] = '\0';
146 *special = ++cp;
147
148 while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
149 ++cp;
150
151 mask |= CEN_SPECIAL;
152 }
153
154 if (cp[0] == ',')
155 {
156 /* Next is sponsor (CEN syntax). */
157 cp[0] = '\0';
158 *sponsor = ++cp;
159
160 while (cp[0] != '\0' && cp[0] != '_')
161 ++cp;
162
163 mask |= CEN_SPONSOR;
164 }
165
166 if (cp[0] == '_')
167 {
168 /* Next is revision (CEN syntax). */
169 cp[0] = '\0';
170 *revision = ++cp;
171
172 mask |= CEN_REVISION;
173 }
174 }
175
176 /* For CEN syntax values it might be important to have the
177 separator character in the file name, not for XPG syntax. */
178 if (syntax == xpg)
179 {
180 if (*territory != NULL && (*territory)[0] == '\0')
181 mask &= ~TERRITORY;
182
183 if (*codeset != NULL && (*codeset)[0] == '\0')
184 mask &= ~XPG_CODESET;
185
186 if (*modifier != NULL && (*modifier)[0] == '\0')
187 mask &= ~XPG_MODIFIER;
188 }
189
190 return mask;
191 }