1 /* $NetBSD: src/lib/libc/locale/runeglue.c,v 1.10 2003/03/10 21:18:49 tshiozak Exp $ */
2 /* $DragonFly: src/lib/libc/locale/runeglue.c,v 1.3 2005/09/17 14:39:44 joerg Exp $ */
5 * Copyright (c)1999 Citrus Project,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Id: runeglue.c,v 1.7 2000/12/22 22:52:29 itojun Exp
33 * Glue code to hide "rune" facility from user programs.
34 * This is important to keep backward/future compatibility.
37 #define _CTYPE_PRIVATE
39 #include <sys/types.h>
48 #include "rune_local.h"
53 #if _CACHED_RUNES != 256
54 #error "_CACHED_RUNES != 256"
58 __runetable_to_netbsd_ctype(const char *locale)
62 int16_t *new_toupper, *new_tolower;
64 _DIAGASSERT(locale != NULL);
66 /* set to C locale, to ease failure case handling */
67 if (__libc_ctype_ != __libc_C_ctype_) {
68 /* LINTED const castaway */
69 free(__DECONST(void *, __libc_ctype_));
70 __libc_ctype_ = __libc_C_ctype_;
72 if (__libc_toupper_tab_ != __libc_C_toupper_) {
73 /* LINTED const castaway */
74 free(__DECONST(void *, __libc_toupper_tab_));
75 __libc_toupper_tab_ = __libc_C_toupper_;
77 if (__libc_tolower_tab_ != __libc_C_tolower_) {
78 /* LINTED const castaway */
79 free(__DECONST(void *, __libc_tolower_tab_));
80 __libc_tolower_tab_ = __libc_C_tolower_;
83 if (strcmp(locale, "C") == 0 || strcmp(locale, "POSIX") == 0)
86 new_ctype = malloc(sizeof(*new_ctype) * (1 + _CTYPE_NUM_CHARS));
87 if (new_ctype == NULL)
89 new_toupper = malloc(sizeof(*new_toupper) * (1 + 256));
90 if (new_toupper == NULL) {
94 new_tolower = malloc(sizeof(*new_tolower) * (1 + 256));
95 if (new_tolower == NULL) {
101 memset(new_ctype, 0, sizeof(*new_ctype) * (1 + _CTYPE_NUM_CHARS));
102 memset(new_toupper, 0, sizeof(*new_toupper) * (1 + 256));
103 memset(new_tolower, 0, sizeof(*new_tolower) * (1 + 256));
106 new_toupper[0] = EOF;
107 new_tolower[0] = EOF;
108 for (i = 0; i < _CTYPE_NUM_CHARS; i++) {
109 new_ctype[i + 1] = 0;
110 if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_U)
111 new_ctype[i + 1] |= _CTYPEMASK_U;
112 if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_L)
113 new_ctype[i + 1] |= _CTYPEMASK_L;
114 if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_D)
115 new_ctype[i + 1] |= _CTYPEMASK_D;
116 if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_S)
117 new_ctype[i + 1] |= _CTYPEMASK_S;
118 if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_P)
119 new_ctype[i + 1] |= _CTYPEMASK_P;
120 if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_C)
121 new_ctype[i + 1] |= _CTYPEMASK_C;
122 if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_X)
123 new_ctype[i + 1] |= _CTYPEMASK_X;
124 if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_B)
125 new_ctype[i + 1] |= _CTYPEMASK_B;
126 if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_A)
127 new_ctype[i + 1] |= _CTYPEMASK_A;
128 if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_G)
129 new_ctype[i + 1] |= _CTYPEMASK_G;
130 if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_R)
131 new_ctype[i + 1] |= _CTYPEMASK_R;
133 new_toupper[i + 1] = (int16_t)_CurrentRuneLocale->rl_mapupper[i];
134 new_tolower[i + 1] = (int16_t)_CurrentRuneLocale->rl_maplower[i];
137 __libc_ctype_ = new_ctype;
138 __libc_toupper_tab_ = new_toupper;
139 __libc_tolower_tab_ = new_tolower;