OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [sys/] [linux/] [intl/] [finddomain.c] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
#include <newlib.h>
2
 
3
#ifdef _MB_CAPABLE
4
 
5
/* Handle list of needed message catalogs
6
   Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
7
   This file is part of the GNU C Library.
8
   Written by Ulrich Drepper <drepper@gnu.org>, 1995.
9
 
10
   The GNU C Library is free software; you can redistribute it and/or
11
   modify it under the terms of the GNU Lesser General Public
12
   License as published by the Free Software Foundation; either
13
   version 2.1 of the License, or (at your option) any later version.
14
 
15
   The GNU C Library is distributed in the hope that it will be useful,
16
   but WITHOUT ANY WARRANTY; without even the implied warranty of
17
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
   Lesser General Public License for more details.
19
 
20
   You should have received a copy of the GNU Lesser General Public
21
   License along with the GNU C Library; if not, write to the Free
22
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23
   02111-1307 USA.  */
24
 
25
#ifdef HAVE_CONFIG_H
26
# include <config.h>
27
#endif
28
 
29
#include <stdio.h>
30
#include <sys/types.h>
31
 
32
#if defined STDC_HEADERS || defined _LIBC
33
# include <stdlib.h>
34
#else
35
# ifdef HAVE_MALLOC_H
36
#  include <malloc.h>
37
# else
38
void free ();
39
# endif
40
#endif
41
 
42
#if defined HAVE_STRING_H || defined _LIBC
43
# include <string.h>
44
#else
45
# include <strings.h>
46
# ifndef memcpy
47
#  define memcpy(Dst, Src, Num) (bcopy (Src, Dst, Num), (Dst))
48
# endif
49
#endif
50
 
51
#if defined HAVE_UNISTD_H || defined _LIBC
52
# include <unistd.h>
53
#endif
54
 
55
#include "gettextP.h"
56
#ifdef _LIBC
57
# include <libintl.h>
58
#else
59
# include "libgnuintl.h"
60
#endif
61
 
62
/* @@ end of prolog @@ */
63
/* List of already loaded domains.  */
64
static struct loaded_l10nfile *_nl_loaded_domains;
65
 
66
 
67
/* Return a data structure describing the message catalog described by
68
   the DOMAINNAME and CATEGORY parameters with respect to the currently
69
   established bindings.  */
70
struct loaded_l10nfile *
71
internal_function
72
_nl_find_domain (dirname, locale, domainname, domainbinding)
73
     const char *dirname;
74
     char *locale;
75
     const char *domainname;
76
     struct binding *domainbinding;
77
{
78
  struct loaded_l10nfile *retval;
79
  const char *language;
80
  const char *modifier;
81
  const char *territory;
82
  const char *codeset;
83
  const char *normalized_codeset;
84
  const char *special;
85
  const char *sponsor;
86
  const char *revision;
87
  const char *alias_value;
88
  int mask;
89
 
90
  /* LOCALE can consist of up to four recognized parts for the XPG syntax:
91
 
92
                language[_territory[.codeset]][@modifier]
93
 
94
     and six parts for the CEN syntax:
95
 
96
        language[_territory][+audience][+special][,[sponsor][_revision]]
97
 
98
     Beside the first part all of them are allowed to be missing.  If
99
     the full specified locale is not found, the less specific one are
100
     looked for.  The various parts will be stripped off according to
101
     the following order:
102
                (1) revision
103
                (2) sponsor
104
                (3) special
105
                (4) codeset
106
                (5) normalized codeset
107
                (6) territory
108
                (7) audience/modifier
109
   */
110
 
111
  /* If we have already tested for this locale entry there has to
112
     be one data set in the list of loaded domains.  */
113
  retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
114
                               strlen (dirname) + 1, 0, locale, NULL, NULL,
115
                               NULL, NULL, NULL, NULL, NULL, domainname, 0);
116
  if (retval != NULL)
117
    {
118
      /* We know something about this locale.  */
119
      int cnt;
120
 
121
      if (retval->decided == 0)
122
        _nl_load_domain (retval, domainbinding);
123
 
124
      if (retval->data != NULL)
125
        return retval;
126
 
127
      for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
128
        {
129
          if (retval->successor[cnt]->decided == 0)
130
            _nl_load_domain (retval->successor[cnt], domainbinding);
131
 
132
          if (retval->successor[cnt]->data != NULL)
133
            break;
134
        }
135
      return cnt >= 0 ? retval : NULL;
136
      /* NOTREACHED */
137
    }
138
 
139
  /* See whether the locale value is an alias.  If yes its value
140
     *overwrites* the alias name.  No test for the original value is
141
     done.  */
142
  alias_value = _nl_expand_alias (locale);
143
  if (alias_value != NULL)
144
    {
145
#if defined _LIBC || defined HAVE_STRDUP
146
      locale = strdup (alias_value);
147
      if (locale == NULL)
148
        return NULL;
149
#else
150
      size_t len = strlen (alias_value) + 1;
151
      locale = (char *) malloc (len);
152
      if (locale == NULL)
153
        return NULL;
154
 
155
      memcpy (locale, alias_value, len);
156
#endif
157
    }
158
 
159
  /* Now we determine the single parts of the locale name.  First
160
     look for the language.  Termination symbols are `_' and `@' if
161
     we use XPG4 style, and `_', `+', and `,' if we use CEN syntax.  */
162
  mask = _nl_explode_name (locale, &language, &modifier, &territory,
163
                           &codeset, &normalized_codeset, &special,
164
                           &sponsor, &revision);
165
 
166
  /* Create all possible locale entries which might be interested in
167
     generalization.  */
168
  retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
169
                               strlen (dirname) + 1, mask, language, territory,
170
                               codeset, normalized_codeset, modifier, special,
171
                               sponsor, revision, domainname, 1);
172
  if (retval == NULL)
173
    /* This means we are out of core.  */
174
    return NULL;
175
 
176
  if (retval->decided == 0)
177
    _nl_load_domain (retval, domainbinding);
178
  if (retval->data == NULL)
179
    {
180
      int cnt;
181
      for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
182
        {
183
          if (retval->successor[cnt]->decided == 0)
184
            _nl_load_domain (retval->successor[cnt], domainbinding);
185
          if (retval->successor[cnt]->data != NULL)
186
            break;
187
        }
188
    }
189
 
190
  /* The room for an alias was dynamically allocated.  Free it now.  */
191
  if (alias_value != NULL)
192
    free (locale);
193
 
194
  /* The space for normalized_codeset is dynamically allocated.  Free it.  */
195
  if (mask & XPG_NORM_CODESET)
196
    free ((void *) normalized_codeset);
197
 
198
  return retval;
199
}
200
 
201
 
202
#ifdef _LIBC
203
static void __attribute__ ((unused))
204
free_mem (void)
205
{
206
  struct loaded_l10nfile *runp = _nl_loaded_domains;
207
 
208
  while (runp != NULL)
209
    {
210
      struct loaded_l10nfile *here = runp;
211
      if (runp->data != NULL)
212
        _nl_unload_domain ((struct loaded_domain *) runp->data);
213
      runp = runp->next;
214
      free ((char *) here->filename);
215
      free (here);
216
    }
217
}
218
 
219
text_set_element (__libc_subfreeres, free_mem);
220
#endif
221
 
222
#endif /* _MB_CAPABLE */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.