~ubuntu-branches/ubuntu/saucy/m17n-lib/saucy

« back to all changes in this revision

Viewing changes to intl/explodename.c

  • Committer: Bazaar Package Importer
  • Author(s): Harshula Jayasuriya
  • Date: 2010-11-23 01:39:29 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20101123013929-rs3kpqgu4kr3qx32
Tags: 1.6.2-1
* New upstream release 1.6.2.
* Update Standards-Version to Debian Policy 3.9.1. (No changes)
* debian/control: Depends: m17n-db and m17n-contrib. (Closes: #599643)
* PATCH: (make_locale): Don't call setlocale.  Just parse the arg NAME.
         (Closes: #601858)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 1995-1998, 2000-2001, 2003 Free Software Foundation, Inc.
 
1
/* Copyright (C) 1995-1998, 2000-2001, 2003, 2005, 2007 Free Software Foundation, Inc.
2
2
   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
3
3
 
4
4
   This program is free software; you can redistribute it and/or modify it
13
13
 
14
14
   You should have received a copy of the GNU Library General Public
15
15
   License along with this program; if not, write to the Free Software
16
 
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
16
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17
17
   USA.  */
18
18
 
19
19
#ifdef HAVE_CONFIG_H
37
37
 
38
38
/* @@ end of prolog @@ */
39
39
 
40
 
char *
 
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);
 
44
 
 
45
static char *
41
46
_nl_find_language (const char *name)
42
47
{
43
 
  while (name[0] != '\0' && name[0] != '_' && name[0] != '@'
44
 
         && name[0] != '+' && name[0] != ',')
 
48
  while (name[0] != '\0' && name[0] != '_' && name[0] != '@' && name[0] != '.')
45
49
    ++name;
46
50
 
47
51
  return (char *) name;
52
56
_nl_explode_name (char *name,
53
57
                  const char **language, const char **modifier,
54
58
                  const char **territory, const char **codeset,
55
 
                  const char **normalized_codeset, const char **special,
56
 
                  const char **sponsor, const char **revision)
 
59
                  const char **normalized_codeset)
57
60
{
58
 
  enum { undecided, xpg, cen } syntax;
59
61
  char *cp;
60
62
  int mask;
61
63
 
63
65
  *territory = NULL;
64
66
  *codeset = NULL;
65
67
  *normalized_codeset = NULL;
66
 
  *special = NULL;
67
 
  *sponsor = NULL;
68
 
  *revision = NULL;
69
68
 
70
69
  /* Now we determine the single parts of the locale name.  First
71
 
     look for the language.  Termination symbols are `_' and `@' if
72
 
     we use XPG4 style, and `_', `+', and `,' if we use CEN syntax.  */
 
70
     look for the language.  Termination symbols are `_', '.', and `@'.  */
73
71
  mask = 0;
74
 
  syntax = undecided;
75
72
  *language = cp = name;
76
73
  cp = _nl_find_language (*language);
77
74
 
79
76
    /* This does not make sense: language has to be specified.  Use
80
77
       this entry as it is without exploding.  Perhaps it is an alias.  */
81
78
    cp = strchr (*language, '\0');
82
 
  else if (cp[0] == '_')
 
79
  else
83
80
    {
84
 
      /* Next is the territory.  */
85
 
      cp[0] = '\0';
86
 
      *territory = ++cp;
87
 
 
88
 
      while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
89
 
             && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
90
 
        ++cp;
91
 
 
92
 
      mask |= TERRITORY;
 
81
      if (cp[0] == '_')
 
82
        {
 
83
          /* Next is the territory.  */
 
84
          cp[0] = '\0';
 
85
          *territory = ++cp;
 
86
 
 
87
          while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@')
 
88
            ++cp;
 
89
 
 
90
          mask |= XPG_TERRITORY;
 
91
        }
93
92
 
94
93
      if (cp[0] == '.')
95
94
        {
96
95
          /* Next is the codeset.  */
97
 
          syntax = xpg;
98
96
          cp[0] = '\0';
99
97
          *codeset = ++cp;
100
98
 
107
105
            {
108
106
              *normalized_codeset = _nl_normalize_codeset (*codeset,
109
107
                                                           cp - *codeset);
110
 
              if (strcmp (*codeset, *normalized_codeset) == 0)
 
108
              if (*normalized_codeset == NULL)
 
109
                return -1;
 
110
              else if (strcmp (*codeset, *normalized_codeset) == 0)
111
111
                free ((char *) *normalized_codeset);
112
112
              else
113
113
                mask |= XPG_NORM_CODESET;
115
115
        }
116
116
    }
117
117
 
118
 
  if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
 
118
  if (cp[0] == '@')
119
119
    {
120
120
      /* Next is the modifier.  */
121
 
      syntax = cp[0] == '@' ? xpg : cen;
122
121
      cp[0] = '\0';
123
122
      *modifier = ++cp;
124
123
 
125
 
      while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
126
 
             && cp[0] != ',' && cp[0] != '_')
127
 
        ++cp;
128
 
 
129
 
      mask |= XPG_MODIFIER | CEN_AUDIENCE;
130
 
    }
131
 
 
132
 
  if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
133
 
    {
134
 
      syntax = cen;
135
 
 
136
 
      if (cp[0] == '+')
137
 
        {
138
 
          /* Next is special application (CEN syntax).  */
139
 
          cp[0] = '\0';
140
 
          *special = ++cp;
141
 
 
142
 
          while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
143
 
            ++cp;
144
 
 
145
 
          mask |= CEN_SPECIAL;
146
 
        }
147
 
 
148
 
      if (cp[0] == ',')
149
 
        {
150
 
          /* Next is sponsor (CEN syntax).  */
151
 
          cp[0] = '\0';
152
 
          *sponsor = ++cp;
153
 
 
154
 
          while (cp[0] != '\0' && cp[0] != '_')
155
 
            ++cp;
156
 
 
157
 
          mask |= CEN_SPONSOR;
158
 
        }
159
 
 
160
 
      if (cp[0] == '_')
161
 
        {
162
 
          /* Next is revision (CEN syntax).  */
163
 
          cp[0] = '\0';
164
 
          *revision = ++cp;
165
 
 
166
 
          mask |= CEN_REVISION;
167
 
        }
168
 
    }
169
 
 
170
 
  /* For CEN syntax values it might be important to have the
171
 
     separator character in the file name, not for XPG syntax.  */
172
 
  if (syntax == xpg)
173
 
    {
174
 
      if (*territory != NULL && (*territory)[0] == '\0')
175
 
        mask &= ~TERRITORY;
176
 
 
177
 
      if (*codeset != NULL && (*codeset)[0] == '\0')
178
 
        mask &= ~XPG_CODESET;
179
 
 
180
 
      if (*modifier != NULL && (*modifier)[0] == '\0')
181
 
        mask &= ~XPG_MODIFIER;
182
 
    }
 
124
      if (cp[0] != '\0')
 
125
        mask |= XPG_MODIFIER;
 
126
    }
 
127
 
 
128
  if (*territory != NULL && (*territory)[0] == '\0')
 
129
    mask &= ~XPG_TERRITORY;
 
130
 
 
131
  if (*codeset != NULL && (*codeset)[0] == '\0')
 
132
    mask &= ~XPG_CODESET;
183
133
 
184
134
  return mask;
185
135
}