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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [sys/] [linux/] [intl/] [l10nflist.c] - Blame information for rev 207

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
#include <newlib.h>
2
 
3
#ifdef _MB_CAPABLE
4
 
5
/* Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
6
   This file is part of the GNU C Library.
7
   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
8
 
9
   The GNU C Library is free software; you can redistribute it and/or
10
   modify it under the terms of the GNU Lesser General Public
11
   License as published by the Free Software Foundation; either
12
   version 2.1 of the License, or (at your option) any later version.
13
 
14
   The GNU C Library is distributed in the hope that it will be useful,
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
   Lesser General Public License for more details.
18
 
19
   You should have received a copy of the GNU Lesser General Public
20
   License along with the GNU C Library; if not, write to the Free
21
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22
   02111-1307 USA.  */
23
 
24
/* Tell glibc's <string.h> to provide a prototype for stpcpy().
25
   This must come before <config.h> because <config.h> may include
26
   <features.h>, and once <features.h> has been included, it's too late.  */
27
#ifndef _GNU_SOURCE
28
# define _GNU_SOURCE    1
29
#endif
30
 
31
#ifdef HAVE_CONFIG_H
32
# include <config.h>
33
#endif
34
 
35
 
36
#if defined HAVE_STRING_H || defined _LIBC
37
# include <string.h>
38
#else
39
# include <strings.h>
40
# ifndef memcpy
41
#  define memcpy(Dst, Src, Num) (bcopy (Src, Dst, Num), (Dst))
42
# endif
43
#endif
44
#if !HAVE_STRCHR && !defined _LIBC
45
# ifndef strchr
46
#  define strchr index
47
# endif
48
#endif
49
 
50
#if defined _LIBC || defined HAVE_ARGZ_H
51
# include <argz.h>
52
#endif
53
#include <ctype.h>
54
#include <sys/types.h>
55
 
56
#if defined STDC_HEADERS || defined _LIBC
57
# include <stdlib.h>
58
#endif
59
 
60
#include "loadinfo.h"
61
 
62
/* On some strange systems still no definition of NULL is found.  Sigh!  */
63
#ifndef NULL
64
# if defined __STDC__ && __STDC__
65
#  define NULL ((void *) 0)
66
# else
67
#  define NULL 0
68
# endif
69
#endif
70
 
71
/* @@ end of prolog @@ */
72
 
73
#define HAVE_STPCPY 1
74
 
75
#ifdef _GLIBC
76
/* Rename the non ANSI C functions.  This is required by the standard
77
   because some ANSI C functions will require linking with this object
78
   file and the name space must not be polluted.  */
79
# ifndef stpcpy
80
#  define stpcpy(dest, src) __stpcpy(dest, src)
81
# endif
82
#else
83
# ifndef HAVE_STPCPY
84
static char *stpcpy PARAMS ((char *dest, const char *src));
85
# endif
86
#endif
87
 
88
/* Define function which are usually not available.  */
89
 
90
#if !defined _LIBC && !defined HAVE___ARGZ_COUNT
91
/* Returns the number of strings in ARGZ.  */
92
static size_t argz_count__ PARAMS ((const char *argz, size_t len));
93
 
94
static size_t
95
argz_count__ (argz, len)
96
     const char *argz;
97
     size_t len;
98
{
99
  size_t count = 0;
100
  while (len > 0)
101
    {
102
      size_t part_len = strlen (argz);
103
      argz += part_len + 1;
104
      len -= part_len + 1;
105
      count++;
106
    }
107
  return count;
108
}
109
# undef __argz_count
110
# define __argz_count(argz, len) argz_count__ (argz, len)
111
#endif  /* !_LIBC && !HAVE___ARGZ_COUNT */
112
 
113
#if !defined _LIBC && !defined HAVE___ARGZ_STRINGIFY
114
/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
115
   except the last into the character SEP.  */
116
static void argz_stringify__ PARAMS ((char *argz, size_t len, int sep));
117
 
118
static void
119
argz_stringify__ (argz, len, sep)
120
     char *argz;
121
     size_t len;
122
     int sep;
123
{
124
  while (len > 0)
125
    {
126
      size_t part_len = strlen (argz);
127
      argz += part_len;
128
      len -= part_len + 1;
129
      if (len > 0)
130
        *argz++ = sep;
131
    }
132
}
133
# undef __argz_stringify
134
# define __argz_stringify(argz, len, sep) argz_stringify__ (argz, len, sep)
135
#endif  /* !_LIBC && !HAVE___ARGZ_STRINGIFY */
136
 
137
#if !defined _LIBC && !defined HAVE___ARGZ_NEXT
138
static char *argz_next__ PARAMS ((char *argz, size_t argz_len,
139
                                  const char *entry));
140
 
141
static char *
142
argz_next__ (argz, argz_len, entry)
143
     char *argz;
144
     size_t argz_len;
145
     const char *entry;
