pcsxr-1.9.92
[pcsx_rearmed.git] / win32 / intl / explodename.c
CommitLineData
ef79bbde
P
1/* Copyright (C) 1995, 1996, 1997, 1998 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. */
17
18#include "intlconfig.h"
19
20#if defined STDC_HEADERS || defined _LIBC
21# include <stdlib.h>
22#endif
23
24#if defined HAVE_STRING_H || defined _LIBC
25# include <string.h>
26#else
27# include <strings.h>
28#endif
29#include <sys/types.h>
30
31#include "loadinfo.h"
32
33/* On some strange systems still no definition of NULL is found. Sigh! */
34#ifndef NULL
35# if defined __STDC__ && __STDC__
36# define NULL ((void *) 0)
37# else
38# define NULL 0
39# endif
40#endif
41
42/* @@ end of prolog @@ */
43
44int
45_nl_explode_name (name, language, modifier, territory, codeset,
46 normalized_codeset, special, sponsor, revision)
47 char *name;
48 const char **language;
49 const char **modifier;
50 const char **territory;
51 const char **codeset;
52 const char **normalized_codeset;
53 const char **special;
54 const char **sponsor;
55 const char **revision;
56{
57 enum { undecided, xpg, cen } syntax;
58 char *cp;
59 int mask;
60
61 *modifier = NULL;
62 *territory = NULL;
63 *codeset = NULL;
64 *normalized_codeset = NULL;
65 *special = NULL;
66 *sponsor = NULL;
67 *revision = NULL;
68
69 /* Now we determine the single parts of the locale name. First
70 look for the language. Termination symbols are `_' and `@' if
71 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
72 mask = 0;
73 syntax = undecided;
74 *language = cp = name;
75 while (cp[0] != '\0' && cp[0] != '_' && cp[0] != '@'
76 && cp[0] != '+' && cp[0] != ',')
77 ++cp;
78
79 if (*language == cp)
80 /* This does not make sense: language has to be specified. Use
81 this entry as it is without exploding. Perhaps it is an alias. */
82 cp = strchr (*language, '\0');
83 else if (cp[0] == '_')
84 {
85 /* Next is the territory. */
86 cp[0] = '\0';
87 *territory = ++cp;
88
89 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
90 && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
91 ++cp;
92
93 mask |= TERRITORY;
94
95 if (cp[0] == '.')
96 {
97 /* Next is the codeset. */
98 syntax = xpg;
99 cp[0] = '\0';
100 *codeset = ++cp;
101
102 while (cp[0] != '\0' && cp[0] != '@')
103 ++cp;
104
105 mask |= XPG_CODESET;
106
107 if (*codeset != cp && (*codeset)[0] != '\0')
108 {
109 *normalized_codeset = _nl_normalize_codeset (*codeset,
110 cp - *codeset);
111 if (strcmp (*codeset, *normalized_codeset) == 0)
112 free ((char *) *normalized_codeset);
113 else
114 mask |= XPG_NORM_CODESET;
115 }
116 }
117 }
118
119 if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
120 {
121 /* Next is the modifier. */
122 syntax = cp[0] == '@' ? xpg : cen;
123 cp[0] = '\0';
124 *modifier = ++cp;
125
126 while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
127 && cp[0] != ',' && cp[0] != '_')
128 ++cp;
129
130 mask |= XPG_MODIFIER | CEN_AUDIENCE;
131 }
132
133 if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
134 {
135 syntax = cen;
136
137 if (cp[0] == '+')
138 {
139 /* Next is special application (CEN syntax). */
140 cp[0] = '\0';
141 *special = ++cp;
142
143 while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
144 ++cp;
145
146 mask |= CEN_SPECIAL;
147 }
148
149 if (cp[0] == ',')
150 {
151 /* Next is sponsor (CEN syntax). */
152 cp[0] = '\0';
153 *sponsor = ++cp;
154
155 while (cp[0] != '\0' && cp[0] != '_')
156 ++cp;
157
158 mask |= CEN_SPONSOR;
159 }
160
161 if (cp[0] == '_')
162 {
163 /* Next is revision (CEN syntax). */
164 cp[0] = '\0';
165 *revision = ++cp;
166
167 mask |= CEN_REVISION;
168 }
169 }
170
171 /* For CEN syntax values it might be important to have the
172 separator character in the file name, not for XPG syntax. */
173 if (syntax == xpg)
174 {
175 if (*territory != NULL && (*territory)[0] == '\0')
176 mask &= ~TERRITORY;
177
178 if (*codeset != NULL && (*codeset)[0] == '\0')
179 mask &= ~XPG_CODESET;
180
181 if (*modifier != NULL && (*modifier)[0] == '\0')
182 mask &= ~XPG_MODIFIER;
183 }
184
185 return mask;
186}