Install gettext-0.18.1.1.tar.gz
[msysgit.git] / mingw / share / gettext / intl / explodename.c
blobeb5dd755c3c369866216f53e260cea5fd1349394
1 /* Copyright (C) 1995-1998, 2000-2001, 2003, 2005, 2007 Free Software Foundation, Inc.
2 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published
6 by the Free Software Foundation; either version 2, or (at your option)
7 any later version.
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 GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 USA. */
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
23 #include <stdlib.h>
24 #include <string.h>
25 #include <sys/types.h>
27 #include "loadinfo.h"
29 /* On some strange systems still no definition of NULL is found. Sigh! */
30 #ifndef NULL
31 # if defined __STDC__ && __STDC__
32 # define NULL ((void *) 0)
33 # else
34 # define NULL 0
35 # endif
36 #endif
38 /* @@ end of prolog @@ */
40 /* Split a locale name NAME into a leading language part and all the
41 rest. Return a pointer to the first character after the language,
42 i.e. to the first byte of the rest. */
43 static char *_nl_find_language (const char *name);
45 static char *
46 _nl_find_language (const char *name)
48 while (name[0] != '\0' && name[0] != '_' && name[0] != '@' && name[0] != '.')
49 ++name;
51 return (char *) name;
55 int
56 _nl_explode_name (char *name,
57 const char **language, const char **modifier,
58 const char **territory, const char **codeset,
59 const char **normalized_codeset)
61 char *cp;
62 int mask;
64 *modifier = NULL;
65 *territory = NULL;
66 *codeset = NULL;
67 *normalized_codeset = NULL;
69 /* Now we determine the single parts of the locale name. First
70 look for the language. Termination symbols are `_', '.', and `@'. */
71 mask = 0;
72 *language = cp = name;
73 cp = _nl_find_language (*language);
75 if (*language == cp)
76 /* This does not make sense: language has to be specified. Use
77 this entry as it is without exploding. Perhaps it is an alias. */
78 cp = strchr (*language, '\0');
79 else
81 if (cp[0] == '_')
83 /* Next is the territory. */
84 cp[0] = '\0';
85 *territory = ++cp;
87 while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@')
88 ++cp;
90 mask |= XPG_TERRITORY;
93 if (cp[0] == '.')
95 /* Next is the codeset. */
96 cp[0] = '\0';
97 *codeset = ++cp;
99 while (cp[0] != '\0' && cp[0] != '@')
100 ++cp;
102 mask |= XPG_CODESET;
104 if (*codeset != cp && (*codeset)[0] != '\0')
106 *normalized_codeset = _nl_normalize_codeset (*codeset,
107 cp - *codeset);
108 if (*normalized_codeset == NULL)
109 return -1;
110 else if (strcmp (*codeset, *normalized_codeset) == 0)
111 free ((char *) *normalized_codeset);
112 else
113 mask |= XPG_NORM_CODESET;
118 if (cp[0] == '@')
120 /* Next is the modifier. */
121 cp[0] = '\0';
122 *modifier = ++cp;
124 if (cp[0] != '\0')
125 mask |= XPG_MODIFIER;
128 if (*territory != NULL && (*territory)[0] == '\0')
129 mask &= ~XPG_TERRITORY;
131 if (*codeset != NULL && (*codeset)[0] == '\0')
132 mask &= ~XPG_CODESET;
134 return mask;