source: trunk/src/binutils/intl/explodename.c@ 2060

Last change on this file since 2060 was 610, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r609,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.5 KB
Line 
1/* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
2 Contributed by Ulrich Drepper <[email protected]>, 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 {
111 *normalized_codeset = _nl_normalize_codeset (*codeset,
112 cp - *codeset);
113 if (strcmp (*codeset, *normalized_codeset) == 0)
114 free ((char *) *normalized_codeset);
115 else
116 mask |= XPG_NORM_CODESET;
117 }
118 }
119 }
120
121 if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
122 {
123 /* Next is the modifier. */
124 syntax = cp[0] == '@' ? xpg : cen;
125 cp[0] = '\0';
126 *modifier = ++cp;
127
128 while (syntax == cen && cp[0] != '\0' && cp[0] != '+'