~ubuntu-branches/ubuntu/maverick/texinfo/maverick

« back to all changes in this revision

Viewing changes to intl/localealias.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2005-10-28 15:10:30 UTC
  • mto: (2.1.1 dapper) (3.1.4 hardy)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20051028151030-9nsf2s2k2z3fktjt
Tags: upstream-4.8
ImportĀ upstreamĀ versionĀ 4.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Handle aliases for locale names.
2
 
   Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
 
2
   Copyright (C) 1995-1999, 2000-2001, 2003 Free Software Foundation, Inc.
3
3
 
4
4
   This program is free software; you can redistribute it and/or modify it
5
5
   under the terms of the GNU Library General Public License as published
35
35
#include <sys/types.h>
36
36
 
37
37
#ifdef __GNUC__
 
38
# undef alloca
38
39
# define alloca __builtin_alloca
39
40
# define HAVE_ALLOCA 1
40
41
#else
41
 
# if defined HAVE_ALLOCA_H || defined _LIBC
42
 
#  include <alloca.h>
 
42
# ifdef _MSC_VER
 
43
#  include <malloc.h>
 
44
#  define alloca _alloca
43
45
# else
44
 
#  ifdef _AIX
 
46
#  if defined HAVE_ALLOCA_H || defined _LIBC
 
47
#   include <alloca.h>
 
48
#  else
 
49
#   ifdef _AIX
45
50
 #pragma alloca
46
 
#  else
47
 
#   ifndef alloca
 
51
#   else
 
52
#    ifndef alloca
48
53
char *alloca ();
 
54
#    endif
49
55
#   endif
50
56
#  endif
51
57
# endif
56
62
 
57
63
#include "gettextP.h"
58
64
 
 
65
#if ENABLE_RELOCATABLE
 
66
# include "relocatable.h"
 
67
#else
 
68
# define relocate(pathname) (pathname)
 
69
#endif
 
70
 
59
71
/* @@ end of prolog @@ */
60
72
 
61
73
#ifdef _LIBC
98
110
# define freea(p) free (p)
99
111
#endif
100
112
 
101
 
#if defined _LIBC_REENTRANT || defined HAVE_FGETS_UNLOCKED
 
113
#if defined _LIBC_REENTRANT || HAVE_DECL_FGETS_UNLOCKED
102
114
# undef fgets
103
115
# define fgets(buf, len, s) fgets_unlocked (buf, len, s)
104
116
#endif
105
 
#if defined _LIBC_REENTRANT || defined HAVE_FEOF_UNLOCKED
 
117
#if defined _LIBC_REENTRANT || HAVE_DECL_FEOF_UNLOCKED
106
118
# undef feof
107
119
# define feof(s) feof_unlocked (s)
108
120
#endif
115
127
};
116
128
 
117
129
 
118
 
static char *string_space;
 
130
#ifndef _LIBC
 
131
# define libc_freeres_ptr(decl) decl
 
132
#endif
 
133
 
 
134
libc_freeres_ptr (static char *string_space);
119
135
static size_t string_space_act;
120
136
static size_t string_space_max;
121
 
static struct alias_map *map;
 
137
libc_freeres_ptr (static struct alias_map *map);
122
138
static size_t nmap;
123
139
static size_t maxmap;
124
140
 
125
141
 
126
142
/* Prototypes for local functions.  */
127
 
static size_t read_alias_file PARAMS ((const char *fname, int fname_len))
 
143
static size_t read_alias_file (const char *fname, int fname_len)
128
144
     internal_function;
129
 
static int extend_alias_table PARAMS ((void));
130
 
static int alias_compare PARAMS ((const struct alias_map *map1,
131
 
                                  const struct alias_map *map2));
 
145
static int extend_alias_table (void);
 
146
static int alias_compare (const struct alias_map *map1,
 
147
                          const struct alias_map *map2);
132
148
 
133
149
 
134
150
const char *
135
 
_nl_expand_alias (name)
136
 
    const char *name;
 
