Update.
[glibc.git] / intl / explodename.c
blobbfaa5aba53f1af2ddb92f0581e748989c613f8c9
1 /* Copyright (C) 1995-1998, 2000, 2001, 2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/types.h>
28 #include "loadinfo.h"
30 /* On some strange systems still no definition of NULL is found. Sigh! */
31 #ifndef NULL
32 # if defined __STDC__ && __STDC__
33 # define NULL ((void *) 0)
34 # else
35 # define NULL 0
36 # endif
37 #endif
39 /* @@ end of prolog @@ */
41 char *
42 _nl_find_language (name)
43 const char *name;
45 while (name[0] != '\0' && name[0] != '_' && name[0] != '@' && name[0] != '.')
46 ++name;
48 return (char *) name;
52 int
53 _nl_explode_name (name, language, modifier, territory, codeset,
54 normalized_codeset)
55 char *name;
56 const char **language;
57 const char **modifier;
58 const char **territory;
59 const char **codeset;
60 const char **normalized_codeset;
62 char *cp;
63 int mask;
65 *modifier = NULL;
66 *territory = NULL;
67 *codeset = NULL;
68 *normalized_codeset = NULL;
70 /* Now we determine the single parts of the locale name. First
71 look for the language. Termination symbols are `_', '.', and `@'. */
72 mask = 0;
73 *language = cp = name;
74 cp = _nl_find_language (*language);
76 if (*language == cp)
77 /* This does not make sense: language has to be specified. Use
78 this entry as it is without exploding. Perhaps it is an alias. */
79 cp = strchr (*language, '\0');
80 else if (cp[0] != '@')
82 if (cp[0] == '_')
84 /* Next is the territory. */
85 cp[0] = '\0';
86 *territory = ++cp;
88 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@')
89 ++cp;
91 mask |= XPG_TERRITORY;
94 if (cp[0] == '.')
96 /* Next is the codeset. */
97 cp[0] = '\0';
98 *codeset = ++cp;
100 while (cp[0] != '\0' && cp[0] != '@')
101 ++cp;
103 mask |= XPG_CODESET;
105 if (*codeset != cp && (*codeset)[0] != '\0')
107 *normalized_codeset = _nl_normalize_codeset (*codeset,
108 cp - *codeset);
109 if (strcmp (*codeset, *normalized_codeset) == 0)
110 free ((char *) *normalized_codeset);
111 else
112 mask |= XPG_NORM_CODESET;
117 if (cp[0] == '@')
119 /* Next is the modifier. */
120 cp[0] = '\0';
121 *modifier = ++cp;
123 if (cp[0] != '\0')
124 mask |= XPG_MODIFIER;
127 if (*territory != NULL && (*territory)[0] == '\0')
128 mask &= ~XPG_TERRITORY;
130 if (*codeset != NULL && (*codeset)[0] == '\0')
131 mask &= ~XPG_CODESET;
133 return mask;