annotate intl/explodename.c @ 2037:4fd820ec8298 trunk

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