Add a manual page explaining the format of /etc/manpath.config.
[dragonfly/vkernel-mp.git] / lib / libc / locale / iswctype.c
bloba9085ef379da3ab2032236734912201d05a19386
1 /* $NetBSD: src/lib/libc/locale/iswctype.c,v 1.14 2003/08/07 16:43:04 agc Exp $ */
2 /* $DragonFly: src/lib/libc/locale/iswctype.c,v 1.1 2005/03/16 07:54:41 joerg Exp $ */
4 /*
5 * Copyright (c) 1989 The Regents of the University of California.
6 * All rights reserved.
7 * (c) UNIX System Laboratories, Inc.
8 * All or some portions of this file are derived from material licensed
9 * to the University of California by American Telephone and Telegraph
10 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11 * the permission of UNIX System Laboratories, Inc.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
38 #include <ctype.h>
39 #include <errno.h>
40 #include <string.h>
41 #include <wchar.h>
42 #include <wctype.h>
43 #include "rune.h"
44 #include "runetype.h"
45 #include "rune_local.h"
46 #include "_wctrans_local.h"
48 static _RuneType __runetype_w(wint_t);
49 static int __isctype_w(wint_t, _RuneType);
50 static wint_t __toupper_w(wint_t);
51 static wint_t __tolower_w(wint_t);
53 static _RuneType
54 __runetype_w(wint_t c)
56 _RuneLocale *rl = _CurrentRuneLocale;
58 if (_RUNE_ISCACHED(c))
59 return(rl->rl_runetype[c]);
60 else
61 return(___runetype_mb(c));
64 static int
65 __isctype_w(wint_t c, _RuneType f)
67 if (__runetype_w(c) & f)
68 return(1);
69 else
70 return(0);
73 static wint_t
74 __toupper_w(wint_t c)
76 return(_towctrans(c, _wctrans_upper(_CurrentRuneLocale)));
79 static wint_t
80 __tolower_w(wint_t c)
82 return(_towctrans(c, _wctrans_lower(_CurrentRuneLocale)));
85 #undef iswalnum
86 int
87 iswalnum(wint_t c)
89 return(__isctype_w((c), _CTYPE_A|_CTYPE_D));
92 #undef iswalpha
93 int
94 iswalpha(wint_t c)
96 return(__isctype_w((c), _CTYPE_A));
99 #undef iswblank
101 iswblank(wint_t c)
103 return(__isctype_w((c), _CTYPE_B));
106 #undef iswcntrl
108 iswcntrl(wint_t c)
110 return(__isctype_w((c), _CTYPE_C));
113 #undef iswdigit
115 iswdigit(wint_t c)
117 return(__isctype_w((c), _CTYPE_D));
120 #undef iswgraph
122 iswgraph(wint_t c)
124 return(__isctype_w((c), _CTYPE_G));
127 #undef iswlower
129 iswlower(wint_t c)
131 return(__isctype_w((c), _CTYPE_L));
134 #undef iswprint
136 iswprint(wint_t c)
138 return(__isctype_w((c), _CTYPE_R));
141 #undef iswpunct
143 iswpunct(wint_t c)
145 return(__isctype_w((c), _CTYPE_P));
148 #undef iswspace
150 iswspace(wint_t c)
152 return(__isctype_w((c), _CTYPE_S));
155 #undef iswupper
157 iswupper(wint_t c)
159 return(__isctype_w((c), _CTYPE_U));
162 #undef iswxdigit
164 iswxdigit(wint_t c)
166 return(__isctype_w((c), _CTYPE_X));
169 #undef towupper
170 wint_t
171 towupper(wint_t c)
173 return(__toupper_w(c));
176 #undef towlower
177 wint_t
178 towlower(wint_t c)
180 return(__tolower_w(c));
183 #undef wcwidth
185 wcwidth(wchar_t c)
187 return(((unsigned)__runetype_w(c) & _CTYPE_SWM) >> _CTYPE_SWS);
190 #undef wctrans
191 wctrans_t
192 wctrans(const char *charclass)
194 int i;
195 _RuneLocale *rl = _CurrentRuneLocale;
197 if (rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name == NULL)
198 _wctrans_init(rl);
200 for (i = 0; i < _WCTRANS_NINDEXES; i++) {
201 if (strcmp(rl->rl_wctrans[i].te_name, charclass) == 0)
202 return((wctrans_t)&rl->rl_wctrans[i]);
205 return((wctrans_t)NULL);
208 #undef towctrans
209 wint_t
210 towctrans(wint_t c, wctrans_t desc)
212 if (desc == NULL) {
213 errno = EINVAL;
214 return(c);
216 return(_towctrans(c, (_WCTransEntry *)desc));
219 #undef wctype
220 wctype_t
221 wctype(const char *property)
223 int i;
224 _RuneLocale *rl = _CurrentRuneLocale;
226 for (i=0; i < _WCTYPE_NINDEXES; i++) {
227 if (strcmp(rl->rl_wctype[i].te_name, property) == 0)
228 return((wctype_t)&rl->rl_wctype[i]);
230 return((wctype_t)NULL);
233 #undef iswctype
235 iswctype(wint_t c, wctype_t charclass)
238 * SUSv3: If charclass is 0, iswctype() shall return 0.
240 if (charclass == (wctype_t)0)
241 return(0);
243 return (__isctype_w(c, ((_WCTypeEntry *)charclass)->te_mask));