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