| 1 | /* Handle aliases for locale names.
|
|---|
| 2 | Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
|
|---|
| 3 | Written by Ulrich Drepper <[email protected]>, 1995.
|
|---|
| 4 |
|
|---|
| 5 | This program is free software; you can redistribute it and/or modify
|
|---|
| 6 | it under the terms of the GNU General Public License as published by
|
|---|
| 7 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 8 | any later version.
|
|---|
| 9 |
|
|---|
| 10 | This program is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with this program; if not, write to the Free Software Foundation,
|
|---|
| 17 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|---|
| 18 |
|
|---|
| 19 | #ifdef HAVE_CONFIG_H
|
|---|
| 20 | # include <config.h>
|
|---|
| 21 | #endif
|
|---|
| 22 |
|
|---|
| 23 | #include <ctype.h>
|
|---|
| 24 | #include <stdio.h>
|
|---|
| 25 | #include <sys/types.h>
|
|---|
| 26 |
|
|---|
| 27 | #ifdef __GNUC__
|
|---|
| 28 | # define alloca __builtin_alloca
|
|---|
| 29 | # define HAVE_ALLOCA 1
|
|---|
| 30 | #else
|
|---|
| 31 | # if defined HAVE_ALLOCA_H || defined _LIBC
|
|---|
| 32 | # include <alloca.h>
|
|---|
| 33 | # else
|
|---|
| 34 | # ifdef _AIX
|
|---|
| 35 | #pragma alloca
|
|---|
| 36 | # else
|
|---|
| 37 | # ifndef alloca
|
|---|
| 38 | char *alloca ();
|
|---|
| 39 | # endif
|
|---|
| 40 | # endif
|
|---|
| 41 | # endif
|
|---|
| 42 | #endif
|
|---|
| 43 |
|
|---|
| 44 | #if defined STDC_HEADERS || defined _LIBC
|
|---|
| 45 | # include <stdlib.h>
|
|---|
| 46 | #else
|
|---|
| 47 | char *getenv ();
|
|---|
| 48 | # ifdef HAVE_MALLOC_H
|
|---|
| 49 | # include <malloc.h>
|
|---|
| 50 | # else
|
|---|
| 51 | void free ();
|
|---|
| 52 | # endif
|
|---|
| 53 | #endif
|
|---|
| 54 |
|
|---|
| 55 | #if defined HAVE_STRING_H || defined _LIBC
|
|---|
| 56 | # ifndef _GNU_SOURCE
|
|---|
| 57 | # define _GNU_SOURCE 1
|
|---|
| 58 | # endif
|
|---|
| 59 | # include <string.h>
|
|---|
| 60 | #else
|
|---|
| 61 | # include <strings.h>
|
|---|
| 62 | # ifndef memcpy
|
|---|
| 63 | # define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num)
|
|---|
| 64 | # endif
|
|---|
| 65 | #endif
|
|---|
| 66 | #if !HAVE_STRCHR && !defined _LIBC
|
|---|
| 67 | # ifndef strchr
|
|---|
| 68 | # define strchr index
|
|---|
| 69 | # endif
|
|---|
| 70 | #endif
|
|---|
| 71 |
|
|---|
| 72 | #include "gettext.h"
|
|---|
| 73 | #include "gettextP.h"
|
|---|
| 74 |
|
|---|
| 75 | /* @@ end of prolog @@ */
|
|---|
| 76 |
|
|---|
| 77 | #ifdef _LIBC
|
|---|
| 78 | /* Rename the non ANSI C functions. This is required by the standard
|
|---|
| 79 | because some ANSI C functions will require linking with this object
|
|---|
| 80 | file and the name space must not be polluted. */
|
|---|
| 81 | # define strcasecmp __strcasecmp
|
|---|
| 82 |
|
|---|
| 83 | # define mempcpy __mempcpy
|
|---|
| 84 | # define HAVE_MEMPCPY 1
|
|---|
| 85 |
|
|---|
| 86 | /* We need locking here since we can be called from different places. */
|
|---|
| 87 | # include <bits/libc-lock.h>
|
|---|
| 88 |
|
|---|
| 89 | __libc_lock_define_initialized (static, lock);
|
|---|
| 90 | #endif
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 | /* For those loosing systems which don't have `alloca' we have to add
|
|---|
| 94 | some additional code emulating it. */
|
|---|
| 95 | #ifdef HAVE_ALLOCA
|
|---|
| 96 | /* Nothing has to be done. */
|
|---|
| 97 | # define ADD_BLOCK(list, address) /* nothing */
|
|---|
| 98 | # define FREE_BLOCKS(list) /* nothing */
|
|---|
| 99 | #else
|
|---|
| 100 | struct block_list
|
|---|
| 101 | {
|
|---|
| 102 | void *address;
|
|---|
| 103 | struct block_list *next;
|
|---|
| 104 | };
|
|---|
| 105 | # define ADD_BLOCK(list, addr) \
|
|---|
| 106 | do { \
|
|---|
| 107 | struct block_list *newp = (struct block_list *) malloc (sizeof (*newp)); \
|
|---|
| 108 | /* If we cannot get a free block we cannot add the new element to \
|
|---|
| 109 | the list. */ \
|
|---|
| 110 | if (newp != NULL) { \
|
|---|
| 111 | newp->address = (addr); \
|
|---|
| 112 | newp->next = (list); \
|
|---|
| 113 | (list) = newp; \
|
|---|
| 114 | } \
|
|---|
| 115 | } while (0)
|
|---|
| 116 | # define FREE_BLOCKS(list) \
|
|---|
| 117 | do { \
|
|---|
| 118 | while (list != NULL) { \
|
|---|
| 119 | struct block_list *old = list; \
|
|---|
| 120 | list = list->next; \
|
|---|
| 121 | free (old); \
|
|---|
| 122 | } \
|
|---|
| 123 | } while (0)
|
|---|
| 124 | # undef alloca
|
|---|
| 125 | # define alloca(size) (malloc (size))
|
|---|
| 126 | #endif /* have alloca */
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 | struct alias_map
|
|---|
| 130 | {
|
|---|
| 131 | const char *alias;
|
|---|
| 132 | const char *value;
|
|---|
| 133 | };
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 | static char *string_space = NULL;
|
|---|
| 137 | static size_t string_space_act = 0;
|
|---|
| 138 | static size_t string_space_max = 0;
|
|---|
| 139 | static struct alias_map *map;
|
|---|
| 140 | static size_t nmap = 0;
|
|---|
| 141 | static size_t maxmap = 0;
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 | /* Prototypes for local functions. */
|
|---|
| 145 | static size_t read_alias_file PARAMS ((const char *fname, int fname_len))
|
|---|
| 146 | internal_function;
|
|---|
| 147 | static void extend_alias_table PARAMS ((void));
|
|---|
| 148 | static int alias_compare PARAMS ((const struct alias_map *map1,
|
|---|
| 149 | const struct alias_map *map2));
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 | const char *
|
|---|
| 153 | _nl_expand_alias (name)
|
|---|
| 154 | const char *name;
|
|---|
| 155 | {
|
|---|
| 156 | static const char *locale_alias_path = LOCALE_ALIAS_PATH;
|
|---|
| 157 | struct alias_map *retval;
|
|---|
| 158 | const char *result = NULL;
|
|---|
| 159 | size_t added;
|
|---|
| 160 |
|
|---|
| 161 | #ifdef _LIBC
|
|---|
| 162 | __libc_lock_lock (lock);
|
|---|
| 163 | #endif
|
|---|
|
|---|