146
{
147
  if (entry)
148
    {
149
      if (entry < argz + argz_len)
150
        entry = strchr (entry, '\0') + 1;
151
 
152
      return entry >= argz + argz_len ? NULL : (char *) entry;
153
    }
154
  else
155
    if (argz_len > 0)
156
      return argz;
157
    else
158
      return 0;
159
}
160
# undef __argz_next
161
# define __argz_next(argz, len, entry) argz_next__ (argz, len, entry)
162
#endif  /* !_LIBC && !HAVE___ARGZ_NEXT */
163
 
164
 
165
/* Return number of bits set in X.  */
166
static int pop PARAMS ((int x));
167
 
168
static inline int
169
pop (x)
170
     int x;
171
{
172
  /* We assume that no more than 16 bits are used.  */
173
  x = ((x & ~0x5555) >> 1) + (x & 0x5555);
174
  x = ((x & ~0x3333) >> 2) + (x & 0x3333);
175
  x = ((x >> 4) + x) & 0x0f0f;
176
  x = ((x >> 8) + x) & 0xff;
177
 
178
  return x;
179
}
180
 
181
 
182
struct loaded_l10nfile *
183
_nl_make_l10nflist (l10nfile_list, dirlist, dirlist_len, mask, language,
184
                    territory, codeset, normalized_codeset, modifier, special,
185
                    sponsor, revision, filename, do_allocate)
186
     struct loaded_l10nfile **l10nfile_list;
187
     const char *dirlist;
188
     size_t dirlist_len;
189
     int mask;
190
     const char *language;
191
     const char *territory;
192
     const char *codeset;
193
     const char *normalized_codeset;
194
     const char *modifier;
195
     const char *special;
196
     const char *sponsor;
197
     const char *revision;
198
     const char *filename;
199
     int do_allocate;
200
{
201
  char *abs_filename;
202
  struct loaded_l10nfile *last = NULL;
203
  struct loaded_l10nfile *retval;
204
  char *cp;
205
  size_t entries;
206
  int cnt;
207
 
208
  /* Allocate room for the full file name.  */
209
  abs_filename = (char *) malloc (dirlist_len
210
                                  + strlen (language)
211
                                  + ((mask & TERRITORY) != 0
212
                                     ? strlen (territory) + 1 : 0)
213
                                  + ((mask & XPG_CODESET) != 0
214
                                     ? strlen (codeset) + 1 : 0)
215
                                  + ((mask & XPG_NORM_CODESET) != 0
216
                                     ? strlen (normalized_codeset) + 1 : 0)
217
                                  + (((mask & XPG_MODIFIER) != 0
218
                                      || (mask & CEN_AUDIENCE) != 0)
219
                                     ? strlen (modifier) + 1 : 0)
220
                                  + ((mask & CEN_SPECIAL) != 0
221
                                     ? strlen (special) + 1 : 0)
222
                                  + (((mask & CEN_SPONSOR) != 0
223
                                      || (mask & CEN_REVISION) != 0)
224
                                     ? (1 + ((mask & CEN_SPONSOR) != 0
225
                                             ? strlen (sponsor) + 1 : 0)
226
                                        + ((mask & CEN_REVISION) != 0
227
                                           ? strlen (revision) + 1 : 0)) : 0)
228
                                  + 1 + strlen (filename) + 1);
229
 
230
  if (abs_filename == NULL)
231
    return NULL;
232
 
233
  retval = NULL;
234
  last = NULL;
235
 
236
  /* Construct file name.  */
237
  memcpy (abs_filename, dirlist, dirlist_len);
238
  argz_stringify (abs_filename, dirlist_len, ':');
239
  cp = abs_filename + (dirlist_len - 1);
240
  *cp++ = '/';
241
  cp = stpcpy (cp, language);
242
 
243
  if ((mask & TERRITORY) != 0)
244
    {
245
      *cp++ = '_';
246
      cp = stpcpy (cp, territory);
247
    }
248
  if ((mask & XPG_CODESET) != 0)
249
    {
250
      *cp++ = '.';
251
      cp = stpcpy (cp, codeset);
252
    }
253
  if ((mask & XPG_NORM_CODESET) != 0)
254
    {
255
      *cp++ = '.';
256
      cp = stpcpy (cp, normalized_codeset);
257
    }
258
  if ((mask & (XPG_MODIFIER | CEN_AUDIENCE)) != 0)
259
    {
260
      /* This component can be part of both syntaces but has different
261
         leading characters.  For CEN we use `+', else `@'.  */
262
      *cp++ = (mask & CEN_AUDIENCE) != 0 ? '+' : '@';
263
      cp = stpcpy (cp, modifier);
264
    }
265
  if ((mask & CEN_SPECIAL) != 0)
266
    {
267
      *cp++ = '+';
268
      cp = stpcpy (cp, special);
269
    }
270
  if ((mask & (CEN_SPONSOR | CEN_REVISION)) != 0)
271
    {
272
      *cp++ = ',';
273
      if ((mask & CEN_SPONSOR) != 0)
274
        cp = stpcpy (cp, sponsor);
275
      if ((mask & CEN_REVISION) != 0)
276
        {
277
          *cp++ = '_';
278
          cp = stpcpy (cp, revision);
279
        }
280
    }
281
 
282
  *cp++ = '/';
283
  stpcpy (cp, filename);
284
 
285
  /* Look in list of already loaded domains whether it is already
286
     available.  */
287
  last = NULL;
288
  for (retval = *l10nfile_list; retval != NULL; retval = retval->next)
289
    if (retval->filename != NULL)
290
      {
291
        int compare = strcmp (retval->filename, abs_filename);
292
        if (compare == 0)
293
          /* We found it!  */
294
          break;
295
        if (compare < 0)
296
          {
297
            /* It's not in the list.  */
298
            retval = NULL;
299
            break;
300
          }
301
 
302
        last = retval;
303
      }
304
 
305
  if (retval != NULL || do_allocate == 0)
306
    {
307
      free (abs_filename);
308
      return retval;
309
    }
310
 
311
  retval = (struct loaded_l10nfile *)
312
    malloc (sizeof (*retval) + (argz_count (dirlist, dirlist_len)
313
                                * (1 << pop (mask))
314
                                * sizeof (struct loaded_l10nfile *)));
315
  if (retval == NULL)
316
    return NULL;
317
 
318
  retval->filename = abs_filename;
319
  retval->decided = (argz_count (dirlist, dirlist_len) != 1
320
                     || ((mask & XPG_CODESET) != 0
321
                         && (mask & XPG_NORM_CODESET) != 0));
322
  retval->data = NULL;
323
 
324
  if (last == NULL)
325
    {
326
      retval->next = *l10nfile_list;
327
      *l10nfile_list = retval;
328
    }
329
  else
330
    {
331
      retval->next = last->next;
332
      last->next = retval;
333
    }
334
 
335
  entries = 0;
336
  /* If the DIRLIST is a real list the RETVAL entry corresponds not to
337
     a real file.  So we have to use the DIRLIST separation mechanism
338
     of the inner loop.  */
339
  cnt = argz_count (dirlist, dirlist_len) == 1 ? mask - 1 : mask;
340
  for (; cnt >= 0; --cnt)
341
    if ((cnt & ~mask) == 0
342
        && ((cnt & CEN_SPECIFIC) == 0 || (cnt & XPG_SPECIFIC) == 0)
343
        && ((cnt & XPG_CODESET) == 0 || (cnt & XPG_NORM_CODESET) == 0))
344
      {
345
        /* Iterate over all elements of the DIRLIST.  */
346
        char *dir = NULL;
347
 
348
        while ((dir = argz_next ((char *) dirlist, dirlist_len, dir))
349
               != NULL)
350
          retval->successor[entries++]
351
            = _nl_make_l10nflist (l10nfile_list, dir, strlen (dir) + 1, cnt,
352
                                  language, territory, codeset,
353
                                  normalized_codeset, modifier, special,
354
                                  sponsor, revision, filename, 1);
355
      }
356
  retval->successor[entries] = NULL;
357
 
358
  return retval;
359
}
360
 