151
_nl_expand_alias (const char *name)
137
152
{
138
153
  static const char *locale_alias_path;
139
154
  struct alias_map *retval;
156
171
      if (nmap > 0)
157
172
        retval = (struct alias_map *) bsearch (&item, map, nmap,
158
173
                                               sizeof (struct alias_map),
159
 
                                               (int (*) PARAMS ((const void *,
160
 
                                                                 const void *))
 
174
                                               (int (*) (const void *,
 
175
                                                         const void *)
161
176
                                                ) alias_compare);
162
177
      else
163
178
        retval = NULL;
199
214
 
200
215
static size_t
201
216
internal_function
202
 
read_alias_file (fname, fname_len)
203
 
     const char *fname;
204
 
     int fname_len;
 
217
read_alias_file (const char *fname, int fname_len)
205
218
{
206
219
  FILE *fp;
207
220
  char *full_fname;
217
230
  memcpy (&full_fname[fname_len], aliasfile, sizeof aliasfile);
218
231
#endif
219
232
 
220
 
  fp = fopen (full_fname, "r");
 
233
  fp = fopen (relocate (full_fname), "r");
221
234
  freea (full_fname);
222
235
  if (fp == NULL)
223
236
    return 0;
234
247
         a) we are only interested in the first two fields
235
248
         b) these fields must be usable as file names and so must not
236
249
            be that long
237
 
       */
238
 
      char buf[BUFSIZ];
 
250
         We avoid a multi-kilobyte buffer here since this would use up
 
251
         stack space which we might not have if the program ran out of
 
252
         memory.  */
 
253
      char buf[400];
239
254
      char *alias;
240
255
      char *value;
241
256
      char *cp;
244
259
        /* EOF reached.  */
245
260
        break;
246
261
 
247
 
      /* Possibly not the whole line fits into the buffer.  Ignore
248
 
         the rest of the line.  */
249
 
      if (strchr (buf, '\n') == NULL)
250
 
        {
251
 
          char altbuf[BUFSIZ];
252
 
          do
253
 
            if (FGETS (altbuf, sizeof altbuf, fp) == NULL)
254
 
              /* Make sure the inner loop will be left.  The outer loop
255
 
                 will exit at the `feof' test.  */
256
 
              break;
257
 
          while (strchr (altbuf, '\n') == NULL);
258
 
        }
259
 
 
260
262
      cp = buf;
261
263
      /* Ignore leading white space.  */
262
264
      while (isspace ((unsigned char) cp[0]))
340
342
              ++added;
341
343
            }
342
344
        }
 
345
 
 
346
      /* Possibly not the whole line fits into the buffer.  Ignore
 
347
         the rest of the line.  */
 
348
      while (strchr (buf, '\n') == NULL)
 
349
        if (FGETS (buf, sizeof buf, fp) == NULL)
 
350
          /* Make sure the inner loop will be left.  The outer loop
 
351
             will exit at the `feof' test.  */
 
352
          break;
343
353
    }
344
354
 
345
355
  /* Should we test for ferror()?  I think we have to silently ignore
348
358
 
349
359
  if (added > 0)
350
360
    qsort (map, nmap, sizeof (struct alias_map),
351
 
           (int (*) PARAMS ((const void *, const void *))) alias_compare);
 
361
           (int (*) (const void *, const void *)) alias_compare);
352
362
 
353
363
  return added;
354
364
}
373
383
}
374
384
 
375
385
 
376
 
#ifdef _LIBC
377
 
static void __attribute__ ((unused))
378
 
free_mem (void)
379
 
{
380
 
  if (string_space != NULL)
381
 
    free (string_space);
382
 
  if (map != NULL)
383
 
    free (map);
384
 
}
385
 
text_set_element (__libc_subfreeres, free_mem);
386
 
#endif
387
 
 
388
 
 
389
386
static int
390
 
alias_compare (map1, map2)
391
 
     const struct alias_map *map1;
392
 
     const struct alias_map *map2;
 
387
alias_compare (const struct alias_map *map1, const struct alias_map *map2)
393
388
{
394
389
#if defined _LIBC || defined HAVE_STRCASECMP
395
390
  return strcasecmp (map1->alias, map2->alias);