Sync usage with man page.
[netbsd-mini2440.git] / lib / libc / locale / runeglue.c
blobfea4ab2581e71d4c34349de8f0a96a512f490f53
1 /* $NetBSD: runeglue.c,v 1.13.2.1 2009/01/04 17:02:20 christos Exp $ */
3 /*-
4 * Copyright (c)1999 Citrus Project,
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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
26 * SUCH DAMAGE.
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
42 #include <assert.h>
43 #include <limits.h>
44 #include <stdio.h>
45 #include <sys/types.h>
46 #include <ctype.h>
47 #include <stdlib.h>
48 #include <string.h>
49 #include <wchar.h>
50 #include "citrus_module.h"
51 #include "citrus_ctype.h"
52 #include "rune.h"
53 #include "rune_local.h"
55 #if EOF != -1
56 #error "EOF != -1"
57 #endif
58 #if _CACHED_RUNES != 256
59 #error "_CACHED_RUNES != 256"
60 #endif
62 int
63 __runetable_to_netbsd_ctype(rl)
64 _RuneLocale *rl;
66 int i, ch;
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));
73 if (!new_ctype)
74 return -1;
75 new_toupper = malloc(sizeof(*new_toupper) * (1 + 256));
76 if (!new_toupper) {
77 free(new_ctype);
78 return -1;
80 new_tolower = malloc(sizeof(*new_tolower) * (1 + 256));
81 if (!new_tolower) {
82 free(new_ctype);
83 free(new_toupper);
84 return -1;
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));
91 new_ctype[0] = 0;
92 new_toupper[0] = EOF;
93 new_tolower[0] = EOF;
94 for (i = 0; i < _CTYPE_NUM_CHARS; i++) {
95 new_ctype[i + 1] = 0;
96 new_toupper[i + 1] = i;
97 new_tolower[i + 1] = i;
99 /* XXX: FIXME
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)) {
104 free(new_ctype);
105 free(new_toupper);
106 free(new_tolower);
107 return -1;
109 if (ch == EOF)
110 continue;
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).
133 #if 1
134 if ((rl->rl_runetype[i] & (_CTYPE_R | _CTYPE_G)) == _CTYPE_R)
135 new_ctype[i + 1] |= _B;
136 #else
137 if (rl->rl_runetype[i] & _CTYPE_B)
138 new_ctype[i + 1] |= _B;
139 #endif
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;
151 return 0;