361
/* Normalize codeset name.  There is no standard for the codeset
362
   names.  Normalization allows the user to use any of the common
363
   names.  The return value is dynamically allocated and has to be
364
   freed by the caller.  */
365
const char *
366
_nl_normalize_codeset (codeset, name_len)
367
     const char *codeset;
368
     size_t name_len;
369
{
370
  int len = 0;
371
  int only_digit = 1;
372
  char *retval;
373
  char *wp;
374
  size_t cnt;
375
 
376
  for (cnt = 0; cnt < name_len; ++cnt)
377
    if (isalnum (codeset[cnt]))
378
      {
379
        ++len;
380
 
381
        if (isalpha (codeset[cnt]))
382
          only_digit = 0;
383
      }
384
 
385
  retval = (char *) malloc ((only_digit ? 3 : 0) + len + 1);
386
 
387
  if (retval != NULL)
388
    {
389
      if (only_digit)
390
        wp = stpcpy (retval, "iso");
391
      else
392
        wp = retval;
393
 
394
      for (cnt = 0; cnt < name_len; ++cnt)
395
        if (isalpha (codeset[cnt]))
396
          *wp++ = tolower (codeset[cnt]);
397
        else if (isdigit (codeset[cnt]))
398
          *wp++ = codeset[cnt];
399
 
400
      *wp = '\0';
401
    }
402
 
403
  return (const char *) retval;
404
}
405
 
406
 
407
/* @@ begin of epilog @@ */
408
 
409
/* We don't want libintl.a to depend on any other library.  So we
410
   avoid the non-standard function stpcpy.  In GNU C Library this
411
   function is available, though.  Also allow the symbol HAVE_STPCPY
412
   to be defined.  */
413
#if !_GLIBC && !HAVE_STPCPY
414
static char *
415
stpcpy (dest, src)
416
     char *dest;
417
     const char *src;
418
{
419
  while ((*dest++ = *src++) != '\0')
420
    /* Do nothing. */ ;
421
  return dest - 1;
422
}
423
#endif
424
 
425
#endif /* _MB_CAPABLE */

powered by: WebSVN 2.1.0

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