No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / texinfo / intl / explodename.c
blob5bed4f9a965eeb4e2a962806c9e4f9793e074b10
1 /* $NetBSD$ */
3 /* Copyright (C) 1995-1998, 2000-2001, 2003 Free Software Foundation, Inc.
4 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published
8 by the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 USA. */
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
25 #include <stdlib.h>
26 #include <string.h>
27 #include <sys/types.h>
29 #include "loadinfo.h"
31 /* On some strange systems still no definition of NULL is found. Sigh! */
32 #ifndef NULL
33 # if defined __STDC__ && __STDC__
34 # define NULL ((void *) 0)
35 # else
36 # define NULL 0
37 # endif
38 #endif
40 /* @@ end of prolog @@ */
42 char *
43 _nl_find_language (const char *name)
45 while (name[0] != '\0' && name[0] != '_' && name[0] != '@'
46 && name[0] != '+' && name[0] != ',')
47 ++name;
49 return (char *) name;
53 int
54 _nl_explode_name (char *name,
55 const char **language, const char **modifier,
56 const char **territory, const char **codeset,
57 const char **normalized_codeset, const char **special,
58 const char **sponsor, const char **revision)
60 enum { undecided, xpg, cen } syntax;
61 char *cp;
62 int mask;
64 *modifier = NULL;
65 *territory = NULL;
66 *codeset = NULL;
67 *normalized_codeset = NULL;
68 *special = NULL;
69 *sponsor = NULL;
70 *revision = NULL;
72 /* Now we determine the single parts of the locale name. First
73 look for the language. Termination symbols are `_' and `@' if
74 we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
75 mask = 0;
76 syntax = undecided;
77 *language = cp = name;
78 cp = _nl_find_language (*language);
80 if (*language == cp)
81 /* This does not make sense: language has to be specified. Use
82 this entry as it is without exploding. Perhaps it is an alias. */
83 cp = strchr (*language, '\0');
84 else if (cp[0] == '_')
86 /* Next is the territory. */
87 cp[0] = '\0';
88 *territory = ++cp;
90 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
91 && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
92 ++cp;
94 mask |= TERRITORY;
96 if (cp[0] == '.')
98 /* Next is the codeset. */
99 syntax = xpg;
100 cp[0] = '\0';
101 *codeset = ++cp;
103 while (cp[0] != '\0' && cp[0] != '@')
104 ++cp;
106 mask |= XPG_CODESET;
108 if (*codeset != cp && (*codeset)[0] != '\0')
110 *normalized_codeset = _nl_normalize_codeset (*codeset,
111 cp - *codeset);
112 if (strcmp (*codeset, *normalized_codeset) == 0)
113 free ((char *) *normalized_codeset);
114 else
115 mask |= XPG_NORM_CODESET;
120 if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
122 /* Next is the modifier. */
123 syntax = cp[0] == '@' ? xpg : cen;
124 cp[0] = '\0';
125 *modifier = ++cp;
127 while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
128 && cp[0] != ',' && cp[0] != '_')
129 ++cp;
131 mask |= XPG_MODIFIER | CEN_AUDIENCE;
134 if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
136 syntax = cen;
138 if (cp[0] == '+')
140 /* Next is special application (CEN syntax). */
141 cp[0] = '\0';
142 *special = ++cp;
144 while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
145 ++cp;
147 mask |= CEN_SPECIAL;
150 if (cp[0] == ',')
152 /* Next is sponsor (CEN syntax). */
153 cp[0] = '\0';
154 *sponsor = ++cp;
156 while (cp[0] != '\0' && cp[0] != '_')
157 ++cp;
159 mask |= CEN_SPONSOR;
162 if (cp[0] == '_')
164 /* Next is revision (CEN syntax). */
165 cp[0] = '\0';
166 *revision = ++cp;
168 mask |= CEN_REVISION;
172 /* For CEN syntax values it might be important to have the
173 separator character in the file name, not for XPG syntax. */
174 if (syntax == xpg)
176 if (*territory != NULL && (*territory)[0] == '\0')
177 mask &= ~TERRITORY;
179 if (*codeset != NULL && (*codeset)[0] == '\0')
180 mask &= ~XPG_CODESET;
182 if (*modifier != NULL && (*modifier)[0] == '\0')
183 mask &= ~XPG_MODIFIER;
186 return mask;