Sync usage with man page.
[netbsd-mini2440.git] / lib / libc / locale / _wctype.c
blob5f6087e31bdfa340b599546b3ff68361b328ad10
1 /* $NetBSD: _wctype.c,v 1.4 2009/01/18 19:53:11 christos Exp $ */
3 /*-
4 * Copyright (c)2008 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.
29 /*-
30 * Copyright (c) 1993
31 * The Regents of the University of California. All rights reserved.
33 * This code is derived from software contributed to Berkeley by
34 * Paul Borman at Krystal Technologies.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
61 #include <sys/cdefs.h>
62 #if defined(LIBC_SCCS) && !defined(lint)
63 __RCSID("$NetBSD: _wctype.c,v 1.4 2009/01/18 19:53:11 christos Exp $");
64 #endif /* LIBC_SCCS and not lint */
66 #include <assert.h>
67 #include <ctype.h>
68 #include <errno.h>
69 #include <string.h>
71 #include "rune.h"
72 #include "_wctrans_local.h"
73 #include "_wctype_local.h"
75 _RuneType
76 _runetype_priv(_RuneLocale const *rl, wint_t wc)
78 __nbrune_t wc0;
79 _RuneRange const *rr;
80 _RuneEntry *base, *re;
81 uint32_t x;
83 _DIAGASSERT(rl != NULL);
85 if (wc == WEOF)
86 return 0U;
87 if (_RUNE_ISCACHED(wc))
88 return rl->rl_runetype[(size_t)wc];
89 wc0 = (__nbrune_t)wc;
90 rr = &rl->rl_runetype_ext;
91 _DIAGASSERT(rr != NULL);
92 base = rr->rr_rune_ranges;
93 for (x = rr->rr_nranges; x != (uint32_t)0; x >>= 1) {
94 re = base + (x >> 1);
95 if (re->re_min <= wc0 && re->re_max >= wc0) {
96 if (re->re_rune_types)
97 return re->re_rune_types[wc0 - re->re_min];
98 else
99 return re->re_map;
100 } else if (wc0 > re->re_max) {
101 base = re + 1;
102 --x;
105 return (_RuneType)0U;
109 _iswctype_priv(_RuneLocale const *rl,
110 wint_t wc, _WCTypeEntry const *te)
112 return !!(_runetype_priv(rl, wc) & te->te_mask);
115 wint_t
116 /*ARGSUSED*/
117 _towctrans_priv(_RuneLocale const *rl,
118 wint_t wc, _WCTransEntry const *te)
120 __nbrune_t wc0;
121 _RuneRange *rr;
122 _RuneEntry *base, *re;
123 uint32_t x;
125 _DIAGASSERT(rl != NULL);
126 _DIAGASSERT(te != NULL);
128 if (wc == WEOF)
129 return wc;
130 _DIAGASSERT(te->te_name != NULL);
131 if (_RUNE_ISCACHED(wc))
132 return te->te_cached[(size_t)wc];
133 wc0 = (__nbrune_t)wc;
134 rr = te->te_extmap;
135 _DIAGASSERT(rr != NULL);
136 base = rr->rr_rune_ranges;
137 for (x = rr->rr_nranges; x != (uint32_t)0; x >>= 1) {
138 re = base + (x >> 1);
139 if (re->re_min <= wc0 && re->re_max >= wc0) {
140 return re->re_map + wc0 - re->re_min;
141 } else if (wc0 >= re->re_max) {
142 base = re + 1;
143 --x;
146 return wc;