1 /* $NetBSD: runeglue.c,v 1.13.2.1 2009/01/04 17:02:20 christos Exp $ */
4 * Copyright (c)1999 Citrus Project,
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * Id: runeglue.c,v 1.7 2000/12/22 22:52:29 itojun Exp
32 * Glue code to hide "rune" facility from user programs.
33 * This is important to keep backward/future compatibility.
36 #include <sys/cdefs.h>
37 #if defined(LIBC_SCCS) && !defined(lint)
38 __RCSID("$NetBSD: runeglue.c,v 1.13.2.1 2009/01/04 17:02:20 christos Exp $");
39 #endif /* LIBC_SCCS and not lint */
41 #define _CTYPE_PRIVATE
45 #include <sys/types.h>
50 #include "citrus_module.h"
51 #include "citrus_ctype.h"
53 #include "rune_local.h"
58 #if _CACHED_RUNES != 256
59 #error "_CACHED_RUNES != 256"
63 __runetable_to_netbsd_ctype(rl
)
67 unsigned char *new_ctype
;
68 short *new_toupper
, *new_tolower
;
70 _DIAGASSERT(rl
!= NULL
);
72 new_ctype
= malloc(sizeof(*new_ctype
) * (1 + _CTYPE_NUM_CHARS
));
75 new_toupper
= malloc(sizeof(*new_toupper
) * (1 + 256));
80 new_tolower
= malloc(sizeof(*new_tolower
) * (1 + 256));
87 memset(new_ctype
, 0, sizeof(*new_ctype
) * (1 + _CTYPE_NUM_CHARS
));
88 memset(new_toupper
, 0, sizeof(*new_toupper
) * (1 + 256));
89 memset(new_tolower
, 0, sizeof(*new_tolower
) * (1 + 256));
94 for (i
= 0; i
< _CTYPE_NUM_CHARS
; i
++) {
96 new_toupper
[i
+ 1] = i
;
97 new_tolower
[i
+ 1] = i
;
100 * expected 'x' == L'x', see defect report #279
101 * http://www.open-std.org/JTC1/SC22/WG14/www/docs/dr_279.htm
103 if (_citrus_ctype_wctob(rl
->rl_citrus_ctype
, (wint_t)i
, &ch
)) {
112 if (rl
->rl_runetype
[i
] & _CTYPE_U
)
113 new_ctype
[i
+ 1] |= _U
;
114 if (rl
->rl_runetype
[i
] & _CTYPE_L
)
115 new_ctype
[i
+ 1] |= _L
;
116 if (rl
->rl_runetype
[i
] & _CTYPE_D
)
117 new_ctype
[i
+ 1] |= _N
;
118 if (rl
->rl_runetype
[i
] & _CTYPE_S
)
119 new_ctype
[i
+ 1] |= _S
;
120 if (rl
->rl_runetype
[i
] & _CTYPE_P
)
121 new_ctype
[i
+ 1] |= _P
;
122 if (rl
->rl_runetype
[i
] & _CTYPE_C
)
123 new_ctype
[i
+ 1] |= _C
;
124 if (rl
->rl_runetype
[i
] & _CTYPE_X
)
125 new_ctype
[i
+ 1] |= _X
;
127 * TWEAK! _B has been used incorrectly (or with older
128 * declaration) in ctype.h isprint() macro.
129 * _B does not mean isblank, it means "isprint && !isgraph".
130 * the following is okay since isblank() was hardcoded in
131 * function (i.e. isblank() is inherently locale unfriendly).
134 if ((rl
->rl_runetype
[i
] & (_CTYPE_R
| _CTYPE_G
)) == _CTYPE_R
)
135 new_ctype
[i
+ 1] |= _B
;
137 if (rl
->rl_runetype
[i
] & _CTYPE_B
)
138 new_ctype
[i
+ 1] |= _B
;
140 new_toupper
[i
+ 1] = (short)rl
->rl_mapupper
[i
];
141 new_tolower
[i
+ 1] = (short)rl
->rl_maplower
[i
];
144 /* LINTED const cast */
145 rl
->rl_ctype_tab
= (const unsigned char *)new_ctype
;
146 /* LINTED const cast */
147 rl
->rl_toupper_tab
= (const short *)new_toupper
;
148 /* LINTED const cast */
149 rl
->rl_tolower_tab
= (const short *)new_tolower
;